|
| 1 | +BEGIN { |
| 2 | + orig_rs = RS; |
| 3 | + orig_fs = FS; |
| 4 | + RS=" "; |
| 5 | + mod_count = 0; |
| 6 | + SUBSEP=":"; |
| 7 | +} |
| 8 | + |
| 9 | +function get_deps(module_name, depline, cmd) |
| 10 | +{ |
| 11 | + # this could probably be made *much* better |
| 12 | + RS=orig_rs; |
| 13 | + FS="[(,) \t]+" |
| 14 | + cmd = "grep PHP_ADD_EXTENSION_DEP ext/" module_name "/config*.m4" |
| 15 | + while (cmd | getline) { |
| 16 | +# printf("GOT: %s,%s,%s,%s,%s\n", $1, $2, $3, $4, $5); |
| 17 | + if (!length($5)) { |
| 18 | + $5 = 0; |
| 19 | + } |
| 20 | + mod_deps[module_name, $4] = $5; |
| 21 | + } |
| 22 | + close(cmd) |
| 23 | + RS=" "; |
| 24 | + FS=orig_fs; |
| 25 | +} |
| 26 | + |
| 27 | +function get_module_index(name, i) |
| 28 | +{ |
| 29 | + for (i in mods) { |
| 30 | + if (mods[i] == name) { |
| 31 | + return i; |
| 32 | + } |
| 33 | + } |
| 34 | + return -1; |
| 35 | +} |
| 36 | + |
| 37 | +function do_deps(mod_idx, module_name, mod_name_len, dep, ext, val, depidx) |
| 38 | +{ |
| 39 | + module_name = mods[mod_idx]; |
| 40 | + mod_name_len = length(module_name); |
| 41 | + |
| 42 | + for (ext in mod_deps) { |
| 43 | + if (substr(ext, 0, mod_name_len+1) != module_name SUBSEP) { |
| 44 | + continue; |
| 45 | + } |
| 46 | + val = mod_deps[ext]; |
| 47 | + ext = substr(ext, mod_name_len+2, length(ext)-mod_name_len); |
| 48 | + |
| 49 | + depidx = get_module_index(ext); |
| 50 | + if (depidx >= 0) { |
| 51 | + do_deps(depidx); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + #printf(" phpext_%s_ptr,\n", module_name); |
| 56 | + printf(" phpext_%s_ptr,@NEWLINE@", module_name); |
| 57 | + delete mods[mod_idx]; |
| 58 | +} |
| 59 | + |
| 60 | +function count(arr, n, i) |
| 61 | +{ |
| 62 | + n = 0; |
| 63 | + for (i in arr) |
| 64 | + n++; |
| 65 | + return n; |
| 66 | +} |
| 67 | + |
| 68 | +/^[a-zA-Z0-9_-]+/ { |
| 69 | + # mini hack for pedantic awk |
| 70 | + gsub("[^a-zA-Z0-9_-]", "", $1) |
| 71 | + # add each item to array |
| 72 | + mods[mod_count++] = $1 |
| 73 | + |
| 74 | + # see if it has any module deps |
| 75 | + get_deps($1); |
| 76 | +} |
| 77 | +END { |
| 78 | + # order it correctly |
| 79 | + out_count = 0; |
| 80 | + |
| 81 | + while (count(mods)) { |
| 82 | + # count down, since we need to assemble it in reverse order |
| 83 | + for (i = mod_count-1; i >= 0; --i) { |
| 84 | + if (i in mods) { |
| 85 | + do_deps(i); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments