genmoddep.awk 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. }
  33. else {
  34. printf "error: %u: unrecognized input format\n", NR >"/dev/stderr";
  35. error++;
  36. }
  37. }
  38. # Output the result.
  39. END {
  40. if (error >= 1)
  41. exit 1;
  42. total_depcount = 0
  43. for (mod in modtab) {
  44. # Remove duplications.
  45. split(modtab[mod], depmods, " ");
  46. for (depmod in uniqmods) {
  47. delete uniqmods[depmod];
  48. }
  49. for (i in depmods) {
  50. depmod = depmods[i];
  51. # Ignore kernel, as always loaded.
  52. if (depmod != "kernel" && depmod != mod)
  53. uniqmods[depmod] = 1;
  54. }
  55. modlist = ""
  56. depcount[mod] = 0
  57. for (depmod in uniqmods) {
  58. modlist = modlist " " depmod;
  59. inverse_dependencies[depmod] = inverse_dependencies[depmod] " " mod
  60. depcount[mod]++
  61. total_depcount++
  62. }
  63. if (mod == "all_video") {
  64. continue;
  65. }
  66. printf "%s:%s\n", mod, modlist;
  67. }
  68. # Check that we have no dependency circles
  69. while (total_depcount != 0) {
  70. something_done = 0
  71. for (mod in depcount) {
  72. if (depcount[mod] == 0) {
  73. delete depcount[mod]
  74. split(inverse_dependencies[mod], inv_depmods, " ");
  75. for (ctr in inv_depmods) {
  76. depcount[inv_depmods[ctr]]--
  77. total_depcount--
  78. }
  79. delete inverse_dependencies[mod]
  80. something_done = 1
  81. }
  82. }
  83. if (something_done == 0) {
  84. for (mod in depcount) {
  85. circle = circle " " mod
  86. }
  87. printf "error: modules %s form a dependency circle\n", circle >"/dev/stderr";
  88. exit 1
  89. }
  90. }
  91. modlist = ""
  92. while (getline <"video.lst") {
  93. modlist = modlist " " $1;
  94. }
  95. printf "all_video:%s\n", modlist;
  96. }