we'll probably get this right until 1.0
[awesomized/ext-ion] / config.m4
index 4d85c675f9559da9eb48712f7336e4ad159e7e47..63188c28dc3cbed38064672e43d422f41352ce9e 100644 (file)
--- a/config.m4
+++ b/config.m4
 
 PHP_ARG_WITH([ion],
-  [for ion support],
+  [for ION support],
   [AS_HELP_STRING([--with-ion],
     [path to libion])],
   [no])
 
-if test "$PHP_ION" != "no"; then
+AC_ARG_VAR([GIT], [git executable])
+AC_PATH_PROG([GIT], [git])
+PHP_SUBST([GIT])
 
-  SEARCH_PATH="/usr/local /usr"     # you might want to change this
-  SEARCH_FOR="/include/ionc/ion.h"  # you most likely want to change this
-  if test -r $PHP_ION/$SEARCH_FOR; then # path given as parameter
-    ION_DIR=$PHP_ION
-  else # search default path list
-    AC_MSG_CHECKING([for ion files in default path])
-    for i in $SEARCH_PATH ; do
-      if test -r $i/$SEARCH_FOR; then
-        ION_DIR=$i
-        AC_MSG_RESULT(found in $i)
-      fi
-    done
-  fi
-  dnl
-  if test -z "$ION_DIR"; then
+AC_ARG_VAR([CMAKE], [cmake executable])
+AC_PATH_PROG([CMAKE], [cmake])
+PHP_SUBST([CMAKE])
+
+use_bundled_ionc=false
+AC_DEFUN([ION_BUNDLE], [dnl
+
+  sdir=PHP_EXT_SRCDIR([ion])
+  AC_MSG_CHECKING([for bundled ion-c])
+  if test -f $sdir/ion-c/CMakeLists.txt; then
+    AC_MSG_RESULT([ion-c])
+  elif test -d $sdir/.git; then
+    AC_MSG_RESULT([git submodule])
+    cd $sdir
+    if ! "$GIT" submodule update --init --depth 1 --recursive ion-c; then
+      cd -
+      AC_MSG_ERROR([giving up on path "$sdir"])
+    fi
+    cd -
+  elif "$GIT" clone -q --depth 1 --recursive https://github.com/amzn/ion-c $sdir/ion-c; then
+    AC_MSG_RESULT([git clone])
+  else
     AC_MSG_RESULT([not found])
-    AC_MSG_ERROR([Please reinstall the ion distribution])
+    AC_MSG_ERROR([invalid bundle: $sdir/ion-c])
   fi
 
-  PHP_ADD_INCLUDE($ION_DIR/include)
+  PHP_ADD_INCLUDE(PHP_EXT_SRCDIR([ion])/ion-c/ionc/include)
+  PHP_ADD_INCLUDE(PHP_EXT_SRCDIR([ion])/ion-c/decNumber/include)
 
-  LIBNAME=ionc
-  LIBSYMBOL=ion_error_to_str
-  PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
-  [
-    PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $ION_DIR/$PHP_LIBDIR, ION_SHARED_LIBADD)
-  ],[
-    AC_MSG_ERROR([could not link with ionc library.])
-  ],[
-    -L$ION_DIR/$PHP_LIBDIR -lm
-  ])
-  LIBNAME=decNumber
-  LIBSYMBOL=decQuadFromInt32
+  PHP_EXPAND_PATH(PHP_EXT_BUILDDIR([ion]), bdir)
+  bdir="$bdir/ion-c/build"
+  if test "$ext_shared" = yes; then
+    ION_SHARED_LIBADD="-lionc_static -ldecNumber_static -L$bdir/ionc -L$bdir/decNumber"
+  else
+    DLIBS="$DLIBS -lionc_static -ldecNumber_static"
+    EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$bdir/ionc -L$bdir/decNumber"
+    EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM -L$bdir/ionc -L$bdir/decNumber"
+  fi
+
+  if test "$PHP_DEBUG" = 1; then
+    LIB_IONC_BUILD=Debug
+  else
+    LIB_IONC_BUILD=Release
+  fi
+  PHP_SUBST(LIB_IONC_BUILD)
+  PHP_ADD_MAKEFILE_FRAGMENT()
+])
+AC_DEFUN([ION_CHECK_LIB], [dnl
+  LIBNAME=$1
+  LIBSYMBOL=$2
   PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
   [
+    [have_]AS_TR_SH($LIBNAME)[_]AS_TR_SH($LIBSYMBOL)=true
+    AC_DEFINE([HAVE_]AS_TR_CPP($LIBNAME)[_]AS_TR_CPP($LIBSYMBOL), 1, [ ])
     PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $ION_DIR/$PHP_LIBDIR, ION_SHARED_LIBADD)
   ],[
-    AC_MSG_ERROR([could not link with ionc library.])
+    [have_]AS_TR_SH($LIBNAME)[_]AS_TR_SH($LIBSYMBOL)=true
+    AC_MSG_WARN([could not link with $LIBNAME library or find $LIBSYMBOL.])
   ],[
     -L$ION_DIR/$PHP_LIBDIR -lm
   ])
+])
+AC_DEFUN([ION_SYSTEM], [dnl
+    SEARCH_PATH="/usr/local /usr"
+    SEARCH_FOR="/include/ionc/ion.h"
+    if test -r $PHP_ION/$SEARCH_FOR; then
+      ION_DIR=$PHP_ION
+    else
+      AC_MSG_CHECKING([for ion-c files in default path])
+      for i in $SEARCH_PATH ; do
+        if test -r $i/$SEARCH_FOR; then
+          ION_DIR=$i
+          break
+        fi
+      done
+    fi
+    dnl
+    if test -n "$ION_DIR"; then
+      AC_MSG_RESULT(found in $ION_DIR)
+      PHP_ADD_INCLUDE([$ION_DIR/include])
+      ION_CHECK_LIB(ionc, ion_error_to_str)
+      ION_CHECK_LIB(decNumber, decQuadFromInt32)
+      if ! $have_ionc_ion_error_to_str || ! $have_decNumber_decQuadFromInt32; then
+        ION_BUNDLE
+      fi
+    else
+      AC_MSG_RESULT([not found])
+      ION_BUNDLE
+    fi
 
-  PHP_SUBST(ION_SHARED_LIBADD)
-  AC_DEFINE(HAVE_ION, 1, [ Have ion support ])
+])
 
+if test "$PHP_ION" != "no"; then
   PHP_NEW_EXTENSION(ion, ion.c, $ext_shared)
+
+  case "$PHP_ION" in
+  ion-c|b|bundle*)  ION_BUNDLE  ;;
+  *)                ION_SYSTEM  ;;
+  esac
+
+  PHP_SUBST(ION_SHARED_LIBADD)
+  AC_DEFINE(HAVE_ION, 1, [ Have ion support ])
 fi