Question

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.

Was it helpful?

Solution 2

eventually I used:

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

OTHER TIPS

You'll have to use a loop:

LIBS := $(foreach D,$(DIRS),$D/lib$D.a)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top