diff options
author | Wez Furlong <wez@php.net> | 2004-07-18 12:03:51 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2004-07-18 12:03:51 +0000 |
commit | ed682e570a3dace45aa894b14b667336f50085cf (patch) | |
tree | 4553eaa4cf8dcaf79804ae3bbd7185fc8efeddaf /build | |
parent | 22b70fcb31d91962bf05fa38a6cc5c2f51b2198c (diff) | |
download | php-git-ed682e570a3dace45aa894b14b667336f50085cf.tar.gz |
Implement extension load-order deps.
Diffstat (limited to 'build')
-rw-r--r-- | build/genif.sh | 6 | ||||
-rw-r--r-- | build/order_by_dep.awk | 89 |
2 files changed, 92 insertions, 3 deletions
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); + } + } + } +} |