On Saturday 05 February 2005 01:01, Gregorio Guidi wrote: > So I think we should: > > for main problem: encourage the use of AC_ARG_WITH and AC_ARG_ENABLE. > > for child problem: provide a standard interpretation of those macros > (either through a macro that standardizes the use of > AC_ARG_WITH/AC_ARG_ENABLE, such as the ones I posted at the beginning; or > through some more precise documentation on their use, so that I can point > to it when interacting with software developers). I'm coming back to this problem after trying to write something down. I think there aren't catch-all solutions for the moment, all that can be done is extending a bit the autoconf documentation with respect to these macros, maybe adding a few examples for the most common use cases. Please take a look at the patch below and say what you think. Note: as you can see, the patch assumes there will be a solution for the "AC_REQUIRE in shell conditional" issue. Gregorio
Index: doc/autoconf.texi =================================================================== RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v retrieving revision 1.879 diff -u -B -r1.879 autoconf.texi --- doc/autoconf.texi 15 Feb 2005 06:40:21 -0000 1.879 +++ doc/autoconf.texi 15 Feb 2005 17:00:23 -0000 @@ -13222,6 +13222,78 @@ You should format your @var{help-string} with the macro @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}). + +The following example shows how to use the @code{AC_ARG_WITH} macro in +a very 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 +did not specify neither @option{--with-readline} nor +@option{--without-readline}, you want to enable support for readline only +if the library is available on the system. + +@example +AC_ARG_WITH(readline, + AS_HELP_STRING(--with-readline, [support fancy command line editing @@<:@@default=check@@:>@@]), , + with_readline=check) +LIBREADLINE= +if test "x$with_readline" != xno; then + AC_CHECK_LIB(readline, main, + [ + LIBREADLINE="-lreadline -lncurses" + AC_DEFINE_UNQUOTED(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) +fi +AC_SUBST(LIBREADLINE) +@end example + +The next example shows how to use @code{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. + +@example +AC_ARG_WITH(readline, + AS_HELP_STRING([--with-readline],[enable experimental support for readline @@<:@@default=disabled@@:>@@]), , + with_readline=no) +LIBREADLINE= +if test "x$with_readline" != xno; then + AC_CHECK_LIB(readline, main, + [ + LIBREADLINE="-lreadline -lncurses" + AC_DEFINE_UNQUOTED(HAVE_LIBREADLINE, 1, [Define if you have libreadline]) + ],[ + AC_MSG_FAILURE([--with-readline was given, but test for readline failed]) + ], -lncurses) +fi +AC_SUBST(LIBREADLINE) +@end example + +The last example shows how to use @code{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. + +@example +AC_ARG_WITH(readline, + AS_HELP_STRING([--without-readline],[disable support for readline @@<:@@default=enabled@@:>@@]), , + with_readline=yes) +LIBREADLINE= +if test "x$with_readline" != xno; then + AC_CHECK_LIB(readline, main, + [ + LIBREADLINE="-lreadline -lncurses" + AC_DEFINE_UNQUOTED(HAVE_LIBREADLINE, 1, [Define if you have libreadline]) + ],[ + AC_MSG_FAILURE([test for readline failed, use --without-readline if you want to force readline support off]) + ], -lncurses) +fi +AC_SUBST(LIBREADLINE) +@end example + +The examples above can be adapted with small effort to the case where +@code{AC_ARG_ENABLE} should be preferred to @code{AC_ARG_WITH} (see +@ref{Package Options}). @end defmac @defmac AC_WITH (@var{package}, @var{action-if-given}, @ovar{action-if-not-given}) @@ -13292,6 +13364,10 @@ You should format your @var{help-string} with the macro @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}). + +See the examples suggested with the definition of @code{AC_ARG_WITH} +(@pxref{External Software}) to get an idea of possible utilizations of +@code{AC_ARG_ENABLE}. @end defmac @defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @ovar{action-if-not-given})
_______________________________________________ Autoconf mailing list Autoconf@xxxxxxx http://lists.gnu.org/mailman/listinfo/autoconf