makefile中的循环控制

GNU make的foreach函数

foreach函数仅GNU make支持:

下面的代码中使用了函数foreach和shell

files=main.exe a.exe b.exe
all:
	echo $(files_1); \
	rm -f $(foreach i, $(shell echo $(files) | sed s/.exe//g), $(i).o)

shell 循环

以下代码实现与上面同样的功能, 该版本的循环, 在多平台(AIX, HP-UX, SUSE)测试没有问题:

files=main.exe a.exe b.exe

all:
	for name in `echo $(files) | sed s/.exe//g`; \
	do \
		rm -f "$$name".o; \
	done

注意, 在makefile中的shell变量要用2个$号表示变量名称

你可能感兴趣的:(make,bash)