Reputation: 1151
I am writing my configure.ac
script, and have a few custom enable arguments which define macros in my C code if enabled. An example:
AC_ARG_ENABLE([example],
AS_HELP_STRING([--enable-example], [This is an example]))
AS_IF([test "x$enable_example" = "xyes"], [
AC_DEFINE(EXAMPLE_MACRO, 1, [This is a definition example])
])
Now say I have an enable option which, if enabled, must disable the effects of --enable-example
option. I have the normal setup:
AC_ARG_ENABLE([another-feature],
AS_HELP_STRING([--another-feature], [This is a feature which enables something, but disables --enable-example]))
AS_IF([test "x$enable_another_feature" = "xyes"], [
AC_DEFINE(ANOTHER_FEATURE_MACRO, 1, [This is another feature definition])
])
Now I need to be able to undefine the EXAMPLE_MACRO
macro, but I can't find anything to undo the AC_DEFINE
. Am I missing something?
Upvotes: 4
Views: 1675
Reputation: 94
In case of boolean type symbols like in your example, where you simply enable flag or disable, all you need is another call to AC_DEFINE to disable the symbol:
AC_DEFINE(EXAMPLE_MACRO, 0)
The symbol will still exist, but with the new value of 0 (boolean false).
Update: To complete the answer, the usual way you do it if there are conflicting options specified is termination with error during compilation. When you define a symbol, and config.h.in contains the #undef EXAMPLE_MACRO, the AC_DEFINE will turn it around into #define EXAMPLE_MACRO. So you have two options to work with such a macro, check if its value is set to 1/0 or do a check for both macros set and assert if they are.
Upvotes: 0
Reputation: 22328
Why not simply delay the AC_DEFINE
function calls? Note, I'm not a big fan of the AS_IF
macro...
if test "x$enable_another_feature" = xyes ; then
# enable_example="no" # (optional)
AC_DEFINE([ANOTHER_FEATURE_MACRO], [1])
elif test "x$enable_example" = xyes ; then
AC_DEFINE([EXAMPLE_MACRO], [1])
fi
If the AC_DEFINE
is not executed, the corresponding #define ...
is not instantiated in the config header. Discussed here.
Upvotes: 1