I'll take as example the Autotools, if you are using a different tool-chain you can surely adapt it. The idea is simple, the Vala sources are only compiled in maintainer mode. When you compile the application from the development branch you will usually have a script called
autogen.sh
to build the configure script that will automatically be executed with the parameter --enable-maintainer-mode
. When providing the distribution tarball that is created with make distcheck
, the configure script will not be run with that parameter (except if specified by hand) and the source files to build from will be filled in with the C filenames.The example below is very generic and can be copy/pasted but should be adapted.
Autoconf script
1. The initialization of Automake and the maintainer mode in the autoconf script. The Automake version is checked for 1.11 which is the first version that comes with Vala support. The extra dist-bzip2 argument is there to provide an extra bzipped distribution tarball as you guessed it.AM_INIT_AUTOMAKE([1.11 dist-bzip2])2. The check for Vala only on maintainer mode. The AM_PROG_VALAC defines the variable VALAC that can be reused inside the Makefile.am files and accepts an optional version check.
AM_MAINTAINER_MODE()
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then3. It is possible to sum up the build configuration at the end of the autoconf script.
AM_PROG_VALAC([0.7.4])
if test "x$VALAC" = "x" ; then
AC_MSG_ERROR([Cannot find the "valac" compiler in your PATH])
fi
fi
echo
echo "Build Configuration:"
echo
echo "* Maintainer Mode: $USE_MAINTAINER_MODE"
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
echo
echo " * Vala: $VALAC"
echo
fi
Automake script
1. The declaration of the Vala sources and their respective compiled C sources.product_VALASOURCES = \2. Use the special BUILT_SOURCES variable to build given targets before running a dist with e.g. make distcheck. This usually done in maintainer mode, as in this case to be sure the releases won't have anything to do with Vala.
obj1.vala \
obj2.vala \
main.vala
product_VALABUILTSOURCES = $(product_VALASOURCES:.vala=.c) product.h
if MAINTAINER_MODE3. The final sources for the product are filled in with the generated Vala sources. The Vala sources are not passed to any SOURCES which is why they are passed to the special EXTRA_DIST variable.
PACKAGES = --pkg=gtk+-2.0
BUILT_SOURCES = vala.stamp
vala.stamp: $(product_VALASOURCES)
$(VALAC) --vapidir=$(srcdir) $(PACKAGES) $^ -C -H product.h
touch $@
endif
product_SOURCES = \
random-source.c \
random-header.h \
$(product_VALABUILTSOURCES)
EXTRA_DIST = $(product_VALASOURCES)
if MAINTAINER_MODE
CLEANFILES = \
$(BUILT_SOURCES) \
$(product_VALABUILTSOURCES)
endif
That's it
There are many existent Vala projects nowadays from where you can pick up new ideas, and this post is just an example amongst many others. The full example is available in the xfce4-vala bindings.Update: I corrected some mistakes seen in green in the script portions. If VALAC is unset the configure script must quit otherwise the resulting Makefiles will have empty commands instead of /usr/bin/valac. Also the generated header file must be passed to product_VALABUILTSOURCES otherwise it would have been left out from distributions as it wans't passed to any product_SOURCES nor EXTRA_DIST variables.
No comments:
Post a Comment