Spent some of my morning fixing a build issue that came down to the use of AC_ARG_ENABLE. I thought it was worth recording some notes for its use:
Something enabled by default:
AC_ARG_ENABLE([badgers],
[AC_HELP_STRING([--enable-badgers=@<:@yes/no@:>@],
[Enable badgers @<:@default=yes@:>@])],
[],
[enable_badgers=yes])
Something disabled by default:
AC_ARG_ENABLE([badgers],
[AC_HELP_STRING([--enable-badgers=@<:@yes/no@:>@],
[Enable badgers @<:@default=no@:>@])],
[],
[enable_badgers=no])
Observe that in this case the only thing that changes is the default value in the third parameter to AC_ARG_ENABLE (and also the documentation
)
Something enabled by default but with a –disable syntax:
AC_ARG_ENABLE([badgers],
[AC_HELP_STRING([--disable-badgers],
[Disable badgers],
[],
[enable_badgers=yes])
Notice that this case is just the same as the first except with the help changed. Of course you actually need to use the value from the flag. I think this is more readable if presented outside the AC_ARG_ENABLE parameters this is possible because AC_ARG_ENABLE always sets a variable called enable_<thing>. Awesome, huh?
For conditional pkg-config:
AS_IF([test "x$enable_badgers" = "xyes"],
[PKG_CHECK_MODULES(BADGERS, [badgers-1.0])],
[])
For conditional building:
AM_CONDITIONAL(ENABLE_BADGERS, test "x$badgers" = xyes)