How do I target multiple directories with a single Makefile?

I am using GNU Make to create three different editions of a static html document.

I am using Less as a CSS preprocessor.

My directory structure looks like this:

Makefile
160x600/style.less
300x250/style.less
728x90/style.less

      

This is my Makefile:

LESSC=lessc -x # use -x for debugging

.PHONY: all clean

all: 160x600 300x250 728x90

%.css: %.less
    $(LESSC) $< > $@

160x600: 160x600/style.css
300x250: 300x250/style.css
728x90: 728x90/style.css

clean:
    rm -f 160x600/*.css
    rm -f 300x250/*.css
    rm -f 728x90/*.css

      

This way I can use make 160x600

to build style.css from style.less.

But I don't want to explicitly specify the target rule for each directory. Instead, I tried to add this rule instead of three specific directories:

%: %/style.css

      

But it doesn't work. I guess this example shows what my purpose is. Is there a way to accept any directory as a target so that I just need to specify the directory names in the rule all:

?

+3


source to share


1 answer


use static template rule :



res_dirs = 160x600 300x250 728x90

$(res_dirs): %: %/style.css

      

+3


source







All Articles