[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: subst and patsubst
From: |
Paul D. Smith |
Subject: |
Re: subst and patsubst |
Date: |
Fri, 23 Mar 2001 16:03:59 -0500 |
%% Joerg Krautwurst-Schmid <address@hidden> writes:
jk> I want to cut of a pice of the current directory to get only a
jk> spcific part: eg. pwd is /home/jks/playpen/branch_one/xyz/scr/bin
jk> now I want to have to root '/home/jks/playpen/branch_one/xyz' without
jk> src/bin.
I'm assuming you don't know and can't find either the prefix or the
suffix, or even know how many levels of directory you want to delete
(e.g., you don't have anything like TOPDIR=../.. or something). If you
know any of that, I can show you how to do this more reliably using
make's filename functions, which operate safely on "/" boundaries.
Otherwise, if (a) you can assume you will have no spaces in your
filenames, and (b) you know that there is only one /xyz/ part in your
path/string, then you can use this cute hack:
ifneq ($(words $(CURDIR)),1)
$(error You must not have whitespace in the path ($(CURDIR)))
endif
osroot := $(word 1,$(subst /xyz/, ,$(CURDIR)))/xyz
If you can have >1 instance of /xyz/, then you have to decide how you
want to break it; if you want to take only up to the first /xyz/ then
you can use the above: if you want all up to the _last_ /xyz/, then
you'll have to use something like this:
ostmp := $(subst /xyz/, ,$(CURDIR))
osroot := $(word $(words $(ostmp)),$(ostmp))/xyz
If you have to allow for whitespace in the path, then you'll have to
pick some character which is _NOT_ legal, and convert all your
whitespace to that character with $(subst ...), then proceed as above,
then reset all the instances of that illegal character back to spaces
in $(osroot) with $(subst ...) again.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
- subst and patsubst, Joerg Krautwurst-Schmid, 2001/03/23
- Re: subst and patsubst,
Paul D. Smith <=