profzoom
profzoom

Reputation: 327

Create custom ./configure command line arguments

I'm updating a project to use autotools, and to maintain backwards compatibility with previous versions, I would like the user to be able to run ./configure --foo=bar to set a build option.

Based on reading the docs, it looks like I could set up ./configure --enable-foo, ./configure --with-foo, or ./configure foo=bar without any problem, but I'm not seeing anything allowing the desired behavior (specifically having a double dash -- before the option).

Any suggestions?

Upvotes: 3

Views: 1203

Answers (2)

ldav1s
ldav1s

Reputation: 16315

There's no way I know of doing this in configure.ac. You'll have to patch configure. This can be done by running the patching script in a bootstrap.sh after running autoreconf. You'll have to add your option to the ac_option processing loop. The case for --x looks like a promising one to copy or replace to inject your new option, something like:

--foo=*)
      my_foo=$ac_optarg ;;

There's also some code that strips out commandline args when configure sometimes needs to be re-invoked. It'll be up to you to determine whether --foo should be stripped or not. I think this is probably why they don't allow this in the first place.

If it were me, I'd try and lobby for AC_ARG_WITH (e.g. --with-foo=bar). It seems like a lot less work.

Upvotes: 4

Patricio Rossi
Patricio Rossi

Reputation: 163

in order to do that you have to add to your configure.ac something like this:

# Enable debugging mode
AC_ARG_ENABLE(debug,
  AC_HELP_STRING([--enable-debug],[Show a lot of extra information when running]),
  AM_CPPFLAGS="$AM_CPPFLAGS -DDEBUG"
  debug_messages=yes,
  debug_messages=no)

AC_SUBST(AM_CPPFLAGS)
AC_SUBST(AM_CXXFLAGS)

echo -e "\n--------- build environment -----------
Debug Mode     : $debug_messages"

That is just a simple example to add for example a --enable-debug, it will set the DEBUG constant on the config.h file. then your have to code something like this:

#include "config.h"
#ifdef DEBUG
    // do debug
#else
    // no debug
#endif

Upvotes: -1

Related Questions