Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable substitution in Makefile target dependency

I have a Makefile with targets that have associated dependencies. So I use lookup table like:

APPS = a b c

dependency.lookup.a := x
dependency.lookup.b := y
dependency.lookup.c := z

$(APPS): %: path/$(dependency.lookup.%).datafile
    do something with $(dependency.lookup.$@)

This makefile gives me error. *** No rule to make target 'path/.datafile'

Constraints: Only MinGW. can't use shell/MSYS. Also support FreeBSD.

like image 596
Mohammad Azim Avatar asked Feb 04 '23 19:02

Mohammad Azim


1 Answers

This requires using Secondary Expansion feature:

.SECONDEXPANSION:
$(APPS): %: path/$$(dependency.loopup.$$*).datafile
    @echo "$@ depends on $^"

%.datafile : # Create one on demand for testing.
    mkdir -p ${@D}
    touch $@

Outputs:

mkdir -p path/
touch path/x.datafile
a depends on path/x.datafile

Alternatively, use regular dependencies:

a : path/x.datafile
b : path/y.datafile
c : path/z.datafile

$(APPS): % :
    @echo "$@ depends on $^"

The top 3 lines only add dependencies, the rule is specified separately. The output is the same.

like image 194
Maxim Egorushkin Avatar answered Mar 05 '23 17:03

Maxim Egorushkin