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 dnl dnl @version $Id:$ dnl @author Roger Leigh 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 #include int main () { int major, minor, micro; char *tmp_version; system ("touch conf.]DOWN[test"); /* HP/UX 9 (address@hidden) 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 ], [ 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 ], [ 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]) ])