makefile 的 ifdef, ifeq 使用及辨析
来源:互联网 发布:linux 下except用法 编辑:程序博客网 时间:2024/06/08 06:00
#可以用命令行传递变量
RELEASE = abc
#ifdef 变量名称不能加$()
ifdef RELEASE
$(warning RELEASE defined)
else
$(warning RELEASE not defined)
endif
#ifeq 后面参数要叫$(), 因为是值引用, 值可以为数值或字符串
ifeq ($(RELEASE),abc)
$(warning RELEASE eqal abc)
else
$(warning RELEASE not equal abc)
endif
all:
@echo ok!
**************************************************
make 编译不同版本,例如debug, release 的简单示例。
用make 变量ver, 控制CFLAGS 变量,从而编译出不同版本。
[/pts/2@hjj ~/test]$ cat test.c
#include <stdio.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
char *tty=ttyname(0);
printf("tty is %s\n",tty);
return 0;
}
[/pts/2@hjj ~/test]$ cat Makefile
CC = gcc
TARGET = test
OBJS = test.o
ifeq ($(ver), debug)
$(warning ver is debug)
CFLAGS = -g -Ddebug
else
$(warning ver is not debug)
CFLAGS = -c -O3
endif
$(TARGET): $(OBJS)
$(CC) -o $@ $^
clean:
rm test test.o
注释: makefile 采用了ifeq-else-endif 结构
可以判别莫个make变量是否定义。
make变量可以在makefile中定义,也可以由make命令行传递。
由于makefile 支持环境变量,所以你预先定义了环境变量,也可以不在命令行中传递而直接使用环境变量
这种机制使得编写脚本控制不同的复杂的编译成为可能,
例如支持各种地域的不同的版本。用地域变量,控制make的编译选项/D,控制编译出不同的版本
----------------------------------------
编译debug 版本, 从命令行传递变量
----------------------------------------
[/pts/2@hjj ~/test]$ make ver=debug
Makefile:6: ver is debug
gcc -g -Ddebug -c -o test.o test.c
gcc -o test test.o
----------------------------------------
清理,无所谓版本信息
----------------------------------------
[/pts/2@hjj ~/test]$ make clean
Makefile:9: ver is not debug
rm test test.o
----------------------------------------
编译release 版本
----------------------------------------
[/pts/2@hjj ~/test]$ make
Makefile:9: ver is not debug
gcc -c -O3 -c -o test.o test.c
gcc -o test test.o
**************************************************
RELEASE = abc
#ifdef 变量名称不能加$()
ifdef RELEASE
$(warning RELEASE defined)
else
$(warning RELEASE not defined)
endif
#ifeq 后面参数要叫$(), 因为是值引用, 值可以为数值或字符串
ifeq ($(RELEASE),abc)
$(warning RELEASE eqal abc)
else
$(warning RELEASE not equal abc)
endif
all:
@echo ok!
**************************************************
make 编译不同版本,例如debug, release 的简单示例。
用make 变量ver, 控制CFLAGS 变量,从而编译出不同版本。
[/pts/2@hjj ~/test]$ cat test.c
#include <stdio.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
char *tty=ttyname(0);
printf("tty is %s\n",tty);
return 0;
}
[/pts/2@hjj ~/test]$ cat Makefile
CC = gcc
TARGET = test
OBJS = test.o
ifeq ($(ver), debug)
$(warning ver is debug)
CFLAGS = -g -Ddebug
else
$(warning ver is not debug)
CFLAGS = -c -O3
endif
$(TARGET): $(OBJS)
$(CC) -o $@ $^
clean:
rm test test.o
注释: makefile 采用了ifeq-else-endif 结构
可以判别莫个make变量是否定义。
make变量可以在makefile中定义,也可以由make命令行传递。
由于makefile 支持环境变量,所以你预先定义了环境变量,也可以不在命令行中传递而直接使用环境变量
这种机制使得编写脚本控制不同的复杂的编译成为可能,
例如支持各种地域的不同的版本。用地域变量,控制make的编译选项/D,控制编译出不同的版本
----------------------------------------
编译debug 版本, 从命令行传递变量
----------------------------------------
[/pts/2@hjj ~/test]$ make ver=debug
Makefile:6: ver is debug
gcc -g -Ddebug -c -o test.o test.c
gcc -o test test.o
----------------------------------------
清理,无所谓版本信息
----------------------------------------
[/pts/2@hjj ~/test]$ make clean
Makefile:9: ver is not debug
rm test test.o
----------------------------------------
编译release 版本
----------------------------------------
[/pts/2@hjj ~/test]$ make
Makefile:9: ver is not debug
gcc -c -O3 -c -o test.o test.c
gcc -o test test.o
**************************************************
0 0
- makefile 的 ifdef, ifeq 使用及辨析
- makefile 的ifeq和ifdef的区别
- makefile 的ifeq和ifdef的区别
- makefile 的ifeq和ifdef的区别
- makefile 的ifeq和ifdef的区别
- makefile中的ifeq、ifdef、ifneq的区别
- Android.mk/makefile 的ifeq和ifdef的区别
- makefile中的条件判断ifeq、ifneq、ifdef
- 日常笔记之makefile中的ifeq ifdef
- Linux Makefile ifeq正确使用
- ifeq ifneq ifdef ifndef
- ifeq ifneq ifdef ifndef
- ifeq ifneq ifdef ifndef
- ifeq ifneq ifdef ifndef
- Makefile中的ifeq 多条件使用
- Makefile中的ifeq 多条件使用
- Makefile ifeq or statement
- Makefile ifneq ifeq strip
- 【SSH三大框架】Hibernate基础第十三篇:lazy、constrained、fetch三个属性的作用和使用方法
- “按需加载”的应用
- 【计算几何初步-凸包-Jarvis步进法。】【HDU1392】Surround the Trees
- jQuery获取Select元素,并选择的Text和Value:
- 人品计算器
- makefile 的 ifdef, ifeq 使用及辨析
- 第14周--多科成绩单(2)
- 多线程文件下载
- 乾隆年间贪污贿赂成风:皇帝敛财不逊臣子
- 优化Android应用内存的若干方法
- Oracle 11g下 ORA-01417的解决办法
- 代码是灵魂,注释是心声
- 强大的shell命令
- javascript 植入cookie,读取cookie