模板make

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的形式更简单,参数传递则是通过函数的形式;访问则是以编号的形式;

对比

编号的形式代码简介;阅读难一点;
变量的形式代码复杂一点;阅读简单一点;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值