makefile备份-goods search project

 

CC      = gcc
CPP     = g++
AR = ar
RM      = rm -f

#Define the resource compiler.
RC = windres

## debug flag  
DBG_ENABLE := 1

OS = $(shell uname)

## source file path  
SRC_PATH  := ./src/
SRC_PATH_EXT := 
DEMO :=./demo/main.cpp

## target file name  
TARGET     := goodsSearch
DEMO_TARGET := run

## get all source files  
SRCS := $(foreach spath, $(SRC_PATH), $(wildcard $(spath)*.c) $(wildcard $(spath)*.cpp))

## all .o based on all .c/.cpp
OBJS = $(SRCS:.c=.o)
OBJS := $(OBJS:.cpp=.o) 

## macro define
DEFS := __LINUX__ OS_LINUX _FILE_OFFSET_BITS=64

#if freeimage is static-linked use this !
#DEFS += FREEIMAGE_LIB

## need libs, add at here  
LIBS := opencv_core opencv_highgui opencv_imgproc cafl boost_system boost_thread glog hdf5_serial_hl hdf5_serial boost_regex gflags leveldb  cublas curand sqlite3 cudnn cudart

DEMO_LIBS = $(LIBS)
DEMO_LIBS += goodsSearch

## used headers  file path  
INCLUDE_PATH := ./include ./include/third /usr/local/cuda/include  ./src

#$(warning $(INCLUDE_PATH))

## used include librarys file path  
LIBRARY_PATH := ./  ./libs  /usr/include/tbb /usr/lib/python2.7/json /usr/local/cuda/lib64 ./opencvlibs /usr/lib/aarch64-linux-gnu /usr/local/cuda-10.0/targets/aarch64-linux/lib /home/software/gflags/build/lib
 
## debug for debug info, when use gdb to debug  
ifeq (1, ${DBG_ENABLE})   
CFLAGS += -D_DEBUG -g -DDEBUG=1 
else
CFLAGS += -O2 -DNDEBUG
endif

#for ENCYPT flags

ifeq ($(OS), Linux)
LIBS += dl rt
CFLAGS += -fPIC
TARGET_EXT := .so
LIBRARY_PATH += 
LDFLAGS += -Wl,--rpath=./libs 
endif

#CFLAGS += -msse4.2 -march=core2 -pipe $(foreach m, $(DEFS), -D$(m)) 
#CFLAGS += -march=armv8.2-a -pipe $(foreach m, $(DEFS), -D$(m)) 

CFLAGS += -march=armv8.2-a -pipe $(foreach m, $(DEFS), -D$(m)) 
  
## get all include path  
CFLAGS  += $(foreach dir, $(INCLUDE_PATH), -I$(dir))  

CXXFLAGS += $(CFLAGS) -std=c++11

## get all library path  
LDFLAGS += -lpthread $(foreach lib, $(LIBRARY_PATH), -L$(lib))
DEMO_LDFLAGS := $(LDFLAGS)
## get all librarys  
LDFLAGS += $(foreach lib, $(LIBS), -l$(lib))

DEMO_LDFLAGS += $(foreach lib, $(DEMO_LIBS), -l$(lib))

RCFLAGS ?= -DNDEBUG


default: all

%.o: %.c
    $(CC) $(CFLAGS) -g -c $< -o $@

%.o: %.cpp
    $(CPP) $(CXXFLAGS) -g -c $< -o $@
    
all: $(OBJS) $(RESOURCE)
    #$(CPP) $(CXXFLAGS) -o $(TARGET) $(OBJS) $(RESOURCE) $(LDFLAGS)
    $(CPP) $(CXXFLAGS) -g -shared -o lib$(TARGET)$(TARGET_EXT) $(OBJS) $(RESOURCE) $(LDFLAGS)
    mv libgoodsSearch.so ./libs
    $(CPP) $(CXXFLAGS) -g -o $(DEMO_TARGET) $(DEMO) $(DEMO_LDFLAGS)

clean:  
    $(RM) $(OBJS) $(DEMO_TARGET) $(TARGET).* $(RESOURCE)

 

posted @ 2020-06-14 21:22  cumtchw  阅读(131)  评论(0编辑  收藏  举报