From 73b2b5132acc318ea889d76f4befcbf33584be19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Fri, 14 Jul 2017 15:29:30 +0200
Subject: [PATCH 2/2] Use MySQL parameters also for DLZ modules

---
 configure                                          | 147 +++++++++++++++++----
 configure.in                                       |   8 +-
 contrib/dlz/config.dlz.in                          |   2 +
 .../dlz/modules/mysql/{Makefile => Makefile.in}    |   4 +-
 .../dlz/modules/mysqldyn/{Makefile => Makefile.in} |   4 +-
 5 files changed, 135 insertions(+), 30 deletions(-)
 rename contrib/dlz/modules/mysql/{Makefile => Makefile.in} (81%)
 rename contrib/dlz/modules/mysqldyn/{Makefile => Makefile.in} (81%)

diff --git a/configure b/configure
index e10f513..eda8601 100755
--- a/configure
+++ b/configure
@@ -646,12 +646,15 @@ BUILD_LDFLAGS
 BUILD_CPPFLAGS
 BUILD_CFLAGS
 BUILD_CC
+DLZ_DRIVER_MYSQL_LIBS
+DLZ_DRIVER_MYSQL_INCLUDES
 DLZ_SYSTEM_TEST
 DLZ_DRIVER_OBJS
 DLZ_DRIVER_SRCS
 DLZ_DRIVER_LIBS
 DLZ_DRIVER_INCLUDES
 CONTRIB_DLZ
+MYSQL_CONFIG
 PG_CONFIG
 SO_TARGETS
 SO_STRIP
@@ -22271,6 +22274,8 @@ DLZ_DRIVER_LIBS=""
 DLZ_DRIVER_SRCS=""
 DLZ_DRIVER_OBJS=""
 DLZ_SYSTEM_TEST=""
+DLZ_DRIVER_MYSQL_INCLUDES=""
+DLZ_DRIVER_MYSQL_LIBS=""
 
 #
 # Configure support for building a shared library object
@@ -22647,10 +22652,12 @@ $as_echo "no" >&6; }
 	if test -n "-I$use_dlz_postgres"
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES -I$use_dlz_postgres"
+		DLZ_DRIVER_POSTGRES_INCLUDES="-I$use_dlz_postgres"
 	fi
 	if test -n "-L$use_dlz_postgres_lib -lpq"
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS -L$use_dlz_postgres_lib -lpq"
+		DLZ_DRIVER_POSTGRES_LIBS="-L$use_dlz_postgres_lib -lpq"
 	fi
 
 
@@ -22675,38 +22682,89 @@ else
 fi
 
 
+for ac_prog in mysql_config
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_MYSQL_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$MYSQL_CONFIG"; then
+  ac_cv_prog_MYSQL_CONFIG="$MYSQL_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_MYSQL_CONFIG="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+MYSQL_CONFIG=$ac_cv_prog_MYSQL_CONFIG
+if test -n "$MYSQL_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MYSQL_CONFIG" >&5
+$as_echo "$MYSQL_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$MYSQL_CONFIG" && break
+done
+
+
 mysql_include=""
 mysql_lib=""
 if test "$use_dlz_mysql" = "yes"
 then
-	# User did not specify a path - guess it
-	mysqldirs="/usr /usr/local /usr/local/mysql /usr/pkg"
-	for d in $mysqldirs
-	do
-		if test -f $d/include/mysql/mysql.h
-		then
-			use_dlz_mysql=$d
-			mysql_include=$d/include/mysql
-			if test -d $d/lib/mysql
+	if test -n "$MYSQL_CONFIG"
+	then
+		mysql_include=`${MYSQL_CONFIG} --include`
+		mysql_lib=`${MYSQL_CONFIG} --libs`
+		use_dlz_mysql="config"
+
+	else
+		# User did not specify a path - guess it
+		mysqldirs="/usr /usr/local /usr/local/mysql /usr/pkg"
+		for d in $mysqldirs
+		do
+			if test -f $d/include/mysql/mysql.h
 			then
-				mysql_lib=$d/lib/mysql
-			else
-				mysql_lib=$d/lib
-			fi
-			break
-		elif test -f $d/include/mysql.h
-		then
-			use_dlz_mysql=$d
-			mysql_include=$d/include
+				use_dlz_mysql=$d
+				mysql_include=$d/include/mysql
 			if test -d $d/lib/mysql
-			then
+				then
 				mysql_lib=$d/lib/mysql
-			else
-				mysql_lib=$d/lib
+				else
+					mysql_lib=$d/lib
+				fi
+				break
+			elif test -f $d/include/mysql.h
+			then
+				use_dlz_mysql=$d
+				mysql_include=$d/include
+				if test -d $d/lib/mysql
+				then
+					mysql_lib=$d/lib/mysql
+				else
+					mysql_lib=$d/lib
+				fi
+				break
 			fi
-			break
-		fi
-	done
+		done
+	fi
 elif test "$use_dlz_mysql" != "no"
 then
 	d=$use_dlz_mysql
@@ -22743,6 +22801,29 @@ case "$use_dlz_mysql" in
 		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 		;;
+	config)
+
+	CONTRIB_DLZ="$CONTRIB_DLZ -DDLZ_MYSQL"
+	for i in dlz_mysql_driver
+	do
+		DLZ_DRIVER_SRCS="$DLZ_DRIVER_SRCS $dlzdir/$i.c"
+		DLZ_DRIVER_OBJS="$DLZ_DRIVER_OBJS $i.$O"
+	done
+	if test -n "${mysql_include}"
+	then
+		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES ${mysql_include}"
+		DLZ_DRIVER_MYSQL_INCLUDES="${mysql_include}"
+	fi
+	if test -n "${mysql_lib}"
+	then
+		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS ${mysql_lib}"
+		DLZ_DRIVER_MYSQL_LIBS="${mysql_lib}"
+	fi
+
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: using mysql with libs ${mysql_lib} and includes ${mysql_include}" >&5
+$as_echo "using mysql with libs ${mysql_lib} and includes ${mysql_include}" >&6; }
+		;;
 	*)
 
 	CONTRIB_DLZ="$CONTRIB_DLZ -DDLZ_MYSQL"
@@ -22754,10 +22835,12 @@ $as_echo "no" >&6; }
 	if test -n "-I${mysql_include}"
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES -I${mysql_include}"
+		DLZ_DRIVER_MYSQL_INCLUDES="-I${mysql_include}"
 	fi
 	if test -n "-L${mysql_lib} -lmysqlclient -lz -lcrypt -lm"
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS -L${mysql_lib} -lmysqlclient -lz -lcrypt -lm"
+		DLZ_DRIVER_MYSQL_LIBS="-L${mysql_lib} -lmysqlclient -lz -lcrypt -lm"
 	fi
 
 
@@ -22941,10 +23024,12 @@ $as_echo "not found" >&6; }
 	if test -n "$dlz_bdb_inc"
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES $dlz_bdb_inc"
+		DLZ_DRIVER_BDB_INCLUDES="$dlz_bdb_inc"
 	fi
 	if test -n "$dlz_bdb_libs"
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS $dlz_bdb_libs"
+		DLZ_DRIVER_BDB_LIBS="$dlz_bdb_libs"
 	fi
 
 
@@ -22988,10 +23073,12 @@ $as_echo "no" >&6; }
 	if test -n ""
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES "
+		DLZ_DRIVER_FILESYSTEM_INCLUDES=""
 	fi
 	if test -n ""
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS "
+		DLZ_DRIVER_FILESYSTEM_LIBS=""
 	fi
 
 		DLZ_SYSTEM_TEST=filesystem
@@ -23053,10 +23140,12 @@ $as_echo "no" >&6; }
 	if test -n "-I$use_dlz_ldap/include"
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES -I$use_dlz_ldap/include"
+		DLZ_DRIVER_LDAP_INCLUDES="-I$use_dlz_ldap/include"
 	fi
 	if test -n "-L$use_dlz_ldap/lib -lldap -llber"
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS -L$use_dlz_ldap/lib -lldap -llber"
+		DLZ_DRIVER_LDAP_LIBS="-L$use_dlz_ldap/lib -lldap -llber"
 	fi
 
 
@@ -23174,10 +23263,12 @@ $as_echo "not found" >&6; }
 	if test -n "$dlz_odbc_include"
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES $dlz_odbc_include"
+		DLZ_DRIVER_ODBC_INCLUDES="$dlz_odbc_include"
 	fi
 	if test -n "$dlz_odbc_libs"
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS $dlz_odbc_libs"
+		DLZ_DRIVER_ODBC_LIBS="$dlz_odbc_libs"
 	fi
 
 
@@ -23219,10 +23310,12 @@ $as_echo "no" >&6; }
 	if test -n ""
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES "
+		DLZ_DRIVER_STUB_INCLUDES=""
 	fi
 	if test -n ""
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS "
+		DLZ_DRIVER_STUB_LIBS=""
 	fi
 
 
@@ -23261,7 +23354,7 @@ then
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 	DLZ_DRIVER_RULES=contrib/dlz/drivers/rules
-	ac_config_files="$ac_config_files $DLZ_DRIVER_RULES"
+	ac_config_files="$ac_config_files $DLZ_DRIVER_RULES contrib/dlz/modules/mysql/Makefile contrib/dlz/modules/mysqldyn/Makefile"
 
 else
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -23277,6 +23370,8 @@ fi
 
 
 
+
+
 if test "yes" = "$cross_compiling"; then
 	if test -z "$BUILD_CC"; then
 		as_fn_error $? "BUILD_CC not set" "$LINENO" 5
@@ -24423,6 +24518,8 @@ do
     "atf-config") CONFIG_COMMANDS="$CONFIG_COMMANDS atf-config" ;;
     "contrib/dlz/bin/dlzbdb/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/dlz/bin/dlzbdb/Makefile" ;;
     "$DLZ_DRIVER_RULES") CONFIG_FILES="$CONFIG_FILES $DLZ_DRIVER_RULES" ;;
+    "contrib/dlz/modules/mysql/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/dlz/modules/mysql/Makefile" ;;
+    "contrib/dlz/modules/mysqldyn/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/dlz/modules/mysqldyn/Makefile" ;;
     "chmod") CONFIG_COMMANDS="$CONFIG_COMMANDS chmod" ;;
     "make/Makefile") CONFIG_FILES="$CONFIG_FILES make/Makefile" ;;
     "make/mkdep") CONFIG_FILES="$CONFIG_FILES make/mkdep" ;;
diff --git a/configure.in b/configure.in
index 7886208..d3e27f3 100644
--- a/configure.in
+++ b/configure.in
@@ -4823,6 +4823,8 @@ DLZ_DRIVER_LIBS=""
 DLZ_DRIVER_SRCS=""
 DLZ_DRIVER_OBJS=""
 DLZ_SYSTEM_TEST=""
+DLZ_DRIVER_MYSQL_INCLUDES=""
+DLZ_DRIVER_MYSQL_LIBS=""
 
 # 
 # Configure support for building a shared library object
@@ -4945,7 +4947,9 @@ if test -n "$CONTRIB_DLZ"
 then
 	AC_MSG_RESULT(yes)
 	DLZ_DRIVER_RULES=contrib/dlz/drivers/rules
-	AC_CONFIG_FILES([$DLZ_DRIVER_RULES])
+	AC_CONFIG_FILES([$DLZ_DRIVER_RULES
+		contrib/dlz/modules/mysql/Makefile
+		contrib/dlz/modules/mysqldyn/Makefile])
 else
 	AC_MSG_RESULT(no)
 	DLZ_DRIVER_RULES=/dev/null
@@ -4957,6 +4961,8 @@ AC_SUBST(DLZ_DRIVER_LIBS)
 AC_SUBST(DLZ_DRIVER_SRCS)
 AC_SUBST(DLZ_DRIVER_OBJS)
 AC_SUBST(DLZ_SYSTEM_TEST)
+AC_SUBST(DLZ_DRIVER_MYSQL_INCLUDES)
+AC_SUBST(DLZ_DRIVER_MYSQL_LIBS)
 AC_SUBST_FILE(DLZ_DRIVER_RULES)
 
 if test "yes" = "$cross_compiling"; then
diff --git a/contrib/dlz/config.dlz.in b/contrib/dlz/config.dlz.in
index 69259fe..b4d8976 100644
--- a/contrib/dlz/config.dlz.in
+++ b/contrib/dlz/config.dlz.in
@@ -38,10 +38,12 @@ AC_DEFUN(DLZ_ADD_DRIVER, [
 	if test -n "$3"
 	then
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES $3"
+		DLZ_DRIVER_$1_INCLUDES="$3"
 	fi
 	if test -n "$4"
 	then
 		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS $4"
+		DLZ_DRIVER_$1_LIBS="$4"
 	fi
 ])
 
diff --git a/contrib/dlz/modules/mysql/Makefile b/contrib/dlz/modules/mysql/Makefile.in
similarity index 81%
rename from contrib/dlz/modules/mysql/Makefile
rename to contrib/dlz/modules/mysql/Makefile.in
index ad3876c..5ab31be 100644
--- a/contrib/dlz/modules/mysql/Makefile
+++ b/contrib/dlz/modules/mysql/Makefile.in
@@ -1,8 +1,8 @@
 prefix = /usr
 libdir = $(prefix)/lib/bind9
 
-CFLAGS=-fPIC -g -I../include
-MYSQL_LIBS=-lmysqlclient
+CFLAGS=-fPIC -Wall -g -I../include @DLZ_DRIVER_MYSQL_INCLUDES@
+MYSQL_LIBS=@DLZ_DRIVER_MYSQL_LIBS@
 
 all: dlz_mysql_dynamic.so
 
diff --git a/contrib/dlz/modules/mysqldyn/Makefile b/contrib/dlz/modules/mysqldyn/Makefile.in
similarity index 81%
rename from contrib/dlz/modules/mysqldyn/Makefile
rename to contrib/dlz/modules/mysqldyn/Makefile.in
index bba91af..248e3da 100644
--- a/contrib/dlz/modules/mysqldyn/Makefile
+++ b/contrib/dlz/modules/mysqldyn/Makefile.in
@@ -1,8 +1,8 @@
 prefix = /usr
 libdir = $(prefix)/lib/bind9
 
-CFLAGS=-fPIC -Wall -g -I../include
-MYSQL_LIBS=-lmysqlclient
+CFLAGS=-fPIC -Wall -g -I../include @DLZ_DRIVER_MYSQL_INCLUDES@
+MYSQL_LIBS=@DLZ_DRIVER_MYSQL_LIBS@
 
 all: dlz_mysqldyn_mod.so
 
-- 
2.9.4

