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的结果中只打印了命令结果。@符号表示不回显命令本身。
makefile之命令包&多行变量的更多相关文章
- makefile的命令包定义及使用
下面以\build\core\product.mk下面的内容为例介绍: define _find-android-products-files $(shell test -d device & ...
- learning makefile 定义命令包
- makefile详解 嵌套执行make,定义命令包
嵌套执行make 在一些大的工程中,我们会把我们不同模块或是不同功能的源文件放在不同的目录中,我们可以在每个目录中都书写一个该目录的Makefile,这有利于让我们的Makefile变得更加地简洁,而 ...
- 跟我一起写Makefile--- 变量(嵌套变量+追加变量+overrid+多行变量+环境变量+目标变量+模式变量)
目录(?)[-] 使用变量 一变量的基础 二变量中的变量 三变量高级用法 四追加变量值 五override 指示符 六多行变量 七环境变量 八目标变量 九模式变量 使用变量 ———— 在Makefil ...
- [转] Makefile 基础 (4) —— Makefile 书写命令
该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客:(最原始版本) http://blog.csdn.net/haoel/article/details/2886 我转自 ...
- ***LINUX添加PHP环境变量:CentOS下将php和mysql命令加入到环境变量中
CentOS系统下如何将PHP和mysql命令加入到环境变量中,在Linux CentOS系统上 安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到 ...
- yarn如何全局安装命令以及和环境变量的关系
npm全局安装 npm i -g xxx yarn 全局安装 yarn global add xxx 然而你可能会发现npm全局安装后的命令可以直接使用,而yarn却不行,这是为什么呢? 我们来查看下 ...
- bash 脚本编程七 将命令输出保存到变量中(转载)
转自:http://blog.csdn.net/csfreebird/article/details/7978699 `符号包含的命令执行完后,可以讲其输出结果保存到变量中 #!/bin/bash v ...
- shell中命令代换$()与`` 、 变量代换${} 、 整数运算$(( )) 的区别
命令代换$()与`` . 变量代换${} . 整数运算$(( )) 1.$( ) 与 ` ` (反引号) 在 bash shell 中,$( ) 与 ` ` (反引号) 都是用来做命令替换用(comm ...
随机推荐
- meteor学习-- #一 安装meteor快速使用
下载安装 curl https://install.meteor.com/ | sh meteor会自动下载mongodb和其他需要依赖的库,不需要手动安装. 如果是Windows 的用户,请使用 m ...
- 理解PHP的变量,值与引用的关系
--- title: 理解PHP的变量,值与引用的关系 createdDate: 2015-03-11 category: php --- PHP的变量与C++中的变量是两种截然不容的概念.如果没有理 ...
- 流畅的python第八章对象引用,可变性和垃圾回收
变量不是盒子 在==和is之间选择 ==比较两个对象的值,而is比较对象的标识 元组的相对不可变姓 元组与多数的python集合(列表,字典,集,等等)一样,保存的是对象的引用.如果引用的元素是可变的 ...
- 怎样在Ubuntu手机应用中得到全部的环境变量值
我们在先前的例程中已经通过一些方法得到我们应用的一些环境变量值.这些值有的很实用.比方我们能够得到我们应用所仅仅能訪问的文件夹.在今天的例程中,我们来展示一种方法能够得到应用全部的环境变量.在我们的实 ...
- Druid对比Redshift
Redshift 内部使用了亚马逊取得了授权的ParAccel 实时注入数据 抛开可能的性能不同, 有功能性的不同 Druid 适合分析大数据量的流式数据, 也能够实时加载和聚合数据一般来讲, 传统的 ...
- MVVM和MVC的区别,以及MVVM的缺点
MVVM和MVC的区别 MVC和MVVM的区别其实并不大.都是一种设计思想. 主要就是MVC中Controller演变成MVVM中的viewModel. MVVM主要解决了MVC中大量的DOM操作使页 ...
- eslint 错误
是因为你使用了eslint,这个是eslint的规范报错,能不用分号就不用分号. 去掉封号就醒了. 另外,方法的()前面也要有空格,不然页报错: indentifier is not in a cam ...
- 抓取网页图片的脚本(javascript)
抓取网页图片的脚本(javascript) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24172223 脚本内容 (没有换行) ...
- zabbix_LAMP源码安装
Zabbix源码包安装 Cenos5.3 Basic server 安装顺序 Libxml2 Libmcrypt Zlib Libpng Jpeg:需要创建目录jpeg /bin /lib /incl ...
- PHP Warning exec() has been disabled for security reasons怎么办
如果是PHPNOW,还是找到php-apache2handler.ini这个文件,把禁用的函数去掉即可. 注意是这个文件夹