Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile patsubst multiple occcurence in replacement pattern

Tags:

makefile

I have 3 dirs and want to link an executable against the libraries

I already have the directory list:

DIRS=Math Graph Test

I want to get the library list like this:

LIBS=Math/libMath.a Graph/libGraph.a Test/libTest.a

If I use this:

$(DIRS:%=%/%.a)

I get:

Math/%.a Graph/%.a Test/%.a

GNU Makefile says:

Only the first ‘%’ in the pattern and replacement is treated this way; any subsequent ‘%’ is unchanged.

Here I need 2 occurrences to be replaced, not just the first one.

like image 362
RumburaK Avatar asked May 09 '14 12:05

RumburaK


2 Answers

You'll have to use a loop:

LIBS := $(foreach D,$(DIRS),$D/lib$D.a)
like image 118
MadScientist Avatar answered Nov 13 '22 04:11

MadScientist


eventually I used:

LIBS := $(join $(DIRS), $(DIRS:%=/lib%.a))

like image 1
RumburaK Avatar answered Nov 13 '22 05:11

RumburaK