Makefile 프로젝트 파일

4783 단어
###############################################################
# File Name     : Makefile
# Author        : skytrails
# Email         : [email protected]
# Create Time   : 2015-09-20 17:51
################################################################
# 

_MK_DEBUG = 0
ifeq ($(_MK_DEBUG), 1)
	CC := @g++
	MKDIR := @mkdir
else
	CC := g++
	MKDIR := mkdir
endif
RM = rm -f
BIN = $(shell pwd)/bin
UTIL_LIB = $(BIN)/libUtil.so
PUB_LIB = $(BIN)/libPubClass.so
BUS_LIB = $(BIN)/libBusiness.so
TARGET=$(BIN)/startapp.1.0
CFLAGS = -O2 
export OBJSDIR=$(shell pwd)/objs
#----------------------------test
TEST_DIRS = src/test
TEST_FILES = $(foreach dir, $(TEST_DIRS), $(wildcard $(dir)/*.cpp))
TEST_OBJS = $(patsubst src%, objs%, $(patsubst %.cpp, %.o, $(TEST_FILES)))
#----------------------------util
UTILDIRS = src/util/deamon 
PUBFILES = $(foreach dir, $(UTILDIRS), $(wildcard $(dir)/*.cpp $(dir)/*.c))
UTIL_DEP = $(patsubst src%, objs%, $(patsubst %.cpp, %.d, $(patsubst %.c, %.cpp, $(PUBFILES))))
UTIL_DDIRS = $(patsubst src%, objs%, $(UTILDIRS))
PUBOBJS = $(patsubst %.d, %.o, $(UTIL_DEP))
#---------------------------util end
#---------------------------pubclass
PUB_DIRS = src/pubclass\
src/pubclass/log
PUB_FILES = $(foreach dir, $(PUB_DIRS), $(wildcard $(dir)/*.cpp))
PUB_OBJS_DIRS = $(patsubst src%, objs%, $(PUB_FILES))
PUB_OBJS = $(patsubst src%, objs%, $(patsubst %.cpp, %.o, $(PUB_FILES)))
PUB_DEP = $(patsubst %.o, %.d, $(PUB_OBJS))

#---------------------------pubclass end
#---------------------------business begin
BUS_DIRS = src/business
BUS_FILES = $(foreach dir, $(BUS_DIRS), $(wildcard $(dir)/*.cpp))
BUS_OBJS_DIRS = $(patsubst src%, objs%, $(BUS_DIRS))
BUS_OBJS = $(patsubst src%, objs%, $(patsubst %.cpp, %.o, $(BUS_FILES)))
BUS_DEP = $(patsubst %.o, %.d, $(BUS_OBJS))
#---------------------------business end
all:$(UTIL_DEP) $(PUB_DEP) $(BUS_DEP) $(UTIL_LIB) $(PUB_LIB) $(BUS_LIB) $(TARGET)
	@ln -sf $(TARGET) $(BIN)/exp
	@ctags -R  --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++

$(PUB_DEP):objs/%.d:src/%.cpp
	$(MKDIR) -p $(dir $@)
	$(CC) -MM $< |\
	sed "$ s+$(patsubst %.d,%.o, $(notdir $@))+$(patsubst %.d,%.o,$@)+g" |\
	sed '$$ a\\tg++ -fPIC -shared -c -o $(patsubst %.d, %.o, $@) $<' > $@

$(UTIL_DEP):objs/%.d:src/%.cpp
	$(MKDIR) -p $(dir $@)
	$(CC) -MM $< |\
	sed "$ s+$(patsubst %.d,%.o, $(notdir $@))+$(patsubst %.d,%.o,$@)+g" |\
	sed '$$ a\\tg++ -fPIC -shared -c -o $(patsubst %.d, %.o, $@) $<' > $@

$(BUS_DEP):objs/%.d:src/%.cpp
	$(MKDIR) -p $(dir $@)
	$(CC) -MM $< |\
	sed "$ s+$(patsubst %.d,%.o, $(notdir $@))+$(patsubst %.d,%.o,$@)+g" |\
	sed '$$ a\\tg++ -fPIC -shared -c -o $(patsubst %.d, %.o, $@) $<' > $@
#----- 
$(UTIL_LIB):$(PUBOBJS)
	$(CC) -shared -fPIC $< -o $@ $(CFLAGS)

$(PUB_LIB):$(PUB_OBJS)
	$(CC) -shared -fPIC $^ -o $@ $(CFLAGS)

$(BUS_LIB):$(BUS_OBJS)
	$(CC) -shared -fPIC $^ -o $@ $(CFLAGS) -L$(BIN) -lPubClass

$(TARGET):src/startApp.cpp
	#$(CC) -rdynamic $< -o $@ -ldl -L$(BIN) -lPubClass
	$(CC) $< -o $@ -L$(BIN) -ldl

-include $(UTIL_DEP)
-include $(PUB_DEP)
-include $(BUS_DEP)

.PHONY : clean touch
test:$(TEST_FILES)
	$(MKDIR) -p $(BIN)/test
	$(CC) $^ -o $(BIN)/test/$@ 
clean:
	find objs/ -type f | xargs rm -f;
	find bin/ -type f | xargs rm -f;
touch:

엔지니어링 디렉토리 트리는 다음과 같습니다.
.├── bin│   ├── exp ->/home/skytrails/back_trunk/bin/startapp.1.0│   └── startapp.1.0├── Makefile├── objs│   ├── business│   │   ├── exp.d│   │   └── exp.o│   ├── pubclass│   │   ├── Debug│   │   ├── excApp.d│   │   ├── excApp.o│   │   ├── log│   │   │   ├── Debug.d│   │   │   ├── Debug.o│   │   │   ├── Trace.d│   │   │   └── Trace.o│   │   ├── process.d│   │   └── process.o│   └── util│       └── deamon│           ├── deamon.d│           └── deamon.o├── shell│   ├── home│   └── vimplugin│       ├── nerdtree.zip│       └── omnicppcomplete-0.41.zip├── src│   ├── business│   │   ├── exp.cpp│   │   └── exp.h│   ├── pubclass│   │   ├── excApp.cpp│   │   ├── excApp.h│   │   ├── log│   │   ├── process.cpp│   │   └── process.h│   ├── startApp.cpp│   ├── test│   │   └── test.cpp│   ├── third-part│   └── util│       ├── deamon│       │   ├── deamon.cpp│       │   └── deamon.h│       └── types.h└── tags

좋은 웹페이지 즐겨찾기