qemu add new option

示例如下:

diff --git a/holyshit/meson.build b/holyshit/meson.build
new file mode 100644
index 0000000000..f0d07d0c87
--- /dev/null
+++ b/holyshit/meson.build
@@ -0,0 +1,3 @@
+i386_ss.add(files(
+  'shit.c'
+))
diff --git a/holyshit/shit.c b/holyshit/shit.c
new file mode 100644
index 0000000000..769694400a
--- /dev/null
+++ b/holyshit/shit.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+#include "shit.h"
+
+void shit(void) {
+    printf("shit\n");
+}
diff --git a/holyshit/shit.h b/holyshit/shit.h
new file mode 100644
index 0000000000..1956460a30
--- /dev/null
+++ b/holyshit/shit.h
@@ -0,0 +1,10 @@
+//
+// Created by runsisi on 6/12/23.
+//
+
+#ifndef QEMU_SHIT_H
+#define QEMU_SHIT_H
+
+void shit(void);
+
+#endif //QEMU_SHIT_H
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index a88a126123..4513bdc6e6 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -63,6 +63,8 @@
 #include "hw/i386/kvm/xen_evtchn.h"
 #endif
 
+#include "holyshit/shit.h"
+
 /* Physical Address of PVH entry point read from kernel ELF NOTE */
 static size_t pvh_start_addr;
 
@@ -97,6 +99,8 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
 
 void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)
 {
+//#error test compiling reaches here ---
+    shit();
     Object *cpu = object_new(MACHINE(x86ms)->cpu_type);
 
     if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) {
diff --git a/meson.build b/meson.build
index 34306a6205..4e553570fb 100644
--- a/meson.build
+++ b/meson.build
@@ -3326,6 +3326,11 @@ subdir('ui')
 subdir('hw')
 subdir('gdbstub')
 
+
+if get_option('shit')
+    subdir('holyshit')
+endif
+
 if enable_modules
   libmodulecommon = static_library('module-common', files('module-common.c') + genh, pic: true, c_args: '-DBUILD_DSO')
   modulecommon = declare_dependency(link_whole: libmodulecommon, compile_args: '-DBUILD_DSO')
diff --git a/meson_options.txt b/meson_options.txt
index 90237389e2..3a31f2641b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -39,6 +39,9 @@ option('coroutine_backend', type: 'combo',
 # on the configure script command line.  After adding an option
 # here make sure to run "make update-buildoptions".
 
+option('shit', type : 'boolean', value: false,
+       description: 'build holyshit')
+
 option('docs', type : 'feature', value : 'auto',
        description: 'Documentations build support')
 option('fuzzing', type : 'boolean', value: false,
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 5714fd93d9..2497b1d311 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -45,6 +45,7 @@ meson_options_help() {
   printf "%s\n" '  --enable-safe-stack      SafeStack Stack Smash Protection (requires'
   printf "%s\n" '                           clang/llvm and coroutine backend ucontext)'
   printf "%s\n" '  --enable-sanitizers      enable default sanitizers'
+  printf "%s\n" '  --enable-shit            build holyshit'
   printf "%s\n" '  --enable-strip           Strip targets on install'
   printf "%s\n" '  --enable-tcg-interpreter TCG with bytecode interpreter (slow)'
   printf "%s\n" '  --enable-trace-backends=CHOICES'
@@ -434,6 +435,8 @@ _meson_option_parse() {
     --disable-seccomp) printf "%s" -Dseccomp=disabled ;;
     --enable-selinux) printf "%s" -Dselinux=enabled ;;
     --disable-selinux) printf "%s" -Dselinux=disabled ;;
+    --enable-shit) printf "%s" -Dshit=true ;;
+    --disable-shit) printf "%s" -Dshit=false ;;
     --enable-slirp) printf "%s" -Dslirp=enabled ;;
     --disable-slirp) printf "%s" -Dslirp=disabled ;;
     --enable-slirp-smbd) printf "%s" -Dslirp_smbd=enabled ;;

其中 meson-buildoptions.sh 这个文件的修改是 make update-buildoptions 得到的,在 meson_options.txt 中增加的选项要通过 make update-buildoptions 最终在 meson-buildoptions.sh 中体现,然后就可以 ../configure --enable-shit 这样用了。

注意,能执行 make update-buildoptions 的前提是之前已经 configure 过一次了,否则 makefile 都没有,没法执行。

make update-buildoptions 会调用 scripts/meson-buildoptions.py 更新 meson-buildoptions.sh

configure: automatically parse command line for meson -D options
https://github.com/qemu/qemu/commit/3b4da13293482134b81d71be656ec76beff73a76


最后修改于 2023-06-17