From: Wez Furlong Date: Sun, 18 Jul 2004 12:03:51 +0000 (+0000) Subject: Implement extension load-order deps. X-Git-Tag: PRE_ZEND_VM_DISPATCH_PATCH~474 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed682e570a3dace45aa894b14b667336f50085cf;p=php Implement extension load-order deps. --- diff --git a/acinclude.m4 b/acinclude.m4 index 084f70cc56..22fa428728 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1920,3 +1920,14 @@ AC_DEFUN(PHP_TEST_BUILD, [ LIBS=$old_LIBS ]) ]) + +dnl This macro is currently a placeholder in the config.m4 file +dnl it is scanned by genif.sh when it builds the internal functions +dnl list, so that modules can be init'd in the correct order +dnl $1 = name of extension, $2 = extension upon which it depends +dnl $3 = optional: if true, it's ok for $2 to have not been configured +dnl default is false and should halt the build. +dnl See ADD_EXTENSION_DEP in win32 build +AC_DEFUN(PHP_ADD_EXTENSION_DEP, []) + + diff --git a/build/genif.sh b/build/genif.sh index cb5233b5ac..6fb8fc391f 100644 --- a/build/genif.sh +++ b/build/genif.sh @@ -1,6 +1,6 @@ #! /bin/sh -# $Id: genif.sh,v 1.3 2002-03-22 10:22:41 sas Exp $ +# $Id: genif.sh,v 1.4 2004-07-18 12:03:51 wez Exp $ # replacement for genif.pl infile=$1 @@ -17,13 +17,13 @@ if test -z "$infile" || test -z "$srcdir"; then exit 1 fi -module_ptrs=$extra_module_ptrs header_list= olddir=`pwd` cd $srcdir +module_ptrs="$extra_module_ptrs`echo $@ | $awk -f ./build/order_by_dep.awk`" + for ext in ${1+"$@"} ; do - module_ptrs=" phpext_${ext}_ptr,@NEWLINE@$module_ptrs" header_list="$header_list ext/$ext/*.h" done diff --git a/build/order_by_dep.awk b/build/order_by_dep.awk new file mode 100644 index 0000000000..38128b2e1b --- /dev/null +++ b/build/order_by_dep.awk @@ -0,0 +1,89 @@ +BEGIN { + orig_rs = RS; + orig_fs = FS; + RS=" "; + mod_count = 0; + SUBSEP=":"; +} + +function get_deps(module_name, depline, cmd) +{ + # this could probably be made *much* better + RS=orig_rs; + FS="[(,) \t]+" + cmd = "grep PHP_ADD_EXTENSION_DEP ext/" module_name "/config*.m4" + while (cmd | getline) { +# printf("GOT: %s,%s,%s,%s,%s\n", $1, $2, $3, $4, $5); + if (!length($5)) { + $5 = 0; + } + mod_deps[module_name, $4] = $5; + } + close(cmd) + RS=" "; + FS=orig_fs; +} + +function get_module_index(name, i) +{ + for (i in mods) { + if (mods[i] == name) { + return i; + } + } + return -1; +} + +function do_deps(mod_idx, module_name, mod_name_len, dep, ext, val, depidx) +{ + module_name = mods[mod_idx]; + mod_name_len = length(module_name); + + for (ext in mod_deps) { + if (substr(ext, 0, mod_name_len+1) != module_name SUBSEP) { + continue; + } + val = mod_deps[ext]; + ext = substr(ext, mod_name_len+2, length(ext)-mod_name_len); + + depidx = get_module_index(ext); + if (depidx >= 0) { + do_deps(depidx); + } + } + + #printf(" phpext_%s_ptr,\n", module_name); + printf(" phpext_%s_ptr,@NEWLINE@", module_name); + delete mods[mod_idx]; +} + +function count(arr, n, i) +{ + n = 0; + for (i in arr) + n++; + return n; +} + +/^[a-zA-Z0-9_-]+/ { + # mini hack for pedantic awk + gsub("[^a-zA-Z0-9_-]", "", $1) + # add each item to array + mods[mod_count++] = $1 + + # see if it has any module deps + get_deps($1); +} +END { + # order it correctly + out_count = 0; + + while (count(mods)) { + # count down, since we need to assemble it in reverse order + for (i = mod_count-1; i >= 0; --i) { + if (i in mods) { + do_deps(i); + } + } + } +} diff --git a/configure.in b/configure.in index 3a41752663..bd56fc63ac 100644 --- a/configure.in +++ b/configure.in @@ -130,7 +130,31 @@ PHP_RUNPATH_SWITCH PHP_PROG_RE2C AC_PROG_RANLIB AC_PROG_LN_S -AC_PROG_AWK + +dnl Some vendors force mawk before gawk; mawk is broken so we don't like that, +dnl and check manually +dnl AC_PROG_AWK +AC_CHECK_PROGS(AWK, gawk nawk awk mawk, bork, /usr/xpg4/bin/:$PATH) +case "$AWK" in + *mawk) + AC_MSG_WARN([mawk is known to have problems on some systems. You should install GNU awk]) + ;; + *gawk) + ;; + bork) + AC_MSG_ERROR([Could not find awk; Install GNU awk]) + ;; + *) + AC_MSG_CHECKING([if $AWK is broken]) + if ! $AWK 'function foo() {}' >/dev/null 2>&1 ; then + AC_MSG_RESULT([yes]) + AC_MSG_ERROR([You should install GNU awk]) + else + AC_MSG_RESULT([no - good!]) + fi + ;; +esac + AC_PROG_YACC if test "$YACC" != "bison -y"; then AC_MSG_WARN([You will need bison if you want to regenerate the PHP parsers.]) diff --git a/ext/dom/config.m4 b/ext/dom/config.m4 index 82c97e6bd3..d4eea28109 100644 --- a/ext/dom/config.m4 +++ b/ext/dom/config.m4 @@ -26,6 +26,7 @@ if test "$PHP_DOM" != "no" && test "$PHP_LIBXML" != "no"; then typeinfo.c domerror.c domlocator.c namednodemap.c userdatahandler.c], $ext_shared) PHP_SUBST(DOM_SHARED_LIBADD) + PHP_ADD_EXTENSION_DEP(dom, libxml) ], [ AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.]) ]) diff --git a/ext/simplexml/config.m4 b/ext/simplexml/config.m4 index 9fa9c455ed..1869c20561 100644 --- a/ext/simplexml/config.m4 +++ b/ext/simplexml/config.m4 @@ -18,4 +18,5 @@ if test "$PHP_SIMPLEXML" != "no" && test "$PHP_LIBXML" != "no"; then ], [ AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.]) ]) + PHP_ADD_EXTENSION_DEP(simplexml, libxml) fi diff --git a/ext/spl/config.m4 b/ext/spl/config.m4 index 0f5e43181d..f5b5639ddf 100755 --- a/ext/spl/config.m4 +++ b/ext/spl/config.m4 @@ -10,4 +10,5 @@ if test "$PHP_SPL" != "no"; then fi AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c, $ext_shared) + PHP_ADD_EXTENSION_DEP(spl, simplexml) fi diff --git a/ext/xml/config.m4 b/ext/xml/config.m4 index 72c98ed814..a7c87e3673 100644 --- a/ext/xml/config.m4 +++ b/ext/xml/config.m4 @@ -47,5 +47,6 @@ if test "$PHP_XML" != "no" && test "$PHP_LIBXML" != "no" -o "$PHP_LIBEXPAT_DIR" PHP_NEW_EXTENSION(xml, xml.c $xml_extra_sources, $ext_shared) PHP_SUBST(XML_SHARED_LIBADD) + PHP_ADD_EXTENSION_DEP(xml, libxml) AC_DEFINE(HAVE_XML, 1, [ ]) fi diff --git a/ext/xsl/config.m4 b/ext/xsl/config.m4 index 13290409ac..552ed94f2d 100644 --- a/ext/xsl/config.m4 +++ b/ext/xsl/config.m4 @@ -59,4 +59,5 @@ if test "$PHP_XSL" != "no"; then AC_DEFINE(HAVE_XSL,1,[ ]) PHP_NEW_EXTENSION(xsl, php_xsl.c xsltprocessor.c, $ext_shared) PHP_SUBST(XSL_SHARED_LIBADD) + PHP_ADD_EXTENSION_DEP(xsl, libxml) fi