[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Recursive $(call)
From: |
Philip Guenther |
Subject: |
Recursive $(call) |
Date: |
Fri, 22 Feb 2002 18:08:43 -0800 |
It would greatly increase the expressiveness of GNU make's macro
expansion if it was possible to define recursive macro functions. For
example, here's a function that performs calculates the transitive
closure of a set of dependencies:
# If $(firstword) is car, this is cdr:
rest = $(wordlist 1,$(words ${1}),${1})
tclose = $(if ${1},$(firstword ${1}) \
$(call tclose,$(sort ${DEP_$(firstword ${1})} \
$(call rest,${1}))))
You could then define variables ala:
DEP_foo = bar baz quux
DEP_baz = quux blarp
and expect $(sort $(call tclose,foo)) to expand to "bar baz blarp quux"
Unfortunately, the restriction on recursive macros not referencing
themselves includes references via $(call). I would argue that GNU make
should not try to protect someone from themself if the write a recursive
$(call). Yes, you can trivially write infinite loops if it's allowed,
but the increase in expressiveness is substantial.
(Yes, you can write a version of tclose that expands the dependencies up
to a present depth, but that's a kludge. I would rather call out to the
shell and do the full expansion there then do that.)
Philip Guenther
- Recursive $(call),
Philip Guenther <=