[53] | 1 | /* Pattern and suffix rule internals 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"
|
---|
[903] | 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 "rule.h"
|
---|
| 27 |
|
---|
[903] | 28 | static void freerule (struct rule *rule, struct rule *lastrule);
|
---|
[53] | 29 | |
---|
| 30 |
|
---|
| 31 | /* Chain of all pattern rules. */
|
---|
| 32 |
|
---|
| 33 | struct rule *pattern_rules;
|
---|
| 34 |
|
---|
| 35 | /* Pointer to last rule in the chain, so we can add onto the end. */
|
---|
| 36 |
|
---|
| 37 | struct rule *last_pattern_rule;
|
---|
| 38 |
|
---|
| 39 | /* Number of rules in the chain. */
|
---|
| 40 |
|
---|
| 41 | unsigned int num_pattern_rules;
|
---|
| 42 |
|
---|
| 43 | /* Maximum number of target patterns of any pattern rule. */
|
---|
| 44 |
|
---|
| 45 | unsigned int max_pattern_targets;
|
---|
| 46 |
|
---|
| 47 | /* Maximum number of dependencies of any pattern rule. */
|
---|
| 48 |
|
---|
| 49 | unsigned int max_pattern_deps;
|
---|
| 50 |
|
---|
| 51 | /* Maximum length of the name of a dependencies of any pattern rule. */
|
---|
| 52 |
|
---|
| 53 | unsigned int max_pattern_dep_length;
|
---|
| 54 |
|
---|
| 55 | /* Pointer to structure for the file .SUFFIXES
|
---|
| 56 | whose dependencies are the suffixes to be searched. */
|
---|
| 57 |
|
---|
| 58 | struct file *suffix_file;
|
---|
| 59 |
|
---|
| 60 | /* Maximum length of a suffix. */
|
---|
| 61 |
|
---|
| 62 | unsigned int maxsuffix;
|
---|
| 63 | |
---|
| 64 |
|
---|
| 65 | /* Compute the maximum dependency length and maximum number of
|
---|
| 66 | dependencies of all implicit rules. Also sets the subdir
|
---|
| 67 | flag for a rule when appropriate, possibly removing the rule
|
---|
| 68 | completely when appropriate. */
|
---|
| 69 |
|
---|
| 70 | void
|
---|
| 71 | count_implicit_rule_limits (void)
|
---|
[153] | 72 | {
|
---|
[3140] | 73 | char *name;
|
---|
[53] | 74 | int namelen;
|
---|
| 75 | struct rule *rule;
|
---|
| 76 |
|
---|
| 77 | num_pattern_rules = max_pattern_targets = max_pattern_deps = 0;
|
---|
| 78 | max_pattern_dep_length = 0;
|
---|
| 79 |
|
---|
| 80 | name = 0;
|
---|
| 81 | namelen = 0;
|
---|
| 82 | rule = pattern_rules;
|
---|
| 83 | while (rule != 0)
|
---|
[903] | 84 | {
|
---|
[53] | 85 | unsigned int ndeps = 0;
|
---|
| 86 | struct dep *dep;
|
---|
| 87 | struct rule *next = rule->next;
|
---|
| 88 |
|
---|
[903] | 89 | ++num_pattern_rules;
|
---|
[3140] | 90 |
|
---|
[53] | 91 | if (rule->num > max_pattern_targets)
|
---|
| 92 | max_pattern_targets = rule->num;
|
---|
[3140] | 93 |
|
---|
[2591] | 94 | for (dep = rule->deps; dep != 0; dep = dep->next)
|
---|
| 95 | {
|
---|
[53] | 96 | const char *dname = dep_name (dep);
|
---|
| 97 | unsigned int len = strlen (dname);
|
---|
[2591] | 98 |
|
---|
[903] | 99 | #ifdef VMS
|
---|
[53] | 100 | const char *p = strrchr (dname, ']');
|
---|
[2591] | 101 | const char *p2;
|
---|
| 102 | if (p == 0)
|
---|
[53] | 103 | p = strrchr (dname, ':');
|
---|
[2591] | 104 | p2 = p != 0 ? strchr (dname, '%') : 0;
|
---|
| 105 | #else
|
---|
[53] | 106 | const char *p = strrchr (dname, '/');
|
---|
[2591] | 107 | const char *p2 = p != 0 ? strchr (dname, '%') : 0;
|
---|
[53] | 108 | #endif
|
---|
[3140] | 109 | ndeps++;
|
---|
| 110 |
|
---|
[53] | 111 | if (len > max_pattern_dep_length)
|
---|
[3140] | 112 | max_pattern_dep_length = len;
|
---|
| 113 |
|
---|
| 114 | if (p != 0 && p2 > p)
|
---|
| 115 | {
|
---|
| 116 | /* There is a slash before the % in the dep name.
|
---|
| 117 | Extract the directory name. */
|
---|
| 118 | if (p == dname)
|
---|
| 119 | ++p;
|
---|
| 120 | if (p - dname > namelen)
|
---|
| 121 | {
|
---|
| 122 | namelen = p - dname;
|
---|
| 123 | name = xrealloc (name, namelen + 1);
|
---|
| 124 | }
|
---|
[53] | 125 | memcpy (name, dname, p - dname);
|
---|
[3140] | 126 | name[p - dname] = '\0';
|
---|
| 127 |
|
---|
| 128 | /* In the deps of an implicit rule the 'changed' flag
|
---|
[53] | 129 | actually indicates that the dependency is in a
|
---|
[3140] | 130 | nonexistent subdirectory. */
|
---|
| 131 |
|
---|
| 132 | dep->changed = !dir_file_exists_p (name, "");
|
---|
| 133 | }
|
---|
| 134 | else
|
---|
| 135 | /* This dependency does not reside in a subdirectory. */
|
---|
[53] | 136 | dep->changed = 0;
|
---|
| 137 | }
|
---|
[3140] | 138 |
|
---|
[53] | 139 | if (ndeps > max_pattern_deps)
|
---|
| 140 | max_pattern_deps = ndeps;
|
---|
| 141 |
|
---|
| 142 | rule = next;
|
---|
[3140] | 143 | }
|
---|
[53] | 144 |
|
---|
| 145 | free (name);
|
---|
| 146 | }
|
---|
| 147 | |
---|
| 148 |
|
---|
[3140] | 149 | /* Create a pattern rule from a suffix rule.
|
---|
[53] | 150 | TARGET is the target suffix; SOURCE is the source suffix.
|
---|
| 151 | CMDS are the commands.
|
---|
| 152 | If TARGET is nil, it means the target pattern should be '(%.o)'.
|
---|
[903] | 153 | If SOURCE is nil, it means there should be no deps. */
|
---|
| 154 |
|
---|
[53] | 155 | static void
|
---|
[903] | 156 | convert_suffix_rule (const char *target, const char *source,
|
---|
[53] | 157 | struct commands *cmds)
|
---|
| 158 | {
|
---|
[903] | 159 | const char **names, **percents;
|
---|
| 160 | struct dep *deps;
|
---|
| 161 |
|
---|
[53] | 162 | names = xmalloc (sizeof (const char *));
|
---|
| 163 | percents = xmalloc (sizeof (const char *));
|
---|
[3140] | 164 |
|
---|
| 165 | if (target == 0)
|
---|
[53] | 166 | {
|
---|
[903] | 167 | /* Special case: TARGET being nil means we are defining a '.X.a' suffix
|
---|
[53] | 168 | rule; the target pattern is always '(%.o)'. */
|
---|
[903] | 169 | #ifdef VMS
|
---|
[53] | 170 | *names = strcache_add_len ("(%.obj)", 7);
|
---|
[903] | 171 | #else
|
---|
[53] | 172 | *names = strcache_add_len ("(%.o)", 5);
|
---|
| 173 | #endif
|
---|
| 174 | *percents = *names + 1;
|
---|
| 175 | }
|
---|
[903] | 176 | else
|
---|
| 177 | {
|
---|
| 178 | /* Construct the target name. */
|
---|
| 179 | unsigned int len = strlen (target);
|
---|
| 180 | char *p = alloca (1 + len + 1);
|
---|
| 181 | p[0] = '%';
|
---|
[53] | 182 | memcpy (p + 1, target, len + 1);
|
---|
| 183 | *names = strcache_add_len (p, len + 1);
|
---|
| 184 | *percents = *names;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | if (source == 0)
|
---|
| 188 | deps = 0;
|
---|
[903] | 189 | else
|
---|
| 190 | {
|
---|
| 191 | /* Construct the dependency name. */
|
---|
| 192 | unsigned int len = strlen (source);
|
---|
[503] | 193 | char *p = alloca (1 + len + 1);
|
---|
[903] | 194 | p[0] = '%';
|
---|
[53] | 195 | memcpy (p + 1, source, len + 1);
|
---|
| 196 | deps = alloc_dep ();
|
---|
[903] | 197 | deps->name = strcache_add_len (p, len + 1);
|
---|
[53] | 198 | }
|
---|
| 199 |
|
---|
| 200 | create_pattern_rule (names, percents, 1, 0, deps, cmds, 0);
|
---|
[903] | 201 | }
|
---|
| 202 |
|
---|
[53] | 203 | /* Convert old-style suffix rules to pattern rules.
|
---|
| 204 | All rules for the suffixes on the .SUFFIXES list are converted and added to
|
---|
| 205 | the chain of pattern rules. */
|
---|
| 206 |
|
---|
[903] | 207 | void
|
---|
| 208 | convert_to_pattern (void)
|
---|
[53] | 209 | {
|
---|
[903] | 210 | struct dep *d, *d2;
|
---|
| 211 | char *rulename;
|
---|
| 212 |
|
---|
[53] | 213 | /* We will compute every potential suffix rule (.x.y) from the list of
|
---|
| 214 | suffixes in the .SUFFIXES target's dependencies and see if it exists.
|
---|
| 215 | First find the longest of the suffixes. */
|
---|
| 216 |
|
---|
[903] | 217 | maxsuffix = 0;
|
---|
| 218 | for (d = suffix_file->deps; d != 0; d = d->next)
|
---|
[3140] | 219 | {
|
---|
[53] | 220 | unsigned int l = strlen (dep_name (d));
|
---|
| 221 | if (l > maxsuffix)
|
---|
[903] | 222 | maxsuffix = l;
|
---|
| 223 | }
|
---|
[53] | 224 |
|
---|
| 225 | /* Space to construct the suffix rule target name. */
|
---|
| 226 | rulename = alloca ((maxsuffix * 2) + 1);
|
---|
[903] | 227 |
|
---|
| 228 | for (d = suffix_file->deps; d != 0; d = d->next)
|
---|
[53] | 229 | {
|
---|
[3140] | 230 | unsigned int slen;
|
---|
[903] | 231 |
|
---|
[53] | 232 | /* Make a rule that is just the suffix, with no deps or commands.
|
---|
[903] | 233 | This rule exists solely to disqualify match-anything rules. */
|
---|
[3140] | 234 | convert_suffix_rule (dep_name (d), 0, 0);
|
---|
| 235 |
|
---|
[53] | 236 | if (d->file->cmds != 0)
|
---|
[903] | 237 | /* Record a pattern for this suffix's null-suffix rule. */
|
---|
| 238 | convert_suffix_rule ("", dep_name (d), d->file->cmds);
|
---|
[53] | 239 |
|
---|
[903] | 240 | /* Add every other suffix to this one and see if it exists as a
|
---|
| 241 | two-suffix rule. */
|
---|
[53] | 242 | slen = strlen (dep_name (d));
|
---|
[3140] | 243 | memcpy (rulename, dep_name (d), slen);
|
---|
[903] | 244 |
|
---|
| 245 | for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
|
---|
| 246 | {
|
---|
[3140] | 247 | struct file *f;
|
---|
[53] | 248 | unsigned int s2len;
|
---|
[903] | 249 |
|
---|
[3140] | 250 | s2len = strlen (dep_name (d2));
|
---|
| 251 |
|
---|
[53] | 252 | /* Can't build something from itself. */
|
---|
[3140] | 253 | if (slen == s2len && streq (dep_name (d), dep_name (d2)))
|
---|
| 254 | continue;
|
---|
| 255 |
|
---|
| 256 | memcpy (rulename + slen, dep_name (d2), s2len + 1);
|
---|
[53] | 257 | f = lookup_file (rulename);
|
---|
[3140] | 258 | if (f == 0 || f->cmds == 0)
|
---|
| 259 | continue;
|
---|
| 260 |
|
---|
| 261 | if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a')
|
---|
| 262 | /* A suffix rule '.X.a:' generates the pattern rule '(%.o): %.X'.
|
---|
| 263 | It also generates a normal '%.a: %.X' rule below. */
|
---|
[53] | 264 | convert_suffix_rule (NULL, /* Indicates '(%.o)'. */
|
---|
[3140] | 265 | dep_name (d),
|
---|
| 266 | f->cmds);
|
---|
| 267 |
|
---|
| 268 | /* The suffix rule '.X.Y:' is converted
|
---|
[53] | 269 | to the pattern rule '%.Y: %.X'. */
|
---|
| 270 | convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds);
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
[903] | 273 | }
|
---|
| 274 |
|
---|
| 275 |
|
---|
| 276 | /* Install the pattern rule RULE (whose fields have been filled in) at the end
|
---|
| 277 | of the list (so that any rules previously defined will take precedence).
|
---|
| 278 | If this rule duplicates a previous one (identical target and dependencies),
|
---|
[53] | 279 | the old one is replaced if OVERRIDE is nonzero, otherwise this new one is
|
---|
[903] | 280 | thrown out. When an old rule is replaced, the new one is put at the end of
|
---|
[53] | 281 | the list. Return nonzero if RULE is used; zero if not. */
|
---|
| 282 |
|
---|
[903] | 283 | static int
|
---|
| 284 | new_pattern_rule (struct rule *rule, int override)
|
---|
[53] | 285 | {
|
---|
| 286 | struct rule *r, *lastrule;
|
---|
| 287 | unsigned int i, j;
|
---|
| 288 |
|
---|
| 289 | rule->in_use = 0;
|
---|
| 290 | rule->terminal = 0;
|
---|
| 291 |
|
---|
| 292 | rule->next = 0;
|
---|
| 293 |
|
---|
[903] | 294 | /* Search for an identical rule. */
|
---|
[53] | 295 | lastrule = 0;
|
---|
[3140] | 296 | for (r = pattern_rules; r != 0; lastrule = r, r = r->next)
|
---|
| 297 | for (i = 0; i < rule->num; ++i)
|
---|
| 298 | {
|
---|
[903] | 299 | for (j = 0; j < r->num; ++j)
|
---|
[3140] | 300 | if (!streq (rule->targets[i], r->targets[j]))
|
---|
| 301 | break;
|
---|
| 302 | /* If all the targets matched... */
|
---|
| 303 | if (j == r->num)
|
---|
| 304 | {
|
---|
| 305 | struct dep *d, *d2;
|
---|
| 306 | for (d = rule->deps, d2 = r->deps;
|
---|
| 307 | d != 0 && d2 != 0; d = d->next, d2 = d2->next)
|
---|
| 308 | if (!streq (dep_name (d), dep_name (d2)))
|
---|
| 309 | break;
|
---|
| 310 | if (d == 0 && d2 == 0)
|
---|
| 311 | {
|
---|
| 312 | /* All the dependencies matched. */
|
---|
| 313 | if (override)
|
---|
| 314 | {
|
---|
| 315 | /* Remove the old rule. */
|
---|
| 316 | freerule (r, lastrule);
|
---|
| 317 | /* Install the new one. */
|
---|
| 318 | if (pattern_rules == 0)
|
---|
| 319 | pattern_rules = rule;
|
---|
[53] | 320 | else
|
---|
[3140] | 321 | last_pattern_rule->next = rule;
|
---|
| 322 | last_pattern_rule = rule;
|
---|
| 323 |
|
---|
| 324 | /* We got one. Stop looking. */
|
---|
| 325 | goto matched;
|
---|
| 326 | }
|
---|
| 327 | else
|
---|
| 328 | {
|
---|
| 329 | /* The old rule stays intact. Destroy the new one. */
|
---|
| 330 | freerule (rule, (struct rule *) 0);
|
---|
| 331 | return 0;
|
---|
[53] | 332 | }
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | matched:;
|
---|
| 338 |
|
---|
| 339 | if (r == 0)
|
---|
[3140] | 340 | {
|
---|
[53] | 341 | /* There was no rule to replace. */
|
---|
[3140] | 342 | if (pattern_rules == 0)
|
---|
[53] | 343 | pattern_rules = rule;
|
---|
| 344 | else
|
---|
| 345 | last_pattern_rule->next = rule;
|
---|
| 346 | last_pattern_rule = rule;
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | return 1;
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 |
|
---|
[3140] | 353 | /* Install an implicit pattern rule based on the three text strings
|
---|
[53] | 354 | in the structure P points to. These strings come from one of
|
---|
| 355 | the arrays of default implicit pattern rules.
|
---|
| 356 | TERMINAL specifies what the 'terminal' field of the rule should be. */
|
---|
| 357 |
|
---|
[903] | 358 | void
|
---|
[3140] | 359 | install_pattern_rule (struct pspec *p, int terminal)
|
---|
[53] | 360 | {
|
---|
[903] | 361 | struct rule *r;
|
---|
[53] | 362 | const char *ptr;
|
---|
[903] | 363 |
|
---|
| 364 | r = xmalloc (sizeof (struct rule));
|
---|
| 365 |
|
---|
| 366 | r->num = 1;
|
---|
[53] | 367 | r->targets = xmalloc (sizeof (const char *));
|
---|
| 368 | r->suffixes = xmalloc (sizeof (const char *));
|
---|
[903] | 369 | r->lens = xmalloc (sizeof (unsigned int));
|
---|
| 370 |
|
---|
| 371 | r->lens[0] = strlen (p->target);
|
---|
| 372 | r->targets[0] = p->target;
|
---|
[53] | 373 | r->suffixes[0] = find_percent_cached (&r->targets[0]);
|
---|
| 374 | assert (r->suffixes[0] != NULL);
|
---|
[3140] | 375 | ++r->suffixes[0];
|
---|
[53] | 376 |
|
---|
| 377 | ptr = p->dep;
|
---|
| 378 | r->deps = PARSE_SIMPLE_SEQ ((char **)&ptr, struct dep);
|
---|
| 379 |
|
---|
[1867] | 380 | if (new_pattern_rule (r, 0))
|
---|
[903] | 381 | {
|
---|
[1867] | 382 | r->terminal = terminal;
|
---|
| 383 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 384 | r->cmds = xmalloc (sizeof (struct commands));
|
---|
[53] | 385 | #else
|
---|
| 386 | r->cmds = alloccache_alloc (&commands_cache);
|
---|
[3140] | 387 | #endif
|
---|
[53] | 388 | r->cmds->fileinfo.filenm = 0;
|
---|
[3140] | 389 | r->cmds->fileinfo.lineno = 0;
|
---|
[53] | 390 | r->cmds->fileinfo.offset = 0;
|
---|
| 391 | /* These will all be string literals, but we malloc space for them
|
---|
[3140] | 392 | anyway because somebody might want to free them later. */
|
---|
| 393 | r->cmds->commands = xstrdup (p->commands);
|
---|
[2056] | 394 | r->cmds->command_lines = 0;
|
---|
| 395 | r->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
|
---|
| 396 |
|
---|
[53] | 397 | #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
|
---|
| 398 | r->cmds->refs = 1000;
|
---|
| 399 | #endif
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
| 404 | /* Free all the storage used in RULE and take it out of the
|
---|
| 405 | pattern_rules chain. LASTRULE is the rule whose next pointer
|
---|
| 406 | points to RULE. */
|
---|
| 407 |
|
---|
| 408 | static void
|
---|
| 409 | freerule (struct rule *rule, struct rule *lastrule)
|
---|
[2591] | 410 | {
|
---|
[53] | 411 | struct rule *next = rule->next;
|
---|
[2591] | 412 |
|
---|
| 413 | free_dep_chain (rule->deps);
|
---|
| 414 |
|
---|
[903] | 415 | /* MSVC erroneously warns without a cast here. */
|
---|
[53] | 416 | free ((void *)rule->targets);
|
---|
| 417 | free ((void *)rule->suffixes);
|
---|
| 418 | free (rule->lens);
|
---|
| 419 |
|
---|
[3140] | 420 | /* We can't free the storage for the commands because there
|
---|
[53] | 421 | are ways that they could be in more than one place:
|
---|
| 422 | * If the commands came from a suffix rule, they could also be in
|
---|
| 423 | the 'struct file's for other suffix rules or plain targets given
|
---|
| 424 | on the same makefile line.
|
---|
[3140] | 425 | * If two suffixes that together make a two-suffix rule were each
|
---|
| 426 | given twice in the .SUFFIXES list, and in the proper order, two
|
---|
[53] | 427 | identical pattern rules would be created and the second one would
|
---|
[903] | 428 | be discarded here, but both would contain the same 'struct commands'
|
---|
[53] | 429 | pointer from the 'struct file' for the suffix rule. */
|
---|
| 430 |
|
---|
| 431 | free (rule);
|
---|
| 432 |
|
---|
| 433 | if (pattern_rules == rule)
|
---|
| 434 | if (lastrule != 0)
|
---|
| 435 | abort ();
|
---|
| 436 | else
|
---|
| 437 | pattern_rules = next;
|
---|
| 438 | else if (lastrule != 0)
|
---|
| 439 | lastrule->next = next;
|
---|
| 440 | if (last_pattern_rule == rule)
|
---|
[903] | 441 | last_pattern_rule = lastrule;
|
---|
| 442 | }
|
---|
| 443 | |
---|
| 444 |
|
---|
[53] | 445 | /* Create a new pattern rule with the targets in the nil-terminated array
|
---|
| 446 | TARGETS. TARGET_PERCENTS is an array of pointers to the % in each element
|
---|
| 447 | of TARGETS. N is the number of items in the array (not counting the nil
|
---|
[903] | 448 | element). The new rule has dependencies DEPS and commands from COMMANDS.
|
---|
| 449 | It is a terminal rule if TERMINAL is nonzero. This rule overrides
|
---|
[53] | 450 | identical rules with different commands if OVERRIDE is nonzero.
|
---|
| 451 |
|
---|
[903] | 452 | The storage for TARGETS and its elements and TARGET_PERCENTS is used and
|
---|
| 453 | must not be freed until the rule is destroyed. */
|
---|
[53] | 454 |
|
---|
| 455 | void
|
---|
[903] | 456 | create_pattern_rule (const char **targets, const char **target_percents,
|
---|
| 457 | unsigned int n, int terminal, struct dep *deps,
|
---|
[53] | 458 | struct commands *commands, int override)
|
---|
[903] | 459 | {
|
---|
[53] | 460 | unsigned int i;
|
---|
| 461 | struct rule *r = xmalloc (sizeof (struct rule));
|
---|
| 462 |
|
---|
[903] | 463 | r->num = n;
|
---|
| 464 | r->cmds = commands;
|
---|
[53] | 465 | r->deps = deps;
|
---|
[903] | 466 | r->targets = targets;
|
---|
[53] | 467 | r->suffixes = target_percents;
|
---|
| 468 | r->lens = xmalloc (n * sizeof (unsigned int));
|
---|
[903] | 469 |
|
---|
| 470 | for (i = 0; i < n; ++i)
|
---|
[53] | 471 | {
|
---|
| 472 | r->lens[i] = strlen (targets[i]);
|
---|
| 473 | assert (r->suffixes[i] != NULL);
|
---|
| 474 | ++r->suffixes[i];
|
---|
[2056] | 475 | }
|
---|
[2137] | 476 |
|
---|
| 477 | if (new_pattern_rule (r, override))
|
---|
[2056] | 478 | r->terminal = terminal;
|
---|
[53] | 479 | #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
|
---|
| 480 | if (commands != NULL)
|
---|
| 481 | commands->refs = 1000;
|
---|
| 482 | #endif
|
---|
[3140] | 483 | }
|
---|
[53] | 484 | |
---|
| 485 |
|
---|
[903] | 486 | /* Print the data base of rules. */
|
---|
[53] | 487 |
|
---|
[903] | 488 | static void /* Useful to call from gdb. */
|
---|
[53] | 489 | print_rule (struct rule *r)
|
---|
| 490 | {
|
---|
[903] | 491 | unsigned int i;
|
---|
[53] | 492 |
|
---|
| 493 | for (i = 0; i < r->num; ++i)
|
---|
| 494 | {
|
---|
| 495 | fputs (r->targets[i], stdout);
|
---|
[2591] | 496 | putchar ((i + 1 == r->num) ? ':' : ' ');
|
---|
[53] | 497 | }
|
---|
| 498 | if (r->terminal)
|
---|
| 499 | putchar (':');
|
---|
| 500 |
|
---|
| 501 | print_prereqs (r->deps);
|
---|
| 502 |
|
---|
| 503 | if (r->cmds != 0)
|
---|
| 504 | print_commands (r->cmds);
|
---|
[903] | 505 | }
|
---|
| 506 |
|
---|
[53] | 507 | void
|
---|
| 508 | print_rule_data_base (void)
|
---|
| 509 | {
|
---|
| 510 | unsigned int rules, terminal;
|
---|
| 511 | struct rule *r;
|
---|
| 512 |
|
---|
| 513 | puts (_("\n# Implicit Rules"));
|
---|
| 514 |
|
---|
| 515 | rules = terminal = 0;
|
---|
| 516 | for (r = pattern_rules; r != 0; r = r->next)
|
---|
| 517 | {
|
---|
| 518 | ++rules;
|
---|
[3140] | 519 |
|
---|
[53] | 520 | putchar ('\n');
|
---|
| 521 | print_rule (r);
|
---|
| 522 |
|
---|
| 523 | if (r->terminal)
|
---|
| 524 | ++terminal;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
[3140] | 527 | if (rules == 0)
|
---|
[53] | 528 | puts (_("\n# No implicit rules."));
|
---|
| 529 | else
|
---|
| 530 | {
|
---|
[3140] | 531 | printf (_("\n# %u implicit rules, %u"), rules, terminal);
|
---|
| 532 | #ifndef NO_FLOAT
|
---|
[53] | 533 | printf (" (%.1f%%)", (double) terminal / (double) rules * 100.0);
|
---|
| 534 | #else
|
---|
| 535 | {
|
---|
| 536 | int f = (terminal * 1000 + 5) / rules;
|
---|
| 537 | printf (" (%d.%d%%)", f/10, f%10);
|
---|
| 538 | }
|
---|
| 539 | #endif
|
---|
| 540 | puts (_(" terminal."));
|
---|
| 541 | }
|
---|
| 542 |
|
---|
[3140] | 543 | if (num_pattern_rules != rules)
|
---|
| 544 | {
|
---|
[53] | 545 | /* This can happen if a fatal error was detected while reading the
|
---|
| 546 | makefiles and thus count_implicit_rule_limits wasn't called yet. */
|
---|
| 547 | if (num_pattern_rules != 0)
|
---|
| 548 | ONN (fatal, NILF, _("BUG: num_pattern_rules is wrong! %u != %u"),
|
---|
| 549 | num_pattern_rules, rules);
|
---|
| 550 | }
|
---|
| 551 | }
|
---|