Crypto++ 8.0 Free C++ class library of cryptographic schemes

GNUmakefile-cross
1 # https://www.gnu.org/software/make/manual/make.html#Makefile-Conventions
2 # and https://www.gnu.org/prep/standards/standards.html
3
4 SHELL = /bin/sh
5
6 # If needed
7 TMPDIR ?= /tmp
8 # Used for ARMv7 and NEON.
9 FP_ABI ?= hard
10 # Used for feature tests
11 TOUT ?= a.out
12 TOUT := $(strip $(TOUT))
13
14 # Default CXXFLAGS if none were provided
15 CXXFLAGS ?= -DNDEBUG -g2 -O3 -fPIC -pipe
16
17 AR ?= ar
18 ARFLAGS ?= cr
19 RANLIB ?= ranlib
20 CP ?= cp
21 MV ?= mv
22 CHMOD ?= chmod
23 MKDIR ?= mkdir -p
24 EGREP ?= egrep
25
26 LN ?= ln -sf
27 LDCONF ?= /sbin/ldconfig -n
28
29 IS_IOS ?= 0
30 IS_ANDROID ?= 0
31 IS_ARM_EMBEDDED ?= 0
32 IS_NEON ?= 0
33
34 # Can be used by Android and Embeeded cross-compiles. Disable by default because
35 # Android and embedded users typically don't run this configuration.
36 HAS_SOLIB_VERSION ?= 0
37
38 # Formely adhoc.cpp was created from adhoc.cpp.proto when needed.
39 # This is now needed because ISA tests are performed using adhoc.cpp.
40 ifeq ($(wildcard adhoc.cpp),)
41 $(shell cp adhoc.cpp.proto adhoc.cpp)
42 endif
43
44 ###########################################################
45 ##### General Variables #####
46 ###########################################################
47
48 # Default prefix for make install
49 ifeq ($(PREFIX),)
50 PREFIX = /usr/local
51 endif
52
53 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
54 ifeq ($(DATADIR),)
55 DATADIR := $(PREFIX)/share
56 endif
57 ifeq ($(LIBDIR),)
58 LIBDIR := $(PREFIX)/lib
59 endif
60 ifeq ($(BINDIR),)
61 BINDIR := $(PREFIX)/bin
62 endif
63 ifeq ($(INCLUDEDIR),)
64 INCLUDEDIR := $(PREFIX)/include
65 endif
66
67 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
68 ifeq ($(ARFLAGS),rv)
69 ARFLAGS = r
70 endif
71
72 # Sadly, we can't actually use GCC_PRAGMA_AWARE because of GCC bug 53431.
73 # Its a shame because GCC has so much to offer by the way of analysis.
74 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431
75 ifneq ($(CLANG_COMPILER),0)
76 CXXFLAGS += -Wall
77 endif
78
79 ###########################################################
80 ##### iOS #####
81 ###########################################################
82
83 # iOS cross-compile configuration.
84 # See http://www.cryptopp.com/wiki/iOS_(Command_Line).
85 ifeq ($(IS_IOS),1)
86 CXX = clang++
87
88 CXXFLAGS += $(IOS_FLAGS) -arch $(IOS_ARCH)
89 CXXFLAGS += -isysroot "$(IOS_SYSROOT)" -stdlib=libc++
90
91 AR = libtool
92 ARFLAGS = -static -o
93 RANLIB = ranlib
94 endif
95
96 ###########################################################
97 ##### Android #####
98 ###########################################################
99
100 # Android cross-compile configuration.
101 # See http://www.cryptopp.com/wiki/Android_(Command_Line).
102 ifeq ($(IS_ANDROID),1)
103 # CPP, CXX, AR, RANLIB, LD, etc are set in 'setenv-android.sh'
104 CXXFLAGS += $(AOSP_FLAGS) -DANDROID --sysroot=$(AOSP_SYSROOT)
105 CXXFLAGS += -Wa,--noexecstack -I$(AOSP_STL_INC) -I$(AOSP_SYS_ARCH_INC)
106 LDFLAGS += --sysroot=$(AOSP_LD_SYSROOT)
107
108 # c++config.h shows up in odd places at times.
109 ifneq ($(AOSP_BITS_INC),)
110 CXXFLAGS += -I$(AOSP_BITS_INC)
111 endif
112
113 # STL headers
114 LDLIBS += $(AOSP_STL_LIB)
115
116 # Source files copied into PWD for Android cpu-features
117 # setenv-android.sh does the copying. Its a dirty compile.
118 AOSP_CPU_OBJ = cpu-features.o
119 endif
120
121 ###########################################################
122 ##### Embedded #####
123 ###########################################################
124
125 # ARM embedded cross-compile configuration.
126 # See http://www.cryptopp.com/wiki/ARM_Embedded_(Command_Line)
127 # and http://www.cryptopp.com/wiki/ARM_Embedded_(Bare Metal).
128 ifeq ($(IS_ARM_EMBEDDED),1)
129 # CPP, CXX, AR, RANLIB, LD, etc are set in 'setenv-embedded.sh'
130 CXXFLAGS += $(ARM_EMBEDDED_FLAGS) --sysroot=$(ARM_EMBEDDED_SYSROOT)
131 endif
132
133 ###########################################################
134 ##### Compiler and Platform #####
135 ###########################################################
136
137 # Wait until CXXFLAGS have been set by setenv scripts.
138
139 GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(EGREP) -v -E 'llvm|clang' | $(EGREP) -i -c -E '(gcc|g\+\+)')
140 CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(EGREP) -i -c -E 'llvm|clang')
141
142 HOSTX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | cut -f 1 -d '-')
143 ifeq ($(HOSTX),)
144 HOSTX := $(shell uname -m 2>/dev/null)
145 endif
146
147 # This dance is because Clang reports the host architecture instead
148 # of the target architecture. Running Clang on an x86_64 machine with
149 # -arch arm64 yields x86_64 instead of aarch64 or arm64.
150
151 ifeq ($(CLANG_COMPILER),1)
152 IS_X86 := $(shell echo $(CXXFLAGS) | $(EGREP) -v 64 | $(EGREP) -i -c -E 'i.86')
153 IS_X64 := $(shell echo $(CXXFLAGS) | $(EGREP) -i -c -E 'x86_64|amd64')
154 IS_ARM32 := $(shell echo $(CXXFLAGS) | $(EGREP) -v 64 | $(EGREP) -i -c -E 'arm|armhf|arm7l|eabihf')
155 IS_ARMV8 := $(shell echo $(CXXFLAGS) | $(EGREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
156 else
157 IS_X86 := $(shell echo $(HOSTX) | $(EGREP) -v 64 | $(EGREP) -i -c -E 'i.86')
158 IS_X64 := $(shell echo $(HOSTX) | $(EGREP) -i -c -E 'x86_64|amd64')
159 IS_ARM32 := $(shell echo $(HOSTX) | $(EGREP) -v 64 | $(EGREP) -i -c -E 'arm|armhf|arm7l|eabihf')
160 IS_ARMV8 := $(shell echo $(HOSTX) | $(EGREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
161 endif
162
163 $(info Here's what we found... IS_X86: $(IS_X86), IS_X64: $(IS_X64), IS_ARM32: $(IS_ARM32), IS_ARMV8: $(IS_ARMV8))
164
165 ###########################################################
166 ##### Test Program #####
167 ###########################################################
168
169 # Hack to skip CPU feature tests for some recipes
170 DETECT_FEATURES ?= 1
171 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),-DCRYPTOPP_DISABLE_ASM)
172 DETECT_FEATURES := 0
173 else ifeq ($(findstring clean,$(MAKECMDGOALS)),clean)
174 DETECT_FEATURES := 0
175 else ifeq ($(findstring distclean,$(MAKECMDGOALS)),distclean)
176 DETECT_FEATURES := 0
177 else ifeq ($(findstring distclean,$(MAKECMDGOALS)),trim)
178 DETECT_FEATURES := 0
179 endif
180
181 # Strip out -Wall, -Wextra and friends for feature testing
182 ifeq ($(DETECT_FEATURES),1)
183 TCXXFLAGS := $(filter-out -Wall -Wextra -Werror% -Wunused -Wconversion -Wp%, $(CXXFLAGS))
184 ifneq ($(strip $(TCXXFLAGS)),)
185 $(info Using testing flags: $(TCXXFLAGS))
186 endif
187 #TPROG = TestPrograms/test_cxx.cxx
188 #$(info Testing compile... )
189 #$(info $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 1>/dev/null))
190 endif
191
192 # For the previous messages
193 $(info )
194
195 ###########################################################
196 ##### X86/X32/X64 Options #####
197 ###########################################################
198
199 ifneq ($(IS_X86)$(IS_X64),00)
200 ifeq ($(DETECT_FEATURES),1)
201
202 SSE2_FLAG = -msse2
203 SSE3_FLAG = -msse3
204 SSSE3_FLAG = -mssse3
205 SSE41_FLAG = -msse4.1
206 SSE42_FLAG = -msse4.2
207 CLMUL_FLAG = -mpclmul
208 AESNI_FLAG = -maes
209 AVX_FLAG = -mavx
210 AVX2_FLAG = -mavx2
211 SHANI_FLAG = -msha
212
213 TPROG = TestPrograms/test_x86_sse2.cxx
214 TOPT = $(SSE2_FLAG)
215 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
216 ifeq ($(strip $(HAVE_OPT)),0)
217 CHACHA_FLAG = $(SSE2_FLAG)
218 else
219 SSE2_FLAG =
220 endif
221
222 TPROG = TestPrograms/test_x86_ssse3.cxx
223 TOPT = $(SSSE3_FLAG)
224 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
225 ifeq ($(strip $(HAVE_OPT)),0)
226 ARIA_FLAG = $(SSSE3_FLAG)
227 CHAM_FLAG = $(SSSE3_FLAG)
228 LEA_FLAG = $(SSSE3_FLAG)
229 SIMECK_FLAG = $(SSSE3_FLAG)
230 SIMON64_FLAG = $(SSSE3_FLAG)
231 SIMON128_FLAG = $(SSSE3_FLAG)
232 SPECK64_FLAG = $(SSSE3_FLAG)
233 SPECK128_FLAG = $(SSSE3_FLAG)
234 else
235 SSSE3_FLAG =
236 endif
237
238 TPROG = TestPrograms/test_x86_sse41.cxx
239 TOPT = $(SSE41_FLAG)
240 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
241 ifeq ($(strip $(HAVE_OPT)),0)
242 BLAKE2B_FLAG = $(SSE41_FLAG)
243 BLAKE2S_FLAG = $(SSE41_FLAG)
244 SIMON64_FLAG = $(SSE41_FLAG)
245 SPECK64_FLAG = $(SSE41_FLAG)
246 else
247 SSE41_FLAG =
248 endif
249
250 TPROG = TestPrograms/test_x86_sse42.cxx
251 TOPT = $(SSE42_FLAG)
252 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
253 ifeq ($(strip $(HAVE_OPT)),0)
254 CRC_FLAG = $(SSE42_FLAG)
255 else
256 SSE42_FLAG =
257 endif
258
259 TPROG = TestPrograms/test_x86_clmul.cxx
260 TOPT = $(CLMUL_FLAG)
261 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
262 ifeq ($(strip $(HAVE_OPT)),0)
263 GCM_FLAG = $(SSSE3_FLAG) $(CLMUL_FLAG)
264 else
265 CLMUL_FLAG =
266 endif
267
268 TPROG = TestPrograms/test_x86_aes.cxx
269 TOPT = $(AESNI_FLAG)
270 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
271 ifeq ($(strip $(HAVE_OPT)),0)
272 AES_FLAG = $(SSE41_FLAG) $(AESNI_FLAG)
273 SM4_FLAG = $(SSSE3_FLAG) $(AESNI_FLAG)
274 else
275 AESNI_FLAG =
276 endif
277
278 TPROG = TestPrograms/test_x86_avx.cxx
279 TOPT = $(AVX_FLAG)
280 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
281 ifeq ($(strip $(HAVE_OPT)),0)
282 # XXX_FLAG = $(AVX_FLAG)
283 else
284 AVX_FLAG =
285 endif
286
287 TPROG = TestPrograms/test_x86_avx2.cxx
288 TOPT = $(AVX2_FLAG)
289 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
290 ifeq ($(strip $(HAVE_OPT)),0)
291 CHACHA_AVX2_FLAG = $(AVX2_FLAG)
292 else
293 AVX2_FLAG =
294 endif
295
296 TPROG = TestPrograms/test_x86_sha.cxx
297 TOPT = $(SHANI_FLAG)
298 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
299 ifeq ($(strip $(HAVE_OPT)),0)
300 SHA_FLAG = $(SSE42_FLAG) $(SHANI_FLAG)
301 else
302 SHANI_FLAG =
303 endif
304
305 ifeq ($(SSE2_FLAG),)
306 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
307 else ifeq ($(SSE3_FLAG),)
308 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE3
309 else ifeq ($(SSSE3_FLAG),)
310 CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
311 else ifeq ($(SSE41_FLAG),)
312 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
313 else ifeq ($(SSE42_FLAG),)
314 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
315 endif
316
317 ifneq ($(SSE42_FLAG),)
318
319 # Unusual GCC/Clang on Macports. It assembles AES, but not CLMUL.
320 # test_x86_clmul.s:15: no such instruction: 'pclmulqdq $0, %xmm1,%xmm0'
321 ifeq ($(CLMUL_FLAG),)
322 CXXFLAGS += -DCRYPTOPP_DISABLE_CLMUL
323 endif
324 ifeq ($(AESNI_FLAG),)
325 CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
326 endif
327
328 ifeq ($(AVX_FLAG),)
329 CXXFLAGS += -DCRYPTOPP_DISABLE_AVX
330 else ifeq ($(AVX2_FLAG),)
331 CXXFLAGS += -DCRYPTOPP_DISABLE_AVX2
332 else ifeq ($(SHANI_FLAG),)
333 CXXFLAGS += -DCRYPTOPP_DISABLE_SHANI
334 endif
335 endif
336
337 # Drop to SSE2 if available
338 ifeq ($(GCM_FLAG),)
339 ifneq ($(SSE2_FLAG),)
340 GCM_FLAG = $(SSE2_FLAG)
341 endif
342 endif
343
344 # DETECT_FEATURES
345 endif
346
347 # IS_X86, IS_X32 and IS_X64
348 endif
349
350 ###########################################################
351 ##### ARM A-32, Aach64 and NEON #####
352 ###########################################################
353
354 ifneq ($(IS_ARM32)$(IS_ARMV8),00)
355 ifeq ($(DETECT_FEATURES),1)
356
357 ifeq ($(IS_ARM32),1)
358
359 ifneq ($(IS_IOS)$(IS_ANDROID),00)
360 NEON_FLAG =
361 else
362 NEON_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
363 endif
364
365 TPROG = TestPrograms/test_arm_neon.cxx
366 TOPT = $(NEON_FLAG)
367 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
368 ifeq ($(strip $(HAVE_OPT)),0)
369 ARIA_FLAG = $(NEON_FLAG)
370 AES_FLAG = $(NEON_FLAG)
371 CRC_FLAG = $(NEON_FLAG)
372 GCM_FLAG = $(NEON_FLAG)
373 BLAKE2B_FLAG = $(NEON_FLAG)
374 BLAKE2S_FLAG = $(NEON_FLAG)
375 CHACHA_FLAG = $(NEON_FLAG)
376 CHAM_FLAG = $(NEON_FLAG)
377 LEA_FLAG = $(NEON_FLAG)
378 SHA_FLAG = $(NEON_FLAG)
379 SIMECK_FLAG = $(NEON_FLAG)
380 SIMON64_FLAG = $(NEON_FLAG)
381 SIMON128_FLAG = $(NEON_FLAG)
382 SPECK64_FLAG = $(NEON_FLAG)
383 SPECK128_FLAG = $(NEON_FLAG)
384 SM4_FLAG = $(NEON_FLAG)
385 else
386 NEON_FLAG =
387 CXXFLAGS += -DCRYPTOPP_DISABLE_NEON
388 endif
389
390 # IS_NEON
391 endif
392
393 ifeq ($(IS_ARMV8),1)
394
395 ifeq ($(IS_IOS),1)
396 ASIMD_FLAG =
397 CRC_FLAG =
398 AES_FLAG =
399 PMUL_FLAG =
400 SHA_FLAG =
401 else
402 ASIMD_FLAG = -march=armv8-a
403 CRC_FLAG = -march=armv8-a+crc
404 AES_FLAG = -march=armv8-a+crypto
405 PMULL_FLAG = -march=armv8-a+crypto
406 SHA_FLAG = -march=armv8-a+crypto
407 endif
408
409 TPROG = TestPrograms/test_arm_acle.cxx
410 TOPT = $(ASIMD_FLAG)
411 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
412 ifeq ($(strip $(HAVE_OPT)),0)
413 ACLE_FLAG += -DCRYPTOPP_ARM_ACLE_AVAILABLE=1
414 else
415 CXXFLAGS += -DCRYPTOPP_ARM_ACLE_AVAILABLE=0
416 endif
417
418 TPROG = TestPrograms/test_arm_asimd.cxx
419 TOPT = $(ASIMD_FLAG)
420 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
421 ifeq ($(strip $(HAVE_OPT)),0)
422 ARIA_FLAG = $(ASIMD_FLAG)
423 BLAKE2B_FLAG = $(ASIMD_FLAG)
424 BLAKE2S_FLAG = $(ASIMD_FLAG)
425 CHACHA_FLAG = $(ASIMD_FLAG)
426 CHAM_FLAG = $(ASIMD_FLAG)
427 LEA_FLAG = $(ASIMD_FLAG)
428 NEON_FLAG = $(ASIMD_FLAG)
429 SIMECK_FLAG = $(ASIMD_FLAG)
430 SIMON64_FLAG = $(ASIMD_FLAG)
431 SIMON128_FLAG = $(ASIMD_FLAG)
432 SPECK64_FLAG = $(ASIMD_FLAG)
433 SPECK128_FLAG = $(ASIMD_FLAG)
434 SM4_FLAG = $(ASIMD_FLAG)
435 else
436 ASIMD_FLAG =
437 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
438 endif
439
440 TPROG = TestPrograms/test_arm_crc.cxx
441 TOPT = $(CRC_FLAG)
442 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
443 ifneq ($(strip $(HAVE_OPT)),0)
444 CRC_FLAG =
445 CXXFLAGS += -DCRYPTOPP_ARM_CRC32_AVAILABLE=0
446 endif
447
448 TPROG = TestPrograms/test_arm_aes.cxx
449 TOPT = $(AES_FLAG)
450 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
451 ifneq ($(strip $(HAVE_OPT)),0)
452 AES_FLAG =
453 CXXFLAGS += -DCRYPTOPP_ARM_AES_AVAILABLE=0
454 endif
455
456 TPROG = TestPrograms/test_arm_pmull.cxx
457 TOPT = $(PMULL_FLAG)
458 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
459 ifneq ($(strip $(HAVE_OPT)),0)
460 PMULL_FLAG =
461 CXXFLAGS += -DCRYPTOPP_ARM_PMULL_AVAILABLE=0
462 endif
463
464 TPROG = TestPrograms/test_arm_sha.cxx
465 TOPT = $(SHA_FLAG)
466 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
467 ifneq ($(strip $(HAVE_OPT)),0)
468 SHA_FLAG =
469 CXXFLAGS += -DCRYPTOPP_ARM_SHA_AVAILABLE=0
470 endif
471
472 TPROG = TestPrograms/test_arm_sm3.cxx
473 TOPT = -march=armv8.4-a+crypto
474 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
475 ifeq ($(strip $(HAVE_OPT)),0)
476 SM3_FLAG = -march=armv8.4-a+crypto
477 SM4_FLAG = -march=armv8.4-a+crypto
478 endif
479
480 TPROG = TestPrograms/test_arm_sha3.cxx
481 TOPT = -march=armv8.4-a+crypto
482 HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
483 ifeq ($(strip $(HAVE_OPT)),0)
484 SHA3_FLAG = -march=armv8.4-a+crypto
485 SHA512_FLAG = -march=armv8.4-a+crypto
486 endif
487
488 # IS_ARMV8
489 endif
490
491 # DETECT_FEATURES
492 endif
493
494 # IS_ARM32, IS_ARMV8, IS_NEON
495 endif
496
497 ###########################################################
498 ##### Common #####
499 ###########################################################
500
501 # No ASM for Travis testing
502 ifeq ($(findstring no-asm,$(MAKECMDGOALS)),no-asm)
503 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
504 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
505 endif # CXXFLAGS
506 endif # No ASM
507
508 # Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
509 ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
510 ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
511 CXXFLAGS += -fsanitize=undefined
512 endif # CXXFLAGS
513 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
514 CXXFLAGS += -DCRYPTOPP_COVERAGE
515 endif # CXXFLAGS
516 endif # UBsan
517
518 # Address Sanitizer (Asan) testing. Issue 'make asan'.
519 ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
520 ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
521 CXXFLAGS += -fsanitize=address
522 endif # CXXFLAGS
523 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
524 CXXFLAGS += -DCRYPTOPP_COVERAGE
525 endif # CXXFLAGS
526 ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
527 CXXFLAGS += -fno-omit-frame-pointer
528 endif # CXXFLAGS
529 endif # Asan
530
531 # LD gold linker testing. Triggered by 'LD=ld.gold'.
532 ifeq ($(findstring ld.gold,$(LD)),ld.gold)
533 ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
534 ELF_FORMAT := $(shell file `which ld.gold` 2>&1 | cut -d":" -f 2 | $(EGREP) -i -c "elf")
535 ifneq ($(ELF_FORMAT),0)
536 LDFLAGS += -fuse-ld=gold
537 endif # ELF/ELF64
538 endif # CXXFLAGS
539 endif # Gold
540
541 # Valgrind testing. Issue 'make valgrind'.
542 ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
543 # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
544 CXXFLAGS := $(CXXFLAGS:-g%=-g3)
545 CXXFLAGS := $(CXXFLAGS:-O%=-O1)
546 CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
547 ifeq ($(findstring -DCRYPTOPP_VALGRIND,$(CXXFLAGS)),)
548 CXXFLAGS += -DCRYPTOPP_VALGRIND
549 endif # -DCRYPTOPP_VALGRIND
550 endif # Valgrind
551
552 # Debug testing on GNU systems. Triggered by -DDEBUG.
553 # Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
554 ifneq ($(filter -DDEBUG -DDEBUG=1,$(CXXFLAGS)),)
555 USING_GLIBCXX := $(shell $(CXX) $(CXXFLAGS) -E pch.cpp 2>&1 | $(EGREP) -i -c "__GLIBCXX__")
556 ifneq ($(USING_GLIBCXX),0)
557 ifeq ($(HAS_NEWLIB),0)
558 ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CXXFLAGS)),)
559 CXXFLAGS += -D_GLIBCXX_DEBUG
560 endif # CXXFLAGS
561 endif # HAS_NEWLIB
562 endif # USING_GLIBCXX
563 endif # GNU Debug build
564
565 # Dead code stripping. Issue 'make lean'.
566 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
567 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
568 CXXFLAGS += -ffunction-sections
569 endif # CXXFLAGS
570 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
571 CXXFLAGS += -fdata-sections
572 endif # CXXFLAGS
573 ifneq ($(IS_IOS),0)
574 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
575 LDFLAGS += -Wl,-dead_strip
576 endif # CXXFLAGS
577 else # BSD, Linux and Unix
578 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
579 LDFLAGS += -Wl,--gc-sections
580 endif # LDFLAGS
581 endif # MAKECMDGOALS
582 endif # Dead code stripping
583
584 ###########################################################
585 ##### Source and object files #####
586 ###########################################################
587
588 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
589 SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp cryptlib_bds.cpp,$(sort $(wildcard *.cpp)))
590 # For Makefile.am; resource.h is Windows
591 INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
592
593 # Cryptogams AES for ARMv4 and above. We couple to ARMv7.
594 # Avoid iOS. It cannot consume the assembly.
595 ifeq ($(IS_ARM32),1)
596 ifneq ($(IS_IOS),1)
597 CRYPTOGAMS_AES_FLAG = -march=armv7-a
598 CRYPTOGAMS_AES_FLAG += -Wa,--noexecstack
599 SRCS += aes_armv4.S
600 endif
601 endif
602
603 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
604 OBJS := $(SRCS:.cpp=.o)
605 OBJS := $(OBJS:.S=.o)
606
607 # List test.cpp first to tame C++ static initialization problems.
608 TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp bench3.cpp datatest.cpp dlltest.cpp fipsalgt.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp validat5.cpp validat6.cpp validat7.cpp validat8.cpp validat9.cpp validat10.cpp regtest1.cpp regtest2.cpp regtest3.cpp regtest4.cpp
609 TESTINCL := bench.h factory.h validate.h
610
611 # Test objects
612 TESTOBJS := $(TESTSRCS:.cpp=.o)
613 LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
614
615 # For Shared Objects, Diff, Dist/Zip rules
616 LIB_VER := $(shell $(EGREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3)
617 LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
618 LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
619 LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
620
621 ifeq ($(strip $(LIB_PATCH)),)
622 LIB_PATCH := 0
623 endif
624
625 ifeq ($(HAS_SOLIB_VERSION),1)
626 # Full version suffix for shared library
627 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
628 # Different patchlevels and minors are compatible since 6.1
629 SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
630 SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
631 endif # HAS_SOLIB_VERSION
632
633 ###########################################################
634 ##### Targets and Recipes #####
635 ###########################################################
636
637 # Default builds program with static library only
638 .PHONY: default
639 default: cryptest.exe
640
641 .PHONY: all static dynamic
642 all: static dynamic cryptest.exe
643
644 ifneq ($(IS_IOS),0)
645 static: libcryptopp.a
646 shared dynamic dylib: libcryptopp.dylib
647 else
648 static: libcryptopp.a
649 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
650 endif
651
652 .PHONY: test check
653 test check: cryptest.exe
654 ./cryptest.exe v
655
656 # CXXFLAGS are tuned earlier. Applications must use linker flags
657 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
658 .PHONY: lean
659 lean: static dynamic cryptest.exe
660
661 .PHONY: clean
662 clean:
663 -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(AOSP_CPU_OBJ) rdrand-*.o $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
664 @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
665 @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
666 @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct et
667 @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
668 @-$(RM) /tmp/adhoc.exe
669 @-$(RM) -r /tmp/cryptopp_test/
670 @-$(RM) -r *.exe.dSYM/
671 @-$(RM) -r *.dylib.dSYM/
672 @-$(RM) -r cov-int/
673
674 .PHONY: autotools-clean
675 autotools-clean:
676 @-$(RM) -f configure.ac configure configure.in Makefile.am Makefile.in Makefile
677 @-$(RM) -f config.guess config.status config.sub config.h.in compile depcomp
678 @-$(RM) -f install-sh stamp-h1 ar-lib *.lo *.la *.m4 local.* lt*.sh missing
679 @-$(RM) -f cryptest cryptestcwd libtool* libcryptopp.la libcryptopp.pc*
680 @-$(RM) -rf m4/ auto*.cache/ .deps/ .libs/
681
682 .PHONY: cmake-clean
683 cmake-clean:
684 @-$(RM) -f cryptopp-config.cmake CMakeLists.txt
685 @-$(RM) -rf cmake_build/
686
687 .PHONY: distclean
688 distclean: clean autotools-clean cmake-clean
689 -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt
690 @-$(RM) cryptest-*.txt cryptopp.tgz libcryptopp.pc *.o *.bc *.ii *~
691 @-$(RM) -r cryptlib.lib cryptest.exe *.suo *.sdf *.pdb Win32/ x64/ ipch/
692 @-$(RM) -r $(LIBOBJS:.o=.obj) $(TESTOBJS:.o=.obj)
693 @-$(RM) -r $(LIBOBJS:.o=.lst) $(TESTOBJS:.o=.lst)
694 @-$(RM) -r TestCoverage/ ref*/
695 @-$(RM) cryptopp$(LIB_VER)\.* CryptoPPRef.zip
696
697 # Install cryptest.exe, libcryptopp.a and libcryptopp.so.
698 # The library install was broken-out into its own recipe at GH #653.
699 .PHONY: install
700 install: cryptest.exe install-lib
701 @-$(MKDIR) $(DESTDIR)$(BINDIR)
702 $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
703 $(CHMOD) 0755 $(DESTDIR)$(BINDIR)/cryptest.exe
704 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestData
705 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
706 $(CP) TestData/*.dat $(DESTDIR)$(DATADIR)/cryptopp/TestData
707 $(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestData/*.dat
708 $(CP) TestVectors/*.txt $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
709 $(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
710
711 # A recipe to install only the library, and not cryptest.exe. Also
712 # see https://github.com/weidai11/cryptopp/issues/653.
713 .PHONY: install-lib
714 install-lib:
715 @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
716 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
717 $(CHMOD) 0644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
718 ifneq ($(wildcard libcryptopp.a),)
719 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
720 $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
721 $(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
722 endif
723 ifneq ($(wildcard libcryptopp.dylib),)
724 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
725 $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
726 $(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
727 -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
728 endif
729 ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
730 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
731 $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
732 $(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
733 ifeq ($(HAS_SOLIB_VERSION),1)
734 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
735 $(LDCONF) $(DESTDIR)$(LIBDIR)
736 endif
737 endif
738 ifneq ($(wildcard libcryptopp.pc),)
739 @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
740 $(CP) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig
741 $(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
742 endif
743
744 .PHONY: remove uninstall
745 remove uninstall:
746 -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
747 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
748 -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
749 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
750 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
751 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
752 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
753
754 libcryptopp.a: $(LIBOBJS) $(AOSP_CPU_OBJ)
755 $(AR) $(ARFLAGS) $@ $(LIBOBJS) $(AOSP_CPU_OBJ)
756 $(RANLIB) $@
757
758 ifeq ($(HAS_SOLIB_VERSION),1)
759 .PHONY: libcryptopp.so
760 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
761 endif
762
763 libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS) $(AOSP_CPU_OBJ)
764 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) -Wl,--exclude-libs,ALL $(LIBOBJS) $(AOSP_CPU_OBJ) $(LDFLAGS) $(LDLIBS)
765 ifeq ($(HAS_SOLIB_VERSION),1)
766 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
767 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
768 endif
769
770 libcryptopp.dylib: $(LIBOBJS) $(AOSP_CPU_OBJ)
771 $(CXX) -dynamiclib -o $@ $(strip $(CXXFLAGS)) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS) $(AOSP_CPU_OBJ)
772
773 cryptest.exe: libcryptopp.a $(TESTOBJS)
774 $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
775
776 # Used to generate list of source files for Autotools, CMakeList and Android.mk
777 .PHONY: sources
778 sources:
779 $(info ***** Library sources *****)
780 $(info $(filter-out $(TESTSRCS),$(SRCS)))
781 $(info )
782 $(info ***** Library headers *****)
783 $(info $(filter-out $(TESTINCL),$(INCL)))
784 $(info )
785 $(info ***** Test sources *****)
786 $(info $(TESTSRCS))
787 $(info )
788 $(info ***** Test headers *****)
789 $(info $(TESTINCL))
790
791 adhoc.cpp: adhoc.cpp.proto
792 ifeq ($(wildcard adhoc.cpp),)
793 cp adhoc.cpp.proto adhoc.cpp
794 else
795 touch adhoc.cpp
796 endif
797
798 # Include dependencies, if present. You must issue `make deps` to create them.
799 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
800 -include GNUmakefile.deps
801 endif # Dependencies
802
803 # Cryptogams ARM asm implementation.
804 aes_armv4.o : aes_armv4.S
805 $(CXX) $(strip $(CXXFLAGS) -fpermissive $(CRYPTOGAMS_AES_FLAG) -c) $<
806
807 cpu-features.o: cpu-features.h cpu-features.c
808 $(CXX) $(strip $(CXXFLAGS) -fpermissive -c) cpu-features.c
809
810 # SSSE3 or NEON available
811 aria_simd.o : aria_simd.cpp
812 $(CXX) $(strip $(CXXFLAGS) $(ARIA_FLAG) -c) $<
813
814 # SSE, NEON or POWER7 available
815 blake2s_simd.o : blake2s_simd.cpp
816 $(CXX) $(strip $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
817
818 # SSE, NEON or POWER8 available
819 blake2b_simd.o : blake2b_simd.cpp
820 $(CXX) $(strip $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
821
822 # SSE2 or NEON available
823 chacha_simd.o : chacha_simd.cpp
824 $(CXX) $(strip $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
825
826 # AVX2 available
827 chacha_avx.o : chacha_avx.cpp
828 $(CXX) $(strip $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
829
830 # SSSE3 available
831 cham_simd.o : cham_simd.cpp
832 $(CXX) $(strip $(CXXFLAGS) $(CHAM_FLAG) -c) $<
833
834 # Power9 available
835 darn.o : darn.cpp
836 $(CXX) $(strip $(CXXFLAGS) $(DARN_FLAG) -c) $<
837
838 # SSE2 on i686
839 donna_sse.o : donna_sse.cpp
840 $(CXX) $(strip $(CXXFLAGS) $(SSE2_FLAG) -c) $<
841
842 # SSE2 on i686
843 sse_simd.o : sse_simd.cpp
844 $(CXX) $(strip $(CXXFLAGS) $(SSE2_FLAG) -c) $<
845
846 # SSE4.2 or ARMv8a available
847 crc_simd.o : crc_simd.cpp
848 $(CXX) $(strip $(CXXFLAGS) $(CRC_FLAG) -c) $<
849
850 # PCLMUL or ARMv7a/ARMv8a available
851 gcm_simd.o : gcm_simd.cpp
852 $(CXX) $(strip $(CXXFLAGS) $(GCM_FLAG) -c) $<
853
854 # SSSE3 available
855 lea_simd.o : lea_simd.cpp
856 $(CXX) $(strip $(CXXFLAGS) $(LEA_FLAG) -c) $<
857
858 # NEON available
859 neon_simd.o : neon_simd.cpp
860 $(CXX) $(strip $(CXXFLAGS) $(NEON_FLAG) -c) $<
861
862 # AESNI or ARMv7a/ARMv8a available
863 rijndael_simd.o : rijndael_simd.cpp
864 $(CXX) $(strip $(CXXFLAGS) $(AES_FLAG) -c) $<
865
866 # SSE4.2/SHA-NI or ARMv8a available
867 sha_simd.o : sha_simd.cpp
868 $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
869
870 # SSE4.2/SHA-NI or ARMv8a available
871 shacal2_simd.o : shacal2_simd.cpp
872 $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
873
874 # SSSE3 or NEON available
875 simeck_simd.o : simeck_simd.cpp
876 $(CXX) $(strip $(CXXFLAGS) $(SIMECK_FLAG) -c) $<
877
878 # SSE4.1, NEON or POWER7 available
879 simon64_simd.o : simon64_simd.cpp
880 $(CXX) $(strip $(CXXFLAGS) $(SIMON64_FLAG) -c) $<
881
882 # SSSE3, NEON or POWER8 available
883 simon128_simd.o : simon128_simd.cpp
884 $(CXX) $(strip $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
885
886 # SSE4.1, NEON or POWER7 available
887 speck64_simd.o : speck64_simd.cpp
888 $(CXX) $(strip $(CXXFLAGS) $(SPECK64_FLAG) -c) $<
889
890 # SSSE3, NEON or POWER8 available
891 speck128_simd.o : speck128_simd.cpp
892 $(CXX) $(strip $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
893
894 # ARMv8.4 available
895 sm3_simd.o : sm3_simd.cpp
896 $(CXX) $(strip $(CXXFLAGS) $(SM3_FLAG) -c) $<
897
898 # AESNI available
899 sm4_simd.o : sm4_simd.cpp
900 $(CXX) $(strip $(CXXFLAGS) $(SM4_FLAG) -c) $<
901
902 %.o : %.cpp
903 $(CXX) $(strip $(CXXFLAGS) -c) $<
904
905 .PHONY: dep deps depend
906 dep deps depend GNUmakefile.deps:
907 $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DISABLE_ASM) -MM *.cpp > GNUmakefile.deps