help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how-to Recursive Ascend


From: Montaseri
Subject: Re: how-to Recursive Ascend
Date: Fri, 9 Apr 2010 02:21:20 -0700

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....
address@hidden:~/src/perl/rfind> find
.
./a
./a/b
./a/b/c
./foo
./env.mk
address@hidden:~/src/perl/rfind> cd a/b/c
address@hidden:~/src/perl/rfind/a/b/c>


address@hidden:~/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`

address@hidden:~/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 <address@hidden> 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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]