order_by_dep.awk 1.5 KB

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