VirtualBox

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

Last change on this file since 2592 was 2591, checked in by bird, 13 years ago

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

  • Property svn:eol-style set to native
File size: 23.4 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/* Set FILE's automatic variables up. */
120
121void
122#if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
123set_file_variables (struct file *file, int called_early)
124#else
125set_file_variables (struct file *file)
126#endif
127{
128 struct dep *d;
129 const char *at, *percent, *star, *less;
130#ifdef CONFIG_WITH_STRCACHE2
131 const char *org_stem = file->stem;
132#endif
133
134#ifndef NO_ARCHIVES
135 /* If the target is an archive member `lib(member)',
136 then $@ is `lib' and $% is `member'. */
137
138 if (ar_name (file->name))
139 {
140 unsigned int len;
141 const char *cp;
142 char *p;
143
144 cp = strchr (file->name, '(');
145 p = alloca (cp - file->name + 1);
146 memcpy (p, file->name, cp - file->name);
147 p[cp - file->name] = '\0';
148 at = p;
149 len = strlen (cp + 1);
150 p = alloca (len);
151 memcpy (p, cp + 1, len - 1);
152 p[len - 1] = '\0';
153 percent = p;
154 }
155 else
156#endif /* NO_ARCHIVES. */
157 {
158 at = file->name;
159 percent = "";
160 }
161
162 /* $* is the stem from an implicit or static pattern rule. */
163 if (file->stem == 0)
164 {
165 /* In Unix make, $* is set to the target name with
166 any suffix in the .SUFFIXES list stripped off for
167 explicit rules. We store this in the `stem' member. */
168 const char *name;
169 unsigned int len;
170
171#ifndef NO_ARCHIVES
172 if (ar_name (file->name))
173 {
174 name = strchr (file->name, '(') + 1;
175 len = strlen (name) - 1;
176 }
177 else
178#endif
179 {
180 name = file->name;
181#ifndef CONFIG_WITH_STRCACHE2
182 len = strlen (name);
183#else
184 len = strcache2_get_len (&file_strcache, name);
185#endif
186 }
187
188#ifndef CONFIG_WITH_STRCACHE2
189 for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
190 {
191 unsigned int slen = strlen (dep_name (d));
192#else
193 for (d = enter_file (suffixes_strcached)->deps; d ; d = d->next)
194 {
195 unsigned int slen = strcache2_get_len (&file_strcache, dep_name (d));
196#endif
197 if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
198 {
199 file->stem = strcache_add_len (name, len - slen);
200 break;
201 }
202 }
203 if (d == 0)
204 file->stem = "";
205 }
206 star = file->stem;
207
208 /* $< is the first not order-only dependency. */
209 less = "";
210 for (d = file->deps; d != 0; d = d->next)
211 if (!d->ignore_mtime)
212 {
213 if (!d->need_2nd_expansion)
214 less = dep_name (d);
215 break;
216 }
217
218 if (file->cmds == default_file->cmds)
219 /* This file got its commands from .DEFAULT.
220 In this case $< is the same as $@. */
221 less = at;
222
223#define DEFINE_VARIABLE(name, len, value) \
224 (void) define_variable_for_file (name,len,value,o_automatic,0,file)
225
226 /* Define the variables. */
227
228#ifndef CONFIG_WITH_RDONLY_VARIABLE_VALUE
229 DEFINE_VARIABLE ("<", 1, less);
230 DEFINE_VARIABLE ("*", 1, star);
231 DEFINE_VARIABLE ("@", 1, at);
232 DEFINE_VARIABLE ("%", 1, percent);
233#else /* CONFIG_WITH_RDONLY_VARIABLE_VALUE */
234# define DEFINE_VARIABLE_RO_VAL(name, len, value, value_len) \
235 define_variable_in_set((name), (len), (value), (value_len), -1, \
236 (o_automatic), 0, (file)->variables->set, NILF)
237
238 if (*less == '\0')
239 DEFINE_VARIABLE_RO_VAL ("<", 1, "", 0);
240 else if (less != at || at == file->name)
241 DEFINE_VARIABLE_RO_VAL ("<", 1, less, strcache_get_len (less));
242 else
243 DEFINE_VARIABLE ("<", 1, less);
244
245 if (*star == '\0')
246 DEFINE_VARIABLE_RO_VAL ("*", 1, "", 0);
247 else if (file->stem != org_stem)
248 DEFINE_VARIABLE_RO_VAL ("*", 1, star, strcache_get_len (star));
249 else
250 DEFINE_VARIABLE ("*", 1, star);
251
252 if (at == file->name)
253 DEFINE_VARIABLE_RO_VAL ("@", 1, at, strcache_get_len (at));
254 else
255 DEFINE_VARIABLE ("@", 1, at);
256
257 if (*percent == '\0')
258 DEFINE_VARIABLE_RO_VAL ("%", 1, "", 0);
259 else
260 DEFINE_VARIABLE ("%", 1, percent);
261#endif /* CONFIG_WITH_RDONLY_VARIABLE_VALUE */
262
263#if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
264 /* The $^, $+, $? and $| variables should not be set if we're called
265 early by a .MUST_MAKE invocation or $(commands ). */
266 if (called_early)
267 return;
268#endif
269
270 /* Compute the values for $^, $+, $?, and $|. */
271#ifdef CONFIG_WITH_LAZY_DEPS_VARS
272 /* Lazy doesn't work for double colon rules with multiple files with
273 commands, nor for files that has been thru rehash_file() (vpath). */
274 if ( ( file->double_colon
275 && ( file->double_colon != file
276 || file->last != file))
277 || file->name != file->hname) /* XXX: Rehashed files should be fixable! */
278#endif
279 {
280 static char *plus_value=0, *bar_value=0, *qmark_value=0;
281 static unsigned int plus_max=0, bar_max=0, qmark_max=0;
282
283 unsigned int qmark_len, plus_len, bar_len;
284 char *cp;
285 char *caret_value;
286 char *qp;
287 char *bp;
288 unsigned int len;
289
290 struct hash_table dep_hash;
291 void **slot;
292
293 /* Compute first the value for $+, which is supposed to contain
294 duplicate dependencies as they were listed in the makefile. */
295
296 plus_len = 0;
297 bar_len = 0;
298 for (d = file->deps; d != 0; d = d->next)
299 if (! d->ignore_mtime)
300 {
301 if (!d->need_2nd_expansion)
302 {
303#ifndef CONFIG_WITH_STRCACHE2
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++;
319 if (plus_len == 0)
320 plus_len++;
321
322 if (plus_len > plus_max)
323 plus_value = xrealloc (plus_value, plus_max = plus_len);
324
325 cp = plus_value;
326
327 qmark_len = plus_len + 1; /* Will be this or less. */
328 for (d = file->deps; d != 0; d = d->next)
329 if (! d->ignore_mtime && ! d->need_2nd_expansion)
330 {
331 const char *c = dep_name (d);
332
333#ifndef NO_ARCHIVES
334 if (ar_name (c))
335 {
336 c = strchr (c, '(') + 1;
337 len = strlen (c) - 1;
338 }
339 else
340#endif
341#ifndef CONFIG_WITH_STRCACHE2
342 len = strlen (c);
343#else
344 len = strcache2_get_len (&file_strcache, c);
345#endif
346
347 memcpy (cp, c, len);
348 cp += len;
349 *cp++ = FILE_LIST_SEPARATOR;
350 if (! (d->changed || always_make_flag))
351 qmark_len -= len + 1; /* Don't space in $? for this one. */
352 }
353
354 /* Kill the last space and define the variable. */
355
356 cp[cp > plus_value ? -1 : 0] = '\0';
357 DEFINE_VARIABLE ("+", 1, plus_value);
358
359 /* Compute the values for $^, $?, and $|. */
360
361 cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */
362
363 if (qmark_len > qmark_max)
364 qmark_value = xrealloc (qmark_value, qmark_max = qmark_len);
365 qp = qmark_value;
366
367 if (bar_len > bar_max)
368 bar_value = xrealloc (bar_value, bar_max = bar_len);
369 bp = bar_value;
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
378 for (d = file->deps; d != 0; d = d->next)
379 {
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);
406#ifndef NO_ARCHIVES
407 if (ar_name (c))
408 {
409 c = strchr (c, '(') + 1;
410 len = strlen (c) - 1;
411 }
412 else
413#endif
414#ifndef CONFIG_WITH_STRCACHE2
415 len = strlen (c);
416#else
417 len = strcache2_get_len (&file_strcache, c);
418#endif
419
420 if (d->ignore_mtime)
421 {
422 memcpy (bp, c, len);
423 bp += len;
424 *bp++ = FILE_LIST_SEPARATOR;
425 }
426 else
427 {
428 memcpy (cp, c, len);
429 cp += len;
430 *cp++ = FILE_LIST_SEPARATOR;
431 if (d->changed || always_make_flag)
432 {
433 memcpy (qp, c, len);
434 qp += len;
435 *qp++ = FILE_LIST_SEPARATOR;
436 }
437 }
438 }
439
440 hash_free (&dep_hash, 0);
441
442 /* Kill the last spaces and define the variables. */
443
444 cp[cp > caret_value ? -1 : 0] = '\0';
445 DEFINE_VARIABLE ("^", 1, caret_value);
446
447 qp[qp > qmark_value ? -1 : 0] = '\0';
448 DEFINE_VARIABLE ("?", 1, qmark_value);
449
450 bp[bp > bar_value ? -1 : 0] = '\0';
451 DEFINE_VARIABLE ("|", 1, bar_value);
452 }
453#ifdef CONFIG_WITH_LAZY_DEPS_VARS
454 else
455 {
456 /* Make a copy of the current dependency chain for later use in
457 potential $(dep-pluss $@) calls. Then drop duplicate deps. */
458
459 /* assert (file->org_deps == NULL); - FIXME? */
460 free_dep_chain (file->org_deps);
461 file->org_deps = copy_dep_chain (file->deps);
462
463 /** @todo do uniquize_deps (file->deps); in the $(dep-* ) functions, it'll
464 * save even more space that way. */
465 }
466#endif /* CONFIG_WITH_LAZY_DEPS_VARS */
467#undef DEFINE_VARIABLE
468}
469
470
471/* Chop CMDS up into individual command lines if necessary.
472 Also set the `lines_flags' and `any_recurse' members. */
473
474void
475chop_commands (struct commands *cmds)
476{
477 unsigned int nlines, idx;
478 char **lines;
479
480 /* If we don't have any commands,
481 or we already parsed them, never mind. */
482
483 if (!cmds || cmds->command_lines != 0)
484 return;
485
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')
509 {
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] == '\\')
516 {
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 }
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;
537 }
538
539 if (idx != nlines)
540 {
541 nlines = idx;
542 lines = xrealloc (lines, nlines * sizeof (char *));
543 }
544 }
545
546 /* Finally, set the corresponding CMDS->lines_flags elements and the
547 CMDS->any_recurse flag. */
548
549 cmds->ncommand_lines = nlines;
550 cmds->command_lines = lines;
551
552 cmds->any_recurse = 0;
553#ifndef CONFIG_WITH_COMMANDS_FUNC
554 cmds->lines_flags = xmalloc (nlines);
555#else
556 cmds->lines_flags = xmalloc (nlines * sizeof (cmds->lines_flags[0]));
557#endif
558
559 for (idx = 0; idx < nlines; ++idx)
560 {
561 int flags = 0;
562 const char *p = lines[idx];
563
564 while (isblank (*p) || *p == '-' || *p == '@' || *p == '+' IF_WITH_COMMANDS_FUNC(|| *p == '%'))
565 switch (*(p++))
566 {
567 case '+':
568 flags |= COMMANDS_RECURSE;
569 break;
570 case '@':
571 flags |= COMMANDS_SILENT;
572 break;
573 case '-':
574 flags |= COMMANDS_NOERROR;
575 break;
576#ifdef CONFIG_WITH_COMMANDS_FUNC
577 case '%':
578 flags |= COMMAND_GETTER_SKIP_IT;
579 break;
580#endif
581 }
582
583 /* If no explicit '+' was given, look for MAKE variable references. */
584 if (!(flags & COMMANDS_RECURSE)
585#ifndef KMK
586 && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
587#else
588 && (strstr (p, "$(KMK)") != 0 || strstr (p, "${KMK}") != 0 ||
589 strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
590#endif
591 flags |= COMMANDS_RECURSE;
592
593#ifdef CONFIG_WITH_KMK_BUILTIN
594 /* check if kmk builtin command */
595 if (!strncmp(p, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
596 flags |= COMMANDS_KMK_BUILTIN;
597#endif
598
599 cmds->lines_flags[idx] = flags;
600 cmds->any_recurse |= flags & COMMANDS_RECURSE;
601 }
602}
603
604
605/* Execute the commands to remake FILE. If they are currently executing,
606 return or have already finished executing, just return. Otherwise,
607 fork off a child process to run the first command line in the sequence. */
608
609void
610execute_file_commands (struct file *file)
611{
612 const char *p;
613
614 /* Don't go through all the preparations if
615 the commands are nothing but whitespace. */
616
617 for (p = file->cmds->commands; *p != '\0'; ++p)
618 if (!isspace ((unsigned char)*p) && *p != '-' && *p != '@')
619 break;
620 if (*p == '\0')
621 {
622 /* If there are no commands, assume everything worked. */
623#ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
624 file->command_flags |= COMMANDS_NO_COMMANDS;
625#endif
626 set_command_state (file, cs_running);
627 file->update_status = 0;
628 notice_finished_file (file);
629 return;
630 }
631
632 /* First set the automatic variables according to this file. */
633
634 initialize_file_variables (file, 0);
635
636#if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
637 set_file_variables (file, 0 /* final call */);
638#else
639 set_file_variables (file);
640#endif
641
642 /* Start the commands running. */
643 new_job (file);
644}
645
646
647/* This is set while we are inside fatal_error_signal,
648 so things can avoid nonreentrant operations. */
649
650int handling_fatal_signal = 0;
651
652/* Handle fatal signals. */
653
654RETSIGTYPE
655fatal_error_signal (int sig)
656{
657#ifdef __MSDOS__
658 extern int dos_status, dos_command_running;
659
660 if (dos_command_running)
661 {
662 /* That was the child who got the signal, not us. */
663 dos_status |= (sig << 8);
664 return;
665 }
666 remove_intermediates (1);
667 exit (EXIT_FAILURE);
668#else /* not __MSDOS__ */
669#ifdef _AMIGA
670 remove_intermediates (1);
671 if (sig == SIGINT)
672 fputs (_("*** Break.\n"), stderr);
673
674 exit (10);
675#else /* not Amiga */
676#if defined (WINDOWS32) && !defined (CONFIG_NEW_WIN32_CTRL_EVENT)
677 extern HANDLE main_thread;
678
679 /* Windows creates a sperate thread for handling Ctrl+C, so we need
680 to suspend the main thread, or else we will have race conditions
681 when both threads call reap_children. */
682 if (main_thread)
683 {
684 DWORD susp_count = SuspendThread (main_thread);
685
686 if (susp_count != 0)
687 fprintf (stderr, "SuspendThread: suspend count = %ld\n", susp_count);
688 else if (susp_count == (DWORD)-1)
689 {
690 DWORD ierr = GetLastError ();
691
692 fprintf (stderr, "SuspendThread: error %ld: %s\n",
693 ierr, map_windows32_error_to_string (ierr));
694 }
695 }
696#endif
697 handling_fatal_signal = 1;
698
699 /* Set the handling for this signal to the default.
700 It is blocked now while we run this handler. */
701 signal (sig, SIG_DFL);
702
703 /* A termination signal won't be sent to the entire
704 process group, but it means we want to kill the children. */
705
706 if (sig == SIGTERM)
707 {
708 struct child *c;
709 for (c = children; c != 0; c = c->next)
710 if (!c->remote)
711 (void) kill (c->pid, SIGTERM);
712 }
713
714 /* If we got a signal that means the user
715 wanted to kill make, remove pending targets. */
716
717 if (sig == SIGTERM || sig == SIGINT
718#ifdef SIGHUP
719 || sig == SIGHUP
720#endif
721#ifdef SIGQUIT
722 || sig == SIGQUIT
723#endif
724 )
725 {
726 struct child *c;
727
728 /* Remote children won't automatically get signals sent
729 to the process group, so we must send them. */
730 for (c = children; c != 0; c = c->next)
731 if (c->remote)
732 (void) remote_kill (c->pid, sig);
733
734 for (c = children; c != 0; c = c->next)
735 delete_child_targets (c);
736
737 /* Clean up the children. We don't just use the call below because
738 we don't want to print the "Waiting for children" message. */
739 while (job_slots_used > 0)
740 reap_children (1, 0);
741 }
742 else
743 /* Wait for our children to die. */
744 while (job_slots_used > 0)
745 reap_children (1, 1);
746
747 /* Delete any non-precious intermediate files that were made. */
748
749 remove_intermediates (1);
750#ifdef SIGQUIT
751 if (sig == SIGQUIT)
752 /* We don't want to send ourselves SIGQUIT, because it will
753 cause a core dump. Just exit instead. */
754 exit (EXIT_FAILURE);
755#endif
756
757#ifdef WINDOWS32
758# ifndef CONFIG_NEW_WIN32_CTRL_EVENT
759 if (main_thread)
760 CloseHandle (main_thread);
761# endif /* !CONFIG_NEW_WIN32_CTRL_EVENT */
762 /* Cannot call W32_kill with a pid (it needs a handle). The exit
763 status of 130 emulates what happens in Bash. */
764 exit (130);
765#else
766 /* Signal the same code; this time it will really be fatal. The signal
767 will be unblocked when we return and arrive then to kill us. */
768 if (kill (getpid (), sig) < 0)
769 pfatal_with_name ("kill");
770#endif /* not WINDOWS32 */
771#endif /* not Amiga */
772#endif /* not __MSDOS__ */
773}
774
775
776/* Delete FILE unless it's precious or not actually a file (phony),
777 and it has changed on disk since we last stat'd it. */
778
779static void
780delete_target (struct file *file, const char *on_behalf_of)
781{
782 struct stat st;
783 int e;
784
785 if (file->precious || file->phony)
786 return;
787#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
788 assert (!file->multi_maybe);
789#endif
790
791#ifndef NO_ARCHIVES
792 if (ar_name (file->name))
793 {
794 time_t file_date = (file->last_mtime == NONEXISTENT_MTIME
795 ? (time_t) -1
796 : (time_t) FILE_TIMESTAMP_S (file->last_mtime));
797 if (ar_member_date (file->name) != file_date)
798 {
799 if (on_behalf_of)
800 error (NILF, _("*** [%s] Archive member `%s' may be bogus; not deleted"),
801 on_behalf_of, file->name);
802 else
803 error (NILF, _("*** Archive member `%s' may be bogus; not deleted"),
804 file->name);
805 }
806 return;
807 }
808#endif
809
810 EINTRLOOP (e, stat (file->name, &st));
811 if (e == 0
812 && S_ISREG (st.st_mode)
813 && FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime)
814 {
815 if (on_behalf_of)
816 error (NILF, _("*** [%s] Deleting file `%s'"), on_behalf_of, file->name);
817 else
818 error (NILF, _("*** Deleting file `%s'"), file->name);
819 if (unlink (file->name) < 0
820 && errno != ENOENT) /* It disappeared; so what. */
821 perror_with_name ("unlink: ", file->name);
822 }
823}
824
825
826/* Delete all non-precious targets of CHILD unless they were already deleted.
827 Set the flag in CHILD to say they've been deleted. */
828
829void
830delete_child_targets (struct child *child)
831{
832 struct dep *d;
833
834 if (child->deleted)
835 return;
836
837 /* Delete the target file if it changed. */
838 delete_target (child->file, NULL);
839
840 /* Also remove any non-precious targets listed in the `also_make' member. */
841 for (d = child->file->also_make; d != 0; d = d->next)
842 delete_target (d->file, child->file->name);
843
844#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
845 /* Also remove any multi target siblings, except for the 'maybe' ones (we
846 handle that here) and precious ones (delete_target deals with that).
847 Note that CHILD is always the multi target head (see remake.c). */
848 if (child->file == child->file->multi_head)
849 {
850 struct file *f2;
851 for (f2 = child->file->multi_next; f2; f2 = f2->multi_next)
852 if (!f2->multi_maybe)
853 delete_target (f2, child->file->name);
854 }
855#endif
856
857 child->deleted = 1;
858}
859
860
861/* Print out the commands in CMDS. */
862
863void
864print_commands (const struct commands *cmds)
865{
866 const char *s;
867
868 fputs (_("# recipe to execute"), stdout);
869
870 if (cmds->fileinfo.filenm == 0)
871 puts (_(" (built-in):"));
872 else
873 printf (_(" (from `%s', line %lu):\n"),
874 cmds->fileinfo.filenm, cmds->fileinfo.lineno);
875
876 s = cmds->commands;
877 while (*s != '\0')
878 {
879 const char *end;
880
881 end = strchr (s, '\n');
882 if (end == 0)
883 end = s + strlen (s);
884
885 printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s);
886
887 s = end + (end[0] == '\n');
888 }
889}
Note: See TracBrowser for help on using the repository browser.

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