help-make
[Top][All Lists]
Advanced

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

Re: Help with make rule


From: Paul Smith
Subject: Re: Help with make rule
Date: Thu, 20 Jan 2011 14:37:06 -0500

On Thu, 2011-01-20 at 14:23 -0500, Bob Bell wrote:
> What I'd really like to do is write a rule like this:
> 
> $(objdir)/%: | $(objdir)
> $(objdir): ; mkdir $@
> 
> The goal here is that all build output goes into a separate directory 
> $(objdir), and so I need to have all contents of the directory
> dependent on the creation of that directory.
> 
> I *could* bundle up all the contents of the directory and make them 
> explictly depend on the directory.  But I'd prefer something simpler
> and less prone to oversight.

I typically just force the directory to be created, with something like:

        __dummy := $(shell mkdir -p $(objdir))

This will be run before any rules.

> I presume the example above doesn't work because a pattern rule must
> be required to have % in both the target and the prerequisite.  

No.  You are allowed to declare pattern rules where there's no % in the
prerequisite.

It doesn't work because it's not legal to create a pattern rule that
doesn't have a recipe.  What you're trying to do is not create a pattern
rule, but rather create some kind of pattern-matched prerequisite
definition.  GNU make doesn't support that feature.

In the GNU make manual you'll see that a pattern rule that has no recipe
is defined to delete that rule.





reply via email to

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