Bring configure support for LZ4 up to snuff.
authorTom Lane <[email protected]>
Sun, 21 Mar 2021 21:20:17 +0000 (17:20 -0400)
committerTom Lane <[email protected]>
Sun, 21 Mar 2021 21:20:17 +0000 (17:20 -0400)
It's not okay to just shove the pkg_config results right into our
build flags, for a couple different reasons:

* This fails to maintain the separation between CPPFLAGS and CFLAGS,
as well as that between LDFLAGS and LIBS.  (The CPPFLAGS angle is,
I believe, the reason for warning messages reported when building
with MacPorts' liblz4.)

* If pkg_config emits anything other than -I/-D/-L/-l switches,
it's highly unlikely that we want to absorb those.  That'd be more
likely to break the build than do anything helpful.  (Even the -D
case is questionable; but we're doing that for libxml2, so I kept it.)

Also, it's not okay to skip doing an AC_CHECK_LIB probe, as
evidenced by recent build failure on topminnow; that should
have been caught at configure time.

Model fixes for this on configure's libxml2 support.

It appears that somebody overlooked an autoheader run, too.

Discussion: https://postgr.es/m/20210119190720[email protected]

configure
configure.ac
src/include/pg_config.h.in
src/tools/msvc/Solution.pm

index 6d34243dca2c09d32410995d20da65e01fe238ec..fe66b79d69ae4094a71cbb7be69de0292018f883 100755 (executable)
--- a/configure
+++ b/configure
@@ -8699,8 +8699,18 @@ else
 $as_echo "yes" >&6; }
 
 fi
-  LIBS="$LZ4_LIBS $LIBS"
-  CFLAGS="$LZ4_CFLAGS $CFLAGS"
+  # We only care about -I, -D, and -L switches;
+  # note that -llz4 will be added by AC_CHECK_LIB below.
+  for pgac_option in $LZ4_CFLAGS; do
+    case $pgac_option in
+      -I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
+    esac
+  done
+  for pgac_option in $LZ4_LIBS; do
+    case $pgac_option in
+      -L*) LDFLAGS="$LDFLAGS $pgac_option";;
+    esac
+  done
 fi
 
 #
 
 fi
 
+if test "$with_lz4" = yes ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LZ4_compress_default in -llz4" >&5
+$as_echo_n "checking for LZ4_compress_default in -llz4... " >&6; }
+if ${ac_cv_lib_lz4_LZ4_compress_default+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-llz4  $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 LZ4_compress_default ();
+int
+main ()
+{
+return LZ4_compress_default ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_lz4_LZ4_compress_default=yes
+else
+  ac_cv_lib_lz4_LZ4_compress_default=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_lz4_LZ4_compress_default" >&5
+$as_echo "$ac_cv_lib_lz4_LZ4_compress_default" >&6; }
+if test "x$ac_cv_lib_lz4_LZ4_compress_default" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBLZ4 1
+_ACEOF
+
+  LIBS="-llz4 $LIBS"
+
+else
+  as_fn_error $? "library 'lz4' is required for LZ4 support" "$LINENO" 5
+fi
+
+fi
+
 # Note: We can test for libldap_r only after we know PTHREAD_LIBS
 if test "$with_ldap" = yes ; then
   _LIBS="$LIBS"
index e54e2fb632c110dbe267f71d1d1277c00ea76c10..76568d1e4b0477b9adc3b597ec3fe45af9d86f7b 100644 (file)
@@ -997,8 +997,18 @@ AC_SUBST(with_lz4)
 
 if test "$with_lz4" = yes; then
   PKG_CHECK_MODULES(LZ4, liblz4)
-  LIBS="$LZ4_LIBS $LIBS"
-  CFLAGS="$LZ4_CFLAGS $CFLAGS"
+  # We only care about -I, -D, and -L switches;
+  # note that -llz4 will be added by AC_CHECK_LIB below.
+  for pgac_option in $LZ4_CFLAGS; do
+    case $pgac_option in
+      -I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
+    esac
+  done
+  for pgac_option in $LZ4_LIBS; do
+    case $pgac_option in
+      -L*) LDFLAGS="$LDFLAGS $pgac_option";;
+    esac
+  done
 fi
 
 #
@@ -1271,6 +1281,10 @@ if test "$with_libxslt" = yes ; then
   AC_CHECK_LIB(xslt, xsltCleanupGlobals, [], [AC_MSG_ERROR([library 'xslt' is required for XSLT support])])
 fi
 
+if test "$with_lz4" = yes ; then
+  AC_CHECK_LIB(lz4, LZ4_compress_default, [], [AC_MSG_ERROR([library 'lz4' is required for LZ4 support])])
+fi
+
 # Note: We can test for libldap_r only after we know PTHREAD_LIBS
 if test "$with_ldap" = yes ; then
   _LIBS="$LIBS"
index d873c177cb71bcf2f8930d9df48716c3b347b78d..fcbf33670484bb350c5d6f7c217f8f0c35e530ac 100644 (file)
 /* Define to 1 if you have the `ldap_r' library (-lldap_r). */
 #undef HAVE_LIBLDAP_R
 
+/* Define to 1 if you have the `lz4' library (-llz4). */
+#undef HAVE_LIBLZ4
+
 /* Define to 1 if you have the `m' library (-lm). */
 #undef HAVE_LIBM
 
 /* Define to 1 if `long long int' works and is 64 bits. */
 #undef HAVE_LONG_LONG_INT_64
 
+/* Define to 1 if you have the <lz4.h> header file. */
+#undef HAVE_LZ4_H
+
+/* Define to 1 if you have the <lz4/lz4.h> header file. */
+#undef HAVE_LZ4_LZ4_H
+
 /* Define to 1 if you have the <mbarrier.h> header file. */
 #undef HAVE_MBARRIER_H
 
 /* Define to 1 to build with LLVM based JIT support. (--with-llvm) */
 #undef USE_LLVM
 
-/* Define to 1 to build with LZ4 support (--with-lz4) */
+/* Define to 1 to build with LZ4 support. (--with-lz4) */
 #undef USE_LZ4
 
 /* Define to select named POSIX semaphores. */
index ea8ed4be30929649f0b3eea09b58d99752c7261d..9342347c9e532a9b57a707b6a2aa41c9c50f2b88 100644 (file)
@@ -298,6 +298,7 @@ sub GenerateFiles
        HAVE_LIBCRYPTO                              => undef,
        HAVE_LIBLDAP                                => undef,
        HAVE_LIBLDAP_R                              => undef,
+       HAVE_LIBLZ4                                 => undef,
        HAVE_LIBM                                   => undef,
        HAVE_LIBPAM                                 => undef,
        HAVE_LIBREADLINE                            => undef,
@@ -311,6 +312,8 @@ sub GenerateFiles
        HAVE_LOCALE_T               => 1,
        HAVE_LONG_INT_64            => undef,
        HAVE_LONG_LONG_INT_64       => 1,
+       HAVE_LZ4_H                  => undef,
+       HAVE_LZ4_LZ4_H              => undef,
        HAVE_MBARRIER_H             => undef,
        HAVE_MBSTOWCS_L             => 1,
        HAVE_MEMORY_H               => 1,