the detail analysis of makefile's froeach

本文详细解读了Makefile中foreach函数的工作原理,并通过实例展示了如何使用此函数来简化目录下文件的查找与处理过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Today , as work need ,I saw something about the foreach function in makefile and now  I am writing it out.  

 

$(foreach var,list,text)

The first two arguments, var and list, are expanded before anything else is done; note that the last argument, text, is not expanded at the same time. Then for each word of the expanded value of list, the variable named by the expanded value of var is set to that word, and text is expanded. Presumably textcontains references to that variable, so its expansion will be different each time.

OK,let see some examples.

 

dirs := a b c d
files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))

As you can see from the example, the dir represent a,b,c and d. The

This example has the same result (except for setting ‘dirs’) as the following example:

     files := $(wildcard a/* b/* c/* d/*)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值