-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
226 lines (187 loc) · 4.74 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#
# 'make' build executable file 'main'
# 'make clean' removes all .o and executable files
#
# set flags for makefile like so:
# make USE_SIMD=1 USE_OMP=1 PMODE=1
# define the Cpp compiler to use
CXX = g++
# define any compile-time flags
CXXFLAGS := -std=c++17 -Wall -Wextra
# Toggle debug mode
DEBUG := 0
ifneq ($(DEBUG),0)
ifneq ($(DEBUG),1)
$(error DEBUG must be 0 or 1)
endif
endif
ifeq ($(DEBUG),1)
CXXFLAGS += -g
endif
# Set optimization level
O := 3
ifneq ($(O),0)
ifneq ($(O),1)
ifneq ($(O),2)
ifneq ($(O),3)
$(error O must be 0, 1, 2 or 3)
endif
endif
endif
endif
CXXFLAGS += -O$(O)
# Toggle SIMD
USE_SIMD := 1
ifneq ($(USE_SIMD),0)
ifneq ($(USE_SIMD),1)
$(error USE_SIMD must be 0 or 1)
endif
endif
ifeq ($(USE_SIMD),1)
CXXFLAGS += -mavx
else
$(info SIMD disabled)
endif
# Toggle OpenMP
USE_OMP := 1
ifneq ($(USE_OMP),0)
ifneq ($(USE_OMP),1)
$(error USE_OMP must be 0 or 1)
endif
endif
ifeq ($(USE_OMP),1)
CXXFLAGS += -fopenmp
else
$(info OpenMP disabled)
endif
# Set parallel mode
# (0: sequential mode, 1: parallelize over queries, 2: parallelize over queries and lists)
PMODE := 2
ifneq ($(PMODE),0)
ifneq ($(PMODE),1)
ifneq ($(PMODE),2)
$(error PMODE must be 0, 1 or 2)
endif
endif
endif
ifeq ($(USE_OMP),0)
override PMODE := 0
endif
CXXFLAGS += -D PMODE=$(PMODE)
# Toggle dynamic insertion
DYNAMIC_INSERTION := 1
ifneq ($(DYNAMIC_INSERTION),0)
ifneq ($(DYNAMIC_INSERTION),1)
$(error DYNAMIC_INSERTION must be 0 or 1)
endif
endif
CXXFLAGS += -D DYNAMIC_INSERTION=$(DYNAMIC_INSERTION)
# Other parameters
ifdef MIN_TOTAL_SIZE_BYTES
CXXFLAGS += -D MIN_TOTAL_SIZE_BYTES=$(MIN_TOTAL_SIZE_BYTES)
endif
ifdef MIN_N_ENTRIES_PER_LIST
CXXFLAGS += -D MIN_N_ENTRIES_PER_LIST=$(MIN_N_ENTRIES_PER_LIST)
endif
ifdef MAX_BUFFER_SIZE
CXXFLAGS += -D MAX_BUFFER_SIZE=$(MAX_BUFFER_SIZE)
endif
# Test parameters
ifdef TEST_N_SAMPLES
CXXFLAGS += -D TEST_N_SAMPLES=$(TEST_N_SAMPLES)
endif
ifdef TEST_N_LISTS
CXXFLAGS += -D TEST_N_LISTS=$(TEST_N_LISTS)
endif
ifdef TEST_N_PROBES
CXXFLAGS += -D TEST_N_PROBES=$(TEST_N_PROBES)
endif
ifdef TEST_N_RESULTS
CXXFLAGS += -D TEST_N_RESULTS=$(TEST_N_RESULTS)
endif
ifdef TEST_N_THREADS
CXXFLAGS += -D TEST_N_THREADS=$(TEST_N_THREADS)
endif
# define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify
# their path using -Lpath, something like:
# LFLAGS =
# define output directory
OUTPUT := out
# define source directory
SRC := src
# define include directory
INCLUDE := include
# define lib directory
LIB := lib
# define test directory
TEST := tests
TMP := tests/tmp
ifeq ($(OS),Windows_NT)
MAIN := main.exe
SOURCEDIRS := $(SRC)
INCLUDEDIRS := $(INCLUDE)
LIBDIRS := $(LIB)
FIXPATH = $(subst /,\,$1)
RM := del /q /f
MD := mkdir
else
MAIN := main
TESTMAIN := testmain
BENCHMAIN := benchmain
SOURCEDIRS := $(shell find $(SRC) -type d)
TESTDIRS := $(shell find $(TEST) -type d)
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
LIBDIRS := $(shell find $(LIB) -type d)
FIXPATH = $1
RM = rm -f
MD := mkdir -p
endif
# define any directories containing header files other than /usr/include
INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
# define the C libs
LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
# define the C source files
SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
# define test source files
TESTS_NO_SRC := $(wildcard $(patsubst %,%/*.cpp, $(TESTDIRS)))
TESTS := $(TESTS_NO_SRC) $(SOURCES:$(SRC)/$(MAIN).cpp=)
# define the C object files
OBJECTS := $(SOURCES:.cpp=.o)
TESTOBJECTS := $(TESTS:.cpp=.o)
TESTOBJECTS_NO_TESTMAIN := $(TESTOBJECTS:$(TEST)/TestMain.o=)
#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the definitions above and by
# deleting dependencies appended to the file from 'make depend'
#
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
OUTPUTTEST := $(call FIXPATH,$(OUTPUT)/$(TESTMAIN))
all: $(OUTPUT) $(MAIN)
test: $(OUTPUT) $(TESTMAIN)
bench: $(OUTPUT) $(BENCHMAIN)
$(OUTPUT):
$(MD) $(OUTPUT)
$(MAIN): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
$(TESTMAIN): $(TESTOBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTTEST) $(TESTOBJECTS) $(LFLAGS) $(LIBS)
# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
# (see the gnu make manual section about automatic variables)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
.PHONY: clean
clean:
$(RM) $(OUTPUTMAIN)
$(RM) $(call FIXPATH,$(OBJECTS))
$(RM) $(OUTPUTTEST)
$(RM) $(call FIXPATH,$(TESTOBJECTS_NO_TESTMAIN))
$(RM) -r $(TMP)/*
run: all
./$(OUTPUTMAIN)
runtest: test
./$(OUTPUTTEST)
runtests: test
./$(OUTPUTTEST) --success