The next patch relies on dtc for boards with a bundled DTB. These boards
depend on libfdt already. Make sure that there is a dtc iff libfdt is used
such that the DTBs can be generated.

Co-developed-by: Paolo Bonzini <pbonz...@redhat.com>
Signed-off-by: Bernhard Beschow <shen...@gmail.com>
---
 meson.build                                   | 16 +++--
 pc-bios/dtb/meson.build                       |  1 -
 subprojects/dtc.wrap                          |  1 +
 .../packagefiles/dtc-meson-override.patch     | 62 +++++++++++++++++++
 4 files changed, 75 insertions(+), 5 deletions(-)
 create mode 100644 subprojects/packagefiles/dtc-meson-override.patch

diff --git a/meson.build b/meson.build
index b5f74aa37a..2963789033 100644
--- a/meson.build
+++ b/meson.build
@@ -2089,13 +2089,15 @@ if numa.found() and not cc.links('''
 endif
 
 fdt = not_found
+dtc = not_found
 fdt_opt = get_option('fdt')
 if fdt_opt == 'enabled' and get_option('wrap_mode') == 'nodownload'
   fdt_opt = 'system'
 endif
 if fdt_opt in ['enabled', 'system'] or (fdt_opt == 'auto' and have_system)
   fdt = cc.find_library('fdt', required: fdt_opt == 'system')
-  if fdt.found() and cc.links('''
+  dtc = find_program('dtc', required: fdt_opt == 'system')
+  if dtc.found() and fdt.found() and cc.links('''
      #include <libfdt.h>
      #include <libfdt_env.h>
      int main(void) { fdt_find_max_phandle(NULL, NULL); return 0; }''',
@@ -2104,16 +2106,22 @@ if fdt_opt in ['enabled', 'system'] or (fdt_opt == 
'auto' and have_system)
   elif fdt_opt != 'system'
     fdt_opt = get_option('wrap_mode') == 'nodownload' ? 'disabled' : 'internal'
     fdt = not_found
+    dtc = not_found
   else
-    error('system libfdt is too old (1.5.1 or newer required)')
+    if dtc.found()
+      error('system libfdt is too old (1.5.1 or newer required)')
+    else
+      error('device tree compiler not found')
+    endif
   endif
 endif
 if fdt_opt == 'internal'
   assert(not fdt.found())
   libfdt_proj = subproject('dtc', required: true,
-                           default_options: ['tools=false',  'yaml=disabled',
+                           default_options: ['tools=true',  'yaml=disabled',
                                              'python=disabled', 
'default_library=static'])
-  fdt = libfdt_proj.get_variable('libfdt_dep')
+  fdt = dependency('libfdt', required: true)
+  dtc = find_program('dtc', required: true)
 endif
 
 rdma = not_found
diff --git a/pc-bios/dtb/meson.build b/pc-bios/dtb/meson.build
index 993032949f..9fcdbeff14 100644
--- a/pc-bios/dtb/meson.build
+++ b/pc-bios/dtb/meson.build
@@ -5,7 +5,6 @@ dtbs = [
   'petalogix-s3adsp1800.dtb',
 ]
 
-dtc = find_program('dtc', required: false)
 if dtc.found()
   foreach out : dtbs
     f = fs.replace_suffix(out, '.dts')
diff --git a/subprojects/dtc.wrap b/subprojects/dtc.wrap
index d1bc9174e9..347ca61ea6 100644
--- a/subprojects/dtc.wrap
+++ b/subprojects/dtc.wrap
@@ -2,3 +2,4 @@
 url = https://gitlab.com/qemu-project/dtc.git
 revision = b6910bec11614980a21e46fbccc35934b671bd81
 depth = 1
+diff_files = dtc-meson-override.patch
diff --git a/subprojects/packagefiles/dtc-meson-override.patch 
b/subprojects/packagefiles/dtc-meson-override.patch
new file mode 100644
index 0000000000..9dd8cf85a7
--- /dev/null
+++ b/subprojects/packagefiles/dtc-meson-override.patch
@@ -0,0 +1,62 @@
+diff --git a/libfdt/meson.build b/libfdt/meson.build
+index 0307ffb..6581965 100644
+--- a/libfdt/meson.build
++++ b/libfdt/meson.build
+@@ -30,6 +30,7 @@ libfdt_dep = declare_dependency(
+   include_directories: libfdt_inc,
+   link_with: libfdt,
+ )
++meson.override_dependency('libfdt', libfdt_dep)
+ 
+ install_headers(
+   files(
+diff --git a/meson.build b/meson.build
+index b23ea1b..7def0a6 100644
+--- a/meson.build
++++ b/meson.build
+@@ -54,6 +54,7 @@ version_gen_h = vcs_tag(
+ 
+ subdir('libfdt')
+ 
++dtc_tools = []
+ if get_option('tools')
+   flex = find_program('flex', required: true)
+   bison = find_program('bison', required: true)
+@@ -77,7 +78,7 @@ if get_option('tools')
+   )
+ 
+   if cc.check_header('fnmatch.h')
+-    executable(
++    dtc_tools += executable(
+       'convert-dtsv0',
+       [
+         lgen.process('convert-dtsv0-lexer.l'),
+@@ -88,7 +89,7 @@ if get_option('tools')
+     )
+   endif
+ 
+-  executable(
++  dtc_tools += executable(
+     'dtc',
+     [
+       lgen.process('dtc-lexer.l'),
+@@ -108,7 +109,7 @@ if get_option('tools')
+   )
+ 
+   foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay']
+-    executable(e, files(e + '.c'), dependencies: util_dep, install: true)
++    dtc_tools += executable(e, files(e + '.c'), dependencies: util_dep, 
install: true)
+   endforeach
+ 
+   install_data(
+@@ -118,6 +119,10 @@ if get_option('tools')
+   )
+ endif
+ 
++foreach e: dtc_tools
++  meson.override_find_program(e.name(), e)
++endforeach
++
+ if not meson.is_cross_build()
+   if py.found() and swig.found()
+     subdir('pylibfdt')
-- 
2.50.0


Reply via email to