使用多个扩展名制作目标

时间:2015-05-28 16:42:59

标签: makefile

如何在gnu make(在mac上)执行以下操作。我有扩展名.js.jsx的文件需要完成构建。

SRC = $(shell find src -name '*.js' -o -name '*.jsx')
LIB = $(SRC:src/%=lib/%)
lib/%.js: src/%.js
    @echo "building $@"
上面

仅定义*.js个文件的目标。现在,为了包含* .jsx,我重复如下(有效)。

lib/%.js: src/%.js
    @echo "building $@"

lib/%.jsx: src/%.jsx
    @echo "building $@"

无论如何要结合这些。我试过像

lib/%.js%: src/%.js%
    @echo "building $@"

但没有工作(make: *** No rule to make target lib / abc.jsx&#39;,build'. Stop.需要<)

编辑:

重复js & jsx的构建没有给出与导致文件重复相同的结果。构建过程编译jsx文件并写为.js。所以,我想表达的是,for all files with extension。js或.jsx , run it through the build process (which renames the compiled output as .js for both js and jsx

1 个答案:

答案 0 :(得分:1)

一种方法是使用静态模式。另外make还有一个用于简单文件扩展的内置wildcard函数

SRC := $(wildcard src/*.js src/*.jsx)
LIB := $(SRC:src/%=lib/%)

$(LIB): lib/%: src/%
    @echo building $@ from $^