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 9BEGIN { 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 # rtld objects are always PIC. 54 if (target_pattern ~ /^rtld/ && o != ".os") { 55 continue; 56 } 57 if (target_pattern == "%") { 58 command_suffix = ""; 59 } else { 60 prefix = gensub(/%/, "", 1, target_pattern); 61 command_suffix = " $(" prefix "CPPFLAGS)" " $(" prefix "CFLAGS)"; 62 } 63 target = "$(objpfx)" target_pattern o ":"; 64 if (asm_rules) { 65 dep = dir "/" dep_pattern ".S"; 66 print target, dep, "$(before-compile)"; 67 print "\t$(compile-command.S)" command_suffix; 68 } 69 dep = dir "/" dep_pattern ".c"; 70 print target, dep, "$(before-compile)"; 71 print "\t$(compile-command.c)" command_suffix; 72 } 73 } 74 print "$(inst_includedir)/%.h:", dir "/%.h", "$(+force)"; 75 print "\t$(do-install)"; 76 } 77 78 print "sysd-rules-done := t"; 79 exit 0; 80} 81