zoukankan      html  css  js  c++  java
  • makefile之命令包&多行变量

    define&endef

    1. 命令包(canned recipes)&多行变量(muti-line variables)

    The define directive is followed on the same line by the name of the variable being
    defined and an (optional) assignment operator, and nothing more. The value to give the
    variable appears on the following lines. The end of the value is marked by a line containing
    just the word endef.Aside from this difference in syntax, define works just like any other
    variable definition. The variable name may contain function and variable references, which
    are expanded when the directive is read to find the actual variable name to use.

    You may omit the variable assignment operator if you prefer. If omitted, make assumes
    it to be ‘=’ and creates a recursively-expanded variable. When using a ‘+=’ operator, the value is appended to the previous value as with any other append operation: with a single space separating the old and new
    values.

    You may nest define directives: make will keep track of nested directives and report
    an error if they are not all properly closed with endef. Note that lines beginning with
    the recipe prefix character are considered part of a recipe, so any define or endef strings
    appearing on such a line will not be considered make directives.

    本质上就是通过define directive来定义一个变量,而这个变量包含一组命令,而这一组命令经常会被多个地方使用到,那么通过对该变量的引用,就能相应召开这一组命令。就像c语言的函数一样。也可以当作是makefile中“函数"的定义。需要注意的是该变量名不能与其他变量名冲突。

    1.1 示例

    1.1.1 命令包的简单使用---自定义函数

    all:                    
        @$(cmd)
    
    define cmd
        echo "test define 1"
        echo "test define 2"
        echo "test define 3"
    endef
    
    

    cmd 是命令包的名字,在define 和 endef 间的部分即是命令主体。

    源码路径:https://github.com/suonikeyinsuxiao/trunk/tree/master/makefile_project/define/define1

    从执行结果可以看出,命令包变量cmd被引用展开后,被执行。上图中make的结果中只打印了命令结果。@符号表示不回显命令本身。

  • 相关阅读:
    关于jqGrid组件数据显示不出问题
    jq修改导航栏样式(选中、使用两张图片替代的是否选中效果)
    jq获取图片并转换为base64
    jq怎么给图片绑定上传文件按钮
    ajax上传文件
    layui超链接追加tab选项卡必须手动刷新才出现问题
    thinkphp5中使用excel导出数据表格(包涵图片)
    关于php条形码生成(barcode),修改样式
    php中对象赋值问题
    数组小工具2
  • 原文地址:https://www.cnblogs.com/black-mamba/p/9637137.html
Copyright © 2011-2022 走看看