From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> The meson build system allows projects to "vendor" dtc easily, thanks to subproject(). We have plans to switch qemu to meson (see https://wiki.qemu.org/Features/Meson), and this would help to handle dtc submodule. meson rules are arguably simpler to write and maintain than the hand-crafted/custom Makefile. meson support various backends, and default build options (including coverage, sanitizer, debug/release etc, see: https://mesonbuild.com/Builtin-options.html) Compare to the Makefiles, the same build targets should be built and installed and the same tests should be run ("meson test" can be provided extra test arguments for running checkm/checkv). There is no support EXTRAVERSION/LOCAL_VERSION/CONFIG_LOCALVERSION, instead the version is simply set with project(), and vcs_tag() is used for git/dirty version reporting (This is most common and is hopefully enough. If necessary, configure-time options could be added for extra versioning.). libfdt shared library is build following regular naming conventions: instead of libfdt.so.1 -> libfdt-1.5.0.so (with current build-sys), libfdt.so.1 -> libfdt.so.1.5.0. I am not sure why the current build system use an uncommon naming pattern. Both Linux native build and mingw cross-build pass. CI pass. Tests are only run on native build. The current Makefiles are left in-tree, and make/check still work. Eventually, the Makefiles could be marked as deprecated, to start a transition period and avoid having to maintain 2 build systems in the near future. run_tests.sh could eventually be replaced by the meson test runner, which would have several advantages in term of flexibility/features, but this is left for another day. Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> --- libfdt/meson.build | 38 ++++++++++++++ meson.build | 116 +++++++++++++++++++++++++++++++++++++++++ pylibfdt/meson.build | 21 ++++++++ tests/meson.build | 120 +++++++++++++++++++++++++++++++++++++++++++ version_gen.h.in | 1 + 5 files changed, 296 insertions(+) create mode 100644 libfdt/meson.build create mode 100644 meson.build create mode 100644 pylibfdt/meson.build create mode 100644 tests/meson.build create mode 100644 version_gen.h.in diff --git a/libfdt/meson.build b/libfdt/meson.build new file mode 100644 index 0000000..14d8bd5 --- /dev/null +++ b/libfdt/meson.build @@ -0,0 +1,38 @@ +version_script = '-Wl,--version-script=@0@'.format(meson.current_source_dir() / 'version.lds') +if not cc.has_link_argument(version_script) + version_script = [] +endif + +libfdt = library( + 'fdt', + files( + 'fdt.c', + 'fdt_addresses.c', + 'fdt_empty_tree.c', + 'fdt_overlay.c', + 'fdt_ro.c', + 'fdt_rw.c', + 'fdt_strerror.c', + 'fdt_sw.c', + 'fdt_wip.c', + ), + version: '1.5.0', + link_args: ['-Wl,--no-undefined', version_script], + link_depends: 'version.lds', + install: true, +) + +libfdt_inc = include_directories('.') + +libfdt_dep = declare_dependency( + include_directories: libfdt_inc, + link_with: libfdt, +) + +install_headers( + files( + 'fdt.h', + 'libfdt.h', + 'libfdt_env.h', + ) +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..e2c5eec --- /dev/null +++ b/meson.build @@ -0,0 +1,116 @@ +project('dtc', 'c', + version: '1.5.0', + license: ['GPL2+', 'BSD-2'], + default_options: 'werror=true', +) + +cc = meson.get_compiler('c') + +foreach w: [ + '-Wall', + '-Wpointer-arith', + '-Wcast-qual', + '-Wnested-externs', + '-Wstrict-prototypes', + '-Wmissing-prototypes', + '-Wredundant-decls', + '-Wshadow' +] + if cc.has_argument(w) + add_project_arguments(w, language: 'c') + endif +endforeach + +if host_machine.system() == 'windows' + add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: 'c') +endif + +yamltree = 'yamltree.c' +yaml = dependency('yaml-0.1', required: false) +if not yaml.found() + add_project_arguments('-DNO_YAML', language: 'c') + yamltree = [] +endif + +valgrind = dependency('valgrind', required: false) +if not valgrind.found() + add_project_arguments('-DNO_VALGRIND', language: 'c') +endif + +flex = find_program('flex', required: false) +bison = find_program('bison', required: false) + +lgen = generator( + flex, + output: '@PLAINNAME@.lex.c', + arguments : ['-o', '@OUTPUT@', '@INPUT@'], +) + +pgen = generator( + bison, + output: ['@BASENAME@.tab.c', '@BASENAME@.tab.h'], + arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@'], +) + +py = import('python') +py = py.find_installation(required: false) + +version_gen_h = vcs_tag( + input: 'version_gen.h.in', + output: 'version_gen.h', +) + +subdir('libfdt') + +util_dep = declare_dependency( + sources: ['util.c', version_gen_h], + include_directories: '.', + dependencies: libfdt_dep +) + +if cc.check_header('fnmatch.h') + executable( + 'convert-dtsv0', + [ + lgen.process('convert-dtsv0-lexer.l'), + 'srcpos.c', + ], + dependencies: util_dep, + install: true, + ) +endif + +executable( + 'dtc', + [ + lgen.process('dtc-lexer.l'), + pgen.process('dtc-parser.y'), + 'checks.c', + 'data.c', + 'dtc.c', + 'flattree.c', + 'fstree.c', + 'livetree.c', + 'srcpos.c', + 'treesource.c', + yamltree, + ], + dependencies: [util_dep, yaml], + install: true, +) + +foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay'] + executable(e, files(e + '.c'), dependencies: util_dep, install: true) +endforeach + +install_data( + 'dtdiff', + install_dir: get_option('prefix') / get_option('bindir'), + install_mode: 'rwxr-xr-x', +) + +subdir('pylibfdt') + +if not meson.is_cross_build() + subdir('tests') +endif diff --git a/pylibfdt/meson.build b/pylibfdt/meson.build new file mode 100644 index 0000000..0ab0cc7 --- /dev/null +++ b/pylibfdt/meson.build @@ -0,0 +1,21 @@ +swig = find_program('swig', required: false) + +if py.found() and swig.found() + custom_target( + 'pylibfdt', + input: 'libfdt.i', + output: '_libfdt.so', + depends: version_gen_h, + command: [ + py, + files('setup.py'), + '--quiet', + 'build_ext', + '--build-lib=' + meson.current_build_dir(), + ], + build_by_default: true) + + meson.add_install_script('setup.py', 'install', '--prefix=' + get_option('prefix'), '--root=$DESTDIR') +else + message('Missing dependencies to build pylibfdt, skipped') +endif diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..7104262 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,120 @@ +trees = static_library('trees', files('trees.S'), c_args: '-D__ASSEMBLY__', + include_directories: libfdt_inc) + +dumptrees = executable('dumptrees', files('dumptrees.c'), + link_with: trees, dependencies: libfdt_dep) + +dumptrees_dtb = custom_target( + 'dumptrees', + command: [dumptrees, meson.current_build_dir()], + output: [ + 'test_tree1.dtb', + 'bad_node_char.dtb', + 'bad_node_format.dtb', + 'bad_prop_char.dtb', + 'ovf_size_strings.dtb', + 'truncated_property.dtb', + 'truncated_string.dtb', + 'truncated_memrsv.dtb', + ] +) + +testutil_dep = declare_dependency(sources: ['testutils.c'], link_with: trees) + +tests = [ + 'add_subnode_with_nops', + 'addr_size_cells', + 'addr_size_cells2', + 'appendprop1', + 'appendprop2', + 'appendprop_addrrange', + 'boot-cpuid', + 'char_literal', + 'check_full', + 'check_header', + 'check_path', + 'del_node', + 'del_property', + 'dtb_reverse', + 'dtbs_equal_ordered', + 'dtbs_equal_unordered', + 'extra-terminating-null', + 'find_property', + 'fs_tree1', + 'get_alias', + 'get_mem_rsv', + 'get_name', + 'get_path', + 'get_phandle', + 'get_prop_offset', + 'getprop', + 'incbin', + 'integer-expressions', + 'mangle-layout', + 'move_and_save', + 'node_check_compatible', + 'node_offset_by_compatible', + 'node_offset_by_phandle', + 'node_offset_by_prop_value', + 'nop_node', + 'nop_property', + 'nopulate', + 'notfound', + 'open_pack', + 'overlay', + 'overlay_bad_fixup', + 'parent_offset', + 'path-references', + 'path_offset', + 'path_offset_aliases', + 'phandle_format', + 'property_iterate', + 'propname_escapes', + 'references', + 'root_node', + 'rw_oom', + 'rw_tree1', + 'set_name', + 'setprop', + 'setprop_inplace', + 'sized_cells', + 'string_escapes', + 'stringlist', + 'subnode_iterate', + 'subnode_offset', + 'supernode_atdepth_offset', + 'sw_states', + 'sw_tree1', + 'utilfdt_test', +] + +tests += [ + 'truncated_memrsv', + 'truncated_property', + 'truncated_string', +] + +dl = cc.find_library('dl', required: false) +if dl.found() + tests += [ + 'asm_tree_dump', + 'value-labels', + ] +endif + +foreach t: tests + executable(t, files(t + '.c'), dependencies: [testutil_dep, util_dep, libfdt_dep, dl]) +endforeach + +run_tests = find_program('run_tests.sh') + +test( + 'run-test', + run_tests, + workdir: meson.current_build_dir(), + depends: dumptrees_dtb, + env: [ + 'PYTHON=' + py.path(), + 'PYTHONPATH=' + meson.source_root() / 'pylibfdt', + ] +) diff --git a/version_gen.h.in b/version_gen.h.in new file mode 100644 index 0000000..7771abb --- /dev/null +++ b/version_gen.h.in @@ -0,0 +1 @@ +#define DTC_VERSION "DTC @VCS_TAG@" -- 2.23.0