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 <thuth@redhat.com>
Message-Id: <20211007130829.632254-18-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2021-10-07 15:08:28 +02:00
parent 03a3c0b3c5
commit 61d63097be
4 changed files with 106 additions and 10 deletions

View File

@ -87,7 +87,7 @@ x := $(shell rm -rf meson-private meson-info meson-logs)
endif endif
# 1. ensure config-host.mak is up-to-date # 1. ensure config-host.mak is up-to-date
config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/scripts/meson-buildoptions.sh $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
@echo config-host.mak is out-of-date, running configure @echo config-host.mak is out-of-date, running configure
@if test -f meson-private/coredata.dat; then \ @if test -f meson-private/coredata.dat; then \
./config.status --skip-meson; \ ./config.status --skip-meson; \
@ -124,6 +124,12 @@ ifneq ($(MESON),)
Makefile.mtest: build.ninja scripts/mtest2make.py Makefile.mtest: build.ninja scripts/mtest2make.py
$(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@ $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
-include Makefile.mtest -include Makefile.mtest
.PHONY: update-buildoptions
all update-buildoptions: $(SRC_PATH)/scripts/meson-buildoptions.sh
$(SRC_PATH)/scripts/meson-buildoptions.sh: $(SRC_PATH)/meson_options.txt
$(MESON) introspect --buildoptions $(SRC_PATH)/meson.build | $(PYTHON) \
scripts/meson-buildoptions.py > $@.tmp && mv $@.tmp $@
endif endif
# 4. Rules to bridge to other makefiles # 4. Rules to bridge to other makefiles

31
configure vendored
View File

@ -789,6 +789,18 @@ fi
werror="" werror=""
. $source_path/scripts/meson-buildoptions.sh
meson_options=
meson_option_parse() {
meson_options="$meson_options $(_meson_option_parse "$@")"
if test $? -eq 1; then
echo "ERROR: unknown option $1"
echo "Try '$0 --help' for more information"
exit 1
fi
}
for opt do for opt do
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
case "$opt" in case "$opt" in
@ -1548,6 +1560,8 @@ for opt do
;; ;;
--disable-slirp-smbd) slirp_smbd=no --disable-slirp-smbd) slirp_smbd=no
;; ;;
--enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
;;
*) *)
echo "ERROR: unknown option $opt" echo "ERROR: unknown option $opt"
echo "Try '$0 --help' for more information" echo "Try '$0 --help' for more information"
@ -1804,11 +1818,9 @@ Advanced options (experts only):
enable plugins via shared library loading enable plugins via shared library loading
--disable-containers don't use containers for cross-building --disable-containers don't use containers for cross-building
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin] --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
EOF
Optional features, enabled with --enable-FEATURE and meson_options_help
disabled with --disable-FEATURE, default is enabled if available cat << EOF
(unless built with --without-default-features):
system all system emulation targets system all system emulation targets
user supported user emulation targets user supported user emulation targets
linux-user all linux usermode emulation targets linux-user all linux usermode emulation targets
@ -4489,7 +4501,8 @@ if test "$skip_meson" = no; then
mv $cross config-meson.cross mv $cross config-meson.cross
rm -rf meson-private meson-info meson-logs rm -rf meson-private meson-info meson-logs
NINJA=$ninja $meson setup \ run_meson() {
NINJA=$ninja $meson setup \
--prefix "$prefix" \ --prefix "$prefix" \
--libdir "$libdir" \ --libdir "$libdir" \
--libexecdir "$libexecdir" \ --libexecdir "$libexecdir" \
@ -4534,9 +4547,9 @@ if test "$skip_meson" = no; then
-Dpa=$pa -Daudio_drv_list=$audio_drv_list -Dtcg_interpreter=$tcg_interpreter \ -Dpa=$pa -Daudio_drv_list=$audio_drv_list -Dtcg_interpreter=$tcg_interpreter \
-Dtrace_backends=$trace_backends -Dtrace_file=$trace_file -Dlinux_aio=$linux_aio \ -Dtrace_backends=$trace_backends -Dtrace_file=$trace_file -Dlinux_aio=$linux_aio \
-Dnetmap=$netmap -Dvde=$vde \ -Dnetmap=$netmap -Dvde=$vde \
$cross_arg \ "$@" $cross_arg "$PWD" "$source_path"
"$PWD" "$source_path" }
eval run_meson $meson_options
if test "$?" -ne 0 ; then if test "$?" -ne 0 ; then
error_exit "meson setup failed" error_exit "meson setup failed"
fi fi

64
scripts/meson-buildoptions.py Executable file
View File

@ -0,0 +1,64 @@
#! /usr/bin/env python3
# Generate configure command line options handling code, based on Meson's
# user build options introspection data
#
# Copyright (C) 2021 Red Hat, Inc.
#
# Author: Paolo Bonzini <pbonzini@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
import textwrap
import shlex
import sys
def sh_print(line=""):
print(' printf "%s\\n"', shlex.quote(line))
def load_options(json):
json = [
x
for x in json
if x["section"] == "user"
and ":" not in x["name"]
and x["name"] not in SKIP_OPTIONS
]
return sorted(json, key=lambda x: x["name"])
def print_help(options):
print("meson_options_help() {")
sh_print()
sh_print("Optional features, enabled with --enable-FEATURE and")
sh_print("disabled with --disable-FEATURE, default is enabled if available")
sh_print("(unless built with --without-default-features):")
sh_print()
print("}")
def print_parse(options):
print("_meson_option_parse() {")
print(" case $1 in")
print(" *) return 1 ;;")
print(" esac")
print("}")
options = load_options(json.load(sys.stdin))
print("# This file is generated by meson-buildoptions.py, do not edit!")
print_help(options)
print_parse(options)

View File

@ -0,0 +1,13 @@
# This file is generated by meson-buildoptions.py, do not edit!
meson_options_help() {
printf "%s\n" ''
printf "%s\n" 'Optional features, enabled with --enable-FEATURE and'
printf "%s\n" 'disabled with --disable-FEATURE, default is enabled if available'
printf "%s\n" '(unless built with --without-default-features):'
printf "%s\n" ''
}
_meson_option_parse() {
case $1 in
*) return 1 ;;
esac
}