Reputation: 58682
How to do the following in gnu make (on mac). I have files with extendion .js
and .jsx
which needs to go through the build.
SRC = $(shell find src -name '*.js' -o -name '*.jsx')
LIB = $(SRC:src/%=lib/%)
lib/%.js: src/%.js
@echo "building $@"
above only define the target for *.js
files. Now, to include *.jsx, I duplicated like below (which works).
lib/%.js: src/%.js
@echo "building $@"
lib/%.jsx: src/%.jsx
@echo "building $@"
Anyway to combine these. I tried like
lib/%.js%: src/%.js%
@echo "building $@"
but didn't work (make: *** No rule to make target
lib/abc.jsx', needed by build'. Stop.
)
duplicating the build for js & jsx
didn't give the same result as it causes duplication of files. The build process compile jsx
file and write as .js
. so, what I am trying to express is, for all files with extension
.js or .jsx, run it through the build process (which renames the compiled output as .js for both js and jsx
.
Upvotes: 0
Views: 2960
Reputation: 21000
One way is to use a static pattern. Also make has a builtin wildcard
function for simple file expansion
SRC := $(wildcard src/*.js src/*.jsx)
LIB := $(SRC:src/%=lib/%)
$(LIB): lib/%: src/%
@echo building $@ from $^
Upvotes: 1