On Mon, Jul 23, 2001 at 02:01:02AM +0200, Guido Draheim wrote: > > Tim Van Holder wrote: > > > > > Nowadays, many shared libraries include a -config script e.g. libgtk > > > [...] > > > There is much duplication of code here. Anyone wishing to use this > > > scheme must duplicate the script and then amend it for their use, and > > > also convert the m4 macro as well, to AM_PATH_<LIB>. libtool could be > > > used to automate this. Currently I maintain the gimp-print build > > > > It seems to me this really is something that would fall under autoconf's > > jurisdiction, so I've CC'd that list. > > > > >[...] > > > To remove the need for m4 macro duplication, a single macro could be > > > used instead. E.g.: > > > > > > AC_PATH_LIB(libname, minimum_version, header, config-script) > > > where libname is the name of the library to check for e.g. gtk, gimp. > > > minimum version is the lowest version to allow > > > header is the header to include when compiling the test program > > > (default libname/libname.h) > > > script is the config script to run (default libname-config) > > > > This seems potentially useful, though it would depend on how compatible > > <lib>-config scripts actually are (i.e. if gtk-config and sdl-config, > > for example, were to take different options, the usefulness of this > > macro would be limited at best). Well, if there is a minumum requirement a config script has to conform to, and they are all generated with the companion macro, there shouldn't be a problem. > > > AC_LIB_CONFIG(libname, location) > > > this would generate the script libname-config in the specified > > > location in the source tree. The following variables would be used in > > > > That should be be AC_CONFIG_LIBCONFIG, to match the existing > > AC_CONFIG_* macros. I'm not sure this has to be a specific macro though, > > as it could be easily created using the existing config.status mechanism. > > [...] > > There is a generic-config macro that I'm using quite often. However it > does not implant code into config.status - it would be best to have > that done somehow. Anyway, check the m4 source in the ac-archive under: > http://www.gnu.org/software/ac-archive/Miscellaneous/ac_create_generic_config.html This is what I was looking for. Will this ever be made part of the autoconf distribution? I hope you don't mind, I have made a few changes to the macro (see the attached file). The changes: * more flexible - include more detail in output script - use --prefix=DIR and --exec-prefix=DIR for --cflags and --libs output * fixed a minor error in the script * use library-specific variables, so there can be many libconfig scripts in a single package (one per library) * Renamed to AC_CONFIG_LIBCONFIG * generate library-config.in, which is then processed by config.status to make library-config (so variables are always valid (e.g. $prefix) Is this OK? This is my first real attempt at m4, so there may be cleaner ways of doing some things (e.g. remove some of the `translit' macros). I would also like to auto-generate version headers, using version variables in configure.in to work with the lib-check macro. I could add an optional third header argument, or make an entirely separate macro (AC_CONFIG_LIBHEADER?). Which would be best? > btw, it does complement a generic lib-check macro that can be found as: > http://www.gnu.org/software/ac-archive/Miscellaneous/ac_path_generic.html I'll have a look at this next. I'll try to add support for the --prefix and --exec-prefix options if that's OK. Thanks for the pointers. Feel free to use the attached macro for whatever you wish. Regards, Roger -- Roger Leigh ** Registration Number: 151826, http://counter.li.org ** Need Epson Stylus Utilities? http://gimp-print.sourceforge.net/ For GPG Public Key: finger [EMAIL PROTECTED] or see public keyservers.
dnl @synopsis AC_CONFIG_LIBCONFIG [(LIBRARY [, DESTINATION])] dnl dnl Creates a custom LIBRARY-config file that has all the dnl things that you want, hmm, well, at least it has dnl --cflags, --version, --libs. Optionally output header containing dnl version details for use with other macros. dnl dnl This macros saves you all the typing for a library-config.in script, dnl you don't even need to distribute one along. Place this macro dnl in your configure.ac, et voila, you got one that you want to install. dnl dnl The defaults: $1 = $LIBRARY $2 = $DESTINATION. dnl dnl It is suggested that the following CFLAGS and LIBS variables are used dnl in your configure.in. library_cflags and library_libs are dnl *essential*. If they do not exist, defaults will be taken from dnl LIBRARY_CFLAGS, LIBRARY_LIBS (should be -llibrary *only*) and dnl LIBRARY_LIBDEPS (-l options for libraries your library depends upon. dnl LIBLIBRARY_LIBS is simply $LIBRARY_LIBS $LIBRARY_LIBDEPS. dnl NB. LIBRARY and library are the name of your library, in upper and dnl lower case, repectively e.g. GTK, gtk. dnl dnl LIBRARY_CFLAGS: cflags for compiling libraries and example progs dnl LIBRARY_LIBS: libraries for linking programs. dnl LIBRARY_LIBDEPS*: libraries for linking libraries against dnl library_cflags*: cflags to store in library-config dnl library_libs*: libs to store in library-config dnl LIBLIBRARY_LIBS: libs to link programs IN THIS PACKAGE ONLY against dnl LIBRARY_VERSION*: the version of your library (x.y.z recommended) dnl *=required if you want sensible output. dnl dnl There is also an AC_SUBST(LIBRARY_CONFIG) that will be set to dnl the name of the file that we output in this macro. Use as: dnl dnl install-exec-local: install-config dnl install-config: dnl $(mkinstalldirs) $(DESTDIR)$(bindir) dnl $(INSTALL_EXEC) @LIBRARY_CONFIG@ $(DESTDIR)$(bindir) dnl dnl Or, if using automake: dnl dnl bin_SCRIPTS = @LIBRARY_CONFIG@ dnl dnl Based upon AC_CREATE_GENERIC_CONFIG (ac_create_generic_config.m4) dnl by Guido Draheim <[EMAIL PROTECTED]> dnl dnl @version $Id:$ dnl @author Roger Leigh <[EMAIL PROTECTED]> dnl AC_DEFUN([AC_CONFIG_LIBCONFIG],[# create a custom library-config file ($1-config) L=`echo ifelse($1, , $PACKAGE, $1)` D=`echo ifelse($2, , ., $2)` L=`echo $L` dnl V=`echo ifelse($1, , $VERSION, $1)` F=`echo $D/$L-config.in` if test -z "$translit($1_cflags, [A-Z], [a-z])" ; then if test -n "$translit($1_CFLAGS, [a-z], [A-Z])" ; then translit($1_cflags, [A-Z], [a-z])="$translit($1_CFLAGS, [a-z], [A-Z])" else translit($1_cflags, [A-Z], [a-z])='' fi AC_SUBST(translit($1_cflags, [A-Z], [a-z])) fi if test -z "$translit($1_libs, [A-Z], [a-z])" ; then if test -n "$translit($1_LIBS, [a-z], [A-Z])" ; then translit($1_libs, [A-Z], [a-z])="$translit($1_LIBS, [a-z], [A-Z])" else translit($1_libs, [A-Z], [a-z])='-l$1' fi if test -n "$translit($1_LIBDEPS, [a-z], [A-Z])" ; then translit($1_libs, [A-Z], [a-z])="$translit($1_libs, [A-Z], [a-z]) $translit($1_LIBDEPS, [a-z], [A-Z])" fi AC_SUBST(translit($1_libs, [A-Z], [a-z])) fi if test -z "$translit($1_VERSION, [a-z], [A-Z])" ; then translit($1_VERSION, [a-z], [A-Z])="$VERSION" AC_SUBST(translit($1_VERSION, [a-z], [A-Z])) fi AC_MSG_RESULT(creating lib$L configuration script... $F) echo '#! /bin/sh' >$F echo ' ' >>$F echo 'template_version="1.0.0"' >>$F echo ' ' >>$F echo 'package="@PACKAGE@"' >>$F echo 'version="@translit($1_VERSION, [a-z], [A-Z])@"' >>$F echo 'cflags="@translit($1_cflags, [A-Z], [a-z])@"' >>$F echo 'libs="@translit($1_libs, [A-Z], [a-z])@"' >>$F echo ' ' >>$F # in the order of occurence a standard automake Makefile echo 'prefix="@prefix@"' >>$F echo 'exec_prefix="@exec_prefix@"' >>$F echo 'bindir="@bindir@"' >>$F echo 'sbindir="@sbindir@"' >>$F echo 'libexecdir="@libexecdir@"' >>$F echo 'datadir="@datadir@"' >>$F echo 'sysconfdir="@sysconfdir@"' >>$F echo 'sharedstatedir="@sharedstatedir@"' >>$F echo 'localstatedir="@localstatedir@"' >>$F echo 'libdir="@libdir@"' >>$F echo 'infodir="@infodir@"' >>$F echo 'mandir="@mandir@"' >>$F echo 'includedir="@includedir@"' >>$F echo 'target="'$target'"' >>$F echo 'host="'$host'"' >>$F echo 'build="'$build'"' >>$F echo ' ' >>$F echo 'if test "'"\$""#"'" -eq 0; then' >>$F echo ' cat <<EOF' >>$F echo 'Usage: $1-config [[OPTIONS]]' >>$F echo 'Options:' >>$F echo ' [[--prefix[=DIR]]]' >>$F echo ' [[--exec-prefix[=DIR]]]' >>$F echo ' [[--package]]' >>$F echo ' [[--version]]' >>$F echo ' [[--cflags]]' >>$F echo ' [[--libs]]' >>$F echo ' [[--help]]' >>$F echo 'EOF' >>$F echo 'fi' >>$F echo ' ' >>$F echo 'o=""' >>$F echo 'h=""' >>$F echo 'for i ; do' >>$F echo ' case $i in' >>$F echo ' --prefix=*) prefix=`echo $i | sed -e "s/--prefix=//"` ;' >>$F echo ' includedir="$prefix/include" ;' >>$F echo ' libdir="$prefix/lib" ;;' >>$F echo ' --prefix) o="$o $prefix" ;;' >>$F echo ' --exec_prefix|--eprefix) o="$o $exec_prefix" ;;' >>$F echo ' --exec-prefix=*) exec_prefix=`echo $i | sed -e "s/--exec-prefix=//"` ;' >>$F echo ' libdir="$exec_prefix/lib" ;;' >>$F echo ' --package) o="$o $package" ;;' >>$F echo ' --version) o="$o $version" ;;' >>$F echo ' --cflags) if test "_$includedir" != "_/usr/include" ; then' >>$F echo ' o="$o -I$includedir" ;' >>$F echo ' o="$o $cflags" ; fi' >>$F echo ' ;;' >>$F echo ' --libs) o="$o -L$libdir $libs" ;;' >>$F echo ' --bindir) o="$o $bindir" ;;' >>$F echo ' --sbindir) o="$o $sbindir" ;;' >>$F echo ' --libexecdir) o="$o $libexecdir" ;;' >>$F echo ' --datadir) o="$o $datadir" ;;' >>$F echo ' --sysconfdir) o="$o $sysconfdir" ;;' >>$F echo ' --sharedstatedir) o="$o $sharedstatedir" ;;' >>$F echo ' --localstatedir) o="$o $localstatedir" ;;' >>$F echo ' --libdir) o="$o $libdir" ;;' >>$F echo ' --infodir) o="$o $infodir" ;;' >>$F echo ' --mandir) o="$o $mandir" ;;' >>$F echo ' --target) o="$o $target" ;;' >>$F echo ' --host) o="$o $host" ;;' >>$F echo ' --build) o="$o $build" ;;' >>$F echo ' --pkgdatadir) o="$o $datadir/$package" ;;' >>$F echo ' --pkglibdir) o="$o $libdir/$package" ;;' >>$F echo ' --pkgincludedir) o="$o $includedir/$package" ;;' >>$F echo ' --template-version) o="$o $template_version" ;;' >>$F echo ' --help) h="1" ;;' >>$F echo ' //*|/*//*|./*//*) v=`echo $i | sed -e s://:\$:g`' >>$F echo ' v=`eval "echo $v"` ' >>$F echo ' o="$o $v" ;; ' >>$F echo ' esac' >>$F echo 'done' >>$F echo ' ' >>$F echo 'o=`eval "echo $o"`' >>$F echo 'o=`eval "echo $o"`' >>$F echo 'eval "echo $o"' >>$F echo ' ' >>$F echo 'if test ! -z "$h" ; then ' >>$F echo 'cat <<EOF' >>$F echo 'All available options:' >>$F echo ' --prefix=DIR and Change prefix and exec-prefix' >>$F echo ' --exec-prefix=DIR (only affects --libs and --cflags)' >>$F echo ' --prefix \$prefix $prefix' >>$F echo ' --package \$package $package' >>$F echo ' --version \$version $version' >>$F echo ' --cflags -I\$includedir unless it is /usr/include' >>$F echo ' --libs -L\$libdir \$LIBS $libs' >>$F echo ' --exec_prefix or... ' >>$F echo ' --eprefix \$exec_prefix $exec_prefix' >>$F echo ' --bindir \$bindir $bindir' >>$F echo ' --sbindir \$sbindir $sbindir' >>$F echo ' --libexecdir \$libexecdir $libexecdir' >>$F echo ' --datadir \$datadir $datadir' >>$F echo ' --sysconfdir \$sysconfdir $sysconfdir' >>$F echo ' --sharedstatedir \$sharedstatedir$sharedstatedir' >>$F echo ' --localstatedir \$localstatedir $localstatedir' >>$F echo ' --libdir \$libdir $libdir' >>$F echo ' --infodir \$infodir $infodir' >>$F echo ' --mandir \$mandir $mandir' >>$F echo ' --target \$target $target' >>$F echo ' --host \$host $host' >>$F echo ' --build \$build $build' >>$F echo ' --pkgdatadir \$datadir/\$package' >>$F echo ' --pkglibdir \$libdir/\$package' >>$F echo ' --pkgincludedir \$includedir/\$package' >>$F echo ' --template-version $template_version' >>$F echo ' --help generated by ac_create_libconfig.m4' >>$F echo 'EOF' >>$F echo 'fi' >>$F translit($1_CONFIG, [a-z], [A-Z])="$F" AC_SUBST(translit($1_CONFIG, [a-z], [A-Z])) ])