sysd-rules.awk 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # This is a GAWK script to generate the sysd-rules file.
  2. # It does not read any input, but it requires that several variables
  3. # be set on its command line (using -v) to their makefile counterparts:
  4. # all_object_suffixes $(all-object-suffixes)
  5. # inhibit_sysdep_asm $(inhibit-sysdep-asm)
  6. # config_sysdirs $(config_sysdirs)
  7. # sysd_rules_patterns $(sysd-rules-patterns)
  8. BEGIN {
  9. print "sysd-rules-sysdirs :=", config_sysdirs;
  10. nsuffixes = split(all_object_suffixes, suffixes);
  11. ninhibit_asm = split(inhibit_sysdep_asm, inhibit_asm);
  12. nsysdirs = split(config_sysdirs, sysdirs);
  13. npatterns = split(sysd_rules_patterns, patterns);
  14. # Each element of $(sysd-rules-patterns) is a pair TARGET:DEP.
  15. # They are no in particular order. We need to sort them so that
  16. # the longest TARGET is first, and, among elements with the same
  17. # TARGET, the longest DEP is first.
  18. for (i = 1; i <= npatterns; ++i) {
  19. if (split(patterns[i], td, ":") != 2) {
  20. msg = "bad sysd-rules-patterns element '" patterns[i] "'";
  21. print msg > "/dev/stderr";
  22. exit 2;
  23. }
  24. target_order = sprintf("%09d", npatterns + 1 - length(td[1]));
  25. dep_order = sprintf("%09d", npatterns - length(td[2]));
  26. sort_patterns[target_order SUBSEP dep_order] = patterns[i];
  27. }
  28. asorti(sort_patterns, map_patterns);
  29. for (i in map_patterns) {
  30. patterns[i] = sort_patterns[map_patterns[i]];
  31. }
  32. for (sysdir_idx = 1; sysdir_idx <= nsysdirs; ++sysdir_idx) {
  33. dir = sysdirs[sysdir_idx];
  34. if (dir !~ /^\//) dir = "$(..)" dir;
  35. asm_rules = 1;
  36. for (i = 1; i <= ninhibit_asm; ++i) {
  37. if (dir ~ ("^.*sysdeps/" inhibit_asm[i] "$")) {
  38. asm_rules = 0;
  39. break;
  40. }
  41. }
  42. for (suffix_idx = 1; suffix_idx <= nsuffixes; ++suffix_idx) {
  43. o = suffixes[suffix_idx];
  44. for (pattern_idx = 1; pattern_idx <= npatterns; ++pattern_idx) {
  45. pattern = patterns[pattern_idx];
  46. split(pattern, td, ":");
  47. target_pattern = td[1];
  48. dep_pattern = td[2];
  49. # rtld objects are always PIC.
  50. if (target_pattern ~ /^rtld/ && o != ".os") {
  51. continue;
  52. }
  53. if (target_pattern == "%") {
  54. command_suffix = "";
  55. } else {
  56. prefix = gensub(/%/, "", 1, target_pattern);
  57. command_suffix = " $(" prefix "CPPFLAGS)" " $(" prefix "CFLAGS)";
  58. }
  59. target = "$(objpfx)" target_pattern o ":";
  60. if (asm_rules) {
  61. dep = dir "/" dep_pattern ".S";
  62. print target, dep, "$(before-compile)";
  63. print "\t$(compile-command.S)" command_suffix;
  64. }
  65. dep = dir "/" dep_pattern ".c";
  66. print target, dep, "$(before-compile)";
  67. print "\t$(compile-command.c)" command_suffix;
  68. }
  69. }
  70. print "$(inst_includedir)/%.h:", dir "/%.h", "$(+force)";
  71. print "\t$(do-install)";
  72. }
  73. print "sysd-rules-done := t";
  74. exit 0;
  75. }