Changeset 2596 for vendor/gnumake/current/commands.c
- Timestamp:
- Jun 20, 2012, 12:44:52 AM (13 years ago)
- Location:
- vendor/gnumake/current
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current
- Property svn:ignore deleted
-
vendor/gnumake/current/commands.c
r1989 r2596 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 … … 41 41 42 42 43 44 static unsigned long 45 dep_hash_1 (const void *key) 46 { 47 const struct dep *d = key; 48 return_STRING_HASH_1 (dep_name (d)); 49 } 50 51 static unsigned long 52 dep_hash_2 (const void *key) 53 { 54 const struct dep *d = key; 55 return_STRING_HASH_2 (dep_name (d)); 56 } 57 58 static int 59 dep_hash_cmp (const void *x, const void *y) 60 { 61 const struct dep *dx = x; 62 const struct dep *dy = y; 63 return strcmp (dep_name (dx), dep_name (dy)); 64 } 65 43 66 /* Set FILE's automatic variables up. */ 44 67 … … 46 69 set_file_variables (struct file *file) 47 70 { 48 conststruct dep *d;71 struct dep *d; 49 72 const char *at, *percent, *star, *less; 50 73 … … 118 141 if (!d->ignore_mtime) 119 142 { 120 less = dep_name (d); 143 if (!d->need_2nd_expansion) 144 less = dep_name (d); 121 145 break; 122 146 } … … 150 174 unsigned int len; 151 175 176 struct hash_table dep_hash; 177 void **slot; 178 152 179 /* Compute first the value for $+, which is supposed to contain 153 180 duplicate dependencies as they were listed in the makefile. */ 154 181 155 182 plus_len = 0; 183 bar_len = 0; 156 184 for (d = file->deps; d != 0; d = d->next) 157 if (! d->ignore_mtime) 158 plus_len += strlen (dep_name (d)) + 1; 185 { 186 if (!d->need_2nd_expansion) 187 { 188 if (d->ignore_mtime) 189 bar_len += strlen (dep_name (d)) + 1; 190 else 191 plus_len += strlen (dep_name (d)) + 1; 192 } 193 } 194 195 if (bar_len == 0) 196 bar_len++; 197 159 198 if (plus_len == 0) 160 199 plus_len++; … … 162 201 if (plus_len > plus_max) 163 202 plus_value = xrealloc (plus_value, plus_max = plus_len); 203 164 204 cp = plus_value; 165 205 166 206 qmark_len = plus_len + 1; /* Will be this or less. */ 167 207 for (d = file->deps; d != 0; d = d->next) 168 if (! d->ignore_mtime )208 if (! d->ignore_mtime && ! d->need_2nd_expansion) 169 209 { 170 210 const char *c = dep_name (d); … … 183 223 cp += len; 184 224 *cp++ = FILE_LIST_SEPARATOR; 185 if (! d->changed)225 if (! (d->changed || always_make_flag)) 186 226 qmark_len -= len + 1; /* Don't space in $? for this one. */ 187 227 } … … 191 231 cp[cp > plus_value ? -1 : 0] = '\0'; 192 232 DEFINE_VARIABLE ("+", 1, plus_value); 193 194 /* Make sure that no dependencies are repeated. This does not195 really matter for the purpose of updating targets, but it196 might make some names be listed twice for $^ and $?. */197 198 uniquize_deps (file->deps);199 200 bar_len = 0;201 for (d = file->deps; d != 0; d = d->next)202 if (d->ignore_mtime)203 bar_len += strlen (dep_name (d)) + 1;204 if (bar_len == 0)205 bar_len++;206 233 207 234 /* Compute the values for $^, $?, and $|. */ … … 217 244 bp = bar_value; 218 245 246 /* Make sure that no dependencies are repeated in $^, $?, and $|. It 247 would be natural to combine the next two loops but we can't do it 248 because of a situation where we have two dep entries, the first 249 is order-only and the second is normal (see below). */ 250 251 hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp); 252 219 253 for (d = file->deps; d != 0; d = d->next) 220 254 { 221 const char *c = dep_name (d); 222 255 if (d->need_2nd_expansion) 256 continue; 257 258 slot = hash_find_slot (&dep_hash, d); 259 if (HASH_VACANT (*slot)) 260 hash_insert_at (&dep_hash, d, slot); 261 else 262 { 263 /* Check if the two prerequisites have different ignore_mtime. 264 If so then we need to "upgrade" one that is order-only. */ 265 266 struct dep* hd = (struct dep*) *slot; 267 268 if (d->ignore_mtime != hd->ignore_mtime) 269 d->ignore_mtime = hd->ignore_mtime = 0; 270 } 271 } 272 273 for (d = file->deps; d != 0; d = d->next) 274 { 275 const char *c; 276 277 if (d->need_2nd_expansion || hash_find_item (&dep_hash, d) != d) 278 continue; 279 280 c = dep_name (d); 223 281 #ifndef NO_ARCHIVES 224 282 if (ar_name (c)) 225 283 { 226 284 c = strchr (c, '(') + 1; … … 233 291 if (d->ignore_mtime) 234 292 { 235 293 memcpy (bp, c, len); 236 294 bp += len; 237 295 *bp++ = FILE_LIST_SEPARATOR; 238 296 } 239 297 else 240 298 { 241 299 memcpy (cp, c, len); 242 300 cp += len; 243 301 *cp++ = FILE_LIST_SEPARATOR; 244 if (d->changed )302 if (d->changed || always_make_flag) 245 303 { 246 304 memcpy (qp, c, len); … … 251 309 } 252 310 311 hash_free (&dep_hash, 0); 312 253 313 /* Kill the last spaces and define the variables. */ 254 314 … … 273 333 chop_commands (struct commands *cmds) 274 334 { 275 const char *p;276 335 unsigned int nlines, idx; 277 336 char **lines; … … 283 342 return; 284 343 285 /* Chop CMDS->commands up into lines in CMDS->command_lines. 286 Also set the corresponding CMDS->lines_flags elements, 287 and the CMDS->any_recurse flag. */ 288 289 nlines = 5; 290 lines = xmalloc (5 * sizeof (char *)); 291 idx = 0; 292 p = cmds->commands; 293 while (*p != '\0') 294 { 295 const char *end = p; 296 find_end:; 297 end = strchr (end, '\n'); 298 if (end == 0) 299 end = p + strlen (p); 300 else if (end > p && end[-1] == '\\') 344 /* Chop CMDS->commands up into lines in CMDS->command_lines. */ 345 346 if (one_shell) 347 { 348 int l = strlen (cmds->commands); 349 350 nlines = 1; 351 lines = xmalloc (nlines * sizeof (char *)); 352 lines[0] = xstrdup (cmds->commands); 353 354 /* Strip the trailing newline. */ 355 if (l > 0 && lines[0][l-1] == '\n') 356 lines[0][l-1] = '\0'; 357 } 358 else 359 { 360 const char *p; 361 362 nlines = 5; 363 lines = xmalloc (nlines * sizeof (char *)); 364 idx = 0; 365 p = cmds->commands; 366 while (*p != '\0') 301 367 { 302 int backslash = 1; 303 const char *b; 304 for (b = end - 2; b >= p && *b == '\\'; --b) 305 backslash = !backslash; 306 if (backslash) 368 const char *end = p; 369 find_end:; 370 end = strchr (end, '\n'); 371 if (end == 0) 372 end = p + strlen (p); 373 else if (end > p && end[-1] == '\\') 307 374 { 308 ++end; 309 goto find_end; 375 int backslash = 1; 376 const char *b; 377 for (b = end - 2; b >= p && *b == '\\'; --b) 378 backslash = !backslash; 379 if (backslash) 380 { 381 ++end; 382 goto find_end; 383 } 310 384 } 385 386 if (idx == nlines) 387 { 388 nlines += 2; 389 lines = xrealloc (lines, nlines * sizeof (char *)); 390 } 391 lines[idx++] = xstrndup (p, end - p); 392 p = end; 393 if (*p != '\0') 394 ++p; 311 395 } 312 396 313 if (idx == nlines)397 if (idx != nlines) 314 398 { 315 nlines += 2;399 nlines = idx; 316 400 lines = xrealloc (lines, nlines * sizeof (char *)); 317 401 } 318 lines[idx++] = savestring (p, end - p); 319 p = end; 320 if (*p != '\0') 321 ++p; 322 } 323 324 if (idx != nlines) 325 { 326 nlines = idx; 327 lines = xrealloc (lines, nlines * sizeof (char *)); 328 } 402 } 403 404 /* Finally, set the corresponding CMDS->lines_flags elements and the 405 CMDS->any_recurse flag. */ 329 406 330 407 cmds->ncommand_lines = nlines; … … 333 410 cmds->any_recurse = 0; 334 411 cmds->lines_flags = xmalloc (nlines); 412 335 413 for (idx = 0; idx < nlines; ++idx) 336 414 { 337 415 int flags = 0; 338 339 for (p = lines[idx]; 340 isblank ((unsigned char)*p) || *p == '-' || *p == '@' || *p == '+'; 341 ++p) 342 switch (*p) 416 const char *p = lines[idx]; 417 418 while (isblank (*p) || *p == '-' || *p == '@' || *p == '+') 419 switch (*(p++)) 343 420 { 344 421 case '+':
Note:
See TracChangeset
for help on using the changeset viewer.