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