On Nov 20, 2007 9:11 AM, Ken Smith <[EMAIL PROTECTED]> wrote:
> On Nov 20, 2007 3:02 AM, Robert P. J. Day <[EMAIL PROTECTED]> wrote:
> >   wanted:  a simple way to transform the string (and its entries):
> >     -Ia -I/b -Ic -I/d
> > to
> >     -I/src/a -I/b -I/src/c -I/d
>
> Here is a solution but I'm not sure if you will consider it short and sweet.
>
> paths := a /b c /d
> abspaths := $(filter /%,$(paths))
> relpaths := $(filter-out /%,$(paths))
> qual-paths := $(addprefix /src/,$(relpaths)) $(abspaths)

That reorders the paths, putting all the previously-relative paths
before all the previously-absolute paths.  That may not be acceptable.
 To preserve the order, perform the transformation inside a
$(foreach):

# A function that adds $1 as a prefix to any non-absolute paths in $2
make-absolute = $(foreach dir,$2,$(if $(filter-out /%,${dir}),$1)${dir})

absprefix = /src/
paths = a /b c /d
abs-paths = $(call make-absolute,${absprefix},${paths})

Chaining that with $(patsubst) to strip and re-add the -I should be
straightforward.


Philip Guenther


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to