[Libosinfo] [osinfo-db-tools PATCH 2/8] Add support to meson build system

Fabiano Fidêncio fidencio at redhat.com
Thu Jun 20 15:21:21 UTC 2019


Meson build system is a way simpler and easier to understand build
system that can provide (with some work-arounds here and there) the same
functionalities currently available with our current build system
(autotools).

For now, as meson support is not fully complete* and requires a quite
new version of meson still not present in all systems supported on
libvirt-jenkis-ci, let's keep autotools around so more extensive testing
if meson's functionalities can be done before actually removing
autotools support.

*: the support is not fully complete as there's still no equivalent of
`make syntax-check` provided.

A quite nice description of meson, ninja, and their workflow was part of
the spice* commits introducing support to meson/ninja and is copied
below:
```
- Meson: https://mesonbuild.com

  This is the equivalent of autogen/configure step in autotools. It
  generates the files that will be used by ninja to actually build the
  source code.

  The project has received lots of traction recently, with many GNOME
  projects willing to move to this new build system. The following wiki
  page has more details of the status of the many projects being ported:

    https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting

  Meson has a python-like syntax, easy to read, and the documentation
  on the project is very complete, with a dedicated page on how to port
  from autotools, explaining how most common use cases can be
  implemented using meson.

    http://mesonbuild.com/Porting-from-autotools.html

  Other important sources of information:

    http://mesonbuild.com/howtox.html
    http://mesonbuild.com/Syntax.html
    http://mesonbuild.com/Reference-manual.html

- Ninja: https://ninja-build.org

  Ninja is the equivalent of make in an autotools setup, which actually
  builds the source code. It has being used by large and complex
  projects such as Google Chrome, Android and LLVM. There is not much to
  say about ninja (other than it is much faster than make) because we
  won't interact directly with it as much, as meson does the middle man
  job here. The reasoning for creating ninja in the first place is
  explained on the following post:

    http://neugierig.org/software/chromium/notes/2011/02/ninja.html

  Also its manual provides more in-depth information about the design
  principles:

    https://ninja-build.org/manual.html

- Basic workflow:

  Meson package is available for most if not all distros, so, taking
  Fedora as an example, we only need to run:

    # dnf -y install meson ninja-build.

  With Meson, building in-tree is not possible at all, so we need to
  pass a directory as argument to meson where we want the build to be
  done. This has the advantage of creating builds with different options
  under the same parent directory, e.g.:

    $ meson ./build --prefix=/usr
    $ meson ./build-extra -Dextra-checks=true -Dalignment-checks=true

  After configuration is done, we call ninja to actually do the build.

    $ ninja -C ./build
    $ ninja -C ./build install

- Hacking:

  * meson.build: Mandatory for the project root and usually found under
                 each directory you want something to be built.
```

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 build-aux/dist.sh |   8 ++
 meson.build       |  40 +++++++
 po/meson.build    |   2 +
 tests/meson.build |  21 ++++
 tools/meson.build | 271 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 342 insertions(+)
 create mode 100755 build-aux/dist.sh
 create mode 100644 meson.build
 create mode 100644 po/meson.build
 create mode 100644 tests/meson.build
 create mode 100644 tools/meson.build

diff --git a/build-aux/dist.sh b/build-aux/dist.sh
new file mode 100755
index 0000000..f2a4bc6
--- /dev/null
+++ b/build-aux/dist.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+SOURCE_ROOT=$1
+
+$SOURCE_ROOT/build-aux/gitlog-to-changelog > $MESON_DIST_ROOT/ChangeLog
+
+out="`git log --pretty=format:'%aN <%aE>' | sort -u`"
+perl -p -e "s/#authorslist#// and print '$out'" < $SOURCE_ROOT/AUTHORS.in > $MESON_DIST_ROOT/AUTHORS
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..a057dfa
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,40 @@
+project(
+    'osinfo-db-tools', 'c',
+    version: '1.6.0',
+    license: 'GPLv2+',
+    meson_version: '>= 0.49.0'
+)
+
+osinfo_db_tools_prefix = get_option('prefix')
+
+# those directories have to be known by the project
+osinfo_db_tools_datadir = join_paths(osinfo_db_tools_prefix, get_option('datadir'))
+osinfo_db_tools_localedir = join_paths(osinfo_db_tools_prefix, get_option('localedir'))
+osinfo_db_tools_pkgdatadir = join_paths(osinfo_db_tools_datadir, meson.project_name())
+osinfo_db_tools_sysconfdir = join_paths(osinfo_db_tools_prefix, get_option('sysconfdir'))
+
+# those directories will have files installed in
+osinfo_db_tools_bindir = join_paths(osinfo_db_tools_prefix, get_option('bindir'))
+osinfo_db_tools_docdir = join_paths(osinfo_db_tools_datadir, 'doc', meson.project_name())
+osinfo_db_tools_licensedir = join_paths(osinfo_db_tools_datadir, 'license', meson.project_name())
+osinfo_db_tools_mandir = join_paths(osinfo_db_tools_prefix, get_option('mandir'))
+
+# spec files
+osinfo_db_tools_spec_data = configuration_data()
+osinfo_db_tools_spec_data.set('VERSION', meson.project_version())
+
+specs = ['osinfo-db-tools.spec', 'mingw-osinfo-db-tools.spec']
+foreach spec: specs
+    configure_file(
+        input: spec + '.in',
+        output: spec,
+        configuration: osinfo_db_tools_spec_data
+    )
+endforeach
+
+# ninja dist helper
+meson.add_dist_script('build-aux/dist.sh', meson.source_root())
+
+subdir('tools')
+subdir('po')
+subdir('tests')
diff --git a/po/meson.build b/po/meson.build
new file mode 100644
index 0000000..79c6233
--- /dev/null
+++ b/po/meson.build
@@ -0,0 +1,2 @@
+i18n = import('i18n')
+i18n.gettext(meson.project_name(), preset: 'glib')
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..6cf2ca8
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,21 @@
+python = import('python')
+
+python3 = python.find_installation('python3')
+if python3.found()
+    tests = {
+        'export/import test': 'test_osinfo_db_export_import.py',
+        'path test': 'test_osinfo_db_path.py',
+        'validate test': 'test_osinfo_db_validate.py'
+    }
+
+    env_vars = [
+        'abs_top_builddir=' + meson.build_root(),
+        'abs_top_srcdir=' + meson.source_root(),
+        'datadir=' + osinfo_db_tools_datadir,
+        'sysconfdir=' + osinfo_db_tools_sysconfdir
+    ]
+
+    foreach name, file: tests
+        test(name, find_program(file), env: env_vars)
+    endforeach
+endif
diff --git a/tools/meson.build b/tools/meson.build
new file mode 100644
index 0000000..d6d858b
--- /dev/null
+++ b/tools/meson.build
@@ -0,0 +1,271 @@
+# includes
+osinfo_db_tools_include = [include_directories('.')]
+
+# sources
+#  common sources
+osinfo_db_tools_common_sources = [
+    'osinfo-db-util.c',
+    'osinfo-db-util.h'
+]
+
+# dependencies
+#  glib stuff
+glib_version = '2.36'
+glib_version_info = '>= @0@'.format(glib_version)
+glib_dep = dependency('glib-2.0', version: glib_version_info)
+gio_dep = dependency('gio-2.0', version: glib_version_info)
+gobject_dep = dependency('gobject-2.0', version: glib_version_info)
+
+#  everything else
+libarchive_dep = dependency('libarchive', version: '>= 3.0.0')
+libxml_dep = dependency('libxml-2.0', version: '>= 2.6.0')
+json_glib_dep = dependency('json-glib-1.0')
+
+#  common dependencies
+osinfo_db_tools_common_dependencies = [gobject_dep, gio_dep, glib_dep]
+
+# arguments
+osinfo_db_tools_cflags = []
+
+#  glib stuff
+osinfo_db_tools_cflags += [
+    '-DGLIB_MIN_REQUIRED_VERSION="0"'.format(glib_version),
+    '-DGLIB_MAX_ALLOWED_VERSION="0"'.format(glib_version)
+]
+
+#  directories used
+osinfo_db_tools_cflags += [
+    '-DPKGDATADIR="@0@"'.format(osinfo_db_tools_pkgdatadir),
+    '-DDATA_DIR="@0@"'.format(osinfo_db_tools_datadir),
+    '-DSYSCONFDIR="@0@"'.format(osinfo_db_tools_sysconfdir),
+    '-DLOCALEDIR="@0@"'.format(osinfo_db_tools_localedir),
+]
+
+#  gettext package name
+osinfo_db_tools_cflags += ['-DGETTEXT_PACKAGE="0"'.format(meson.project_name())]
+
+#  cflags to check whether the compiler supports them or not
+osinfo_db_tools_check_cflags = [
+  '-W',
+  '-Waddress',
+  '-Waggressive-loop-optimizations',
+  '-Wall',
+  '-Warray-bounds',
+  '-Wattributes',
+  '-Wbuiltin-macro-redefined',
+  '-Wcast-align',
+  '-Wchar-subscripts',
+  '-Wclobbered',
+  '-Wcomment',
+  '-Wcomments',
+  '-Wcoverage-mismatch',
+  '-Wcpp',
+  '-Wdate-time',
+  '-Wdeprecated-declarations',
+  '-Wdisabled-optimization',
+  '-Wdiv-by-zero',
+  '-Wdouble-promotion',
+  '-Wempty-body',
+  '-Wendif-labels',
+  '-Wenum-compare',
+  '-Wextra',
+  '-Wformat-contains-nul',
+  '-Wformat-extra-args',
+  '-Wformat-security',
+  '-Wformat-y2k',
+  '-Wformat-zero-length',
+  '-Wfree-nonheap-object',
+  '-Wignored-qualifiers',
+  '-Wimplicit',
+  '-Wimplicit-function-declaration',
+  '-Wimplicit-int',
+  '-Winit-self',
+  '-Winline',
+  '-Wint-to-pointer-cast',
+  '-Winvalid-memory-model',
+  '-Winvalid-pch',
+  '-Wjump-misses-init',
+  '-Wlogical-op',
+  '-Wmain',
+  '-Wmaybe-uninitialized',
+  '-Wmissing-braces',
+  '-Wmissing-declarations',
+  '-Wmissing-field-initializers',
+  '-Wmissing-include-dirs',
+  '-Wmissing-parameter-type',
+  '-Wmissing-prototypes',
+  '-Wmultichar',
+  '-Wnarrowing',
+  '-Wnested-externs',
+  '-Wnonnull',
+  '-Wold-style-declaration',
+  '-Wold-style-definition',
+  '-Wopenmp-simd',
+  '-Woverflow',
+  '-Woverlength-strings',
+  '-Woverride-init',
+  '-Wpacked',
+  '-Wpacked-bitfield-compat',
+  '-Wparentheses',
+  '-Wpointer-arith',
+  '-Wpointer-sign',
+  '-Wpointer-to-int-cast',
+  '-Wpragmas',
+  '-Wreturn-local-addr',
+  '-Wreturn-type',
+  '-Wsequence-point',
+  '-Wshadow',
+  '-Wsizeof-pointer-memaccess',
+  '-Wstack-protector',
+  '-Wstrict-aliasing',
+  '-Wstrict-overflow',
+  '-Wstrict-prototypes',
+  '-Wsuggest-attribute=const',
+  '-Wsuggest-attribute=format',
+  '-Wsuggest-attribute=noreturn',
+  '-Wsuggest-attribute=pure',
+  '-Wswitch',
+  '-Wswitch-default',
+  '-Wsync-nand',
+  '-Wtrampolines',
+  '-Wtrigraphs',
+  '-Wtype-limits',
+  '-Wuninitialized',
+  '-Wunknown-pragmas',
+  '-Wunsafe-loop-optimizations',
+  '-Wunused',
+  '-Wunused-but-set-parameter',
+  '-Wunused-but-set-variable',
+  '-Wunused-function',
+  '-Wunused-label',
+  '-Wunused-local-typedefs',
+  '-Wunused-parameter',
+  '-Wunused-result',
+  '-Wunused-value',
+  '-Wunused-variable',
+  '-Wvarargs',
+  '-Wvariadic-macros',
+  '-Wvector-operation-performance',
+  '-Wvla',
+  '-Wvolatile-register-var',
+  '-Wwrite-strings',
+  '-Wnormalized=nfc',
+  '-Wno-sign-compare',
+  '-Wno-sign-conversion',
+  '-Wno-conversion',
+  '-Wno-unused-parameter',
+  '-Wjump-misses-init',
+  '-Wframe-larger-than=4096',
+  '-Wno-overlength-strings',
+  '-O2',
+  '-Wp,-D_FORTIFY_SOURCE=2',
+  '--param=ssp-buffer-size=4',
+  '-fexceptions',
+  '-fasynchronous-unwind-tables',
+  '-fdiagnostics-show-option',
+  '-funit-at-a-time',
+  '-fipa-pure-const',
+  '-Wno-suggest-attribute=pure',
+  '-Wno-suggest-attribute=const',
+]
+
+if host_machine.system() != 'windows'
+    osinfo_db_tools_check_cflags += ['-fstack-protector-all']
+endif
+
+compiler = meson.get_compiler('c')
+foreach cflag: osinfo_db_tools_check_cflags
+  if compiler.has_argument(cflag)
+    osinfo_db_tools_cflags += [cflag]
+  endif
+endforeach
+
+add_project_arguments(osinfo_db_tools_cflags, language: 'c')
+
+# osinfo-db-validate
+osinfo_db_validate_sources = [
+    osinfo_db_tools_common_sources,
+    'osinfo-db-validate.c'
+]
+osinfo_db_validate_dependencies = [
+    osinfo_db_tools_common_dependencies,
+    libxml_dep
+]
+executable(
+    'osinfo-db-validate',
+    sources: osinfo_db_validate_sources,
+    include_directories: osinfo_db_tools_include,
+    dependencies: osinfo_db_validate_dependencies,
+    install: true
+)
+
+# osinfo-db-import
+osinfo_db_import_sources = [
+    osinfo_db_tools_common_sources,
+    'osinfo-db-import.c'
+]
+osinfo_db_import_dependencies = [
+    osinfo_db_tools_common_dependencies,
+    json_glib_dep,
+    libarchive_dep
+]
+executable(
+    'osinfo-db-import',
+    sources: osinfo_db_import_sources,
+    include_directories: osinfo_db_tools_include,
+    dependencies: osinfo_db_import_dependencies,
+    install: true
+)
+
+# osinfo-db-export
+osinfo_db_export_sources = [
+    osinfo_db_tools_common_sources,
+    'osinfo-db-export.c'
+]
+osinfo_db_export_dependencies = [
+    osinfo_db_tools_common_dependencies,
+    libarchive_dep
+]
+executable(
+    'osinfo-db-export',
+    sources: osinfo_db_export_sources,
+    include_directories: osinfo_db_tools_include,
+    dependencies: osinfo_db_export_dependencies,
+    install: true)
+
+# osinfo-db-path
+osinfo_db_path_sources = [
+    osinfo_db_tools_common_sources,
+    'osinfo-db-path.c'
+]
+osinfo_db_path_dependencies = [osinfo_db_tools_common_dependencies]
+executable(
+    'osinfo-db-path',
+    sources: osinfo_db_path_sources,
+    include_directories: osinfo_db_tools_include,
+    dependencies: osinfo_db_path_dependencies,
+    install: true
+)
+
+# man pages
+pod2man = find_program('pod2man')
+if pod2man.found()
+    files = [
+        'osinfo-db-validate',
+        'osinfo-db-import',
+        'osinfo-db-export',
+        'osinfo-db-path'
+    ]
+
+    foreach file: files
+        custom_target(
+            file + '.1',
+            output: file + '.1',
+            input: file + '.c',
+            install: true,
+            install_dir: join_paths(osinfo_db_tools_datadir, 'man', 'man1'),
+            build_by_default: true,
+            command: [pod2man, '-c', 'Osinfo DB Tools', '@INPUT@', '@OUTPUT@']
+        )
+    endforeach
+endif
-- 
2.21.0




More information about the Libosinfo mailing list