2

I have a very basic understanding of how autoconf and automake work, gathered from various tutorials. However, as I would like my libraries to be flexible during their builds, they need to have the --with-FEATURE and --without-FEATURE functionality commonly found in other programs. How do I implement this?

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
  • possible duplicate of [How do you define the options you see in ./configure --help?](http://stackoverflow.com/questions/2655177/how-do-you-define-the-options-you-see-in-configure-help) – ptomato Apr 17 '11 at 16:43

1 Answers1

7

You'll want to use AC_ARG_WITH, for example:

AC_ARG_WITH(editres,
[  --without-editres                do not use editres])
if test "x${with_editres}" != "xno"; then
    AC_CHECK_LIB(Xmu, _XEditResCheckMessages,
        EDITRES_LIBS="-lXmu"
        AC_DEFINE(HAVE_EDITRES, 1), AC_DEFINE(HAVE_EDITRES, 0),
        ${X_PRE_LIBS} ${XEXT_LIBS} ${XT_LIBS} ${XEXT_LIBS} ${X11_LIBS})
else
    AC_DEFINE(HAVE_EDITRES, 0)
fi
mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • Thanks for that. One little question; I always see authors prefix both operand strings in a comparison with "x". Why do they do this? – Delan Azabani Apr 16 '11 at 06:37
  • 1
    The "x" is a hack to avoid confusing the shell with something that's empty; if `X` is an empty string, then `if test $X != "no"` looks like `if test != "no"` to the shell and the shell does not approve of such things. So, the "x" is added as a prefix to convert empty strings to non-empty strings and thus keep the shell from getting upset and throwing a hissy fit. – mu is too short Apr 16 '11 at 06:44
  • 2
    Use `AS_HELP_STRING` instead of laying out the help string by hand. Also, you've underquoted most of your arguments. – Jack Kelly Apr 18 '11 at 00:09
  • @Jack: How new is `AS_HELP_STRING`? I pulled that editres example out of a `configure.in` that I wrote over a decade ago so it might be a bit musty. Feel free to correct it if your configure-fu is strong than mine. – mu is too short Apr 18 '11 at 00:26
  • @mu is too short: I found reference to `AS_HELP_STRING` bugfixes in the `NEWS` for autoconf 2.60, released in 2006. http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;f=NEWS;hb=HEAD . Quotation, OTOH, is partially personal preference and I err on the side of caution. – Jack Kelly Apr 18 '11 at 02:19
  • @Jack: I wrote the above for mgv back in ~1997 and I was probably working from various example `configure.in` files. – mu is too short Apr 18 '11 at 03:03