help-make
[Top][All Lists]
Advanced

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

Re: Single rule with dependencies with different suffixes


From: Paul Smith
Subject: Re: Single rule with dependencies with different suffixes
Date: Wed, 28 Jan 2009 10:10:43 -0500

On Wed, 2009-01-28 at 00:51 -0600, Paul Smith wrote:
> Let's say I have a Makefile with two sets of source files that differ
> by their suffix, but I want the same command to be applied to them:
> 
> # begin
> 
> JS_SRCS = foo.js bar.js
> CSS_SRCS = quux.css frob.css
> 
> %.min.js : %.js
>       minify $< > $@
> 
> %.min.css : %.css
>       minify $< > $@
> 
> all : ${JS_SRCS} ${CSS_SRCS}
> 
> # end
> 
> So make would produce: foo.min.js bar.min.js quux.min.css frob.min.css
> 
> Is it possible to combine the two rules with the minify command into a
> single rule?

No, not if I understand you correctly (you do need to run minify twice,
once for each target, but you just don't want to write it twice in the
makefile... right?)

The best you can do is put the command in a variable and re-use that
variable:

        MINIFY = minify $< > $@
        
        %.min.js: %.js
                $(MINIFY)
        %.min.css: %.css
                $(MINIFY)

While you still have two rules at least you have a single point of
modification if you need to change the command.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "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]