VirtualBox

source: kBuild/trunk/src/kmk/commands.c@ 2657

Last change on this file since 2657 was 2594, checked in by bird, 13 years ago

Fixed the broken $(deps*).

  • Property svn:eol-style set to native
File size: 24.1 KB
Line 
1/* Command processing for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
42010 Free Software Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 3 of the License, or (at your option) any later
10version.
11
12GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along with
17this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "make.h"
20#include "dep.h"
21#include "filedef.h"
22#include "variable.h"
23#include "job.h"
24#include "commands.h"
25#ifdef WINDOWS32
26#include <windows.h>
27#include "w32err.h"
28#endif
29#ifdef CONFIG_WITH_LAZY_DEPS_VARS
30# include <assert.h>
31#endif
32
33#if VMS
34# define FILE_LIST_SEPARATOR ','
35#else
36# define FILE_LIST_SEPARATOR ' '
37#endif
38
39int remote_kill (int id, int sig);
40
41#ifndef HAVE_UNISTD_H
42int getpid ();
43#endif
44
45
46#ifndef CONFIG_WITH_STRCACHE2
47
48static unsigned long
49dep_hash_1 (const void *key)
50{
51 const struct dep *d = key;
52 return_STRING_HASH_1 (dep_name (d));
53}
54
55static unsigned long
56dep_hash_2 (const void *key)
57{
58 const struct dep *d = key;
59 return_STRING_HASH_2 (dep_name (d));
60}
61
62static int
63dep_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
78static unsigned long
79dep_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
86static unsigned long
87dep_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
93static int
94dep_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
119#ifdef CONFIG_WITH_LAZY_DEPS_VARS
120/* Create as copy of DEPS without duplicates, similar to what
121 set_file_variables does. Used by func_deps. */
122
123struct dep *create_uniqute_deps_chain (struct dep *deps)
124{
125 struct dep *d;
126 struct dep *head = NULL;
127 struct dep **ppnext= &head;
128 struct hash_table dep_hash;
129 void **slot;
130
131 hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
132
133 for (d = deps; d != 0; d = d->next)
134 {
135 if (d->need_2nd_expansion)
136 continue;
137
138 slot = hash_find_slot (&dep_hash, d);
139 if (HASH_VACANT (*slot))
140 {
141 struct dep *n = alloc_dep();
142 *n = *d;
143 n->next = NULL;
144 *ppnext = n;
145 ppnext = &n->next;
146 hash_insert_at (&dep_hash, n, slot);
147 }
148 else
149 {
150 /* Upgrade order only if a normal dep exists.
151 Note! Elected not to upgrade the original, only the sanitized
152 list, need to check that out later. FIXME TODO */
153 struct dep *d2 = (struct dep *)*slot;
154 if (d->ignore_mtime != d2->ignore_mtime)
155 d->ignore_mtime = d2->ignore_mtime = 0;
156 }
157 }
158
159 return head;
160}
161#endif /* CONFIG_WITH_LAZY_DEPS_VARS */
162
163/* Set FILE's automatic variables up. */
164
165void
166#if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
167set_file_variables (struct file *file, int called_early)
168#else
169set_file_variables (struct file *file)
170#endif
171{
172 struct dep *d;
173 const char *at, *percent, *star, *less;
174#ifdef CONFIG_WITH_STRCACHE2
175 const char *org_stem = file->stem;
176#endif
177
178#ifndef NO_ARCHIVES
179 /* If the target is an archive member `lib(member)',
180 then $@ is `lib' and $% is `member'. */
181
182 if (ar_name (file->name))
183 {
184 unsigned int len;
185 const char *cp;
186 char *p;
187
188 cp = strchr (file->name, '(');
189 p = alloca (cp - file->name + 1);
190 memcpy (p, file->name, cp - file->name);
191 p[cp - file->name] = '\0';
192 at = p;
193 len = strlen (cp + 1);
194 p = alloca (len);
195 memcpy (p, cp + 1, len - 1);
196 p[len - 1] = '\0';
197 percent = p;
198 }
199 else
200#endif /* NO_ARCHIVES. */
201 {
202 at = file->name;
203 percent = "";
204 }
205
206 /* $* is the stem from an implicit or static pattern rule. */
207 if (file->stem == 0)
208 {
209 /* In Unix make, $* is set to the target name with
210 any suffix in the .SUFFIXES list stripped off for
211 explicit rules. We store this in the `stem' member. */
212 const char *name;
213 unsigned int len;
214
215#ifndef NO_ARCHIVES
216 if (ar_name (file->name))
217 {
218 name = strchr (file->name, '(') + 1;
219 len = strlen (name) - 1;
220 }
221 else
222#endif
223 {
224 name = file->name;
225#ifndef CONFIG_WITH_STRCACHE2
226 len = strlen (name);
227#else
228 len = strcache2_get_len (&file_strcache, name);
229#endif
230 }
231
232#ifndef CONFIG_WITH_STRCACHE2
233 for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
234 {
235 unsigned int slen = strlen (dep_name (d));
236#else
237 for (d = enter_file (suffixes_strcached)->deps; d ; d = d->next)
238 {
239 unsigned int slen = strcache2_get_len (&file_strcache, dep_name (d));
240#endif
241 if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
242 {
243 file->stem = strcache_add_len (name, len - slen);
244 break;
245 }
246 }
247 if (d == 0)
248 file->stem = "";
249 }
250 star = file->stem;
251
252 /* $< is the first not order-only dependency. */
253 less = "";
254 for (d = file->deps; d != 0; d = d->next)
255 if (!d->ignore_mtime)
256 {
257 if (!d->need_2nd_expansion)
258 less = dep_name (d);
259 break;
260 }
261
262 if (file->cmds == default_file->cmds)
263 /* This file got its commands from .DEFAULT.
264 In this case $< is the same as $@. */
265 less = at;
266
267#define DEFINE_VARIABLE(name, len, value) \
268 (void) define_variable_for_file (name,len,value,o_automatic,0,file)
269
270 /* Define the variables. */
271
272#ifndef CONFIG_WITH_RDONLY_VARIABLE_VALUE
273 DEFINE_VARIABLE ("<", 1, less);
274 DEFINE_VARIABLE ("*", 1, star);
275 DEFINE_VARIABLE ("@", 1, at);
276 DEFINE_VARIABLE ("%", 1, percent);
277#else /* CONFIG_WITH_RDONLY_VARIABLE_VALUE */
278# define DEFINE_VARIABLE_RO_VAL(name, len, value, value_len) \
279 define_variable_in_set((name), (len), (value), (value_len), -1, \
280 (o_automatic), 0, (file)->variables->set, NILF)
281
282 if (*less == '\0')
283 DEFINE_VARIABLE_RO_VAL ("<", 1, "", 0);
284 else if (less != at || at == file->name)
285 DEFINE_VARIABLE_RO_VAL ("<", 1, less, strcache_get_len (less));
286 else
287 DEFINE_VARIABLE ("<", 1, less);
288
289 if (*star == '\0')
290 DEFINE_VARIABLE_RO_VAL ("*", 1, "", 0);
291 else if (file->stem != org_stem)
292 DEFINE_VARIABLE_RO_VAL ("*", 1, star, strcache_get_len (star));
293 else
294 DEFINE_VARIABLE ("*", 1, star);
295
296 if (at == file->name)
297 DEFINE_VARIABLE_RO_VAL ("@", 1, at, strcache_get_len (at));
298 else
299 DEFINE_VARIABLE ("@", 1, at);
300
301 if (*percent == '\0')
302 DEFINE_VARIABLE_RO_VAL ("%", 1, "", 0);
303 else
304 DEFINE_VARIABLE ("%", 1, percent);
305#endif /* CONFIG_WITH_RDONLY_VARIABLE_VALUE */
306
307#if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
308 /* The $^, $+, $? and $| variables should not be set if we're called
309 early by a .MUST_MAKE invocation or $(commands ). */
310 if (called_early)
311 return;
312#endif
313
314 /* Compute the values for $^, $+, $?, and $|. */
315#ifdef CONFIG_WITH_LAZY_DEPS_VARS
316 /* Lazy doesn't work for double colon rules with multiple files with
317 commands, nor for files that has been thru rehash_file() (vpath). */
318 if ( ( file->double_colon
319 && ( file->double_colon != file
320 || file->last != file))
321 || file->name != file->hname) /* XXX: Rehashed files should be fixable! */
322#endif
323 {
324 static char *plus_value=0, *bar_value=0, *qmark_value=0;
325 static unsigned int plus_max=0, bar_max=0, qmark_max=0;
326
327 unsigned int qmark_len, plus_len, bar_len;
328 char *cp;
329 char *caret_value;
330 char *qp;
331 char *bp;
332 unsigned int len;
333
334 struct hash_table dep_hash;
335 void **slot;
336
337 /* Compute first the value for $+, which is supposed to contain
338 duplicate dependencies as they were listed in the makefile. */
339
340 plus_len = 0;
341 bar_len = 0;
342 for (d = file->deps; d != 0; d = d->next)
343 if (! d->ignore_mtime)
344 {
345 if (!d->need_2nd_expansion)
346 {
347#ifndef CONFIG_WITH_STRCACHE2
348 if (d->ignore_mtime)
349 bar_len += strlen (dep_name (d)) + 1;
350 else
351 plus_len += strlen (dep_name (d)) + 1;
352#else
353 if (d->ignore_mtime)
354 bar_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;
355 else
356 plus_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;
357#endif
358 }
359 }
360
361 if (bar_len == 0)
362 bar_len++;
363 if (plus_len == 0)
364 plus_len++;
365
366 if (plus_len > plus_max)
367 plus_value = xrealloc (plus_value, plus_max = plus_len);
368
369 cp = plus_value;
370
371 qmark_len = plus_len + 1; /* Will be this or less. */
372 for (d = file->deps; d != 0; d = d->next)
373 if (! d->ignore_mtime && ! d->need_2nd_expansion)
374 {
375 const char *c = dep_name (d);
376
377#ifndef NO_ARCHIVES
378 if (ar_name (c))
379 {
380 c = strchr (c, '(') + 1;
381 len = strlen (c) - 1;
382 }
383 else
384#endif
385#ifndef CONFIG_WITH_STRCACHE2
386 len = strlen (c);
387#else
388 len = strcache2_get_len (&file_strcache, c);
389#endif
390
391 memcpy (cp, c, len);
392 cp += len;
393 *cp++ = FILE_LIST_SEPARATOR;
394 if (! (d->changed || always_make_flag))
395 qmark_len -= len + 1; /* Don't space in $? for this one. */
396 }
397
398 /* Kill the last space and define the variable. */
399
400 cp[cp > plus_value ? -1 : 0] = '\0';
401 DEFINE_VARIABLE ("+", 1, plus_value);
402
403 /* Compute the values for $^, $?, and $|. */
404
405 cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */
406
407 if (qmark_len > qmark_max)
408 qmark_value = xrealloc (qmark_value, qmark_max = qmark_len);
409 qp = qmark_value;
410
411 if (bar_len > bar_max)
412 bar_value = xrealloc (bar_value, bar_max = bar_len);
413 bp = bar_value;
414
415 /* Make sure that no dependencies are repeated in $^, $?, and $|. It
416 would be natural to combine the next two loops but we can't do it
417 because of a situation where we have two dep entries, the first
418 is order-only and the second is normal (see below). */
419
420 hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
421
422 for (d = file->deps; d != 0; d = d->next)
423 {
424 if (d->need_2nd_expansion)
425 continue;
426
427 slot = hash_find_slot (&dep_hash, d);
428 if (HASH_VACANT (*slot))
429 hash_insert_at (&dep_hash, d, slot);
430 else
431 {
432 /* Check if the two prerequisites have different ignore_mtime.
433 If so then we need to "upgrade" one that is order-only. */
434
435 struct dep* hd = (struct dep*) *slot;
436
437 if (d->ignore_mtime != hd->ignore_mtime)
438 d->ignore_mtime = hd->ignore_mtime = 0;
439 }
440 }
441
442 for (d = file->deps; d != 0; d = d->next)
443 {
444 const char *c;
445
446 if (d->need_2nd_expansion || hash_find_item (&dep_hash, d) != d)
447 continue;
448
449 c = dep_name (d);
450#ifndef NO_ARCHIVES
451 if (ar_name (c))
452 {
453 c = strchr (c, '(') + 1;
454 len = strlen (c) - 1;
455 }
456 else
457#endif
458#ifndef CONFIG_WITH_STRCACHE2
459 len = strlen (c);
460#else
461 len = strcache2_get_len (&file_strcache, c);
462#endif
463
464 if (d->ignore_mtime)
465 {
466 memcpy (bp, c, len);
467 bp += len;
468 *bp++ = FILE_LIST_SEPARATOR;
469 }
470 else
471 {
472 memcpy (cp, c, len);
473 cp += len;
474 *cp++ = FILE_LIST_SEPARATOR;
475 if (d->changed || always_make_flag)
476 {
477 memcpy (qp, c, len);
478 qp += len;
479 *qp++ = FILE_LIST_SEPARATOR;
480 }
481 }
482 }
483
484 hash_free (&dep_hash, 0);
485
486 /* Kill the last spaces and define the variables. */
487
488 cp[cp > caret_value ? -1 : 0] = '\0';
489 DEFINE_VARIABLE ("^", 1, caret_value);
490
491 qp[qp > qmark_value ? -1 : 0] = '\0';
492 DEFINE_VARIABLE ("?", 1, qmark_value);
493
494 bp[bp > bar_value ? -1 : 0] = '\0';
495 DEFINE_VARIABLE ("|", 1, bar_value);
496 }
497#undef DEFINE_VARIABLE
498}
499
500
501/* Chop CMDS up into individual command lines if necessary.
502 Also set the `lines_flags' and `any_recurse' members. */
503
504void
505chop_commands (struct commands *cmds)
506{
507 unsigned int nlines, idx;
508 char **lines;
509
510 /* If we don't have any commands,
511 or we already parsed them, never mind. */
512
513 if (!cmds || cmds->command_lines != 0)
514 return;
515
516 /* Chop CMDS->commands up into lines in CMDS->command_lines. */
517
518 if (one_shell)
519 {
520 int l = strlen (cmds->commands);
521
522 nlines = 1;
523 lines = xmalloc (nlines * sizeof (char *));
524 lines[0] = xstrdup (cmds->commands);
525
526 /* Strip the trailing newline. */
527 if (l > 0 && lines[0][l-1] == '\n')
528 lines[0][l-1] = '\0';
529 }
530 else
531 {
532 const char *p;
533
534 nlines = 5;
535 lines = xmalloc (nlines * sizeof (char *));
536 idx = 0;
537 p = cmds->commands;
538 while (*p != '\0')
539 {
540 const char *end = p;
541 find_end:;
542 end = strchr (end, '\n');
543 if (end == 0)
544 end = p + strlen (p);
545 else if (end > p && end[-1] == '\\')
546 {
547 int backslash = 1;
548 const char *b;
549 for (b = end - 2; b >= p && *b == '\\'; --b)
550 backslash = !backslash;
551 if (backslash)
552 {
553 ++end;
554 goto find_end;
555 }
556 }
557
558 if (idx == nlines)
559 {
560 nlines += 2;
561 lines = xrealloc (lines, nlines * sizeof (char *));
562 }
563 lines[idx++] = xstrndup (p, end - p);
564 p = end;
565 if (*p != '\0')
566 ++p;
567 }
568
569 if (idx != nlines)
570 {
571 nlines = idx;
572 lines = xrealloc (lines, nlines * sizeof (char *));
573 }
574 }
575
576 /* Finally, set the corresponding CMDS->lines_flags elements and the
577 CMDS->any_recurse flag. */
578
579 cmds->ncommand_lines = nlines;
580 cmds->command_lines = lines;
581
582 cmds->any_recurse = 0;
583#ifndef CONFIG_WITH_COMMANDS_FUNC
584 cmds->lines_flags = xmalloc (nlines);
585#else
586 cmds->lines_flags = xmalloc (nlines * sizeof (cmds->lines_flags[0]));
587#endif
588
589 for (idx = 0; idx < nlines; ++idx)
590 {
591 int flags = 0;
592 const char *p = lines[idx];
593
594 while (isblank (*p) || *p == '-' || *p == '@' || *p == '+' IF_WITH_COMMANDS_FUNC(|| *p == '%'))
595 switch (*(p++))
596 {
597 case '+':
598 flags |= COMMANDS_RECURSE;
599 break;
600 case '@':
601 flags |= COMMANDS_SILENT;
602 break;
603 case '-':
604 flags |= COMMANDS_NOERROR;
605 break;
606#ifdef CONFIG_WITH_COMMANDS_FUNC
607 case '%':
608 flags |= COMMAND_GETTER_SKIP_IT;
609 break;
610#endif
611 }
612
613 /* If no explicit '+' was given, look for MAKE variable references. */
614 if (!(flags & COMMANDS_RECURSE)
615#ifndef KMK
616 && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
617#else
618 && (strstr (p, "$(KMK)") != 0 || strstr (p, "${KMK}") != 0 ||
619 strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
620#endif
621 flags |= COMMANDS_RECURSE;
622
623#ifdef CONFIG_WITH_KMK_BUILTIN
624 /* check if kmk builtin command */
625 if (!strncmp(p, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
626 flags |= COMMANDS_KMK_BUILTIN;
627#endif
628
629 cmds->lines_flags[idx] = flags;
630 cmds->any_recurse |= flags & COMMANDS_RECURSE;
631 }
632}
633
634
635/* Execute the commands to remake FILE. If they are currently executing,
636 return or have already finished executing, just return. Otherwise,
637 fork off a child process to run the first command line in the sequence. */
638
639void
640execute_file_commands (struct file *file)
641{
642 const char *p;
643
644 /* Don't go through all the preparations if
645 the commands are nothing but whitespace. */
646
647 for (p = file->cmds->commands; *p != '\0'; ++p)
648 if (!isspace ((unsigned char)*p) && *p != '-' && *p != '@')
649 break;
650 if (*p == '\0')
651 {
652 /* If there are no commands, assume everything worked. */
653#ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
654 file->command_flags |= COMMANDS_NO_COMMANDS;
655#endif
656 set_command_state (file, cs_running);
657 file->update_status = 0;
658 notice_finished_file (file);
659 return;
660 }
661
662 /* First set the automatic variables according to this file. */
663
664 initialize_file_variables (file, 0);
665
666#if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
667 set_file_variables (file, 0 /* final call */);
668#else
669 set_file_variables (file);
670#endif
671
672 /* Start the commands running. */
673 new_job (file);
674}
675
676
677/* This is set while we are inside fatal_error_signal,
678 so things can avoid nonreentrant operations. */
679
680int handling_fatal_signal = 0;
681
682/* Handle fatal signals. */
683
684RETSIGTYPE
685fatal_error_signal (int sig)
686{
687#ifdef __MSDOS__
688 extern int dos_status, dos_command_running;
689
690 if (dos_command_running)
691 {
692 /* That was the child who got the signal, not us. */
693 dos_status |= (sig << 8);
694 return;
695 }
696 remove_intermediates (1);
697 exit (EXIT_FAILURE);
698#else /* not __MSDOS__ */
699#ifdef _AMIGA
700 remove_intermediates (1);
701 if (sig == SIGINT)
702 fputs (_("*** Break.\n"), stderr);
703
704 exit (10);
705#else /* not Amiga */
706#if defined (WINDOWS32) && !defined (CONFIG_NEW_WIN32_CTRL_EVENT)
707 extern HANDLE main_thread;
708
709 /* Windows creates a sperate thread for handling Ctrl+C, so we need
710 to suspend the main thread, or else we will have race conditions
711 when both threads call reap_children. */
712 if (main_thread)
713 {
714 DWORD susp_count = SuspendThread (main_thread);
715
716 if (susp_count != 0)
717 fprintf (stderr, "SuspendThread: suspend count = %ld\n", susp_count);
718 else if (susp_count == (DWORD)-1)
719 {
720 DWORD ierr = GetLastError ();
721
722 fprintf (stderr, "SuspendThread: error %ld: %s\n",
723 ierr, map_windows32_error_to_string (ierr));
724 }
725 }
726#endif
727 handling_fatal_signal = 1;
728
729 /* Set the handling for this signal to the default.
730 It is blocked now while we run this handler. */
731 signal (sig, SIG_DFL);
732
733 /* A termination signal won't be sent to the entire
734 process group, but it means we want to kill the children. */
735
736 if (sig == SIGTERM)
737 {
738 struct child *c;
739 for (c = children; c != 0; c = c->next)
740 if (!c->remote)
741 (void) kill (c->pid, SIGTERM);
742 }
743
744 /* If we got a signal that means the user
745 wanted to kill make, remove pending targets. */
746
747 if (sig == SIGTERM || sig == SIGINT
748#ifdef SIGHUP
749 || sig == SIGHUP
750#endif
751#ifdef SIGQUIT
752 || sig == SIGQUIT
753#endif
754 )
755 {
756 struct child *c;
757
758 /* Remote children won't automatically get signals sent
759 to the process group, so we must send them. */
760 for (c = children; c != 0; c = c->next)
761 if (c->remote)
762 (void) remote_kill (c->pid, sig);
763
764 for (c = children; c != 0; c = c->next)
765 delete_child_targets (c);
766
767 /* Clean up the children. We don't just use the call below because
768 we don't want to print the "Waiting for children" message. */
769 while (job_slots_used > 0)
770 reap_children (1, 0);
771 }
772 else
773 /* Wait for our children to die. */
774 while (job_slots_used > 0)
775 reap_children (1, 1);
776
777 /* Delete any non-precious intermediate files that were made. */
778
779 remove_intermediates (1);
780#ifdef SIGQUIT
781 if (sig == SIGQUIT)
782 /* We don't want to send ourselves SIGQUIT, because it will
783 cause a core dump. Just exit instead. */
784 exit (EXIT_FAILURE);
785#endif
786
787#ifdef WINDOWS32
788# ifndef CONFIG_NEW_WIN32_CTRL_EVENT
789 if (main_thread)
790 CloseHandle (main_thread);
791# endif /* !CONFIG_NEW_WIN32_CTRL_EVENT */
792 /* Cannot call W32_kill with a pid (it needs a handle). The exit
793 status of 130 emulates what happens in Bash. */
794 exit (130);
795#else
796 /* Signal the same code; this time it will really be fatal. The signal
797 will be unblocked when we return and arrive then to kill us. */
798 if (kill (getpid (), sig) < 0)
799 pfatal_with_name ("kill");
800#endif /* not WINDOWS32 */
801#endif /* not Amiga */
802#endif /* not __MSDOS__ */
803}
804
805
806/* Delete FILE unless it's precious or not actually a file (phony),
807 and it has changed on disk since we last stat'd it. */
808
809static void
810delete_target (struct file *file, const char *on_behalf_of)
811{
812 struct stat st;
813 int e;
814
815 if (file->precious || file->phony)
816 return;
817#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
818 assert (!file->multi_maybe);
819#endif
820
821#ifndef NO_ARCHIVES
822 if (ar_name (file->name))
823 {
824 time_t file_date = (file->last_mtime == NONEXISTENT_MTIME
825 ? (time_t) -1
826 : (time_t) FILE_TIMESTAMP_S (file->last_mtime));
827 if (ar_member_date (file->name) != file_date)
828 {
829 if (on_behalf_of)
830 error (NILF, _("*** [%s] Archive member `%s' may be bogus; not deleted"),
831 on_behalf_of, file->name);
832 else
833 error (NILF, _("*** Archive member `%s' may be bogus; not deleted"),
834 file->name);
835 }
836 return;
837 }
838#endif
839
840 EINTRLOOP (e, stat (file->name, &st));
841 if (e == 0
842 && S_ISREG (st.st_mode)
843 && FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime)
844 {
845 if (on_behalf_of)
846 error (NILF, _("*** [%s] Deleting file `%s'"), on_behalf_of, file->name);
847 else
848 error (NILF, _("*** Deleting file `%s'"), file->name);
849 if (unlink (file->name) < 0
850 && errno != ENOENT) /* It disappeared; so what. */
851 perror_with_name ("unlink: ", file->name);
852 }
853}
854
855
856/* Delete all non-precious targets of CHILD unless they were already deleted.
857 Set the flag in CHILD to say they've been deleted. */
858
859void
860delete_child_targets (struct child *child)
861{
862 struct dep *d;
863
864 if (child->deleted)
865 return;
866
867 /* Delete the target file if it changed. */
868 delete_target (child->file, NULL);
869
870 /* Also remove any non-precious targets listed in the `also_make' member. */
871 for (d = child->file->also_make; d != 0; d = d->next)
872 delete_target (d->file, child->file->name);
873
874#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
875 /* Also remove any multi target siblings, except for the 'maybe' ones (we
876 handle that here) and precious ones (delete_target deals with that).
877 Note that CHILD is always the multi target head (see remake.c). */
878 if (child->file == child->file->multi_head)
879 {
880 struct file *f2;
881 for (f2 = child->file->multi_next; f2; f2 = f2->multi_next)
882 if (!f2->multi_maybe)
883 delete_target (f2, child->file->name);
884 }
885#endif
886
887 child->deleted = 1;
888}
889
890
891/* Print out the commands in CMDS. */
892
893void
894print_commands (const struct commands *cmds)
895{
896 const char *s;
897
898 fputs (_("# recipe to execute"), stdout);
899
900 if (cmds->fileinfo.filenm == 0)
901 puts (_(" (built-in):"));
902 else
903 printf (_(" (from `%s', line %lu):\n"),
904 cmds->fileinfo.filenm, cmds->fileinfo.lineno);
905
906 s = cmds->commands;
907 while (*s != '\0')
908 {
909 const char *end;
910
911 end = strchr (s, '\n');
912 if (end == 0)
913 end = s + strlen (s);
914
915 printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s);
916
917 s = end + (end[0] == '\n');
918 }
919}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette