Makefile find in array
If I have something like this:
PROJECTS += path/to/first
PROJECTS += path/to/second
PROJECTS += path/to/third
and
LIBS += lib_output/first.lib
LIBS += lib_output/second.lib
LIBS += lib_output/third.lib
How could I associate the project from PROJECTS += path/to/first
with LIBS += lib_output开发者_开发百科/first.lib
? Is there something like a hashmap available in a makefile? Or possibility to search in an array?
You can simulate lookup tables using computed variable names and the fact that make variable names can include some special characters like dot and forward slash:
PROJECTS += path/to/first
PROJECTS += path/to/second
PROJECTS += path/to/third
LIBS += lib_output/first.lib
LIBS += lib_output/second.lib
LIBS += lib_output/third.lib
lookup.path/to/first := lib_output/first.lib
lookup.path/to/second := lib_output/second.lib
lookup.path/to/third := lib_output/third.lib
path := path/to/first
$(info ${path} -> ${lookup.${path}})
path := path/to/second
$(info ${path} -> ${lookup.${path}})
path := path/to/third
$(info ${path} -> ${lookup.${path}})
Outputs:
$ make
path/to/first -> lib_output/first.lib
path/to/second -> lib_output/second.lib
path/to/third -> lib_output/third.lib
I'm not sure if I completely understand your question, but I think the word
function might be what you need (it may be a GNU make extension):
$(word 2, $(PROJECTS))
returns path/to/second
,
$(word 2, $(LIBS))
returns lib_output/second.lib
.
精彩评论