Changeset 2591 for trunk/src/kmk/commands.c
- Timestamp:
- Jun 17, 2012, 10:45:31 PM (13 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
- Property svn:ignore
-
old new 13 13 stamp-* 14 14 makebook* 15 15 16 .*gdbinit 17 .gdb_history 18 16 19 *.dep 17 20 *.dvi … … 31 34 *.pg 32 35 *.pgs 36 33 37 README 34 38 README.DOS 35 39 README.W32 40 README.OS2 36 41 aclocal.m4 37 42 autom4te.cache … … 52 57 config.h.W32 53 58 config.h-vms 59 54 60 loadavg 55 61 loadavg.c 56 62 make 63 57 64 .deps 58 65 .dep_segment 66 ID 67 TAGS 68 59 69 _* 60 70 sun4 … … 72 82 sol2 73 83 i486-linux 84 74 85 customs 86 75 87 install-sh 76 88 mkinstalldirs 89 90 .directive.asc
-
- Property svn:ignore
-
trunk/src/kmk/commands.c
r2027 r2591 1 1 /* Command processing for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software4 Foundation, Inc.3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 5 5 This file is part of GNU Make. 6 6 … … 44 44 45 45 46 #ifndef CONFIG_WITH_STRCACHE2 47 48 static unsigned long 49 dep_hash_1 (const void *key) 50 { 51 const struct dep *d = key; 52 return_STRING_HASH_1 (dep_name (d)); 53 } 54 55 static unsigned long 56 dep_hash_2 (const void *key) 57 { 58 const struct dep *d = key; 59 return_STRING_HASH_2 (dep_name (d)); 60 } 61 62 static int 63 dep_hash_cmp (const void *x, const void *y) 64 { 65 const struct dep *dx = x; 66 const struct dep *dy = y; 67 return strcmp (dep_name (dx), dep_name (dy)); 68 } 69 70 71 #else /* CONFIG_WITH_STRCACHE2 */ 72 73 /* Exploit the fact that all names are in the string cache. This means equal 74 names shall have the same storage and there is no need for hashing or 75 comparing. Use the address as the first hash, avoiding any touching of 76 the name, and the length as the second. */ 77 78 static unsigned long 79 dep_hash_1 (const void *key) 80 { 81 const char *name = dep_name ((struct dep const *) key); 82 assert (strcache2_is_cached (&file_strcache, name)); 83 return (size_t) name / sizeof(void *); 84 } 85 86 static unsigned long 87 dep_hash_2 (const void *key) 88 { 89 const char *name = dep_name ((struct dep const *) key); 90 return strcache2_get_len (&file_strcache, name); 91 } 92 93 static int 94 dep_hash_cmp (const void *x, const void *y) 95 { 96 struct dep *dx = (struct dep *) x; 97 struct dep *dy = (struct dep *) y; 98 const char *dxname = dep_name (dx); 99 const char *dyname = dep_name (dy); 100 int cmp = dxname == dyname ? 0 : 1; 101 102 /* check preconds: both cached and the cache contains no duplicates. */ 103 assert (strcache2_is_cached (&file_strcache, dxname)); 104 assert (strcache2_is_cached (&file_strcache, dyname)); 105 assert (cmp == 0 || strcmp (dxname, dyname) != 0); 106 107 /* If the names are the same but ignore_mtimes are not equal, one of these 108 is an order-only prerequisite and one isn't. That means that we should 109 remove the one that isn't and keep the one that is. */ 110 111 if (!cmp && dx->ignore_mtime != dy->ignore_mtime) 112 dx->ignore_mtime = dy->ignore_mtime = 0; 113 114 return cmp; 115 } 116 117 #endif /* CONFIG_WITH_STRCACHE2 */ 118 46 119 /* Set FILE's automatic variables up. */ 47 120 … … 53 126 #endif 54 127 { 55 conststruct dep *d;128 struct dep *d; 56 129 const char *at, *percent, *star, *less; 57 130 #ifdef CONFIG_WITH_STRCACHE2 … … 138 211 if (!d->ignore_mtime) 139 212 { 140 less = dep_name (d); 213 if (!d->need_2nd_expansion) 214 less = dep_name (d); 141 215 break; 142 216 } … … 214 288 unsigned int len; 215 289 290 struct hash_table dep_hash; 291 void **slot; 292 216 293 /* Compute first the value for $+, which is supposed to contain 217 294 duplicate dependencies as they were listed in the makefile. */ 218 295 219 296 plus_len = 0; 297 bar_len = 0; 220 298 for (d = file->deps; d != 0; d = d->next) 221 299 if (! d->ignore_mtime) 300 { 301 if (!d->need_2nd_expansion) 302 { 222 303 #ifndef CONFIG_WITH_STRCACHE2 223 plus_len += strlen (dep_name (d)) + 1; 224 #else 225 plus_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1; 226 #endif 304 if (d->ignore_mtime) 305 bar_len += strlen (dep_name (d)) + 1; 306 else 307 plus_len += strlen (dep_name (d)) + 1; 308 #else 309 if (d->ignore_mtime) 310 bar_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1; 311 else 312 plus_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1; 313 #endif 314 } 315 } 316 317 if (bar_len == 0) 318 bar_len++; 227 319 if (plus_len == 0) 228 320 plus_len++; … … 230 322 if (plus_len > plus_max) 231 323 plus_value = xrealloc (plus_value, plus_max = plus_len); 324 232 325 cp = plus_value; 233 326 234 327 qmark_len = plus_len + 1; /* Will be this or less. */ 235 328 for (d = file->deps; d != 0; d = d->next) 236 if (! d->ignore_mtime )329 if (! d->ignore_mtime && ! d->need_2nd_expansion) 237 330 { 238 331 const char *c = dep_name (d); … … 255 348 cp += len; 256 349 *cp++ = FILE_LIST_SEPARATOR; 257 if (! d->changed)350 if (! (d->changed || always_make_flag)) 258 351 qmark_len -= len + 1; /* Don't space in $? for this one. */ 259 352 } … … 263 356 cp[cp > plus_value ? -1 : 0] = '\0'; 264 357 DEFINE_VARIABLE ("+", 1, plus_value); 265 266 /* Make sure that no dependencies are repeated. This does not267 really matter for the purpose of updating targets, but it268 might make some names be listed twice for $^ and $?. */269 270 uniquize_deps (file->deps);271 272 bar_len = 0;273 for (d = file->deps; d != 0; d = d->next)274 if (d->ignore_mtime)275 #ifndef CONFIG_WITH_STRCACHE2276 bar_len += strlen (dep_name (d)) + 1;277 #else278 bar_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;279 #endif280 if (bar_len == 0)281 bar_len++;282 358 283 359 /* Compute the values for $^, $?, and $|. */ … … 293 369 bp = bar_value; 294 370 371 /* Make sure that no dependencies are repeated in $^, $?, and $|. It 372 would be natural to combine the next two loops but we can't do it 373 because of a situation where we have two dep entries, the first 374 is order-only and the second is normal (see below). */ 375 376 hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp); 377 295 378 for (d = file->deps; d != 0; d = d->next) 296 379 { 297 const char *c = dep_name (d); 298 380 if (d->need_2nd_expansion) 381 continue; 382 383 slot = hash_find_slot (&dep_hash, d); 384 if (HASH_VACANT (*slot)) 385 hash_insert_at (&dep_hash, d, slot); 386 else 387 { 388 /* Check if the two prerequisites have different ignore_mtime. 389 If so then we need to "upgrade" one that is order-only. */ 390 391 struct dep* hd = (struct dep*) *slot; 392 393 if (d->ignore_mtime != hd->ignore_mtime) 394 d->ignore_mtime = hd->ignore_mtime = 0; 395 } 396 } 397 398 for (d = file->deps; d != 0; d = d->next) 399 { 400 const char *c; 401 402 if (d->need_2nd_expansion || hash_find_item (&dep_hash, d) != d) 403 continue; 404 405 c = dep_name (d); 299 406 #ifndef NO_ARCHIVES 300 407 if (ar_name (c)) 301 408 { 302 409 c = strchr (c, '(') + 1; … … 313 420 if (d->ignore_mtime) 314 421 { 315 422 memcpy (bp, c, len); 316 423 bp += len; 317 424 *bp++ = FILE_LIST_SEPARATOR; 318 425 } 319 426 else 320 427 { 321 428 memcpy (cp, c, len); 322 429 cp += len; 323 430 *cp++ = FILE_LIST_SEPARATOR; 324 if (d->changed )431 if (d->changed || always_make_flag) 325 432 { 326 433 memcpy (qp, c, len); … … 331 438 } 332 439 440 hash_free (&dep_hash, 0); 441 333 442 /* Kill the last spaces and define the variables. */ 334 443 … … 352 461 file->org_deps = copy_dep_chain (file->deps); 353 462 354 uniquize_deps (file->deps); 463 /** @todo do uniquize_deps (file->deps); in the $(dep-* ) functions, it'll 464 * save even more space that way. */ 355 465 } 356 466 #endif /* CONFIG_WITH_LAZY_DEPS_VARS */ … … 365 475 chop_commands (struct commands *cmds) 366 476 { 367 const char *p;368 477 unsigned int nlines, idx; 369 478 char **lines; … … 375 484 return; 376 485 377 /* Chop CMDS->commands up into lines in CMDS->command_lines. 378 Also set the corresponding CMDS->lines_flags elements, 379 and the CMDS->any_recurse flag. */ 380 381 nlines = 5; 382 lines = xmalloc (5 * sizeof (char *)); 383 idx = 0; 384 p = cmds->commands; 385 while (*p != '\0') 386 { 387 const char *end = p; 388 find_end:; 389 end = strchr (end, '\n'); 390 if (end == 0) 391 end = p + strlen (p); 392 else if (end > p && end[-1] == '\\') 486 /* Chop CMDS->commands up into lines in CMDS->command_lines. */ 487 488 if (one_shell) 489 { 490 int l = strlen (cmds->commands); 491 492 nlines = 1; 493 lines = xmalloc (nlines * sizeof (char *)); 494 lines[0] = xstrdup (cmds->commands); 495 496 /* Strip the trailing newline. */ 497 if (l > 0 && lines[0][l-1] == '\n') 498 lines[0][l-1] = '\0'; 499 } 500 else 501 { 502 const char *p; 503 504 nlines = 5; 505 lines = xmalloc (nlines * sizeof (char *)); 506 idx = 0; 507 p = cmds->commands; 508 while (*p != '\0') 393 509 { 394 int backslash = 1; 395 const char *b; 396 for (b = end - 2; b >= p && *b == '\\'; --b) 397 backslash = !backslash; 398 if (backslash) 510 const char *end = p; 511 find_end:; 512 end = strchr (end, '\n'); 513 if (end == 0) 514 end = p + strlen (p); 515 else if (end > p && end[-1] == '\\') 399 516 { 400 ++end; 401 goto find_end; 517 int backslash = 1; 518 const char *b; 519 for (b = end - 2; b >= p && *b == '\\'; --b) 520 backslash = !backslash; 521 if (backslash) 522 { 523 ++end; 524 goto find_end; 525 } 402 526 } 527 528 if (idx == nlines) 529 { 530 nlines += 2; 531 lines = xrealloc (lines, nlines * sizeof (char *)); 532 } 533 lines[idx++] = xstrndup (p, end - p); 534 p = end; 535 if (*p != '\0') 536 ++p; 403 537 } 404 538 405 if (idx == nlines)539 if (idx != nlines) 406 540 { 407 nlines += 2;541 nlines = idx; 408 542 lines = xrealloc (lines, nlines * sizeof (char *)); 409 543 } 410 lines[idx++] = savestring (p, end - p); 411 p = end; 412 if (*p != '\0') 413 ++p; 414 } 415 416 if (idx != nlines) 417 { 418 nlines = idx; 419 lines = xrealloc (lines, nlines * sizeof (char *)); 420 } 544 } 545 546 /* Finally, set the corresponding CMDS->lines_flags elements and the 547 CMDS->any_recurse flag. */ 421 548 422 549 cmds->ncommand_lines = nlines; … … 429 556 cmds->lines_flags = xmalloc (nlines * sizeof (cmds->lines_flags[0])); 430 557 #endif 558 431 559 for (idx = 0; idx < nlines; ++idx) 432 560 { 433 561 int flags = 0; 434 435 for (p = lines[idx]; 436 #ifndef CONFIG_WITH_COMMANDS_FUNC 437 isblank ((unsigned char)*p) || *p == '-' || *p == '@' || *p == '+'; 438 #else 439 isblank ((unsigned char)*p) || *p == '-' || *p == '@' || *p == '+' || *p == '%'; 440 #endif 441 ++p) 442 switch (*p) 562 const char *p = lines[idx]; 563 564 while (isblank (*p) || *p == '-' || *p == '@' || *p == '+' IF_WITH_COMMANDS_FUNC(|| *p == '%')) 565 switch (*(p++)) 443 566 { 444 567 case '+':
Note:
See TracChangeset
for help on using the changeset viewer.