# # Build rules # # Keep secondary files .SECONDARY: include $(ROOT_DIR)/Makefile.config ifeq ($(strip $(DIR_TCLAP)),) $(error "Build requires TCLAP package (http://tclap.sourceforge.net)") endif # if install, read build details ifeq "$(MAKE-TARGET)" "install" include $(ROOT_DIR)/.makefile.build endif # Object directory OBJ_DIR = .linux # Use gcc4 CXX = g++ # Use rpath or not WITH_RPATH ?= 1 LDFLAGS = ifeq "$(MAKE-TARGET)" "static" WITH_RPATH = 0 LDFLAGS += -static -lboost_system -lboost_thread -lpthread endif # check BOOST USE_BOOST ?= 1 # check boost threads USE_BOOST_THREAD ?= 1 ifeq ($(strip $(LIB_BOOST_THREAD)),) USE_BOOST_THREAD = 0 USE_THREADPOOL = 0 endif ifeq ($(strip $(DIR_THREADPOOL)),) USE_THREADPOOL = 0 endif # Library and binary directories BASE_DIR := $(shell cd $(ROOT_DIR) ; pwd) # Install directories # With rpath, enforce install dir same as build # Without, use same as build as default # prefix - install topdir # libdir/bindir - install lib/bin # BASE_DIR - build top dir # LIB_DIR/BIN_DIR - build top dir # # with rpath : # build and install dirs are the same # default top is BASE_DIR # else : # build is always under BASE_DIR # install under prefix (default BASE_DIR) # #ifeq ($(WITH_RPATH),1) #prefix ?= $(BASE_DIR) #libdir = $(prefix)/lib #bindir = $(prefix)/bin ##LIB_DIR := $(shell mkdir -p $(libdir) ; cd $(libdir) ; pwd) ##BIN_DIR := $(shell mkdir -p $(bindir) ; cd $(bindir) ; pwd) #LIB_DIR := $(libdir) #BIN_DIR := $(bindir) #else #LIB_DIR := $(shell mkdir -p $(BASE_DIR)/lib ; cd $(BASE_DIR)/lib ; pwd) #BIN_DIR := $(shell mkdir -p $(BASE_DIR)/bin ; cd $(BASE_DIR)/bin ; pwd) #prefix ?= $(BASE_DIR) #libdir ?= $(LIB_DIR) #bindir ?= $(BIN_DIR) #endif LIB_DIR := $(shell mkdir -p $(BASE_DIR)/lib ; cd $(BASE_DIR)/lib ; pwd) BIN_DIR := $(shell mkdir -p $(BASE_DIR)/bin ; cd $(BASE_DIR)/bin ; pwd) prefix ?= $(BASE_DIR) libdir ?= $(LIB_DIR) bindir ?= $(BIN_DIR) LIB_INSTDIR := $(prefix)/lib BIN_INSTDIR := $(prefix)/bin # Install user/group INST_USR = $(shell whoami) INST_GRP ?= $(shell groups | cut -f 1 -d ' ' ) # Establish install command # if rpath -> always chown # else # if targetdir==installdir -> chown # else install # endif #ifeq ($(WITH_RPATH),1) #INST_CMD = chown $(INST_USR).$(INST_GRP) #else TARGET_DIR = $(dir $(TARGET)) rpTARGET = $(realpath $(firstword $(TARGET_DIR))) rpINSTDIR = $(realpath $(prefix)/$(INSTDIR)) ifeq ($(rpTARGET),$(rpINSTDIR)) INST_CMD = chown $(INST_USR).$(INST_GRP) else INST_CMD = mkdir -p $(prefix)/$(INSTDIR); install -D -m 755 -g $(INST_GRP) -t $(prefix)/$(INSTDIR) endif #endif # Definitions concerning build environment CPPFLAGS += -DBRH_BUILD_ENV="\"$(shell uname -s -r -v -m -i -p -o)\"" CPPFLAGS += -DBRH_BUILD_TIME="\"$(shell date)\"" # Default pre-processor flags CPPFLAGS += -DBASE_DIR="\"$(BASE_DIR)\"" CPPFLAGS += -D_REENTRANT CPPFLAGS += -D_XOPEN_SOURCE # c++ standard CPPFLAGS += -std=c++11 CXXFLAGS += -std=c++11 # debug flag ifeq ($(USE_DEBUG),3) CXXFLAGS += -fno-inline -fbounds-check else ifeq ($(USE_DEBUG),2) CPPFLAGS += -DBRH_DEBUG CXXFLAGS += -fno-inline -fbounds-check else ifeq ($(USE_DEBUG),1) CPPFLAGS += -DBRH_CHECK_IT CXXFLAGS += -finline-functions -fbounds-check else CXXFLAGS += -finline-functions endif # Default compiler flags CXXFLAGS += -fPIC CXXFLAGS += -MMD CXXFLAGS += -g CXXFLAGS += -Wall -Werror CXXFLAGS += -fexceptions #CXXFLAGS += -fno-inline CXXFLAGS += -O3 #CXXFLAGS += -O0 CXXFLAGS += -I$(BASE_DIR)/src #CXXFLAGS += -std=c++11 #CXXFLAGS += -pg #LDFLAGS += -pg # BRH flags ifeq ($(USE_BRH),1) BRH_DIR = $(BASE_DIR) CPPFLAGS += -I$(BRH_DIR)/src ifeq ($(WITH_RPATH),1) LDFLAGS += -L$(LIB_DIR) -Wl,-rpath,$(LIB_INSTDIR) -lboost_system -lboost_thread -lpthread else LDFLAGS += -L$(LIB_DIR) -lboost_system -lboost_thread -lpthread endif LDLIBS += -lbrh -lboost_system -lboost_thread -lpthread endif ifeq ($(USE_BOOST_THREAD),1) CPPFLAGS += -pthread -DHAS_BOOST_THREADS LDFLAGS += -pthread -L$(DIR_BOOST_LIB) -lboost_system -lboost_thread -lpthread -L$(DIR_BOOST_THREAD) -l$(LIB_BOOST_THREAD) endif ifeq ($(USE_THREADPOOL),1) CPPFLAGS += -DHAS_BOOST_THREADPOOL CPPFLAGS += -I$(DIR_THREADPOOL) endif ifeq ($(USE_BOOST),1) CPPFLAGS += -I$(DIR_BOOST_INC) endif # TCLAP flags ifeq ($(USE_TCLAP),1) CPPFLAGS += -I$(DIR_TCLAP) endif # BOOST flags ifeq ($(USE_THREAD),1) endif # Check file type ifeq ($(suffix $(firstword $(SOURCES))),.cpp) IS_CPP = 1 else IS_CPP = 0 endif # List of objects ifeq ($(IS_CPP),1) OBJECTS = $(SOURCES:%.cpp=$(OBJ_DIR)/%.o) endif # Default build default: all ifeq ($(IS_CPP),1) # Build a binary $(BIN_DIR)/%: $(OBJECTS) Makefile $(BASE_DIR)/Makefile.rules @echo " Linking $(@F)" @mkdir -p $(@D) @$(LINK.cc) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS) # Build a shared library $(LIB_DIR)/%.so: $(OBJECTS) Makefile $(BASE_DIR)/Makefile.rules @echo " Linking $(@F)" @mkdir -p $(@D) @$(LINK.cc) -shared -o $@ $(OBJECTS) $(LDLIBS) # Build a static library $(LIB_DIR)/%.a: $(OBJECTS) Makefile $(BASE_DIR)/Makefile.rules @echo " Linking $(@F)" @mkdir -p $(@D) @ar rcs $@ $(OBJECTS) # Include dependency files -include $(OBJECTS:%.o=%.d) # Build an object file $(OBJ_DIR)/%.o: %.cpp Makefile @echo " Compiling $<" @mkdir -p $(@D) @$(COMPILE.cc) -o $@ $< else $(BIN_DIR)/%.py: %.py @echo " Copying $< to target dir" @cp -f $< $@ endif # Main targets are phony .PHONY: default all clean_target clean_obj doc clean_doc clean install static # Build target all: $(TARGET) static: $(TARGET) # Clean objects clean_obj: @$(RM) -r $(OBJ_DIR) # Clean build clean_target: @$(RM) -r $(OBJ_DIR) $(TARGET) # Build documentation doc: @$(MAKE) -C $(BASE_DIR) $@ # Clean build clean: clean_target # Install install: # @echo "rpT : $(rpTARGET)" # @echo "rpI : $(rpINSTDIR)" # @echo "rpath : $(WITH_RPATH)" # @echo "inst : $(INST_CMD) $(TARGET)" @target="$(TARGET)"; \ [ $${#target} -gt 0 ] || target="$(OUTPUT)"; \ for f in $${target}; do \ fname=`basename $$f`; \ if [ -f $$f ]; then \ echo "Installing in $(prefix)/$(INSTDIR) <$$fname>"; \ $(INST_CMD) $$f; \ fi; \ done