List:MySQL++« Previous MessageNext Message »
From:Adrian Cornish Date:July 3 2014 12:13am
Subject:RFC to add option to use mysql_config
View as plain text  
I tried building Trunk with MariaDB 10  - and ran into some link
issues during bootstrapping because it looks like Maria requires a lot
more libraries

My autoconf stuff is not very good, this seems to work for me - but
what should I do to improve it

I think all modern mysql/mariadb's come with mysql_config now.


Index: config/mysql_loc.m4
===================================================================
--- config/mysql_loc.m4 (revision 2768)
+++ config/mysql_loc.m4 (working copy)
@@ -4,9 +4,10 @@
 dnl
 dnl We define the following configure script flags:
 dnl
+dnl --with-mysql-config: Use mysql_config for lib/header locations
 dnl --with-mysql: Give prefix for both library and headers, and try
 dnl to guess subdirectory names for each by tacking common
-dnl         suffixes on like /lib and /include.
+dnl suffixes on like /lib and /include.
 dnl --with-mysql-lib: Same as --with-mysql, but for library only.
 dnl --with-mysql-include: Same as --with-mysql, but for headers only.
 dnl
@@ -17,6 +18,10 @@
  #
  # Set up configure script macros
  #
+ AC_ARG_WITH(mysql-config,
+ [  --with-mysql-config=<path> path to mysql_config],
+ [MYSQL_config="mysql_config"],
+ [MYSQL_config="$with_mysql_config"])
  AC_ARG_WITH(mysql,
  [  --with-mysql=<path>     root directory path of MySQL installation],
  [MYSQL_lib_check="$with_mysql/lib/mysql $with_mysql/lib"
@@ -36,8 +41,10 @@
  if test "x$acx_pthread_ok" = xyes
  then
  MYSQL_C_LIB_NAME=mysqlclient_r
+ MYSQL_config_arg="--libs_r"
  else
  MYSQL_C_LIB_NAME=mysqlclient
+ MYSQL_config_arg="--libs"
  fi

  #
@@ -45,90 +52,99 @@
  #
  AC_MSG_CHECKING([for MySQL library directory])
  MYSQL_C_LIB_DIR=
- for m in $MYSQL_lib_check
- do
- if test -d "$m" && \
- (test -f "$m/lib$MYSQL_C_LIB_NAME.so" || \
- test -f "$m/lib$MYSQL_C_LIB_NAME.a")
+ if test -z "$MYSQL_config"
+ then
+ for m in $MYSQL_lib_check
+ do
+ if test -d "$m" && \
+ (test -f "$m/lib$MYSQL_C_LIB_NAME.so" || \
+ test -f "$m/lib$MYSQL_C_LIB_NAME.a")
+ then
+ MYSQL_C_LIB_DIR=$m
+ break
+ fi
+ done
+
+ if test -z "$MYSQL_C_LIB_DIR"
  then
- MYSQL_C_LIB_DIR=$m
- break
+ AC_MSG_ERROR([Didn't find $MYSQL_C_LIB_NAME library in '$MYSQL_lib_check'])
  fi
- done

- if test -z "$MYSQL_C_LIB_DIR"
- then
- AC_MSG_ERROR([Didn't find $MYSQL_C_LIB_NAME library in '$MYSQL_lib_check'])
- fi
+ case "$MYSQL_C_LIB_DIR" in
+ /* ) ;;
+ * )  AC_MSG_ERROR([The MySQL library directory ($MYSQL_C_LIB_DIR)
must be an absolute path.]) ;;
+ esac

- case "$MYSQL_C_LIB_DIR" in
- /* ) ;;
- * )  AC_MSG_ERROR([The MySQL library directory ($MYSQL_C_LIB_DIR)
must be an absolute path.]) ;;
- esac
+ AC_MSG_RESULT([$MYSQL_C_LIB_DIR])

- AC_MSG_RESULT([$MYSQL_C_LIB_DIR])
+ case "$MYSQL_C_LIB_DIR" in
+  /usr/lib)
+ MYSQL_C_LIB_DIR=
+ ;;
+  *)
+ LDFLAGS="$LDFLAGS -L${MYSQL_C_LIB_DIR}"
+ ;;
+ esac

- case "$MYSQL_C_LIB_DIR" in
-  /usr/lib)
- MYSQL_C_LIB_DIR=
-   ;;
-  *)
-   LDFLAGS="$LDFLAGS -L${MYSQL_C_LIB_DIR}"
- ;;
- esac

+ #
+ # Look for MySQL C API headers
+ #
+ AC_MSG_CHECKING([for MySQL include directory])
+ MYSQL_C_INC_DIR=
+ for m in $MYSQL_inc_check
+ do
+ if test -d "$m" && test -f "$m/mysql.h"
+ then
+ MYSQL_C_INC_DIR=$m
+ break
+ fi
+ done

- #
- # Look for MySQL C API headers
- #
- AC_MSG_CHECKING([for MySQL include directory])
- MYSQL_C_INC_DIR=
- for m in $MYSQL_inc_check
- do
- if test -d "$m" && test -f "$m/mysql.h"
+ if test -z "$MYSQL_C_INC_DIR"
  then
- MYSQL_C_INC_DIR=$m
- break
+ AC_MSG_ERROR([Didn't find the MySQL include dir in '$MYSQL_inc_check'])
  fi
- done

- if test -z "$MYSQL_C_INC_DIR"
- then
- AC_MSG_ERROR([Didn't find the MySQL include dir in '$MYSQL_inc_check'])
- fi
+ case "$MYSQL_C_INC_DIR" in
+ /* ) ;;
+ * )  AC_MSG_ERROR([The MySQL include directory ($MYSQL_C_INC_DIR)
must be an absolute path.]) ;;
+ esac

- case "$MYSQL_C_INC_DIR" in
- /* ) ;;
- * )  AC_MSG_ERROR([The MySQL include directory ($MYSQL_C_INC_DIR)
must be an absolute path.]) ;;
- esac
+ AC_MSG_RESULT([$MYSQL_C_INC_DIR])

- AC_MSG_RESULT([$MYSQL_C_INC_DIR])
+ CPPFLAGS="$CPPFLAGS -I${MYSQL_C_INC_DIR}"
+ LIBS="$LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
+ else
+ CPPFLAGS="$CPPFLAGS `$MYSQL_config --cflags`"
+ LIBS="$LIBS `$MYSQL_config $MYSQL_config_arg`"
+ MYSQL_C_INC_DIR="`$MYSQL_config --include`"
+ MYSQL_C_LIB_DIR="$LIBS"
+ LDFLAGS="$LDFLAGS $LIBS"
+ fi

- CPPFLAGS="$CPPFLAGS -I${MYSQL_C_INC_DIR}"
-
-    AC_MSG_CHECKING([if we can link to MySQL C API library directly])
  save_LIBS=$LIBS
- LIBS="$LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
+ AC_MSG_CHECKING([if we can link to MySQL C API library directly])
  AC_TRY_LINK(
-        [ #include <mysql.h> ],
-        [ mysql_store_result(0); ],
-        AC_MSG_RESULT([yes]),
-        [ AC_MSG_RESULT([no])
-          LIBS="$save_LIBS"
-          AC_CHECK_HEADERS(zlib.h, AC_CHECK_LIB(z, gzread, [],
-              [ AC_MSG_ERROR([zlib not found]) ]))
-          AC_MSG_CHECKING([whether adding -lz will let MySQL C API
link succeed])
-          MYSQLPP_EXTRA_LIBS="$MYSQLPP_EXTRA_LIBS -lz"
-          LIBS="$save_LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
-          AC_TRY_LINK(
-              [ #include <mysql.h> ],
-              [ mysql_store_result(0); ],
-              AC_MSG_RESULT([yes]),
-              [ AC_MSG_RESULT([no])
-                AC_MSG_ERROR([Unable to link to MySQL client library!])
-              ]
-          )
-        ])
+  [ #include <mysql.h> ],
+  [ mysql_store_result(0); ],
+  AC_MSG_RESULT([yes]),
+  [ AC_MSG_RESULT([no])
+ LIBS="$save_LIBS"
+ AC_CHECK_HEADERS(zlib.h, AC_CHECK_LIB(z, gzread, [],
+  [ AC_MSG_ERROR([zlib not found]) ]))
+ AC_MSG_CHECKING([whether adding -lz will let MySQL C API link succeed])
+ MYSQLPP_EXTRA_LIBS="$MYSQLPP_EXTRA_LIBS -lz"
+ LIBS="$save_LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
+ AC_TRY_LINK(
+  [ #include <mysql.h> ],
+  [ mysql_store_result(0); ],
+  AC_MSG_RESULT([yes]),
+  [ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([Unable to link to MySQL client library!])
+  ]
+ )
+  ])
  LIBS=$save_LIBS

  AC_SUBST(MYSQL_C_INC_DIR)

Index: config/mysql_loc.m4
===================================================================
--- config/mysql_loc.m4	(revision 2768)
+++ config/mysql_loc.m4	(working copy)
@@ -4,9 +4,10 @@
 dnl
 dnl We define the following configure script flags:
 dnl
+dnl		--with-mysql-config: Use mysql_config for lib/header locations
 dnl		--with-mysql: Give prefix for both library and headers, and try
 dnl			to guess subdirectory names for each by tacking common
-dnl         suffixes on like /lib and /include.
+dnl			suffixes on like /lib and /include.
 dnl		--with-mysql-lib: Same as --with-mysql, but for library only.
 dnl		--with-mysql-include: Same as --with-mysql, but for headers only.
 dnl
@@ -17,6 +18,10 @@
 	#
 	# Set up configure script macros
 	#
+	AC_ARG_WITH(mysql-config,
+		[  --with-mysql-config=<path> path to mysql_config],
+		[MYSQL_config="mysql_config"],
+		[MYSQL_config="$with_mysql_config"])
 	AC_ARG_WITH(mysql,
 		[  --with-mysql=<path>     root directory path of MySQL installation],
 		[MYSQL_lib_check="$with_mysql/lib/mysql $with_mysql/lib"
@@ -36,8 +41,10 @@
 	if test "x$acx_pthread_ok" = xyes
 	then
 		MYSQL_C_LIB_NAME=mysqlclient_r
+		MYSQL_config_arg="--libs_r"
 	else
 		MYSQL_C_LIB_NAME=mysqlclient
+		MYSQL_config_arg="--libs"
 	fi
 
 	#
@@ -45,90 +52,99 @@
 	#
 	AC_MSG_CHECKING([for MySQL library directory])
 	MYSQL_C_LIB_DIR=
-	for m in $MYSQL_lib_check
-	do
-		if test -d "$m" && \
-			(test -f "$m/lib$MYSQL_C_LIB_NAME.so" || \
-			 test -f "$m/lib$MYSQL_C_LIB_NAME.a")
+	if test -z "$MYSQL_config"
+	then
+		for m in $MYSQL_lib_check
+		do
+			if test -d "$m" && \
+				(test -f "$m/lib$MYSQL_C_LIB_NAME.so" || \
+				 test -f "$m/lib$MYSQL_C_LIB_NAME.a")
+			then
+				MYSQL_C_LIB_DIR=$m
+				break
+			fi
+		done
+
+		if test -z "$MYSQL_C_LIB_DIR"
 		then
-			MYSQL_C_LIB_DIR=$m
-			break
+			AC_MSG_ERROR([Didn't find $MYSQL_C_LIB_NAME library in '$MYSQL_lib_check'])
 		fi
-	done
 
-	if test -z "$MYSQL_C_LIB_DIR"
-	then
-		AC_MSG_ERROR([Didn't find $MYSQL_C_LIB_NAME library in '$MYSQL_lib_check'])
-	fi
+		case "$MYSQL_C_LIB_DIR" in
+			/* ) ;;
+			* )  AC_MSG_ERROR([The MySQL library directory ($MYSQL_C_LIB_DIR) must be an absolute path.]) ;;
+		esac
 
-	case "$MYSQL_C_LIB_DIR" in
-		/* ) ;;
-		* )  AC_MSG_ERROR([The MySQL library directory ($MYSQL_C_LIB_DIR) must be an absolute path.]) ;;
-	esac
+		AC_MSG_RESULT([$MYSQL_C_LIB_DIR])
 
-	AC_MSG_RESULT([$MYSQL_C_LIB_DIR])
+		case "$MYSQL_C_LIB_DIR" in
+		  /usr/lib)
+			MYSQL_C_LIB_DIR=
+			;;
+		  *)
+			LDFLAGS="$LDFLAGS -L${MYSQL_C_LIB_DIR}"
+			;;
+		esac
 
-	case "$MYSQL_C_LIB_DIR" in
-	  /usr/lib)
-		MYSQL_C_LIB_DIR=
-	  	;;
-	  *)
-	  	LDFLAGS="$LDFLAGS -L${MYSQL_C_LIB_DIR}"
-		;;
-	esac
 
+		#
+		# Look for MySQL C API headers
+		#
+		AC_MSG_CHECKING([for MySQL include directory])
+		MYSQL_C_INC_DIR=
+		for m in $MYSQL_inc_check
+		do
+			if test -d "$m" && test -f "$m/mysql.h"
+			then
+				MYSQL_C_INC_DIR=$m
+				break
+			fi
+		done
 
-	#
-	# Look for MySQL C API headers
-	#
-	AC_MSG_CHECKING([for MySQL include directory])
-	MYSQL_C_INC_DIR=
-	for m in $MYSQL_inc_check
-	do
-		if test -d "$m" && test -f "$m/mysql.h"
+		if test -z "$MYSQL_C_INC_DIR"
 		then
-			MYSQL_C_INC_DIR=$m
-			break
+			AC_MSG_ERROR([Didn't find the MySQL include dir in '$MYSQL_inc_check'])
 		fi
-	done
 
-	if test -z "$MYSQL_C_INC_DIR"
-	then
-		AC_MSG_ERROR([Didn't find the MySQL include dir in '$MYSQL_inc_check'])
-	fi
+		case "$MYSQL_C_INC_DIR" in
+			/* ) ;;
+			* )  AC_MSG_ERROR([The MySQL include directory ($MYSQL_C_INC_DIR) must be an absolute path.]) ;;
+		esac
 
-	case "$MYSQL_C_INC_DIR" in
-		/* ) ;;
-		* )  AC_MSG_ERROR([The MySQL include directory ($MYSQL_C_INC_DIR) must be an absolute path.]) ;;
-	esac
+		AC_MSG_RESULT([$MYSQL_C_INC_DIR])
 
-	AC_MSG_RESULT([$MYSQL_C_INC_DIR])
+		CPPFLAGS="$CPPFLAGS -I${MYSQL_C_INC_DIR}"
+		LIBS="$LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
+	else
+		CPPFLAGS="$CPPFLAGS `$MYSQL_config --cflags`"
+		LIBS="$LIBS `$MYSQL_config $MYSQL_config_arg`"
+		MYSQL_C_INC_DIR="`$MYSQL_config --include`"
+		MYSQL_C_LIB_DIR="$LIBS"
+		LDFLAGS="$LDFLAGS $LIBS"
+	fi
 
-	CPPFLAGS="$CPPFLAGS -I${MYSQL_C_INC_DIR}"
-
-    AC_MSG_CHECKING([if we can link to MySQL C API library directly])
 	save_LIBS=$LIBS
-	LIBS="$LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
+	AC_MSG_CHECKING([if we can link to MySQL C API library directly])
 	AC_TRY_LINK(
-        [ #include <mysql.h> ],
-        [ mysql_store_result(0); ],
-        AC_MSG_RESULT([yes]),
-        [ AC_MSG_RESULT([no])	
-          LIBS="$save_LIBS"
-          AC_CHECK_HEADERS(zlib.h, AC_CHECK_LIB(z, gzread, [],
-              [ AC_MSG_ERROR([zlib not found]) ]))
-          AC_MSG_CHECKING([whether adding -lz will let MySQL C API link succeed])
-          MYSQLPP_EXTRA_LIBS="$MYSQLPP_EXTRA_LIBS -lz"
-          LIBS="$save_LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
-          AC_TRY_LINK(
-              [ #include <mysql.h> ],
-              [ mysql_store_result(0); ],
-              AC_MSG_RESULT([yes]),
-              [ AC_MSG_RESULT([no])
-                AC_MSG_ERROR([Unable to link to MySQL client library!])
-              ]
-          )
-        ])
+		  [ #include <mysql.h> ],
+		  [ mysql_store_result(0); ],
+		  AC_MSG_RESULT([yes]),
+		  [ AC_MSG_RESULT([no]) 
+			 LIBS="$save_LIBS"
+			 AC_CHECK_HEADERS(zlib.h, AC_CHECK_LIB(z, gzread, [],
+				  [ AC_MSG_ERROR([zlib not found]) ]))
+			 AC_MSG_CHECKING([whether adding -lz will let MySQL C API link succeed])
+			 MYSQLPP_EXTRA_LIBS="$MYSQLPP_EXTRA_LIBS -lz"
+			 LIBS="$save_LIBS -l$MYSQL_C_LIB_NAME $MYSQLPP_EXTRA_LIBS"
+			 AC_TRY_LINK(
+				  [ #include <mysql.h> ],
+				  [ mysql_store_result(0); ],
+				  AC_MSG_RESULT([yes]),
+				  [ AC_MSG_RESULT([no])
+					 AC_MSG_ERROR([Unable to link to MySQL client library!])
+				  ]
+			 )
+		  ])
 	LIBS=$save_LIBS
 
 	AC_SUBST(MYSQL_C_INC_DIR)
Thread
RFC to add option to use mysql_configAdrian Cornish3 Jul 2014
  • Re: RFC to add option to use mysql_configWarren Young4 Jul 2014
    • Re: RFC to add option to use mysql_configWarren Young4 Jul 2014
      • Re: RFC to add option to use mysql_configAdrian Cornish4 Jul 2014
        • Re: RFC to add option to use mysql_configWarren Young9 Jul 2014