Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile: Expand relative PREFIX path

In my Makefile, there is a PREFIX variable for specifying where the finished files should be placed. However, internally, I need to use the absolute path of PREFIX because the working directory changes.

I tried something like

PREFIX=../out
REALPREFIX=`readlink -f $(PREFIX)`

which didn't work, and neither did

default: fixprefix $(addprefix $(REALPREFIX)/,$(OBJS))

fixprefix:
        REALPREFIX=`readlink -f $(PREFIX)`

All I need is for the absolute path to be prefixed onto OBJS when the prerequisites list is calculated.

like image 546
erjiang Avatar asked May 11 '11 18:05

erjiang


People also ask

How do you make a relative path in Makefile?

You can use the shell function, and use realpath(1) (which is part of coreutils) and the --relative-to flag. You can even process a whole list of files with one invocation of realpath(1) since it knows how to process many file names.

What is add prefix in Makefile?

$(addprefix prefix , names …) The argument names is regarded as a series of names, separated by whitespace; prefix is used as a unit. The value of prefix is prepended to the front of each individual name and the resulting larger names are concatenated with single spaces between them.

What is Abspath in Makefile?

That's what abspath does. It creates an absolute path. That means it must be anchored at the root.

What is module MK?

The syntax of the Android.mk allows you to group your sources into modules. A module is either a static library, a shared library, or a standalone executable. You can define one or more modules in each Android.mk file, and you can use the same source file in multiple modules.


1 Answers

If you're using GNUMake, you can do this:

REALPREFIX = $(realpath $(PREFIX))
like image 200
Beta Avatar answered Sep 18 '22 16:09

Beta