-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (115 loc) · 4.54 KB
/
Makefile
File metadata and controls
152 lines (115 loc) · 4.54 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode)
OPT ?= -g2 -Werror # (B) Debug mode, w/ full line-level debugging symbols
# OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols
# OPT ?= -O2 -pipe -Wall -W --fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer
#CXX=/opt/compiler/gcc-4.8.2/bin/g++
PROJECT_DIR=.
THIRD_PARTY_DIR=$(PROJECT_DIR)/third_party
# Dependencies
include $(PROJECT_DIR)/depends.mk
INCLUDE_PATH = -I$(PROJECT_DIR)/src \
-I$(THIRD_PARTY_DIR)/include \
-I$(BOOST_PATH) \
-isystem $(GTEST_PATH)/include
LDFLAGS = -L$(TBB_PATH)/lib -ltbb -Wl,-rpath=$(TBB_PATH)/lib \
-L$(GTEST_PATH)/lib -lgtest \
-L$(SNAPPY_PATH)/lib -lsnappy \
-L$(LEVELDB_PATH)/lib -lleveldb \
-L$(PROTOBUF_PATH)/lib -lprotobuf \
-L$(SOFA_PBRPC_PATH)/lib -lsofa-pbrpc \
-L$(GPERFTOOLS_PATH)/lib -ltcmalloc_minimal \
-lgflags -lpthread -lstdc++ -ldl -lz -lrt
SO_LDFLAGS += -rdynamic $(DEPS_LDPATH) $(SO_DEPS_LDFLAGS) -lpthread -lrt -lz -ldl \
-shared -Wl,--version-script,so-version-script # hide symbol of third_party libs
# Compiler
#CXX = g++
CXX = clang
# Compiler opts
GCC_OPTS = -fmax-errors=2
CLANG_OPTS = -ferror-limit=2
# Notes on the flags:
# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8, like -D__const__= -D_GNU_SOURCE
# 3. Removed -Werror: Not block compilation for non-vital warnings, especially when the
# code is tested on newer systems. If the code is used in production, add -Werror back
DFLAGS = -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE
CXXFLAGS = -Wall -fPIC -std=c++11 -pthread $(DFLAGS) $(OPT)
CFLAGS = -Wall -W -fPIC $(DFLAGS) $(OPT)
ifeq ($(CXX), g++)
CXXFLAGS += $(GCC_OPTS)
else ifeq ($(CXX), clang)
CXXFLAGS += $(CLANG_OPTS)
endif
# Files
SRCEXTS = .c .cc .cpp .proto
ALL_DIRS = $(PROJECT_DIR)/src/*
ALL_SRCS = $(foreach d, $(ALL_DIRS), $(wildcard $(addprefix $(d)/*, $(SRCEXTS))))
ALL_OBJS = $(addsuffix .o, $(basename $(ALL_SRCS)))
PLATFORM_UTILS_DIRS = $(PROJECT_DIR)/src/platform $(PROJECT_DIR)/src/utils
PLATFORM_UTILS_SRCS = $(foreach d, $(PLATFORM_UTILS_DIRS), $(wildcard $(addprefix $(d)/*, $(SRCEXTS))))
PLATFORM_UTILS_OBJS = $(addsuffix .o, $(basename $(PLATFORM_UTILS_SRCS)))
PLATFORM_SRCS = \
$(PROJECT_DIR)/src/platform/bdcommon_logging.cc \
$(PROJECT_DIR)/src/platform/mutex.cc
PLATFORM_OBJS = $(addsuffix .o, $(basename $(PLATFORM_SRCS)))
PROTO_FILES = $(wildcard src/proto/*.proto)
PROTO_SRCS = $(patsubst %.proto,%.pb.cc, $(PROTO_FILES))
PROTO_HDRS = $(patsubst %.proto,%.pb.h, $(PROTO_FILES))
PROTO_OBJS = $(patsubst %.proto,%.pb.o, $(PROTO_FILES))
RPC_SRCS = $(wildcard $(PROJECT_DIR)/src/rpc/*.cc)
RPC_OBJS = $(addsuffix .o, $(basename $(RPC_SRCS)))
UTILS_SRCS = \
$(PROJECT_DIR)/src/utils/bdcommon_str_util.cc \
$(PROJECT_DIR)/src/utils/bdcommon_thread.cc \
$(PROJECT_DIR)/src/utils/hash.cc \
$(PROJECT_DIR)/src/utils/status.cc \
$(PROJECT_DIR)/src/utils/string_format.cc \
$(PROJECT_DIR)/src/utils/stringpiece.cc
UTILS_OBJS = $(addsuffix .o, $(basename $(UTILS_SRCS)))
OBJS = $(PLATFORM_OBJS) $(UTILS_OBJS) $(PROTO_OBJS) $(RPC_OBJS)
LIBS =
BINS = $(PLATFORM_UTILS_OBJS)
# Commands
.PHONY:all
all: $(BINS)
@echo "# Done"
.PHONY:clean
clean:
@echo "# Clean"
rm -rf $(ALL_OBJS)
rm -rf $(BINS)
rm -rf $(PROTO_SRCS) $(PROTO_HDRS)
rm -rf *.o
#.SECONDARY: $(PROTO_SRCS)
.PRECIOUS: $(PROTO_SRCS)
# Make
# Depends
$(PROTO_OBJS): $(PROTO_HDRS)
# Tests
.PHONY:test
TEST_BINS = ambry_bit_util_test
test: $(TEST_BINS)
@echo "# Test"
.PHONY:test_clean
test_clean:
@echo "# Test Clean"
rm -rf $(TEST_BINS)
dmlc_registry_test: $(PROJECT_DIR)/src/utils/dmlc_registry_test.o
$(CXX) $^ -o $@ $(LDFLAGS)
caffe2_registry_test: $(PROJECT_DIR)/src/utils/caffe2_registry_test.o $(PROJECT_DIR)/src/utils/caffe2_typeid.o
$(CXX) $^ -o $@ $(LDFLAGS)
ambry_bit_util_test: $(PROJECT_DIR)/src/utils/ambry_bit_util.o $(PROJECT_DIR)/src/utils/ambry_bit_util_test.o
$(CXX) $^ -o $@ $(LDFLAGS)
# Compile & Link
%.pb.cc %.pb.h: %.proto
@echo "# Protoc gen $@"
$(PROTOC) --proto_path=$(PROJECT_DIR)/src/proto --proto_path=/usr/local/include --cpp_out=$(PROJECT_DIR)/src/proto/ $<
%.o: %.cc
@echo "# Compiling cc $@"
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c $< -o $@
%.o:%.cpp
@echo "# Compiling cpp $@"
@$(CXX) -c $(CXXFLAGS) $(INCLUDE_PATH) $< -o $@
%.o:%.c
@echo "# Compiling c $@"
@$(CC) -c $(CFLAGS) $(INCLUDE_PATH) $< -o $@