forked from apache/singa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.example
92 lines (76 loc) · 3.32 KB
/
Makefile.example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
###################User Config Varaibles #############################
# third-party library installation folder
HOME_DIR := /usr
# Lib folder for system and external libs. You may need to change it.
LIBRARY_DIRS := $(HOME_DIR)/lib64 $(HOME_DIR)/lib $(HOME_DIR)/local/lib
# Header folder for system and external libs. You may need to change it.
INCLUDE_DIRS := $(HOME_DIR)/include ./include $(HOME_DIR)/local/include/zookeeper
# g++ location, should support c++11, tested with 4.8.1
CXX := g++
######################Setting Varialbes#######################################
LIBRARIES := glog gflags protobuf rt opencv_highgui opencv_imgproc opencv_core\
lmdb openblas zmq czmq zookeeper_mt
LDFLAGS := $(foreach librarydir, $(LIBRARY_DIRS), -L$(librarydir))\
$(foreach library, $(LIBRARIES), -l$(library))
# Folder to store compiled files
BUILD_DIR := build
MSHADOW_FLAGS :=-DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0
ZK_FLAGS :=-DTHREADED -fpermissive
CXXFLAGS := -O3 -Wall -pthread -fPIC -std=c++11 -Wno-unknown-pragmas \
$(MSHADOW_FLAGS) -DCPU_ONLY=1 $(ZK_FLAGS)\
-funroll-loops $(foreach includedir, $(INCLUDE_DIRS), -I$(includedir))
# find user defined .proto file, and then compute the corresponding .h, .cc
# files, which cannot be found by shell find, because they haven't been
# generated currently
PROTOS := $(shell find src/proto/ -name "*.proto")
PROTO_SRCS :=$(PROTOS:.proto=.pb.cc)
PROTO_HDRS :=$(patsubst src%, include%, $(PROTOS:.proto=.pb.h))
PROTO_OBJS :=$(addprefix $(BUILD_DIR)/, $(PROTO_SRCS:.cc=.o))
# each singa src file will generate a .o file
SINGA_SRCS := $(shell find src/ \( -path "src/test" -o -path "src/main.cc" \) \
-prune -o \( -name "*.cc" -type f \) -print )
SINGA_OBJS := $(sort $(addprefix $(BUILD_DIR)/, $(SINGA_SRCS:.cc=.o)) \
$(PROTO_OBJS) )
-include $(SINGA_OBJS:%.o=%.P)
TEST_SRCS :=$(shell find src/test/ -maxdepth 1 -name "*.cc")
TEST_OBJS := $(sort $(addprefix $(BUILD_DIR)/, $(TEST_SRCS:.cc=.o)))
-include $(TEST_OBJS:%.o=%.P)
GTEST_SRC := include/gtest/gtest-all.cc
GTEST_HDR := include/gtest/gtest.h
GTEST_LIB := $(BUILD_DIR)/libgtest.a
OBJS := $(sort $(SINGA_OBJS) $(TEST_OBJS) )
########################Compilation Section###################################
.PHONY: singa test
singa: $(PROTO_OBJS) $(SINGA_OBJS)
$(CXX) $(SINGA_OBJS) src/main.cc -o singa $(CXXFLAGS) $(LDFLAGS)
@echo
loader: proto $(LOADER_OBJS)
$(CXX) $(LOADER_OBJS) -o $(BUILD_DIR)/loader $(CXXFLAGS) $(LDFLAGS)
@echo
test: proto $(GTEST_LIB) $(TEST_OBJS) $(SINGA_OBJS)
$(CXX) $(TEST_OBJS) include/gtest/gtest_main.cc $(GTEST_LIB) \
$(SINGA_OBJS) -o $(BUILD_DIR)/test $(CXXFLAGS) $(LDFLAGS)
@echo
$(GTEST_LIB): $(GTEST_HDR) $(GTEST_SRC)
$(CXX) $(GTEST_SRC) -c -o $(BUILD_DIR)/gtest-all.o $(CXXFLAGS)
ar -rv $(GTEST_LIB) $(BUILD_DIR)/gtest-all.o
# compile all files
$(OBJS):$(BUILD_DIR)/%.o : %.cc
@mkdir -p $(dir $@)
$(CXX) $< $(CXXFLAGS) -MMD -c -o $@
cp $(BUILD_DIR)/$*.d $(BUILD_DIR)/$*.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(BUILD_DIR)/$*.d >> $(BUILD_DIR)/$*.P; \
rm -f $*.d
proto: $(PROTO_OBJS)
$(PROTO_SRCS): $(PROTOS)
protoc --proto_path=src/proto --cpp_out=src/proto $(PROTOS)
mkdir -p include/proto/
cp src/proto/*.pb.h include/proto/
@echo
clean:
rm -rf *.a *.so
rm -rf include/proto/*
rm -rf src/proto/*.pb.h src/proto/*.pb.cc
rm -rf $(BUILD_DIR)
@echo