-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
229 lines (192 loc) · 7.48 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
227
228
229
#===========================================================================
#
# Makefile --
# Makefile for WarpingSIMD demonstrator package
#
# This file is part of the following software:
#
# - the low-level C++ template SIMD library
# - the SIMD implementation of the MinWarping and the 2D-Warping methods
# for local visual homing.
#
# The software is provided based on the accompanying license agreement in the
# file LICENSE.md.
# The software is provided "as is" without any warranty by the licensor and
# without any liability of the licensor, and the software may not be
# distributed by the licensee; see the license agreement for details.
#
# (C) Ralf Möller
# Computer Engineering
# Faculty of Technology
# Bielefeld University
# www.ti.uni-bielefeld.de
#
#===========================================================================
# 01. Feb 23 (Jonas Keller): added syntax only option (see below)
# see notes below marked ARM for compilation on ARM architecture
#===========================================================================
# binaries
#===========================================================================
binaries = $(patsubst %.C,%,$(wildcard src/test/*.C))
depend_files = $(addsuffix .d,$(binaries))
objects = $(addsuffix .o,$(binaries))
single_header_file = WarpingSIMD.H
#===========================================================================
# definitions and flags
#===========================================================================
# compiler ?= clang++-10
compiler ?= g++
# - rt library is needed for clock_gettime
# - pthread may be needed on some systems
# (you may have to remove -lrt on Mac)
libraries = -lm -lrt # -lpthread
# optimization flags
# -funroll-loops is faster in both min-warping phases
optflags ?= -O3 -funroll-loops
# play in template sandbox only: -DSIMDVEC_SANDBOX
sandbox_defines ?= # -DSIMDVEC_SANDBOX
# set this to something != 0 to only check syntax and not compile
syntax_only ?= 0
# set this to something != 0 to compile statically
static_bins ?= 0
# user defines
# - needed if we use constants in stdint.h: -D__STDC_LIMIT_MACROS
# - save assembly code: -masm=intel -save-temps -fverbose-asm
# - profiling: -pg for gprof
# - valgrind: -mssse3 instead of -march=native for valgrind --tool=callgrind
# - test different vector sets: -msse2, -msse3, -mssse3 -march=native
# - activate SIMDVec load/store alignment check: -DSIMD_ALIGN_CHK
# - use at least -std=c++11
# - for tilt-search programs, -std=c++17 is required, now used
# for compilation on/for ARM:
# - keep -march=native or use a specific architecture, e.g. -march=armv7-a
# or use specific CPU, e.g. -mcpu=cortex-a15
# - replace -mfpmath=sse with -mfpu=neon or remove it, some compilers/architectures
# require it, some don't
# - crosscompilation and emulation may require static_bins to be set to
# something other than 0 (see above) if dynamic libraries are not available
# - may require -lpthread in libraries above
userdefs_arch = -march=native -mfpmath=sse
userdefs_c = -ggdb -fno-var-tracking
userdefs_cppstd = -std=c++17
userdefs_cpp =
# 18. Nov 23 (Jonas Keller): added more warnings
# recommended by:
# https://github.com/cpp-best-practices/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#gcc--clang
# (also has explanations for the flags)
userdefs_warnings = -Wall -Wextra -pedantic -Wpedantic \
-Wnon-virtual-dtor -Wcast-align -Wunused -Woverloaded-virtual \
-Wsign-compare -Wmisleading-indentation -Wformat=2 \
-Wimplicit-fallthrough \
-Wno-format-nonliteral -Wno-cast-align
# 20. Sep 22 (Jonas Keller): use secure template overloads on Windows and disable
# warnings about unsafe functions
# see: https://learn.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt
crt_sec_features_flags = -D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1 \
-D_CRT_SECURE_NO_WARNINGS
ifeq ($(syntax_only),0)
syntax_defines =
else
syntax_defines = -fsyntax-only
endif
ifeq ($(static_bins),0)
static_bins_flags =
else
static_bins_flags = -static
endif
# all flags (split into c and cpp (c++)) to avoid preprocessor warnings
flags_c = $(userdefs_c) $(userdefs_warnings) $(optflags) $(sandbox_defines) $(EXTRA_DEFINES) $(syntax_defines) $(static_bins_flags)
flags_cppstd ?= $(userdefs_cppstd)
flags_cpp = $(flags_c) $(userdefs_cpp) $(flags_cppstd) $(crt_sec_features_flags)
flags_arch ?= $(userdefs_arch)
flags_depends = -MMD -MP
# change -I./external to point to the T-SIMD library for developing WarpingSIMD in parallel with the T-SIMD library
# see README_CONTRIBUTORS_AND_MAINTAINERS.md for more information
flags_includes = -I./src/lib -I./external
# os dependent definitions
ifeq ($(OS),Windows_NT)
RM = del /Q /F
RMDIR_R = rmdir /S /Q
RMDIR = rmdir /Q
MKDIR = mkdir
NULL = NUL
else
RM = rm -f
RMDIR_R = rm -rf
RMDIR = rmdir --ignore-fail-on-non-empty
MKDIR = mkdir -p
NULL = /dev/null
endif
build_dir ?= build
# make sure build_dir is not the root directory
ifeq ($(realpath $(build_dir)),$(realpath .))
$(error build directory cannot be the project root directory)
endif
.PHONY: all
all: $(binaries)
.PHONY: $(binaries)
$(binaries): %: $(build_dir)/%
#===========================================================================
# compiler
#===========================================================================
$(addprefix $(build_dir)/,$(objects)): $(build_dir)/%.o: %.C
@echo compiling default $@ from $<
@$(MKDIR) $(dir $@)
@$(compiler) $(flags_depends) $(flags_arch) $(flags_cpp) $(flags_includes) -c $< -o $@
#===========================================================================
# linker
#===========================================================================
ifeq ($(syntax_only),0)
$(addprefix $(build_dir)/,$(binaries)): %: %.o
@echo linking $@ from $< $(libraries)
@$(MKDIR) $(dir $@)
@$(compiler) $(flags_arch) $(flags_cpp) -o $@ $< $(libraries)
else
$(addprefix $(build_dir)/,$(binaries)): %: %.o ;
endif
#===========================================================================
# other rules
#===========================================================================
.PHONY: clean
clean:
@echo "removing build directory \"$(build_dir)\""
@$(RMDIR_R) $(build_dir) >$(NULL) 2>&1
.PHONY: info
info:
@echo "vector extensions"
@echo | $(compiler) -xc++ -dM -E - $(flags_arch) $(flags_c) \
| grep -e SSE -e AVX -e POPCNT | sort
@echo "compiler: " $(compiler)
@echo "flags_c: " $(flags_c)
@echo "flags_cpp: " $(flags_cpp)
@echo "flags_arch: " $(flags_arch)
@echo "binaries: " $(binaries)
@echo "objects: " $(objects)
# for compileAndTest
.PHONY: flags-info
flags-info:
@echo | $(compiler) -dM -E - $(flags_arch) \
$(optflags) $(EXTRA_DEFINES) \
| grep -e SSE -e AVX -e POPCNT | sort
# for compileAndTest to be compatible with PROG system
# echo -n is to prevent make from printing "nothing to be done"
.PHONY: platform_dirs dep
platform_dirs:
@echo -n
dep:
@echo -n
# 10. Feb 23 (Jonas Keller): added format rule
# 10. Jun 24 (rm): this creates new files instead of the linked ones:
# @clang-format -i *.C *.H
.PHONY: format
format:
@echo "formatting all .C and .H files in src/"
@./scripts/format_cpp.sh src
# uses quom (https://github.com/Viatorus/quom)
.PHONY: single-header
single-header: format
@echo "generating warpingsimd single header file"
@$(MKDIR) $(build_dir)
@./scripts/generate_single-header.sh $(build_dir)/$(single_header_file)
@echo "single header written to $(build_dir)/$(single_header_file)"
-include $(addprefix $(build_dir)/,$(depend_files))