📄 foreach
字号:
# -*-perl-*-# $Id: foreach,v 1.5 2006/03/10 02:20:46 psmith Exp $$description = "Test the foreach function.";$details = "This is a test of the foreach function in gnu make.This function starts with a space separated list ofnames and a variable. Each name in the list is subsitutedinto the variable and the given text evaluated. The generalform of the command is $(foreach var,$list,$text). Severaltypes of foreach loops are tested\n";# TEST 0# Set an environment variable that we can test in the makefile.$extraENV{FOOFOO} = 'foo foo';run_make_test("space = ' '".'null :=auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <foo = bletch null @ garfav = $(foreach var, $(auto_var), $(origin $(var)) )override WHITE := BLACKfor_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )all: auto for2auto : ; @echo $(av)for2: ; @echo $(fe)', '-e WHITE=WHITE CFLAGS=', "undefined file default file environment default file command line override automatic automaticfoo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o default.o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o");delete $extraENV{FOOFOO};# TEST 1: Test that foreach variables take precedence over global# variables in a global scope (like inside an eval). Tests bug #11913run_make_test('.PHONY: all targetall: targetx := BADdefine mktargettarget: x := $(x)target: ; @echo "$(x)"endefx := GLOBAL$(foreach x,FOREACH,$(eval $(value mktarget)))', '', 'FOREACH');# TEST 2: Check some error conditions.run_make_test('x = $(foreach )y = $xall: ; @echo $y', '', "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.", 512);run_make_test('x = $(foreach )y := $xall: ; @echo $y', '', "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.", 512);1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -