genmoddep.awk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #! /usr/bin/awk -f
  2. #
  3. # Copyright (C) 2006 Free Software Foundation, Inc.
  4. #
  5. # This genmoddep.awk is free software; the author
  6. # gives unlimited permission to copy and/or distribute it,
  7. # with or without modifications, as long as this notice is preserved.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  11. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. # PARTICULAR PURPOSE.
  13. # Read symbols' info from stdin.
  14. BEGIN {
  15. error = 0
  16. }
  17. {
  18. if ($1 == "defined") {
  19. if ($3 !~ /^\.refptr\./ && $3 in symtab) {
  20. printf "%s in %s is duplicated in %s\n", $3, $2, symtab[$3] >"/dev/stderr";
  21. error++;
  22. }
  23. symtab[$3] = $2;
  24. modtab[$2] = "" modtab[$2]
  25. } else if ($1 == "undefined") {
  26. if ($3 in symtab)
  27. modtab[$2] = modtab[$2] " " symtab[$3];
  28. else if ($3 != "__gnu_local_gp" && $3 != "_gp_disp") {
  29. printf "%s in %s is not defined\n", $3, $2 >"/dev/stderr";
  30. error++;
  31. }
  32. } else if ($1 == "depends") {
  33. for (i = 3; i <= NF; i++) {
  34. modtab[$2] = modtab[$2] " " $i;
  35. }
  36. } else if ($1 == "") {} #Skip empty lines
  37. else {
  38. printf "error: %u: unrecognized input format\n", NR >"/dev/stderr";
  39. error++;
  40. }
  41. }
  42. # Output the result.
  43. END {
  44. if (error >= 1)
  45. exit 1;
  46. total_depcount = 0
  47. for (mod in modtab) {
  48. # Remove duplications.
  49. split(modtab[mod], depmods, " ");
  50. for (depmod in uniqmods) {
  51. delete uniqmods[depmod];
  52. }
  53. for (i in depmods) {
  54. depmod = depmods[i];
  55. # Ignore kernel, as always loaded.
  56. if (depmod != "kernel" && depmod != mod)
  57. uniqmods[depmod] = 1;
  58. }
  59. modlist = ""
  60. depcount[mod] = 0
  61. n = asorti(uniqmods, w)
  62. for (i = 1; i <= n; i++) {
  63. depmod = w[i]
  64. modlist = modlist " " depmod;
  65. inverse_dependencies[depmod] = inverse_dependencies[depmod] " " mod
  66. depcount[mod]++
  67. total_depcount++
  68. }
  69. if (mod == "all_video") {
  70. continue;
  71. }
  72. printf "%s:%s\n", mod, modlist;
  73. }
  74. # Check that we have no dependency circles
  75. while (total_depcount != 0) {
  76. something_done = 0
  77. for (mod in depcount) {
  78. if (depcount[mod] == 0) {
  79. delete depcount[mod]
  80. split(inverse_dependencies[mod], inv_depmods, " ");
  81. for (ctr in inv_depmods) {
  82. depcount[inv_depmods[ctr]]--
  83. total_depcount--
  84. }
  85. delete inverse_dependencies[mod]
  86. something_done = 1
  87. }
  88. }
  89. if (something_done == 0) {
  90. for (mod in depcount) {
  91. circle = circle " " mod
  92. }
  93. printf "error: modules %s form a dependency circle\n", circle >"/dev/stderr";
  94. exit 1
  95. }
  96. }
  97. modlist = ""
  98. while (getline <"video.lst") {
  99. modlist = modlist " " $1;
  100. }
  101. printf "all_video:%s\n", modlist;
  102. }