Changeset 3140 for trunk/src/kmk/rule.c
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/rule.c
r2591 r3140 1 1 /* Pattern and suffix rule internals for GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 2 Copyright (C) 1988-2016 Free Software Foundation, Inc. 5 3 This file is part of GNU Make. 6 4 … … 17 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 18 16 19 #include "make .h"17 #include "makeint.h" 20 18 21 19 #include <assert.h> 22 20 21 #include "filedef.h" 23 22 #include "dep.h" 24 #include "filedef.h"25 23 #include "job.h" 26 24 #include "commands.h" … … 75 73 char *name; 76 74 int namelen; 77 struct rule *rule , *lastrule;75 struct rule *rule; 78 76 79 77 num_pattern_rules = max_pattern_targets = max_pattern_deps = 0; … … 83 81 namelen = 0; 84 82 rule = pattern_rules; 85 lastrule = 0;86 83 while (rule != 0) 87 84 { … … 93 90 94 91 if (rule->num > max_pattern_targets) 95 92 max_pattern_targets = rule->num; 96 93 97 94 for (dep = rule->deps; dep != 0; dep = dep->next) 98 95 { 99 96 const char *dname = dep_name (dep); 100 97 unsigned int len = strlen (dname); … … 112 109 ndeps++; 113 110 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 /* In the deps of an implicit rule the `changed' flag132 133 134 135 136 137 138 139 140 111 if (len > max_pattern_dep_length) 112 max_pattern_dep_length = len; 113 114 if (p != 0 && p2 > p) 115 { 116 /* There is a slash before the % in the dep name. 117 Extract the directory name. */ 118 if (p == dname) 119 ++p; 120 if (p - dname > namelen) 121 { 122 namelen = p - dname; 123 name = xrealloc (name, namelen + 1); 124 } 125 memcpy (name, dname, p - dname); 126 name[p - dname] = '\0'; 127 128 /* In the deps of an implicit rule the 'changed' flag 129 actually indicates that the dependency is in a 130 nonexistent subdirectory. */ 131 132 dep->changed = !dir_file_exists_p (name, ""); 133 } 134 else 135 /* This dependency does not reside in a subdirectory. */ 136 dep->changed = 0; 137 } 141 138 142 139 if (ndeps > max_pattern_deps) 143 max_pattern_deps = ndeps; 144 145 lastrule = rule; 140 max_pattern_deps = ndeps; 141 146 142 rule = next; 147 143 } 148 144 149 if (name != 0) 150 free (name); 145 free (name); 151 146 } 152 147 … … 155 150 TARGET is the target suffix; SOURCE is the source suffix. 156 151 CMDS are the commands. 157 If TARGET is nil, it means the target pattern should be `(%.o)'.152 If TARGET is nil, it means the target pattern should be '(%.o)'. 158 153 If SOURCE is nil, it means there should be no deps. */ 159 154 … … 170 165 if (target == 0) 171 166 { 172 /* Special case: TARGET being nil means we are defining a `.X.a' suffix173 rule; the target pattern is always `(%.o)'. */167 /* Special case: TARGET being nil means we are defining a '.X.a' suffix 168 rule; the target pattern is always '(%.o)'. */ 174 169 #ifdef VMS 175 170 *names = strcache_add_len ("(%.obj)", 7); … … 225 220 unsigned int l = strlen (dep_name (d)); 226 221 if (l > maxsuffix) 227 222 maxsuffix = l; 228 223 } 229 224 … … 236 231 237 232 /* Make a rule that is just the suffix, with no deps or commands. 238 233 This rule exists solely to disqualify match-anything rules. */ 239 234 convert_suffix_rule (dep_name (d), 0, 0); 240 235 241 236 if (d->file->cmds != 0) 242 243 237 /* Record a pattern for this suffix's null-suffix rule. */ 238 convert_suffix_rule ("", dep_name (d), d->file->cmds); 244 239 245 240 /* Add every other suffix to this one and see if it exists as a … … 249 244 250 245 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 251 246 { 252 247 struct file *f; 253 248 unsigned int s2len; 254 249 255 250 s2len = strlen (dep_name (d2)); 256 251 257 252 /* Can't build something from itself. */ 258 259 260 261 262 263 264 265 266 267 /* A suffix rule `.X.a:' generates the pattern rule `(%.o): %.X'.268 It also generates a normal `%.a: %.X' rule below. */269 convert_suffix_rule (NULL, /* Indicates `(%.o)'. */270 271 272 273 /* The suffix rule `.X.Y:' is converted274 to the pattern rule `%.Y: %.X'. */275 276 253 if (slen == s2len && streq (dep_name (d), dep_name (d2))) 254 continue; 255 256 memcpy (rulename + slen, dep_name (d2), s2len + 1); 257 f = lookup_file (rulename); 258 if (f == 0 || f->cmds == 0) 259 continue; 260 261 if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a') 262 /* A suffix rule '.X.a:' generates the pattern rule '(%.o): %.X'. 263 It also generates a normal '%.a: %.X' rule below. */ 264 convert_suffix_rule (NULL, /* Indicates '(%.o)'. */ 265 dep_name (d), 266 f->cmds); 267 268 /* The suffix rule '.X.Y:' is converted 269 to the pattern rule '%.Y: %.X'. */ 270 convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds); 271 } 277 272 } 278 273 } … … 302 297 for (i = 0; i < rule->num; ++i) 303 298 { 304 305 306 299 for (j = 0; j < r->num; ++j) 300 if (!streq (rule->targets[i], r->targets[j])) 301 break; 307 302 /* If all the targets matched... */ 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 303 if (j == r->num) 304 { 305 struct dep *d, *d2; 306 for (d = rule->deps, d2 = r->deps; 307 d != 0 && d2 != 0; d = d->next, d2 = d2->next) 308 if (!streq (dep_name (d), dep_name (d2))) 309 break; 310 if (d == 0 && d2 == 0) 311 { 312 /* All the dependencies matched. */ 313 if (override) 314 { 315 /* Remove the old rule. */ 316 freerule (r, lastrule); 317 /* Install the new one. */ 318 if (pattern_rules == 0) 319 pattern_rules = rule; 320 else 321 last_pattern_rule->next = rule; 322 last_pattern_rule = rule; 323 324 /* We got one. Stop looking. */ 325 goto matched; 326 } 327 else 328 { 329 /* The old rule stays intact. Destroy the new one. */ 330 freerule (rule, (struct rule *) 0); 331 return 0; 332 } 333 } 334 } 340 335 } 341 336 … … 346 341 /* There was no rule to replace. */ 347 342 if (pattern_rules == 0) 348 343 pattern_rules = rule; 349 344 else 350 345 last_pattern_rule->next = rule; 351 346 last_pattern_rule = rule; 352 347 } … … 359 354 in the structure P points to. These strings come from one of 360 355 the arrays of default implicit pattern rules. 361 TERMINAL specifies what the `terminal' field of the rule should be. */356 TERMINAL specifies what the 'terminal' field of the rule should be. */ 362 357 363 358 void … … 365 360 { 366 361 struct rule *r; 367 c har *ptr;362 const char *ptr; 368 363 369 364 r = xmalloc (sizeof (struct rule)); … … 381 376 382 377 ptr = p->dep; 383 r->deps = PARSE_ FILE_SEQ (&ptr, struct dep, '\0', NULL, 0);378 r->deps = PARSE_SIMPLE_SEQ ((char **)&ptr, struct dep); 384 379 385 380 if (new_pattern_rule (r, 0)) … … 393 388 r->cmds->fileinfo.filenm = 0; 394 389 r->cmds->fileinfo.lineno = 0; 390 r->cmds->fileinfo.offset = 0; 395 391 /* These will all be string literals, but we malloc space for them 396 392 anyway because somebody might want to free them later. */ 397 393 r->cmds->commands = xstrdup (p->commands); 398 394 r->cmds->command_lines = 0; 395 r->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT; 396 399 397 #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS 400 398 r->cmds->refs = 1000; … … 423 421 are ways that they could be in more than one place: 424 422 * If the commands came from a suffix rule, they could also be in 425 the `struct file's for other suffix rules or plain targets given423 the 'struct file's for other suffix rules or plain targets given 426 424 on the same makefile line. 427 425 * If two suffixes that together make a two-suffix rule were each 428 426 given twice in the .SUFFIXES list, and in the proper order, two 429 427 identical pattern rules would be created and the second one would 430 be discarded here, but both would contain the same `struct commands'431 pointer from the `struct file' for the suffix rule. */428 be discarded here, but both would contain the same 'struct commands' 429 pointer from the 'struct file' for the suffix rule. */ 432 430 433 431 free (rule); … … 488 486 /* Print the data base of rules. */ 489 487 490 static void 488 static void /* Useful to call from gdb. */ 491 489 print_rule (struct rule *r) 492 490 { … … 524 522 525 523 if (r->terminal) 526 524 ++terminal; 527 525 } 528 526 … … 532 530 { 533 531 printf (_("\n# %u implicit rules, %u"), rules, terminal); 534 #ifndef 532 #ifndef NO_FLOAT 535 533 printf (" (%.1f%%)", (double) terminal / (double) rules * 100.0); 536 534 #else 537 535 { 538 539 536 int f = (terminal * 1000 + 5) / rules; 537 printf (" (%d.%d%%)", f/10, f%10); 540 538 } 541 539 #endif … … 548 546 makefiles and thus count_implicit_rule_limits wasn't called yet. */ 549 547 if (num_pattern_rules != 0) 550 fatal (NILF, _("BUG: num_pattern_rules is wrong! %u != %u"),551 552 } 553 } 548 ONN (fatal, NILF, _("BUG: num_pattern_rules is wrong! %u != %u"), 549 num_pattern_rules, rules); 550 } 551 }
Note:
See TracChangeset
for help on using the changeset viewer.