docker: fix build without submodule
[awesomized/ext-ion] / config.m4
1
2 PHP_ARG_WITH([ion],
3 [for ION support],
4 [AS_HELP_STRING([--with-ion],
5 [path to libion])],
6 [no])
7
8 AC_ARG_VAR([GIT], [git executable])
9 AC_PATH_PROG([GIT], [git])
10 PHP_SUBST([GIT])
11
12 AC_ARG_VAR([CMAKE], [cmake executable])
13 AC_PATH_PROG([CMAKE], [cmake])
14 PHP_SUBST([CMAKE])
15
16 use_bundled_ionc=false
17 AC_DEFUN([ION_BUNDLE], [dnl
18
19 AC_MSG_CHECKING([for bundled ion-c])
20 if test -f PHP_EXT_SRCDIR([ion])/ion-c/CMakeLists.txt; then
21 AC_MSG_RESULT([ion-c])
22 elif test -d PHP_EXT_SRCDIR([ion])/.git; then
23 AC_MSG_RESULT([git submodule])
24 if ! GIT_DIR=PHP_EXT_SRCDIR([ion])/.git GIT_WORK_TREE=PHP_EXT_SRCDIR([ion])/ \
25 "$GIT" submodule update --init --depth 1 --recursive ion-c; then
26 AC_MSG_ERROR([giving up])
27 fi
28 elif "$GIT" clone -q --depth 1 --recursive https://github.com/amzn/ion-c PHP_EXT_SRCDIR([ion])/ion-c; then
29 AC_MSG_RESULT([git clone])
30 else
31 AC_MSG_RESULT([not found])
32 AC_MSG_ERROR([invalid bundle: PHP_EXT_SRCDIR([ion])/ion-c])
33 fi
34
35 PHP_ADD_INCLUDE(PHP_EXT_SRCDIR([ion])/ion-c/ionc/include)
36 PHP_ADD_INCLUDE(PHP_EXT_SRCDIR([ion])/ion-c/decNumber/include)
37
38 PHP_EXPAND_PATH(PHP_EXT_BUILDDIR([ion]), builddir)
39 builddir="$builddir/ion-c/build"
40 if test "$ext_shared" = yes; then
41 ION_SHARED_LIBADD="-lionc_static -ldecNumber_static -L$builddir/ionc -L$builddir/decNumber"
42 else
43 DLIBS="$DLIBS -lionc_static -ldecNumber_static"
44 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$builddir/ionc -L$builddir/decNumber"
45 EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM -L$builddir/ionc -L$builddir/decNumber"
46 fi
47
48 if test "$PHP_DEBUG" = 1; then
49 LIB_IONC_BUILD=Debug
50 else
51 LIB_IONC_BUILD=Release
52 fi
53 PHP_SUBST(LIB_IONC_BUILD)
54 PHP_ADD_MAKEFILE_FRAGMENT()
55 ])
56 AC_DEFUN([ION_CHECK_LIB], [dnl
57 LIBNAME=$1
58 LIBSYMBOL=$2
59 PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
60 [
61 [have_]AS_TR_SH($LIBNAME)[_]AS_TR_SH($LIBSYMBOL)=true
62 AC_DEFINE([HAVE_]AS_TR_CPP($LIBNAME)[_]AS_TR_CPP($LIBSYMBOL), 1, [ ])
63 PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $ION_DIR/$PHP_LIBDIR, ION_SHARED_LIBADD)
64 ],[
65 [have_]AS_TR_SH($LIBNAME)[_]AS_TR_SH($LIBSYMBOL)=true
66 AC_MSG_WARN([could not link with $LIBNAME library or find $LIBSYMBOL.])
67 ],[
68 -L$ION_DIR/$PHP_LIBDIR -lm
69 ])
70 ])
71 AC_DEFUN([ION_SYSTEM], [dnl
72 SEARCH_PATH="/usr/local /usr"
73 SEARCH_FOR="/include/ionc/ion.h"
74 if test -r $PHP_ION/$SEARCH_FOR; then
75 ION_DIR=$PHP_ION
76 else
77 AC_MSG_CHECKING([for ion-c files in default path])
78 for i in $SEARCH_PATH ; do
79 if test -r $i/$SEARCH_FOR; then
80 ION_DIR=$i
81 break
82 fi
83 done
84 fi
85 dnl
86 if test -n "$ION_DIR"; then
87 AC_MSG_RESULT(found in $ION_DIR)
88 PHP_ADD_INCLUDE([$ION_DIR/include])
89 ION_CHECK_LIB(ionc, ion_error_to_str)
90 ION_CHECK_LIB(decNumber, decQuadFromInt32)
91 if ! $have_ionc_ion_error_to_str || ! $have_decNumber_decQuadFromInt32; then
92 ION_BUNDLE
93 fi
94 else
95 AC_MSG_RESULT([not found])
96 ION_BUNDLE
97 fi
98
99 ])
100
101 if test "$PHP_ION" != "no"; then
102 PHP_NEW_EXTENSION(ion, ion.c, $ext_shared)
103
104 case "$PHP_ION" in
105 ion-c|b|bundle*) ION_BUNDLE ;;
106 *) ION_SYSTEM ;;
107 esac
108
109 PHP_SUBST(ION_SHARED_LIBADD)
110 AC_DEFINE(HAVE_ION, 1, [ Have ion support ])
111 fi