help-make
[Top][All Lists]
Advanced

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

(should-be) simple directory parsing


From: galathaea galathaea
Subject: (should-be) simple directory parsing
Date: Mon, 15 May 2006 17:32:48 -0700

I cannot seem to get my stupid hat off today...
 
 
I have a project which has a top-most directory:
 
<someDirectory>/another/TOP/
 
beneath which I have a large project structure, including
 
<someDirectory>/another/TOP/one/
<someDirectory>/another/TOP/two/underneath
<someDirectory>/another/TOP/two/elsewhere
 
inside of which are makefiles.  Each of these makefiles needs to know the top-most directory's path, and since the current directory has that information imbedded, I foolishly decided to try to parse the information out.
 
In other words, I know the name "TOP".  That is unchanging and unique.  But the names in the directories above it change in our build system as a part of versioning, etc.  So if I find a substring */TOP/ inside the srcdir(=$(shell pwd)), then my task is done.  Simple.
 
Except the string manipulation tools of make do not appear to be quite up to the task.  Instead, I fashioned a recursive function that does this type of thing by finding the realpath of each */.. until I matched the pattern.  This looked something like:

TEST10 = $(if $(filter %/TOP,$(realpath $(1)/..)),$(realpath $(1)/..),$(call TEST10,$(realpath $(1)/..)))

TEST11 = $(call TEST10,$(srcdir))

which worked!...
Until I copied my test code over to my real project. :(
At that point, the same code gave me:
 
Recursive variable `TEST10' references itself (eventually).
 
which, of course, was the point.  I found that my test code had been using an experimental make version "3.81rc" which I had  installed on to my test machine from a different project.  The version that fails (and that I need working code for) is 3.79.1.  This needs to work on Linux Redhat 7.3, kernel 2.4.18, but I doubt that is relevant except that this runs in a bash shell.
 
I can do this in shell scripting really easily:
 
pwd | sed -e "s/\/TOP.*$//"
 
but when I try a naive translation to makefilese:
 
$(shell pwd | sed -e "s/\/TOP.*$//")
 
I get nothing.  I obviously do not understand how to get pipes working in shell calls in makefiles, but I've tried a couple of different ways using quotes and \" escaping the sed command quotes, all without luck.
 
I suspect this is the easiest task in the world and every makefile in the world that I failed to look at today has it right there in plain view.  I suspect there is a one-liner that does this in some obvious way, and I am just wasting time with obscure back-routes.  If anyone can help clear this up for me, I would really appreciate it.
 
Thanks for your time,
galathaea
 
 

reply via email to

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