| 1 | /* Command processing for GNU Make.
|
|---|
| 2 | Copyright (C) 1988,89,91,92,93,94,95,96,97 Free Software Foundation, Inc.
|
|---|
| 3 | This file is part of GNU Make.
|
|---|
| 4 |
|
|---|
| 5 | GNU Make is free software; you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 8 | any later version.
|
|---|
| 9 |
|
|---|
| 10 | GNU Make is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with GNU Make; see the file COPYING. If not, write to
|
|---|
| 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|---|
| 18 | Boston, MA 02111-1307, USA. */
|
|---|
| 19 |
|
|---|
| 20 | #include "make.h"
|
|---|
| 21 | #include "dep.h"
|
|---|
| 22 | #include "filedef.h"
|
|---|
| 23 | #include "variable.h"
|
|---|
| 24 | #include "job.h"
|
|---|
| 25 | #include "commands.h"
|
|---|
| 26 |
|
|---|
| 27 | #if VMS
|
|---|
| 28 | # define FILE_LIST_SEPARATOR ','
|
|---|
| 29 | #else
|
|---|
| 30 | # define FILE_LIST_SEPARATOR ' '
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | extern int remote_kill PARAMS ((int id, int sig));
|
|---|
| 34 |
|
|---|
| 35 | #ifndef HAVE_UNISTD_H
|
|---|
| 36 | extern int getpid ();
|
|---|
| 37 | #endif
|
|---|
| 38 | |
|---|
| 39 |
|
|---|
| 40 | /* Set FILE's automatic variables up. */
|
|---|
| 41 |
|
|---|
| 42 | void
|
|---|
| 43 | set_file_variables (struct file *file)
|
|---|
| 44 | {
|
|---|
| 45 | struct dep *d;
|
|---|
| 46 | char *at, *percent, *star, *less;
|
|---|
| 47 |
|
|---|
| 48 | #ifndef NO_ARCHIVES
|
|---|
| 49 | /* If the target is an archive member `lib(member)',
|
|---|
| 50 | then $@ is `lib' and $% is `member'. */
|
|---|
| 51 |
|
|---|
| 52 | if (ar_name (file->name))
|
|---|
| 53 | {
|
|---|
| 54 | unsigned int len;
|
|---|
| 55 | char *p;
|
|---|
| 56 |
|
|---|
| 57 | p = strchr (file->name, '(');
|
|---|
| 58 | at = (char *) alloca (p - file->name + 1);
|
|---|
| 59 | bcopy (file->name, at, p - file->name);
|
|---|
| 60 | at[p - file->name] = '\0';
|
|---|
| 61 | len = strlen (p + 1);
|
|---|
| 62 | percent = (char *) alloca (len);
|
|---|
| 63 | bcopy (p + 1, percent, len - 1);
|
|---|
| 64 | percent[len - 1] = '\0';
|
|---|
| 65 | }
|
|---|
| 66 | else
|
|---|
| 67 | #endif /* NO_ARCHIVES. */
|
|---|
| 68 | {
|
|---|
| 69 | at = file->name;
|
|---|
| 70 | percent = "";
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /* $* is the stem from an implicit or static pattern rule. */
|
|---|
| 74 | if (file->stem == 0)
|
|---|
| 75 | {
|
|---|
| 76 | /* In Unix make, $* is set to the target name with
|
|---|
| 77 | any suffix in the .SUFFIXES list stripped off for
|
|---|
| 78 | explicit rules. We store this in the `stem' member. */
|
|---|
| 79 | register struct dep *d;
|
|---|
| 80 | char *name;
|
|---|
| 81 | unsigned int len;
|
|---|
| 82 |
|
|---|
| 83 | #ifndef NO_ARCHIVES
|
|---|
| 84 | if (ar_name (file->name))
|
|---|
| 85 | {
|
|---|
| 86 | name = strchr (file->name, '(') + 1;
|
|---|
| 87 | len = strlen (name) - 1;
|
|---|
| 88 | }
|
|---|
| 89 | else
|
|---|
| 90 | #endif
|
|---|
| 91 | {
|
|---|
| 92 | name = file->name;
|
|---|
| 93 | len = strlen (name);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | for (d = enter_file (".SUFFIXES")->deps; d != 0; d = d->next)
|
|---|
| 97 | {
|
|---|
| 98 | unsigned int slen = strlen (dep_name (d));
|
|---|
| 99 | if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
|
|---|
| 100 | {
|
|---|
| 101 | file->stem = savestring (name, len - slen);
|
|---|
| 102 | break;
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 | if (d == 0)
|
|---|
| 106 | file->stem = "";
|
|---|
| 107 | }
|
|---|
| 108 | star = file->stem;
|
|---|
| 109 |
|
|---|
| 110 | /* $< is the first not order-only dependency. */
|
|---|
| 111 | less = "";
|
|---|
| 112 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 113 | if (!d->ignore_mtime)
|
|---|
| 114 | {
|
|---|
| 115 | less = dep_name (d);
|
|---|
| 116 | break;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | if (file->cmds == default_file->cmds)
|
|---|
| 120 | /* This file got its commands from .DEFAULT.
|
|---|
| 121 | In this case $< is the same as $@. */
|
|---|
| 122 | less = at;
|
|---|
| 123 |
|
|---|
| 124 | #define DEFINE_VARIABLE(name, len, value) \
|
|---|
| 125 | (void) define_variable_for_file (name,len,value,o_automatic,0,file)
|
|---|
| 126 |
|
|---|
| 127 | /* Define the variables. */
|
|---|
| 128 |
|
|---|
| 129 | DEFINE_VARIABLE ("<", 1, less);
|
|---|
| 130 | DEFINE_VARIABLE ("*", 1, star);
|
|---|
| 131 | DEFINE_VARIABLE ("@", 1, at);
|
|---|
| 132 | DEFINE_VARIABLE ("%", 1, percent);
|
|---|
| 133 |
|
|---|
| 134 | /* Compute the values for $^, $+, $?, and $|. */
|
|---|
| 135 |
|
|---|
| 136 | {
|
|---|
| 137 | static char *plus_value=0, *bar_value=0, *qmark_value=0;
|
|---|
| 138 | static unsigned int qmark_max=0, plus_max=0, bar_max=0;
|
|---|
| 139 |
|
|---|
| 140 | unsigned int qmark_len, plus_len, bar_len;
|
|---|
| 141 | char *cp;
|
|---|
| 142 | char *caret_value;
|
|---|
| 143 | char *qp;
|
|---|
| 144 | char *bp;
|
|---|
| 145 | unsigned int len;
|
|---|
| 146 |
|
|---|
| 147 | /* Compute first the value for $+, which is supposed to contain
|
|---|
| 148 | duplicate dependencies as they were listed in the makefile. */
|
|---|
| 149 |
|
|---|
| 150 | plus_len = 0;
|
|---|
| 151 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 152 | if (! d->ignore_mtime)
|
|---|
| 153 | plus_len += strlen (dep_name (d)) + 1;
|
|---|
| 154 | if (plus_len == 0)
|
|---|
| 155 | plus_len++;
|
|---|
| 156 |
|
|---|
| 157 | if (plus_len > plus_max)
|
|---|
| 158 | plus_value = (char *) xmalloc (plus_max = plus_len);
|
|---|
| 159 | cp = plus_value;
|
|---|
| 160 |
|
|---|
| 161 | qmark_len = plus_len + 1; /* Will be this or less. */
|
|---|
| 162 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 163 | if (! d->ignore_mtime)
|
|---|
| 164 | {
|
|---|
| 165 | char *c = dep_name (d);
|
|---|
| 166 |
|
|---|
| 167 | #ifndef NO_ARCHIVES
|
|---|
| 168 | if (ar_name (c))
|
|---|
| 169 | {
|
|---|
| 170 | c = strchr (c, '(') + 1;
|
|---|
| 171 | len = strlen (c) - 1;
|
|---|
| 172 | }
|
|---|
| 173 | else
|
|---|
| 174 | #endif
|
|---|
| 175 | len = strlen (c);
|
|---|
| 176 |
|
|---|
| 177 | bcopy (c, cp, len);
|
|---|
| 178 | cp += len;
|
|---|
| 179 | *cp++ = FILE_LIST_SEPARATOR;
|
|---|
| 180 | if (! d->changed)
|
|---|
| 181 | qmark_len -= len + 1; /* Don't space in $? for this one. */
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | /* Kill the last space and define the variable. */
|
|---|
| 185 |
|
|---|
| 186 | cp[cp > plus_value ? -1 : 0] = '\0';
|
|---|
| 187 | DEFINE_VARIABLE ("+", 1, plus_value);
|
|---|
| 188 |
|
|---|
| 189 | /* Make sure that no dependencies are repeated. This does not
|
|---|
| 190 | really matter for the purpose of updating targets, but it
|
|---|
| 191 | might make some names be listed twice for $^ and $?. */
|
|---|
| 192 |
|
|---|
| 193 | uniquize_deps (file->deps);
|
|---|
| 194 |
|
|---|
| 195 | bar_len = 0;
|
|---|
| 196 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 197 | if (d->ignore_mtime)
|
|---|
| 198 | bar_len += strlen (dep_name (d)) + 1;
|
|---|
| 199 | if (bar_len == 0)
|
|---|
| 200 | bar_len++;
|
|---|
| 201 |
|
|---|
| 202 | /* Compute the values for $^, $?, and $|. */
|
|---|
| 203 |
|
|---|
| 204 | cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */
|
|---|
| 205 |
|
|---|
| 206 | if (qmark_len > qmark_max)
|
|---|
| 207 | qmark_value = (char *) xmalloc (qmark_max = qmark_len);
|
|---|
| 208 | qp = qmark_value;
|
|---|
| 209 |
|
|---|
| 210 | if (bar_len > bar_max)
|
|---|
| 211 | bar_value = (char *) xmalloc (bar_max = bar_len);
|
|---|
| 212 | bp = bar_value;
|
|---|
| 213 |
|
|---|
| 214 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 215 | {
|
|---|
| 216 | char *c = dep_name (d);
|
|---|
| 217 |
|
|---|
| 218 | #ifndef NO_ARCHIVES
|
|---|
| 219 | if (ar_name (c))
|
|---|
| 220 | {
|
|---|
| 221 | c = strchr (c, '(') + 1;
|
|---|
| 222 | len = strlen (c) - 1;
|
|---|
| 223 | }
|
|---|
| 224 | else
|
|---|
| 225 | #endif
|
|---|
| 226 | len = strlen (c);
|
|---|
| 227 |
|
|---|
| 228 | if (d->ignore_mtime)
|
|---|
| 229 | {
|
|---|
| 230 | bcopy (c, bp, len);
|
|---|
| 231 | bp += len;
|
|---|
| 232 | *bp++ = FILE_LIST_SEPARATOR;
|
|---|
| 233 | }
|
|---|
| 234 | else
|
|---|
| 235 | {
|
|---|
| 236 | bcopy (c, cp, len);
|
|---|
| 237 | cp += len;
|
|---|
| 238 | *cp++ = FILE_LIST_SEPARATOR;
|
|---|
| 239 | if (d->changed)
|
|---|
| 240 | {
|
|---|
| 241 | bcopy (c, qp, len);
|
|---|
| 242 | qp += len;
|
|---|
| 243 | *qp++ = FILE_LIST_SEPARATOR;
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | /* Kill the last spaces and define the variables. */
|
|---|
| 249 |
|
|---|
| 250 | cp[cp > caret_value ? -1 : 0] = '\0';
|
|---|
| 251 | DEFINE_VARIABLE ("^", 1, caret_value);
|
|---|
| 252 |
|
|---|
| 253 | qp[qp > qmark_value ? -1 : 0] = '\0';
|
|---|
| 254 | DEFINE_VARIABLE ("?", 1, qmark_value);
|
|---|
| 255 |
|
|---|
| 256 | bp[bp > bar_value ? -1 : 0] = '\0';
|
|---|
| 257 | DEFINE_VARIABLE ("|", 1, bar_value);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | #undef DEFINE_VARIABLE
|
|---|
| 261 | }
|
|---|
| 262 | |
|---|
| 263 |
|
|---|
| 264 | /* Chop CMDS up into individual command lines if necessary.
|
|---|
| 265 | Also set the `lines_flags' and `any_recurse' members. */
|
|---|
| 266 |
|
|---|
| 267 | void
|
|---|
| 268 | chop_commands (struct commands *cmds)
|
|---|
| 269 | {
|
|---|
| 270 | register char *p;
|
|---|
| 271 | unsigned int nlines, idx;
|
|---|
| 272 | char **lines;
|
|---|
| 273 |
|
|---|
| 274 | /* If we don't have any commands,
|
|---|
| 275 | or we already parsed them, never mind. */
|
|---|
| 276 |
|
|---|
| 277 | if (!cmds || cmds->command_lines != 0)
|
|---|
| 278 | return;
|
|---|
| 279 |
|
|---|
| 280 | /* Chop CMDS->commands up into lines in CMDS->command_lines.
|
|---|
| 281 | Also set the corresponding CMDS->lines_flags elements,
|
|---|
| 282 | and the CMDS->any_recurse flag. */
|
|---|
| 283 |
|
|---|
| 284 | nlines = 5;
|
|---|
| 285 | lines = (char **) xmalloc (5 * sizeof (char *));
|
|---|
| 286 | idx = 0;
|
|---|
| 287 | p = cmds->commands;
|
|---|
| 288 | while (*p != '\0')
|
|---|
| 289 | {
|
|---|
| 290 | char *end = p;
|
|---|
| 291 | find_end:;
|
|---|
| 292 | end = strchr (end, '\n');
|
|---|
| 293 | if (end == 0)
|
|---|
| 294 | end = p + strlen (p);
|
|---|
| 295 | else if (end > p && end[-1] == '\\')
|
|---|
| 296 | {
|
|---|
| 297 | int backslash = 1;
|
|---|
| 298 | register char *b;
|
|---|
| 299 | for (b = end - 2; b >= p && *b == '\\'; --b)
|
|---|
| 300 | backslash = !backslash;
|
|---|
| 301 | if (backslash)
|
|---|
| 302 | {
|
|---|
| 303 | ++end;
|
|---|
| 304 | goto find_end;
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | if (idx == nlines)
|
|---|
| 309 | {
|
|---|
| 310 | nlines += 2;
|
|---|
| 311 | lines = (char **) xrealloc ((char *) lines,
|
|---|
| 312 | nlines * sizeof (char *));
|
|---|
| 313 | }
|
|---|
| 314 | lines[idx++] = savestring (p, end - p);
|
|---|
| 315 | p = end;
|
|---|
| 316 | if (*p != '\0')
|
|---|
| 317 | ++p;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | if (idx != nlines)
|
|---|
| 321 | {
|
|---|
| 322 | nlines = idx;
|
|---|
| 323 | lines = (char **) xrealloc ((char *) lines,
|
|---|
| 324 | nlines * sizeof (char *));
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | cmds->ncommand_lines = nlines;
|
|---|
| 328 | cmds->command_lines = lines;
|
|---|
| 329 |
|
|---|
| 330 | cmds->any_recurse = 0;
|
|---|
| 331 | cmds->lines_flags = (char *) xmalloc (nlines);
|
|---|
| 332 | for (idx = 0; idx < nlines; ++idx)
|
|---|
| 333 | {
|
|---|
| 334 | int flags = 0;
|
|---|
| 335 |
|
|---|
| 336 | for (p = lines[idx];
|
|---|
| 337 | isblank ((unsigned char)*p) || *p == '-' || *p == '@' || *p == '+';
|
|---|
| 338 | ++p)
|
|---|
| 339 | switch (*p)
|
|---|
| 340 | {
|
|---|
| 341 | case '+':
|
|---|
| 342 | flags |= COMMANDS_RECURSE;
|
|---|
| 343 | break;
|
|---|
| 344 | case '@':
|
|---|
| 345 | flags |= COMMANDS_SILENT;
|
|---|
| 346 | break;
|
|---|
| 347 | case '-':
|
|---|
| 348 | flags |= COMMANDS_NOERROR;
|
|---|
| 349 | break;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | /* If no explicit '+' was given, look for MAKE variable references. */
|
|---|
| 353 | if (!(flags & COMMANDS_RECURSE)
|
|---|
| 354 | && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
|
|---|
| 355 | flags |= COMMANDS_RECURSE;
|
|---|
| 356 |
|
|---|
| 357 | #ifdef CONFIG_WITH_KMK_BUILTIN
|
|---|
| 358 | /* check if kmk builtin command */
|
|---|
| 359 | if (!strncmp(p, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
|
|---|
| 360 | flags |= COMMANDS_BUILTIN;
|
|---|
| 361 | #endif
|
|---|
| 362 |
|
|---|
| 363 | cmds->lines_flags[idx] = flags;
|
|---|
| 364 | cmds->any_recurse |= flags & COMMANDS_RECURSE;
|
|---|
| 365 | }
|
|---|
| 366 | }
|
|---|
| 367 | |
|---|
| 368 |
|
|---|
| 369 | /* Execute the commands to remake FILE. If they are currently executing,
|
|---|
| 370 | return or have already finished executing, just return. Otherwise,
|
|---|
| 371 | fork off a child process to run the first command line in the sequence. */
|
|---|
| 372 |
|
|---|
| 373 | void
|
|---|
| 374 | execute_file_commands (struct file *file)
|
|---|
| 375 | {
|
|---|
| 376 | register char *p;
|
|---|
| 377 |
|
|---|
| 378 | /* Don't go through all the preparations if
|
|---|
| 379 | the commands are nothing but whitespace. */
|
|---|
| 380 |
|
|---|
| 381 | for (p = file->cmds->commands; *p != '\0'; ++p)
|
|---|
| 382 | if (!isspace ((unsigned char)*p) && *p != '-' && *p != '@')
|
|---|
| 383 | break;
|
|---|
| 384 | if (*p == '\0')
|
|---|
| 385 | {
|
|---|
| 386 | /* If there are no commands, assume everything worked. */
|
|---|
| 387 | file->command_flags |= COMMANDS_NO_COMMANDS;
|
|---|
| 388 | set_command_state (file, cs_running);
|
|---|
| 389 | file->update_status = 0;
|
|---|
| 390 | notice_finished_file (file);
|
|---|
| 391 | return;
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | /* First set the automatic variables according to this file. */
|
|---|
| 395 |
|
|---|
| 396 | initialize_file_variables (file, 0);
|
|---|
| 397 |
|
|---|
| 398 | set_file_variables (file);
|
|---|
| 399 |
|
|---|
| 400 | /* Start the commands running. */
|
|---|
| 401 | new_job (file);
|
|---|
| 402 | }
|
|---|
| 403 | |
|---|
| 404 |
|
|---|
| 405 | /* This is set while we are inside fatal_error_signal,
|
|---|
| 406 | so things can avoid nonreentrant operations. */
|
|---|
| 407 |
|
|---|
| 408 | int handling_fatal_signal = 0;
|
|---|
| 409 |
|
|---|
| 410 | /* Handle fatal signals. */
|
|---|
| 411 |
|
|---|
| 412 | RETSIGTYPE
|
|---|
| 413 | fatal_error_signal (int sig)
|
|---|
| 414 | {
|
|---|
| 415 | #ifdef __MSDOS__
|
|---|
| 416 | extern int dos_status, dos_command_running;
|
|---|
| 417 |
|
|---|
| 418 | if (dos_command_running)
|
|---|
| 419 | {
|
|---|
| 420 | /* That was the child who got the signal, not us. */
|
|---|
| 421 | dos_status |= (sig << 8);
|
|---|
| 422 | return;
|
|---|
| 423 | }
|
|---|
| 424 | remove_intermediates (1);
|
|---|
| 425 | exit (EXIT_FAILURE);
|
|---|
| 426 | #else /* not __MSDOS__ */
|
|---|
| 427 | #ifdef _AMIGA
|
|---|
| 428 | remove_intermediates (1);
|
|---|
| 429 | if (sig == SIGINT)
|
|---|
| 430 | fputs (_("*** Break.\n"), stderr);
|
|---|
| 431 |
|
|---|
| 432 | exit (10);
|
|---|
| 433 | #else /* not Amiga */
|
|---|
| 434 | handling_fatal_signal = 1;
|
|---|
| 435 |
|
|---|
| 436 | /* Set the handling for this signal to the default.
|
|---|
| 437 | It is blocked now while we run this handler. */
|
|---|
| 438 | signal (sig, SIG_DFL);
|
|---|
| 439 |
|
|---|
| 440 | /* A termination signal won't be sent to the entire
|
|---|
| 441 | process group, but it means we want to kill the children. */
|
|---|
| 442 |
|
|---|
| 443 | if (sig == SIGTERM)
|
|---|
| 444 | {
|
|---|
| 445 | register struct child *c;
|
|---|
| 446 | for (c = children; c != 0; c = c->next)
|
|---|
| 447 | if (!c->remote)
|
|---|
| 448 | (void) kill (c->pid, SIGTERM);
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | /* If we got a signal that means the user
|
|---|
| 452 | wanted to kill make, remove pending targets. */
|
|---|
| 453 |
|
|---|
| 454 | if (sig == SIGTERM || sig == SIGINT
|
|---|
| 455 | #ifdef SIGHUP
|
|---|
| 456 | || sig == SIGHUP
|
|---|
| 457 | #endif
|
|---|
| 458 | #ifdef SIGQUIT
|
|---|
| 459 | || sig == SIGQUIT
|
|---|
| 460 | #endif
|
|---|
| 461 | )
|
|---|
| 462 | {
|
|---|
| 463 | register struct child *c;
|
|---|
| 464 |
|
|---|
| 465 | /* Remote children won't automatically get signals sent
|
|---|
| 466 | to the process group, so we must send them. */
|
|---|
| 467 | for (c = children; c != 0; c = c->next)
|
|---|
| 468 | if (c->remote)
|
|---|
| 469 | (void) remote_kill (c->pid, sig);
|
|---|
| 470 |
|
|---|
| 471 | for (c = children; c != 0; c = c->next)
|
|---|
| 472 | delete_child_targets (c);
|
|---|
| 473 |
|
|---|
| 474 | /* Clean up the children. We don't just use the call below because
|
|---|
| 475 | we don't want to print the "Waiting for children" message. */
|
|---|
| 476 | while (job_slots_used > 0)
|
|---|
| 477 | reap_children (1, 0);
|
|---|
| 478 | }
|
|---|
| 479 | else
|
|---|
| 480 | /* Wait for our children to die. */
|
|---|
| 481 | while (job_slots_used > 0)
|
|---|
| 482 | reap_children (1, 1);
|
|---|
| 483 |
|
|---|
| 484 | /* Delete any non-precious intermediate files that were made. */
|
|---|
| 485 |
|
|---|
| 486 | remove_intermediates (1);
|
|---|
| 487 |
|
|---|
| 488 | #ifdef SIGQUIT
|
|---|
| 489 | if (sig == SIGQUIT)
|
|---|
| 490 | /* We don't want to send ourselves SIGQUIT, because it will
|
|---|
| 491 | cause a core dump. Just exit instead. */
|
|---|
| 492 | exit (EXIT_FAILURE);
|
|---|
| 493 | #endif
|
|---|
| 494 |
|
|---|
| 495 | #ifdef WINDOWS32
|
|---|
| 496 | /* Cannot call W32_kill with a pid (it needs a handle) */
|
|---|
| 497 | exit (EXIT_FAILURE);
|
|---|
| 498 | #else
|
|---|
| 499 | /* Signal the same code; this time it will really be fatal. The signal
|
|---|
| 500 | will be unblocked when we return and arrive then to kill us. */
|
|---|
| 501 | if (kill (getpid (), sig) < 0)
|
|---|
| 502 | pfatal_with_name ("kill");
|
|---|
| 503 | #endif /* not WINDOWS32 */
|
|---|
| 504 | #endif /* not Amiga */
|
|---|
| 505 | #endif /* not __MSDOS__ */
|
|---|
| 506 | }
|
|---|
| 507 | |
|---|
| 508 |
|
|---|
| 509 | /* Delete FILE unless it's precious or not actually a file (phony),
|
|---|
| 510 | and it has changed on disk since we last stat'd it. */
|
|---|
| 511 |
|
|---|
| 512 | static void
|
|---|
| 513 | delete_target (struct file *file, char *on_behalf_of)
|
|---|
| 514 | {
|
|---|
| 515 | struct stat st;
|
|---|
| 516 | int e;
|
|---|
| 517 |
|
|---|
| 518 | if (file->precious || file->phony)
|
|---|
| 519 | return;
|
|---|
| 520 |
|
|---|
| 521 | #ifndef NO_ARCHIVES
|
|---|
| 522 | if (ar_name (file->name))
|
|---|
| 523 | {
|
|---|
| 524 | time_t file_date = (file->last_mtime == NONEXISTENT_MTIME
|
|---|
| 525 | ? (time_t) -1
|
|---|
| 526 | : (time_t) FILE_TIMESTAMP_S (file->last_mtime));
|
|---|
| 527 | if (ar_member_date (file->name) != file_date)
|
|---|
| 528 | {
|
|---|
| 529 | if (on_behalf_of)
|
|---|
| 530 | error (NILF, _("*** [%s] Archive member `%s' may be bogus; not deleted"),
|
|---|
| 531 | on_behalf_of, file->name);
|
|---|
| 532 | else
|
|---|
| 533 | error (NILF, _("*** Archive member `%s' may be bogus; not deleted"),
|
|---|
| 534 | file->name);
|
|---|
| 535 | }
|
|---|
| 536 | return;
|
|---|
| 537 | }
|
|---|
| 538 | #endif
|
|---|
| 539 |
|
|---|
| 540 | EINTRLOOP (e, stat (file->name, &st));
|
|---|
| 541 | if (e == 0
|
|---|
| 542 | && S_ISREG (st.st_mode)
|
|---|
| 543 | && FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime)
|
|---|
| 544 | {
|
|---|
| 545 | if (on_behalf_of)
|
|---|
| 546 | error (NILF, _("*** [%s] Deleting file `%s'"), on_behalf_of, file->name);
|
|---|
| 547 | else
|
|---|
| 548 | error (NILF, _("*** Deleting file `%s'"), file->name);
|
|---|
| 549 | if (unlink (file->name) < 0
|
|---|
| 550 | && errno != ENOENT) /* It disappeared; so what. */
|
|---|
| 551 | perror_with_name ("unlink: ", file->name);
|
|---|
| 552 | }
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 | /* Delete all non-precious targets of CHILD unless they were already deleted.
|
|---|
| 557 | Set the flag in CHILD to say they've been deleted. */
|
|---|
| 558 |
|
|---|
| 559 | void
|
|---|
| 560 | delete_child_targets (struct child *child)
|
|---|
| 561 | {
|
|---|
| 562 | struct dep *d;
|
|---|
| 563 |
|
|---|
| 564 | if (child->deleted)
|
|---|
| 565 | return;
|
|---|
| 566 |
|
|---|
| 567 | /* Delete the target file if it changed. */
|
|---|
| 568 | delete_target (child->file, (char *) 0);
|
|---|
| 569 |
|
|---|
| 570 | /* Also remove any non-precious targets listed in the `also_make' member. */
|
|---|
| 571 | for (d = child->file->also_make; d != 0; d = d->next)
|
|---|
| 572 | delete_target (d->file, child->file->name);
|
|---|
| 573 |
|
|---|
| 574 | child->deleted = 1;
|
|---|
| 575 | }
|
|---|
| 576 | |
|---|
| 577 |
|
|---|
| 578 | /* Print out the commands in CMDS. */
|
|---|
| 579 |
|
|---|
| 580 | void
|
|---|
| 581 | print_commands (struct commands *cmds)
|
|---|
| 582 | {
|
|---|
| 583 | register char *s;
|
|---|
| 584 |
|
|---|
| 585 | fputs (_("# commands to execute"), stdout);
|
|---|
| 586 |
|
|---|
| 587 | if (cmds->fileinfo.filenm == 0)
|
|---|
| 588 | puts (_(" (built-in):"));
|
|---|
| 589 | else
|
|---|
| 590 | printf (_(" (from `%s', line %lu):\n"),
|
|---|
| 591 | cmds->fileinfo.filenm, cmds->fileinfo.lineno);
|
|---|
| 592 |
|
|---|
| 593 | s = cmds->commands;
|
|---|
| 594 | while (*s != '\0')
|
|---|
| 595 | {
|
|---|
| 596 | char *end;
|
|---|
| 597 |
|
|---|
| 598 | while (isspace ((unsigned char)*s))
|
|---|
| 599 | ++s;
|
|---|
| 600 |
|
|---|
| 601 | end = strchr (s, '\n');
|
|---|
| 602 | if (end == 0)
|
|---|
| 603 | end = s + strlen (s);
|
|---|
| 604 |
|
|---|
| 605 | printf ("\t%.*s\n", (int) (end - s), s);
|
|---|
| 606 |
|
|---|
| 607 | s = end;
|
|---|
| 608 | }
|
|---|
| 609 | }
|
|---|