build-sys: Add --enable-code-generator

This flag is only used for git builds, and can usually safely be
disabled.
When it's enabled, configure.ac will check that python-six and pyparsing
are available, and will use these together with the codegen python
scripts in order to automatically regenerate enums.h when the .proto
files change.
This commit is contained in:
Christophe Fergeau 2015-07-06 18:18:55 +02:00
parent eb2e8ba0e8
commit 2b9d15c1d3
3 changed files with 41 additions and 1 deletions

View File

@ -11,7 +11,7 @@ test -z "$srcdir" && srcdir=.
autoreconf --verbose --force --install
)
CONFIGURE_ARGS="--enable-maintainer-mode"
CONFIGURE_ARGS="--enable-maintainer-mode --enable-code-generator"
if [ -z "$NOCONFIGURE" ]; then
echo "Running configure with $CONFIGURE_ARGS $@"

View File

@ -14,6 +14,22 @@ AM_MAINTAINER_MODE
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
dnl Enable generation of enums.h, mainly useful when building from git,
dnl should not be needed for tarball users
AC_ARG_ENABLE([code-generator],
AS_HELP_STRING([--enable-code-generator=@<:@yes/no/auto@:>@],
[Enable checks needed to use the Python code generator @<:@default=auto@:>@]),
[],
[enable_code_generator="auto"])
if test "x$enable_code_generator" != "xno"; then
AS_IF([test "x$enable_code_generator" = "xyes"], modules_required=[1], modules_required=[])
AX_PYTHON_MODULE([six], $modules_required)
AX_PYTHON_MODULE([pyparsing], $modules_required)
AS_IF([test "x${HAVE_PYMOD_SIX}" = "xno"], enable_code_generator="no")
AS_IF([test "x${HAVE_PYMOD_PYPARSING}" = "xno"], enable_code_generator="no")
fi
AM_CONDITIONAL([ENABLE_CODEGEN], [test "x$enable_code_generator" != "xno"])
AC_OUTPUT([
Makefile
spice-protocol.pc

View File

@ -21,4 +21,28 @@ spice_protocol_include_HEADERS = \
vdi_dev.h \
$(NULL)
# Using the python code generator requires some python modules
# which might not be installed on the user computer. Given that
# enums.h is stored in git, and should be up-to-date anyway,
# we can make this part optional
if ENABLE_CODEGEN
MARSHALLERS_DEPS = \
$(top_srcdir)/python_modules/__init__.py \
$(top_srcdir)/python_modules/codegen.py \
$(top_srcdir)/python_modules/demarshal.py \
$(top_srcdir)/python_modules/marshal.py \
$(top_srcdir)/python_modules/ptypes.py \
$(top_srcdir)/python_modules/spice_parser.py \
$(top_srcdir)/spice_codegen.py \
$(NULL)
BUILT_SOURCES = enums.h
# this is going to upset automake distcheck, since we try to write to
# readonly srcdir. To limit the fail chances, rebuild automatically
# enums.h only if the spice.proto has changed.
enums.h: $(top_srcdir)/spice.proto # $(MARSHALLERS_DEPS)
$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-enums $< $@ >/dev/null
endif
-include $(top_srcdir)/git.mk