1--- meson.build.orig	2024-04-24 10:56:15.000000000 -0400
2+++ meson.build	2024-05-24 09:42:59.912987000 -0400
3@@ -46,8 +46,8 @@
4 genh = []
5 qapi_trace_events = []
6
7-bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
8-supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
9+bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin', 'midnightbsd']
10+supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux', 'midnightbsd']
11 supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv', 'x86', 'x86_64',
12   'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
13
14@@ -75,7 +75,7 @@
15   .allowed()
16 have_ga = get_option('guest_agent') \
17   .disable_auto_if(not have_system and not have_tools) \
18-  .require(targetos in ['sunos', 'linux', 'windows', 'freebsd'],
19+  .require(targetos in ['sunos', 'linux', 'windows', 'freebsd', 'midnightbsd'],
20            error_message: 'unsupported OS for QEMU guest agent') \
21   .allowed()
22 have_block = have_system or have_tools
23@@ -2717,14 +2717,10 @@
24   fdt_opt = get_option('fdt')
25   if fdt_opt in ['enabled', 'auto', 'system']
26     have_internal = fs.exists(meson.current_source_dir() / 'dtc/libfdt/Makefile.libfdt')
27-    fdt = cc.find_library('fdt', kwargs: static_kwargs,
28+    fdt = cc.find_library('fdt', kwargs: static_kwargs, dirs: '/usr/local/lib/',
29                           required: fdt_opt == 'system' or
30-                                    fdt_opt == 'enabled' and not have_internal)
31-    if fdt.found() and cc.links('''
32-       #include <libfdt.h>
33-       #include <libfdt_env.h>
34-       int main(void) { fdt_find_max_phandle(NULL, NULL); return 0; }''',
35-         dependencies: fdt)
36+                                    fdt_opt == 'enabled')
37+    if fdt.found()
38       fdt_opt = 'system'
39     elif fdt_opt == 'system'
40        error('system libfdt requested, but it is too old (1.5.1 or newer required)')
41