[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re: How to transfrom a.c dir1/b.c to -I. -I./dir1
From: |
Philip Guenther |
Subject: |
Re: Re: How to transfrom a.c dir1/b.c to -I. -I./dir1 |
Date: |
Fri, 1 Aug 2008 03:00:09 -0600 |
On Fri, Aug 1, 2008 at 2:34 AM, PRC <address@hidden> wrote:
...
> Did you mean using the function `realpath`? But it is too old to
> support this function for the version of 3.8 of `Make`. Maybe it's more
> simple to invoke shell functions to do this.
'realpath'? Why would you need that function to do what you want?
The manual describes realpath like this:
`$(realpath NAMES...)'
For each file name in NAMES return the canonical absolute name.
...
But your question had nothing to do with canonicalization:
> There is a variable in my Makefile script, whose value is:
> src = a.c dir1/b.c c.c dir2/d.c
> I wonder how to transform its value to
> -I. -I./dir1 -I. -I./dir2
That sounds like simple text manipulation to me: you want to extract
the directory part of each filename and then prepend "-I" to it, no?
For the 'extract directory part', doesn't the function $(dir) on that
same page seem like an obvious first step for a solution?
$ cat Makefile
src = a.c dir1/b.c c.c dir2/d.c
all:
@echo $(src)
@echo $(dir $(src))
$ make
a.c dir1/b.c c.c dir2/d.c
./ dir1/ ./ dir2/
$
Looks like $(dir) leaves a trailing slash, so you need to trim that
and add a leading "-I". That sort of manipulation is easy with
$(patsubst), described on the previous page in the manual:
$ cat Makefile
src = a.c dir1/b.c c.c dir2/d.c
all:
@echo $(src)
@echo $(dir $(src))
@echo $(patsubst %/,-I%,$(dir $(src)))
$ make
a.c dir1/b.c c.c dir2/d.c
./ dir1/ ./ dir2/
-I. -Idir1 -I. -Idir2
$
Do that process of breaking the goal down into steps and debugging it
with a test makefile make sense?
Philip Guenther