Makefile万能写法(gcc程序以及arm-linux-gcc程序)
2013-12-07 14:11
525 查看
转自:http://7071976.blog.51cto.com/7061976/1322211
在linux下使用gcc 编译时,Makefile的万能写法 ,每次只需更改要生成的目标文件名称(test)尽可:
在arm交叉编译时的makefile的万能写法,只需更改int.bin,以及int_elf,int.dis名称即可
更多Makefile学习可百度:GUN MAKE
手册
Makefile的规则
target要求
1、要生成的可执行文件或obj文件;
2、也可以是一个执行的动作名称:clean
Makefile执行规则:
1、执行make时,仅当hell.c文件比hello.o文件更新,才会执行命令:arm-linux-gcc -o hello.o hello.c;
2、如果没有hello.o文件也会执行
3、运行 make clean 时,由于clean 没有依赖,它的命令也会被强制执行
makefile赋值:
Makefile中的"="":="、"?="和"+="区别是:
"="是直接给变量赋值。
":="是将":="右边中包含的变量直接展开给左边的变量赋值。
"?="是在该变量没有被赋值 的情况下为其赋值。
"+="是给该变量追加值。
例:
a = 1
b = 2
c := $(a) 3
d = 4
d ?= 5
b += 6
结果:
a=1
c=1 3
d=4
b=2 6
使用makefile 编译c程序:
1、一些make函数的巧用
1、$(patsubst pattern, replacement,text)
原理:用replacement替换text中符合格式"pattern" 的字
如:$(patsubst %.c, %.o, b.a.c hello.c helloworld.c)
结果为字符串:b.a.o hello.o helloworld.o
2、$(shell command arguments)
3、$(basename names.....)
原理:抽取除"names...."中每一个文件名中除后缀外的一切字符
比如:
$(basename head.S hello.c helloworld.c)
结果为:head hello helloworld
4、$(addsuffix suffix,names...)
如:$(addsuffix .c, head hello helloworld)
结果为:head.o hello.o hello.o helloworld.o
在linux中编译c程序时写make文件就有一些技巧了
在 arm 嵌入式交叉编译时,就可以这样编写Makefile。相应的程序名称相应修改
在linux下使用gcc 编译时,Makefile的万能写法 ,每次只需更改要生成的目标文件名称(test)尽可:
手册
Makefile的规则
1、要生成的可执行文件或obj文件;
2、也可以是一个执行的动作名称:clean
Makefile执行规则:
1、执行make时,仅当hell.c文件比hello.o文件更新,才会执行命令:arm-linux-gcc -o hello.o hello.c;
2、如果没有hello.o文件也会执行
3、运行 make clean 时,由于clean 没有依赖,它的命令也会被强制执行
makefile赋值:
Makefile中的"="":="、"?="和"+="区别是:
"="是直接给变量赋值。
":="是将":="右边中包含的变量直接展开给左边的变量赋值。
"?="是在该变量没有被赋值 的情况下为其赋值。
"+="是给该变量追加值。
例:
a = 1
b = 2
c := $(a) 3
d = 4
d ?= 5
b += 6
结果:
a=1
c=1 3
d=4
b=2 6
使用makefile 编译c程序:
1、一些make函数的巧用
1、$(patsubst pattern, replacement,text)
原理:用replacement替换text中符合格式"pattern" 的字
如:$(patsubst %.c, %.o, b.a.c hello.c helloworld.c)
结果为字符串:b.a.o hello.o helloworld.o
2、$(shell command arguments)
3、$(basename names.....)
原理:抽取除"names...."中每一个文件名中除后缀外的一切字符
比如:
$(basename head.S hello.c helloworld.c)
结果为:head hello helloworld
4、$(addsuffix suffix,names...)
如:$(addsuffix .c, head hello helloworld)
结果为:head.o hello.o hello.o helloworld.o
在linux中编译c程序时写make文件就有一些技巧了
在 arm 嵌入式交叉编译时,就可以这样编写Makefile。相应的程序名称相应修改
相关文章推荐
- Makefile万能写法(gcc程序以及arm-linux-gcc程序)-转
- Makefile万能写法(gcc程序以及arm-linux-gcc程序)
- Linux下gcc与g++用法以及编写makefile
- makefile初步制作,arm-linux- (gcc/ld/objcopy/objdump)详解【转】
- Linux下gcc与g++用法以及编写makefile
- makefile初步制作,arm-linux- (gcc/ld/objcopy/objdump)详解
- makefile 时 出现arm-linux-gcc: Command not found
- arm-linux-gcc裸机程序开发(三)
- Android 运行 C/C++程序 (使用 arm-linux-gcc 交叉编译环境)
- linux下通过编写测试程序的方式来确认arm-linux-gnueabihf-gcc-4.6lib和.h文件的安装位置,为复制libnl做准备
- Linux下使用codeblocks交叉编译ARM-LINUX-GCC程序
- 安装交叉编译工具arm-none-linux-gnueabi-gcc——Linux上编译在android上运行的c程序
- 【opencv交叉编译问题】用arm-linux-gnueabihf-gcc编译程序无法执行
- 虚拟机与主机共享以及arm-linux-gcc3.3.2安装过程
- 交叉编译环境以及开发板上-/bin/sh: ./hello: not found(使用arm-linux-gcc -static -o 来进行静态编译)
- arm-linux-gcc-4.4.3交叉编译google的protobuf。以及使用方法
- Linux中gcc,g++常用编译选项以及makefile的编写
- linux2.6.32.2内核支持arm-linux-gcc 2.95.3静态编译的程序(实录)
- linux gcc 万能makefile的收集
- Linux下gcc与g++用法以及编写makefile