help-make
[Top][All Lists]
Advanced

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

Re: wildcard dependency


From: Luke Shumaker
Subject: Re: wildcard dependency
Date: Wed, 29 Dec 2010 13:34:45 -0500

On Wed, 2010-12-29 at 13:32 +0100, Warlich, Christof wrote:
> Hi,
> 
> I need to ensure that a certain tool is generated before any reciepes are 
> executed for a certain extension. To better understand what I need, consider 
> the following makefile:
> 
> xxx.ext:
>     ./tool
> 
> xxx.ext: tool # This works as expected.
> #$(wildcard *.ext: tool) # Why doesn't this cause "tool" to be made before 
> xxx.j is made, as the line before does?
> tool:
>     echo touch xxx.ext > $@
>     chmod 755 $@
> 
> Please consider that I have a few tousands of files, being handled in almost 
> hundred sub-makefiles. Thus I don't want to add this dependency eveywhere.
> 
> Thanks for any ideas,
> 
> Christof

Well, first, the syntax of wildcard is wrong, it should be:
$(wildcard *.ext): tool
However, wildcard only matches files that _already_ exist, so it won't
help you much when making these files.

What you want is a pattern rule:
%.ext: tool

As for not wanting to edit a hundred makefiles, the *NIX command line is
wonderful for this:
find . -name '*.mk' -print0|xargs -0 sed -i 
's/^\s*\(.*\)\.ext\s*:\s*\(.*\)/\1.ext: \2 tool/' -- Makefile

There special cases where that would break, such as if multiple targets
are given on the same line and the .ext one isn't last, or if it already
has dependencies given and they span multiple lines via \.

But yeah, the pattern rule is probably the best option.

-- 
~ LukeShu
http://lukeshu.ath.cx/




reply via email to

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