genmoddep.awk 2.4 KB

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