autoconf: External Software

1 
1 15.2 Working With External Software
1 ===================================
1 
1 Some packages require, or can optionally use, other software packages
1 that are already installed.  The user can give `configure' command line
1 options to specify which such external software to use.  The options
1 have one of these forms:
1 
1      --with-PACKAGE[=ARG]
1      --without-PACKAGE
1 
1    For example, `--with-gnu-ld' means work with the GNU linker instead
1 of some other linker.  `--with-x' means work with The X Window System.
1 
1    The user can give an argument by following the package name with `='
1 and the argument.  Giving an argument of `no' is for packages that are
1 used by default; it says to _not_ use the package.  An argument that is
1 neither `yes' nor `no' could include a name or number of a version of
1 the other package, to specify more precisely which other package this
1 program is supposed to work with.  If no argument is given, it defaults
1 to `yes'.  `--without-PACKAGE' is equivalent to `--with-PACKAGE=no'.
1 
1    Normally `configure' scripts complain about `--with-PACKAGE' options
1 that they do not support.  ⇒Option Checking, for details, and
1 for how to override the defaults.
1 
1    For each external software package that may be used, `configure.ac'
1 should call `AC_ARG_WITH' to detect whether the `configure' user asked
1 to use it.  Whether each package is used or not by default, and which
1 arguments are valid, is up to you.
1 
1  -- Macro: AC_ARG_WITH (PACKAGE, HELP-STRING, [ACTION-IF-GIVEN],
1           [ACTION-IF-NOT-GIVEN])
1      If the user gave `configure' the option `--with-PACKAGE' or
1      `--without-PACKAGE', run shell commands ACTION-IF-GIVEN.  If
1      neither option was given, run shell commands ACTION-IF-NOT-GIVEN.
1      The name PACKAGE indicates another software package that this
1      program should work with.  It should consist only of alphanumeric
1      characters, dashes, plus signs, and dots.
1 
1      The option's argument is available to the shell commands
1      ACTION-IF-GIVEN in the shell variable `withval', which is actually
1      just the value of the shell variable named `with_PACKAGE', with
1      any non-alphanumeric characters in PACKAGE changed into `_'.  You
1      may use that variable instead, if you wish.
1 
1      The argument HELP-STRING is a description of the option that looks
1      like this:
1             --with-readline         support fancy command line editing
1 
1      HELP-STRING may be more than one line long, if more detail is
1      needed.  Just make sure the columns line up in `configure --help'.
1      Avoid tabs in the help string.  The easiest way to provide the
1      proper leading whitespace is to format your HELP-STRING with the
1      macro `AS_HELP_STRING' (⇒Pretty Help Strings).
1 
1      The following example shows how to use the `AC_ARG_WITH' macro in
1      a common situation.  You want to let the user decide whether to
1      enable support for an external library (e.g., the readline
1      library); if the user specified neither `--with-readline' nor
1      `--without-readline', you want to enable support for readline only
1      if the library is available on the system.
1 
1           AC_ARG_WITH([readline],
1             [AS_HELP_STRING([--with-readline],
1               [support fancy command line editing @<:@default=check@:>@])],
1             [],
1             [with_readline=check])
1 
1           LIBREADLINE=
1           AS_IF([test "x$with_readline" != xno],
1             [AC_CHECK_LIB([readline], [main],
1               [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
1                AC_DEFINE([HAVE_LIBREADLINE], [1],
1                          [Define if you have libreadline])
1               ],
1               [if test "x$with_readline" != xcheck; then
1                  AC_MSG_FAILURE(
1                    [--with-readline was given, but test for readline failed])
1                fi
1               ], -lncurses)])
1 
1      The next example shows how to use `AC_ARG_WITH' to give the user
1      the possibility to enable support for the readline library, in
1      case it is still experimental and not well tested, and is
1      therefore disabled by default.
1 
1           AC_ARG_WITH([readline],
1             [AS_HELP_STRING([--with-readline],
1               [enable experimental support for readline])],
1             [],
1             [with_readline=no])
1 
1           LIBREADLINE=
1           AS_IF([test "x$with_readline" != xno],
1             [AC_CHECK_LIB([readline], [main],
1               [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
1                AC_DEFINE([HAVE_LIBREADLINE], [1],
1                          [Define if you have libreadline])
1               ],
1               [AC_MSG_FAILURE(
1                  [--with-readline was given, but test for readline failed])],
1               [-lncurses])])
1 
1      The last example shows how to use `AC_ARG_WITH' to give the user
1      the possibility to disable support for the readline library, given
1      that it is an important feature and that it should be enabled by
1      default.
1 
1           AC_ARG_WITH([readline],
1             [AS_HELP_STRING([--without-readline],
1               [disable support for readline])],
1             [],
1             [with_readline=yes])
1 
1           LIBREADLINE=
1           AS_IF([test "x$with_readline" != xno],
1             [AC_CHECK_LIB([readline], [main],
1               [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
1                AC_DEFINE([HAVE_LIBREADLINE], [1],
1                          [Define if you have libreadline])
1               ],
1               [AC_MSG_FAILURE(
1                  [readline test failed (--without-readline to disable)])],
1               [-lncurses])])
1 
1      These three examples can be easily adapted to the case where
11      `AC_ARG_ENABLE' should be preferred to `AC_ARG_WITH' (see ⇒
      Package Options).
1