GNU make parse变量

时间:2013-02-13 15:51:59

标签: makefile gnu-make

我想在makefile中解析变量,这个变量有下一个语法:

VARIABLE=folder1=file1,folder2=file2,...,folderN=fileN

在这里我想用它做什么:

ifdef VARIABLE
#
# here I want to assign FOLDER to "folder1, folder2... folderN" in the loop
# and then compare it with current folder
#  
ifeq ($(FOLDER),$(CURRENT_FOLDER))
#
# if true assign FILE1=file1 
#
export MYFILE := FILE1
endif
else
export MYFILE = default_name
endif

我该怎么做?

1 个答案:

答案 0 :(得分:1)

如果您将分隔符,更改为其他分隔符,例如:

VARIABLE=folder1=file1:folder2=file2:...:folderN=fileN

你可以拆分列表

L=$(subst :, ,$(VARIABLE))

提取文件夹(如果有)

E=$(filter $(CURRENT_FOLDER)=%, $L)

并将=之后的最后一部分分配给MYFILE

ifneq ($E,)
export MYFILE := $(patsubst $(CURRENT_FOLDER)=%,%,$E)
else
export MYFILE = default_name
endif