Fix order-only prerequisites for pattern rules. (Savannah patch #2349).

Add a regression test for this.

Older libraries don't allow *alloc(0), so make sure we don't ever do that.
This commit is contained in:
Paul Smith 2004-01-07 19:36:39 +00:00
parent ee3d37a591
commit a35db90275
6 changed files with 64 additions and 5 deletions

View File

@ -11,7 +11,7 @@ makebook*
*.dep *.dvi *.toc *.aux *.log
*.cp *.cps *.fn *.fns *.vr *.vrs *.tp *.tps *.ky *.kys *.pg *.pgs
README README.DOS README.W32
README README.DOS README.W32 README.OS2
aclocal.m4 autom4te.cache
config.h.in config.h config.status config.cache configure
Makefile.in Makefile

View File

@ -1,3 +1,10 @@
2004-01-07 Paul D. Smith <psmith@gnu.org>
* implicit.c (pattern_search): When matching an implicit rule,
remember which dependencies have the ignore_mtime flag set.
Original fix provided in Savannah patch #2349, by Benoit
Poulot-Cazajous <Benoit.Poulot-Cazajous@jaluna.com>.
2003-11-02 Paul D. Smith <psmith@gnu.org>
* function.c (func_if): Strip all the trailing whitespace from the
@ -17,6 +24,11 @@
(get-config/config.guess get-config/config.sub): Get these files
from the Savannah config project instead of ftp.gnu.org.
2003-08-22 Paul D. Smith <psmith@gnu.org>
* misc.c (xmalloc, xrealloc): Add one to 0 sizes, to cater to
systems which don't yet implement the C89 standard :-/.
2003-07-18 Paul D. Smith <psmith@gnu.org>
* dir.c (directory_contents_hash_1, directory_contents_hash_1)

View File

@ -103,6 +103,8 @@ pattern_search (struct file *file, int archive,
/* This buffer records all the dependencies actually found for a rule. */
char **found_files = (char **) alloca (max_pattern_deps * sizeof (char *));
/* This list notes if the associated dep has an "ignore_mtime" flag set. */
unsigned char *found_files_im = (unsigned char *) alloca (max_pattern_deps * sizeof (unsigned char));
/* Number of dep names now in FOUND_FILES. */
unsigned int deps_found = 0;
@ -397,6 +399,7 @@ pattern_search (struct file *file, int archive,
if (lookup_file (p) != 0
|| ((!dep->changed || check_lastslash) && file_exists_p (p)))
{
found_files_im[deps_found] = dep->ignore_mtime;
found_files[deps_found++] = xstrdup (p);
continue;
}
@ -408,6 +411,7 @@ pattern_search (struct file *file, int archive,
DBS (DB_IMPLICIT,
(_("Found prerequisite `%s' as VPATH `%s'\n"), p, vp));
strcpy (vp, p);
found_files_im[deps_found] = dep->ignore_mtime;
found_files[deps_found++] = vp;
continue;
}
@ -437,11 +441,11 @@ pattern_search (struct file *file, int archive,
intermediate_file->name = p;
intermediate_files[deps_found] = intermediate_file;
intermediate_file = 0;
found_files_im[deps_found] = dep->ignore_mtime;
/* Allocate an extra copy to go in FOUND_FILES,
because every elt of FOUND_FILES is consumed
or freed later. */
found_files[deps_found] = xstrdup (p);
++deps_found;
found_files[deps_found++] = xstrdup (p);
continue;
}
@ -541,7 +545,7 @@ pattern_search (struct file *file, int archive,
}
dep = (struct dep *) xmalloc (sizeof (struct dep));
dep->ignore_mtime = 0;
dep->ignore_mtime = found_files_im[deps_found];
s = found_files[deps_found];
if (recursions == 0)
{

5
misc.c
View File

@ -357,7 +357,8 @@ pfatal_with_name (const char *name)
char *
xmalloc (unsigned int size)
{
char *result = (char *) malloc (size);
/* Make sure we don't allocate 0, for pre-ANSI libraries. */
char *result = (char *) malloc (size ? size : 1);
if (result == 0)
fatal (NILF, _("virtual memory exhausted"));
return result;
@ -370,6 +371,8 @@ xrealloc (char *ptr, unsigned int size)
char *result;
/* Some older implementations of realloc() don't conform to ANSI. */
if (! size)
size = 1;
result = ptr ? realloc (ptr, size) : malloc (size);
if (result == 0)
fatal (NILF, _("virtual memory exhausted"));

View File

@ -1,3 +1,8 @@
2004-01-07 Paul D. Smith <psmith@gnu.org>
* scripts/features/order_only: Test order-only prerequisites in
pattern rules (patch #2349).
2003-11-02 Paul D. Smith <psmith@gnu.org>
* scripts/functions/if: Test if on conditionals with trailing

View File

@ -109,4 +109,39 @@ $answer = "touch baz\n";
unlink(qw(foo baz));
# Test order-only in pattern rules
$makefile4 = &get_tmpfile;
open(MAKEFILE,"> $makefile4");
print MAKEFILE <<'EOF';
%.w : %.x | baz
@echo '$$^ = $^'
@echo '$$| = $|'
touch $@
all: foo.w
.PHONY: baz
foo.x baz:
touch $@
EOF
close(MAKEFILE);
# TEST #7 -- make sure the parser was correct.
&run_make_with_options($makefile4, "", &get_logfile);
$answer = "touch foo.x\ntouch baz\n\$^ = foo.x\n\$| = baz\ntouch foo.w\n";
&compare_output($answer,&get_logfile(1));
# TEST #8 -- now we do it again: this time foo.w won't be built
&run_make_with_options($makefile4, "", &get_logfile);
$answer = "touch baz\n";
&compare_output($answer,&get_logfile(1));
unlink(qw(foo.w foo.x baz));
1;