首页
学习
活动
专区
工具
TVP
发布

Eureka的技术时光轴

专栏作者
338
文章
685443
阅读量
39
订阅数
makefile 的 ifdef, ifeq 使用及辨析
#可以用命令行传递变量 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
战神伽罗
2019-07-24
7.6K1
bochs compile 编译
The standard compile uses the configure script, but the Windows platform cannot run the configure script natively. The current solution to this problem is that the Bochs configure script must be run on a different platform that does support shell scripts, with options that cause it to configure for a Win32 platform instead of the native one. Many people have access to a UNIX machine that could run the configure script, or you can use Cygwin or MinGW/MSYS to run the configure script. [3].
战神伽罗
2019-07-24
7640
vscode基于Linux和Windows下c/c++的多文件编译与连接
cygwin64/home/xxx/.bash_profile ,末尾加上如下代码(后面vscodeMake.bat要用到环境变量"_T"):
战神伽罗
2019-07-24
2.8K0
没有更多了
社区活动
腾讯技术创作狂欢月
“码”上创作 21 天,分 10000 元奖品池!
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档