对比makefile二种写法:
第一种:
-include ./makefile.init
RM := rm -rf
CPP_SRCS +=
./GatePlayerMgr.cpp
./GateSharememe.cpp
./GlobleGate.cpp
./NetClient.cpp
./NetDBCache.cpp
./NetGame.cpp
./NetWeb.cpp
./NetWorld.cpp
./gateHead.cpp
./MsgWaitConfig.cpp
./main.cpp
OBJS +=
./GatePlayerMgr.o
./GateSharememe.o
./GlobleGate.o
./NetClient.o
./NetDBCache.o
./NetGame.o
./NetWeb.o
./NetWorld.o
./gateHead.o
./MsgWaitConfig.o
./main.o
CPP_DEPS +=
./GatePlayerMgr.d
./GateSharememe.d
./GlobleGate.d
./NetClient.d
./NetDBCache.d
./NetGame.d
./NetWeb.d
./NetWorld.d
./gateHead.d
./MsgWaitConfig.d
./main.d
%.o: ./%.cpp
g++ -D_GATE_SERVER_ -D__LINUX__ -I"/root/workspace/server_yufei/Server/Gate" -I/root/workspace/server_yufei/Server/thirdparty/lua -I"/root/workspace/server_yufei/Server/Common" -I/root/workspace/server_yufei/Server/thirdparty/protobuf-2.5.0/src -I/root/workspace/server_yufei/Server/thirdparty/jsoncpp-src-0.5.0 -I/root/workspace/server_yufei/Server/thirdparty/mysql/linux_64/include -I/root/workspace/server_yufei/Server/thirdparty/ExtraSocket -I/root/workspace/server_yufei/Server/Base/include -I/root/workspace/server_yufei/Server/Extralib -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
USER_OBJS :=
LIBS := -lBase -lCommon -lExtralib -lExtraSocket -lprotobuf -ljson_linux-gcc-4.4.7_libmt -lrt
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
-include ./makefile.defs
all: Gate
Gate: $(OBJS) $(USER_OBJS)
g++ -L/root/workspace/libs/output_lib -L"/root/workspace/server_yufei/Server/Extralib/" -L"/root/workspace/server_yufei/Server/Base/" -L"/root/workspace/server_yufei/Server/Common/" -L/root/workspace/server_yufei/Server/thirdparty/jsoncpp-src-0.5.0/libs/linux-gcc-4.4.7 -L/root/workspace/server_yufei/Server/thirdparty/protobuf-2.5.0/lib_linux -L/root/workspace/server_yufei/Server/thirdparty/mysql/linux_64/lib -o"Gate" $(OBJS) $(USER_OBJS) $(LIBS)
$(MAKE) --no-print-directory post-build
clean:
-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) Gate
-
post-build:
-cp -u Gate ./././bin
-
.PHONY: all clean dependents
.SECONDARY: post-build
-include ./makefile.targets
第二种:
get_all_sources=$(shell find $(1) -name "*.$(2)")
CCSRC_FLIE=$(call get_all_sources,./,cc)
CPPSRC_FLIE=$(call get_all_sources,./,cpp)
TEMP_OBJ+=$(CCSRC_FLIE:.cc=.o)
TEMP_MD+=$(CCSRC_FLIE:.cc=.d)
TEMP_OBJ+=$(CPPSRC_FLIE:.cpp=.o)
TEMP_MD+=$(CPPSRC_FLIE:.cpp=.d)
INCLUDE=-I ./
-I ../../Server/Common
-I ../../Server/Base/include
-I ../../Server/Extralib
-I ../../Server/thirdparty/lua
-I ../../Server/thirdparty/protobuf-2.5.0/src
-I ../../Server/thirdparty/jsoncpp-src-0.5.0
-I ../../Server/thirdparty/ExtraSocket
-I ../../Server/thirdparty/mysql/linux_64/include
LIB_INCLUDE = -L../../Server/Common/
-L ../../Server/Base/
-L ../../Server/Extralib/
-L ../../Server/thirdparty/ExtraSocket
-L ../../Server/thirdparty/lua
-L ../../Server/thirdparty/jsoncpp-src-0.5.0/libs/linux-gcc-4.4.7
-L ../../Server/thirdparty/protobuf-2.5.0/lib_linux
-L ../../Server/thirdparty/mysql/linux_64/lib
TEMP_LIB=./Gate
LIBS = -lBase -lCommon -lmysqlclient -lLuaEngine -lprotobuf -ljson_linux-gcc-4.4.7_libmt -lExtraSocket -lExtralib -lrt -lmysqlclient
all:$(TEMP_OBJ) $(TEMP_LIB)
$(TEMP_LIB):$(TEMP_OBJ)
@echo "$(TEMP_OBJ) > $(TEMP_LIB)"
g++ $(LIB_INCLUDE) -o $(TEMP_LIB) $(TEMP_OBJ) $(LIBS)
%.o:%.cc
@echo "$< > $@"
g++ -D__LINUX__ -D_GATE_SERVER_ $(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
%.o:%.cpp
@echo "$< > $@"
g++ -D__LINUX__ -D_GATE_SERVER_ $(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
clean:
@rm -vrf $(TEMP_LIB)
$(TEMP_MD)
$(TEMP_OBJ)