[Top][All Lists]

[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) sounds like an rfind(1) to me.

so I rolled up my sleeves and opened up my friendly swiss army nife....perl

Assuming 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));"`

Here is the unit test....
address@hidden:~/src/perl/rfind> find
address@hidden:~/src/perl/rfind> cd 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));"`

address@hidden:~/src/perl/rfind/a/b/c> echo $SRC_ROOT

I am still not happy with this solution....putting this in all Makefiles is a disaster waiting to happen


On Thu, Apr 8, 2010 at 8:50 PM, Eric Melski <address@hidden> wrote:
Montaseri wrote:

I was wondering if someone has solved the following recursive ascend problem.

Take a look at John Graham-Cumming's "Painless non-recursive Make":
That includes a solution to the problem you described.

Hope that helps,

Eric Melski
Electric Cloud, Inc.

reply via email to

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