optionally bundle amzn/ion-c
authorMichael Wallner <mike@php.net>
Mon, 3 Jan 2022 22:29:45 +0000 (23:29 +0100)
committerMichael Wallner <mike@php.net>
Wed, 5 Jan 2022 13:53:57 +0000 (14:53 +0100)
.editorconfig
.gitignore
.gitmodules [new file with mode: 0644]
Makefile.frag [new file with mode: 0644]
config.m4
ion-c [new submodule]

index 7105c468c8c33b941f2b84bfcd832b1233d20281..ac09c3a4727080648e78ae31bca5308076b0306b 100644 (file)
@@ -8,6 +8,10 @@ indent_style = tab
 charset = utf-8
 trim_trailing_whitespace = true
 
+[*.m4]
+indent_style = space
+indent_size = 2
+
 [*.php]
 indent_style = space
 indent_size = 4
index 9bae89b92bf4e64277decc7cd13946109139ad59..30a7c1317d694d200bdf87ed859bd6d5367c88d5 100644 (file)
@@ -1,3 +1,5 @@
+*~
+*.o
 *.lo
 *.la
 .libs
@@ -41,3 +43,5 @@ tests/**/*.mem
 tests/Timestamp/
 tmp-php.ini
 *.dep
+*.gcda
+*.gcno
diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..83bc9a1
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "ion-c"]
+       path = ion-c
+       url = https://github.com/amzn/ion-c
diff --git a/Makefile.frag b/Makefile.frag
new file mode 100644 (file)
index 0000000..463c78b
--- /dev/null
@@ -0,0 +1,29 @@
+LIB_IONC_STATIC := $(builddir)/ion-c/build/ionc/libionc_static.a
+LIB_DECN_STATIC := $(builddir)/ion-c/build/decNumber/libdecNumber_static.a
+
+$(builddir)/ion.lo: $(LIB_IONC_STATIC) $(LIB_DECN_STATIC)
+
+$(builddir)/ion-c/build:
+       mkdir -p $@
+       +cd $@ && CFLAGS=-w CXXFLAGS=-w \
+       $(CMAKE) -Wno-dev --log-level=ERROR \
+               -DCMAKE_BUILD_TYPE=Release \
+               -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
+               $(srcdir)/ion-c
+
+$(LIB_IONC_STATIC): | $(builddir)/ion-c/build
+       +$(CMAKE) --build $| --target ionc_static -- VERBOSE=
+$(LIB_DECN_STATIC): | $(builddir)/ion-c/build
+       +$(CMAKE) --build $| --target decNumber_static -- VERBOSE=
+
+clean: clean-ion
+
+.PHONY: clean-ion
+clean-ion:
+       -rm -rf $(builddir)/ion-c/build
+
+.PHONY: gcov-ion
+gcov-ion:
+       @rm -rf $@
+       @mkdir -p $@
+       gcovr -j $$(nproc) -sr . --html --html-details --html-title $@ -o $@/index.html -f '.*/(php_)?ion.*'
index 4d85c675f9559da9eb48712f7336e4ad159e7e47..28b6ee227585d5a617a411a542690e6cfda41ce6 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])
+
+AC_ARG_VAR([AR], [system library archiver])
+AC_PATH_PROG([AR], [ar])
+PHP_SUBST([AR])
+
+AC_ARG_VAR([RANLIB], [system library archive indexer])
+AC_PATH_PROG([RANLIB], [ranlib])
+PHP_SUBST([RANLIB])
+
+use_bundled_ionc=false
+AC_DEFUN([ION_BUNDLE], [dnl
+
+  AC_MSG_CHECKING([for bundled ion-c])
+  if test -f PHP_EXT_SRCDIR([ion])/ion-c/CMakeLists.txt; then
+    AC_MSG_RESULT([ion-c])
+  elif test -d PHP_EXT_SRCDIR([ion])/.git; then
+    AC_MSG_RESULT([git submodule])
+    if ! GIT_DIR=PHP_EXT_SRCDIR([ion])/.git GIT_WORK_TREE=PHP_EXT_SRCDIR([ion])/ \
+        "$GIT" submodule update --init --depth 1 --recursive ion-c; then
+      AC_MSG_ERROR([giving up])
+    fi
+  else
     AC_MSG_RESULT([not found])
-    AC_MSG_ERROR([Please reinstall the ion distribution])
+    AC_MSG_ERROR([invalid bundle: PHP_EXT_SRCDIR([ion])/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]), builddir)
+  builddir="$builddir/ion-c/build"
+  if test "$ext_shared" = yes; then
+    ION_SHARED_LIBADD="-lionc_static -ldecNumber_static -L$builddir/ionc -L$builddir/decNumber"
+  else
+    DLIBS="$DLIBS -lionc_static -ldecNumber_static"
+    EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$builddir/ionc -L$builddir/decNumber"
+    EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM -L$builddir/ionc -L$builddir/decNumber"
+  fi
+
+  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
diff --git a/ion-c b/ion-c
new file mode 160000 (submodule)
index 0000000..8471ebb
--- /dev/null
+++ b/ion-c
@@ -0,0 +1 @@
+Subproject commit 8471ebb59c38532121a4675d5c2876ba7e59f3d5