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?
The findstring function is what your heart desires: $(findstring find,in) Searches in for an occurrence of find. If it occurs, the value is find; otherwise, the value is empty. You can use this function in a conditional to test for the presence of a specific substring in a given string.
The ifeq directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared.
A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With