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