1

I would like to be able pass arguments to ./configure script, so it would add NDEBUG used by to my generated header file. How can I do that? My configure script is generated from configure.ac.

I already one great answer, but it seems that I my question is wrong. The option would have to remove this NDEBUG, because by default I would like to have assertions turned off. There is no AC_UNDEFINE, so I need to use some trick: define ASSERT_ON, which would turn off NDEBUG. Is there any easier, better way?

2 Answers 2

2

You'll want to use the AC_ARG_ENABLE() macro in your configure.ac file to trigger an action when someone adds --enable-foo to your command line options.

AC_ARG_ENABLE(foo, "used to turn on the NDEBUG flag",
  [ AC_DEFINE(NDEBUG) ]
)
2
  • That is great answer and I would gladly accept, but please take a look at my edit. Maybe you could also help me with this?
    – gruszczy
    Jan 31, 2011 at 21:26
  • If you want to unset a previously set variable within autoconf, you should be able to turn off the variable name itself. Maybe. See the config.cache file for the list of variable names that you might be able to turn off with a simple varname="" type setting. Feb 1, 2011 at 15:22
0

You can use AH_VERBATIM in order to add extra data to your config.h.in (and thus, config.h file).

The thing is, autoconf is going to comment out anything that looks like a #undef statement when producing the config.h file out of the template.

There is a preprocessor trick to avoid that: use #/**/undef/**/. The C preprocessor is going to strip the comments first, but autoconf will not see that as a #undef statement.

To recap, in order to enforce NDEBUG being undefined:

AH_VERBATIM([NDEBUG], [/* Never ever ignore assertions */
#ifdef NDEBUG
#/**/undef/**/ NDEBUG
#endif])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.