On Mon, Jul 23, 2001 at 02:01:02AM +0200, Guido Draheim wrote: > 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 > > 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 have attached a rewritten ac_path_generic.m4 (AM_PATH_LIB), as well as an updated AM_CONFIG_LIBCONFIG. If they are OK, I'm willing to submit them to the archive. Any comments appreciated. 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` dnl we're going to need uppercase, lowercase and user-friendly versions of the dnl string `LIBRARY' pushdef([UP], translit([$1], [a-z], [A-Z]))dnl pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl if test -z "$DOWN[]_cflags" ; then if test -n "$UP[]_CFLAGS" ; then DOWN[]_cflags="$UP[]_CFLAGS" else DOWN[]_cflags='' fi AC_SUBST(DOWN[]_cflags) fi if test -z "$DOWN[]_libs" ; then if test -n "$UP[]_LIBS" ; then DOWN[]_libs="$UP[]_LIBS" else DOWN[]_libs='-l$1' fi if test -n "$UP[]_LIBDEPS" ; then DOWN[]_libs="$DOWN[]_libs $UP[]_LIBDEPS" fi AC_SUBST(DOWN[]_libs) fi if test -z "$UP[]_VERSION" ; then UP[]_VERSION="$VERSION" AC_SUBST(UP[]_VERSION) 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="@UP[]_VERSION@"' >>$F echo 'cflags="@DOWN[]_cflags@"' >>$F echo 'libs="@DOWN[]_libs@"' >>$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 ' *) eval "echo Unknown option: $i" ; exit 1 ;;' >>$F echo ' esac' >>$F echo 'done' >>$F echo ' ' >>$F echo 'o=`eval "echo $o"`' >>$F echo 'o=`eval "echo $o"`' >>$F echo 'if test -n "$o" ; then ' >>$F echo ' eval "echo $o"' >>$F echo 'fi' >>$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 options)' >>$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 UP[]_CONFIG="$F" AC_SUBST(UP[]_CONFIG) popdef([UP]) popdef([DOWN]) ])
dnl @synopsis AC_PATH_LIB(LIBRARY [, MINIMUM-VERSION [, CONFIG-SCRIPT [, HEADERS [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]]]]) dnl dnl Runs a LIBRARY-config script and defines LIBRARY_CFLAGS and LIBRARY_LIBS, dnl saving you from writing your own macro specific to your library. dnl dnl The defaults: dnl $1 = $LIBRARY e.g. gtk, ncurses dnl $2 = $MINIMUM-VERSION x.y.z format e.g. 4.2.1 dnl $3 = $CONFIG-SCRIPT name of libconfig script if not dnl LIBRARY-config dnl $4 = $HEADER Header to include in test program if not dnl called LIBRARY/LIBRARY.h dnl $5 = ACTION-IF-FOUND Shell script to run if library is found dnl $6 = ACTION-IF-NOT-FOUND Shell script to run if library is not found dnl $7 = MODULES List of module names to pass to LIBRARY-config dnl dnl LIBRARY-config must support `--cflags' and `--libs' args. dnl If MINIMUM-VERSION is specified, LIBRARY-config must also support the dnl `--version' arg, and have version information embedded in its header dnl as detailed below: dnl dnl Macros: dnl #define LIBRARY_MAJOR_VERSION (@LIBRARY_MAJOR_VERSION@) dnl #define LIBRARY_MINOR_VERSION (@LIBRARY_MINOR_VERSION@) dnl #define LIBRARY_MICRO_VERSION (@LIBRARY_MICRO_VERSION@) dnl dnl Version numbers (defined in the library): dnl extern const unsigned int library_major_version; dnl extern const unsigned int library_minor_version; dnl extern const unsigned int library_micro_version; dnl dnl If the `--with-library-[exec-]prefix' arguments to ./configure are dnl given, it must also support `--prefix' and `--exec-prefix'. dnl (In other words, it must be like gtk-config.) dnl dnl If modules are to be used, the LIBRARY-config must support modules. dnl dnl For example: dnl dnl AC_PATH_LIB(foo, 1.0.0) dnl dnl would run `foo-config --version' and check that it is at least 1.0.0 dnl dnl If so, the following would then be defined: dnl dnl FOO_CFLAGS to `foo-config --cflags` dnl FOO_LIBS to `foo-config --libs` dnl dnl Based on AM_PATH_GTK (gtk.m4) by Owen Taylor, and AC_PATH_GENERIC dnl (ac_path_generic.m4) by Angus Lees <[EMAIL PROTECTED]> dnl dnl @version $Id:$ dnl @author Roger Leigh <[EMAIL PROTECTED]> dnl AC_DEFUN([AC_PATH_LIB],[# check for presence of lib$1 dnl we're going to need uppercase, lowercase and user-friendly versions of the dnl string `LIBRARY' pushdef([UP], translit([$1], [a-z], [A-Z]))dnl pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl DOWN[]_config="ifelse($3, , $1-config, $3)" DOWN[]_header="ifelse($4, , $1/$1.h, $4)" dnl Get the cflags and libraries from the LIBRARY-config script dnl AC_ARG_WITH(DOWN-prefix,[ --with-]DOWN[-prefix=PFX Prefix where ]UP[ is installed (optional)], DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="") AC_ARG_WITH(DOWN-exec-prefix,[ --with-]DOWN[-exec-prefix=PFX Exec prefix where ]UP[ is installed (optional)], DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="") AC_ARG_ENABLE(DOWN[]test, [ --disable-]DOWN[test Do not try to compile and run a test ]UP[ program], , [enable_]DOWN[test=yes]) # modules to use ifelse($7, , , DOWN[]_config_args="$DOWN[]_config_args $7") if test x$DOWN[]_config_exec_prefix != x ; then DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix" if test x${UP[]_CONFIG+set} != xset ; then UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config fi fi if test x$DOWN[]_config_prefix != x ; then DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix" if test x${UP[]_CONFIG+set} != xset ; then UP[]_CONFIG="$DOWN[]_config_prefix/bin/ifelse($3, , $1-config, $3)" fi fi AC_PATH_PROG(UP[]_CONFIG, $DOWN[]_config, no) min_[]DOWN[]_version="$2" if test -n "$min_[]DOWN[]_version" ; then AC_MSG_CHECKING(for UP - version >= $min_[]DOWN[]_version) no_[]DOWN="" if test "$up[]_CONFIG" = "no" ; then no_[]DOWN=yes else UP[]_CFLAGS=`$UP[]_CONFIG $DOWN[]_config_args --cflags` UP[]_LIBS=`$UP[]_CONFIG $DOWN[]_config_args --libs` DOWN[]_config_major_version=`$UP[]_CONFIG $DOWN[]_config_args --version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` DOWN[]_config_minor_version=`$UP[]_CONFIG $DOWN[]_config_args --version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` DOWN[]_config_micro_version=`$UP[]_CONFIG $DOWN[]_config_args --version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` if test "x$enable_[]DOWN[]test" = "xyes" ; then ac_save_CFLAGS="$CFLAGS" ac_save_LIBS="$LIBS" CFLAGS="$CFLAGS $UP[]_CFLAGS" LIBS="$UP[]_LIBS $LIBS" dnl dnl Now check if the installed UP is sufficiently new. (Also sanity dnl checks the results of DOWN-config to some extent dnl rm -f conf.DOWN[]test AC_TRY_RUN([ #include <$]DOWN[_header> #include <stdio.h> #include <stdlib.h> int main () { int major, minor, micro; char *tmp_version; system ("touch conf.]DOWN[test"); /* HP/UX 9 (%@#!) writes to sscanf strings */ tmp_version = strdup("$min_]DOWN[_version"); if (!tmp_version) { exit(1); } if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { printf("%s, bad version string\n", "$min_]DOWN[_version"); exit(1); } if ((]DOWN[_major_version != $]DOWN[_config_major_version) || (]DOWN[_minor_version != $]DOWN[_config_minor_version) || (]DOWN[_micro_version != $]DOWN[_config_micro_version)) { printf("\n*** ']DOWN[-config --version' returned %d.%d.%d, but \n", \ $]DOWN[_config_major_version, $]DOWN[_config_minor_version, \ $]DOWN[_config_micro_version); printf("*** ]UP[ (%d.%d.%d) was found!\n", \ ]DOWN[_major_version, ]DOWN[_minor_version, ]DOWN[_micro_version); printf("***\n"); printf("*** If $]DOWN[_config was correct, then it is best to remove\n"); printf("*** the old version of ]UP[. You may also be able to\n"); printf("*** fix the error by modifying your LD_LIBRARY_PATH enviroment\n"); printf("*** variable, or by editing /etc/ld.so.conf. Make sure you have\n"); printf("*** run ldconfig if that is required on your system.\n"); printf("*** If $]DOWN[_config was wrong, set the environment\n"); printf("*** variable ]UP[_CONFIG to point to the correct copy of\n"); printf("*** $]DOWN[_config, and remove the file config.cache\n"); printf("*** before re-running configure.\n"); } #if defined (]UP[_MAJOR_VERSION) && defined (]UP[_MINOR_VERSION) && defined (]UP[_MICRO_VERSION) else if ((]DOWN[_major_version != ]UP[_MAJOR_VERSION) || (]DOWN[_minor_version != ]UP[_MINOR_VERSION) || (]DOWN[_micro_version != ]UP[_MICRO_VERSION)) { printf("*** ]UP[ header files (version %d.%d.%d) do not match\n", ]UP[_MAJOR_VERSION, ]UP[_MINOR_VERSION, ]UP[_MICRO_VERSION); printf("*** library (version %d.%d.%d)\n", ]DOWN[_major_version, ]DOWN[_minor_version, ]DOWN[_micro_version); } #endif /* defined (]UP[_MAJOR_VERSION) ... */ else { if ((]DOWN[_major_version > major) || ((]DOWN[_major_version == major) && (]DOWN[_minor_version > minor)) || ((]DOWN[_major_version == major) && (]DOWN[_minor_version == minor) && (]DOWN[_micro_version >= micro))) { return 0; } else { printf("\n*** An old version of ]UP[ (%d.%d.%d) was found.\n", ]DOWN[_major_version, ]DOWN[_minor_version, ]DOWN[_micro_version); printf("*** You need a version of ]UP[ newer than %d.%d.%d.\n", major, minor, micro); /*printf("*** The latest version of ]UP[ is always available from ftp://ftp.my.site\n");*/ printf("***\n"); printf("*** If you have already installed a sufficiently new version, this\n"); printf("*** error probably means that the wrong copy of the $]DOWN[_config\n"); printf("*** shell script is being found. The easiest way to fix this is to\n"); printf("*** remove the old version of ]UP[, but you can also set the\n"); printf("*** ]UP[_CONFIG environment variable to point to the correct\n"); printf("*** copy of $]DOWN[_config. (In this case, you will have to\n"); printf("*** modify your LD_LIBRARY_PATH environment variable, or edit\n"); printf("*** /etc/ld.so.conf so that the correct libraries are found at\n"); printf("*** run-time.)\n"); } } return 1; } ],, no_[]DOWN=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) CFLAGS="$ac_save_CFLAGS" LIBS="$ac_save_LIBS" fi fi else AC_MSG_CHECKING(for UP - any version) no_[]DOWN=yes if test -n "$UP[]_LIBS" ; then if test "x$enable_[]DOWN[]test" = "xyes" ; then ac_save_CFLAGS="$CFLAGS" ac_save_LIBS="$LIBS" CFLAGS="$CFLAGS $UP[]_CFLAGS" LIBS="$UP[]_LIBS $LIBS" AC_TRY_LINK([ #include <$]DOWN[_header> #include <stdio.h> ], [ exit (0); ], [ no_[]DOWN="" ]) CFLAGS="$ac_save_CFLAGS" LIBS="$ac_save_LIBS" fi fi fi if test "x$no_[]DOWN" = x ; then AC_MSG_RESULT(yes) ifelse([$5], , :, [$5]) else AC_MSG_RESULT(no) if test "$UP[]_CONFIG" = "no" ; then echo "*** The DOWN[]_config script installed by UP could not be found" echo "*** If UP was installed in PREFIX, make sure PREFIX/bin is in" echo "*** your path, or set the UP[]_CONFIG environment variable to the" echo "*** full path to DOWN[]_config." else if test -f conf.DOWN[]test ; then : else echo "*** Could not run UP test program, checking why..." CFLAGS="$CFLAGS $UP[]_CFLAGS" LIBS="$LIBS $UP[]_LIBS" AC_TRY_LINK([ #include <$]DOWN[_header> #include <stdio.h> ], [ return ((]DOWN[_major_version) || (]DOWN[_minor_version) || ](]DOWN[_micro_version)); ], [ echo "*** The test program compiled, but did not run. This usually" echo "*** means that the run-time linker is not finding UP or finding" echo "*** finding the wrong version of UP. If it is not finding" echo "*** UP, you'll need to set your LD_LIBRARY_PATH environment" echo "*** variable, or edit /etc/ld.so.conf to point to the installed" echo "*** location. Also, make sure you have run ldconfig if that is" echo "*** required on your system." echo "***" echo "*** If you have an old version installed, it is best to remove" echo "*** it, although you may also be able to get things to work by" echo "*** modifying LD_LIBRARY_PATH" ], [ echo "*** The test program failed to compile or link. See the file" echo "*** config.log for the exact error that occured. This usually" echo "*** means UP was incorrectly installed or that you have" echo "*** moved UP since it was installed. In the latter case," echo "*** you may want to edit the $DOWN[]_config script:" echo "*** $UP[]_CONFIG" ]) CFLAGS="$ac_save_CFLAGS" LIBS="$ac_save_LIBS" fi fi UP[]_CFLAGS="" UP[]_LIBS="" ifelse([$6], , :, [$6]) fi AC_SUBST(UP[]_CFLAGS) AC_SUBST(UP[]_LIBS) rm -f conf.DOWN[]test popdef([UP]) popdef([DOWN]) ])