##########################################################################
# 通用makefile檔案
# makefile規則
# target ... : prerequisites ...
# command
# ...
# ...
# target 是一個目標檔案,可以是Object File,也可以是執行檔案?
# prerequisites是要產生那個target所需要的檔案或是目標,用空格隔開
# command也就是make需要執行的命令。(任意的Shell命令,以Tab開頭)
##########################################################################
# 定義編譯器
CC := g++
# 定義應用程式名稱或者庫名稱
AppName := ugg
# 版本資訊(產生so檔案需要設定)
#APP_VERSION = 1
# 子目錄
SRCDIRS :=
# 編譯選項
FLAGS := -g -Wall
CFLAGS := $(FLAGS)
CXXFLAGS := $(CFLAGS)
##########################################################################
# 以下部分不需修改
# 定義編譯源檔案
SRC = $(wildcard *.c) $(wildcard *.cc) $(wildcard *.cpp)
# 定義包含檔案,以及庫引用
#LINC := -I/home/y/include
LINC :=
#LLDLIBS := -L/home/y/lib -L/usr/local/lib -lmysqlclient -lyconf -llog4cpp_y LLDLIBS :=
OBJS := $(patsubst %.cpp,%.o, $(patsubst %.c, %.o, $(patsubst %.cc, %.o, $(SRC))))
all: depend $(OBJS)
$(CC) $(FLAGS) $(OBJS) -o $(AppName)
depend: $(SRC)
@$(CC) $(FLAGS) -w -MM $^ > $@
-include depend
.PHONY:clean install uninstall rebuild start check test tar
# 刪除過程檔案
clean:
-rm $(AppName) $(OBJS) depend
# 安裝
install:
echo "No Support!";
# 卸載
uninstall:
echo "No Support!";
# 重新編譯
rebuild: clean all
#開始運行
start:
-./$(AppName)
# 測試
check:
-make -t
# 測試
test: check
# 打包
tar:rebuild
echo "No Support!"
#################檔案結束#####################
自己寫的makefile檔案,使用比較簡單,僅使用於源檔案在同一目錄下應用。
詳細,參考文檔內說明即可