[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Recommended Method for adding recursive targets
From: |
Stefano Lattarini |
Subject: |
Re: Recommended Method for adding recursive targets |
Date: |
Fri, 19 Aug 2011 21:42:33 +0200 |
User-agent: |
KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; ) |
Hi Daniel. Just a quick answer, as I'm in a hurry ...
On Friday 19 August 2011, Daniel Neuberger wrote:
> I'm seen a couple of recommendations on this, but no consensus.
> Currently to make sometarget recursive, I add the following above the
> target:
>
> sometarget-%:
> $(MAKE) -C $* sometarget
> sometarget: $(foreach dir, $(SUBDIRS), sometarget-$(dir))
>
These are specific to GNU make though. And if that limitation is OK
with you, be aware that the above will cause a fork bomb if SUBDIRS
contains `.' -- yikes!
I think that if the "sometarget"s in the subdirs can be executed
concurrently, this slightly edited version should work:
sometarget-%:
$(MAKE) -C $* sometarget
sometarget: $(foreach dir, $(filter-out .,$(SUBDIRS)), sometarget-$(dir))
> Suggestions for improvement?
>
I guess your best bet if you want to be portable is to emulate the code
generated by automake for recursive targets (we did something similar for
some custom recursive targets in the automake's own build system); e.g.
(untested!):
$(MY_RECUSRIVE_TARGETS):
@failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
*=* | --[!k]*);; \
*k*) failcom='fail=yes';; \
esac; \
done; \
for subdir in $(SUBDIRS); do \
test "$$subdir" = . && continue; \
($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@) \
|| eval $$failcom; \
done; \
test -z "$$fail"
This doesn't handle subdirs cuncurrently though, even when one runs
"make -jN"; this can be seens either as a feature or as a bug, depending
on the circumstances. Also, be aware that $(am__cd) is an internal
detail, so you might want to unset CDPATH by hand early in the recipe,
and then use simply `cd'.
HTH,
Stefano