bsr
bsr

Reputation: 58682

make target with multiple extension

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 targetlib/abc.jsx', needed by build'. Stop.)

EDIT:

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

Answers (1)

user657267
user657267

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

Related Questions