Skip to content

PHPC-1075: Import libbson and libmongoc Autotools configuration #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
365 changes: 87 additions & 278 deletions config.m4

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions scripts/build/autotools/CheckCompiler.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# If CFLAGS and CXXFLAGS are unset, default to empty.
# This is to tell automake not to include '-g' if C{XX,}FLAGS is not set.
# For more info - http://www.gnu.org/software/automake/manual/autoconf.html#C_002b_002b-Compiler
if test -z "$CXXFLAGS"; then
CXXFLAGS=""
fi
if test -z "$CFLAGS"; then
CFLAGS=""
fi

AC_PROG_CC
AC_PROG_CXX

# Check that an appropriate C compiler is available.
c_compiler="unknown"
AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#if !(defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER))
#error Not a supported GCC compiler
#endif
#if defined(__GNUC__)
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < 40100
#error Not a supported GCC compiler
#endif
#endif
])], [c_compiler="gcc"], [])

# If our BEGIN_IGNORE_DEPRECATIONS macro won't work, pass
# -Wno-deprecated-declarations

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#if !defined(__clang__) && defined(__GNUC__)
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < 40600
#error Does not support deprecation warning pragmas
#endif
#endif
])], [], [STD_CFLAGS="$STD_CFLAGS -Wno-deprecated-declarations"])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#if defined(__clang__)
#define CLANG_VERSION (__clang_major__ * 10000 \
+ __clang_minor__ * 100 \
+ __clang_patchlevel__)
#if CLANG_VERSION < 30300
#error Not a supported Clang compiler
#endif
#endif
])], [c_compiler="clang"], [])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#if !(defined(__SUNPRO_C))
#error Not a supported Sun compiler
#endif
])], [c_compiler="sun"], [])

# The type of parameters for accept, getpeername, getsockname, getsockopt
# all vary the same way by platform.
AX_PROTOTYPE(accept, [
#include <sys/types.h>
#include <sys/socket.h>
], [
int a = 0;
ARG2 *b = 0;
ARG3 *c = 0;
accept (a, b, c);],
ARG2, [struct sockaddr, void],
ARG3, [socklen_t, size_t, int])

MONGOC_SOCKET_ARG2="$ACCEPT_ARG2"
AC_SUBST(MONGOC_SOCKET_ARG2)
MONGOC_SOCKET_ARG3="$ACCEPT_ARG3"
AC_SUBST(MONGOC_SOCKET_ARG3)

AC_LANG_POP([C])

if test "$c_compiler" = "unknown"; then
AC_MSG_ERROR([Compiler GCC >= 4.1 or Clang >= 3.3 is required for C compilation])
fi

# GLibc 2.19 complains about both _BSD_SOURCE and _GNU_SOURCE. The _GNU_SOURCE
# contains everything anyway. So just use that.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <features.h>
#ifndef __GLIBC__
#error not glibc
#endif
]], [])],
LIBC_FEATURES="-D_GNU_SOURCE",
LIBC_FEATURES="-D_BSD_SOURCE")
AC_SUBST(LIBC_FEATURES)

AC_C_CONST
AC_C_INLINE
AC_C_TYPEOF
2 changes: 1 addition & 1 deletion scripts/build/autotools/CheckHost.m4
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ case "$host" in
;;
*-*-*netbsd*)
os_netbsd=yes
ARGET_OS=unix
TARGET_OS=unix
;;
*-*-*freebsd*)
os_freebsd=yes
Expand Down
23 changes: 23 additions & 0 deletions scripts/build/autotools/libbson/CheckAtomics.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
AC_LANG_PUSH([C])
AC_MSG_CHECKING([for __sync_add_and_fetch_4])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
[[int32_t v = 1; return __sync_add_and_fetch_4 (&v, (int32_t)10);]])],
[AC_MSG_RESULT(yes)
have_sync_add_and_fetch_4=yes],
[AC_MSG_RESULT(no)
have_sync_add_and_fetch_4=no])
AS_IF([test "$have_sync_add_and_fetch_4" = "yes"],
[AC_SUBST(BSON_HAVE_ATOMIC_32_ADD_AND_FETCH, 1)],
[AC_SUBST(BSON_HAVE_ATOMIC_32_ADD_AND_FETCH, 0)])

AC_MSG_CHECKING([for __sync_add_and_fetch_8])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
[[int64_t v; return __sync_add_and_fetch_8 (&v, (int64_t)10);]])],
[AC_MSG_RESULT(yes)
have_sync_add_and_fetch_8=yes],
[AC_MSG_RESULT(no)
have_sync_add_and_fetch_8=no])
AS_IF([test "$have_sync_add_and_fetch_8" = "yes"],
[AC_SUBST(BSON_HAVE_ATOMIC_64_ADD_AND_FETCH, 1)],
[AC_SUBST(BSON_HAVE_ATOMIC_64_ADD_AND_FETCH, 0)])
AC_LANG_POP([C])
9 changes: 9 additions & 0 deletions scripts/build/autotools/libbson/CheckHeaders.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AC_HEADER_STDBOOL
AC_SUBST(BSON_HAVE_STDBOOL_H, 0)
if test "$ac_cv_header_stdbool_h" = "yes"; then
AC_SUBST(BSON_HAVE_STDBOOL_H, 1)
fi

AC_CREATE_STDINT_H([$srcdir/src/libbson/src/bson/bson-stdint.h])

AC_CHECK_HEADERS_ONCE([strings.h])
5 changes: 5 additions & 0 deletions scripts/build/autotools/libbson/Endian.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AC_C_BIGENDIAN
AC_SUBST(BSON_BYTE_ORDER, 1234)
if test "x$ac_cv_c_bigendian" = "xyes"; then
AC_SUBST(BSON_BYTE_ORDER, 4321)
fi
105 changes: 105 additions & 0 deletions scripts/build/autotools/libbson/FindDependencies.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Check for strnlen()
dnl AC_CHECK_FUNC isn't properly respecting _XOPEN_SOURCE for strnlen for unknown reason
AC_SUBST(BSON_HAVE_STRNLEN, 0)
AC_CACHE_CHECK([for strnlen],
bson_cv_have_strnlen,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <string.h>
int strnlen () { return 0; }
]])],
[bson_cv_have_strnlen=no],
[bson_cv_have_strnlen=yes])])
if test "$bson_cv_have_strnlen" = yes; then
AC_SUBST(BSON_HAVE_STRNLEN, 1)
fi

# Check for reallocf() (BSD/Darwin)
AC_SUBST(BSON_HAVE_REALLOCF, 0)
AC_CACHE_CHECK([for reallocf],
bson_cv_have_reallocf,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
int reallocf () { return 0; }
]])],
[bson_cv_have_reallocf=no],
[bson_cv_have_reallocf=yes])])
if test "$bson_cv_have_reallocf" = yes; then
AC_SUBST(BSON_HAVE_REALLOCF, 1)
fi

# Check for syscall()
AC_SUBST(BSON_HAVE_SYSCALL_TID, 0)
AC_CACHE_CHECK([for syscall],
bson_cv_have_syscall_tid,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <unistd.h>
#include <sys/syscall.h>
int syscall () { return 0; }
]])],
[bson_cv_have_syscall_tid=no],
[bson_cv_have_syscall_tid=yes])])
if test "$bson_cv_have_syscall_tid" = yes -a "$os_darwin" != "yes"; then
AC_CACHE_CHECK([for SYS_gettid],
bson_cv_have_sys_gettid_tid,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <unistd.h>
#include <sys/syscall.h>
int gettid () { return SYS_gettid; }
]])],
[bson_cv_have_sys_gettid_tid=yes],
[bson_cv_have_sys_gettid_tid=no])])
if test "$bson_cv_have_sys_gettid_tid" = yes; then
AC_SUBST(BSON_HAVE_SYSCALL_TID, 1)
fi
fi

# Check for snprintf()
AC_SUBST(BSON_HAVE_SNPRINTF, 0)
AC_CHECK_FUNC(snprintf, [AC_SUBST(BSON_HAVE_SNPRINTF, 1)])

# Check for struct timespec
AC_SUBST(BSON_HAVE_TIMESPEC, 0)
AC_CHECK_TYPE([struct timespec], [AC_SUBST(BSON_HAVE_TIMESPEC, 1)], [], [#include <time.h>])

# Check for clock_gettime and if it needs -lrt
AC_SUBST(BSON_HAVE_CLOCK_GETTIME, 0)
AC_SEARCH_LIBS([clock_gettime], [rt], [AC_SUBST(BSON_HAVE_CLOCK_GETTIME, 1)])
# Check if math functions need -lm
AC_SEARCH_LIBS([floor], [m])

# Check for gmtime_r()
AC_SUBST(BSON_HAVE_GMTIME_R, 0)
AC_CHECK_FUNC(gmtime_r, [AC_SUBST(BSON_HAVE_GMTIME_R, 1)])

# Check for rand_r()
AC_SUBST(BSON_HAVE_RAND_R, 0)
AC_CHECK_FUNC(rand_r, [AC_SUBST(BSON_HAVE_RAND_R, 1)], [], [#include <stdlib.h>])

# Check for pthreads. We might need to make this better to handle mingw,
# but I actually think it is okay to just check for it even though we will
# use win32 primatives.
AX_PTHREAD([],
[AC_MSG_ERROR([libbson requires pthreads on non-Windows platforms.])])


# The following is borrowed from the guile configure script.
#
# On past versions of Solaris, believe 8 through 10 at least, you
# had to write "pthread_once_t foo = { PTHREAD_ONCE_INIT };".
# This is contrary to POSIX:
# http://www.opengroup.org/onlinepubs/000095399/functions/pthread_once.html
# Check here if this style is required.
#
# glibc (2.3.6 at least) works both with or without braces, so the
# test checks whether it works without.
#
AC_SUBST(BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES, 0)
AC_CACHE_CHECK([whether PTHREAD_ONCE_INIT needs braces],
bson_cv_need_braces_on_pthread_once_init,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>
pthread_once_t foo = PTHREAD_ONCE_INIT;]])],
[bson_cv_need_braces_on_pthread_once_init=no],
[bson_cv_need_braces_on_pthread_once_init=yes])])
if test "$bson_cv_need_braces_on_pthread_once_init" = yes; then
AC_SUBST(BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES, 1)
fi
14 changes: 14 additions & 0 deletions scripts/build/autotools/libbson/Versions.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BSON_CURRENT_FILE=[]PHP_EXT_SRCDIR(mongodb)[/src/libbson/VERSION_CURRENT]
BSON_VERSION=$(cat $BSON_CURRENT_FILE)

dnl Ensure newline for "cut" implementations that need it, e.g. HP-UX.
BSON_MAJOR_VERSION=$( (cat $BSON_CURRENT_FILE; echo) | cut -d- -f1 | cut -d. -f1 )
BSON_MINOR_VERSION=$( (cat $BSON_CURRENT_FILE; echo) | cut -d- -f1 | cut -d. -f2 )
BSON_MICRO_VERSION=$( (cat $BSON_CURRENT_FILE; echo) | cut -d- -f1 | cut -d. -f3 )
BSON_PRERELEASE_VERSION=$(cut -s -d- -f2 $BSON_CURRENT_FILE)

AC_SUBST(BSON_VERSION)
AC_SUBST(BSON_MAJOR_VERSION)
AC_SUBST(BSON_MINOR_VERSION)
AC_SUBST(BSON_MICRO_VERSION)
AC_SUBST(BSON_PRERELEASE_VERSION)
66 changes: 66 additions & 0 deletions scripts/build/autotools/libmongoc/CheckCompression.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
found_snappy="no"
found_zlib="no"
bundled_zlib="no"

PKG_CHECK_MODULES([PHP_MONGODB_SNAPPY],[snappy],[
PHP_EVAL_INCLINE([$PHP_MONGODB_SNAPPY_CFLAGS])
PHP_EVAL_LIBLINE([$PHP_MONGODB_SNAPPY_LIBS],[MONGODB_SHARED_LIBADD])
found_snappy="yes"
],[
PHP_CHECK_LIBRARY([snappy],
[snappy_uncompress],
[have_snappy_lib="yes"],
[have_snappy_lib="no"])

AC_CHECK_HEADER([snappy-c.h],
[have_snappy_headers=yes],
[have_snappy_headers=no])

if test "$have_snappy_lib" = "yes" -a "$have_snappy_headers" = "yes"; then
PHP_ADD_LIBRARY([snappy],,[MONGODB_SHARED_LIBADD])
found_snappy="yes"
fi
])

PKG_CHECK_MODULES([PHP_MONGODB_ZLIB],[zlib],[
PHP_EVAL_INCLINE([$PHP_MONGODB_ZLIB_CFLAGS])
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZLIB_LIBS],[MONGODB_SHARED_LIBADD])
found_zlib="yes"
],[
PHP_CHECK_LIBRARY([zlib],
[compress2],
[have_zlib_lib="yes"],
[have_zlib_lib="no"])

AC_CHECK_HEADER([zlib.h],
[have_zlib_headers=yes],
[have_zlib_headers=no])

if test "$have_zlib_lib" = "yes" -a "$have_zlib_headers" = "yes"; then
PHP_ADD_LIBRARY([z],,[MONGODB_SHARED_LIBADD])
found_zlib="yes"
fi
])

dnl If zlib was not found, use libmongoc's bundled version
AS_IF([test "$found_zlib" != "yes"],[
bundled_zlib="yes"
])

if test "$found_snappy" = "yes" -o "$found_zlib" = "yes" -o "$bundled_zlib" = "yes"; then
AC_SUBST(MONGOC_ENABLE_COMPRESSION, 1)
if test "$found_snappy" = "yes"; then
AC_SUBST(MONGOC_ENABLE_COMPRESSION_SNAPPY, 1)
else
AC_SUBST(MONGOC_ENABLE_COMPRESSION_SNAPPY, 0)
fi
if test "$found_zlib" = "yes" -o "$bundled_zlib" = "yes"; then
AC_SUBST(MONGOC_ENABLE_COMPRESSION_ZLIB, 1)
else
AC_SUBST(MONGOC_ENABLE_COMPRESSION_ZLIB, 0)
fi
else
AC_SUBST(MONGOC_ENABLE_COMPRESSION, 0)
AC_SUBST(MONGOC_ENABLE_COMPRESSION_ZLIB, 0)
AC_SUBST(MONGOC_ENABLE_COMPRESSION_SNAPPY, 0)
fi
Loading