[503] | 1 | /* Target file management 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"
|
---|
[53] | 18 |
|
---|
| 19 | #include <assert.h>
|
---|
| 20 |
|
---|
[3140] | 21 | #include "filedef.h"
|
---|
[53] | 22 | #include "dep.h"
|
---|
| 23 | #include "job.h"
|
---|
| 24 | #include "commands.h"
|
---|
| 25 | #include "variable.h"
|
---|
| 26 | #include "debug.h"
|
---|
| 27 | #include "hash.h"
|
---|
[1915] | 28 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 29 | # include <stddef.h>
|
---|
| 30 | #endif
|
---|
[53] | 31 |
|
---|
| 32 |
|
---|
[287] | 33 | /* Remember whether snap_deps has been invoked: we need this to be sure we
|
---|
| 34 | don't add new rules (via $(eval ...)) afterwards. In the future it would
|
---|
| 35 | be nice to support this, but it means we'd need to re-run snap_deps() or
|
---|
| 36 | at least its functionality... it might mean changing snap_deps() to be run
|
---|
| 37 | per-file, so we can invoke it after the eval... or remembering which files
|
---|
| 38 | in the hash have been snapped (a new boolean flag?) and having snap_deps()
|
---|
| 39 | only work on files which have not yet been snapped. */
|
---|
| 40 | int snapped_deps = 0;
|
---|
| 41 |
|
---|
[53] | 42 | /* Hash table of files the makefile knows how to make. */
|
---|
| 43 |
|
---|
[1902] | 44 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[53] | 45 | static unsigned long
|
---|
| 46 | file_hash_1 (const void *key)
|
---|
| 47 | {
|
---|
| 48 | return_ISTRING_HASH_1 (((struct file const *) key)->hname);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | static unsigned long
|
---|
| 52 | file_hash_2 (const void *key)
|
---|
| 53 | {
|
---|
| 54 | return_ISTRING_HASH_2 (((struct file const *) key)->hname);
|
---|
| 55 | }
|
---|
[1902] | 56 | #endif /* !CONFIG_WITH_STRCACHE2 */
|
---|
[53] | 57 |
|
---|
| 58 | static int
|
---|
| 59 | file_hash_cmp (const void *x, const void *y)
|
---|
| 60 | {
|
---|
[1892] | 61 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1857] | 62 | return_ISTRING_COMPARE (((struct file const *) x)->hname,
|
---|
[3140] | 63 | ((struct file const *) y)->hname);
|
---|
[1892] | 64 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 65 | return ((struct file const *) x)->hname
|
---|
| 66 | == ((struct file const *) y)->hname ? 0 : -1;
|
---|
| 67 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[1857] | 68 | }
|
---|
| 69 |
|
---|
[53] | 70 | static struct hash_table files;
|
---|
| 71 |
|
---|
| 72 | /* Whether or not .SECONDARY with no prerequisites was given. */
|
---|
| 73 | static int all_secondary = 0;
|
---|
| 74 |
|
---|
| 75 | /* Access the hash table of all file records.
|
---|
| 76 | lookup_file given a name, return the struct file * for that name,
|
---|
[903] | 77 | or nil if there is none.
|
---|
| 78 | */
|
---|
[53] | 79 |
|
---|
[1975] | 80 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[53] | 81 | struct file *
|
---|
[903] | 82 | lookup_file (const char *name)
|
---|
[1975] | 83 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
[1857] | 84 | MY_INLINE struct file *
|
---|
| 85 | lookup_file_common (const char *name, int cached)
|
---|
[1975] | 86 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[53] | 87 | {
|
---|
[903] | 88 | struct file *f;
|
---|
[53] | 89 | struct file file_key;
|
---|
[3140] | 90 | #ifdef VMS
|
---|
| 91 | int want_vmsify;
|
---|
| 92 | #ifndef WANT_CASE_SENSITIVE_TARGETS
|
---|
[903] | 93 | char *lname;
|
---|
[53] | 94 | #endif
|
---|
[3140] | 95 | #endif
|
---|
[53] | 96 |
|
---|
| 97 | assert (*name != '\0');
|
---|
| 98 |
|
---|
| 99 | /* This is also done in parse_file_seq, so this is redundant
|
---|
| 100 | for names read from makefiles. It is here for names passed
|
---|
| 101 | on the command line. */
|
---|
| 102 | #ifdef VMS
|
---|
[3140] | 103 | want_vmsify = (strpbrk (name, "]>:^") != NULL);
|
---|
[53] | 104 | # ifndef WANT_CASE_SENSITIVE_TARGETS
|
---|
[503] | 105 | if (*name != '.')
|
---|
| 106 | {
|
---|
[903] | 107 | const char *n;
|
---|
| 108 | char *ln;
|
---|
| 109 | lname = xstrdup (name);
|
---|
[503] | 110 | for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
|
---|
| 111 | *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
|
---|
| 112 | *ln = '\0';
|
---|
| 113 | name = lname;
|
---|
| 114 | }
|
---|
[53] | 115 | # endif
|
---|
| 116 |
|
---|
| 117 | while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
|
---|
| 118 | name += 2;
|
---|
[3140] | 119 | while (name[0] == '<' && name[1] == '>' && name[2] != '\0')
|
---|
| 120 | name += 2;
|
---|
[53] | 121 | #endif
|
---|
[2591] | 122 | while (name[0] == '.'
|
---|
| 123 | #ifdef HAVE_DOS_PATHS
|
---|
[3140] | 124 | && (name[1] == '/' || name[1] == '\\')
|
---|
[2591] | 125 | #else
|
---|
[3140] | 126 | && name[1] == '/'
|
---|
[2591] | 127 | #endif
|
---|
[3140] | 128 | && name[2] != '\0')
|
---|
[53] | 129 | {
|
---|
| 130 | name += 2;
|
---|
[2591] | 131 | while (*name == '/'
|
---|
| 132 | #ifdef HAVE_DOS_PATHS
|
---|
[3140] | 133 | || *name == '\\'
|
---|
[2591] | 134 | #endif
|
---|
[3140] | 135 | )
|
---|
| 136 | /* Skip following slashes: ".//foo" is "foo", not "/foo". */
|
---|
| 137 | ++name;
|
---|
[53] | 138 | }
|
---|
| 139 |
|
---|
| 140 | if (*name == '\0')
|
---|
[3140] | 141 | {
|
---|
| 142 | /* It was all slashes after a dot. */
|
---|
| 143 | #if defined(_AMIGA)
|
---|
| 144 | name = "";
|
---|
[53] | 145 | #else
|
---|
[3140] | 146 | name = "./";
|
---|
[903] | 147 | #endif
|
---|
[3140] | 148 | #if defined(VMS)
|
---|
| 149 | /* TODO - This section is probably not needed. */
|
---|
| 150 | if (want_vmsify)
|
---|
| 151 | name = "[]";
|
---|
| 152 | #endif
|
---|
| 153 | }
|
---|
[1892] | 154 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[53] | 155 | file_key.hname = name;
|
---|
[903] | 156 | f = hash_find_item (&files, &file_key);
|
---|
[1892] | 157 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 158 | if (!cached)
|
---|
| 159 | {
|
---|
[1903] | 160 | file_key.hname = strcache2_lookup_file (&file_strcache, name, strlen (name));
|
---|
[1892] | 161 | if (file_key.hname)
|
---|
[1902] | 162 | f = hash_find_item_strcached (&files, &file_key);
|
---|
[1892] | 163 | else
|
---|
| 164 | f = NULL;
|
---|
| 165 | }
|
---|
| 166 | else
|
---|
| 167 | {
|
---|
| 168 | file_key.hname = name;
|
---|
[1902] | 169 | f = hash_find_item_strcached (&files, &file_key);
|
---|
[1892] | 170 | }
|
---|
| 171 |
|
---|
| 172 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[53] | 173 | #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
|
---|
[503] | 174 | if (*name != '.')
|
---|
| 175 | free (lname);
|
---|
[53] | 176 | #endif
|
---|
[903] | 177 |
|
---|
[53] | 178 | return f;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[1975] | 181 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
[1857] | 182 | /* Given a name, return the struct file * for that name,
|
---|
| 183 | or nil if there is none. */
|
---|
| 184 |
|
---|
| 185 | struct file *
|
---|
| 186 | lookup_file (const char *name)
|
---|
| 187 | {
|
---|
| 188 | return lookup_file_common (name, 0 /* cached */);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | /* Given a name in the strcache, return the struct file * for that name,
|
---|
| 192 | or nil if there is none. */
|
---|
| 193 | struct file *
|
---|
| 194 | lookup_file_cached (const char *name)
|
---|
| 195 | {
|
---|
| 196 | assert (strcache_iscached (name));
|
---|
| 197 | return lookup_file_common (name, 1 /* cached */);
|
---|
| 198 | }
|
---|
[1975] | 199 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[1857] | 200 |
|
---|
| 201 |
|
---|
[903] | 202 | /* Look up a file record for file NAME and return it.
|
---|
| 203 | Create a new record if one doesn't exist. NAME will be stored in the
|
---|
| 204 | new record so it should be constant or in the strcache etc.
|
---|
| 205 | */
|
---|
| 206 |
|
---|
[53] | 207 | struct file *
|
---|
[903] | 208 | enter_file (const char *name)
|
---|
[53] | 209 | {
|
---|
[903] | 210 | struct file *f;
|
---|
| 211 | struct file *new;
|
---|
| 212 | struct file **file_slot;
|
---|
[53] | 213 | struct file file_key;
|
---|
| 214 |
|
---|
| 215 | assert (*name != '\0');
|
---|
[3140] | 216 | assert (! verify_flag || strcache_iscached (name));
|
---|
[53] | 217 |
|
---|
| 218 | #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
|
---|
[503] | 219 | if (*name != '.')
|
---|
| 220 | {
|
---|
[903] | 221 | const char *n;
|
---|
| 222 | char *lname, *ln;
|
---|
| 223 | lname = xstrdup (name);
|
---|
[503] | 224 | for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
|
---|
[903] | 225 | if (isupper ((unsigned char)*n))
|
---|
| 226 | *ln = tolower ((unsigned char)*n);
|
---|
| 227 | else
|
---|
| 228 | *ln = *n;
|
---|
[53] | 229 |
|
---|
[903] | 230 | *ln = '\0';
|
---|
| 231 | name = strcache_add (lname);
|
---|
| 232 | free (lname);
|
---|
[503] | 233 | }
|
---|
[53] | 234 | #endif
|
---|
| 235 |
|
---|
| 236 | file_key.hname = name;
|
---|
[1901] | 237 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[53] | 238 | file_slot = (struct file **) hash_find_slot (&files, &file_key);
|
---|
[1901] | 239 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 240 | file_slot = (struct file **) hash_find_slot_strcached (&files, &file_key);
|
---|
| 241 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[53] | 242 | f = *file_slot;
|
---|
| 243 | if (! HASH_VACANT (f) && !f->double_colon)
|
---|
[3140] | 244 | {
|
---|
| 245 | f->builtin = 0;
|
---|
| 246 | return f;
|
---|
| 247 | }
|
---|
[53] | 248 |
|
---|
[1867] | 249 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
[2591] | 250 | new = xcalloc (sizeof (struct file));
|
---|
[1867] | 251 | #else
|
---|
| 252 | new = alloccache_calloc (&file_cache);
|
---|
| 253 | #endif
|
---|
[53] | 254 | new->name = new->hname = name;
|
---|
[3140] | 255 | new->update_status = us_none;
|
---|
[53] | 256 |
|
---|
| 257 | if (HASH_VACANT (f))
|
---|
[503] | 258 | {
|
---|
| 259 | new->last = new;
|
---|
| 260 | hash_insert_at (&files, new, file_slot);
|
---|
| 261 | }
|
---|
[53] | 262 | else
|
---|
| 263 | {
|
---|
| 264 | /* There is already a double-colon entry for this file. */
|
---|
| 265 | new->double_colon = f;
|
---|
[503] | 266 | f->last->prev = new;
|
---|
| 267 | f->last = new;
|
---|
[53] | 268 | }
|
---|
| 269 |
|
---|
[1701] | 270 | #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
|
---|
| 271 | /* Check if the name needs 2nd expansion or not. */
|
---|
| 272 | if (second_target_expansion && strchr (name, '$') != NULL)
|
---|
| 273 | new->need_2nd_target_expansion = 1;
|
---|
[1793] | 274 | #endif
|
---|
[1701] | 275 |
|
---|
[53] | 276 | return new;
|
---|
| 277 | }
|
---|
| 278 | |
---|
| 279 |
|
---|
[3140] | 280 | /* Rehash FILE to NAME. This is not as simple as resetting
|
---|
[53] | 281 | the 'hname' member, since it must be put in a new hash bucket,
|
---|
| 282 | and possibly merged with an existing file called NAME. */
|
---|
| 283 |
|
---|
[903] | 284 | void
|
---|
[53] | 285 | rehash_file (struct file *from_file, const char *to_hname)
|
---|
| 286 | {
|
---|
| 287 | struct file file_key;
|
---|
| 288 | struct file **file_slot;
|
---|
| 289 | struct file *to_file;
|
---|
| 290 | struct file *deleted_file;
|
---|
| 291 | struct file *f;
|
---|
[1892] | 292 |
|
---|
[1857] | 293 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 294 | assert (strcache_iscached (to_hname));
|
---|
| 295 | assert (strcache_iscached (from_file->hname));
|
---|
| 296 | #endif
|
---|
[903] | 297 |
|
---|
[3140] | 298 | /* If it's already that name, we're done. */
|
---|
[53] | 299 | from_file->builtin = 0;
|
---|
[903] | 300 | file_key.hname = to_hname;
|
---|
[53] | 301 | if (! file_hash_cmp (from_file, &file_key))
|
---|
| 302 | return;
|
---|
[903] | 303 |
|
---|
[53] | 304 | /* Find the end of the renamed list for the "from" file. */
|
---|
| 305 | file_key.hname = from_file->hname;
|
---|
| 306 | while (from_file->renamed != 0)
|
---|
| 307 | from_file = from_file->renamed;
|
---|
[903] | 308 | if (file_hash_cmp (from_file, &file_key))
|
---|
[53] | 309 | /* hname changed unexpectedly!! */
|
---|
| 310 | abort ();
|
---|
[903] | 311 |
|
---|
[1902] | 312 | /* Remove the "from" file from the hash. */
|
---|
[53] | 313 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1902] | 314 | deleted_file = hash_delete (&files, from_file);
|
---|
| 315 | #else
|
---|
| 316 | deleted_file = hash_delete_strcached (&files, from_file);
|
---|
[53] | 317 | #endif
|
---|
| 318 | if (deleted_file != from_file)
|
---|
| 319 | /* from_file isn't the one stored in files */
|
---|
| 320 | abort ();
|
---|
[903] | 321 |
|
---|
[53] | 322 | /* Find where the newly renamed file will go in the hash. */
|
---|
[1901] | 323 | file_key.hname = to_hname;
|
---|
[53] | 324 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1901] | 325 | file_slot = (struct file **) hash_find_slot (&files, &file_key);
|
---|
| 326 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 327 | file_slot = (struct file **) hash_find_slot_strcached (&files, &file_key);
|
---|
[53] | 328 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 329 | to_file = *file_slot;
|
---|
[903] | 330 |
|
---|
[53] | 331 | /* Change the hash name for this file. */
|
---|
| 332 | from_file->hname = to_hname;
|
---|
| 333 | for (f = from_file->double_colon; f != 0; f = f->prev)
|
---|
| 334 | f->hname = to_hname;
|
---|
[903] | 335 |
|
---|
[53] | 336 | /* If the new name doesn't exist yet just set it to the renamed file. */
|
---|
| 337 | if (HASH_VACANT (to_file))
|
---|
[903] | 338 | {
|
---|
| 339 | hash_insert_at (&files, from_file, file_slot);
|
---|
| 340 | return;
|
---|
[53] | 341 | }
|
---|
[903] | 342 |
|
---|
| 343 | /* TO_FILE already exists under TO_HNAME.
|
---|
[53] | 344 | We must retain TO_FILE and merge FROM_FILE into it. */
|
---|
[903] | 345 |
|
---|
| 346 | if (from_file->cmds != 0)
|
---|
| 347 | {
|
---|
| 348 | if (to_file->cmds == 0)
|
---|
| 349 | to_file->cmds = from_file->cmds;
|
---|
| 350 | else if (from_file->cmds != to_file->cmds)
|
---|
[3140] | 351 | {
|
---|
[903] | 352 | size_t l = strlen (from_file->name);
|
---|
| 353 | /* We have two sets of commands. We will go with the
|
---|
| 354 | one given in the rule explicitly mentioning this name,
|
---|
| 355 | but give a message to let the user know what's going on. */
|
---|
| 356 | if (to_file->cmds->fileinfo.filenm != 0)
|
---|
[3140] | 357 | error (&from_file->cmds->fileinfo,
|
---|
| 358 | l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH,
|
---|
[903] | 359 | _("Recipe was specified for file '%s' at %s:%lu,"),
|
---|
| 360 | from_file->name, to_file->cmds->fileinfo.filenm,
|
---|
| 361 | to_file->cmds->fileinfo.lineno);
|
---|
[3140] | 362 | else
|
---|
| 363 | error (&from_file->cmds->fileinfo, l,
|
---|
[903] | 364 | _("Recipe for file '%s' was found by implicit rule search,"),
|
---|
[3140] | 365 | from_file->name);
|
---|
| 366 | l += strlen (to_hname);
|
---|
| 367 | error (&from_file->cmds->fileinfo, l,
|
---|
[903] | 368 | _("but '%s' is now considered the same file as '%s'."),
|
---|
[3140] | 369 | from_file->name, to_hname);
|
---|
| 370 | error (&from_file->cmds->fileinfo, l,
|
---|
[903] | 371 | _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
|
---|
| 372 | to_hname, from_file->name);
|
---|
| 373 | }
|
---|
[53] | 374 | }
|
---|
[2665] | 375 |
|
---|
| 376 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
| 377 | /* Merge multi target attributes and considerations. */
|
---|
| 378 | if (from_file->multi_head)
|
---|
| 379 | {
|
---|
[3140] | 380 | if (to_file->multi_head)
|
---|
| 381 | OSS (fatal, NILF, _("can't rename/merge multi target '%s' with multi target '%s'"),
|
---|
[2665] | 382 | from_file->name, to_hname);
|
---|
| 383 |
|
---|
| 384 | to_file->multi_maybe = from_file->multi_maybe;
|
---|
| 385 | to_file->multi_next = from_file->multi_next;
|
---|
| 386 | to_file->multi_head = f = from_file->multi_head;
|
---|
[2741] | 387 | if (f == from_file)
|
---|
| 388 | {
|
---|
| 389 | for (; f != 0; f = f->multi_next)
|
---|
| 390 | f->multi_head = to_file;
|
---|
| 391 | to_file->multi_head = to_file;
|
---|
[2665] | 392 | }
|
---|
| 393 | else
|
---|
| 394 | {
|
---|
| 395 | while (f->multi_next != from_file)
|
---|
[2740] | 396 | f = f->multi_next;
|
---|
[2665] | 397 | assert(f->multi_next == from_file);
|
---|
| 398 | f->multi_next = to_file;
|
---|
[2741] | 399 | }
|
---|
[2740] | 400 | # ifdef NDEBUG
|
---|
| 401 | from_file->multi_head = to_file->multi_head;
|
---|
[2741] | 402 | from_file->multi_next = NULL;
|
---|
| 403 | # else
|
---|
| 404 | from_file->multi_head = (struct file *)0x2; /* poison */
|
---|
| 405 | from_file->multi_next = (struct file *)0x8;
|
---|
[2665] | 406 | # endif
|
---|
| 407 | }
|
---|
| 408 | #endif
|
---|
[903] | 409 |
|
---|
[53] | 410 | /* Merge the dependencies of the two files. */
|
---|
[903] | 411 |
|
---|
| 412 | if (to_file->deps == 0)
|
---|
| 413 | to_file->deps = from_file->deps;
|
---|
| 414 | else
|
---|
| 415 | {
|
---|
| 416 | struct dep *deps = to_file->deps;
|
---|
| 417 | while (deps->next != 0)
|
---|
| 418 | deps = deps->next;
|
---|
| 419 | deps->next = from_file->deps;
|
---|
[53] | 420 | }
|
---|
[903] | 421 |
|
---|
[53] | 422 | merge_variable_set_lists (&to_file->variables, from_file->variables);
|
---|
[903] | 423 |
|
---|
[3140] | 424 | if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
|
---|
| 425 | OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"),
|
---|
[903] | 426 | from_file->name, to_hname);
|
---|
| 427 | if (!to_file->double_colon && from_file->double_colon)
|
---|
| 428 | {
|
---|
[3140] | 429 | if (to_file->is_target)
|
---|
| 430 | OSS (fatal, NILF,
|
---|
| 431 | _("can't rename double-colon '%s' to single-colon '%s'"),
|
---|
[903] | 432 | from_file->name, to_hname);
|
---|
| 433 | else
|
---|
| 434 | to_file->double_colon = from_file->double_colon;
|
---|
[53] | 435 | }
|
---|
[903] | 436 |
|
---|
| 437 | if (from_file->last_mtime > to_file->last_mtime)
|
---|
| 438 | /* %%% Kludge so -W wins on a file that gets vpathized. */
|
---|
[53] | 439 | to_file->last_mtime = from_file->last_mtime;
|
---|
[903] | 440 |
|
---|
| 441 | to_file->mtime_before_update = from_file->mtime_before_update;
|
---|
[53] | 442 |
|
---|
[903] | 443 | #define MERGE(field) to_file->field |= from_file->field
|
---|
| 444 | MERGE (precious);
|
---|
| 445 | MERGE (tried_implicit);
|
---|
| 446 | MERGE (updating);
|
---|
| 447 | MERGE (updated);
|
---|
| 448 | MERGE (is_target);
|
---|
| 449 | MERGE (cmd_target);
|
---|
[3140] | 450 | MERGE (phony);
|
---|
[903] | 451 | MERGE (loaded);
|
---|
[53] | 452 | MERGE (ignore_vpath);
|
---|
| 453 | #undef MERGE
|
---|
[3140] | 454 |
|
---|
[903] | 455 | to_file->builtin = 0;
|
---|
| 456 | from_file->renamed = to_file;
|
---|
| 457 | }
|
---|
| 458 |
|
---|
[3140] | 459 | /* Rename FILE to NAME. This is not as simple as resetting
|
---|
[903] | 460 | the 'name' member, since it must be put in a new hash bucket,
|
---|
| 461 | and possibly merged with an existing file called NAME. */
|
---|
| 462 |
|
---|
| 463 | void
|
---|
| 464 | rename_file (struct file *from_file, const char *to_hname)
|
---|
| 465 | {
|
---|
| 466 | rehash_file (from_file, to_hname);
|
---|
| 467 | while (from_file)
|
---|
| 468 | {
|
---|
| 469 | from_file->name = from_file->hname;
|
---|
[53] | 470 | from_file = from_file->prev;
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
[1701] | 473 | |
---|
| 474 |
|
---|
| 475 | #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
|
---|
[1793] | 476 | /* Performs secondary target name expansion and then renames
|
---|
[1701] | 477 | the file using rename_file. */
|
---|
| 478 | static void
|
---|
[1881] | 479 | do_2nd_target_expansion (struct file *f)
|
---|
| 480 | {
|
---|
[1898] | 481 | unsigned int len;
|
---|
[1881] | 482 | char *tmp_name = allocated_variable_expand_2 (
|
---|
[1701] | 483 | f->name, strcache2_get_len (&file_strcache, f->name), &len);
|
---|
| 484 | const char *name = strcache_add_len (tmp_name, len);
|
---|
| 485 | free (tmp_name);
|
---|
| 486 | rename_file (f, name);
|
---|
| 487 | }
|
---|
[53] | 488 | #endif /* CONFIG_WITH_2ND_TARGET_EXPANSION */
|
---|
| 489 | |
---|
| 490 |
|
---|
| 491 | /* Remove all nonprecious intermediate files.
|
---|
| 492 | If SIG is nonzero, this was caused by a fatal signal,
|
---|
| 493 | meaning that a different message will be printed, and
|
---|
| 494 | the message will go to stderr rather than stdout. */
|
---|
| 495 |
|
---|
[903] | 496 | void
|
---|
| 497 | remove_intermediates (int sig)
|
---|
[53] | 498 | {
|
---|
| 499 | struct file **file_slot;
|
---|
| 500 | struct file **file_end;
|
---|
| 501 | int doneany = 0;
|
---|
| 502 |
|
---|
| 503 | /* If there's no way we will ever remove anything anyway, punt early. */
|
---|
| 504 | if (question_flag || touch_flag || all_secondary)
|
---|
| 505 | return;
|
---|
| 506 |
|
---|
| 507 | if (sig && just_print_flag)
|
---|
| 508 | return;
|
---|
| 509 |
|
---|
| 510 | file_slot = (struct file **) files.ht_vec;
|
---|
| 511 | file_end = file_slot + files.ht_size;
|
---|
[3140] | 512 | for ( ; file_slot < file_end; file_slot++)
|
---|
[287] | 513 | if (! HASH_VACANT (*file_slot))
|
---|
| 514 | {
|
---|
[1993] | 515 | struct file *f = *file_slot;
|
---|
[287] | 516 | /* Is this file eligible for automatic deletion?
|
---|
[3140] | 517 | Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
|
---|
| 518 | given on the command line, and it's either a -include makefile or
|
---|
| 519 | it's not precious. */
|
---|
| 520 | if (f->intermediate && (f->dontcare || !f->precious)
|
---|
| 521 | && !f->secondary && !f->cmd_target)
|
---|
| 522 | {
|
---|
| 523 | int status;
|
---|
| 524 | if (f->update_status == us_none)
|
---|
| 525 | /* If nothing would have created this file yet,
|
---|
| 526 | don't print an "rm" command for it. */
|
---|
| 527 | continue;
|
---|
| 528 | if (just_print_flag)
|
---|
| 529 | status = 0;
|
---|
| 530 | else
|
---|
| 531 | {
|
---|
| 532 | status = unlink (f->name);
|
---|
| 533 | if (status < 0 && errno == ENOENT)
|
---|
| 534 | continue;
|
---|
| 535 | }
|
---|
| 536 | if (!f->dontcare)
|
---|
| 537 | {
|
---|
| 538 | if (sig)
|
---|
| 539 | OS (error, NILF,
|
---|
| 540 | _("*** Deleting intermediate file '%s'"), f->name);
|
---|
| 541 | else
|
---|
| 542 | {
|
---|
| 543 | if (! doneany)
|
---|
| 544 | DB (DB_BASIC, (_("Removing intermediate files...\n")));
|
---|
| 545 | if (!silent_flag)
|
---|
| 546 | {
|
---|
| 547 | if (! doneany)
|
---|
| 548 | {
|
---|
| 549 | fputs ("rm ", stdout);
|
---|
| 550 | doneany = 1;
|
---|
| 551 | }
|
---|
| 552 | else
|
---|
| 553 | putchar (' ');
|
---|
| 554 | fputs (f->name, stdout);
|
---|
| 555 | fflush (stdout);
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 | if (status < 0)
|
---|
[53] | 559 | perror_with_name ("unlink: ", f->name);
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | if (doneany && !sig)
|
---|
| 565 | {
|
---|
| 566 | putchar ('\n');
|
---|
| 567 | fflush (stdout);
|
---|
[2591] | 568 | }
|
---|
| 569 | }
|
---|
| 570 | |
---|
[503] | 571 |
|
---|
[2591] | 572 | /* Given a string containing prerequisites (fully expanded), break it up into
|
---|
[503] | 573 | a struct dep list. Enter each of these prereqs into the file database.
|
---|
[3140] | 574 | */
|
---|
| 575 | struct dep *
|
---|
[503] | 576 | split_prereqs (char *p)
|
---|
| 577 | {
|
---|
| 578 | struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL,
|
---|
| 579 | PARSEFS_NONE);
|
---|
| 580 |
|
---|
| 581 | if (*p)
|
---|
| 582 | {
|
---|
| 583 | /* Files that follow '|' are "order-only" prerequisites that satisfy the
|
---|
[3140] | 584 | dependency by existing: their modification times are irrelevant. */
|
---|
[1980] | 585 | struct dep *ood;
|
---|
[503] | 586 |
|
---|
| 587 | ++p;
|
---|
| 588 | ood = PARSE_SIMPLE_SEQ (&p, struct dep);
|
---|
| 589 |
|
---|
| 590 | if (! new)
|
---|
| 591 | new = ood;
|
---|
| 592 | else
|
---|
| 593 | {
|
---|
| 594 | struct dep *dp;
|
---|
| 595 | for (dp = new; dp->next != NULL; dp = dp->next)
|
---|
| 596 | ;
|
---|
| 597 | dp->next = ood;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
| 600 | for (; ood != NULL; ood = ood->next)
|
---|
| 601 | ood->ignore_mtime = 1;
|
---|
| 602 | }
|
---|
[2591] | 603 |
|
---|
| 604 | return new;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | /* Given a list of prerequisites, enter them into the file database.
|
---|
| 608 | If STEM is set then first expand patterns using STEM. */
|
---|
| 609 | struct dep *
|
---|
| 610 | enter_prereqs (struct dep *deps, const char *stem)
|
---|
| 611 | {
|
---|
| 612 | struct dep *d1;
|
---|
| 613 |
|
---|
| 614 | if (deps == 0)
|
---|
| 615 | return 0;
|
---|
| 616 |
|
---|
| 617 | /* If we have a stem, expand the %'s. We use patsubst_expand to translate
|
---|
| 618 | the prerequisites' patterns into plain prerequisite names. */
|
---|
| 619 | if (stem)
|
---|
| 620 | {
|
---|
| 621 | const char *pattern = "%";
|
---|
| 622 | char *buffer = variable_expand ("");
|
---|
| 623 | struct dep *dp = deps, *dl = 0;
|
---|
| 624 |
|
---|
| 625 | while (dp != 0)
|
---|
| 626 | {
|
---|
| 627 | char *percent;
|
---|
| 628 | int nl = strlen (dp->name) + 1;
|
---|
| 629 | char *nm = alloca (nl);
|
---|
| 630 | memcpy (nm, dp->name, nl);
|
---|
| 631 | percent = find_percent (nm);
|
---|
| 632 | if (percent)
|
---|
| 633 | {
|
---|
| 634 | char *o;
|
---|
| 635 |
|
---|
| 636 | /* We have to handle empty stems specially, because that
|
---|
| 637 | would be equivalent to $(patsubst %,dp->name,) which
|
---|
| 638 | will always be empty. */
|
---|
| 639 | if (stem[0] == '\0')
|
---|
| 640 | {
|
---|
| 641 | memmove (percent, percent+1, strlen (percent));
|
---|
| 642 | o = variable_buffer_output (buffer, nm, strlen (nm) + 1);
|
---|
| 643 | }
|
---|
| 644 | else
|
---|
| 645 | o = patsubst_expand_pat (buffer, stem, pattern, nm,
|
---|
| 646 | pattern+1, percent+1);
|
---|
| 647 |
|
---|
| 648 | /* If the name expanded to the empty string, ignore it. */
|
---|
| 649 | if (buffer[0] == '\0')
|
---|
| 650 | {
|
---|
| 651 | struct dep *df = dp;
|
---|
| 652 | if (dp == deps)
|
---|
| 653 | dp = deps = deps->next;
|
---|
| 654 | else
|
---|
| 655 | dp = dl->next = dp->next;
|
---|
| 656 | free_dep (df);
|
---|
| 657 | continue;
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | /* Save the name. */
|
---|
| 661 | dp->name = strcache_add_len (buffer, o - buffer);
|
---|
| 662 | }
|
---|
| 663 | dp->stem = stem;
|
---|
| 664 | dp->staticpattern = 1;
|
---|
| 665 | dl = dp;
|
---|
| 666 | dp = dp->next;
|
---|
| 667 | }
|
---|
| 668 | }
|
---|
| 669 |
|
---|
| 670 | /* Enter them as files, unless they need a 2nd expansion. */
|
---|
| 671 | for (d1 = deps; d1 != 0; d1 = d1->next)
|
---|
| 672 | {
|
---|
| 673 | if (d1->need_2nd_expansion)
|
---|
| 674 | continue;
|
---|
| 675 |
|
---|
| 676 | d1->file = lookup_file (d1->name);
|
---|
| 677 | if (d1->file == 0)
|
---|
| 678 | d1->file = enter_file (d1->name);
|
---|
| 679 | d1->staticpattern = 0;
|
---|
| 680 | d1->name = 0;
|
---|
| 681 | }
|
---|
[53] | 682 |
|
---|
| 683 | return deps;
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | /* Set the intermediate flag. */
|
---|
| 687 |
|
---|
| 688 | static void
|
---|
| 689 | set_intermediate (const void *item)
|
---|
| 690 | {
|
---|
[287] | 691 | struct file *f = (struct file *) item;
|
---|
| 692 | f->intermediate = 1;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
[503] | 695 | /* Expand and parse each dependency line. */
|
---|
[2591] | 696 | static void
|
---|
[903] | 697 | expand_deps (struct file *f)
|
---|
[287] | 698 | {
|
---|
| 699 | struct dep *d;
|
---|
| 700 | struct dep **dp;
|
---|
| 701 | const char *file_stem = f->stem;
|
---|
[2591] | 702 | int initialized = 0;
|
---|
| 703 |
|
---|
| 704 | f->updating = 0;
|
---|
| 705 |
|
---|
| 706 | /* Walk through the dependencies. For any dependency that needs 2nd
|
---|
[287] | 707 | expansion, expand it then insert the result into the list. */
|
---|
[503] | 708 | dp = &f->deps;
|
---|
[2591] | 709 | d = f->deps;
|
---|
| 710 | while (d != 0)
|
---|
[503] | 711 | {
|
---|
[2591] | 712 | char *p;
|
---|
| 713 | struct dep *new, *next;
|
---|
| 714 | char *name = (char *)d->name;
|
---|
| 715 |
|
---|
| 716 | if (! d->name || ! d->need_2nd_expansion)
|
---|
| 717 | {
|
---|
| 718 | /* This one is all set already. */
|
---|
[503] | 719 | dp = &d->next;
|
---|
[1848] | 720 | d = d->next;
|
---|
[1850] | 721 | continue;
|
---|
[2634] | 722 | }
|
---|
[1849] | 723 |
|
---|
[1848] | 724 | #ifdef CONFIG_WITH_INCLUDEDEP
|
---|
| 725 | /* Dependencies loaded by includedep are ready for use and we skip
|
---|
[2634] | 726 | the expensive parsing and globbing for them. */
|
---|
| 727 |
|
---|
| 728 | if (d->includedep)
|
---|
| 729 | {
|
---|
| 730 | d->need_2nd_expansion = 0;
|
---|
[3620] | 731 | d->file = lookup_file (name);
|
---|
| 732 | if (d->file == 0)
|
---|
| 733 | d->file = enter_file (name);
|
---|
| 734 | d->name = 0;
|
---|
| 735 | # ifndef CONFIG_WITH_STRCACHE2
|
---|
[1850] | 736 | free (name);
|
---|
[2634] | 737 | # else
|
---|
| 738 | assert (strcache2_is_cached (&file_strcache, name));
|
---|
| 739 | # endif
|
---|
[1848] | 740 |
|
---|
[2591] | 741 | dp = &d->next;
|
---|
[1848] | 742 | d = d->next;
|
---|
[2591] | 743 | continue;
|
---|
| 744 | }
|
---|
| 745 | #endif /* CONFIG_WITH_INCLUDEDEP */
|
---|
[903] | 746 |
|
---|
[3140] | 747 | /* If it's from a static pattern rule, convert the patterns into
|
---|
[2591] | 748 | "$*" so they'll expand properly. */
|
---|
| 749 | if (d->staticpattern)
|
---|
[2634] | 750 | {
|
---|
[2591] | 751 | char *o = variable_expand ("");
|
---|
| 752 | o = subst_expand (o, name, "%", "$*", 1, 2, 0);
|
---|
[1847] | 753 | *o = '\0';
|
---|
[2591] | 754 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1847] | 755 | free (name);
|
---|
[2591] | 756 | d->name = name = xstrdup (variable_buffer); /* bird not d->name, can be reallocated */
|
---|
[903] | 757 | #else
|
---|
[2591] | 758 | d->name = strcache2_add (&file_strcache, variable_buffer, o - variable_buffer);
|
---|
| 759 | #endif
|
---|
| 760 | d->staticpattern = 0;
|
---|
| 761 | }
|
---|
| 762 |
|
---|
[287] | 763 | /* We're going to do second expansion so initialize file variables for
|
---|
[2591] | 764 | the file. Since the stem for static pattern rules comes from
|
---|
| 765 | individual dep lines, we will temporarily set f->stem to d->stem. */
|
---|
| 766 | if (!initialized)
|
---|
[287] | 767 | {
|
---|
[2591] | 768 | initialize_file_variables (f, 0);
|
---|
| 769 | initialized = 1;
|
---|
[287] | 770 | }
|
---|
[2024] | 771 |
|
---|
[2591] | 772 | if (d->stem != 0)
|
---|
[2024] | 773 | f->stem = d->stem;
|
---|
[2591] | 774 |
|
---|
[2024] | 775 | #if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)
|
---|
[287] | 776 | set_file_variables (f, 0 /* real call, f->deps == 0 so we're ok. */);
|
---|
[2591] | 777 | #else
|
---|
[287] | 778 | set_file_variables (f);
|
---|
[2591] | 779 | #endif
|
---|
| 780 |
|
---|
[287] | 781 | p = variable_expand_for_file (d->name, f);
|
---|
[2591] | 782 |
|
---|
| 783 | if (d->stem != 0)
|
---|
[287] | 784 | f->stem = file_stem;
|
---|
[2591] | 785 |
|
---|
| 786 | /* At this point we don't need the name anymore: free it. */
|
---|
[503] | 787 | free (name);
|
---|
[2591] | 788 |
|
---|
| 789 | /* Parse the prerequisites and enter them into the file database. */
|
---|
[503] | 790 | new = enter_prereqs (split_prereqs (p), d->stem);
|
---|
[2591] | 791 |
|
---|
| 792 | /* If there were no prereqs here (blank!) then throw this one out. */
|
---|
| 793 | if (new == 0)
|
---|
| 794 | {
|
---|
[503] | 795 | *dp = d->next;
|
---|
| 796 | free_dep (d);
|
---|
[2591] | 797 | d = *dp;
|
---|
| 798 | continue;
|
---|
[2634] | 799 | }
|
---|
| 800 |
|
---|
| 801 | /* Add newly parsed prerequisites. */
|
---|
| 802 | next = d->next;
|
---|
[2591] | 803 | #ifdef KMK /* bird: memory leak */
|
---|
| 804 | assert(new != d);
|
---|
| 805 | free_dep (d);
|
---|
| 806 | #endif
|
---|
| 807 | *dp = new;
|
---|
| 808 | for (dp = &new->next, d = new->next; d != 0; dp = &d->next, d = d->next)
|
---|
| 809 | ;
|
---|
[503] | 810 | *dp = next;
|
---|
[2591] | 811 | d = *dp;
|
---|
[503] | 812 | }
|
---|
[2591] | 813 | }
|
---|
| 814 |
|
---|
| 815 | /* Reset the updating flag. */
|
---|
| 816 |
|
---|
| 817 | static void
|
---|
[287] | 818 | reset_updating (const void *item)
|
---|
| 819 | {
|
---|
[3140] | 820 | struct file *f = (struct file *) item;
|
---|
| 821 | f->updating = 0;
|
---|
[53] | 822 | }
|
---|
| 823 |
|
---|
| 824 | /* For each dependency of each file, make the 'struct dep' point
|
---|
| 825 | at the appropriate 'struct file' (which may have to be created).
|
---|
| 826 |
|
---|
| 827 | Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
|
---|
| 828 | and various other special targets. */
|
---|
[287] | 829 |
|
---|
| 830 | void
|
---|
| 831 | snap_deps (void)
|
---|
[53] | 832 | {
|
---|
[2591] | 833 | struct file *f;
|
---|
| 834 | struct file *f2;
|
---|
| 835 | struct dep *d;
|
---|
[287] | 836 |
|
---|
[1701] | 837 | /* Remember that we've done this. Once we start snapping deps we can no
|
---|
| 838 | longer define new targets. */
|
---|
| 839 | snapped_deps = 1;
|
---|
| 840 |
|
---|
[1751] | 841 | #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
|
---|
| 842 | /* Perform 2nd target expansion on files which requires this. This will
|
---|
[2591] | 843 | be re-inserting (delete+insert) hash table entries so we have to use
|
---|
[1751] | 844 | hash_dump(). */
|
---|
| 845 | if (second_target_expansion)
|
---|
| 846 | {
|
---|
| 847 | struct file **file_slot_0, **file_end, **file_slot;
|
---|
[1701] | 848 | # ifdef KMK /* turn on warnings here. */
|
---|
[1751] | 849 | int save = warn_undefined_variables_flag;
|
---|
| 850 | warn_undefined_variables_flag = 1;
|
---|
| 851 | # endif
|
---|
| 852 |
|
---|
| 853 | file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
|
---|
| 854 | file_end = file_slot_0 + files.ht_fill;
|
---|
| 855 | for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
|
---|
| 856 | for (f = *file_slot; f != 0; f = f->prev)
|
---|
| 857 | if (f->need_2nd_target_expansion)
|
---|
| 858 | do_2nd_target_expansion (f);
|
---|
[1793] | 859 | free (file_slot_0);
|
---|
| 860 |
|
---|
[1751] | 861 | # ifdef KMK
|
---|
[1797] | 862 | warn_undefined_variables_flag = save;
|
---|
[1751] | 863 | # endif
|
---|
| 864 |
|
---|
[1701] | 865 | /* Disable second target expansion now since we won't expand files
|
---|
| 866 | entered after this point. (Saves CPU cycles in enter_file()). */
|
---|
[1797] | 867 | second_target_expansion = 0;
|
---|
| 868 | }
|
---|
| 869 | #endif /* CONFIG_WITH_2ND_TARGET_EXPANSION */
|
---|
| 870 |
|
---|
| 871 | #ifdef CONFIG_WITH_INCLUDEDEP
|
---|
[1980] | 872 | /* Process any queued includedep files. Since includedep is supposed
|
---|
[1797] | 873 | to be *simple* stuff, we can do this after the second target expansion
|
---|
[2591] | 874 | and thereby save a little time. */
|
---|
| 875 | incdep_flush_and_term ();
|
---|
| 876 | #endif /* CONFIG_WITH_INCLUDEDEP */
|
---|
| 877 |
|
---|
| 878 | /* Perform second expansion and enter each dependency name as a file. We
|
---|
| 879 | must use hash_dump() here because within these loops we likely add new
|
---|
| 880 | files to the table, possibly causing an in-situ table expansion.
|
---|
| 881 |
|
---|
| 882 | We only need to do this if second_expansion has been defined; if it
|
---|
| 883 | hasn't then all deps were expanded as the makefile was read in. If we
|
---|
| 884 | ever change make to be able to unset .SECONDARY_EXPANSION this will have
|
---|
| 885 | to change. */
|
---|
| 886 |
|
---|
| 887 | if (second_expansion)
|
---|
| 888 | {
|
---|
| 889 | struct file **file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
|
---|
| 890 | struct file **file_end = file_slot_0 + files.ht_fill;
|
---|
| 891 | struct file **file_slot;
|
---|
| 892 | const char *suffixes;
|
---|
| 893 |
|
---|
[903] | 894 | /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */
|
---|
[2591] | 895 | f = lookup_file (".SUFFIXES");
|
---|
[3309] | 896 | suffixes = f ? f->name : 0;
|
---|
[2591] | 897 | for (; f != 0; f = f->prev)
|
---|
| 898 | expand_deps (f);
|
---|
| 899 |
|
---|
| 900 | #if 0 /* def KMK - not-parallel is a performance kill, but since double-colon is werid anyway, skip this hack. */
|
---|
| 901 | /* This is a HACK to work around the still broken test #9 in
|
---|
[1950] | 902 | features/double_colon. It produces the wrong result if the build is
|
---|
[2591] | 903 | parallel because of changed evaluation order. Just make these
|
---|
| 904 | problematic rules execute in single field till a proper fix is
|
---|
| 905 | forthcomming... */
|
---|
| 906 |
|
---|
| 907 | for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
|
---|
| 908 | if ( (f = *file_slot) != 0
|
---|
| 909 | && f->double_colon
|
---|
[1980] | 910 | && ( f->double_colon != f
|
---|
[53] | 911 | || f->last != f))
|
---|
[2591] | 912 | for (f2 = f->double_colon; f2 != 0; f2 = f2->prev)
|
---|
| 913 | f2->command_flags |= COMMANDS_NOTPARALLEL;
|
---|
| 914 | #endif /* KMK */
|
---|
| 915 |
|
---|
| 916 | /* For every target that's not .SUFFIXES, expand its prerequisites. */
|
---|
| 917 |
|
---|
| 918 | for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
|
---|
| 919 | for (f = *file_slot; f != 0; f = f->prev)
|
---|
| 920 | if (f->name != suffixes)
|
---|
| 921 | expand_deps (f);
|
---|
| 922 | free (file_slot_0);
|
---|
| 923 | }
|
---|
[903] | 924 | else
|
---|
| 925 | /* We're not doing second expansion, so reset updating. */
|
---|
[53] | 926 | hash_map (&files, reset_updating);
|
---|
| 927 |
|
---|
| 928 | /* Now manage all the special targets. */
|
---|
[3140] | 929 |
|
---|
[53] | 930 | for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
|
---|
| 931 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 932 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
| 933 | f2->precious = 1;
|
---|
[3140] | 934 |
|
---|
[53] | 935 | for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
|
---|
| 936 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 937 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
| 938 | f2->low_resolution_time = 1;
|
---|
[3140] | 939 |
|
---|
| 940 | for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
|
---|
| 941 | for (d = f->deps; d != 0; d = d->next)
|
---|
[287] | 942 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
[3140] | 943 | {
|
---|
| 944 | /* Mark this file as phony nonexistent target. */
|
---|
| 945 | f2->phony = 1;
|
---|
[53] | 946 | f2->is_target = 1;
|
---|
| 947 | f2->last_mtime = NONEXISTENT_MTIME;
|
---|
[903] | 948 | f2->mtime_before_update = NONEXISTENT_MTIME;
|
---|
| 949 | }
|
---|
| 950 |
|
---|
| 951 | for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
|
---|
| 952 | /* Mark .INTERMEDIATE deps as intermediate files. */
|
---|
| 953 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 954 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
[53] | 955 | f2->intermediate = 1;
|
---|
| 956 | /* .INTERMEDIATE with no deps does nothing.
|
---|
[903] | 957 | Marking all files as intermediates is useless since the goal targets
|
---|
| 958 | would be deleted after they are built. */
|
---|
| 959 |
|
---|
| 960 | for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
|
---|
| 961 | /* Mark .SECONDARY deps as both intermediate and secondary. */
|
---|
| 962 | if (f->deps)
|
---|
| 963 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 964 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
| 965 | f2->intermediate = f2->secondary = 1;
|
---|
| 966 | /* .SECONDARY with no deps listed marks *all* files that way. */
|
---|
| 967 | else
|
---|
[53] | 968 | {
|
---|
| 969 | all_secondary = 1;
|
---|
| 970 | hash_map (&files, set_intermediate);
|
---|
| 971 | }
|
---|
| 972 |
|
---|
| 973 | f = lookup_file (".EXPORT_ALL_VARIABLES");
|
---|
| 974 | if (f != 0 && f->is_target)
|
---|
| 975 | export_all_variables = 1;
|
---|
| 976 |
|
---|
[3140] | 977 | f = lookup_file (".IGNORE");
|
---|
[53] | 978 | if (f != 0 && f->is_target)
|
---|
[3140] | 979 | {
|
---|
| 980 | if (f->deps == 0)
|
---|
| 981 | ignore_errors_flag = 1;
|
---|
[53] | 982 | else
|
---|
| 983 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 984 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
| 985 | f2->command_flags |= COMMANDS_NOERROR;
|
---|
| 986 | }
|
---|
| 987 |
|
---|
[3140] | 988 | f = lookup_file (".SILENT");
|
---|
[53] | 989 | if (f != 0 && f->is_target)
|
---|
[3140] | 990 | {
|
---|
| 991 | if (f->deps == 0)
|
---|
| 992 | silent_flag = 1;
|
---|
[53] | 993 | else
|
---|
| 994 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 995 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
| 996 | f2->command_flags |= COMMANDS_SILENT;
|
---|
[520] | 997 | }
|
---|
| 998 |
|
---|
| 999 | f = lookup_file (".NOTPARALLEL");
|
---|
[217] | 1000 | if (f != 0 && f->is_target)
|
---|
| 1001 | #ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
|
---|
[218] | 1002 | not_parallel = 1;
|
---|
| 1003 | #else /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
|
---|
| 1004 | {
|
---|
| 1005 | if (f->deps == 0)
|
---|
[217] | 1006 | {
|
---|
| 1007 | DB (DB_KMK, (_("not_parallel -1\n")));
|
---|
| 1008 | not_parallel = -1;
|
---|
| 1009 | }
|
---|
| 1010 | else
|
---|
[520] | 1011 | for (d = f->deps; d != 0; d = d->next)
|
---|
[217] | 1012 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
[503] | 1013 | f2->command_flags |= COMMANDS_NOTPARALLEL;
|
---|
| 1014 | }
|
---|
| 1015 | #endif /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
|
---|
| 1016 |
|
---|
[2591] | 1017 | #ifndef NO_MINUS_C_MINUS_O
|
---|
[503] | 1018 | /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
|
---|
| 1019 | /* This needs more work: what if the user sets this in the makefile?
|
---|
[53] | 1020 | if (posix_pedantic)
|
---|
| 1021 | define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
|
---|
[3140] | 1022 | */
|
---|
[53] | 1023 | #endif
|
---|
| 1024 | }
|
---|
[153] | 1025 | |
---|
[53] | 1026 |
|
---|
| 1027 | /* Set the 'command_state' member of FILE and all its 'also_make's. */
|
---|
| 1028 |
|
---|
| 1029 | void
|
---|
| 1030 | set_command_state (struct file *file, enum cmd_state state)
|
---|
| 1031 | {
|
---|
| 1032 | struct dep *d;
|
---|
[921] | 1033 |
|
---|
| 1034 | file->command_state = state;
|
---|
| 1035 |
|
---|
[934] | 1036 | for (d = file->also_make; d != 0; d = d->next)
|
---|
| 1037 | d->file->command_state = state;
|
---|
[921] | 1038 |
|
---|
[53] | 1039 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
| 1040 | if (file->multi_head)
|
---|
| 1041 | for (file = file->multi_head; file != 0; file = file->multi_next)
|
---|
| 1042 | file->command_state = state;
|
---|
| 1043 | #endif
|
---|
[3140] | 1044 | }
|
---|
[53] | 1045 | |
---|
| 1046 |
|
---|
[3140] | 1047 | /* Convert an external file timestamp to internal form. */
|
---|
[53] | 1048 |
|
---|
| 1049 | FILE_TIMESTAMP
|
---|
| 1050 | file_timestamp_cons (const char *fname, time_t stamp, long int ns)
|
---|
| 1051 | {
|
---|
[3140] | 1052 | int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
|
---|
[53] | 1053 | FILE_TIMESTAMP s = stamp;
|
---|
| 1054 | FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
|
---|
[3140] | 1055 | FILE_TIMESTAMP ts = product + offset;
|
---|
[53] | 1056 |
|
---|
| 1057 | if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
|
---|
[3140] | 1058 | && product <= ts && ts <= ORDINARY_MTIME_MAX))
|
---|
| 1059 | {
|
---|
[53] | 1060 | char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
|
---|
| 1061 | const char *f = fname ? fname : _("Current time");
|
---|
| 1062 | ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
|
---|
| 1063 | file_timestamp_sprintf (buf, ts);
|
---|
| 1064 | OSS (error, NILF,
|
---|
| 1065 | _("%s: Timestamp out of range; substituting %s"), f, buf);
|
---|
| 1066 | }
|
---|
| 1067 |
|
---|
| 1068 | return ts;
|
---|
| 1069 | }
|
---|
| 1070 | |
---|
| 1071 |
|
---|
| 1072 | /* Return the current time as a file timestamp, setting *RESOLUTION to
|
---|
| 1073 | its resolution. */
|
---|
| 1074 | FILE_TIMESTAMP
|
---|
| 1075 | file_timestamp_now (int *resolution)
|
---|
| 1076 | {
|
---|
| 1077 | int r;
|
---|
| 1078 | time_t s;
|
---|
| 1079 | int ns;
|
---|
| 1080 |
|
---|
| 1081 | /* Don't bother with high-resolution clocks if file timestamps have
|
---|
| 1082 | only one-second resolution. The code below should work, but it's
|
---|
[3140] | 1083 | not worth the hassle of debugging it on hosts where it fails. */
|
---|
| 1084 | #if FILE_TIMESTAMP_HI_RES
|
---|
| 1085 | # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
|
---|
| 1086 | {
|
---|
[53] | 1087 | struct timespec timespec;
|
---|
| 1088 | if (clock_gettime (CLOCK_REALTIME, ×pec) == 0)
|
---|
| 1089 | {
|
---|
| 1090 | r = 1;
|
---|
| 1091 | s = timespec.tv_sec;
|
---|
| 1092 | ns = timespec.tv_nsec;
|
---|
| 1093 | goto got_time;
|
---|
| 1094 | }
|
---|
[3140] | 1095 | }
|
---|
| 1096 | # endif
|
---|
| 1097 | # if HAVE_GETTIMEOFDAY
|
---|
| 1098 | {
|
---|
[53] | 1099 | struct timeval timeval;
|
---|
| 1100 | if (gettimeofday (&timeval, 0) == 0)
|
---|
| 1101 | {
|
---|
| 1102 | r = 1000;
|
---|
| 1103 | s = timeval.tv_sec;
|
---|
| 1104 | ns = timeval.tv_usec * 1000;
|
---|
| 1105 | goto got_time;
|
---|
| 1106 | }
|
---|
| 1107 | }
|
---|
| 1108 | # endif
|
---|
| 1109 | #endif
|
---|
| 1110 |
|
---|
| 1111 | r = 1000000000;
|
---|
| 1112 | s = time ((time_t *) 0);
|
---|
| 1113 | ns = 0;
|
---|
| 1114 |
|
---|
| 1115 | #if FILE_TIMESTAMP_HI_RES
|
---|
| 1116 | got_time:
|
---|
| 1117 | #endif
|
---|
| 1118 | *resolution = r;
|
---|
| 1119 | return file_timestamp_cons (0, s, ns);
|
---|
| 1120 | }
|
---|
| 1121 |
|
---|
| 1122 | /* Place into the buffer P a printable representation of the file
|
---|
| 1123 | timestamp TS. */
|
---|
| 1124 | void
|
---|
[3140] | 1125 | file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
|
---|
| 1126 | {
|
---|
[53] | 1127 | time_t t = FILE_TIMESTAMP_S (ts);
|
---|
| 1128 | struct tm *tm = localtime (&t);
|
---|
| 1129 |
|
---|
| 1130 | if (tm)
|
---|
| 1131 | sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
|
---|
| 1132 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
---|
[903] | 1133 | tm->tm_hour, tm->tm_min, tm->tm_sec);
|
---|
| 1134 | else if (t < 0)
|
---|
| 1135 | sprintf (p, "%ld", (long) t);
|
---|
| 1136 | else
|
---|
[53] | 1137 | sprintf (p, "%lu", (unsigned long) t);
|
---|
| 1138 | p += strlen (p);
|
---|
| 1139 |
|
---|
| 1140 | /* Append nanoseconds as a fraction, but remove trailing zeros. We don't
|
---|
| 1141 | know the actual timestamp resolution, since clock_getres applies only to
|
---|
| 1142 | local times, whereas this timestamp might come from a remote filesystem.
|
---|
| 1143 | So removing trailing zeros is the best guess that we can do. */
|
---|
| 1144 | sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
|
---|
| 1145 | p += strlen (p) - 1;
|
---|
| 1146 | while (*p == '0')
|
---|
| 1147 | p--;
|
---|
[2591] | 1148 | p += *p != '.';
|
---|
| 1149 |
|
---|
| 1150 | *p = '\0';
|
---|
| 1151 | }
|
---|
| 1152 | |
---|
| 1153 |
|
---|
| 1154 | /* Print the data base of files. */
|
---|
| 1155 |
|
---|
| 1156 | void
|
---|
| 1157 | print_prereqs (const struct dep *deps)
|
---|
| 1158 | {
|
---|
| 1159 | const struct dep *ood = 0;
|
---|
| 1160 |
|
---|
| 1161 | /* Print all normal dependencies; note any order-only deps. */
|
---|
| 1162 | for (; deps != 0; deps = deps->next)
|
---|
| 1163 | if (! deps->ignore_mtime)
|
---|
| 1164 | printf (" %s", dep_name (deps));
|
---|
| 1165 | else if (! ood)
|
---|
| 1166 | ood = deps;
|
---|
| 1167 |
|
---|
| 1168 | /* Print order-only deps, if we have any. */
|
---|
| 1169 | if (ood)
|
---|
| 1170 | {
|
---|
| 1171 | printf (" | %s", dep_name (ood));
|
---|
[53] | 1172 | for (ood = ood->next; ood != 0; ood = ood->next)
|
---|
| 1173 | if (ood->ignore_mtime)
|
---|
| 1174 | printf (" %s", dep_name (ood));
|
---|
[903] | 1175 | }
|
---|
[53] | 1176 |
|
---|
[3140] | 1177 | putchar ('\n');
|
---|
| 1178 | }
|
---|
| 1179 |
|
---|
| 1180 | static void
|
---|
| 1181 | print_file (const void *item)
|
---|
| 1182 | {
|
---|
| 1183 | const struct file *f = item;
|
---|
[53] | 1184 |
|
---|
[3140] | 1185 | /* If we're not using builtin targets, don't show them.
|
---|
| 1186 |
|
---|
| 1187 | Ideally we'd be able to delete them altogether but currently there's no
|
---|
| 1188 | facility to ever delete a file once it's been added. */
|
---|
| 1189 | if (no_builtin_rules_flag && f->builtin)
|
---|
| 1190 | return;
|
---|
| 1191 |
|
---|
| 1192 | putchar ('\n');
|
---|
| 1193 |
|
---|
| 1194 | if (f->cmds && f->cmds->recipe_prefix != cmd_prefix)
|
---|
| 1195 | {
|
---|
| 1196 | fputs (".RECIPEPREFIX = ", stdout);
|
---|
| 1197 | cmd_prefix = f->cmds->recipe_prefix;
|
---|
[53] | 1198 | if (cmd_prefix != RECIPEPREFIX_DEFAULT)
|
---|
| 1199 | putchar (cmd_prefix);
|
---|
[921] | 1200 | putchar ('\n');
|
---|
| 1201 | }
|
---|
| 1202 |
|
---|
| 1203 | if (f->variables != 0)
|
---|
| 1204 | print_target_variables (f);
|
---|
| 1205 |
|
---|
| 1206 | if (!f->is_target)
|
---|
| 1207 | puts (_("# Not a target:"));
|
---|
| 1208 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
[53] | 1209 | if (f->multi_head)
|
---|
[921] | 1210 | {
|
---|
| 1211 | const struct file *f2;
|
---|
| 1212 | if (f->multi_head == f)
|
---|
| 1213 | {
|
---|
| 1214 | int multi_maybe = -1;
|
---|
| 1215 | assert (!f->multi_maybe);
|
---|
| 1216 | assert (!f->double_colon);
|
---|
| 1217 |
|
---|
[2665] | 1218 | printf ("%s", f->name);
|
---|
| 1219 | for (f2 = f->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
| 1220 | {
|
---|
| 1221 | printf (" %s%s", f2->multi_maybe != multi_maybe
|
---|
[921] | 1222 | ? f2->multi_maybe ? "+| " : "+ " : "",
|
---|
| 1223 | f2->name);
|
---|
| 1224 | multi_maybe = f2->multi_maybe;
|
---|
| 1225 | }
|
---|
| 1226 | if (f->deps)
|
---|
| 1227 | printf (": \\\n\t");
|
---|
| 1228 | else
|
---|
| 1229 | putchar (':');
|
---|
[2591] | 1230 | }
|
---|
[53] | 1231 | else
|
---|
[921] | 1232 | printf ("%s:%s", f->name, f->double_colon ? ":" : "");
|
---|
| 1233 | }
|
---|
| 1234 | else
|
---|
| 1235 | #endif
|
---|
| 1236 | printf ("%s:%s", f->name, f->double_colon ? ":" : "");
|
---|
| 1237 |
|
---|
| 1238 | print_prereqs (f->deps);
|
---|
| 1239 |
|
---|
| 1240 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
| 1241 | if (f->multi_head && f->multi_head != f)
|
---|
| 1242 | {
|
---|
| 1243 | const struct file *f2;
|
---|
| 1244 | fputs (_("# In multi target list:"), stdout);
|
---|
[53] | 1245 | for (f2 = f->multi_head; f2 != 0; f2 = f2->multi_next)
|
---|
| 1246 | printf (" %s%s", f2->name, f == f2 ? "(*)" : "");
|
---|
| 1247 | putchar ('\n');
|
---|
| 1248 | if (f->multi_maybe)
|
---|
| 1249 | puts (_("# File is an optional multi target member."));
|
---|
[1993] | 1250 | }
|
---|
[53] | 1251 | #endif
|
---|
[287] | 1252 |
|
---|
[2788] | 1253 | if (f->precious)
|
---|
| 1254 | puts (_("# Precious file (prerequisite of .PRECIOUS)."));
|
---|
| 1255 | if (f->phony)
|
---|
| 1256 | puts (_("# Phony target (prerequisite of .PHONY)."));
|
---|
| 1257 | if (f->cmd_target)
|
---|
| 1258 | puts (_("# Command line target."));
|
---|
| 1259 | if (f->dontcare)
|
---|
| 1260 | puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
|
---|
| 1261 | #if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
|
---|
| 1262 | if (f->eval_count > 0)
|
---|
| 1263 | {
|
---|
[3140] | 1264 | # ifdef CONFIG_WITH_COMPILER
|
---|
| 1265 | if (f->evalprog)
|
---|
[53] | 1266 | printf (_("# Makefile evaluated %u times - compiled\n"), f->eval_count);
|
---|
| 1267 | else
|
---|
| 1268 | # endif
|
---|
| 1269 | printf (_("# Makefile evaluated %u times\n"), f->eval_count);
|
---|
[3140] | 1270 | }
|
---|
[53] | 1271 | #endif
|
---|
| 1272 | if (f->builtin)
|
---|
| 1273 | puts (_("# Builtin rule"));
|
---|
| 1274 | puts (f->tried_implicit
|
---|
[2591] | 1275 | ? _("# Implicit rule search has been done.")
|
---|
[53] | 1276 | : _("# Implicit rule search has not been done."));
|
---|
| 1277 | if (f->stem != 0)
|
---|
[3140] | 1278 | printf (_("# Implicit/static pattern stem: '%s'\n"), f->stem);
|
---|
[53] | 1279 | if (f->intermediate)
|
---|
| 1280 | puts (_("# File is an intermediate prerequisite."));
|
---|
| 1281 | if (f->also_make != 0)
|
---|
| 1282 | {
|
---|
| 1283 | const struct dep *d;
|
---|
| 1284 | fputs (_("# Also makes:"), stdout);
|
---|
| 1285 | for (d = f->also_make; d != 0; d = d->next)
|
---|
| 1286 | printf (" %s", dep_name (d));
|
---|
| 1287 | putchar ('\n');
|
---|
| 1288 | }
|
---|
| 1289 | if (f->last_mtime == UNKNOWN_MTIME)
|
---|
| 1290 | puts (_("# Modification time never checked."));
|
---|
| 1291 | else if (f->last_mtime == NONEXISTENT_MTIME)
|
---|
| 1292 | puts (_("# File does not exist."));
|
---|
| 1293 | else if (f->last_mtime == OLD_MTIME)
|
---|
| 1294 | puts (_("# File is very old."));
|
---|
| 1295 | else
|
---|
| 1296 | {
|
---|
| 1297 | char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
|
---|
[1993] | 1298 | file_timestamp_sprintf (buf, f->last_mtime);
|
---|
[53] | 1299 | printf (_("# Last modified %s\n"), buf);
|
---|
| 1300 | }
|
---|
[1993] | 1301 | puts (f->updated
|
---|
[53] | 1302 | ? _("# File has been updated.") : _("# File has not been updated."));
|
---|
| 1303 | switch (f->command_state)
|
---|
| 1304 | {
|
---|
| 1305 | case cs_running:
|
---|
[3140] | 1306 | puts (_("# Recipe currently running (THIS IS A BUG)."));
|
---|
| 1307 | break;
|
---|
| 1308 | case cs_deps_running:
|
---|
| 1309 | puts (_("# Dependencies recipe running (THIS IS A BUG)."));
|
---|
| 1310 | break;
|
---|
| 1311 | case cs_not_started:
|
---|
| 1312 | case cs_finished:
|
---|
| 1313 | switch (f->update_status)
|
---|
| 1314 | {
|
---|
| 1315 | case us_none:
|
---|
| 1316 | break;
|
---|
| 1317 | case us_success:
|
---|
| 1318 | puts (_("# Successfully updated."));
|
---|
| 1319 | break;
|
---|
[53] | 1320 | case us_question:
|
---|
| 1321 | assert (question_flag);
|
---|
[3140] | 1322 | puts (_("# Needs to be updated (-q is set)."));
|
---|
[53] | 1323 | break;
|
---|
| 1324 | case us_failed:
|
---|
| 1325 | puts (_("# Failed to be updated."));
|
---|
| 1326 | break;
|
---|
| 1327 | }
|
---|
| 1328 | break;
|
---|
| 1329 | default:
|
---|
| 1330 | puts (_("# Invalid value in 'command_state' member!"));
|
---|
| 1331 | fflush (stdout);
|
---|
| 1332 | fflush (stderr);
|
---|
[153] | 1333 | abort ();
|
---|
| 1334 | }
|
---|
| 1335 |
|
---|
[53] | 1336 | if (f->variables != 0)
|
---|
| 1337 | print_file_variables (f);
|
---|
| 1338 |
|
---|
| 1339 | if (f->cmds != 0)
|
---|
| 1340 | print_commands (f->cmds);
|
---|
| 1341 |
|
---|
| 1342 | if (f->prev)
|
---|
| 1343 | print_file ((const void *) f->prev);
|
---|
| 1344 | }
|
---|
| 1345 |
|
---|
| 1346 | void
|
---|
| 1347 | print_file_data_base (void)
|
---|
[1918] | 1348 | {
|
---|
| 1349 | puts (_("\n# Files"));
|
---|
| 1350 |
|
---|
| 1351 | hash_map (&files, print_file);
|
---|
| 1352 |
|
---|
| 1353 | fputs (_("\n# files hash-table stats:\n# "), stdout);
|
---|
| 1354 | hash_print_stats (&files, stdout);
|
---|
| 1355 | }
|
---|
| 1356 |
|
---|
| 1357 | #ifdef CONFIG_WITH_PRINT_STATS_SWITCH
|
---|
[903] | 1358 | void
|
---|
| 1359 | print_file_stats (void)
|
---|
[53] | 1360 | {
|
---|
[903] | 1361 | fputs (_("\n# files hash-table stats:\n# "), stdout);
|
---|
[3140] | 1362 | hash_print_stats (&files, stdout);
|
---|
| 1363 | fputs ("\n", stdout);
|
---|
| 1364 | }
|
---|
| 1365 | #endif
|
---|
[903] | 1366 | |
---|
| 1367 |
|
---|
| 1368 | /* Verify the integrity of the data base of files. */
|
---|
| 1369 |
|
---|
| 1370 | #define VERIFY_CACHED(_p,_n) \
|
---|
| 1371 | do{ \
|
---|
| 1372 | if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
|
---|
| 1373 | error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n), \
|
---|
| 1374 | _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \
|
---|
| 1375 | }while(0)
|
---|
| 1376 |
|
---|
| 1377 | static void
|
---|
| 1378 | verify_file (const void *item)
|
---|
| 1379 | {
|
---|
| 1380 | const struct file *f = item;
|
---|
| 1381 | const struct dep *d;
|
---|
[2591] | 1382 |
|
---|
| 1383 | VERIFY_CACHED (f, name);
|
---|
[903] | 1384 | VERIFY_CACHED (f, hname);
|
---|
| 1385 | VERIFY_CACHED (f, vpath);
|
---|
| 1386 | VERIFY_CACHED (f, stem);
|
---|
| 1387 |
|
---|
| 1388 | /* Check the deps. */
|
---|
| 1389 | for (d = f->deps; d != 0; d = d->next)
|
---|
| 1390 | {
|
---|
| 1391 | if (! d->need_2nd_expansion)
|
---|
| 1392 | VERIFY_CACHED (d, name);
|
---|
| 1393 | VERIFY_CACHED (d, stem);
|
---|
[53] | 1394 | }
|
---|
| 1395 | }
|
---|
| 1396 |
|
---|
| 1397 | void
|
---|
| 1398 | verify_file_data_base (void)
|
---|
| 1399 | {
|
---|
| 1400 | hash_map (&files, verify_file);
|
---|
| 1401 | }
|
---|
| 1402 |
|
---|
| 1403 | #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
|
---|
| 1404 |
|
---|
| 1405 | char *
|
---|
| 1406 | build_target_list (char *value)
|
---|
| 1407 | {
|
---|
| 1408 | static unsigned long last_targ_count = 0;
|
---|
| 1409 |
|
---|
| 1410 | if (files.ht_fill != last_targ_count)
|
---|
| 1411 | {
|
---|
| 1412 | unsigned long max = EXPANSION_INCREMENT (strlen (value));
|
---|
| 1413 | unsigned long len;
|
---|
| 1414 | char *p;
|
---|
| 1415 | struct file **fp = (struct file **) files.ht_vec;
|
---|
| 1416 | struct file **end = &fp[files.ht_size];
|
---|
| 1417 |
|
---|
| 1418 | /* Make sure we have at least MAX bytes in the allocated buffer. */
|
---|
| 1419 | value = xrealloc (value, max);
|
---|
| 1420 |
|
---|
| 1421 | p = value;
|
---|
| 1422 | len = 0;
|
---|
| 1423 | for (; fp < end; ++fp)
|
---|
| 1424 | if (!HASH_VACANT (*fp) && (*fp)->is_target)
|
---|
| 1425 | {
|
---|
| 1426 | struct file *f = *fp;
|
---|
| 1427 | int l = strlen (f->name);
|
---|
| 1428 |
|
---|
| 1429 | len += l + 1;
|
---|
[903] | 1430 | if (len > max)
|
---|
[53] | 1431 | {
|
---|
| 1432 | unsigned long off = p - value;
|
---|
| 1433 |
|
---|
| 1434 | max += EXPANSION_INCREMENT (l + 1);
|
---|
| 1435 | value = xrealloc (value, max);
|
---|
| 1436 | p = &value[off];
|
---|
| 1437 | }
|
---|
| 1438 |
|
---|
| 1439 | memcpy (p, f->name, l);
|
---|
| 1440 | p += l;
|
---|
| 1441 | *(p++) = ' ';
|
---|
| 1442 | }
|
---|
| 1443 | *(p-1) = '\0';
|
---|
| 1444 |
|
---|
[1902] | 1445 | last_targ_count = files.ht_fill;
|
---|
| 1446 | }
|
---|
[1793] | 1447 |
|
---|
[1902] | 1448 | return value;
|
---|
| 1449 | }
|
---|
| 1450 |
|
---|
[1980] | 1451 | void
|
---|
[1902] | 1452 | init_hash_files (void)
|
---|
| 1453 | {
|
---|
| 1454 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 1455 | # ifdef KMK
|
---|
| 1456 | hash_init (&files, /*65535*/ 32755, file_hash_1, file_hash_2, file_hash_cmp);
|
---|
| 1457 | # else
|
---|
| 1458 | hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
|
---|
[1980] | 1459 | # endif
|
---|
[53] | 1460 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1461 | # ifdef KMK
|
---|
| 1462 | hash_init_strcached (&files, 32755, &file_strcache,
|
---|
| 1463 | offsetof (struct file, hname));
|
---|
| 1464 | # else
|
---|
| 1465 | hash_init_strcached (&files, 1000, &file_strcache,
|
---|
| 1466 | offsetof (struct file, hname));
|
---|
| 1467 | # endif
|
---|
| 1468 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1469 | }
|
---|
| 1470 |
|
---|
| 1471 | /* EOF */
|
---|