help-make
[Top][All Lists]

## Re: how to fully qualify entries in a "-I" list?

 From: Philip Guenther Subject: Re: how to fully qualify entries in a "-I" list? Date: Tue, 20 Nov 2007 12:53:44 -0700

```On Nov 20, 2007 9:11 AM, Ken Smith <address@hidden> wrote:
> On Nov 20, 2007 3:02 AM, Robert P. J. Day <address@hidden> 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

```