From: Michael Wallner Date: Mon, 3 Jan 2022 22:29:45 +0000 (+0100) Subject: optionally bundle amzn/ion-c X-Git-Tag: v0.1.0~49 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=daaeccccaf6fd7a01f0dacf7961faa5e8bed0851;p=awesomized%2Fext-ion optionally bundle amzn/ion-c --- diff --git a/.editorconfig b/.editorconfig index 7105c46..ac09c3a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore index 9bae89b..30a7c13 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 0000000..83bc9a1 --- /dev/null +++ b/.gitmodules @@ -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 index 0000000..463c78b --- /dev/null +++ b/Makefile.frag @@ -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.*' diff --git a/config.m4 b/config.m4 index 4d85c67..28b6ee2 100644 --- a/config.m4 +++ b/config.m4 @@ -1,56 +1,111 @@ 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 index 0000000..8471ebb --- /dev/null +++ b/ion-c @@ -0,0 +1 @@ +Subproject commit 8471ebb59c38532121a4675d5c2876ba7e59f3d5