• Makefile工程文件


    ###############################################################
    # File Name     : Makefile
    # Author        : skytrails
    # Email         : skytrails@163.com
    # 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

    ..... created by skytrails
  • 相关阅读:
    jieba库与词云的使用——以孙子兵法为例
    Python 计算π及进度条显示
    风车
    UDP协议编程
    matplotlib的基本使用、绘制雷达图及绘制数学函数
    numpy库的学习笔记及自定义手绘风
    PIL库的学习总结及生成GIF
    预测球队比赛结果及利用pyinstaller打包文件
    汉诺塔的实现
    有进度条的圆周率计算
  • 原文地址:https://www.cnblogs.com/skytrails/p/4808325.html
Copyright © 2020-2023  润新知