Blob Blame History Raw
From 993a7802a8d7be32b76c5ae782f63b54804c5ef3 Mon Sep 17 00:00:00 2001
From: ygrek <ygrek@autistici.org>
Date: Tue, 4 Jul 2017 14:17:42 -0700
Subject: [PATCH] improve check for link flags (close #11)

(cherry picked from commit 60eada32c875c8442c39fb51de533924c15f6e93)
---
 Makefile.in  |   8 ++---
 config.h.in  |   3 --
 configure    | 116 ++++++-----------------------------------------------------
 configure.ac |  18 +++++-----
 4 files changed, 23 insertions(+), 122 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 8cb6645..8d305ca 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -7,11 +7,11 @@ VERSION=@PACKAGE_VERSION@
 LIBINSTALL_FILES=$(wildcard *.mli *.cmi *.cma *.cmx *.cmxa *.a *.so)
 
 CFLAGS=@CFLAGS@ @DEFS@ -Wall -Wextra
-CLIBS=$(foreach lib, @LIBS@, $(subst -l,,${lib}))
 CPPFLAGS=@CPPFLAGS@
-LDFLAGS=@LDFLAGS@
-export OCAMLMKLIB_FLAGS=@LDFLAGS@
-export OCAMLFIND_INSTFLAGS=-patch-version "$(VERSION)"
+CLIBS=$(foreach x, $(filter -l%, @MYSQL_LINK_FLAGS@), $(patsubst -l%,%,${x}))
+LDFLAGS=$(filter-out -l%, @MYSQL_LINK_FLAGS@)
+OCAMLMKLIB_FLAGS=$(LDFLAGS)
+OCAMLFIND_INSTFLAGS=-patch-version "$(VERSION)"
 
 build: all opt
 all: byte-code-library 
diff --git a/config.h.in b/config.h.in
index 006275f..6aab0ef 100644
--- a/config.h.in
+++ b/config.h.in
@@ -3,9 +3,6 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
-/* Define to 1 if you have the `mysqlclient' library (-lmysqlclient). */
-#undef HAVE_LIBMYSQLCLIENT
-
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
diff --git a/configure b/configure
index 934605a..fa21110 100755
--- a/configure
+++ b/configure
@@ -620,6 +620,7 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+MYSQL_LINK_FLAGS
 EGREP
 GREP
 CPP
@@ -1500,52 +1501,6 @@ fi
 
 } # ac_fn_c_try_run
 
-# ac_fn_c_try_link LINENO
-# -----------------------
-# Try to link conftest.$ac_ext, and return whether this succeeded.
-ac_fn_c_try_link ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  rm -f conftest.$ac_objext conftest$ac_exeext
-  if { { ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    grep -v '^ *+' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-    mv -f conftest.er1 conftest.err
-  fi
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext && {
-	 test "$cross_compiling" = yes ||
-	 test -x conftest$ac_exeext
-       }; then :
-  ac_retval=0
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_retval=1
-fi
-  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
-  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
-  # interfere with the next link command; also delete a directory that is
-  # left behind by Apple's compiler.  We do this before executing the actions.
-  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-  as_fn_set_status $ac_retval
-
-} # ac_fn_c_try_link
-
 # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
 # -------------------------------------------------------
 # Tests whether HEADER exists, giving a warning if it cannot be compiled using
@@ -3439,67 +3394,18 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MYSQL_INCLUDE" >&5
 $as_echo "$MYSQL_INCLUDE" >&6; }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql_config pkglibdir" >&5
-$as_echo_n "checking for mysql_config pkglibdir... " >&6; }
-MYSQL_LIBDIR=`mysql_config --variable=pkglibdir`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql_config libs" >&5
+$as_echo_n "checking for mysql_config libs... " >&6; }
+MYSQL_LINK_FLAGS=`mysql_config --libs`
 if  test "$?" -eq 0 ; then :
-  LDFLAGS="-L$MYSQL_LIBDIR $LDFLAGS"
+  LDFLAGS="$MYSQL_LINK_FLAGS $LDFLAGS"
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MYSQL_LIBDIR" >&5
-$as_echo "$MYSQL_LIBDIR" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MYSQL_LINK_FLAGS" >&5
+$as_echo "$MYSQL_LINK_FLAGS" >&6; }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for MySQL library..." >&5
-$as_echo "$as_me: checking for MySQL library..." >&6;}
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql_real_connect in -lmysqlclient" >&5
-$as_echo_n "checking for mysql_real_connect in -lmysqlclient... " >&6; }
-if ${ac_cv_lib_mysqlclient_mysql_real_connect+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lmysqlclient  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
 
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char mysql_real_connect ();
-int
-main ()
-{
-return mysql_real_connect ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_mysqlclient_mysql_real_connect=yes
-else
-  ac_cv_lib_mysqlclient_mysql_real_connect=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mysqlclient_mysql_real_connect" >&5
-$as_echo "$ac_cv_lib_mysqlclient_mysql_real_connect" >&6; }
-if test "x$ac_cv_lib_mysqlclient_mysql_real_connect" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBMYSQLCLIENT 1
-_ACEOF
-
-  LIBS="-lmysqlclient $LIBS"
-
-else
-  as_fn_error $? "MySQL client library not found" "$LINENO" 5
-fi
-
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for MySQL header files..." >&5
-$as_echo "$as_me: checking for MySQL header files..." >&6;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql.h..." >&5
+$as_echo "$as_me: checking for mysql.h..." >&6;}
 # On IRIX 5.3, sys/types and inttypes.h are conflicting.
 for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
 		  inttypes.h stdint.h unistd.h
@@ -3517,7 +3423,7 @@ fi
 done
 
 
-for ac_header in mysql.h mysql/mysql.h mysql.h
+for ac_header in mysql.h mysql/mysql.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -3531,7 +3437,7 @@ fi
 done
 
 if test "$ac_cv_header_mysql_mysql_h" != "yes" -a "$ac_cv_header_mysql_h" != "yes"; then
-    as_fn_error $? "MySQL headers not found" "$LINENO" 5
+    as_fn_error $? "mysql.h not found" "$LINENO" 5
 fi
 
 ac_config_headers="$ac_config_headers config.h"
diff --git a/configure.ac b/configure.ac
index b6ace80..3ba4096 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,18 +19,16 @@ MYSQL_INCLUDE=`mysql_config --include`
 AS_IF([ test "$?" -eq 0 ],[CPPFLAGS="$MYSQL_INCLUDE $CPPFLAGS"],)
 AC_MSG_RESULT([$MYSQL_INCLUDE])
 
-AC_MSG_CHECKING([for mysql_config pkglibdir])
-MYSQL_LIBDIR=`mysql_config --variable=pkglibdir`
-AS_IF([ test "$?" -eq 0 ],[LDFLAGS="-L$MYSQL_LIBDIR $LDFLAGS"],)
-AC_MSG_RESULT([$MYSQL_LIBDIR])
+AC_MSG_CHECKING([for mysql_config libs])
+MYSQL_LINK_FLAGS=`mysql_config --libs`
+AS_IF([ test "$?" -eq 0 ],[LDFLAGS="$MYSQL_LINK_FLAGS $LDFLAGS"],)
+AC_MSG_RESULT([$MYSQL_LINK_FLAGS])
+AC_SUBST(MYSQL_LINK_FLAGS)
 
-AC_CHECKING([for MySQL library])
-AC_CHECK_LIB(mysqlclient, mysql_real_connect, [], [AC_MSG_ERROR([MySQL client library not found])])
-
-AC_CHECKING([for MySQL header files])
-AC_CHECK_HEADERS([mysql.h mysql/mysql.h mysql.h], [break])
+AC_CHECKING([for mysql.h])
+AC_CHECK_HEADERS([mysql.h mysql/mysql.h], [break])
 if test "$ac_cv_header_mysql_mysql_h" != "yes" -a "$ac_cv_header_mysql_h" != "yes"; then
-    AC_MSG_ERROR([MySQL headers not found])
+    AC_MSG_ERROR([mysql.h not found])
 fi
 
 AC_CONFIG_HEADERS([config.h])
-- 
2.13.2