We help IT Professionals succeed at work.

relative path to absolute path in makefile

olcay
olcay asked
on
Consider following makefile snippet:

#this is a makefile
...
RELATIVE_ROOT= ../../../..
include ${RELATIVE_ROOT}/ltools/makejar.inc
...

How can I get the absolute path of RELATIVE_ROOT in this makefile?

I tried following command, but havn't success.

all:
    cd $(RELATIVE_ROOT)
    ABSOLUTE_ROOT= $(PWD)
    echo $(ABSOLUTE_ROOT)

Comment
Watch Question

Commented:
Each command is done in a seperate shell.
So you must do it like:

cd bla; Cmd2; Cmd3

Author

Commented:
>>bearware

cd bla; Cmd2; Cmd3 takes no effect

assume following:

this is my current directory olcay:/home/projects/hardware/source/presentation/
and there is my makefile

RELATIVE_ROOT= ../../../..
should be    
olcay:/home/projects

when I perform:
cd $(RELATIVE_ROOT)
then I have to change to:
olcay:/home/projects

My question is how to get the absolute path (olcay:/home/projects) after performing
cd $(RELATIVE_ROOT)
in a variable?

This command:
ABSOLUTE_ROOT= $(PWD)
shows me furthermore
/home/projects/hardware/source/presentation/

OK?

Commented:
That is because you are doing it on seperate likes and the cd does not persist between lines (seperate shell)

and ${PWD} will be evaluated by make I think, so you need to excape it

but I been thinking and I came up with another way to do it - This will step back 4 directorys from your current position:

ABSOLUTE_ROOT := ${shell echo ${PWD} | sed -e 's:\(.*\)/.*/.*/.*/.*:\1:'}


Author

Commented:
>>bearware

Thanx, this is exactly what I need :-)

regards

Author

Commented:
Thanx,

this is exatly what I need :-)

Bye