autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autoconf and optional arguments for the configure script


From: Ed Hartnett
Subject: Re: Autoconf and optional arguments for the configure script
Date: Sat, 25 Jun 2005 08:52:43 -0600
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Bernd Lachner <address@hidden> writes:

> Hi,
>
> thank you for your help, but now I have some more questions. 
>
>> >
>> > I need some optional arguments for a configure script. I have seen the
>> > macros AC_ARG_WITH and AC_ARG_ENABLE in the autoconf manual. As far I can
>> > see, I can add arguments like this to the configure script:
>> >
>> > --enable-option=yes
>> > --with-option
>>
>> --enable-option[=xyz]
>> --with-option[=xyz]
>>
> Ok. I'm new to write configure.ac scripts so I didn't know that I can choose 
> xyz instead yes and no. Is there any site with examples or tutorials to 
> autoconf?

Here's part of an autoconf script I maintain. I offer it in the hope
it might be helpful, and that others might make specific suggestions
or point out any stupid mistakes they see.

So autoconf gurus - please let Bernd and me know if this is wrong!
Thanks.

My configure comes with some options. Here's the help output which
shows the options

  --enable-netcdf-4       build with netcdf-4 (HDF5 is required)
  --enable-64bit          set flags to build in 64-bit mode (ignored if
                          --disable-flag-setting is used)
  --enable-parallel       build parallel netcdf-4 (--enable-netcdf-4 must also
                          be specified)
  --disable-flag-setting  Turn off configure's attempts to correctly set
                          compiler and linker flags.
  --disable-compiler-recover
                          don't continue if a desired C++, F77, or F90
                          compiler is missing
  --disable-f77           don't try to build Fortran 77 API
  --disable-f90           don't try to build Fortran 90 API
  --disable-cxx           don't try to build Fortran 90 API

...

  --with-hdf5=<directory> Specify location of HDF5 library. Configure will
                          expect to find subdirs include and lib.
  --with-temp-large=<directory>
                          Specify directory where large files (i.e. >2 GB)
                          will be written, if large files tests are
                          run.


Here's the configure.ac which handles some of the above. For some
options I need to set an automake conditional, which causes the
configure script to build the makefiles differently depending on the
option. Use AM_CONDITIONAL for that.

Sometimes the configure script sets a macro in config.h. Do that with
the AC_DEFINE macro.

Sometimes there is an argument (ex. --with-hdf5=/usr/local), sometimes
not.

Enjoy!

# This is part of Unidata's netCDF package. Copyright 2005, see the
# COPYRIGHT file for more information.

... snip ...

# Does the user want to build netcdf-4?
AC_MSG_CHECKING([whether netCDF-4 is to be built])
AC_ARG_ENABLE([netcdf-4],
              [AS_HELP_STRING([--enable-netcdf-4],
                              [build with netcdf-4 (HDF5 is required)])])
test "x$enable_netcdf_4" = xyes || enable_netcdf_4=no
AC_MSG_RESULT($enable_netcdf_4)
AM_CONDITIONAL(USE_NETCDF4, [test x$enable_netcdf_4 = xyes])
if test "x$enable_netcdf_4" = xyes; then
   AC_DEFINE([USE_NETCDF4], 1, [if true, build netCDF-4])
fi

# Does the user want to build in 64-bit mode?
AC_MSG_CHECKING([whether netCDF is to be built in 64-bit mode])
AC_ARG_ENABLE([64-bit],
              [AS_HELP_STRING([--enable-64bit],
                              [set flags to build in 64-bit mode (ignored if 
--disable-flag-setting is used)])])
test "x$enable_64bit" = xyes || enable_64bit=no
AC_MSG_RESULT($enable_64bit)

# Does the user want to build netcdf-4 with parallel?
AC_MSG_CHECKING([whether parallel netCDF-4 is to be built])
AC_ARG_ENABLE([parallel],
              [AS_HELP_STRING([--enable-parallel],
                              [build parallel netcdf-4 (--enable-netcdf-4 must 
also be specified)])])
test "x$enable_parallel" = xyes || enable_parallel=no
AC_MSG_RESULT($enable_parallel)
if test "x$enable_parallel" = xyes && test "x$enable_netcdf_4" != xyes; then
   AC_MSG_ERROR(["--enable-parallel is only valid if --enable-netcdf-4 is also 
used."])
fi
AM_CONDITIONAL(USE_PARALLEL, [test "x$enable_parallel" = xyes])
if test "x$enable_parallel" = xyes; then
   AC_DEFINE([USE_PARALLEL], [1], [if true, compile in parallel netCDF-4])
fi

# Did the user specify a location for the HDF5 library?
AC_MSG_CHECKING([whether a location for the HDF5 library was specified])
AC_ARG_WITH([hdf5],
              [AS_HELP_STRING([--with-hdf5=<directory>],
                              [Specify location of HDF5 library. Configure will 
expect to find subdirs include and lib.])])
AC_MSG_RESULT([$with_hdf5])
AM_CONDITIONAL(USE_HDF5_DIR, [test ! "x$with_hdf5" = x])
AC_SUBST(HDF5DIR, [$with_hdf5])

# Does the user want configure to keep hands off any compiler or
# linker settings?
AC_MSG_CHECKING([whether configure should try to set compiler flags])
AC_ARG_ENABLE([flag-setting],
              [AS_HELP_STRING([--disable-flag-setting],
                              [Turn off configure's attempts to correctly set 
compiler and linker flags.])])
test "x$enable_flag_setting" = xno || enable_flag_setting=yes
AC_MSG_RESULT($enable_flag_setting)

# Do we want to recover from a bad C++, F77, or F90 compiler?
nc_compiler_recover=yes
AC_MSG_CHECKING([whether we should just skip C++, F77, or F90 API if compiler 
is missing])
AC_ARG_ENABLE([compiler-recover],
              [AS_HELP_STRING([--disable-compiler-recover],
                              [don't continue if a desired C++, F77, or F90 
compiler is missing])])
test "x$enable_compiler_recover" = "xno" || enable_compiler_recover=yes
AC_MSG_RESULT([$enable_compiler_recover])

# Do we want to build the fortran 77 API? Check for --disable-f77.
nc_build_f77=yes
AC_MSG_CHECKING([whether F77 API is desired])
AC_ARG_ENABLE([f77],
              [AS_HELP_STRING([--disable-f77],
                              [don't try to build Fortran 77 API])])
test "x$enable_f77" = "xno" && nc_build_f77=no
test "x$nc_null_fc" = xyes && nc_build_f77=no
AC_MSG_RESULT([$nc_build_f77])


-- 
Ed Hartnett  -- address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]