Reputation: 302748
I have a bunch of libraries that I want to build as dependencies:
LIBS = libs/foo libs/bar
Each library has an object that I need to compile against, all in a predictable spot. They are:
libs/foo/lib/libfoo-O3.a
libs/bar/lib/libbar-O3.a
I would like to effectively transform my LIBS
string into these rules:
build : libs/foo/lib/libfoo-O3.a libs/bar/lib/libbar-O3.a
libs/foo/lib/libfoo-O3.a:
$(MAKE) -C libs/foo
libs/bar/lib/libbar-O3.a:
$(MAKE) -C libs/bar
I know you can't use %
twice, so unfortunately libs/%/lib/lib%-O3.a
is a non-starter as a target. Is there another way to do this? Something with a define
template?
Upvotes: 1
Views: 387
Reputation: 100806
If you can change the LIBS variable to just contain the name, you can do it easily:
LIBS = foo bar
LIBPATHS := $(foreach L,$(LIBS),libs/$L/lib/lib$L-O3.a)
If you can't you can still do this, only slightly less readable:
LIBS = libs/foo libs/bar
LIBPATHS := $(foreach L,$(LIBS),$L/lib/lib$(notdir $L)-O3.a)
Then just add something like:
$(LIBPATHS):
$(MAKE) -C $(firstword $(subst /lib/, ,$@))
Upvotes: 3