[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why doesn't this work properly?
From: |
Philip Guenther |
Subject: |
Re: Why doesn't this work properly? |
Date: |
Sat, 1 Sep 2007 02:50:34 -0600 |
On 8/31/07, Rick Flower <address@hidden> wrote:
...
> You've completely solved my problem except for one minor issue -- what if
> some of these stubs live in multiple directories?:
>
> ${TOP_DIR}/teststubs/common/src/
> ${TOP_DIR}/teststubs/hardware/src/
> etc
>
> Ideally, I'm specifying the full paths in my Makefile as I indicated in my
> initial email.. However, I was simplifying things for simplicity.. Is there
> any easy way to extend this for multiple directories as well? I tried
> reading up on static pattern rules in the GNU Make help and it indicates
> that I can use multiple "dep-patterns".. However, when I tried it didn't
> seem to find things anymore :
>
> $(notdir $(TESTSTUB_SOURCES)): %: ${TOP_DIR}/teststubs/hardware/src/% \
> ${TOP_DIR}/teststubs/common/src/%
> ln -sf $< $@
That requires all the possibilities to exist, and then always makes a
link to the one under 'hardware'. There are two ways to do what you
want:
1) include a static pattern rule for each source directory:
# create static rules for all the files under .../hardware/src/
$(notdir $(filter \
${TOP_DIR}/teststubs/hardware/src/%,$(TESTSTUB_SOURCES))): %: \
${TOP_DIR}/teststubs/hardware/src/%
ln -sf $< $@
# create static rules for all the files under .../common/src/
$(notdir $(filter \
${TOP_DIR}/teststubs/common/src/%,$(TESTSTUB_SOURCES))): %: \
${TOP_DIR}/teststubs/common/src/%
ln -sf $< $@
# etc...
2) instead of specifying the full path of each stub, just specify the name
and let make pick the path by searching the directories in some order
by supplying multiple pattern rules:
# make tries these in order
%: ${TOP_DIR}/teststubs/hardware/src/%
ln -sf $< $@
%: ${TOP_DIR}/teststubs/common/src/%
ln -sf $< $@
It helps if you can narrow down the left side of the pattern (.cc
files only? use "%.cc", etc), or limit the files in the source
directories to exactly the files that you want link rules for, but
this method suffers from giving make rules for more than you might
want.
3) like (1), but use foreach and eval to generate the rules for all the
directories in the list automatically:
# Given ${d} set to the name of a directory (with trailing slash) of
# stub sources, expand to the rule that should be eval'ed:
define link-rule
$$(notdir $$(filter ${d}%,$${TESTSTUB_SOURCES})): %: ${d}%
ln -sf $$< $$@
endef
# eval the above link rule, setting ${d} in turn to each directory that
# contains stub sources:
$(foreach d,$(sort $(dir ${TESTSTUB_SOURCES})),$(eval ${link-rule}))
Make sense?
Philip Guenther
- Re: Why doesn't this work properly?,
Philip Guenther <=