http://www.cnblogs.com/pengdonglin137/p/3801060.html

在Makefile中我们经常看到 = := ?= +=这几个赋值运算符,那么他们有什么区别呢?

新建一个Makefile,内容为:
ifdef DEFINE_VRE
    VRE = “Hello World!”
else
endif

ifeq ($(OPT),define)
    VRE ?= “Hello World! First!”
endif

ifeq ($(OPT),add)
    VRE += “Kelly!”
endif

ifeq ($(OPT),recover)
    VRE := “Hello World! Again!”
endif

all:
  @echo $(VRE)

敲入以下make命令:
make DEFINE_VRE=true OPT=define 输出:Hello World!
make DEFINE_VRE=true OPT=add 输出:Hello World! Kelly!
make DEFINE_VRE=true OPT=recover  输出:Hello World! Again!
make DEFINE_VRE= OPT=define 输出:Hello World! First!
make DEFINE_VRE= OPT=add 输出:Kelly!
make DEFINE_VRE= OPT=recover 输出:Hello World! Again!

从上面的结果中我们可以清楚的看到他们的区别了
= 是最基本的赋值
:= 是覆盖之前的值
?= 是如果没有被赋值过就赋予等号后面的值
+= 是添加等号后面的值

之前一直纠结makefile中“=”和“:=”的区别到底有什么区别。

1、“=”

make会将整个makefile展开后,再决定变量的值。也就是说,变量的值将会是整个makefile中最后被指定的值。看例子:

x = foo
            y = $(x) bar
            x = xyz

在上例中,y的值将会是 xyz bar ,而不是 foo bar 。

2、“:=”

“:=”表示变量的值决定于它在makefile中的位置,而不是整个makefile展开后的最终值。

x := foo
            y := $(x) bar
            x := xyz

在上例中,y的值将会是 foo bar ,而不是 xyz bar 了。

Makefile的几个赋值运算符(转:笔记)的更多相关文章

  1. Makefile的简单编写【学习笔记】

    首先我们先创建两个简单的文件: main.c #include <stdio.h> extern void hi_fun(); int main() { printf("hell ...

  2. (十)makefile

    一.Makefile的作用和意义(1)工程项目中c文件太多管理不方便,因此用Makefile来做项目管理,方便编译链接过程.(2)uboot和linux kernel本质上都是C语言的项目,都由很多个 ...

  3. c++学习笔记(网上资料)

                                    C++笔记       2007-3-22 1. 程序 —— 可执行文件,人发送给计算机的一组指令.         硬件指令是二进制, ...

  4. Shell脚本——make命令和Makefile文件【转】

    https://blog.csdn.net/twc829/article/details/72729799 make命令是一个常用的编译命令,尤其在C/C++开发中,make命令通过makefile文 ...

  5. makefile自动生成学习

    https://www.cnblogs.com/jrglinux/p/6964169.html 关键是如何写Makefile.am  其他的交给 自动工具完成 添加一个 很好的博客 学习下 https ...

  6. 【Makefile】2-Makefile的介绍及原理

    目录 前言 概念 Chapter 2:介绍 2.1 makefile的规则 2.3 make 是如何工作的 ** 2.5 让 make 自动推导 2.8 Makefile 里面有什么 2.9 Make ...

  7. Makefile-3-书写规则

    目录 前言 概念 Chapter 3:书写规则 3.3 在规则中使用通配符 3.4 文件搜索 3.8 自动生成依赖性 原理 * 直接解析例子 ** sed 命令 参考 书籍 前言 本笔记主要记录Mak ...

  8. [转]Windows平台下Makefile学习笔记

    Windows平台下Makefile学习笔记(一) 作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译 ...

  9. Makefile的学习笔记

    Makefile的学习笔记 标签: makefilewildcard扩展includeshellfile 2012-01-03 00:07 9586人阅读 评论(2) 收藏 举报  分类: Linux ...

随机推荐

  1. Hibernate学习笔记-Hibernate HQL查询

    Session是持久层操作的基础,相当于JDBC中的Connection,通过Session会话来保存.更新.查找数据.session是Hibernate运作的中心,对象的生命周期.事务的管理.数据库 ...

  2. [UVALive] 6492 Welcome Party(最小点覆盖)

    6492 Welcome Party For many summers, the Agile Crystal Mining company ran an internship program for ...

  3. 转:从BeagleBone谈AM335x硬件系统设计

    链接:http://blog.chinaunix.net/uid-730738-id-3266690.html    作者:chenzhufly 从BeagleBone谈AM335x硬件系统设计 日期 ...

  4. BeanUtils框架浅析

    一.使用步骤: 1.添加jar包: commons-beanutils-1.8.0.jar commons-logging.jar 2.使用setProperty()方法对javabean设置属性值 ...

  5. cf B. Sereja and Suffixes

    http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...

  6. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  7. simulate windows postmessage or keydown

    2 ways: 1. under TForm:   if assigned(focused) then      Focused.keydown(key,keychar,[]); 2. using s ...

  8. C++链接器工具错误:LNK2001, LNK2019(转载)

    这是归属于链接器工具错误 这一类. 无法解析的外部符号“symbol” 代码引用了链接器无法在库和对象文件中找到的内容(如函数.变量或标签). 可能的原因 代码请求的内容不存在(例如,符号拼写错误或使 ...

  9. cf413E Maze 2D

    E. Maze 2D time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  10. ACM2136

    /* Problem Description Everybody knows any number can be combined by the prime number. Now, your tas ...