Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

makefile: how to add a prefix to the basename?

I have a list of file path like that:

FILE_PATH := a1.so a2.so bla/a3.so bla/a3.so bla/blo/a4.so.... 

I need to add a prefix to the basename in order to get:

FILE_PATH_PREFIXED := liba1.so liba2.so bla/liba3.so bla/liba3.so bla/blo/liba4.so.... 

any idea?

like image 628
dm76 Avatar asked Aug 24 '09 14:08

dm76


People also ask

How do you enter a prefix in makefile?

The prefix is want is /usr for most packages. So --prefix=/usr will do the job, but not all packages come with configure, a lot of them have just a makefile. How to set the prefix? I'm using dwm as an example and it uses /usr/local as prefix.

What is $@ in makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

What is Notdir in makefile?

$(notdir names …) Extracts all but the directory-part of each file name in names . If the file name contains no slash, it is left unchanged. Otherwise, everything through the last slash is removed from it.

What is include in makefile?

The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: include filenames ... filenames can contain shell file name patterns.


1 Answers

Look at Make's addsufix function.

Here is an example we use with `addsuffix` to place obj files one directory below the source.   SOURCE += MainThread.cpp SOURCE += Blah.cpp  OBJ=$(join $(addsuffix ../obj/, $(dir $(SOURCE))), $(notdir $(SOURCE:.cpp=.o))) 

From the make manual:

$(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. For example,

$(addprefix src/,foo bar) 

produces the result src/foo src/bar.

like image 148
RC. Avatar answered Sep 17 '22 20:09

RC.