# Configure paths for FreeSG # stolen from Sam Lantinga 9/21/99 # stolen from Manish Singh # stolen back from Frank Belew # stolen from Manish Singh # Shamelessly stolen from Owen Taylor dnl AM_PATH_FREESG([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) dnl Test for FreeSG, and define FREESG_CFLAGS and FREESG_LIBS dnl AC_DEFUN([AM_PATH_FREESG], [dnl dnl Get the cflags and libraries from the freesg-config script dnl AC_ARG_WITH(freesg-prefix,[ --with-freesg-prefix=PFX Prefix where FreeSG is installed (optional)], freesg_prefix="$withval", freesg_prefix="") AC_ARG_WITH(freesg-exec-prefix,[ --with-freesg-exec-prefix=PFX Exec prefix where FreeSG is installed (optional)], freesg_exec_prefix="$withval", freesg_exec_prefix="") AC_ARG_ENABLE(freesgtest, [ --disable-freesgtest Do not try to compile and run a test FreeSG program], , enable_freesgtest=yes) if test x$freesg_exec_prefix != x ; then freesg_config_args="$freesg_config_args --exec-prefix=$freesg_exec_prefix" if test x${FREESG_CONFIG+set} != xset ; then FREESG_CONFIG=$freesg_exec_prefix/bin/freesg-config fi fi if test x$freesg_prefix != x ; then freesg_config_args="$freesg_config_args --prefix=$freesg_prefix" if test x${FREESG_CONFIG+set} != xset ; then FREESG_CONFIG=$freesg_prefix/bin/freesg-config fi fi if test "x$prefix" != xNONE; then PATH="$prefix/bin:$prefix/usr/bin:$PATH" fi AC_PATH_PROG(FREESG_CONFIG, freesg-config, no, [$PATH]) min_freesg_version=ifelse([$1], ,0.11.0,$1) AC_MSG_CHECKING(for FreeSG - version >= $min_freesg_version) no_freesg="" if test "$FREESG_CONFIG" = "no" ; then no_freesg=yes else FREESG_CFLAGS=`$FREESG_CONFIG $freesg_config_args --cflags` FREESG_LIBS=`$FREESG_CONFIG $freesg_config_args --libs` freesg_major_version=`$FREESG_CONFIG $freesg_config_args --version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\).*/\1/'` freesg_minor_version=`$FREESG_CONFIG $freesg_config_args --version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\).*/\2/'` freesg_micro_version=`$FREESG_CONFIG $freesg_config_args --version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\).*/\3/'` if test "x$enable_freesgtest" = "xyes" ; then ac_save_CFLAGS="$CFLAGS" ac_save_CXXFLAGS="$CXXFLAGS" ac_save_LIBS="$LIBS" CFLAGS="$CFLAGS $FREESG_CFLAGS" CXXFLAGS="$CXXFLAGS $FREESG_CFLAGS" LIBS="$LIBS $FREESG_LIBS" dnl dnl Now check if the installed FreeSG is sufficiently new. (Also sanity dnl checks the results of freesg-config to some extent dnl rm -f conf.freesgtest AC_TRY_RUN([ #include #include #include #include #include char* my_strdup (char *str) { char *new_str; if (str) { new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); strcpy (new_str, str); } else new_str = NULL; return new_str; } int main (int argc, char *argv[]) { int major, minor, micro; char *tmp_version; /* This hangs on some systems (?) system ("touch conf.freesgtest"); */ { FILE *fp = fopen("conf.freesgtest", "a"); if ( fp ) fclose(fp); } /* HP/UX 9 (%@#!) writes to sscanf strings */ tmp_version = my_strdup("$min_freesg_version"); if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { printf("%s, bad version string\n", "$min_freesg_version"); exit(1); } if (($freesg_major_version > major) || (($freesg_major_version == major) && ($freesg_minor_version > minor)) || (($freesg_major_version == major) && ($freesg_minor_version == minor) && ($freesg_micro_version >= micro))) { return 0; } else { printf("\n*** 'freesg-config --version' returned %d.%d.%d, but the minimum version\n", $freesg_major_version, $freesg_minor_version, $freesg_micro_version); printf("*** of FreeSG required is %d.%d.%d. If freesg-config is correct, then it is\n", major, minor, micro); printf("*** best to upgrade to the required version.\n"); printf("*** If freesg-config was wrong, set the environment variable FREESG_CONFIG\n"); printf("*** to point to the correct copy of freesg-config, and remove the file\n"); printf("*** config.cache before re-running configure\n"); return 1; } } ],, no_freesg=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) CFLAGS="$ac_save_CFLAGS" CXXFLAGS="$ac_save_CXXFLAGS" LIBS="$ac_save_LIBS" fi fi if test "x$no_freesg" = x ; then AC_MSG_RESULT(yes) ifelse([$2], , :, [$2]) else AC_MSG_RESULT(no) if test "$FREESG_CONFIG" = "no" ; then echo "*** The freesg-config script installed by FreeSG could not be found" echo "*** If FreeSG was installed in PREFIX, make sure PREFIX/bin is in" echo "*** your path, or set the FREESG_CONFIG environment variable to the" echo "*** full path to freesg-config." else if test -f conf.freesgtest ; then : else echo "*** Could not run FreeSG test program, checking why..." CFLAGS="$CFLAGS $FREESG_CFLAGS" CXXFLAGS="$CXXFLAGS $FREESG_CFLAGS" LIBS="$LIBS $FREESG_LIBS" AC_TRY_LINK([ #include #include #include int main(int argc, char *argv[]) { return 0; } #undef main #define main K_and_R_C_main ], [ return 0; ], [ echo "*** The test program compiled, but did not run. This usually means" echo "*** that the run-time linker is not finding FreeSG or finding the wrong" echo "*** version of FreeSG. If it is not finding FreeSG, you'll need to set your" echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" echo "*** to the installed location Also, make sure you have run ldconfig if that" echo "*** is required on your system" echo "***" echo "*** If you have an old version installed, it is best to remove it, although" echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], [ echo "*** The test program failed to compile or link. See the file config.log for the" echo "*** exact error that occured. This usually means FreeSG was incorrectly installed" echo "*** or that you have moved FreeSG since it was installed. In the latter case, you" echo "*** may want to edit the freesg-config script: $FREESG_CONFIG" ]) CFLAGS="$ac_save_CFLAGS" CXXFLAGS="$ac_save_CXXFLAGS" LIBS="$ac_save_LIBS" fi fi FREESG_CFLAGS="" FREESG_LIBS="" ifelse([$3], , :, [$3]) fi AC_SUBST(FREESG_CFLAGS) AC_SUBST(FREESG_LIBS) rm -f conf.freesgtest ])