# 2008-01-08 Herbert Straub # http://www.linuxhacker.at # # Better mysqlclient detection for NDOUtils # from Ton Voon # see details: # http://altinity.blogs.com/dotorg/2007/04/better_mysqlcli.html # diff -Nru ndoutils-1.4b7-ORIG/configure.in ndoutils-1.4b7/configure.in --- ndoutils-1.4b7-ORIG/configure.in 2007-10-31 19:17:03.000000000 +0100 +++ ndoutils-1.4b7/configure.in 2008-01-08 17:42:48.000000000 +0100 @@ -170,57 +170,21 @@ AC_ARG_ENABLE(pgsql,--enable-pgsql enables PostgreSQL database support) AS_IF([test x$enable_pgsql = xno], [USE_PGSQL=no]) -dnl Optional MySQL library and include paths -AC_ARG_WITH(mysql-lib,--with-mysql-lib=DIR sets location of the MySQL client library,[ - DBLDFLAGS="-L${withval}" - LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}" - ]) -if test "$withval" = "" ; then - dnl If no library path specified, add default (RedHat) path for good measure - DBLDFLAGS="$LDFLAGS -L/usr/lib/mysql" -fi -AC_ARG_WITH(mysql-inc,--with-mysql-inc=DIR sets location of the MySQL client include files,[ - DBCFLAGS="${DBCFLAGS} -I${withval}" - ]) - -dnl Optional PostgreSQL library and include paths -AC_ARG_WITH(pgsql-lib,--with-pgsql-lib=DIR sets location of the PostgreSQL client library,[ - DBLDFLAGS="-L${withval}" - LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}" - ]) -AC_ARG_WITH(pgsql-inc,--with-pgsql-inc=DIR sets location of the PostgreSQL client include files,[ - DBCFLAGS="${DBCFLAGS} -I${withval}" - ]) - -save_LDFLAGS="$LDFLAGS" -LDFLAGS="${LDFLAGS} ${DBLDFLAGS}" -save_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="${DBCFLAGS}" -save_CFLAGS="$CFLAGS" -CFLAGS="${DBCFLAGS}" dnl Are we using any MySQL routines? if test $USE_MYSQL = yes; then - - MYSQLLIBFOUND=no - - dnl check compress lib for Mac OSX as well... - AC_CHECK_LIB(z,compress) - dnl AC_CHECK_LIB(mysqlclient,mysql_store_result,MYSQLLIBFOUND=yes,MYSQLLIBFOUND=no) - AC_CHECK_LIB(mysqlclient,mysql_store_result,MYSQLLIBFOUND=yes,) - AC_CHECK_LIB(mysqlclient,mysql_connect,MYSQLLIBFOUND=yes,) - - dnl Did we find the MySQL libraries? - if test x$MYSQLLIBFOUND = xno; then + np_mysqlclient + if test $with_mysql = "no" ; then echo "" echo "" echo "*** MySQL library could not be located... **************************" echo "" - echo "You chose to compile NDBXT with MySQL support, but I was unable to" + echo "You chose to compile NDOutils with MySQL support, but I was unable to" echo "locate the MySQL library on your system. If the library is" echo "installed, use the --with-mysql-lib argument to specify the" echo "location of the MySQL library." - echo "" + echo "installed, use the --with-mysql=DIR argument to specify the" + echo "location of the MySQL library, We assume mysql_config is in DIR/dir" echo "NOTE: After you install the necessary libraries on your system:" echo " 1. Make sure /etc/ld.so.conf has an entry for the directory in" echo " which the MySQL libraries are installed." @@ -230,45 +194,37 @@ echo " 4. Rerun the configure script." echo "" echo "TIP: Try the following...." - echo "" - echo " ./configure --with-mysql-lib=/usr/lib/mysql" + echo " ./configure --with-mysql=/usr/lib/mysql" echo "" echo "********************************************************************" echo "" echo "" USE_MYSQL=no - fi - - AC_CHECK_HEADER(mysql/mysql.h,MYSQLINCFOUND=yes,MYSQLINCFOUND=no) - - dnl Did we find the MySQL header files? - if test x$MYSQLINCFOUND = xno; then - echo "" - echo "" - echo "*** MySQL include file could not be located... **********************" - echo "" - echo "You chose to compile NDBXT with MySQL support, but I was unable to" - echo "locate on your system. If the include file is" - echo "installed, use the --with-mysql-inc argument to specify the location" - echo "of the MySQL include file." - echo "" - echo "********************************************************************" - echo "" - echo "" - - USE_MYSQL=no - - fi - - dnl We found the MySQL lib! - if test x$USE_MYSQL = xyes; then + else echo "MySQL library and include file(s) were found!" AC_DEFINE_UNQUOTED(USE_MYSQL) - DBLIBS="$DBLIBS -lmysqlclient" + DBLIBS="$DBLIBS $np_mysql_libs" + CFLAGS="$CFLAGS $np_mysql_include" fi fi +dnl Optional PostgreSQL library and include paths +AC_ARG_WITH(pgsql-lib,--with-pgsql-lib=DIR sets location of the PostgreSQL client library,[ + DBLDFLAGS="-L${withval}" + LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}" + ]) +AC_ARG_WITH(pgsql-inc,--with-pgsql-inc=DIR sets location of the PostgreSQL client include files,[ + DBCFLAGS="${DBCFLAGS} -I${withval}" + ]) + +save_LDFLAGS="$LDFLAGS" +LDFLAGS="${LDFLAGS} ${DBLDFLAGS}" +save_CPPFLAGS="$CPPFLAGS" +CPPFLAGS="${DBCFLAGS}" +save_CFLAGS="$CFLAGS" +CFLAGS="${DBCFLAGS}" + dnl Are we using any PostgreSQL routines? if test $USE_PGSQL = yes; then diff -Nru ndoutils-1.4b7-ORIG/m4/np_mysqlclient.m4 ndoutils-1.4b7/m4/np_mysqlclient.m4 --- ndoutils-1.4b7-ORIG/m4/np_mysqlclient.m4 1970-01-01 01:00:00.000000000 +0100 +++ ndoutils-1.4b7/m4/np_mysqlclient.m4 2008-01-08 17:28:05.000000000 +0100 @@ -0,0 +1,71 @@ +# np_mysqlclient.m4 +dnl Copyright (C) 2007 Nagios Plugins Team +dnl This file is free software; the Nagios Plugin Team +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Test for mysql availability using mysql_config +dnl Uses --with-mysql= yes(autodetection - default) | no | path +dnl Sets 4 variables: +dnl with_mysql = path/to/mysql_config (if found and can compile mysqlclient) or "no" +dnl np_mysql_include = flags for include, from mysql_config --include (will be guessed as $with_mysql/include if --include not found) +dnl np_mysql_libs = flags for libs, from mysql_config --libs +dnl np_mysql_cflags = flags for cflags, from mysql_config --cflags +dnl Also sets in config.h: +dnl HAVE_MYSQLCLIENT +dnl Copile your code with: +dnl $(CC) $(np_mysql_include) code.c $(np_mysql_libs) + +AC_DEFUN([np_mysqlclient], +[ + AC_ARG_WITH(mysql, + AS_HELP_STRING([--with-mysql=DIR], + [Locates mysql libraries. Expects DIR/bin/mysql_config. Default to search for mysql_config in PATH]), + with_mysql=$withval, + with_mysql=yes) + + if test "x$with_mysql" != "xno" ; then + if test "x$with_mysql" = "xyes" ; then + AC_PATH_PROG(np_mysql_config, mysql_config) + else + if test -x $with_mysql/bin/mysql_config ; then + np_mysql_config="$with_mysql/bin/mysql_config" + fi + fi + if test -z "$np_mysql_config"; then + with_mysql="no" + else + np_mysql_include="`$np_mysql_config --include`" + # Mysql 3 does not support --include. --cflags should be sufficient + if test $? -ne 0; then + np_mysql_include="-I$with_mysql/include" # Guessed location + fi + np_mysql_libs="`$np_mysql_config --libs`" + np_mysql_cflags="`$np_mysql_config --cflags`" + + dnl Test a mysql_init. Some systems have mysql_config, but no headers + _savedcppflags="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $np_mysql_include" + + dnl Putting $np_mysql_libs as other libraries ensures that all mysql dependencies are linked in + dnl Although -lmysqlclient is duplicated, it is not a problem + AC_CHECK_LIB([mysqlclient], [mysql_init], [ + with_mysql=$np_mysql_config + AC_DEFINE(HAVE_MYSQLCLIENT, 1, [Defined if mysqlclient is found and can compile]) + ], [with_mysql=no], [$np_mysql_libs]) + CPPFLAGS=$_savedcppflags + + fi + fi +]) + +dnl Will take $1, find last occurrance of -LDIR and add DIR to LD_RUN_PATH +AC_DEFUN([np_add_to_runpath], +[ + dnl Need [[ ]] so autoconf gives us just one set + np_libdir=`echo "$1" | sed -e 's/.*-L\([[^ ]]*\) .*/\1/'` + if test "x$np_libdir" != x ; then + LD_RUN_PATH="${np_libdir}${LD_RUN_PATH:+:}${LD_RUN_PATH}" + fi +]) + diff -Nru ndoutils-1.4b7-ORIG/Makefile.in ndoutils-1.4b7/Makefile.in --- ndoutils-1.4b7-ORIG/Makefile.in 2007-10-03 20:58:48.000000000 +0200 +++ ndoutils-1.4b7/Makefile.in 2008-01-08 17:42:23.000000000 +0100 @@ -10,15 +10,15 @@ SRC_INCLUDE=./include/ all: - cd $(SRC_BASE); $(MAKE) ; cd .. + cd $(SRC_BASE) && $(MAKE) clean: - cd $(SRC_BASE); $(MAKE) $@ ; cd .. + cd $(SRC_BASE) && $(MAKE) $@ rm -f core rm -f *~ */*~ include/nagios-*/*~ distclean: clean - cd $(SRC_BASE); $(MAKE) $@ ; cd .. + cd $(SRC_BASE) && $(MAKE) $@ rm -f config.log config.status config.cache $(SRC_INCLUDE)/config.h rm -f Makefile rm -f init-script.suse subst