You can't have two patterns. The best way would be not having map
twice in the target name.
If you must, and you're using GNU make, secondary expansion might be useful:
.SECONDEXPANSION:
$(Home)/ecc_%.gff: $$(word 1,$$(subst _, ,$$*)).fpp
Normally you can't use automatic variables such as $*
in prerequisites, but secondary expansion allows you to do just that. Note that I used $$
in place of $
so that the real expansion happens in the second pass and not in the first one.
Say you are making $(Home)/ecc_map_1st_map.gff
. The $*
variable is going to be the stem, i.e. map_1st_map
. Then $(subst _, ,...)
replaces underscores with spaces, to obtain map 1st map
. Now $(word N,...)
extracts the N-th space-separated word in there. First word would be the first map
, second would be 1st
, third would be the second map
. I'm picking the first one.
Of course this is pretty lax and doesn't guarantee you'll match exactly the targets you wanted ($(Home)/ecc_map_2nd_notmap__foo.gff
would match and give map.fpp
). You could do further checks (1st
in the middle, other two must match) and bail out:
extract-name = $(call extract-name-helper,$1,$(word 1,$(subst _, ,$1)))
extract-name-helper = $(if $(filter $2_1st_$2,$1),$2,$(error Invalid .gff target))
.SECONDEXPANSION:
ecc_%.gff: $$(call extract-name,$$*).fpp
But that doesn't look like a sensible solution.
Wrapping up, if don't have similarly named files, then the first solution would work well. Also, if you know the target names beforehand, you could make it safer with an explicit pattern rule (or even generate them on the fly).