lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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 | |
| 9 | BEGIN { |
| 10 | print "sysd-rules-sysdirs :=", config_sysdirs; |
| 11 | |
| 12 | nsuffixes = split(all_object_suffixes, suffixes); |
| 13 | ninhibit_asm = split(inhibit_sysdep_asm, inhibit_asm); |
| 14 | nsysdirs = split(config_sysdirs, sysdirs); |
| 15 | npatterns = split(sysd_rules_patterns, patterns); |
| 16 | |
| 17 | # Each element of $(sysd-rules-patterns) is a pair TARGET:DEP. |
| 18 | # They are no in particular order. We need to sort them so that |
| 19 | # the longest TARGET is first, and, among elements with the same |
| 20 | # TARGET, the longest DEP is first. |
| 21 | for (i = 1; i <= npatterns; ++i) { |
| 22 | if (split(patterns[i], td, ":") != 2) { |
| 23 | msg = "bad sysd-rules-patterns element '" patterns[i] "'"; |
| 24 | print msg > "/dev/stderr"; |
| 25 | exit 2; |
| 26 | } |
| 27 | target_order = sprintf("%09d", npatterns + 1 - length(td[1])); |
| 28 | dep_order = sprintf("%09d", npatterns - length(td[2])); |
| 29 | sort_patterns[target_order SUBSEP dep_order] = patterns[i]; |
| 30 | } |
| 31 | asorti(sort_patterns, map_patterns); |
| 32 | for (i in map_patterns) { |
| 33 | patterns[i] = sort_patterns[map_patterns[i]]; |
| 34 | } |
| 35 | |
| 36 | for (sysdir_idx = 1; sysdir_idx <= nsysdirs; ++sysdir_idx) { |
| 37 | dir = sysdirs[sysdir_idx]; |
| 38 | if (dir !~ /^\//) dir = "$(..)" dir; |
| 39 | asm_rules = 1; |
| 40 | for (i = 1; i <= ninhibit_asm; ++i) { |
| 41 | if (dir ~ ("^.*sysdeps/" inhibit_asm[i] "$")) { |
| 42 | asm_rules = 0; |
| 43 | break; |
| 44 | } |
| 45 | } |
| 46 | for (suffix_idx = 1; suffix_idx <= nsuffixes; ++suffix_idx) { |
| 47 | o = suffixes[suffix_idx]; |
| 48 | for (pattern_idx = 1; pattern_idx <= npatterns; ++pattern_idx) { |
| 49 | pattern = patterns[pattern_idx]; |
| 50 | split(pattern, td, ":"); |
| 51 | target_pattern = td[1]; |
| 52 | dep_pattern = td[2]; |
| 53 | if (target_pattern == "%") { |
| 54 | command_suffix = ""; |
| 55 | } else { |
| 56 | prefix = gensub(/%/, "", "", target_pattern); |
| 57 | command_suffix = " $(" prefix "CPPFLAGS)"; |
| 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 | |
| 74 | print "sysd-rules-done := t"; |
| 75 | exit 0; |
| 76 | } |