Pierre-Antoine Guillaume
Pierre-Antoine Guillaume

Reputation: 1126

Makefile combine similar rules

I have in my makefile some similar rules:


include .env
include .env.local


var/make/.env: .env | var/make
    @sed 's/=/?=/' $< > $@

var/make/.env.local: .env.local | var/make
    @sed 's/=/?=/' $< > $@

var/make:
    mkdir $@

Is there a way to make a generic rule ?

var/make/.env*: name-matching-previous-.env* | var/make
    @sed 's/=/?=/' $< > $@

.env* being one file at a time

Upvotes: 0

Views: 29

Answers (1)

Beta
Beta

Reputation: 99084

Yes, you can write a pattern rule:

var/make/.en%: .en% | var/make
    @sed 's/=/?=/' $< > $@

The % matches the variable part of the target name. (The target must end in en% and not env% because the % cannot match an empty string.)

Upvotes: 1

Related Questions