转载的makefile

#set your project name
PRJ_NAME = MGameServer
#set your project type : choose one below
PRJ_TYPE = g++ -o
#PRJ_TYPE =
#PRJ_TYPE = ar -r

#set Debug or Release
Compile_Flag = Debug
#Compile_Flag = Release

#set your output path
Output:= bin

#set your source folder
SRC := SRC
#add the lib you used here
#LIBS := -lLib1 -lLib2 -lLib3
LIBS := -levent -llua -lmysqlclient -levent_pthreads  -lpthread
#LIBPATH := -Lpath1 -Lpath2 -Lpath3
LIBPATH := -L/root/mysql/lib -L/usr/libevent/lib
INCLUDEPATH := -I/usr/libevent/include -I/root/workspace/mysql/include -I/root/workspace/GameServer/include 
# INCLUDEPATH := -I/usr/lib/XXX/include

###################################
#DON"T MODIFY THE BELOWS

#combine output folder
FinalOutput := $(Output)/$(Compile_Flag)/

#list all dirs
SUBDIRS := $(shell find $(SRC) -type d)
#flags in makefile
DEBUG_FLAG = -std=c++0x -O0 -g3 -Wall -c -fmessage-length=0
RELEASE_FLAG = -std=c++0x  -O3 -Wall -c -fmessage-length=0
RM := rm -rf

#set compile flag
ifeq ($(Compile_Flag),Debug)
CFLAGS := $(DEBUG_FLAG)
else
CFLAGS := $(RELEASE_FLAG)
endif

#prepare files
CPP_SRCS:=$(shell find $(SRC) -name *.cpp)
OBJS:=$(CPP_SRCS:%.cpp=$(FinalOutput)%.o)

#all target
all: dir $(FinalOutput)$(PRJ_NAME)
dir:
 mkdir -p $(FinalOutput);
 for val in $(SUBDIRS);do
   mkdir -p $(FinalOutput)$${val};
 done;

#tool invocations
$(FinalOutput)$(PRJ_NAME):$(OBJS)
 @echo 'Building target: $@'
 @echo 'Invoking:GCC C++ Linker'
 $(PRJ_TYPE) $(LIBPATH) -o"$@" $^ $(LIBS)
 @echo 'Finished building target: $@'
 @echo ' '

$(FinalOutput)%o:./%cpp
 @echo 'Building file: $<'
 @echo 'Invoking:GCC C++ Compiler'
 g++ $(CFLAGS) $(INCLUDEPATH) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
 @echo 'Finished building: $<'
 @echo ' '

#other targets
clean:
 -$(RM) $(Output)/*
 -@echo ' '
.PHONY:all clean
.SECONDARY:

原文地址:https://www.cnblogs.com/liulebao/p/3382150.html