【问题标题】:How to target multiple directories with a single Makefile?如何使用单个 Makefile 定位多个目录?
【发布时间】:2013-01-02 06:29:01
【问题描述】:

我正在使用 GNU Make 构建三个不同版本的静态 html 文档。

我使用 Less 作为 CSS 预处理器。

我的目录结构如下:

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

这是我的 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

这样,我可以使用make 160x600 从 style.less 构建 style.css。

但我不想明确列出每个目录的目标规则。相反,我尝试添加此规则而不是三个特定于目录的规则:

%: %/style.css

但这不起作用。我认为从那个例子中可以清楚地看出我的目标是什么。有没有办法接受任何目录作为目标,这样我只需在all: 规则中列出目录名称?

【问题讨论】:

标签: makefile less


【解决方案1】:

使用static pattern rule:

res_dirs = 160x600 300x250 728x90

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

【讨论】:

  • 谢谢,第一种方法效果很好 :) 合并后的版本不行。
  • @DaniloBargen,对,我明白了。不合并比较容易,第二个变种我删了。
猜你喜欢
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-16
  • 2020-04-25
  • 1970-01-01
相关资源
最近更新 更多