码:
LIST=0 1 2 3 4 5 PREFIX=rambo # some looping logic to interate over LIST
预期结果:@H_301_4@
rambo0: sh rambo_script0.sh rambo1: sh rambo_script1.sh
由于我的LIST有6个元素,因此应该生成6个目标.将来,如果我想添加更多目标,我希望能够修改我的LIST而不是触及代码的任何其他部分.@H_301_4@
如何编写循环逻辑?@H_301_4@
使用
text-transforming functions.使用patsubst,您可以进行非常一般的转换.对于构造文件名,addsuffix和addprefix都很方便.
对于规则,请使用pattern rules.@H_301_4@
整体结果可能如下所示:@H_301_4@
LIST = 0 1 3 4 5 targets = $(addprefix rambo,$(LIST)) all: $(targets) $(targets): rambo%: rambo%.sh sh $<