How to target multiple directories with a single Makefile?

元气小坏坏 提交于 2019-12-10 19:38:55

问题


I'm using GNU Make to build three different editions of a static html document.

I use 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 list a target rule for each directory. Instead, I tried adding this rule instead of the three directory specific ones:

%: %/style.css

But that does not work. I assume it's clear from that example what my goal is. Is there a way to accept any directory as a target, so that I just have to list the directory names in the all: rule?


回答1:


use static pattern rule:

res_dirs = 160x600 300x250 728x90

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


来源:https://stackoverflow.com/questions/14400732/how-to-target-multiple-directories-with-a-single-makefile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!