Browse Source

[2342] Enable MySQL support with flag in configure.ac

Stephen Morris 12 years ago
parent
commit
1d70d3df4d
4 changed files with 88 additions and 12 deletions
  1. 61 2
      configure.ac
  2. 15 6
      src/lib/dhcp/Makefile.am
  3. 3 4
      src/lib/dhcp/lease_mgr_factory.cc
  4. 9 0
      src/lib/dhcp/tests/Makefile.am

+ 61 - 2
configure.ac

@@ -1,5 +1,4 @@
-#                                               -*- Autoconf -*-
-# Process this file with autoconf to produce a configure script.
+CXXFLAGS Process this file with autoconf to produce a configure script.
 
 
 AC_PREREQ([2.59])
 AC_PREREQ([2.59])
 AC_INIT(bind10-devel, 20120817, bind10-dev@isc.org)
 AC_INIT(bind10-devel, 20120817, bind10-dev@isc.org)
@@ -730,6 +729,64 @@ AC_LINK_IFELSE(
 )
 )
 CPPFLAGS=$CPPFLAGS_SAVED
 CPPFLAGS=$CPPFLAGS_SAVED
 LIBS=$LIBS_SAVED
 LIBS=$LIBS_SAVED
+#===
+
+# Check for MySql.  The path to the mysql_config program is given with
+# the --with-mysql-config (default to /usr/bin/mysql-config).
+
+mysql_config="no"
+AC_ARG_WITH([mysql-config],
+  AC_HELP_STRING([--with-mysql-config=PATH],
+    [specify the path to the mysql_config script]),
+    [mysql_config="$withval"])
+
+if test "${mysql_config}" = "yes" ; then
+    MYSQL_CONFIG="/usr/bin/mysql_config"
+elif test "${mysql_config}" != "no" ; then
+    MYSQL_CONFIG="${withval}"
+fi
+
+if test "$MYSQL_CONFIG" != "" ; then
+    if test -d "$MYSQL_CONFIG" ; then
+        AC_MSG_ERROR([Specified mysql_config program ${MYSQL_CONFIG} is a directory])
+    fi
+    if ! test -x "$MYSQL_CONFIG" ; then
+        AC_MSG_ERROR([--with-mysql-config should point to a mysql_config program])
+    fi
+
+    MYSQL_CPPFLAGS=`$MYSQL_CONFIG --cflags`
+    MYSQL_LIBS=`$MYSQL_CONFIG --libs`
+
+    AC_SUBST(MYSQL_CPPFLAGS)
+    AC_SUBST(MYSQL_LIBS)
+
+    # Check that a simple program using MySQL functions can compile and link.
+    CPPFLAGS_SAVED="$CPPFLAGS"
+    LIBS_SAVED="$LIBS"
+
+    CPPFLAGS="$MYSQL_CPPFLAGS $CPPFLAGS"
+    LIBS="$MYSQL_LIBS $LIBS"
+
+    AC_LINK_IFELSE(
+            [AC_LANG_PROGRAM([#include <mysql/mysql.h>],
+                             [MYSQL mysql_handle;
+                              (void) mysql_init(&mysql_handle);
+                             ])],
+            [AC_MSG_RESULT([checking for MySQL headers and library... yes])],
+            [AC_MSG_RESULT([checking for MySQL headers and library... no])
+             AC_MSG_ERROR([Needs MySQL library])]
+    )
+
+    CPPFLAGS=$CPPFLAGS_SAVED
+    LIBS=$LIBS_SAVED
+
+    # Note that MYSQL is present in the config.h file
+    AC_DEFINE([HAVE_MYSQL], [1], [MySQL is present])
+fi
+
+# ... and at the shell level, so Makefile.am can take action depending on this.
+AM_CONDITIONAL(HAVE_MYSQL, test "$MYSQL_CONFIG" != "")
+
 
 
 # Check for log4cplus
 # Check for log4cplus
 log4cplus_path="yes"
 log4cplus_path="yes"
@@ -1409,6 +1466,8 @@ dnl includes too
                  ${LOG4CPLUS_LIBS}
                  ${LOG4CPLUS_LIBS}
   SQLite:        $SQLITE_CFLAGS
   SQLite:        $SQLITE_CFLAGS
                  $SQLITE_LIBS
                  $SQLITE_LIBS
+  MySQL:         $MYSQL_CPPFLAGS
+                 $MYSQL_LIBS
 
 
 Features:
 Features:
   $enable_features
   $enable_features

+ 15 - 6
src/lib/dhcp/Makefile.am

@@ -2,6 +2,9 @@ SUBDIRS = . tests
 
 
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += $(BOOST_INCLUDES)
+if HAVE_MYSQL
+AM_CPPFLAGS += $(MYSQL_CPPFLAGS)
+endif
 
 
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
 
@@ -24,7 +27,9 @@ libb10_dhcp___la_SOURCES += iface_mgr_sun.cc
 libb10_dhcp___la_SOURCES += lease_mgr.cc lease_mgr.h
 libb10_dhcp___la_SOURCES += lease_mgr.cc lease_mgr.h
 libb10_dhcp___la_SOURCES += lease_mgr_factory.cc lease_mgr_factory.h
 libb10_dhcp___la_SOURCES += lease_mgr_factory.cc lease_mgr_factory.h
 libb10_dhcp___la_SOURCES += libdhcp++.cc libdhcp++.h
 libb10_dhcp___la_SOURCES += libdhcp++.cc libdhcp++.h
+if HAVE_MYSQL
 libb10_dhcp___la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h
 libb10_dhcp___la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h
+endif
 libb10_dhcp___la_SOURCES += option4_addrlst.cc option4_addrlst.h
 libb10_dhcp___la_SOURCES += option4_addrlst.cc option4_addrlst.h
 libb10_dhcp___la_SOURCES += option6_addrlst.cc option6_addrlst.h
 libb10_dhcp___la_SOURCES += option6_addrlst.cc option6_addrlst.h
 libb10_dhcp___la_SOURCES += option6_iaaddr.cc option6_iaaddr.h
 libb10_dhcp___la_SOURCES += option6_iaaddr.cc option6_iaaddr.h
@@ -33,11 +38,21 @@ libb10_dhcp___la_SOURCES += option.cc option.h
 libb10_dhcp___la_SOURCES += pkt4.cc pkt4.h
 libb10_dhcp___la_SOURCES += pkt4.cc pkt4.h
 libb10_dhcp___la_SOURCES += pkt6.cc pkt6.h
 libb10_dhcp___la_SOURCES += pkt6.cc pkt6.h
 
 
+libb10_dhcp___la_CXXFLAGS = $(AM_CXXFLAGS)
+libb10_dhcp___la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
+libb10_dhcp___la_LIBADD   = $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
+libb10_dhcp___la_LIBADD  += $(top_builddir)/src/lib/util/libb10-util.la
+libb10_dhcp___la_LDFLAGS  = -no-undefined -version-info 2:0:0
+if HAVE_MYSQL
+libb10_dhcp___la_LDFLAGS += $(MYSQL_LIBS)
+endif
+
 libb10_dhcpsrv_la_SOURCES  = cfgmgr.cc cfgmgr.h
 libb10_dhcpsrv_la_SOURCES  = cfgmgr.cc cfgmgr.h
 libb10_dhcpsrv_la_SOURCES += pool.cc pool.h
 libb10_dhcpsrv_la_SOURCES += pool.cc pool.h
 libb10_dhcpsrv_la_SOURCES += subnet.cc subnet.h
 libb10_dhcpsrv_la_SOURCES += subnet.cc subnet.h
 libb10_dhcpsrv_la_SOURCES += triplet.h
 libb10_dhcpsrv_la_SOURCES += triplet.h
 libb10_dhcpsrv_la_SOURCES += addr_utilities.cc addr_utilities.h
 libb10_dhcpsrv_la_SOURCES += addr_utilities.cc addr_utilities.h
+
 libb10_dhcpsrv_la_CXXFLAGS = $(AM_CXXFLAGS)
 libb10_dhcpsrv_la_CXXFLAGS = $(AM_CXXFLAGS)
 libb10_dhcpsrv_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
 libb10_dhcpsrv_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
 libb10_dhcpsrv_la_LIBADD   = $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
 libb10_dhcpsrv_la_LIBADD   = $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
@@ -46,12 +61,6 @@ libb10_dhcpsrv_la_LDFLAGS  = -no-undefined -version-info 2:0:0
 
 
 EXTRA_DIST  = README
 EXTRA_DIST  = README
 
 
-libb10_dhcp___la_CXXFLAGS = $(AM_CXXFLAGS)
-libb10_dhcp___la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
-libb10_dhcp___la_LIBADD   = $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
-libb10_dhcp___la_LIBADD  += $(top_builddir)/src/lib/util/libb10-util.la
-libb10_dhcp___la_LDFLAGS  = -no-undefined -version-info 2:0:0
-
 if USE_CLANGPP
 if USE_CLANGPP
 # Disable unused parameter warning caused by some of the
 # Disable unused parameter warning caused by some of the
 # Boost headers when compiling with clang.
 # Boost headers when compiling with clang.

+ 3 - 4
src/lib/dhcp/lease_mgr_factory.cc

@@ -14,10 +14,6 @@
 
 
 #include "config.h"
 #include "config.h"
 
 
-// TEMP
-#define HAVE_MYSQL 1
-
-
 #include <algorithm>
 #include <algorithm>
 #include <iostream>
 #include <iostream>
 #include <iterator>
 #include <iterator>
@@ -30,7 +26,10 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string.hpp>
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
 #include <dhcp/lease_mgr_factory.h>
 #include <dhcp/lease_mgr_factory.h>
+
+#ifdef HAVE_MYSQL
 #include <dhcp/mysql_lease_mgr.h>
 #include <dhcp/mysql_lease_mgr.h>
+#endif
 
 
 using namespace std;
 using namespace std;
 
 

+ 9 - 0
src/lib/dhcp/tests/Makefile.am

@@ -4,6 +4,9 @@ AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dhcp/tests\"
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dhcp/tests\"
 AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
 AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
+# Temp
+AM_CPPFLAGS += -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing
+AM_CPPFLAGS += -DUNIV_LINUX
 
 
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
 
@@ -30,7 +33,9 @@ libdhcp___unittests_SOURCES += duid_unittest.cc
 libdhcp___unittests_SOURCES += iface_mgr_unittest.cc
 libdhcp___unittests_SOURCES += iface_mgr_unittest.cc
 libdhcp___unittests_SOURCES += lease_mgr_factory_unittest.cc
 libdhcp___unittests_SOURCES += lease_mgr_factory_unittest.cc
 libdhcp___unittests_SOURCES += lease_mgr_unittest.cc
 libdhcp___unittests_SOURCES += lease_mgr_unittest.cc
+if HAVE_MYSQL
 libdhcp___unittests_SOURCES += mysql_lease_mgr_unittest.cc
 libdhcp___unittests_SOURCES += mysql_lease_mgr_unittest.cc
+endif
 libdhcp___unittests_SOURCES += libdhcp++_unittest.cc
 libdhcp___unittests_SOURCES += libdhcp++_unittest.cc
 libdhcp___unittests_SOURCES += option4_addrlst_unittest.cc
 libdhcp___unittests_SOURCES += option4_addrlst_unittest.cc
 libdhcp___unittests_SOURCES += option6_addrlst_unittest.cc
 libdhcp___unittests_SOURCES += option6_addrlst_unittest.cc
@@ -43,6 +48,10 @@ libdhcp___unittests_SOURCES += pkt6_unittest.cc
 libdhcp___unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
 libdhcp___unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
 libdhcp___unittests_LDFLAGS  = $(AM_LDFLAGS)  $(GTEST_LDFLAGS)
 libdhcp___unittests_LDFLAGS  = $(AM_LDFLAGS)  $(GTEST_LDFLAGS)
 libdhcp___unittests_CXXFLAGS = $(AM_CXXFLAGS)
 libdhcp___unittests_CXXFLAGS = $(AM_CXXFLAGS)
+if HAVE_MYSQL
+libdhcp___unittests_CPPFLAGS += $(MYSQL_CPPFLAGS)
+libdhcp___unittests_LDFLAGS  += $(MYSQL_LIBS)
+endif
 
 
 libdhcpsrv_unittests_SOURCES  = run_unittests.cc
 libdhcpsrv_unittests_SOURCES  = run_unittests.cc
 libdhcpsrv_unittests_SOURCES += addr_utilities_unittest.cc
 libdhcpsrv_unittests_SOURCES += addr_utilities_unittest.cc