Skip to content

Commit c90422c

Browse files
committed
PHPC-1186: Consolidate libbson and libmongoc build configs
1 parent 88bdd78 commit c90422c

22 files changed

+1746
-222
lines changed

config.m4

Lines changed: 88 additions & 221 deletions
Large diffs are not rendered by default.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# If CFLAGS and CXXFLAGS are unset, default to empty.
2+
# This is to tell automake not to include '-g' if C{XX,}FLAGS is not set.
3+
# For more info - http://www.gnu.org/software/automake/manual/autoconf.html#C_002b_002b-Compiler
4+
if test -z "$CXXFLAGS"; then
5+
CXXFLAGS=""
6+
fi
7+
if test -z "$CFLAGS"; then
8+
CFLAGS=""
9+
fi
10+
11+
AC_PROG_CC
12+
AC_PROG_CXX
13+
14+
# Check that an appropriate C compiler is available.
15+
c_compiler="unknown"
16+
AC_LANG_PUSH([C])
17+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
18+
#if !(defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER))
19+
#error Not a supported GCC compiler
20+
#endif
21+
#if defined(__GNUC__)
22+
#define GCC_VERSION (__GNUC__ * 10000 \
23+
+ __GNUC_MINOR__ * 100 \
24+
+ __GNUC_PATCHLEVEL__)
25+
#if GCC_VERSION < 40100
26+
#error Not a supported GCC compiler
27+
#endif
28+
#endif
29+
])], [c_compiler="gcc"], [])
30+
31+
# If our BEGIN_IGNORE_DEPRECATIONS macro won't work, pass
32+
# -Wno-deprecated-declarations
33+
34+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
35+
#if !defined(__clang__) && defined(__GNUC__)
36+
#define GCC_VERSION (__GNUC__ * 10000 \
37+
+ __GNUC_MINOR__ * 100 \
38+
+ __GNUC_PATCHLEVEL__)
39+
#if GCC_VERSION < 40600
40+
#error Does not support deprecation warning pragmas
41+
#endif
42+
#endif
43+
])], [], [STD_CFLAGS="$STD_CFLAGS -Wno-deprecated-declarations"])
44+
45+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
46+
#if defined(__clang__)
47+
#define CLANG_VERSION (__clang_major__ * 10000 \
48+
+ __clang_minor__ * 100 \
49+
+ __clang_patchlevel__)
50+
#if CLANG_VERSION < 30300
51+
#error Not a supported Clang compiler
52+
#endif
53+
#endif
54+
])], [c_compiler="clang"], [])
55+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
56+
#if !(defined(__SUNPRO_C))
57+
#error Not a supported Sun compiler
58+
#endif
59+
])], [c_compiler="sun"], [])
60+
61+
# The type of parameters for accept, getpeername, getsockname, getsockopt
62+
# all vary the same way by platform.
63+
AX_PROTOTYPE(accept, [
64+
#include <sys/types.h>
65+
#include <sys/socket.h>
66+
], [
67+
int a = 0;
68+
ARG2 *b = 0;
69+
ARG3 *c = 0;
70+
accept (a, b, c);],
71+
ARG2, [struct sockaddr, void],
72+
ARG3, [socklen_t, size_t, int])
73+
74+
MONGOC_SOCKET_ARG2="$ACCEPT_ARG2"
75+
AC_SUBST(MONGOC_SOCKET_ARG2)
76+
MONGOC_SOCKET_ARG3="$ACCEPT_ARG3"
77+
AC_SUBST(MONGOC_SOCKET_ARG3)
78+
79+
AC_LANG_POP([C])
80+
81+
if test "$c_compiler" = "unknown"; then
82+
AC_MSG_ERROR([Compiler GCC >= 4.1 or Clang >= 3.3 is required for C compilation])
83+
fi
84+
85+
# GLibc 2.19 complains about both _BSD_SOURCE and _GNU_SOURCE. The _GNU_SOURCE
86+
# contains everything anyway. So just use that.
87+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
88+
#include <features.h>
89+
#ifndef __GLIBC__
90+
#error not glibc
91+
#endif
92+
]], [])],
93+
LIBC_FEATURES="-D_GNU_SOURCE",
94+
LIBC_FEATURES="-D_BSD_SOURCE")
95+
AC_SUBST(LIBC_FEATURES)
96+
97+
AC_C_CONST
98+
AC_C_INLINE
99+
AC_C_TYPEOF

scripts/build/autotools/CheckHost.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ case "$host" in
1717
;;
1818
*-*-*netbsd*)
1919
os_netbsd=yes
20-
ARGET_OS=unix
20+
TARGET_OS=unix
2121
;;
2222
*-*-*freebsd*)
2323
os_freebsd=yes
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
AC_LANG_PUSH([C])
2+
AC_MSG_CHECKING([for __sync_add_and_fetch_4])
3+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
4+
[[int32_t v = 1; return __sync_add_and_fetch_4 (&v, (int32_t)10);]])],
5+
[AC_MSG_RESULT(yes)
6+
have_sync_add_and_fetch_4=yes],
7+
[AC_MSG_RESULT(no)
8+
have_sync_add_and_fetch_4=no])
9+
AS_IF([test "$have_sync_add_and_fetch_4" = "yes"],
10+
[AC_SUBST(BSON_HAVE_ATOMIC_32_ADD_AND_FETCH, 1)],
11+
[AC_SUBST(BSON_HAVE_ATOMIC_32_ADD_AND_FETCH, 0)])
12+
13+
AC_MSG_CHECKING([for __sync_add_and_fetch_8])
14+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
15+
[[int64_t v; return __sync_add_and_fetch_8 (&v, (int64_t)10);]])],
16+
[AC_MSG_RESULT(yes)
17+
have_sync_add_and_fetch_8=yes],
18+
[AC_MSG_RESULT(no)
19+
have_sync_add_and_fetch_8=no])
20+
AS_IF([test "$have_sync_add_and_fetch_8" = "yes"],
21+
[AC_SUBST(BSON_HAVE_ATOMIC_64_ADD_AND_FETCH, 1)],
22+
[AC_SUBST(BSON_HAVE_ATOMIC_64_ADD_AND_FETCH, 0)])
23+
AC_LANG_POP([C])
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
AC_HEADER_STDBOOL
2+
AC_SUBST(BSON_HAVE_STDBOOL_H, 0)
3+
if test "$ac_cv_header_stdbool_h" = "yes"; then
4+
AC_SUBST(BSON_HAVE_STDBOOL_H, 1)
5+
fi
6+
7+
AC_CREATE_STDINT_H([$srcdir/src/libbson/src/bson/bson-stdint.h])
8+
9+
AC_CHECK_HEADERS_ONCE([strings.h])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AC_C_BIGENDIAN
2+
AC_SUBST(BSON_BYTE_ORDER, 1234)
3+
if test "x$ac_cv_c_bigendian" = "xyes"; then
4+
AC_SUBST(BSON_BYTE_ORDER, 4321)
5+
fi
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Check for strnlen()
2+
dnl AC_CHECK_FUNC isn't properly respecting _XOPEN_SOURCE for strnlen for unknown reason
3+
AC_SUBST(BSON_HAVE_STRNLEN, 0)
4+
AC_CACHE_CHECK([for strnlen],
5+
bson_cv_have_strnlen,
6+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
7+
#include <string.h>
8+
int strnlen () { return 0; }
9+
]])],
10+
[bson_cv_have_strnlen=no],
11+
[bson_cv_have_strnlen=yes])])
12+
if test "$bson_cv_have_strnlen" = yes; then
13+
AC_SUBST(BSON_HAVE_STRNLEN, 1)
14+
fi
15+
16+
# Check for reallocf() (BSD/Darwin)
17+
AC_SUBST(BSON_HAVE_REALLOCF, 0)
18+
AC_CACHE_CHECK([for reallocf],
19+
bson_cv_have_reallocf,
20+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
21+
#include <stdlib.h>
22+
int reallocf () { return 0; }
23+
]])],
24+
[bson_cv_have_reallocf=no],
25+
[bson_cv_have_reallocf=yes])])
26+
if test "$bson_cv_have_reallocf" = yes; then
27+
AC_SUBST(BSON_HAVE_REALLOCF, 1)
28+
fi
29+
30+
# Check for syscall()
31+
AC_SUBST(BSON_HAVE_SYSCALL_TID, 0)
32+
AC_CACHE_CHECK([for syscall],
33+
bson_cv_have_syscall_tid,
34+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
35+
#include <unistd.h>
36+
#include <sys/syscall.h>
37+
int syscall () { return 0; }
38+
]])],
39+
[bson_cv_have_syscall_tid=no],
40+
[bson_cv_have_syscall_tid=yes])])
41+
if test "$bson_cv_have_syscall_tid" = yes -a "$os_darwin" != "yes"; then
42+
AC_CACHE_CHECK([for SYS_gettid],
43+
bson_cv_have_sys_gettid_tid,
44+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
45+
#include <unistd.h>
46+
#include <sys/syscall.h>
47+
int gettid () { return SYS_gettid; }
48+
]])],
49+
[bson_cv_have_sys_gettid_tid=yes],
50+
[bson_cv_have_sys_gettid_tid=no])])
51+
if test "$bson_cv_have_sys_gettid_tid" = yes; then
52+
AC_SUBST(BSON_HAVE_SYSCALL_TID, 1)
53+
fi
54+
fi
55+
56+
# Check for snprintf()
57+
AC_SUBST(BSON_HAVE_SNPRINTF, 0)
58+
AC_CHECK_FUNC(snprintf, [AC_SUBST(BSON_HAVE_SNPRINTF, 1)])
59+
60+
# Check for struct timespec
61+
AC_SUBST(BSON_HAVE_TIMESPEC, 0)
62+
AC_CHECK_TYPE([struct timespec], [AC_SUBST(BSON_HAVE_TIMESPEC, 1)], [], [#include <time.h>])
63+
64+
# Check for clock_gettime and if it needs -lrt
65+
AC_SUBST(BSON_HAVE_CLOCK_GETTIME, 0)
66+
AC_SEARCH_LIBS([clock_gettime], [rt], [AC_SUBST(BSON_HAVE_CLOCK_GETTIME, 1)])
67+
# Check if math functions need -lm
68+
AC_SEARCH_LIBS([floor], [m])
69+
70+
# Check for gmtime_r()
71+
AC_SUBST(BSON_HAVE_GMTIME_R, 0)
72+
AC_CHECK_FUNC(gmtime_r, [AC_SUBST(BSON_HAVE_GMTIME_R, 1)])
73+
74+
# Check for rand_r()
75+
AC_SUBST(BSON_HAVE_RAND_R, 0)
76+
AC_CHECK_FUNC(rand_r, [AC_SUBST(BSON_HAVE_RAND_R, 1)], [], [#include <stdlib.h>])
77+
78+
# Check for pthreads. We might need to make this better to handle mingw,
79+
# but I actually think it is okay to just check for it even though we will
80+
# use win32 primatives.
81+
AX_PTHREAD([],
82+
[AC_MSG_ERROR([libbson requires pthreads on non-Windows platforms.])])
83+
84+
85+
# The following is borrowed from the guile configure script.
86+
#
87+
# On past versions of Solaris, believe 8 through 10 at least, you
88+
# had to write "pthread_once_t foo = { PTHREAD_ONCE_INIT };".
89+
# This is contrary to POSIX:
90+
# http://www.opengroup.org/onlinepubs/000095399/functions/pthread_once.html
91+
# Check here if this style is required.
92+
#
93+
# glibc (2.3.6 at least) works both with or without braces, so the
94+
# test checks whether it works without.
95+
#
96+
AC_SUBST(BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES, 0)
97+
AC_CACHE_CHECK([whether PTHREAD_ONCE_INIT needs braces],
98+
bson_cv_need_braces_on_pthread_once_init,
99+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>
100+
pthread_once_t foo = PTHREAD_ONCE_INIT;]])],
101+
[bson_cv_need_braces_on_pthread_once_init=no],
102+
[bson_cv_need_braces_on_pthread_once_init=yes])])
103+
if test "$bson_cv_need_braces_on_pthread_once_init" = yes; then
104+
AC_SUBST(BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES, 1)
105+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BSON_CURRENT_FILE=[]PHP_EXT_SRCDIR(mongodb)[/src/libbson/VERSION_CURRENT]
2+
BSON_VERSION=$(cat $BSON_CURRENT_FILE)
3+
4+
dnl Ensure newline for "cut" implementations that need it, e.g. HP-UX.
5+
BSON_MAJOR_VERSION=$( (cat $BSON_CURRENT_FILE; echo) | cut -d- -f1 | cut -d. -f1 )
6+
BSON_MINOR_VERSION=$( (cat $BSON_CURRENT_FILE; echo) | cut -d- -f1 | cut -d. -f2 )
7+
BSON_MICRO_VERSION=$( (cat $BSON_CURRENT_FILE; echo) | cut -d- -f1 | cut -d. -f3 )
8+
BSON_PRERELEASE_VERSION=$(cut -s -d- -f2 $BSON_CURRENT_FILE)
9+
10+
AC_SUBST(BSON_VERSION)
11+
AC_SUBST(BSON_MAJOR_VERSION)
12+
AC_SUBST(BSON_MINOR_VERSION)
13+
AC_SUBST(BSON_MICRO_VERSION)
14+
AC_SUBST(BSON_PRERELEASE_VERSION)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
found_snappy="no"
2+
found_zlib="no"
3+
bundled_zlib="no"
4+
5+
PKG_CHECK_MODULES([PHP_MONGODB_SNAPPY],[snappy],[
6+
PHP_EVAL_INCLINE([$PHP_MONGODB_SNAPPY_CFLAGS])
7+
PHP_EVAL_LIBLINE([$PHP_MONGODB_SNAPPY_LIBS],[MONGODB_SHARED_LIBADD])
8+
found_snappy="yes"
9+
],[
10+
PHP_CHECK_LIBRARY([snappy],
11+
[snappy_uncompress],
12+
[have_snappy_lib="yes"],
13+
[have_snappy_lib="no"])
14+
15+
AC_CHECK_HEADER([snappy-c.h],
16+
[have_snappy_headers=yes],
17+
[have_snappy_headers=no])
18+
19+
if test "$have_snappy_lib" = "yes" -a "$have_snappy_headers" = "yes"; then
20+
PHP_ADD_LIBRARY([snappy],,[MONGODB_SHARED_LIBADD])
21+
found_snappy="yes"
22+
fi
23+
])
24+
25+
PKG_CHECK_MODULES([PHP_MONGODB_ZLIB],[zlib],[
26+
PHP_EVAL_INCLINE([$PHP_MONGODB_ZLIB_CFLAGS])
27+
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZLIB_LIBS],[MONGODB_SHARED_LIBADD])
28+
found_zlib="yes"
29+
],[
30+
PHP_CHECK_LIBRARY([zlib],
31+
[compress2],
32+
[have_zlib_lib="yes"],
33+
[have_zlib_lib="no"])
34+
35+
AC_CHECK_HEADER([zlib.h],
36+
[have_zlib_headers=yes],
37+
[have_zlib_headers=no])
38+
39+
if test "$have_zlib_lib" = "yes" -a "$have_zlib_headers" = "yes"; then
40+
PHP_ADD_LIBRARY([z],,[MONGODB_SHARED_LIBADD])
41+
found_zlib="yes"
42+
fi
43+
])
44+
45+
dnl If zlib was not found, use libmongoc's bundled version
46+
AS_IF([test "$found_zlib" != "yes"],[
47+
bundled_zlib="yes"
48+
])
49+
50+
if test "$found_snappy" = "yes" -o "$found_zlib" = "yes" -o "$bundled_zlib" = "yes"; then
51+
AC_SUBST(MONGOC_ENABLE_COMPRESSION, 1)
52+
if test "$found_snappy" = "yes"; then
53+
AC_SUBST(MONGOC_ENABLE_COMPRESSION_SNAPPY, 1)
54+
else
55+
AC_SUBST(MONGOC_ENABLE_COMPRESSION_SNAPPY, 0)
56+
fi
57+
if test "$found_zlib" = "yes" -o "$bundled_zlib" = "yes"; then
58+
AC_SUBST(MONGOC_ENABLE_COMPRESSION_ZLIB, 1)
59+
else
60+
AC_SUBST(MONGOC_ENABLE_COMPRESSION_ZLIB, 0)
61+
fi
62+
else
63+
AC_SUBST(MONGOC_ENABLE_COMPRESSION, 0)
64+
AC_SUBST(MONGOC_ENABLE_COMPRESSION_ZLIB, 0)
65+
AC_SUBST(MONGOC_ENABLE_COMPRESSION_SNAPPY, 0)
66+
fi

0 commit comments

Comments
 (0)