[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simulating multiple wildcards in a match using .SECONDEXPANSION?
From: |
Danny Boelens |
Subject: |
Re: Simulating multiple wildcards in a match using .SECONDEXPANSION? |
Date: |
Mon, 06 Apr 2009 14:15:40 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Windows/20090302) |
Michael R. Head wrote:
I'd like to make a rule that generates a output file for each pair in
the cross product of two lists of input files. I have a simple makefile
that does what I want, but it's ugly.
I'm wondering if anyone has any suggestions on improving it. At a
minimum, I'd like to get rid of the foreachs in the targets.
You can do that because you know how you constructed the cross product
targets. In your case: if you replace the underscore ('_') with a space
(' '), the cross product target falls apart into its components again:
As=a1 a2 a3
Bs=b4 b5 b6
ABs=$(foreach a,$(As),$(foreach b,$(Bs),$(a)_$(b)))
empty :=
space := $(empty) $(empty)
A=$(word 1,$(subst _,$(space),$@))
B=$(word 2,$(subst _,$(space),$@))
A_SE=$$(word 1,$$(subst _,$(space),$$@))
B_SE=$$(word 2,$$(subst _,$(space),$$@))
all: $(ABs)
$(As) $(Bs):
.SECONDEXPANSION:
$(ABs): $(A_SE) $(B_SE)
@echo $@: $^
@echo A=$A, B=$B
But looking at your original problem description, I think I'd use
another approach to solve it. One using a define as 'rule template',
because it's a bit easier to read and understand in my opinion - but
that might be just me. Something like this (untested):
As=a1 a2 a3
Bs=b4 b5 b6
.PHONY: all
all:
$(As) $(Bs) :
define MyRule
all : $(1)_$(2)
$(1)_$(2) : $(1) $(2)
@echo $$@ : $$^
@echo A=$1, B=$2
endef
$(foreach a,$(As),$(foreach b,$(Bs),$(eval $(call MyRule,$(a),$(b)))))
Hope this helps,
Danny