Skip to content

Commit 61d6309

Browse files
committed
configure: prepare for auto-generated option parsing
Prepare the configure script and Makefile for automatically generated help and parsing. Because we need to run the script to generate the full help, we cannot rely on the user supplying the path to a Python interpreter with --python; therefore, the introspection output is parsed into shell functions and stored in scripts/. The converter is written in Python as standard for QEMU, and this commit contains a stub. Tested-by: Thomas Huth <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 03a3c0b commit 61d6309

File tree

4 files changed

+106
-10
lines changed

4 files changed

+106
-10
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ x := $(shell rm -rf meson-private meson-info meson-logs)
8787
endif
8888

8989
# 1. ensure config-host.mak is up-to-date
90-
config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
90+
config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/scripts/meson-buildoptions.sh $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
9191
@echo config-host.mak is out-of-date, running configure
9292
@if test -f meson-private/coredata.dat; then \
9393
./config.status --skip-meson; \
@@ -124,6 +124,12 @@ ifneq ($(MESON),)
124124
Makefile.mtest: build.ninja scripts/mtest2make.py
125125
$(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
126126
-include Makefile.mtest
127+
128+
.PHONY: update-buildoptions
129+
all update-buildoptions: $(SRC_PATH)/scripts/meson-buildoptions.sh
130+
$(SRC_PATH)/scripts/meson-buildoptions.sh: $(SRC_PATH)/meson_options.txt
131+
$(MESON) introspect --buildoptions $(SRC_PATH)/meson.build | $(PYTHON) \
132+
scripts/meson-buildoptions.py > $@.tmp && mv $@.tmp $@
127133
endif
128134

129135
# 4. Rules to bridge to other makefiles

configure

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,18 @@ fi
789789

790790
werror=""
791791

792+
. $source_path/scripts/meson-buildoptions.sh
793+
794+
meson_options=
795+
meson_option_parse() {
796+
meson_options="$meson_options $(_meson_option_parse "$@")"
797+
if test $? -eq 1; then
798+
echo "ERROR: unknown option $1"
799+
echo "Try '$0 --help' for more information"
800+
exit 1
801+
fi
802+
}
803+
792804
for opt do
793805
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
794806
case "$opt" in
@@ -1548,6 +1560,8 @@ for opt do
15481560
;;
15491561
--disable-slirp-smbd) slirp_smbd=no
15501562
;;
1563+
--enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
1564+
;;
15511565
*)
15521566
echo "ERROR: unknown option $opt"
15531567
echo "Try '$0 --help' for more information"
@@ -1804,11 +1818,9 @@ Advanced options (experts only):
18041818
enable plugins via shared library loading
18051819
--disable-containers don't use containers for cross-building
18061820
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
1807-
1808-
Optional features, enabled with --enable-FEATURE and
1809-
disabled with --disable-FEATURE, default is enabled if available
1810-
(unless built with --without-default-features):
1811-
1821+
EOF
1822+
meson_options_help
1823+
cat << EOF
18121824
system all system emulation targets
18131825
user supported user emulation targets
18141826
linux-user all linux usermode emulation targets
@@ -4489,7 +4501,8 @@ if test "$skip_meson" = no; then
44894501
mv $cross config-meson.cross
44904502

44914503
rm -rf meson-private meson-info meson-logs
4492-
NINJA=$ninja $meson setup \
4504+
run_meson() {
4505+
NINJA=$ninja $meson setup \
44934506
--prefix "$prefix" \
44944507
--libdir "$libdir" \
44954508
--libexecdir "$libexecdir" \
@@ -4534,9 +4547,9 @@ if test "$skip_meson" = no; then
45344547
-Dpa=$pa -Daudio_drv_list=$audio_drv_list -Dtcg_interpreter=$tcg_interpreter \
45354548
-Dtrace_backends=$trace_backends -Dtrace_file=$trace_file -Dlinux_aio=$linux_aio \
45364549
-Dnetmap=$netmap -Dvde=$vde \
4537-
$cross_arg \
4538-
"$PWD" "$source_path"
4539-
4550+
"$@" $cross_arg "$PWD" "$source_path"
4551+
}
4552+
eval run_meson $meson_options
45404553
if test "$?" -ne 0 ; then
45414554
error_exit "meson setup failed"
45424555
fi

scripts/meson-buildoptions.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#! /usr/bin/env python3
2+
3+
# Generate configure command line options handling code, based on Meson's
4+
# user build options introspection data
5+
#
6+
# Copyright (C) 2021 Red Hat, Inc.
7+
#
8+
# Author: Paolo Bonzini <[email protected]>
9+
#
10+
# This program is free software; you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation; either version 2, or (at your option)
13+
# any later version.
14+
#
15+
# This program is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
23+
import json
24+
import textwrap
25+
import shlex
26+
import sys
27+
28+
def sh_print(line=""):
29+
print(' printf "%s\\n"', shlex.quote(line))
30+
31+
32+
def load_options(json):
33+
json = [
34+
x
35+
for x in json
36+
if x["section"] == "user"
37+
and ":" not in x["name"]
38+
and x["name"] not in SKIP_OPTIONS
39+
]
40+
return sorted(json, key=lambda x: x["name"])
41+
42+
43+
def print_help(options):
44+
print("meson_options_help() {")
45+
sh_print()
46+
sh_print("Optional features, enabled with --enable-FEATURE and")
47+
sh_print("disabled with --disable-FEATURE, default is enabled if available")
48+
sh_print("(unless built with --without-default-features):")
49+
sh_print()
50+
print("}")
51+
52+
53+
def print_parse(options):
54+
print("_meson_option_parse() {")
55+
print(" case $1 in")
56+
print(" *) return 1 ;;")
57+
print(" esac")
58+
print("}")
59+
60+
61+
options = load_options(json.load(sys.stdin))
62+
print("# This file is generated by meson-buildoptions.py, do not edit!")
63+
print_help(options)
64+
print_parse(options)

scripts/meson-buildoptions.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is generated by meson-buildoptions.py, do not edit!
2+
meson_options_help() {
3+
printf "%s\n" ''
4+
printf "%s\n" 'Optional features, enabled with --enable-FEATURE and'
5+
printf "%s\n" 'disabled with --disable-FEATURE, default is enabled if available'
6+
printf "%s\n" '(unless built with --without-default-features):'
7+
printf "%s\n" ''
8+
}
9+
_meson_option_parse() {
10+
case $1 in
11+
*) return 1 ;;
12+
esac
13+
}

0 commit comments

Comments
 (0)