[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug or correct behavior?

From: Mike Shal
Subject: Re: Bug or correct behavior?
Date: Tue, 5 Feb 2008 14:45:28 -0500

On 2/5/08, Derek Clegg <address@hidden> wrote:
> Given this simple makefile
> start: dir/a.c
> dir/%.c: %.c | dir ; cp $< $@
> dir/%.c: foo.h
> dir: ; mkdir $@
> a.c foo.h: ; touch $@
> I'm seeing the following when I run make:
> touch a.c
> mkdir dir
> cp a.c dir/a.c
> This is surprising; my expectation is that the dependency "dir/%c.:
> foo.h" would force "foo.h" to be created as well.  Is this a bug or
> correct behavior?  My reading of the manual has led me to believe it's
> a bug, but since it's not explicitly addressed in the manual, I'm not
> completely sure.

Pattern rules are treated a little differently. Specifically, see
section 10.5.1 "Introduction to Pattern Rules" in the make info pages:

  The order in which pattern rules appear in the makefile is important
  since this is the order in which they are considered.  Of equally
  applicable rules, only the first one found is used.

In your example, only the first pattern rule will apply, and the foo.h
dependency will be ignored. You could move foo.h to the line above and
have a single pattern rule to get your expected behavior in this case.
If your actual Makefiles are a bit more complex, you may want to look
into static pattern rules as well to provide a little more
fine-grained control.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]