order_by_dep.awk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, module_dir, depline, cmd)
  9. {
  10. # this could probably be made *much* better
  11. RS=orig_rs;
  12. FS="[ \t]*[(,)][ \t]*"
  13. cmd = "grep PHP_ADD_EXTENSION_DEP " module_dir "/config*.m4"
  14. while (cmd | getline) {
  15. #printf("GOT: %s,%s,%s,%s\n", $1, $2, $3, $4);
  16. if (!length($4)) {
  17. $4 = 0;
  18. }
  19. mod_deps[module_name, $3] = $4;
  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. split($1, mod, ";");
  61. # mini hack for pedantic awk
  62. gsub("[^a-zA-Z0-9_-]", "", mod[1])
  63. # add each item to array
  64. mods[mod_count++] = mod[1]
  65. # see if it has any module deps
  66. get_deps(mod[1], mod[2]);
  67. }
  68. END {
  69. # order it correctly
  70. out_count = 0;
  71. while (count(mods)) {
  72. for (i = 0; i <= mod_count - 1; i++) {
  73. if (i in mods) {
  74. do_deps(i);
  75. }
  76. }
  77. }
  78. }