I have an autotools project. I wish to exclude some files from the project, if the user configures so during build. For example, if the build is configured with –no-gui , the files related to GUI are not to be included in the build.
-
What is the standard macro for such a flag in autoconf? Something that could be configured with like –disable-gui?
-
How to establish the link between this configure option and automake input files?
I have Calcote’s introductory book Autotools here. If you can give pointers as to the macros involved, I can look it up in the book or the net.
Thank you,
Elan.
According to the autoconf manual, the correct way to do this is with an
--enable-FEATUREargument toconfigure. That’s done using the macroAC_ARG_ENABLE. The four argument toAC_ARG_ENABLEare, in order,FEATURE,HELP-STRING,ACTION-IF-GIVEN,ACTION-IF-NOT-GIVEN. So inconfigure.ac:AS_HELP_STRINGwraps the help string nicely, and the@<:@and@:>@are quadrigraphs which expand to[and]in the output of./configure --help. Even though I’ve specified an emptyACTION-IF-GIVEN,configurewill still setenable_guitoyesorno, depending on whether--enable-guior--disable-gui(which is an alias for--enable-gui=no) was passed.So the shell variable
$enable_guiwill be eitheryes,noorcheck. This is for the benefit of the poor packagers who make the distribution packages, as it’s considered poor form to build optional support based only on a check. See the gentoo article on automagic dependencies, but packagers would prefer for the build to fail than silently not include a wanted feature.Now, if
$enable_guiisyesorcheck, we want to check for dependencies and fail if we manually enabled the feature. Since I don’t know what library your gui depends on, I’m just going to usepkg-configto check forgtk+-2.0. The four arguments toPKG_CHECK_MODULES(provided by thepkg-configpackage) are, in order,VARIABLE,MODULES,ACTION-IF-FOUNDandACTION-IF-NOT-FOUND:The reason we use
AS_IFinstead of just writing a normal shellif-expression is so thatautoconfexpands anything that an enclosed macro might require (herePKG_CHECK_MODULESinternally depends on macros likePKG_PROG_PKG_CONFIG). You can test that this does the right thing in all cases by doing something like./configure --enable-gui PKG_CONFIG=/bin/false.Anyway, we’ve now resolved
enable_gui=checkinto eitherenable_gui=yesorenable_gui=no. Now we have to pass this toautomake. The macro to use is AM_CONDITIONAL. Its arguments are, in order,CONDITIONAL(the name used inMakefile.am) andCONDITION(the shell test to setCONDITIONAL):Now, we move over to
Makefile.am, I’m going to assume a simple program with a couple of optional sources: