-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
209 lines (187 loc) · 5.39 KB
/
Makefile
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Makefile for DimmWitted Gibbs Sampler
.DEFAULT_GOAL := all
################################################################################
# common compiler flags
CXXFLAGS += -std=c++0x -Wall -Werror -fno-strict-aliasing
LDFLAGS +=
LDLIBS +=
ifdef DEBUG
CXXFLAGS += -g -DDEBUG
endif
# platform dependent compiler flags
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
ifndef CXX
CXX = g++
endif
ifndef DEBUG
CXXFLAGS += -Ofast
endif
endif
ifeq ($(UNAME), Darwin)
ifndef CXX
CXX = clang++
endif
ifndef DEBUG
CXXFLAGS += -O3
endif
# optimization
CXXFLAGS += -stdlib=libc++
CXXFLAGS += -flto
endif
################################################################################
# source files
SOURCES += src/dimmwitted.cc
SOURCES += src/cmd_parser.cc
SOURCES += src/binary_format.cc
SOURCES += src/bin2text.cc
SOURCES += src/text2bin.cc
SOURCES += src/main.cc
SOURCES += src/weight.cc
SOURCES += src/variable.cc
SOURCES += src/factor.cc
SOURCES += src/factor_graph.cc
SOURCES += src/inference_result.cc
SOURCES += src/gibbs_sampler.cc
SOURCES += src/timer.cc
SOURCES += src/numa_nodes.cc
OBJECTS = $(SOURCES:.cc=.o)
PROGRAM = dw
# header files
HEADERS += $(wildcard src/*.h)
# test files
TEST_SOURCES += test/test_main.cc
TEST_SOURCES += test/factor_test.cc
TEST_SOURCES += test/binary_format_test.cc
TEST_SOURCES += test/loading_test.cc
TEST_SOURCES += test/factor_graph_test.cc
TEST_SOURCES += test/sampler_test.cc
TEST_OBJECTS = $(TEST_SOURCES:.cc=.o)
TEST_PROGRAM = $(PROGRAM)_test
$(TEST_OBJECTS): CXXFLAGS += -I./src/
all: $(PROGRAM)
.PHONY: all
################################################################################
# how to link our sampler
$(PROGRAM): $(OBJECTS)
$(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS)
# how to link our sampler unit tests
$(TEST_PROGRAM): $(TEST_OBJECTS) $(filter-out src/main.o,$(OBJECTS))
$(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS)
################################################################################
# compiler generated dependency
# See: http://stackoverflow.com/a/16969086
DEPENDENCIES = $(SOURCES:.cc=.d) $(TEST_SOURCES:.cc=.d) $(TEXT2BIN_SOURCES:.cc=.d)
-include $(DEPENDENCIES)
CXXFLAGS += -MMD
# how to compile each source
%.o: %.cc
$(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $<
################################################################################
# how to get dependencies prepared
dep:
.PHONY: dep
### Google Test for unit tests
# https://github.com/google/googletest
# test files need gtest
$(OBJECTS): CXXFLAGS += -I./lib/gtest-1.7.0/include/
$(TEST_OBJECTS): CXXFLAGS += -I./lib/gtest-1.7.0/include/
$(TEST_PROGRAM): LDFLAGS += -L./lib/gtest/
$(TEST_PROGRAM): LDLIBS += -lgtest
dep: dep-gtest
dep-gtest: lib/gtest-1.7.0.zip
# gtest for tests
set -eu;\
cd lib;\
unzip -o $(<F);\
mkdir -p $(@:dep-%=%);\
cd $(@:dep-%=%);\
cmake ../$(<F:%.zip=%);\
make -j;\
#
clean-dep: clean-dep-gtest
clean-dep-gtest:
rm -rf lib/gtest
.PHONY: dep-gtest clean-dep-gtest
### TCLAP for command-line args parsing
# http://tclap.sourceforge.net
CXXFLAGS += -I./lib/tclap/include/
dep: dep-tclap
dep-tclap: lib/tclap-1.2.1.tar.gz
set -eu;\
cd lib;\
tar xf $(<F);\
cd $(<F:%.tar.gz=%);\
./configure --prefix=$(abspath $(<D)/$(@:dep-%=%));\
make -j;\
make install;\
#
clean-dep: clean-dep-tclap
clean-dep-tclap:
rm -rf lib/tclap
.PHONY: dep-tclap clean-dep-tclap
### NUMA for Linux
# http://oss.sgi.com/projects/libnuma/
ifeq ($(UNAME), Linux)
CXXFLAGS += -I./lib/numactl/include
LDFLAGS += -L./lib/numactl/lib
LDFLAGS += -Wl,-Bstatic -Wl,-Bdynamic
LDLIBS += -lnuma -lrt -lpthread
dep: dep-numactl # only for Linux
endif
dep-numactl: lib/numactl-2.0.11.tar.gz
# libnuma
echo "installing libnuma";\
cd lib;\
tar xf $(<F);\
cd $(<F:%.tar.gz=%);\
./configure --prefix=$(abspath lib/$(@:dep-%=%));\
make;\
make install;\
#
clean-dep: clean-dep-numactl
clean-dep-numactl:
rm -rf lib/numactl
.PHONY: dep-numactl clean-dep-numactl
################################################################################
# how to clean
clean:
rm -f $(PROGRAM) $(OBJECTS) $(TEST_PROGRAM) $(TEST_OBJECTS) $(DEPENDENCIES)
.PHONY: clean
clean-dep:
.PHONY: clean-dep
################################################################################
# how to test
include test/bats.mk
test-build: $(PROGRAM) $(TEST_PROGRAM)
# how to quickly turn actual test output into expected ones
actual-expected:
for actual in test/*/*.bin; do \
expected="$$actual".txt; \
[[ -e "$$expected" ]] || continue; \
xxd "$$actual" >"$$expected"; \
done
.PHONY: actual-expected
################################################################################
# how to format code
# XXX requiring a particular version since clang-format is not backward-compatible
CLANG_FORMAT_REQUIRED_VERSION := 3.7
ifndef CLANG_FORMAT
ifneq ($(shell which clang-format-$(CLANG_FORMAT_REQUIRED_VERSION) 2>/dev/null),)
CLANG_FORMAT := clang-format-$(CLANG_FORMAT_REQUIRED_VERSION)
else
CLANG_FORMAT := clang-format
endif
endif
ifeq (0,$(shell $(CLANG_FORMAT) --version | grep -cF $(CLANG_FORMAT_REQUIRED_VERSION)))
format:
@echo '# ERROR: clang-format $(CLANG_FORMAT_REQUIRED_VERSION) required'
@echo '# On a Mac, try:'
@echo 'brew reinstall https://github.com/Homebrew/homebrew-core/raw/0c1a8721e1d2aeca63647f4f1b5f5a1dbe5d9a8b/Formula/clang-format.rb'
@echo '# Otherwise, install a release for your OS from http://llvm.org/releases/'
@false
else
format:
$(CLANG_FORMAT) -i $(SOURCES) $(TEST_SOURCES) $(TEXT2BIN_SOURCES) $(HEADERS)
endif
.PHONY: format