您的位置:首页 > 其它

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 基础文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: