If the user gave configure the option --with-package
or --without-package, run shell commands
action-if-given. If neither option was given, run shell commands
action-if-not-given. The name package indicates another
software package that this program should work with. It should consist
only of alphanumeric characters and dashes.
The option's argument is available to the shell commands
action-if-given in the shell variable withval
, which is
actually just the value of the shell variable with_
package,
with any - characters changed into ‘_’. You may use that
variable instead, if you wish.
The argument help-string is a description of the option that
looks like this:
--with-readline support fancy command line editing
help-string may be more than one line long, if more detail is
needed. Just make sure the columns line up in ‘configure
--help’. Avoid tabs in the help string. You'll need to enclose the
help string in ‘[’ and ‘]’ in order to produce the leading
blanks.
You should format your help-string with the macro
AS_HELP_STRING
(see Pretty Help Strings).
The following example shows how to use the AC_ARG_WITH
macro in
a common situation. You want to let the user decide whether to enable
support for an external library (e.g., the readline library); if the user
specified neither --with-readline nor --without-readline,
you want to enable support for readline only if the library is available
on the system.
AC_ARG_WITH([readline],
[AS_HELP_STRING([--with-readline],
[support fancy command line editing @<:@default=check@:>@])],
[],
[with_readline=check])
LIBREADLINE=
AS_IF([test "x$with_readline" != xno],
[AC_CHECK_LIB([readline], [main],
[AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
AC_DEFINE([HAVE_LIBREADLINE], [1],
[Define if you have libreadline])
],
[if test "x$with_readline" != xcheck; then
AC_MSG_FAILURE(
[--with-readline was given, but test for readline failed])
fi
], -lncurses)])
The next example shows how to use AC_ARG_WITH
to give the user the
possibility to enable support for the readline library, in case it is still
experimental and not well tested, and is therefore disabled by default.
AC_ARG_WITH([readline],
[AS_HELP_STRING([--with-readline],
[enable experimental support for readline])],
[],
[with_readline=no])
LIBREADLINE=
AS_IF([test "x$with_readline" != xno],
[AC_CHECK_LIB([readline], [main],
[AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
AC_DEFINE([HAVE_LIBREADLINE], [1],
[Define if you have libreadline])
],
[AC_MSG_FAILURE(
[--with-readline was given, but test for readline failed])],
[-lncurses])])
The last example shows how to use AC_ARG_WITH
to give the user the
possibility to disable support for the readline library, given that it is
an important feature and that it should be enabled by default.
AC_ARG_WITH([readline],
[AS_HELP_STRING([--without-readline],
[disable support for readline])],
[],
[with_readline=yes])
LIBREADLINE=
AS_IF([test "x$with_readline" != xno],
[AC_CHECK_LIB([readline], [main],
[AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
AC_DEFINE([HAVE_LIBREADLINE], [1],
[Define if you have libreadline])
],
[AC_MSG_FAILURE(
[readline test failed (--without-readline to disable)])],
[-lncurses])])
These three examples can be easily adapted to the case where
AC_ARG_ENABLE
should be preferred to AC_ARG_WITH
(see
Package Options).