簡單通用的makefile檔案

來源:互聯網
上載者:User
##########################################################################
# 通用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檔案,使用比較簡單,僅使用於源檔案在同一目錄下應用。
詳細,參考文檔內說明即可

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.