makefile 进阶--可以用于实际嵌入式工程中的文件编写2目录引入
2016-03-23 16:37
459 查看
RM=rm
RMFLAGS=-fr
CC=cc
OBJS=hello.o hello1.o
MKDIR=mkdir
DIRS=dirobj direxe
EXE=main
EXE:=$(addprefix direxe/,$(EXE))
OBJS:=$(addprefix dirobj/,$(OBJS))
.PHONY:all clean
all:$(EXE) $(DIRS)
$(DIRS):
$(MKDIR) $@
$(EXE):$(OBJS)
$(CC) -o $@ $^
dirobj/%.o:%.c #moshi
$(CC) -o $@ -c $^
clean:
$(RM) $(RMFLAGS) dirobj
执行结果:
melody@melody-G41D3:~/zmakefile/make4$ make
cc -o dirobj/hello.o -c hello.c
cc -o dirobj/hello1.o -c hello1.c
cc -o direxe/main dirobj/hello.o dirobj/hello1.o
melody@melody-G41D3:~/zmakefile/make4$ ./main
myprint 1!
melody@melody-G41D3:~/zmakefile/make4$ ls
direxe hello1.c hello.c makefile 基础文件
dirobj hello1.h main makefile~ 基础文件~
melody@melody-G41D3:~/zmakefile/make4$ cd dirobj
melody@melody-G41D3:~/zmakefile/make4/dirobj$ ls
hello1.o hello.o
melody@melody-G41D3:~/zmakefile/make4$ make clean
rm -fr dirobj
melody@melody-G41D3:~/zmakefile/make4$ ls
direxe hello1.h main makefile~ 基础文件~
hello1.c hello.c makefile 基础文件
RMFLAGS=-fr
CC=cc
OBJS=hello.o hello1.o
MKDIR=mkdir
DIRS=dirobj direxe
EXE=main
EXE:=$(addprefix direxe/,$(EXE))
OBJS:=$(addprefix dirobj/,$(OBJS))
.PHONY:all clean
all:$(EXE) $(DIRS)
$(DIRS):
$(MKDIR) $@
$(EXE):$(OBJS)
$(CC) -o $@ $^
dirobj/%.o:%.c #moshi
$(CC) -o $@ -c $^
clean:
$(RM) $(RMFLAGS) dirobj
执行结果:
melody@melody-G41D3:~/zmakefile/make4$ make
cc -o dirobj/hello.o -c hello.c
cc -o dirobj/hello1.o -c hello1.c
cc -o direxe/main dirobj/hello.o dirobj/hello1.o
melody@melody-G41D3:~/zmakefile/make4$ ./main
myprint 1!
melody@melody-G41D3:~/zmakefile/make4$ ls
direxe hello1.c hello.c makefile 基础文件
dirobj hello1.h main makefile~ 基础文件~
melody@melody-G41D3:~/zmakefile/make4$ cd dirobj
melody@melody-G41D3:~/zmakefile/make4/dirobj$ ls
hello1.o hello.o
melody@melody-G41D3:~/zmakefile/make4$ make clean
rm -fr dirobj
melody@melody-G41D3:~/zmakefile/make4$ ls
direxe hello1.h main makefile~ 基础文件~
hello1.c hello.c makefile 基础文件
相关文章推荐
- MySQL Replication, 主从和双主配置
- Cg入门17:Fragment shader - 片段级光照(添加阴影)
- 不认识spring xml配置文件dtd和xsd类型,血与泪的教训啊
- DFS之素数环问题
- 世界各大名牌大学课件
- Puppet模块(九):redis模块
- ubuntu开机出现:system program problem detected
- Android5.0+(Percent 百分比布局)
- JVM调优总结
- RPC学习(一):RPC的基础
- 微信高仿
- SharePoint2013 IT Professional - Permission Level
- Java字符串:StringBuffer使用详解及源码分析
- ThreadLocal
- Android中使用Adapter和ListView的使用
- dos 命令大全
- 对于画图板项目的相关总结和思考
- redis学习总结(未完成)
- App 开发:Hybrid 架构下的 HTML5 应用加速方案
- React-Native Android 学习笔记——2,自定义 logger