makefile中的循环控制


GNU make的foreach函数

foreach函数仅GNU make支持:

下面的代码中使用了函数foreach和shell

 
  1. files=main.exe a.exe b.exe  
  2. all:  
  3.     echo $(files); \  
  4.     rm -f $(foreach i, $(shell echo $(files) | sed s/.exe//g), $(i).o)  

shell 循环

以下代码实现与上面同样的功能, 该版本的循环, 在多平台(AIX, HP-UX, SUSE)测试没有问题:

 
  1. files=main.exe a.exe b.exe  
  2.   
  3. all:  
  4.     for name in `echo $(files) | sed s/.exe//g`; \  
  5.     do \  
  6.         rm -f "$$name".o; \  
  7.     done  


注意, 在makefile中的shell变量要用2个$号表示变量名称


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM