1 # https://www.gnu.org/software/make/manual/make.html#Makefile-Conventions
2 # and https://www.gnu.org/prep/standards/standards.html
8 # Used for feature tests
10 TOUT := $(strip $(TOUT))
12 # Allow override for the cryptest.exe recipe. Change to
13 # ./libcryptopp.so or ./libcryptopp.dylib to suit your
14 # taste. https://github.com/weidai11/cryptopp/issues/866
15 LINK_LIBRARY ?= libcryptopp.a
16 LINK_LIBRARY_PATH ?= ./
18 # Default FLAGS if none were provided
20 CXXFLAGS ?= -g2 -O3 -fPIC -pipe
33 LDCONF ?= /sbin/ldconfig -n
39 # Clang is reporting armv8l-unknown-linux-gnueabihf
40 # for ARMv7 images on Aarch64 hardware.
41 MACHINEX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
42 HOSTX := $(shell echo $(MACHINEX) | cut -f 1 -d '-')
44 HOSTX := $(shell uname -m 2>/dev/null)
47 IS_LINUX := $(shell echo $(MACHINEX) | $(GREP) -i -c "Linux")
49 # Can be used by Android and Embedded cross-compiles. Disable by default because
50 # Android and embedded users typically don't run this configuration.
51 HAS_SOLIB_VERSION ?= 0
53 # Formerly adhoc.cpp was created from adhoc.cpp.proto when needed.
54 # This is now needed because ISA tests are performed using adhoc.cpp.
55 ifeq ($(wildcard adhoc.cpp),)
56 $(shell cp adhoc.cpp.proto adhoc.cpp)
59 ###########################################################
60 ##### General Variables #####
61 ###########################################################
63 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
68 LIBDIR := $(PREFIX)/lib
71 DATADIR := $(PREFIX)/share
74 INCLUDEDIR := $(PREFIX)/include
77 BINDIR := $(PREFIX)/bin
80 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
85 ###########################################################
87 ###########################################################
89 # MacOS cross-compile configuration.
90 # See http://www.cryptopp.com/wiki/MacOS_(Command_Line).
92 # setenv-macos.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
93 IS_APPLE_LIBTOOL=$(shell libtool -V 2>&1 | $(GREP) -i -c 'Apple')
94 ifeq ($(IS_APPLE_LIBTOOL),1)
102 ###########################################################
104 ###########################################################
106 # iOS cross-compile configuration.
107 # See http://www.cryptopp.com/wiki/iOS_(Command_Line).
109 # setenv-ios.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
114 ###########################################################
116 ###########################################################
118 # Android cross-compile configuration.
119 # See http://www.cryptopp.com/wiki/Android_(Command_Line).
120 ifeq ($(IS_ANDROID),1)
121 # setenv-android.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
123 # Source files copied into PWD for Android cpu-features
124 # setenv-android.sh does the copying. Its a dirty compile.
125 ANDROID_CPU_OBJ = cpu-features.o
128 ###########################################################
130 ###########################################################
132 # ARM embedded cross-compile configuration.
133 # See http://www.cryptopp.com/wiki/ARM_Embedded_(Command_Line)
134 # and http://www.cryptopp.com/wiki/ARM_Embedded_(Bare Metal).
135 ifeq ($(IS_ARM_EMBEDDED),1)
136 # setenv-android.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
139 ###########################################################
140 ##### Compiler and Platform #####
141 ###########################################################
143 # Wait until CXXFLAGS have been set by setenv scripts.
145 GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -v -E 'llvm|clang' | $(GREP) -i -c -E '(gcc|g\+\+)')
146 CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c -E 'llvm|clang')
148 HOSTX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | cut -f 1 -d '-')
150 HOSTX := $(shell uname -m 2>/dev/null)
153 # This dance is because Clang reports the host architecture instead
154 # of the target architecture for -dumpmachine. Running Clang on an
155 # x86_64 machine with -arch arm64 yields x86_64 instead of arm64.
157 ifeq ($(CLANG_COMPILER),1)
158 # The compiler is either GCC or Clang
159 IS_X86 := $(shell echo $(CXXFLAGS) | $(GREP) -v 64 | $(GREP) -i -c -E 'i.86')
160 IS_X64 := $(shell echo $(CXXFLAGS) | $(GREP) -i -c -E 'x86_64|amd64')
161 IS_ARM32 := $(shell echo $(CXXFLAGS) | $(GREP) -v 64 | $(GREP) -i -c -E 'arm|armhf|arm7l|armeabihf')
162 IS_ARMV8 := $(shell echo $(CXXFLAGS) | $(GREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
164 IS_X86 := $(shell echo $(HOSTX) | $(GREP) -v 64 | $(GREP) -i -c -E 'i.86')
165 IS_X64 := $(shell echo $(HOSTX) | $(GREP) -i -c -E 'x86_64|amd64')
166 IS_ARM32 := $(shell echo $(HOSTX) | $(GREP) -v 64 | $(GREP) -i -c -E 'arm|armhf|arm7l|eabihf')
167 IS_ARMV8 := $(shell echo $(HOSTX) | $(GREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
178 # Uncomment for debugging
179 # $(info Here's what we found... IS_X86: $(IS_X86), IS_X64: $(IS_X64), IS_ARM32: $(IS_ARM32), IS_ARMV8: $(IS_ARMV8))
181 ###########################################################
182 ##### Test Program #####
183 ###########################################################
185 # Hack to skip CPU feature tests for some recipes
187 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),-DCRYPTOPP_DISABLE_ASM)
189 else ifeq ($(findstring clean,$(MAKECMDGOALS)),clean)
191 else ifeq ($(findstring distclean,$(MAKECMDGOALS)),distclean)
193 else ifeq ($(findstring trim,$(MAKECMDGOALS)),trim)
195 else ifeq ($(findstring zip,$(MAKECMDGOALS)),zip)
199 # Strip out -Wall, -Wextra and friends for feature testing. FORTIFY_SOURCE is removed
200 # because it requires -O1 or higher, but we use -O0 to tame the optimizer.
201 # Always print testing flags since some tests always happen, like 64-bit.
202 TCXXFLAGS := $(filter-out -D_FORTIFY_SOURCE=% -M -MM -Wall -Wextra -Werror% -Wunused -Wconversion -Wp%, $(CPPFLAGS) $(CXXFLAGS))
203 ifneq ($(strip $(TCXXFLAGS)),)
204 $(info Using testing flags: $(TCXXFLAGS))
207 # TCOMMAND is used for just about all tests. Make will lazy-evaluate
208 # the variables when executed by $(shell $(TCOMMAND) ...).
209 TCOMMAND = $(CXX) $(TCXXFLAGS) $(TEXTRA) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT)
211 ###########################################################
212 ##### X86/X32/X64 Options #####
213 ###########################################################
215 ifneq ($(IS_X86)$(IS_X64),00)
216 ifeq ($(DETECT_FEATURES),1)
221 SSE41_FLAG = -msse4.1
222 SSE42_FLAG = -msse4.2
223 CLMUL_FLAG = -mpclmul
229 TPROG = TestPrograms/test_x86_sse2.cpp
231 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
232 ifeq ($(strip $(HAVE_OPT)),0)
233 CHACHA_FLAG = $(SSE2_FLAG)
235 # Make does not have useful debugging facilities. Show the user
236 # what happened by compiling again without the pipe.
237 $(info Running make again to see what failed)
238 $(info $(shell $(TCOMMAND)))
243 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
246 # Need SSE2 or higher for these tests
247 ifneq ($(SSE2_FLAG),)
248 TPROG = TestPrograms/test_x86_ssse3.cpp
250 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
251 ifeq ($(strip $(HAVE_OPT)),0)
252 ARIA_FLAG = $(SSSE3_FLAG)
253 CHAM_FLAG = $(SSSE3_FLAG)
254 KECCAK_FLAG = $(SSSE3_FLAG)
255 LEA_FLAG = $(SSSE3_FLAG)
256 LSH256_FLAG = $(SSSE3_FLAG)
257 LSH512_FLAG = $(SSSE3_FLAG)
258 SIMON128_FLAG = $(SSSE3_FLAG)
259 SPECK128_FLAG = $(SSSE3_FLAG)
264 # The first Apple MacBooks were Core2's with SSE4.1
265 ifneq ($(IS_DARWIN),0)
266 # Add SSE2 algo's here as required
267 # They get a free upgrade
270 TPROG = TestPrograms/test_x86_sse41.cpp
272 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
273 ifeq ($(strip $(HAVE_OPT)),0)
274 BLAKE2B_FLAG = $(SSE41_FLAG)
275 BLAKE2S_FLAG = $(SSE41_FLAG)
280 TPROG = TestPrograms/test_x86_sse42.cpp
282 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
283 ifeq ($(strip $(HAVE_OPT)),0)
284 CRC_FLAG = $(SSE42_FLAG)
289 TPROG = TestPrograms/test_x86_clmul.cpp
291 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
292 ifeq ($(strip $(HAVE_OPT)),0)
293 GCM_FLAG = $(SSSE3_FLAG) $(CLMUL_FLAG)
294 GF2N_FLAG = $(CLMUL_FLAG)
299 TPROG = TestPrograms/test_x86_aes.cpp
301 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
302 ifeq ($(strip $(HAVE_OPT)),0)
303 AES_FLAG = $(SSE41_FLAG) $(AESNI_FLAG)
304 SM4_FLAG = $(SSSE3_FLAG) $(AESNI_FLAG)
309 TPROG = TestPrograms/test_x86_avx.cpp
311 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
312 ifeq ($(strip $(HAVE_OPT)),0)
313 # XXX_FLAG = $(AVX_FLAG)
318 TPROG = TestPrograms/test_x86_avx2.cpp
320 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
321 ifeq ($(strip $(HAVE_OPT)),0)
322 CHACHA_AVX2_FLAG = $(AVX2_FLAG)
323 LSH256_AVX2_FLAG = $(AVX2_FLAG)
324 LSH512_AVX2_FLAG = $(AVX2_FLAG)
329 TPROG = TestPrograms/test_x86_sha.cpp
331 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
332 ifeq ($(strip $(HAVE_OPT)),0)
333 SHA_FLAG = $(SSE42_FLAG) $(SHANI_FLAG)
339 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE3
340 else ifeq ($(SSSE3_FLAG),)
341 CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
342 else ifeq ($(SSE41_FLAG),)
343 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
344 else ifeq ($(SSE42_FLAG),)
345 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
348 ifneq ($(SSE42_FLAG),)
349 # Unusual GCC/Clang on Macports. It assembles AES, but not CLMUL.
350 # test_x86_clmul.s:15: no such instruction: 'pclmulqdq $0, %xmm1,%xmm0'
351 ifeq ($(CLMUL_FLAG),)
352 CXXFLAGS += -DCRYPTOPP_DISABLE_CLMUL
354 ifeq ($(AESNI_FLAG),)
355 CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
359 CXXFLAGS += -DCRYPTOPP_DISABLE_AVX
360 else ifeq ($(AVX2_FLAG),)
361 CXXFLAGS += -DCRYPTOPP_DISABLE_AVX2
363 # SHANI independent of AVX per GH #1045
364 ifeq ($(SHANI_FLAG),)
365 CRYPTOPP_CXXFLAGS += -DCRYPTOPP_DISABLE_SHANI
369 # Drop to SSE2 if available
371 GCM_FLAG = $(SSE2_FLAG)
374 # Most Clang cannot handle mixed asm with positional arguments, where the
375 # body is Intel style with no prefix and the templates are AT&T style.
376 # Also see https://bugs.llvm.org/show_bug.cgi?id=39895 .
378 # CRYPTOPP_DISABLE_MIXED_ASM is now being added in config_asm.h for all
379 # Clang compilers. This test will need to be re-enabled if Clang fixes it.
380 #TPROG = TestPrograms/test_asm_mixed.cpp
382 #HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
383 #ifneq ($(strip $(HAVE_OPT)),0)
384 # CXXFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM
393 # IS_X86, IS_X32 and IS_X64
396 ###########################################################
397 ##### ARM A-32 and NEON #####
398 ###########################################################
400 ifneq ($(IS_ARM32),0)
401 ifeq ($(DETECT_FEATURES),1)
403 # Android needs -c compile flag for NEON. Otherwise there's an odd linker message.
404 ifeq ($(IS_ANDROID),1)
405 NEON_FLAG = -march=armv7-a -mfpu=vfpv3-d16 -mfpu=neon
407 NEON_FLAG = -march=armv7-a -mfpu=neon
410 # Clang needs an option to include <arm_neon.h>
411 TPROG = TestPrograms/test_arm_neon_header.cpp
412 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1 $(NEON_FLAG)
413 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
414 ifeq ($(strip $(HAVE_OPT)),0)
415 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
418 TPROG = TestPrograms/test_arm_neon.cpp
420 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
421 ifeq ($(strip $(HAVE_OPT)),0)
422 ARIA_FLAG = $(NEON_FLAG)
423 AES_FLAG = $(NEON_FLAG)
424 CRC_FLAG = $(NEON_FLAG)
425 GCM_FLAG = $(NEON_FLAG)
426 BLAKE2B_FLAG = $(NEON_FLAG)
427 BLAKE2S_FLAG = $(NEON_FLAG)
428 CHACHA_FLAG = $(NEON_FLAG)
429 CHAM_FLAG = $(NEON_FLAG)
430 LEA_FLAG = $(NEON_FLAG)
431 SHA_FLAG = $(NEON_FLAG)
432 SIMON128_FLAG = $(NEON_FLAG)
433 SPECK128_FLAG = $(NEON_FLAG)
434 SM4_FLAG = $(NEON_FLAG)
436 # Make does not have useful debugging facilities. Show the user
437 # what happened by compiling again without the pipe.
438 $(info Running make again to see what failed)
439 $(info $(shell $(TCOMMAND)))
444 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
452 ###########################################################
453 ##### Aach32 and Aarch64 #####
454 ###########################################################
456 ifneq ($(IS_ARMV8),0)
457 ifeq ($(DETECT_FEATURES),1)
460 ASIMD_FLAG = -arch arm64
461 CRC_FLAG = -arch arm64
462 AES_FLAG = -arch arm64
463 PMUL_FLAG = -arch arm64
464 SHA_FLAG = -arch arm64
466 ASIMD_FLAG = -march=armv8-a
467 CRC_FLAG = -march=armv8-a+crc
468 AES_FLAG = -march=armv8-a+crypto
469 GCM_FLAG = -march=armv8-a+crypto
470 GF2N_FLAG = -march=armv8-a+crypto
471 SHA_FLAG = -march=armv8-a+crypto
474 TPROG = TestPrograms/test_arm_neon_header.cpp
475 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1
476 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
477 ifeq ($(strip $(HAVE_OPT)),0)
478 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
481 TPROG = TestPrograms/test_arm_acle_header.cpp
482 TOPT = -DCRYPTOPP_ARM_ACLE_HEADER=1 $(ASIMD_FLAG)
483 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
484 ifeq ($(strip $(HAVE_OPT)),0)
485 TEXTRA += -DCRYPTOPP_ARM_ACLE_HEADER=1
488 TPROG = TestPrograms/test_arm_asimd.cpp
490 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
491 ifeq ($(strip $(HAVE_OPT)),0)
492 ARIA_FLAG = $(ASIMD_FLAG)
493 BLAKE2B_FLAG = $(ASIMD_FLAG)
494 BLAKE2S_FLAG = $(ASIMD_FLAG)
495 CHACHA_FLAG = $(ASIMD_FLAG)
496 CHAM_FLAG = $(ASIMD_FLAG)
497 LEA_FLAG = $(ASIMD_FLAG)
498 NEON_FLAG = $(ASIMD_FLAG)
499 SIMON128_FLAG = $(ASIMD_FLAG)
500 SPECK128_FLAG = $(ASIMD_FLAG)
501 SM4_FLAG = $(ASIMD_FLAG)
503 # Make does not have useful debugging facilities. Show the user
504 # what happened by compiling again without the pipe.
505 $(info Running make again to see what failed)
506 $(info $(shell $(TCOMMAND)))
510 ifeq ($(ASIMD_FLAG),)
511 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
514 ifneq ($(ASIMD_FLAG),)
516 TPROG = TestPrograms/test_arm_crc.cpp
518 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
519 ifneq ($(strip $(HAVE_OPT)),0)
521 CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_CRC32
524 TPROG = TestPrograms/test_arm_aes.cpp
526 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
527 ifneq ($(strip $(HAVE_OPT)),0)
529 CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_AES
532 TPROG = TestPrograms/test_arm_pmull.cpp
534 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
535 ifneq ($(strip $(HAVE_OPT)),0)
538 CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_PMULL
541 TPROG = TestPrograms/test_arm_sha1.cpp
543 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
544 ifneq ($(strip $(HAVE_OPT)),0)
546 CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA1
549 TPROG = TestPrograms/test_arm_sha256.cpp
551 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
552 ifneq ($(strip $(HAVE_OPT)),0)
554 CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA2
557 TPROG = TestPrograms/test_arm_sm3.cpp
558 TOPT = -march=armv8.4-a+sm3
559 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
560 ifeq ($(strip $(HAVE_OPT)),0)
561 SM3_FLAG = -march=armv8.4-a+sm3
562 SM4_FLAG = -march=armv8.4-a+sm3
564 #CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_SM3
565 #CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_SM4
568 TPROG = TestPrograms/test_arm_sha3.cpp
569 TOPT = -march=armv8.4-a+sha3
570 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
571 ifeq ($(strip $(HAVE_OPT)),0)
572 SHA3_FLAG = -march=armv8.4-a+sha3
574 #CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA3
577 TPROG = TestPrograms/test_arm_sha512.cpp
578 TOPT = -march=armv8.4-a+sha512
579 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
580 ifeq ($(strip $(HAVE_OPT)),0)
581 SHA512_FLAG = -march=armv8.4-a+sha512
583 #CXXFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA512
594 ###########################################################
596 ###########################################################
598 # No ASM for Travis testing
599 ifeq ($(findstring no-asm,$(MAKECMDGOALS)),no-asm)
600 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
601 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
605 # Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
606 ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
607 ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
608 CXXFLAGS += -fsanitize=undefined
610 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
611 CXXFLAGS += -DCRYPTOPP_COVERAGE
615 # Address Sanitizer (Asan) testing. Issue 'make asan'.
616 ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
617 ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
618 CXXFLAGS += -fsanitize=address
620 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
621 CXXFLAGS += -DCRYPTOPP_COVERAGE
623 ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
624 CXXFLAGS += -fno-omit-frame-pointer
628 # LD gold linker testing. Triggered by 'LD=ld.gold'.
629 ifeq ($(findstring ld.gold,$(LD)),ld.gold)
630 ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
631 ELF_FORMAT := $(shell file `which ld.gold` 2>&1 | cut -d":" -f 2 | $(GREP) -i -c "elf")
632 ifneq ($(ELF_FORMAT),0)
633 LDFLAGS += -fuse-ld=gold
638 # Valgrind testing. Issue 'make valgrind'.
639 ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
640 # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
641 CXXFLAGS := $(CXXFLAGS:-g%=-g3)
642 CXXFLAGS := $(CXXFLAGS:-O%=-O1)
643 CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
644 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
645 CXXFLAGS += -DCRYPTOPP_COVERAGE
646 endif # -DCRYPTOPP_COVERAGE
649 # Debug testing on GNU systems. Triggered by -DDEBUG.
650 # Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
651 ifneq ($(filter -DDEBUG -DDEBUG=1,$(CXXFLAGS)),)
652 USING_GLIBCXX := $(shell $(CXX) $(CXXFLAGS) -E pch.cpp 2>&1 | $(GREP) -i -c "__GLIBCXX__")
653 ifneq ($(USING_GLIBCXX),0)
654 ifeq ($(HAS_NEWLIB),0)
655 ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CXXFLAGS)),)
656 CXXFLAGS += -D_GLIBCXX_DEBUG
659 endif # USING_GLIBCXX
660 endif # GNU Debug build
662 # Dead code stripping. Issue 'make lean'.
663 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
664 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
665 CXXFLAGS += -ffunction-sections
667 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
668 CXXFLAGS += -fdata-sections
671 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
672 LDFLAGS += -Wl,-dead_strip
674 else # BSD, Linux and Unix
675 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
676 LDFLAGS += -Wl,--gc-sections
679 endif # Dead code stripping
681 ###########################################################
682 ##### Source and object files #####
683 ###########################################################
685 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
686 SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp,$(sort $(wildcard *.cpp)))
687 # For Makefile.am; resource.h is Windows
688 INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
690 # Cryptogams source files. We couple to ARMv7.
691 # Limit to Linux. The source files target the GNU assembler.
692 # Also see https://www.cryptopp.com/wiki/Cryptogams.
693 ifeq ($(IS_ARM32)$(IS_LINUX),11)
694 ifeq ($(CLANG_COMPILER),1)
695 CRYPTOGAMS_ARMV4_FLAG = -march=armv7-a -Wa,--noexecstack
696 CRYPTOGAMS_ARMV4_THUMB_FLAG = -march=armv7-a -mthumb -Wa,--noexecstack
698 CRYPTOGAMS_ARMV4_FLAG = -march=armv7-a -Wa,--noexecstack
699 CRYPTOGAMS_ARMV4_THUMB_FLAG = -march=armv7-a -Wa,--noexecstack
701 SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S sha512_armv4.S
704 # Remove unneeded arch specific files to speed build time.
705 ifeq ($(IS_PPC32)$(IS_PPC64),00)
706 SRCS := $(filter-out ppc_%,$(SRCS))
708 ifeq ($(IS_ARM32)$(IS_ARMV8),00)
709 SRCS := $(filter-out arm_%,$(SRCS))
710 SRCS := $(filter-out neon_%,$(SRCS))
712 ifeq ($(IS_X86)$(IS_X32)$(IS_X64),000)
713 SRCS := $(filter-out sse_%,$(SRCS))
716 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
717 OBJS := $(SRCS:.cpp=.o)
718 OBJS := $(OBJS:.S=.o)
720 # List test.cpp first to tame C++ static initialization problems.
721 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
722 TESTINCL := bench.h factory.h validate.h
725 TESTOBJS := $(TESTSRCS:.cpp=.o)
726 LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
728 # Clean recipe, Issue 998. Don't filter-out some artifacts from the list of objects
729 # The *.S is a hack. It makes the ASM appear like C++ so the object files make the CLEAN_OBJS list
730 CLEAN_SRCS := $(wildcard *.cpp) $(patsubst %.S,%.cpp,$(wildcard *.S))
731 CLEAN_OBJS := $(CLEAN_SRCS:.cpp=.o) $(CLEAN_SRCS:.cpp=.import.o) $(CLEAN_SRCS:.cpp=.export.o)
733 # For Shared Objects, Diff, Dist/Zip rules
734 LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config_ver.h | cut -d" " -f 3)
735 LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
736 LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
737 LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
739 ifeq ($(strip $(LIB_PATCH)),)
743 ifeq ($(HAS_SOLIB_VERSION),1)
744 # Full version suffix for shared library
745 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
746 # Different patchlevels and minors are compatible since 6.1
747 SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
748 SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
749 endif # HAS_SOLIB_VERSION
751 ###########################################################
752 ##### Targets and Recipes #####
753 ###########################################################
755 # Default builds program with static library only
757 default: cryptest.exe
759 .PHONY: all static dynamic
760 all: static dynamic cryptest.exe
763 static: libcryptopp.a
764 shared dynamic dylib: libcryptopp.dylib
766 static: libcryptopp.a
767 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
771 test check: cryptest.exe
774 # CXXFLAGS are tuned earlier. Applications must use linker flags
775 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
777 lean: static dynamic cryptest.exe
781 -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(CLEAN_OBJS) $(ANDROID_CPU_OBJ) rdrand-*.o
782 @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
783 @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
784 @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.dat ct et
785 @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
786 @-$(RM) /tmp/adhoc.exe
787 @-$(RM) -r /tmp/cryptopp_test/
788 @-$(RM) -r *.exe.dSYM/
789 @-$(RM) -r *.dylib.dSYM/
792 .PHONY: autotools-clean
794 @-$(RM) -f configure.ac configure configure.in Makefile.am Makefile.in Makefile
795 @-$(RM) -f config.guess config.status config.sub config.h.in compile depcomp
796 @-$(RM) -f install-sh stamp-h1 ar-lib *.lo *.la *.m4 local.* lt*.sh missing
797 @-$(RM) -f cryptest cryptestcwd libtool* libcryptopp.la libcryptopp.pc*
798 @-$(RM) -rf build-aux/ m4/ auto*.cache/ .deps/ .libs/
802 @-$(RM) -f cryptopp-config.cmake CMakeLists.txt
803 @-$(RM) -rf cmake_build/
805 .PHONY: android-clean
807 @-$(RM) -f $(patsubst %_simd.cpp,%_simd.cpp.neon,$(wildcard *_simd.cpp))
811 distclean: clean autotools-clean cmake-clean android-clean
812 -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt
813 -$(RM) cryptest_all.info cryptest_debug.info cryptest_noasm.info cryptest_base.info cryptest.info cryptest_release.info
814 @-$(RM) cryptest-*.txt cryptopp.tgz libcryptopp.pc *.o *.bc *.ii *~
815 @-$(RM) -r cryptlib.lib cryptest.exe *.suo *.sdf *.pdb Win32/ x64/ ipch/
816 @-$(RM) -r $(LIBOBJS:.o=.obj) $(TESTOBJS:.o=.obj)
817 @-$(RM) -r $(LIBOBJS:.o=.lst) $(TESTOBJS:.o=.lst)
818 @-$(RM) -r TestCoverage/ ref*/
819 @-$(RM) cryptopp$(LIB_VER)\.* CryptoPPRef.zip
821 # Install cryptest.exe, libcryptopp.a and libcryptopp.so.
822 # The library install was broken-out into its own recipe at GH #653.
824 install: cryptest.exe install-lib
825 @-$(MKDIR) $(DESTDIR)$(BINDIR)
826 $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
827 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(BINDIR)/cryptest.exe
828 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestData
829 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
830 $(CP) TestData/*.dat $(DESTDIR)$(DATADIR)/cryptopp/TestData
831 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/cryptopp/TestData/*.dat
832 $(CP) TestVectors/*.txt $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
833 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
835 # A recipe to install only the library, and not cryptest.exe. Also
836 # see https://github.com/weidai11/cryptopp/issues/653.
839 @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
840 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
841 $(CHMOD) u=rw,go=r $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
842 ifneq ($(wildcard libcryptopp.a),)
843 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
844 $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
845 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/libcryptopp.a
847 ifneq ($(wildcard libcryptopp.dylib),)
848 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
849 $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
850 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
851 -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
853 ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
854 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
855 $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
856 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
857 ifeq ($(HAS_SOLIB_VERSION),1)
858 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
859 $(LDCONF) $(DESTDIR)$(LIBDIR)
862 ifneq ($(wildcard libcryptopp.pc),)
863 @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
864 $(CP) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig
865 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
868 .PHONY: remove uninstall
870 -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
871 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
872 -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
873 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
874 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
875 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
876 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
878 libcryptopp.a: $(LIBOBJS) $(ANDROID_CPU_OBJ)
879 $(AR) $(ARFLAGS) $@ $(LIBOBJS) $(ANDROID_CPU_OBJ)
882 ifeq ($(HAS_SOLIB_VERSION),1)
883 .PHONY: libcryptopp.so
884 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
887 libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS) $(ANDROID_CPU_OBJ)
888 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) -Wl,--exclude-libs,ALL $(LIBOBJS) $(ANDROID_CPU_OBJ) $(LDFLAGS) $(LDLIBS)
889 ifeq ($(HAS_SOLIB_VERSION),1)
890 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
891 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
894 libcryptopp.dylib: $(LIBOBJS)
895 $(CXX) -dynamiclib -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS)
897 cryptest.exe: $(LINK_LIBRARY) $(TESTOBJS)
898 $(CXX) -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) $(TESTOBJS) $(LINK_LIBRARY_PATH)$(LINK_LIBRARY) $(LDFLAGS) $(LDLIBS)
900 # Used to generate list of source files for Autotools, CMakeList and Android.mk
903 $(info ***** Library sources *****)
904 $(info $(filter-out $(TESTSRCS),$(SRCS)))
906 $(info ***** Library headers *****)
907 $(info $(filter-out $(TESTINCL),$(INCL)))
909 $(info ***** Test sources *****)
912 $(info ***** Test headers *****)
915 adhoc.cpp: adhoc.cpp.proto
916 ifeq ($(wildcard adhoc.cpp),)
917 cp adhoc.cpp.proto adhoc.cpp
922 # Include dependencies, if present. You must issue `make deps` to create them.
923 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
924 -include GNUmakefile.deps
927 # A few recipes trigger warnings for -std=c++11 and -stdlib=c++
928 NOSTD_CXXFLAGS=$(filter-out -stdlib=%,$(filter-out -std=%,$(CXXFLAGS)))
930 # Cryptogams ARM asm implementation. AES needs -mthumb for Clang
931 aes_armv4.o : aes_armv4.S
932 $(CXX) $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARMV4_THUMB_FLAG) -c) $<
934 # Use C++ compiler on C source after patching.
935 # https://github.com/weidai11/cryptopp/issues/926
936 cpu-features.o: cpu-features.h cpu-features.c
937 $(CXX) -x c $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) -c) cpu-features.c
939 # SSSE3 or NEON available
940 aria_simd.o : aria_simd.cpp
941 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(ARIA_FLAG) -c) $<
943 # SSE, NEON or POWER7 available
944 blake2s_simd.o : blake2s_simd.cpp
945 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
947 # SSE, NEON or POWER8 available
948 blake2b_simd.o : blake2b_simd.cpp
949 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
951 # SSE2 or NEON available
952 chacha_simd.o : chacha_simd.cpp
953 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
956 chacha_avx.o : chacha_avx.cpp
957 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
960 cham_simd.o : cham_simd.cpp
961 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHAM_FLAG) -c) $<
965 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(DARN_FLAG) -c) $<
968 donna_sse.o : donna_sse.cpp
969 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
972 sse_simd.o : sse_simd.cpp
973 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
975 # SSE4.2 or ARMv8a available
976 crc_simd.o : crc_simd.cpp
977 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CRC_FLAG) -c) $<
979 # PCLMUL or ARMv7a/ARMv8a available
980 gcm_simd.o : gcm_simd.cpp
981 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GCM_FLAG) -c) $<
984 gf2n_simd.o : gf2n_simd.cpp
985 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GF2N_FLAG) -c) $<
988 keccak_simd.o : keccak_simd.cpp
989 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(KECCAK_FLAG) -c) $<
992 lea_simd.o : lea_simd.cpp
993 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LEA_FLAG) -c) $<
996 lsh256_sse.o : lsh256_sse.cpp
997 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_FLAG) -c) $<
1000 lsh256_avx.o : lsh256_avx.cpp
1001 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_AVX2_FLAG) -c) $<
1004 lsh512_sse.o : lsh512_sse.cpp
1005 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_FLAG) -c) $<
1008 lsh512_avx.o : lsh512_avx.cpp
1009 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_AVX2_FLAG) -c) $<
1012 neon_simd.o : neon_simd.cpp
1013 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(NEON_FLAG) -c) $<
1015 # AESNI or ARMv7a/ARMv8a available
1016 rijndael_simd.o : rijndael_simd.cpp
1017 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(AES_FLAG) -c) $<
1019 # SSE4.2/SHA-NI or ARMv8a available
1020 sha_simd.o : sha_simd.cpp
1021 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1023 # Cryptogams SHA1 asm implementation.
1024 sha1_armv4.o : sha1_armv4.S
1025 $(CXX) $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARMV4_FLAG) -c) $<
1027 # Cryptogams SHA256 asm implementation.
1028 sha256_armv4.o : sha256_armv4.S
1029 $(CXX) $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARMV4_FLAG) -c) $<
1031 # Cryptogams SHA512 asm implementation.
1032 sha512_armv4.o : sha512_armv4.S
1033 $(CXX) $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARMV4_FLAG) -c) $<
1035 # SSE4.2/SHA-NI or ARMv8a available
1036 shacal2_simd.o : shacal2_simd.cpp
1037 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1039 # SSSE3, NEON or POWER8 available
1040 simon128_simd.o : simon128_simd.cpp
1041 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
1043 # SSSE3, NEON or POWER8 available
1044 speck128_simd.o : speck128_simd.cpp
1045 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
1048 sm3_simd.o : sm3_simd.cpp
1049 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM3_FLAG) -c) $<
1052 sm4_simd.o : sm4_simd.cpp
1053 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM4_FLAG) -c) $<
1056 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) -c) $<
1058 .PHONY: dep deps depend
1059 dep deps depend GNUmakefile.deps:
1060 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS)) -MM *.cpp > GNUmakefile.deps