twar
twar

Reputation: 71

Makefile variable and loop

I've got some makefile generated by conan which is included by my main Makefile. That generated Makefile (conanbuildinfo.mak) contains some variable lets say it is something like this:

CONAN_LIBS = librarya libraryb libraryc

Starting with this in my main makefile:

LIBS=-lsocket

I'd like to achieve following end result:

LIBS=-lsocket -llibrarya -llibraryb -llibraryc

so iterate over $CONAN_LIBS and add each variable with -l prefix to LIBS.

How can I do it? :)

Upvotes: 0

Views: 137

Answers (1)

Frank
Frank

Reputation: 56

With GNU make you can try 'foreach':

CONAN_LIBS = librarya libraryb libraryc
LIBS = $(foreach entry, $(CONAN_LIBS), -l$(entry))
all:
    echo $(LIBS)

make all

-llibrarya -llibraryb -llibraryc

Upvotes: 1

Related Questions