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