On 6/12/25 07:12, Paolo Bonzini wrote:
I'll send a patch to the upstream dtc project and you can add it to QEMU via diff_files (see commit 64644bc4eab2f for an example).
This is the patch, backported to QEMU's version of the dtc subproject:

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')


and this is how you can then find dtc in QEMU's meson.build:

diff --git a/meson.build b/meson.build
index 61595015802..831678b4580 100644
--- a/meson.build
+++ b/meson.build
@@ -2121,13 +2121,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; }''',
@@ -2136,8 +2138,12 @@ 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
 if fdt_opt == 'internal'
@@ -2145,7 +2148,8 @@ if fdt_opt == 'internal'
   libfdt_proj = subproject('dtc', required: true,
                            default_options: ['tools=false',  '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


Reply via email to