Reputation: 558
I need to calculate a file path based on some subsytem names. See MWE below. Is there an easier way to achieve the same please? See my aa, ab, ac and join approach below.
I'm not keen on the double use of $(subsystem) as relies on make executing in the same order. I've tried using $(patsubst) but it only replaces the first instance of %. Any hints please?
#
## Given some subsystem names
subsystem := pi_sub_chris \
pi_sub_rob \
pi_sub_greg
#
## And an output directory
dir_export := ../pi_sw/export
#
## Calculate a file path in export directory to be made
## Is there a better way to do this!?
aa := $(addprefix $(dir_export)/,$(subsystem))
ab := $(addsuffix /a2l/, $(aa))
ac := $(addsuffix .a2l, $(subsystem))
files_to_be_made := $(join $(ab), $(ac))
.PHONY :
go : $(files_to_be_made)
@echo Done!
%.a2l :
@echo A perl script is run here to generate file $@
Which correctly outputs:
A perl script is run here to generate file ../pi_sw/export/pi_sub_chris/a2l/pi_sub_chris.a2l
A perl script is run here to generate file ../pi_sw/export/pi_sub_rob/a2l/pi_sub_rob.a2l
A perl script is run here to generate file ../pi_sw/export/pi_sub_greg/a2l/pi_sub_greg.a2l
Done!
Upvotes: 0
Views: 99
Reputation: 100781
There's no problem relying on the order in which these variables are expanded; that MUST be true or just about every makefile will break. It's absolutely guaranteed.
However, if you don't like it you could use something like:
files_to_be_made := $(foreach S,$(subsystem),$(dir_export)/$S/a21/$S.a21)
Upvotes: 3