Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping characters in Makefiles 'addprefix'

Tags:

makefile

I have a list of libraries:

lib_paths := dir1 dir2 dir3

that I would like to add to my rpath via

LDFLAGS += (addprefix -Wl,-rpath,$(lib_paths))

Of course, this fails because , is the delimiter to the addprefix function in Makefiles. How can I escape the comma?

like image 452
user14717 Avatar asked Oct 20 '25 05:10

user14717


2 Answers

You have to put it in a variable. Make will break arguments on commas before it expands them, so:

comma = ,

LDFLAGS += $(addprefix -Wl$(comma)-rpath,$(lib_paths))
like image 70
MadScientist Avatar answered Oct 22 '25 03:10

MadScientist


Basically -Wl,-rpath is just the short variant of -Xlinker -rpath=:

LDFLAGS += $(addprefix -Xlinker -rpath=,$(lib_paths))
like image 32
Molith Avatar answered Oct 22 '25 03:10

Molith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!