make/src/rule.c

640 lines
19 KiB
C
Raw Normal View History

1992-01-11 19:37:36 +08:00
/* Pattern and suffix rule internals for GNU Make.
2024-01-07 06:55:04 +08:00
Copyright (C) 1988-2024 Free Software Foundation, Inc.
1992-01-11 19:37:36 +08:00
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
1992-01-11 19:37:36 +08:00
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1992-01-11 19:37:36 +08:00
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>. */
1992-01-11 19:37:36 +08:00
#include "makeint.h"
#include <assert.h>
#include "filedef.h"
#include "dep.h"
#include "job.h"
#include "commands.h"
1992-01-11 19:37:36 +08:00
#include "variable.h"
#include "rule.h"
static void freerule (struct rule *rule, struct rule *lastrule);
1992-01-11 19:37:36 +08:00
/* Chain of all pattern rules. */
struct rule *pattern_rules;
/* Pointer to last rule in the chain, so we can add onto the end. */
struct rule *last_pattern_rule;
/* Number of rules in the chain. */
unsigned int num_pattern_rules;
1993-07-01 06:40:50 +08:00
/* Maximum number of target patterns of any pattern rule. */
unsigned int max_pattern_targets;
1992-01-11 19:37:36 +08:00
/* Maximum number of dependencies of any pattern rule. */
unsigned int max_pattern_deps;
/* Maximum length of the name of a dependencies of any pattern rule. */
size_t max_pattern_dep_length;
1992-01-11 19:37:36 +08:00
/* Pointer to structure for the file .SUFFIXES
whose dependencies are the suffixes to be searched. */
struct file *suffix_file;
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
/* Return the rule definition: space separated rule targets, followed by
either a colon or two colons in the case of a terminal rule, followed by
space separated rule prerequisites, followed by a pipe, followed by
order-only prerequisites, if present. */
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
const char *
get_rule_defn (struct rule *r)
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
{
if (r->_defn == NULL)
{
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
size_t len = 8; /* Reserve for ":: ", " | ", and nul. */
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
unsigned int k;
char *p;
const char *sep = "";
const struct dep *dep, *ood = 0;
for (k = 0; k < r->num; ++k)
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
len += r->lens[k] + 1;
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
for (dep = r->deps; dep; dep = dep->next)
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
len += strlen (dep_name (dep)) + (dep->wait_here ? CSTRLEN (" .WAIT") : 0) + 1;
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
p = r->_defn = xmalloc (len);
for (k = 0; k < r->num; ++k, sep = " ")
p = mempcpy (mempcpy (p, sep, strlen (sep)), r->targets[k], r->lens[k]);
*p++ = ':';
if (r->terminal)
*p++ = ':';
/* Copy all normal dependencies; note any order-only deps. */
for (dep = r->deps; dep; dep = dep->next)
if (dep->ignore_mtime == 0)
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
{
if (dep->wait_here)
p = mempcpy (p, " .WAIT", CSTRLEN (" .WAIT"));
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
p = mempcpy (mempcpy (p, " ", 1), dep_name (dep),
strlen (dep_name (dep)));
}
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
else if (ood == 0)
ood = dep;
/* Copy order-only deps, if we have any. */
for (sep = " | "; ood; ood = ood->next, sep = " ")
if (ood->ignore_mtime)
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
{
p = mempcpy (p, sep, strlen (sep));
if (ood->wait_here)
p = mempcpy (p, ".WAIT ", CSTRLEN (".WAIT "));
[SV 13862] Implement the .WAIT special target The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
2022-09-13 06:18:49 +08:00
p = mempcpy (p, dep_name (ood), strlen (dep_name (ood)));
}
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
*p = '\0';
}
return r->_defn;
}
1992-01-11 19:37:36 +08:00
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
/* Compute the maximum dependency length and maximum number of dependencies of
all implicit rules. Also sets the subdir flag for a rule when appropriate,
possibly removing the rule completely when appropriate.
Add any global EXTRA_PREREQS here as well. */
1992-01-11 19:37:36 +08:00
void
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
snap_implicit_rules (void)
1992-01-11 19:37:36 +08:00
{
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
char *name = NULL;
size_t namelen = 0;
struct rule *rule;
struct dep *dep;
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
struct dep *prereqs = expand_extra_prereqs (lookup_variable (STRING_SIZE_TUPLE(".EXTRA_PREREQS")));
unsigned int pre_deps = 0;
1992-01-11 19:37:36 +08:00
1993-07-01 06:40:50 +08:00
max_pattern_dep_length = 0;
for (dep = prereqs; dep; dep = dep->next)
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
{
const char *d = dep_name (dep);
size_t l = strlen (d);
if (second_expansion)
{
if (!dep->name)
dep->name = xstrdup (dep->file->name);
dep->need_2nd_expansion = 1;
}
if (dep->need_2nd_expansion)
/* When pattern_search allocates a buffer, allow 5 bytes per each % to
substitute each % with $(*F) while avoiding realloc. */
while ((d = strchr (d, '%')) != 0)
{
l += 4;
++d;
}
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
if (l > max_pattern_dep_length)
max_pattern_dep_length = l;
++pre_deps;
}
num_pattern_rules = max_pattern_targets = max_pattern_deps = 0;
for (rule = pattern_rules; rule; rule = rule->next)
1992-01-11 19:37:36 +08:00
{
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
unsigned int ndeps = pre_deps;
struct dep *lastdep = NULL;
1993-07-01 06:40:50 +08:00
1992-01-11 19:37:36 +08:00
++num_pattern_rules;
1998-07-31 04:54:47 +08:00
if (rule->num > max_pattern_targets)
max_pattern_targets = rule->num;
1993-07-01 06:40:50 +08:00
for (dep = rule->deps; dep != 0; dep = dep->next)
{
const char *dname = dep_name (dep);
size_t len = strlen (dname);
#if MK_OS_VMS
const char *p = strrchr (dname, ']');
const char *p2;
2000-01-22 13:43:03 +08:00
if (p == 0)
p = strrchr (dname, ':');
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
p2 = p ? strchr (p, '%') : 0;
#else
const char *p = strrchr (dname, '/');
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
const char *p2 = p ? strchr (p, '%') : 0;
2000-01-22 13:43:03 +08:00
#endif
ndeps++;
1992-01-11 19:37:36 +08:00
if (len > max_pattern_dep_length)
max_pattern_dep_length = len;
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
if (!dep->next)
lastdep = dep;
if (p2)
{
/* There is a slash before the % in the dep name.
Extract the directory name. */
if (p == dname)
++p;
if ((size_t) (p - dname) > namelen)
{
namelen = p - dname;
name = xrealloc (name, namelen + 1);
}
memcpy (name, dname, p - dname);
name[p - dname] = '\0';
/* In the deps of an implicit rule the 'changed' flag
actually indicates that the dependency is in a
nonexistent subdirectory. */
dep->changed = !dir_file_exists_p (name, "");
}
else
/* This dependency does not reside in a subdirectory. */
dep->changed = 0;
}
1992-01-11 19:37:36 +08:00
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
if (prereqs)
{
if (lastdep)
lastdep->next = copy_dep_chain (prereqs);
else
rule->deps = copy_dep_chain (prereqs);
}
1992-01-11 19:37:36 +08:00
if (ndeps > max_pattern_deps)
max_pattern_deps = ndeps;
1992-01-11 19:37:36 +08:00
}
1998-07-31 04:54:47 +08:00
free (name);
Support the .EXTRA_PREREQS special variable Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
2020-01-02 18:08:06 +08:00
free_dep_chain (prereqs);
1992-01-11 19:37:36 +08:00
}
1993-05-25 07:02:13 +08:00
/* Create a pattern rule from a suffix rule.
TARGET is the target suffix; SOURCE is the source suffix.
CMDS are the commands.
If TARGET is nil, it means the target pattern should be '(%.o)'.
1993-05-25 07:02:13 +08:00
If SOURCE is nil, it means there should be no deps. */
static void
convert_suffix_rule (const char *target, const char *source,
struct commands *cmds)
1993-05-25 07:02:13 +08:00
{
const char **names, **percents;
1993-05-25 07:02:13 +08:00
struct dep *deps;
names = xmalloc (sizeof (const char *));
percents = xmalloc (sizeof (const char *));
1993-05-25 07:02:13 +08:00
if (target == 0)
1993-10-22 04:48:08 +08:00
{
/* Special case: TARGET being nil means we are defining a '.X.a' suffix
rule; the target pattern is always '(%.o)'. */
#if MK_OS_VMS
*names = strcache_add_len ("(%.obj)", 7);
#else
*names = strcache_add_len ("(%.o)", 5);
#endif
*percents = *names + 1;
1993-10-22 04:48:08 +08:00
}
1993-05-25 07:02:13 +08:00
else
{
/* Construct the target name. */
size_t len = strlen (target);
char *p = alloca (1 + len + 1);
p[0] = '%';
memcpy (p + 1, target, len + 1);
*names = strcache_add_len (p, len + 1);
*percents = *names;
1993-05-25 07:02:13 +08:00
}
if (source == 0)
deps = 0;
else
{
/* Construct the dependency name. */
size_t len = strlen (source);
char *p = alloca (1 + len + 1);
p[0] = '%';
memcpy (p + 1, source, len + 1);
2006-03-17 22:24:20 +08:00
deps = alloc_dep ();
deps->name = strcache_add_len (p, len + 1);
1993-05-25 07:02:13 +08:00
}
create_pattern_rule (names, percents, 1, 0, deps, cmds, 0);
1993-05-25 07:02:13 +08:00
}
1992-01-11 19:37:36 +08:00
/* Convert old-style suffix rules to pattern rules.
All rules for the suffixes on the .SUFFIXES list are converted and added to
the chain of pattern rules. */
1992-01-11 19:37:36 +08:00
void
convert_to_pattern (void)
1992-01-11 19:37:36 +08:00
{
struct dep *d, *d2;
char *rulename;
1992-01-11 19:37:36 +08:00
/* We will compute every potential suffix rule (.x.y) from the list of
suffixes in the .SUFFIXES target's dependencies and see if it exists.
First find the longest of the suffixes. */
1992-01-11 19:37:36 +08:00
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 12:14:57 +08:00
size_t maxsuffix = 0;
1992-01-11 19:37:36 +08:00
for (d = suffix_file->deps; d != 0; d = d->next)
{
size_t l = strlen (dep_name (d));
if (l > maxsuffix)
maxsuffix = l;
1992-01-11 19:37:36 +08:00
}
/* Space to construct the suffix rule target name. */
rulename = alloca ((maxsuffix * 2) + 1);
1992-01-11 19:37:36 +08:00
for (d = suffix_file->deps; d != 0; d = d->next)
{
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 12:14:57 +08:00
struct file *f;
size_t slen;
1992-01-11 19:37:36 +08:00
/* Make a rule that is just the suffix, with no deps or commands.
This rule exists solely to disqualify match-anything rules. */
convert_suffix_rule (dep_name (d), 0, 0);
1992-01-11 19:37:36 +08:00
if (d->file->cmds != 0)
/* Record a pattern for this suffix's null-suffix rule. */
convert_suffix_rule ("", dep_name (d), d->file->cmds);
1992-01-11 19:37:36 +08:00
1993-05-25 07:02:13 +08:00
slen = strlen (dep_name (d));
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 12:14:57 +08:00
memcpy (rulename, dep_name (d), slen + 1);
f = lookup_file (rulename);
if (f && f->cmds)
{
if (!f->deps)
f->suffix = 1;
else if (!posix_pedantic)
{
O (error, &f->cmds->fileinfo,
_("warning: ignoring prerequisites on suffix rule definition"));
f->suffix = 1;
}
}
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 12:14:57 +08:00
/* Add every other suffix to this one and see if it exists as a
two-suffix rule. */
1992-01-11 19:37:36 +08:00
for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
{
size_t s2len;
s2len = strlen (dep_name (d2));
1992-01-11 19:37:36 +08:00
/* Can't build something from itself. */
if (slen == s2len && streq (dep_name (d), dep_name (d2)))
continue;
memcpy (rulename + slen, dep_name (d2), s2len + 1);
f = lookup_file (rulename);
/* No target, or no commands: it can't be a suffix rule. */
if (f == 0 || f->cmds == 0)
continue;
/* POSIX says that suffix rules can't have prerequisites.
In POSIX mode, don't make this a suffix rule. Previous versions
of GNU Make did treat this as a suffix rule and ignored the
prerequisites, which is bad. In the future we'll do the same as
POSIX, but for now preserve the old behavior and warn about it. */
if (f->deps != 0)
{
if (posix_pedantic)
continue;
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 12:14:57 +08:00
O (error, &f->cmds->fileinfo,
_("warning: ignoring prerequisites on suffix rule definition"));
}
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 12:14:57 +08:00
f->suffix = 1;
if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a')
/* A suffix rule '.X.a:' generates the pattern rule '(%.o): %.X'.
It also generates a normal '%.a: %.X' rule below. */
convert_suffix_rule (NULL, /* Indicates '(%.o)'. */
dep_name (d),
f->cmds);
/* The suffix rule '.X.Y:' is converted
to the pattern rule '%.Y: %.X'. */
convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds);
}
1992-01-11 19:37:36 +08:00
}
}
/* Install the pattern rule RULE (whose fields have been filled in) at the end
of the list (so that any rules previously defined will take precedence).
If this rule duplicates a previous one (identical target and dependencies),
the old one is replaced if OVERRIDE is nonzero, otherwise this new one is
thrown out. When an old rule is replaced, the new one is put at the end of
the list. Return nonzero if RULE is used; zero if not. */
1992-01-11 19:37:36 +08:00
static int
new_pattern_rule (struct rule *rule, int override)
1992-01-11 19:37:36 +08:00
{
struct rule *r, *lastrule;
unsigned int i, j;
1992-01-11 19:37:36 +08:00
rule->in_use = 0;
rule->terminal = 0;
rule->next = 0;
/* Search for an identical rule. */
1992-05-26 13:26:26 +08:00
lastrule = 0;
1992-01-11 19:37:36 +08:00
for (r = pattern_rules; r != 0; lastrule = r, r = r->next)
for (i = 0; i < rule->num; ++i)
1992-03-24 17:50:46 +08:00
{
for (j = 0; j < r->num; ++j)
if (!streq (rule->targets[i], r->targets[j]))
break;
/* If all the targets matched... */
if (j == r->num)
{
struct dep *d, *d2;
for (d = rule->deps, d2 = r->deps;
d != 0 && d2 != 0; d = d->next, d2 = d2->next)
if (!streq (dep_name (d), dep_name (d2)))
break;
if (d == 0 && d2 == 0)
{
/* All the dependencies matched. */
if (override)
{
/* Remove the old rule. */
freerule (r, lastrule);
/* Install the new one. */
if (pattern_rules == 0)
pattern_rules = rule;
else
last_pattern_rule->next = rule;
last_pattern_rule = rule;
/* We got one. Stop looking. */
goto matched;
}
else
{
/* The old rule stays intact. Destroy the new one. */
freerule (rule, (struct rule *) 0);
return 0;
}
}
}
1992-03-24 17:50:46 +08:00
}
1992-01-11 19:37:36 +08:00
matched:;
if (r == 0)
{
/* There was no rule to replace. */
if (pattern_rules == 0)
pattern_rules = rule;
1992-01-11 19:37:36 +08:00
else
last_pattern_rule->next = rule;
1992-01-11 19:37:36 +08:00
last_pattern_rule = rule;
}
return 1;
}
/* Install an implicit pattern rule based on the three text strings
in the structure P points to. These strings come from one of
the arrays of default implicit pattern rules.
TERMINAL specifies what the 'terminal' field of the rule should be. */
1992-01-11 19:37:36 +08:00
void
install_pattern_rule (struct pspec *p, int terminal)
1992-01-11 19:37:36 +08:00
{
struct rule *r;
const char *ptr;
1992-01-11 19:37:36 +08:00
r = xmalloc (sizeof (struct rule));
1992-01-11 19:37:36 +08:00
r->num = 1;
r->targets = xmalloc (sizeof (const char *));
r->suffixes = xmalloc (sizeof (const char *));
r->lens = xmalloc (sizeof (unsigned int));
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
r->_defn = NULL;
1992-01-11 19:37:36 +08:00
r->lens[0] = (unsigned int) strlen (p->target);
r->targets[0] = p->target;
r->suffixes[0] = find_percent_cached (&r->targets[0]);
assert (r->suffixes[0] != NULL);
++r->suffixes[0];
1992-01-11 19:37:36 +08:00
ptr = p->dep;
r->deps = PARSE_SIMPLE_SEQ ((char **)&ptr, struct dep);
1992-01-11 19:37:36 +08:00
if (new_pattern_rule (r, 0))
{
r->terminal = terminal ? 1 : 0;
r->cmds = xmalloc (sizeof (struct commands));
1998-10-03 13:39:55 +08:00
r->cmds->fileinfo.filenm = 0;
r->cmds->fileinfo.lineno = 0;
r->cmds->fileinfo.offset = 0;
1992-01-11 19:37:36 +08:00
/* These will all be string literals, but we malloc space for them
anyway because somebody might want to free them later. */
r->cmds->commands = xstrdup (p->commands);
1992-01-11 19:37:36 +08:00
r->cmds->command_lines = 0;
r->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
1992-01-11 19:37:36 +08:00
}
}
/* Free all the storage used in RULE and take it out of the
pattern_rules chain. LASTRULE is the rule whose next pointer
points to RULE. */
static void
freerule (struct rule *rule, struct rule *lastrule)
1992-01-11 19:37:36 +08:00
{
struct rule *next = rule->next;
free_dep_chain (rule->deps);
/* MSVC erroneously warns without a cast here. */
free ((void *)rule->targets);
free ((void *)rule->suffixes);
free (rule->lens);
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
free ((void *) rule->_defn);
1992-01-11 19:37:36 +08:00
/* We can't free the storage for the commands because there
are ways that they could be in more than one place:
* If the commands came from a suffix rule, they could also be in
the 'struct file's for other suffix rules or plain targets given
1992-01-11 19:37:36 +08:00
on the same makefile line.
* If two suffixes that together make a two-suffix rule were each
given twice in the .SUFFIXES list, and in the proper order, two
identical pattern rules would be created and the second one would
be discarded here, but both would contain the same 'struct commands'
pointer from the 'struct file' for the suffix rule. */
1992-01-11 19:37:36 +08:00
free (rule);
1992-01-11 19:37:36 +08:00
if (pattern_rules == rule)
1992-04-27 03:19:06 +08:00
if (lastrule != 0)
1992-01-11 19:37:36 +08:00
abort ();
else
pattern_rules = next;
1992-04-29 08:44:29 +08:00
else if (lastrule != 0)
1992-01-11 19:37:36 +08:00
lastrule->next = next;
if (last_pattern_rule == rule)
last_pattern_rule = lastrule;
}
/* Create a new pattern rule with the targets in the nil-terminated array
TARGETS. TARGET_PERCENTS is an array of pointers to the % in each element
of TARGETS. N is the number of items in the array (not counting the nil
element). The new rule has dependencies DEPS and commands from COMMANDS.
1992-01-11 19:37:36 +08:00
It is a terminal rule if TERMINAL is nonzero. This rule overrides
identical rules with different commands if OVERRIDE is nonzero.
The storage for TARGETS and its elements and TARGET_PERCENTS is used and
must not be freed until the rule is destroyed. */
1992-01-11 19:37:36 +08:00
void
create_pattern_rule (const char **targets, const char **target_percents,
unsigned short n, int terminal, struct dep *deps,
struct commands *commands, int override)
1992-01-11 19:37:36 +08:00
{
unsigned int i;
struct rule *r = xmalloc (sizeof (struct rule));
1992-01-11 19:37:36 +08:00
r->num = n;
1992-01-11 19:37:36 +08:00
r->cmds = commands;
r->deps = deps;
r->targets = targets;
r->suffixes = target_percents;
r->lens = xmalloc (n * sizeof (unsigned int));
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
r->_defn = NULL;
1992-01-11 19:37:36 +08:00
for (i = 0; i < n; ++i)
1992-01-11 19:37:36 +08:00
{
r->lens[i] = (unsigned int) strlen (targets[i]);
assert (r->suffixes[i] != NULL);
++r->suffixes[i];
1992-01-11 19:37:36 +08:00
}
if (new_pattern_rule (r, override))
r->terminal = terminal ? 1 : 0;
1992-01-11 19:37:36 +08:00
}
/* Print the data base of rules. */
static void /* Useful to call from gdb. */
print_rule (struct rule *r)
1993-10-18 19:04:04 +08:00
{
[SV 61042] Enhance logging of implicit rule search Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
2021-10-18 06:03:04 +08:00
fputs (get_rule_defn (r), stdout);
putchar ('\n');
1993-10-18 19:04:04 +08:00
if (r->cmds != 0)
print_commands (r->cmds);
}
1992-01-11 19:37:36 +08:00
void
print_rule_data_base (void)
1992-01-11 19:37:36 +08:00
{
unsigned int rules, terminal;
struct rule *r;
1992-01-11 19:37:36 +08:00
puts (_("\n# Implicit Rules"));
1992-01-11 19:37:36 +08:00
1993-02-22 05:58:43 +08:00
rules = terminal = 0;
1992-01-11 19:37:36 +08:00
for (r = pattern_rules; r != 0; r = r->next)
{
++rules;
putchar ('\n');
1993-10-18 19:04:04 +08:00
print_rule (r);
1992-01-11 19:37:36 +08:00
1993-10-18 19:04:04 +08:00
if (r->terminal)
++terminal;
1992-01-11 19:37:36 +08:00
}
if (rules == 0)
puts (_("\n# No implicit rules."));
1992-01-11 19:37:36 +08:00
else
{
printf (_("\n# %u implicit rules, %u (%.1f%%) terminal."),
rules, terminal, (double) terminal / (double) rules * 100.0);
1992-01-11 19:37:36 +08:00
}
1992-07-15 07:08:36 +08:00
if (num_pattern_rules != rules)
{
/* This can happen if a fatal error was detected while reading the
makefiles and thus count_implicit_rule_limits wasn't called yet. */
if (num_pattern_rules != 0)
ONN (fatal, NILF, "INTERNAL: num_pattern_rules is wrong! %u != %u",
num_pattern_rules, rules);
}
1992-01-11 19:37:36 +08:00
}