Variable arguments list to a Makefile

旧巷老猫 提交于 2019-12-12 01:54:28

问题


I would like do something like following. I would like to have a variable argument list for a Makefile.

make VAR_ARG_LIST=src1,src2,src3,src4

Can I do like this? If I can, how do I extract src1,src2 or src3 from the variable VAR_ARG_LIST inside the Makefile?

Thanks,


回答1:


You really haven't provided enough information for a solution. Why do you want to extract those values? What do you want to do with them?

However, I can answer the question you asked and hope it is useful. If you're using GNU make you can do this:

COMMA := ,
VAR_ARG_LIST_A := $(subst $(COMMA), ,$(VAR_ARG_LIST))
VAR_ARG_LIST_1 := $(word 1,$(VAR_ARG_LIST_A))
VAR_ARG_LIST_2 := $(word 2,$(VAR_ARG_LIST_A))

etc.




回答2:


If you want a list of targets in a macro for make to use, use blanks to separate them (and quotes to enclose them) on the command line:

make VAR_ARG_LIST="src1 src2 src3 src4"

This can be used inside the makefile without much trouble at all:

PROGRAMS = ${VAR_ARG_LIST}

all:  ${PROGRAMS}

and it will go off and create the programs src1, ... src4 from the rest of the rules in the makefile.

If that isn't roughly what you're after, then you need to clarify your question.



来源:https://stackoverflow.com/questions/9962297/variable-arguments-list-to-a-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!