Denisof
Denisof

Reputation: 336

Makefile double extension pattern matching

How to write the correct Makefile if I want to define generic targets of the form a.ext1.new_ext, a.ext2.new_ext, b.ext1.new_ext, b.ext2.new_ext etc. with prerequisites a.ext1, a.ext2, b.ext1, b.ext2 respectively? Kind of this but general rule:

a.ext1.new_ext: a.ext1
    compiler --input a.ext1 --output a.ext1.new_ext

a.ext2.new_ext: a.ext2
    compiler --input a.ext2 --output a.ext2.new_ext

b.ext1.ext: b.ext1
    compiler --input b.ext1 --output b.ext1.new_ext

b.ext2.new_ext: b.ext2
    compiler --input b.ext2 --output b.ext2.new_ext

...

Thanks!

P.S. I call Makefile from root directory ., prerequisites are in ./src/folder and I need the output in ./build/folder. More precisely, my Makefile:

SRC := $(shell find ./src -type f \( -name '*.ext1' -or -name '*.ext2' \))
OBJ := $(patsubst ./src%, ./build%, $(SRC))
OBJ := $(addsuffix .ext, $(OBJ))

# Doesn't work
%.ext: %
    mkdir -p $(dir $@)
    compiler --input $< --output $@

Upvotes: 0

Views: 44

Answers (2)

Denisof
Denisof

Reputation: 336

It seems the solution is:

./build/%.spv : ./src/%
    mkdir -p $(dir $@)
    $(GLSL) $(GLSL_FLAGS) $< -o $@

Thanks for you suggestions!

Upvotes: 0

MadScientist
MadScientist

Reputation: 100866

What is wrong with:

%.new_ext: %
        compiler --input $< --output $@

? If what you tried doesn't work, it's better to show us what you tried and copy/paste the not-working thing, than to ask a generic question which might lead us to give answers that don't solve your actual problem.

Upvotes: 1

Related Questions