help-gnu-utils
[Top][All Lists]
Advanced

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

Re: Preprocessing files with make


From: Paul D. Smith
Subject: Re: Preprocessing files with make
Date: 29 Aug 2004 13:53:35 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

%% Michael Chastain <mec.gnu@mindspring.com> writes:

  mc> "Paul D. Smith" <psmith@gnu.org> wrote:
  >> In what way does it interact poorly with other dependency rules?

  mc> If a static pattern rule matches a target, then it generates
  mc> warnings to override the generic static pattern rule with a
  mc> specialized rule.

Whoa, wait, now you've switched topics from pattern rules to STATIC
pattern rules!  Although the names are similar they are very different
things.  In your posts until you have always been showing pattern rules,
not static pattern rules.

A static pattern rule is actually best thought of as a way to generate a
lot of explicit rules using a pattern.  A pattern rule is a way to
define a class of targets that can be built with that rule.

So, creating a normal explicit rule that creates the same target as a
static pattern rule is the same as creating two explicit rules with the
same target, and you get a warning about that.

However, there will never be a warning for creating an explicit rule
that also matches a normal pattern rule.

  mc>   alpha.o: %.o
  mc>           cc -c $< -o $@ -DFOO

No; that is NOT a pattern rule!  That's an explicit rule to build
alpha.o saying it can be built from the literal filename '%.o'.

A pattern rule _MUST_ have a pattern character (%) in the target.  It is
optional for the prerequisite list, but it has to exist in the target.

  mc> This particular feature of static patterns rules is worse than
  mc> implicit rules.

I don't know what you mean by that, since they are not intended to be
equivalent in that way.

If you want to define a generic way to build targets that match a
pattern, use pattern rules.  If you want to define a specific way to
build a specific target, use explicit rules.  If you have a lot of
explicit rules to create where all the targets meet a specific pattern,
use a static pattern rule.

It doesn't make sense to define an explicit rule and a static pattern
rule for the same target: which one should make use?

  mc> Also, not a question of interaction, but a real limitation in gnu
  mc> make 3.79.1 at least: static pattern rules don't allow free use of
  mc> the "%" character in constructing dependencies.

Yes, but that's true of _ALL_ types of rules.  This is a simple
order-of-evaluation misunderstanding: when make runs it performs its
work in two distinct phases: the first phase reads in all the makefiles
and constructs an internal dependency graph.

The second phase walks that graph, running commands to update targets.

During the first phase is when all the evaluation of "immediate"
references (variables and functions) is performed.  This happens
_BEFORE_ any processing of patterns, etc.

  mc>   $(O_FILES): %.o: %.c $(dep_list_%)

So here the variable $(O_FILES) and the variable literally called
$(dep_list_%) are evaluated first, the latter expanding to the empty
string, before the rule is parsed.

It's pretty difficult to come up with an ordering that would behave the
way you would like, since the $(O_FILES) variable has to be expanded
before any patterns can be matched.

Even if such an ordering could be determined it would be very complex to
understand and implement, and there are plenty of situations where it
would not work.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@gnu.org>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist


reply via email to

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