makefile 進階--可以用於實際嵌入式工程中的文件編寫1

               之前makefile的編寫僅僅是初級的入門,無法對實際的嵌入式工程進行編譯,從現在開始,記錄一下makefile怎樣擴展應用到實際工程中.

       第一步,引入目錄

 RM=rm
RMFLAGS=-f
 CC=cc
OBJS=hello.o hello1.o
MKDIR=mkdir
DIRS=dirobj direxe
EXE=main

.PHONY:all clean
all:$(EXE) $(DIRS)
$(DIRS):
    $(MKDIR) $@
$(EXE):$(OBJS)
    $(CC) -o $@ $^
%.o:%.c                        #moshi
    $(CC) -o $@ -c $^
clean:
    rm -f *.o

運行結果

y-G41D3:~/zmakefile/make3$ ls
direxe  hello1.c  hello1.o  hello.o  makefile   基礎文件
dirobj  hello1.h  hello.c   main     makefile~  基礎文件~
melody@melody-G41D3:~/zmakefile/make3$ make clean
rm -f *.o
melody@melody-G41D3:~/zmakefile/make3$ ls
direxe  hello1.c  hello.c  makefile   基礎文件
dirobj  hello1.h  main     makefile~  基礎文件~




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章