[Make] refactor build script to use config file

This commit is contained in:
tqchen 2016-01-02 18:49:05 -08:00
parent 7e6f00ee11
commit 084f5f4715
5 changed files with 124 additions and 56 deletions

2
.gitignore vendored
View File

@ -69,4 +69,4 @@ nb-configuration*
.pydevproject
.settings/
build
config.mk

View File

@ -1,39 +1,11 @@
ifndef CC
export CC = $(if $(shell which gcc-5),gcc-5,gcc)
endif
ifndef CXX
export CXX = $(if $(shell which g++-5),g++-5,g++)
endif
export LDFLAGS= -pthread -lm
export CFLAGS= -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fPIC -Iinclude
ifndef LINT_LANG
LINT_LANG= "all"
endif
ifeq ($(OS), Windows_NT)
export CXX = g++ -m64
export CC = gcc -m64
endif
UNAME= $(shell uname)
ifeq ($(UNAME), Linux)
LDFLAGS += -lrt
endif
ifeq ($(no_omp),1)
CFLAGS += -DDISABLE_OPENMP
ifndef config
ifneq ("$(wildcard ./config.mk)","")
config = config.mk
else
ifeq ($(omp_mac_static),1)
CFLAGS += -static-libgcc -static-libstdc++ -L. -fopenmp
else
CFLAGS += -fopenmp
config = make/config.mk
endif
endif
ifndef DMLC_CORE
DMLC_CORE = dmlc-core
endif
@ -42,21 +14,60 @@ ifndef RABIT
RABIT = rabit
endif
ROOTDIR = $(CURDIR)
UNAME= $(shell uname)
include $(config)
ifeq ($(USE_OPENMP), 0)
export NO_OPENMP = 1
endif
include $(DMLC_CORE)/make/dmlc.mk
# use customized config file
ifndef CC
export CC = $(if $(shell which gcc-5),gcc-5,gcc)
endif
ifndef CXX
export CXX = $(if $(shell which g++-5),g++-5,g++)
endif
ifeq ($(OS), Windows_NT)
export CXX = g++ -m64
export CC = gcc -m64
endif
export LDFLAGS= -pthread -lm $(ADD_LDFLAGS) $(DMLC_LDFLAGS)
export CFLAGS= -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fPIC -Iinclude $(ADD_CFLAGS)
CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include
ifndef LINT_LANG
LINT_LANG= "all"
endif
ifeq ($(UNAME), Linux)
LDFLAGS += -lrt
endif
ifeq ($(USE_OPENMP), 1)
CFLAGS += -fopenmp
else
CFLAGS += -DDISABLE_OPENMP
endif
# specify tensor path
.PHONY: clean all lint
.PHONY: clean all lint clean_all
all: lib/libxgboost.a lib/libxgboost.so
$(DMLC_CORE)/libdmlc.a:
+ cd $(DMLC_CORE); make libdmlc.a; cd $(ROOTDIR)
+ cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR)
$(RABIT)/lib/librabit.a:
+ cd $(RABIT); make lib/librabit.a; cd $(ROOTDIR)
$(RABIT)/lib/$(LIB_RABIT):
+ cd $(RABIT); make lib/$(LIB_RABIT); cd $(ROOTDIR)
CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include
SRC = $(wildcard src/*.cc src/*/*.cc)
OBJ = $(patsubst src/%.cc, build/%.o, $(SRC))
LIB_DEP = $(DMLC_CORE)/libdmlc.a $(RABIT)/lib/librabit.a
LIB_DEP = $(DMLC_CORE)/libdmlc.a $(RABIT)/lib/$(LIB_RABIT)
ALL_DEP = $(OBJ) $(LIB_DEP)
build/%.o: src/%.cc
@ -78,7 +89,7 @@ lint:
clean:
$(RM) -r build lib bin *~ */*~ */*/*~ */*/*/*~
clean_all: clean
clean: clean_all
cd $(DMLC_CORE); make clean; cd -
cd $(RABIT); make clean; cd -

View File

@ -6,27 +6,14 @@
# See additional instruction in doc/build.md
#for building static OpenMP lib in MAC for easier installation in MAC
#doesn't work with XCode clang/LLVM since Apple doesn't support,
#needs brew install gcc 4.9+ with OpenMP. By default the static link is OFF
static_omp=0
if ((${static_omp}==1)); then
rm libgomp.a
ln -s `g++ -print-file-name=libgomp.a`
make clean
make omp_mac_static=1
echo "Successfully build multi-thread static link xgboost"
exit 0
fi
if make; then
echo "Successfully build multi-thread xgboost"
else
echo "-----------------------------"
echo "Building multi-thread xgboost failed"
echo "Start to build single-thread xgboost"
make clean
make no_omp=1
make clean_all
make config=config/mininum.mk
echo "Successfully build single-thread xgboost"
echo "If you want multi-threaded version"
echo "See additional instructions in doc/build.md"

48
make/config.mk Normal file
View File

@ -0,0 +1,48 @@
#-----------------------------------------------------
# xgboost: the configuration compile script
#
# If you want to change the configuration, please use the following
# steps. Assume you are on the root directory of xgboost.
# First copy the this file so that any local changes will be ignored by git
#
# $ cp make/config.mk .
#
# Next modify the according entries, and then compile by
#
# $ make
#
# or build in parallel with 8 threads
#
# $ make -j8
#----------------------------------------------------
# choice of compiler, by default use system preference.
# export CC = gcc
# export CXX = g++
# export MPICXX = mpicxx
# the additional link flags you want to add
ADD_LDFLAGS =
# the additional compile flags you want to add
ADD_CFLAGS =
# Whether enable openmp support, needed for multi-threading.
USE_OPENMP = 1
# whether use HDFS support during compile
USE_HDFS = 0
# whether use AWS S3 support during compile
USE_S3 = 0
# whether use Azure blob support during compile
USE_AZURE = 0
# Rabit library version,
# - librabit.a Normal distributed version.
# - librabit_empty.a Non distributed mock version,
LIB_RABIT = librabit.a
# path to libjvm.so
LIBJVM=$(JAVA_HOME)/jre/lib/amd64/server

22
make/minimum.mk Normal file
View File

@ -0,0 +1,22 @@
#-----------------------------------------------------
# xgboost: minumum dependency configuration,
# see config.mk for template.
#----------------------------------------------------
# Whether enable openmp support, needed for multi-threading.
USE_OPENMP = 0
# whether use HDFS support during compile
USE_HDFS = 0
# whether use AWS S3 support during compile
USE_S3 = 0
# whether use Azure blob support during compile
USE_AZURE = 0
# Rabit library version,
# - librabit.a Normal distributed version.
# - librabit_empty.a Non distributed mock version,
LIB_RABIT = librabit_empty.a