Thanks Eric....very interesting solution. John Graham sure knows his Make
The trick seem to be deciphering
_walk = $(if $1,$(wildcard /$(subst $(sp),/,$1)/$2) $(call _walk,$(wordlist
2,$(words $1),x $1),$2))
_find = $(firstword $(call _walk,$(strip $(subst /, ,$1)),$2))
_ROOT := $(patsubst %/root.mak,%,$(call _find,$(CURDIR),root.mak))
which is basically a reverse find. Which makes me wonder why unix folks have
not provided this option with our friendly find(1) command....it sounds like
an rfind(1) to me.
so I rolled up my sleeves and opened up my friendly swiss army nife....perl
Assuming env.mk is only in some SRC_ROOT directory, all make files can have
the following
SRC_ROOT=`perl -MCwd -e "@path=split('/',getcwd);do{ if (-f join('/', @path
, '/' , @ARGV)){ print join('/', @path);exit}}while(pop(@path));" env.mk`
Here is the unit test....
m...@medi:~/src/perl/rfind> find
.
./a
./a/b
./a/b/c
./foo
./env.mk
m...@medi:~/src/perl/rfind> cd a/b/c
m...@medi:~/src/perl/rfind/a/b/c>
m...@medi:~/src/perl/rfind/a/b/c> SRC_ROOT=`perl -MCwd -e
"@path=split('/',getcwd);do{ if (-f join('/', @path , '/' , @ARGV)){ print
join('/', @path);exit}}while(pop(@path));" env.mk`
m...@medi:~/src/perl/rfind/a/b/c> echo $SRC_ROOT
/home/medi/src/perl/rfind
I am still not happy with this solution....putting this in all Makefiles is
a disaster waiting to happen
medi
On Thu, Apr 8, 2010 at 8:50 PM, Eric Melski <[email protected]>wrote:
> Montaseri wrote:
>
> Greetings,
>
> I was wondering if someone has solved the following recursive ascend
> problem.
>
>
> Take a look at John Graham-Cumming's "Painless non-recursive Make":
>
> http://www.cmcrossroads.com/ask-mr-make/8133-painless-non-recursive-make
>
> That includes a solution to the problem you described.
>
> Hope that helps,
>
> Eric Melski
> Electric Cloud, Inc.
> http://blog.electric-cloud.com/
>
>
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make