* Handle case of empty static pattern rule prerequisites.

* Fix linenumbers in error messages for rule definitions.
This commit is contained in:
Paul Smith 2000-03-27 20:53:50 +00:00
parent c637af71d9
commit 4145bcbcda
6 changed files with 75 additions and 53 deletions

View file

@ -1,5 +1,15 @@
2000-03-27 Paul D. Smith <psmith@gnu.org> 2000-03-27 Paul D. Smith <psmith@gnu.org>
* read.c (record_files): Check if expanding a static pattern
rule's prerequisite pattern leaves an empty string as the
prerequisite, and issue an error if so. Fixes PR/1670.
(read_makefile): Store the starting linenumber for a rule in
TGTS_STARTED.
(record_waiting_files): Use the TGTS_STARTED value for the file
location passed to record_file() instead of the current
linenumber, so error messages list the line where the target was
defined instead of the line after the end of the rule definition.
* remake.c (start_updating, finish_updating, is_updating): Fix * remake.c (start_updating, finish_updating, is_updating): Fix
PR/1671; circular dependencies in double-colon rules are not PR/1671; circular dependencies in double-colon rules are not
diagnosed. These macros set the updating flag in the root diagnosed. These macros set the updating flag in the root
@ -28,8 +38,8 @@
2000-03-23 Paul Eggert <eggert@twinsun.com> 2000-03-23 Paul Eggert <eggert@twinsun.com>
* filedef.h (FILE_TIMESTAMP_STAT_MODTIME): Don't use * filedef.h (FILE_TIMESTAMP_STAT_MODTIME): Use st_mtime instead of
st_mtim.tv_sec; this doesn't work on Unixware. st_mtim.tv_sec; the latter doesn't work on Unixware.
2000-03-18 Paul D. Smith <psmith@gnu.org> 2000-03-18 Paul D. Smith <psmith@gnu.org>

8
NEWS
View file

@ -1,6 +1,6 @@
GNU make NEWS -*-indented-text-*- GNU make NEWS -*-indented-text-*-
History of user-visible changes. History of user-visible changes.
25 Jan 2000 27 Mar 2000
Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
See the end for copying conditions. See the end for copying conditions.
@ -36,12 +36,6 @@ Version 3.79
current makefile is run serially regardless of the value of -j. current makefile is run serially regardless of the value of -j.
However, submakes are still eligible for parallel execution. However, submakes are still eligible for parallel execution.
* The $(call ...) function doesn't expand its arguments automatically
anymore. This allows you to put builtin functions like "if" and
"foreach", which also have special expansion rules, in a $(call ...)
function and have it work properly. This was suggested by Damien
GIBOU <damien.gibou@st.com>.
* The --debug option has changed: it now allows optional flags * The --debug option has changed: it now allows optional flags
controlling the amount and type of debugging output. By default only controlling the amount and type of debugging output. By default only
a minimal amount information is generated, displaying the names of a minimal amount information is generated, displaying the names of

3
file.c
View file

@ -58,8 +58,7 @@ lookup_file (name)
register char *lname, *ln; register char *lname, *ln;
#endif #endif
if (*name == '\0') assert (*name != '\0');
abort ();
/* This is also done in parse_file_seq, so this is redundant /* This is also done in parse_file_seq, so this is redundant
for names read from makefiles. It is here for names passed for names read from makefiles. It is here for names passed

25
read.c
View file

@ -287,7 +287,7 @@ read_makefile (filename, flags)
unsigned int commands_len = 200; unsigned int commands_len = 200;
char *commands; char *commands;
unsigned int commands_idx = 0; unsigned int commands_idx = 0;
unsigned int cmds_started; unsigned int cmds_started, tgts_started;
char *p; char *p;
char *p2; char *p2;
int len, reading_target; int len, reading_target;
@ -313,9 +313,13 @@ read_makefile (filename, flags)
{ \ { \
if (filenames != 0) \ if (filenames != 0) \
{ \ { \
int lineno = fileinfo.lineno; \
struct floc fi; \
fi.filenm = fileinfo.filenm; \
fi.lineno = tgts_started; \
record_files (filenames, pattern, pattern_percent, deps, \ record_files (filenames, pattern, pattern_percent, deps, \
cmds_started, commands, commands_idx, two_colon, \ cmds_started, commands, commands_idx, two_colon, \
&fileinfo, !(flags & RM_NO_DEFAULT_GOAL)); \ &fi, !(flags & RM_NO_DEFAULT_GOAL)); \
using_filename |= commands_idx > 0; \ using_filename |= commands_idx > 0; \
} \ } \
filenames = 0; \ filenames = 0; \
@ -327,7 +331,7 @@ read_makefile (filename, flags)
fileinfo.lineno = 1; fileinfo.lineno = 1;
pattern_percent = 0; pattern_percent = 0;
cmds_started = fileinfo.lineno; /* cmds_started = fileinfo.lineno; */
if (ISDB (DB_VERBOSE)) if (ISDB (DB_VERBOSE))
{ {
@ -755,6 +759,7 @@ read_makefile (filename, flags)
/* Record the previous rule. */ /* Record the previous rule. */
record_waiting_files (); record_waiting_files ();
tgts_started = fileinfo.lineno;
/* Search the line for an unquoted ; that is not after an /* Search the line for an unquoted ; that is not after an
unquoted #. */ unquoted #. */
@ -1540,7 +1545,7 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
char *implicit_percent; char *implicit_percent;
nextf = filenames->next; nextf = filenames->next;
free ((char *) filenames); free (filenames);
implicit_percent = find_percent (name); implicit_percent = find_percent (name);
implicit |= implicit_percent != 0; implicit |= implicit_percent != 0;
@ -1608,6 +1613,12 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
continue; continue;
o = patsubst_expand (buffer, name, pattern, d->name, o = patsubst_expand (buffer, name, pattern, d->name,
pattern_percent, percent); pattern_percent, percent);
/* If the name expanded to the empty string, that's
illegal. */
if (o == buffer)
fatal (flocp,
_("target `%s' leaves prerequisite pattern empty"),
name);
free (d->name); free (d->name);
d->name = savestring (buffer, o - buffer); d->name = savestring (buffer, o - buffer);
} }
@ -1627,7 +1638,8 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
/* If CMDS == F->CMDS, this target was listed in this rule /* If CMDS == F->CMDS, this target was listed in this rule
more than once. Just give a warning since this is harmless. */ more than once. Just give a warning since this is harmless. */
if (cmds != 0 && cmds == f->cmds) if (cmds != 0 && cmds == f->cmds)
error (flocp, _("target `%s' given more than once in the same rule."), error (flocp,
_("target `%s' given more than once in the same rule."),
f->name); f->name);
/* Check for two single-colon entries both with commands. /* Check for two single-colon entries both with commands.
@ -1636,7 +1648,8 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
else if (cmds != 0 && f->cmds != 0 && f->is_target) else if (cmds != 0 && f->cmds != 0 && f->is_target)
{ {
error (&cmds->fileinfo, error (&cmds->fileinfo,
_("warning: overriding commands for target `%s'"), f->name); _("warning: overriding commands for target `%s'"),
f->name);
error (&f->cmds->fileinfo, error (&f->cmds->fileinfo,
_("warning: ignoring old commands for target `%s'"), _("warning: ignoring old commands for target `%s'"),
f->name); f->name);

View file

@ -1,5 +1,9 @@
2000-03-27 Paul D. Smith <psmith@gnu.org> 2000-03-27 Paul D. Smith <psmith@gnu.org>
* scripts/features/statipattrules: Test that static pattern rules
whose prerequisite patterns resolve to empty strings throw an
error (instead of dumping core). Fixes PR/1670.
* scripts/features/reinvoke: Make more robust by touching "b" * scripts/features/reinvoke: Make more robust by touching "b"
first, to ensure it's not newer than "a". first, to ensure it's not newer than "a".
Reported by Marco Franzen <Marco.Franzen@Thyron.com>. Reported by Marco Franzen <Marco.Franzen@Thyron.com>.
@ -7,7 +11,8 @@
* scripts/functions/call: Whoops. The fix to PR/1527 caused * scripts/functions/call: Whoops. The fix to PR/1527 caused
recursive invocations of $(call ...) to break. I can't come up recursive invocations of $(call ...) to break. I can't come up
with any way to get both working at the same time, so I backed out with any way to get both working at the same time, so I backed out
the fix to 1527 and added a test case for recursive calls. the fix to 1527 and added a test case for recursive calls. This
also tests the fix for PR/1610.
* scripts/features/double_colon: Test that circular dependencies * scripts/features/double_colon: Test that circular dependencies
in double-colon rule sets are detected correctly (PR/1671). in double-colon rule sets are detected correctly (PR/1671).

View file

@ -1,66 +1,67 @@
$description = "The following test creates a makefile to test static \n" # -*-perl-*-
."pattern rules. Static pattern rules are rules which \n" $description = "Test handling of static pattern rules.";
."specify multiple targets and construct the dependency \n"
."names for each target based on the target name. ";
$details = "The makefile created in this test has three targets. The \n" $details = "\
."filter command is used to get those target names ending in \n" The makefile created in this test has three targets. The
.".o and statically creates a compile command with the target\n" filter command is used to get those target names ending in
."name and the target name with .c. It also does the same thing\n" .o and statically creates a compile command with the target
."for another target filtered with .elc and creates a command\n" name and the target name with .c. It also does the same thing
."to emacs a .el file"; for another target filtered with .elc and creates a command
to emacs a .el file";
open(MAKEFILE,"> $makefile"); open(MAKEFILE,"> $makefile");
print MAKEFILE <<'EOF';
files = foo.elc bar.o lose.o
# The Contents of the MAKEFILE ... $(filter %.o,$(files)): %.o: %.c ; @echo CC -c $(CFLAGS) $< -o $@
print MAKEFILE "files = foo.elc bar.o lose.o \n\n"
."\$(filter %.o,\$(files)): %.o: %.c\n"
."\t\@echo CC -c \$(CFLAGS) \$< -o \$@ \n"
."\$(filter %.elc,\$(files)): %.elc: %.el \n"
."\t\@echo emacs \$< \n";
# END of Contents of MAKEFILE
$(filter %.elc,$(files)): %.elc: %.el ; @echo emacs $<
EOF
close(MAKEFILE); close(MAKEFILE);
&touch("bar.c","lose.c");
&touch('bar.c', 'lose.c');
# TEST #1 # TEST #1
# ------- # -------
&run_make_with_options($makefile, &run_make_with_options($makefile, '', &get_logfile);
"",
&get_logfile,
0);
# Create the answer to what should be produced by this Makefile
$answer = "CC -c bar.c -o bar.o\n"; $answer = "CC -c bar.c -o bar.o\n";
&compare_output($answer,&get_logfile(1)); &compare_output($answer, &get_logfile(1));
# TEST #2 # TEST #2
# ------- # -------
&run_make_with_options($makefile,"lose.o",&get_logfile);
&run_make_with_options($makefile, 'lose.o', &get_logfile);
$answer = "CC -c lose.c -o lose.o\n"; $answer = "CC -c lose.c -o lose.o\n";
&compare_output($answer, &get_logfile(1));
&compare_output($answer,&get_logfile(1));
# TEST #3 # TEST #3
# ------- # -------
&touch("foo.el"); &touch("foo.el");
&run_make_with_options($makefile,"foo.elc",&get_logfile); &run_make_with_options($makefile, 'foo.elc', &get_logfile);
$answer = "emacs foo.el\n"; $answer = "emacs foo.el\n";
&compare_output($answer, &get_logfile(1));
&compare_output($answer,&get_logfile(1));
unlink('foo.el', 'bar.c', 'lose.c');
# TEST #4 -- PR/1670: don't core dump on invalid static pattern rules
# -------
$makefile2 = &get_tmpfile;
open(MAKEFILE, "> $makefile2");
print MAKEFILE "foo: foo%: % ; \@echo $@\n";
close(MAKEFILE);
&run_make_with_options($makefile2, '', &get_logfile, 512);
$answer = "$makefile2:1: *** target `foo' leaves prerequisite pattern empty. Stop.\n";
&compare_output($answer, &get_logfile(1));
unlink("foo.el","bar.c","lose.c");
1; 1;