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的结果中只打印了命令结果。@符号表示不回显命令本身。

makefile之命令包&多行变量的更多相关文章

  1. makefile的命令包定义及使用

    下面以\build\core\product.mk下面的内容为例介绍: define _find-android-products-files $(shell test -d device & ...

  2. learning makefile 定义命令包

  3. makefile详解 嵌套执行make,定义命令包

    嵌套执行make 在一些大的工程中,我们会把我们不同模块或是不同功能的源文件放在不同的目录中,我们可以在每个目录中都书写一个该目录的Makefile,这有利于让我们的Makefile变得更加地简洁,而 ...

  4. 跟我一起写Makefile--- 变量(嵌套变量+追加变量+overrid+多行变量+环境变量+目标变量+模式变量)

    目录(?)[-] 使用变量 一变量的基础 二变量中的变量 三变量高级用法 四追加变量值 五override 指示符 六多行变量 七环境变量 八目标变量 九模式变量 使用变量 ———— 在Makefil ...

  5. [转] Makefile 基础 (4) —— Makefile 书写命令

    该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客:(最原始版本) http://blog.csdn.net/haoel/article/details/2886 我转自 ...

  6. ***LINUX添加PHP环境变量:CentOS下将php和mysql命令加入到环境变量中

    CentOS系统下如何将PHP和mysql命令加入到环境变量中,在Linux CentOS系统上 安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到 ...

  7. yarn如何全局安装命令以及和环境变量的关系

    npm全局安装 npm i -g xxx yarn 全局安装 yarn global add xxx 然而你可能会发现npm全局安装后的命令可以直接使用,而yarn却不行,这是为什么呢? 我们来查看下 ...

  8. bash 脚本编程七 将命令输出保存到变量中(转载)

    转自:http://blog.csdn.net/csfreebird/article/details/7978699 `符号包含的命令执行完后,可以讲其输出结果保存到变量中 #!/bin/bash v ...

  9. shell中命令代换$()与`` 、 变量代换${} 、 整数运算$(( )) 的区别

    命令代换$()与`` . 变量代换${} . 整数运算$(( )) 1.$( ) 与 ` ` (反引号) 在 bash shell 中,$( ) 与 ` ` (反引号) 都是用来做命令替换用(comm ...

随机推荐

  1. 简单总结es6箭头符号

    1.es6箭头符号的几种写法 (1)没有参数 ()=>1*1 (2)一个参数 x=>x*x (3)两个参数以及多个参数 (x,y,z)=>x*y*z 2.箭头符号不会绑定this.a ...

  2. 流畅的python第十章序列的修改,散列和切片学习记录

    只要实现了__len__和__getitem__两个方法即可将该类视为序列. 切片原理 动态存取属性 如果实现了__getattr__方法,也要定义__setattr__方法,以防对象行为不一致

  3. python numpy学习记录

    numpy是一个python和矩阵相关的库,在机器学习中非常有用,记录下numpy的基本用法 numpy的数组类叫做ndarray也叫做数组,跟python标准库中的array.array不同,后者只 ...

  4. springmvc怎么重定向,从一个controller跳到另一个controller

    第一种情况,不带参数跳转: 方法一:使用ModelAndView return new ModelAndView("redirect:/toList");  这样可以重定向到toL ...

  5. Android面试题(2)

    1.activity的生命周期 方法 描述 可被杀死 下一个 onCreate() 在activity第一次被创建的时候调用.这里是你做所有初始化设置的地方──创建视图.设置布局.绑定数据至列表等.如 ...

  6. 【Javascript】js图形编辑器库介绍

    10个JavaScript库绘制自己的图表 jopen 2015-04-06 18:18:38 • 发布 摘要:10个JavaScript库绘制自己的图表 JointJS JointJS is a J ...

  7. (转)NIO 内存映射文件

    内存映射文件 I/O 是一种读和写文件数据的方法,它可以比常规的基于流或者基于通道的 I/O 快得多. 内存映射文件 I/O 是通过使文件中的数据神奇般地出现为内存数组的内容来完成的.这其初听起来似乎 ...

  8. ESP8266学习笔记6:ESP8266规范wifi连接操作

    一.前言 我整理了从2015年至今关于ESP8266的学习笔记,梳理出来了开发环境.基础功能.进阶学习三大部分.方便自己和他人.可点此查看,欢迎交流. 之前在笔记4<ESP8266的SmartC ...

  9. C调用栈重温

    C栈的地址是从高位地址不断忘低位地址膨胀的,最先调用的函数所处的栈地址最高,后被调用的地址在低位: A->H这些地址表明了表明了基本的调用关系,AB是函数入参,CD是函数内的变量. 先调用者在高 ...

  10. okhttp-OkGo的文件下载模块

    OkDownload主要功能 结合OkGo的request进行网络请求,支持与OkGo保持相同的配置方法和传参方式 支持断点下载,支持突然断网,强杀进程后,继续断点下载 每个下载任务具有无状态.下载. ...