zoukankan      html  css  js  c++  java
  • 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个$号表示变量名称

  • 相关阅读:
    NYOJ题目22 素数求和
    最大连续子序列&&MAX SUM
    Computer Transformation
    #转 二分查找
    吃巧克力
    公司年会
    亲和串
    开门人和关门人
    找新朋友
    big number
  • 原文地址:https://www.cnblogs.com/catgatp/p/6527617.html
Copyright © 2011-2022 走看看