include
include
其他代码然后扩张;
两个文件;模板独立定义在一个文件中一般是因为通用
eval replace
一个文件中定义局部模板;则是仅这里使用;
ch@chvm:~/ch/mkdfile/template$ make
inner good0 nice0 hahahah
inner good1 nice1 hahahah
inner good2 nice2 hahahah
inner good3 nice3 hahahah
make: Nothing to be done for 'all'.
ch@chvm:~/ch/mkdfile/template$ cat Makefile
define print_t
$(info inner $(good) $(nice) hahahah)
endef
good := good0
nice := nice0
$(eval $(print_t))
good := good1
nice := nice1
$(eval $(print_t))
good := good2
nice := nice2
$(eval $(print_t))
good := good3
nice := nice3
$(eval $(print_t))
.PHONY:all
all:;
- 可以看到上面的输出 make, 将相似的代码抽象;不同的代码独立;
eval call
ch@chvm:~/ch/mkdfile/template$ make
inner good0 nice0 hahahah
inner good1 nice1 hahahah
inner good2 nice2 hahahah
inner good3 nice3 hahahah
make: Nothing to be done for 'all'.
ch@chvm:~/ch/mkdfile/template$ cat Makefile
define print_t
$(info inner $(1) $(2) hahahah)
endef
$(eval $(call print_t, good0, nice0))
$(eval $(call print_t, good1, nice1))
$(eval $(call print_t, good2, nice2))
$(eval $(call print_t, good3, nice3))
.PHONY:all
all:;
这里以call的形式更简单,参数传递则是通过函数的形式;访问则是以编号的形式;
对比
编号的形式代码简介;阅读难一点;
变量的形式代码复杂一点;阅读简单一点;