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
10TOUT := $(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
15LINK_LIBRARY ?= libcryptopp.a
16LINK_LIBRARY_PATH ?= ./
18# Default FLAGS if none were provided
20CXXFLAGS ?= -g2 -O3 -fPIC -pipe
33LDCONF ?= /sbin/ldconfig -n
39# Clang is reporting armv8l-unknown-linux-gnueabihf
40# for ARMv7 images on Aarch64 hardware.
41MACHINEX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
42HOSTX := $(shell echo $(MACHINEX) | cut -f 1 -d '-')
44 HOSTX := $(shell uname -m 2>/dev/null)
47IS_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.
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.
55ifeq ($(wildcard adhoc.cpp),)
56$(shell cp adhoc.cpp.proto adhoc.cpp)
59###########################################################
60##### General Variables #####
61###########################################################
63# Needed when the assembler is invoked
64ifeq ($(findstring -Wa,--noexecstack,$(ASFLAGS)$(CXXFLAGS)),)
65 ASFLAGS += -Wa,--noexecstack
68# On ARM we may compile aes_armv4.S, sha1_armv4.S, sha256_armv4.S, and
69# sha512_armv4.S through the CC compiler
70ifeq ($(GCC_COMPILER),1)
72else ifeq ($(CLANG_COMPILER),1)
76# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
81 LIBDIR := $(PREFIX)/lib
84 DATADIR := $(PREFIX)/share
87 INCLUDEDIR := $(PREFIX)/include
90 BINDIR := $(PREFIX)/bin
93# We honor ARFLAGS, but the "v" option used by default causes a noisy make
98###########################################################
100###########################################################
102# MacOS cross-compile configuration.
103# See http://www.cryptopp.com/wiki/MacOS_(Command_Line).
105 # setenv-macos.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
106 IS_APPLE_LIBTOOL=$(shell libtool -V 2>&1 | $(GREP) -i -c 'Apple')
107 ifeq ($(IS_APPLE_LIBTOOL),1)
110 AR = /usr/bin/libtool
115###########################################################
117###########################################################
119# iOS cross-compile configuration.
120# See http://www.cryptopp.com/wiki/iOS_(Command_Line).
122 # setenv-ios.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
127###########################################################
129###########################################################
131# Android cross-compile configuration.
132# See http://www.cryptopp.com/wiki/Android_(Command_Line).
133ifeq ($(IS_ANDROID),1)
134 # setenv-android.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
136 # Source files copied into PWD for Android cpu-features
137 # setenv-android.sh does the copying. Its a dirty compile.
138 ANDROID_CPU_OBJ = cpu-features.o
141###########################################################
143###########################################################
145# ARM embedded cross-compile configuration.
146# See http://www.cryptopp.com/wiki/ARM_Embedded_(Command_Line)
147# and http://www.cryptopp.com/wiki/ARM_Embedded_(Bare Metal).
148ifeq ($(IS_ARM_EMBEDDED),1)
149 # setenv-android.sh sets CPPFLAGS, CXXFLAGS and LDFLAGS
152###########################################################
153##### Compiler and Platform #####
154###########################################################
156# Wait until CXXFLAGS have been set by setenv scripts.
158GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -v -E 'llvm|clang' | $(GREP) -i -c -E '(gcc|g\+\+)')
159CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c -E 'llvm|clang')
161HOSTX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | cut -f 1 -d '-')
163 HOSTX := $(shell uname -m 2>/dev/null)
166# This dance is because Clang reports the host architecture instead
167# of the target architecture for -dumpmachine. Running Clang on an
168# x86_64 machine with -arch arm64 yields x86_64 instead of arm64.
170ifeq ($(CLANG_COMPILER),1)
171 # The compiler is either GCC or Clang
172 IS_X86 := $(shell echo $(CXXFLAGS) | $(GREP) -v 64 | $(GREP) -i -c -E 'i.86')
173 IS_X64 := $(shell echo $(CXXFLAGS) | $(GREP) -i -c -E 'x86_64|amd64')
174 IS_ARM32 := $(shell echo $(CXXFLAGS) | $(GREP) -v 64 | $(GREP) -i -c -E 'arm|armhf|arm7l|armeabihf')
175 IS_ARMV8 := $(shell echo $(CXXFLAGS) | $(GREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
177 IS_X86 := $(shell echo $(HOSTX) | $(GREP) -v 64 | $(GREP) -i -c -E 'i.86')
178 IS_X64 := $(shell echo $(HOSTX) | $(GREP) -i -c -E 'x86_64|amd64')
179 IS_ARM32 := $(shell echo $(HOSTX) | $(GREP) -v 64 | $(GREP) -i -c -E 'arm|armhf|arm7l|eabihf')
180 IS_ARMV8 := $(shell echo $(HOSTX) | $(GREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
190# Uncomment for debugging
191# $(info Here's what we found... IS_X86: $(IS_X86), IS_X64: $(IS_X64), IS_ARM32: $(IS_ARM32), IS_ARMV8: $(IS_ARMV8))
193###########################################################
194##### Test Program #####
195###########################################################
197# Hack to skip CPU feature tests for some recipes
199ifneq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CPPFLAGS)$(CXXFLAGS)h),)
201else ifneq ($(findstring clean,$(MAKECMDGOALS)),)
203else ifneq ($(findstring distclean,$(MAKECMDGOALS)),)
205else ifneq ($(findstring trim,$(MAKECMDGOALS)),)
207else ifneq ($(findstring zip,$(MAKECMDGOALS)),)
211# Strip out -Wall, -Wextra and friends for feature testing. FORTIFY_SOURCE is removed
212# because it requires -O1 or higher, but we use -O0 to tame the optimizer.
213# Always print testing flags since some tests always happen, like 64-bit.
214TCXXFLAGS := $(filter-out -D_FORTIFY_SOURCE=% -M -MM -Wall -Wextra -Werror% -Wunused -Wconversion -Wp%, $(CPPFLAGS) $(CXXFLAGS))
215ifneq ($(strip $(TCXXFLAGS)),)
216 $(info Using testing flags: $(TCXXFLAGS))
219# TCOMMAND is used for just about all tests. Make will lazy-evaluate
220# the variables when executed by $(shell $(TCOMMAND) ...).
221TCOMMAND = $(CXX) -I. $(TCXXFLAGS) $(TEXTRA) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT)
223###########################################################
224##### X86/X32/X64 Options #####
225###########################################################
227ifneq ($(IS_X86)$(IS_X64),00)
228ifeq ($(DETECT_FEATURES),1)
233 SSE41_FLAG = -msse4.1
234 SSE42_FLAG = -msse4.2
235 CLMUL_FLAG = -mpclmul
241 TPROG = TestPrograms/test_x86_sse2.cpp
243 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
244 ifeq ($(strip $(HAVE_OPT)),0)
245 CHACHA_FLAG = $(SSE2_FLAG)
247 # Make does not have useful debugging facilities. Show the user
248 # what happened by compiling again without the pipe.
249 $(info Running make again to see what failed)
250 $(info $(shell $(TCOMMAND)))
255 CPPFLAGS += -DCRYPTOPP_DISABLE_ASM
258 # Need SSE2 or higher for these tests
259 ifneq ($(SSE2_FLAG),)
261 TPROG = TestPrograms/test_x86_sse3.cpp
263 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
264 ifneq ($(strip $(HAVE_OPT)),0)
268 TPROG = TestPrograms/test_x86_ssse3.cpp
270 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
271 ifeq ($(strip $(HAVE_OPT)),0)
272 ARIA_FLAG = $(SSSE3_FLAG)
273 CHAM_FLAG = $(SSSE3_FLAG)
274 KECCAK_FLAG = $(SSSE3_FLAG)
275 LEA_FLAG = $(SSSE3_FLAG)
276 LSH256_FLAG = $(SSSE3_FLAG)
277 LSH512_FLAG = $(SSSE3_FLAG)
278 SIMON128_FLAG = $(SSSE3_FLAG)
279 SPECK128_FLAG = $(SSSE3_FLAG)
284 # The first Apple MacBooks were Core2's with SSE4.1
285 ifneq ($(IS_DARWIN),0)
286 # Add SSE2 algo's here as required
287 # They get a free upgrade
290 TPROG = TestPrograms/test_x86_sse41.cpp
292 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
293 ifeq ($(strip $(HAVE_OPT)),0)
294 BLAKE2B_FLAG = $(SSE41_FLAG)
295 BLAKE2S_FLAG = $(SSE41_FLAG)
300 TPROG = TestPrograms/test_x86_sse42.cpp
302 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
303 ifeq ($(strip $(HAVE_OPT)),0)
304 CRC_FLAG = $(SSE42_FLAG)
309 TPROG = TestPrograms/test_x86_clmul.cpp
311 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
312 ifeq ($(strip $(HAVE_OPT)),0)
313 GCM_FLAG = $(SSSE3_FLAG) $(CLMUL_FLAG)
314 GF2N_FLAG = $(CLMUL_FLAG)
319 TPROG = TestPrograms/test_x86_aes.cpp
321 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
322 ifeq ($(strip $(HAVE_OPT)),0)
323 AES_FLAG = $(SSE41_FLAG) $(AESNI_FLAG)
324 SM4_FLAG = $(SSSE3_FLAG) $(AESNI_FLAG)
329 TPROG = TestPrograms/test_x86_avx.cpp
331 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
332 ifeq ($(strip $(HAVE_OPT)),0)
333 # XXX_FLAG = $(AVX_FLAG)
338 TPROG = TestPrograms/test_x86_avx2.cpp
340 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
341 ifeq ($(strip $(HAVE_OPT)),0)
342 CHACHA_AVX2_FLAG = $(AVX2_FLAG)
343 LSH256_AVX2_FLAG = $(AVX2_FLAG)
344 LSH512_AVX2_FLAG = $(AVX2_FLAG)
349 TPROG = TestPrograms/test_x86_sha.cpp
351 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
352 ifeq ($(strip $(HAVE_OPT)),0)
353 SHA_FLAG = $(SSE42_FLAG) $(SHANI_FLAG)
359 CPPFLAGS += -DCRYPTOPP_DISABLE_SSE3
360 else ifeq ($(SSSE3_FLAG),)
361 CPPFLAGS += -DCRYPTOPP_DISABLE_SSSE3
362 else ifeq ($(SSE41_FLAG),)
363 CPPFLAGS += -DCRYPTOPP_DISABLE_SSE4
364 else ifeq ($(SSE42_FLAG),)
365 CPPFLAGS += -DCRYPTOPP_DISABLE_SSE4
368 ifneq ($(SSE42_FLAG),)
369 # Unusual GCC/Clang on Macports. It assembles AES, but not CLMUL.
370 # test_x86_clmul.s:15: no such instruction: 'pclmulqdq $0, %xmm1,%xmm0'
371 ifeq ($(CLMUL_FLAG),)
372 CPPFLAGS += -DCRYPTOPP_DISABLE_CLMUL
374 ifeq ($(AESNI_FLAG),)
375 CPPFLAGS += -DCRYPTOPP_DISABLE_AESNI
379 CPPFLAGS += -DCRYPTOPP_DISABLE_AVX
380 else ifeq ($(AVX2_FLAG),)
381 CPPFLAGS += -DCRYPTOPP_DISABLE_AVX2
383 # SHANI independent of AVX per GH #1045
384 ifeq ($(SHANI_FLAG),)
385 CPPFLAGS += -DCRYPTOPP_DISABLE_SHANI
389 # Drop to SSE2 if available
391 GCM_FLAG = $(SSE2_FLAG)
394 # Most Clang cannot handle mixed asm with positional arguments, where the
395 # body is Intel style with no prefix and the templates are AT&T style.
396 # Also see https://bugs.llvm.org/show_bug.cgi?id=39895 .
398 # CRYPTOPP_DISABLE_MIXED_ASM is now being added in config_asm.h for all
399 # Clang compilers. This test will need to be re-enabled if Clang fixes it.
400 #TPROG = TestPrograms/test_asm_mixed.cpp
402 #HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
403 #ifneq ($(strip $(HAVE_OPT)),0)
404 # CPPFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM
416###########################################################
417##### ARM A-32 and NEON #####
418###########################################################
422# No need for feature detection on this platform if NEON is disabled
423ifneq ($(findstring -DCRYPTOPP_DISABLE_ARM_NEON,$(CPPFLAGS)$(CXXFLAGS)),)
427ifeq ($(DETECT_FEATURES),1)
429 # Android needs -c compile flag for NEON. Otherwise there's an odd linker message.
430 ifeq ($(IS_ANDROID),1)
431 NEON_FLAG = -march=armv7-a -mfpu=vfpv3-d16 -mfpu=neon
433 NEON_FLAG = -march=armv7-a -mfpu=neon
436 # Clang needs an option to include <arm_neon.h>
437 TPROG = TestPrograms/test_arm_neon_header.cpp
438 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1 $(NEON_FLAG)
439 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
440 ifeq ($(strip $(HAVE_OPT)),0)
441 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
444 TPROG = TestPrograms/test_arm_neon.cpp
446 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
447 ifeq ($(strip $(HAVE_OPT)),0)
448 ARIA_FLAG = $(NEON_FLAG)
449 AES_FLAG = $(NEON_FLAG)
450 CRC_FLAG = $(NEON_FLAG)
451 GCM_FLAG = $(NEON_FLAG)
452 BLAKE2B_FLAG = $(NEON_FLAG)
453 BLAKE2S_FLAG = $(NEON_FLAG)
454 CHACHA_FLAG = $(NEON_FLAG)
455 CHAM_FLAG = $(NEON_FLAG)
456 LEA_FLAG = $(NEON_FLAG)
457 SHA_FLAG = $(NEON_FLAG)
458 SIMON128_FLAG = $(NEON_FLAG)
459 SPECK128_FLAG = $(NEON_FLAG)
460 SM4_FLAG = $(NEON_FLAG)
462 # Make does not have useful debugging facilities. Show the user
463 # what happened by compiling again without the pipe.
464 #$(info Running make again to see what failed)
465 #$(info $(shell $(TCOMMAND)))
470 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_NEON
478###########################################################
479##### Aach32 and Aarch64 #####
480###########################################################
483ifeq ($(DETECT_FEATURES),1)
486 ASIMD_FLAG = -arch arm64
487 CRC_FLAG = -arch arm64
488 AES_FLAG = -arch arm64
489 PMUL_FLAG = -arch arm64
490 SHA_FLAG = -arch arm64
492 ASIMD_FLAG = -march=armv8-a
493 CRC_FLAG = -march=armv8-a+crc
494 AES_FLAG = -march=armv8-a+crypto
495 GCM_FLAG = -march=armv8-a+crypto
496 GF2N_FLAG = -march=armv8-a+crypto
497 SHA_FLAG = -march=armv8-a+crypto
500 TPROG = TestPrograms/test_arm_neon_header.cpp
501 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1
502 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
503 ifeq ($(strip $(HAVE_OPT)),0)
504 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
507 TPROG = TestPrograms/test_arm_acle_header.cpp
508 TOPT = -DCRYPTOPP_ARM_ACLE_HEADER=1 $(ASIMD_FLAG)
509 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
510 ifeq ($(strip $(HAVE_OPT)),0)
511 TEXTRA += -DCRYPTOPP_ARM_ACLE_HEADER=1
514 TPROG = TestPrograms/test_arm_asimd.cpp
516 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
517 ifeq ($(strip $(HAVE_OPT)),0)
518 ARIA_FLAG = $(ASIMD_FLAG)
519 BLAKE2B_FLAG = $(ASIMD_FLAG)
520 BLAKE2S_FLAG = $(ASIMD_FLAG)
521 CHACHA_FLAG = $(ASIMD_FLAG)
522 CHAM_FLAG = $(ASIMD_FLAG)
523 LEA_FLAG = $(ASIMD_FLAG)
524 NEON_FLAG = $(ASIMD_FLAG)
525 SIMON128_FLAG = $(ASIMD_FLAG)
526 SPECK128_FLAG = $(ASIMD_FLAG)
527 SM4_FLAG = $(ASIMD_FLAG)
529 # Make does not have useful debugging facilities. Show the user
530 # what happened by compiling again without the pipe.
531 $(info Running make again to see what failed)
532 $(info $(shell $(TCOMMAND)))
536 ifeq ($(ASIMD_FLAG),)
537 CPPFLAGS += -DCRYPTOPP_DISABLE_ASM
540 ifneq ($(ASIMD_FLAG),)
542 TPROG = TestPrograms/test_arm_crc.cpp
544 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
545 ifneq ($(strip $(HAVE_OPT)),0)
547 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_CRC32
550 TPROG = TestPrograms/test_arm_aes.cpp
552 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
553 ifneq ($(strip $(HAVE_OPT)),0)
555 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_AES
558 TPROG = TestPrograms/test_arm_pmull.cpp
560 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
561 ifneq ($(strip $(HAVE_OPT)),0)
564 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_PMULL
567 TPROG = TestPrograms/test_arm_sha1.cpp
569 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
570 ifneq ($(strip $(HAVE_OPT)),0)
572 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA1
575 TPROG = TestPrograms/test_arm_sha256.cpp
577 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
578 ifneq ($(strip $(HAVE_OPT)),0)
580 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA2
583 TPROG = TestPrograms/test_arm_sm3.cpp
584 TOPT = -march=armv8.4-a+sm3
585 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
586 ifeq ($(strip $(HAVE_OPT)),0)
587 SM3_FLAG = -march=armv8.4-a+sm3
588 SM4_FLAG = -march=armv8.4-a+sm3
590 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SM3
591 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SM4
594 TPROG = TestPrograms/test_arm_sha3.cpp
595 TOPT = -march=armv8.4-a+sha3
596 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
597 ifeq ($(strip $(HAVE_OPT)),0)
598 SHA3_FLAG = -march=armv8.4-a+sha3
600 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA3
603 TPROG = TestPrograms/test_arm_sha512.cpp
604 TOPT = -march=armv8.4-a+sha512
605 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
606 ifeq ($(strip $(HAVE_OPT)),0)
607 SHA512_FLAG = -march=armv8.4-a+sha512
609 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA512
620###########################################################
622###########################################################
624# Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
625ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
626 ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
627 CXXFLAGS += -fsanitize=undefined
629 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CPPFLAGS)$(CXXFLAGS)),)
630 CPPFLAGS += -DCRYPTOPP_COVERAGE
634# Address Sanitizer (Asan) testing. Issue 'make asan'.
635ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
636 ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
637 CXXFLAGS += -fsanitize=address
639 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CPPFLAGS)$(CXXFLAGS)),)
640 CPPFLAGS += -DCRYPTOPP_COVERAGE
642 ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
643 CXXFLAGS += -fno-omit-frame-pointer
647# LD gold linker testing. Triggered by 'LD=ld.gold'.
648ifeq ($(findstring ld.gold,$(LD)),ld.gold)
649 ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
650 ELF_FORMAT := $(shell file `which ld.gold` 2>&1 | cut -d":" -f 2 | $(GREP) -i -c "elf")
651 ifneq ($(ELF_FORMAT),0)
652 LDFLAGS += -fuse-ld=gold
657# Valgrind testing. Issue 'make valgrind'.
658ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
659 # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
660 CXXFLAGS := $(CXXFLAGS:-g%=-g3)
661 CXXFLAGS := $(CXXFLAGS:-O%=-O1)
662 CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
663 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CPPFLAGS)$(CXXFLAGS)),)
664 CPPFLAGS += -DCRYPTOPP_COVERAGE
668# Debug testing on GNU systems. Triggered by -DDEBUG.
669# Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
670ifneq ($(filter -DDEBUG -DDEBUG=1,$(CPPFLAGS) $(CXXFLAGS)),)
671 USING_GLIBCXX := $(shell $(CXX) $(CPPFLAGS) $(CXXFLAGS) -E pch.cpp 2>&1 | $(GREP) -i -c "__GLIBCXX__")
672 ifneq ($(USING_GLIBCXX),0)
673 ifeq ($(HAS_NEWLIB),0)
674 ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CPPFLAGS)$(CXXFLAGS)),)
675 CPPFLAGS += -D_GLIBCXX_DEBUG
678 endif # USING_GLIBCXX
679endif # GNU Debug build
681# Dead code stripping. Issue 'make lean'.
682ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
683 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
684 CXXFLAGS += -ffunction-sections
686 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
687 CXXFLAGS += -fdata-sections
690 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
691 LDFLAGS += -Wl,-dead_strip
693 else # BSD, Linux and Unix
694 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
695 LDFLAGS += -Wl,--gc-sections
698endif # Dead code stripping
700###########################################################
701##### Source and object files #####
702###########################################################
704# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
705SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp,$(sort $(wildcard *.cpp)))
706# For Makefile.am; resource.h is Windows
707INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
709# Cryptogams source files. We couple to ARMv7 and NEON.
710# Limit to Linux. The source files target the GNU assembler.
711# Also see https://www.cryptopp.com/wiki/Cryptogams.
712ifeq ($(IS_ARM32)$(IS_LINUX),11)
713 ifeq ($(filter -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_ARM_NEON,$(CPPFLAGS)$(CXXFLAGS)),)
714 # Do not use -march=armv7 if the compiler is already targeting the ISA.
715 # Also see https://github.com/weidai11/cryptopp/issues/1094
716 ifeq ($(shell $(CXX) -dM -E TestPrograms/test_cxx.cpp 2>/dev/null | grep -E '__ARM_ARCH 7|__ARM_ARCH_7A__'),)
717 CRYPTOGAMS_ARMV7_FLAG = -march=armv7-a
719 ifeq ($(CLANG_COMPILER),1)
720 CRYPTOGAMS_ARM_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
721 CRYPTOGAMS_ARM_THUMB_FLAG = $(CRYPTOGAMS_ARMV7_FLAG) -mthumb
723 # -mfpu=auto due to https://github.com/weidai11/cryptopp/issues/1094
724 CRYPTOGAMS_ARM_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
725 CRYPTOGAMS_ARM_THUMB_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
727 SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S sha512_armv4.S
731# Remove unneeded arch specific files to speed build time.
732ifeq ($(IS_PPC32)$(IS_PPC64),00)
733 SRCS := $(filter-out %_ppc.cpp,$(SRCS))
735ifeq ($(IS_ARM32)$(IS_ARMV8),00)
736 SRCS := $(filter-out arm_%,$(SRCS))
737 SRCS := $(filter-out neon_%,$(SRCS))
738 SRCS := $(filter-out %_armv4.S,$(SRCS))
740ifeq ($(IS_X86)$(IS_X64),00)
741 SRCS := $(filter-out sse_%,$(SRCS))
742 SRCS := $(filter-out %_sse.cpp,$(SRCS))
743 SRCS := $(filter-out %_avx.cpp,$(SRCS))
746# If ASM is disabled we can remove the SIMD files, too.
747ifneq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
748 SRCS := $(filter-out arm_%,$(SRCS))
749 SRCS := $(filter-out ppc_%,$(SRCS))
750 SRCS := $(filter-out neon_%,$(SRCS))
751 SRCS := $(filter-out sse_%,$(SRCS))
752 SRCS := $(filter-out %_sse.cpp,$(SRCS))
753 SRCS := $(filter-out %_avx.cpp,$(SRCS))
754 SRCS := $(filter-out %_ppc.cpp,$(SRCS))
755 SRCS := $(filter-out %_simd.cpp,$(SRCS))
756 SRCS := $(filter-out %_armv4.S,$(SRCS))
759# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
760OBJS := $(SRCS:.cpp=.o)
763# List test.cpp first to tame C++ static initialization problems.
764TESTSRCS := 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
765TESTINCL := bench.h factory.h validate.h
768TESTOBJS := $(TESTSRCS:.cpp=.o)
769LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
771# Clean recipe, Issue 998. Don't filter-out some artifacts from the list of objects
772# The *.S is a hack. It makes the ASM appear like C++ so the object files make the CLEAN_OBJS list
773CLEAN_SRCS := $(wildcard *.cpp) $(patsubst %.S,%.cpp,$(wildcard *.S))
774CLEAN_OBJS := $(CLEAN_SRCS:.cpp=.o) $(CLEAN_SRCS:.cpp=.import.o) $(CLEAN_SRCS:.cpp=.export.o)
776# For Shared Objects, Diff, Dist/Zip rules
777LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config_ver.h | cut -d" " -f 3)
778LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
779LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
780LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
782ifeq ($(strip $(LIB_PATCH)),)
786ifeq ($(HAS_SOLIB_VERSION),1)
787# Full version suffix for shared library
788SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
789# Different patchlevels and minors are compatible since 6.1
790SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
791SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
792endif # HAS_SOLIB_VERSION
794###########################################################
795##### Targets and Recipes #####
796###########################################################
798# Default builds program with static library only
802.PHONY: all static dynamic
803all: static dynamic cryptest.exe
807shared dynamic dylib: libcryptopp.dylib
810shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
814test check: cryptest.exe
817# CXXFLAGS are tuned earlier. Applications must use linker flags
818# -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
820lean: static dynamic cryptest.exe
824 -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(CLEAN_OBJS) $(ANDROID_CPU_OBJ) rdrand-*.o
825 @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
826 @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
827 @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.dat ct et
828 @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
829 @-$(RM) /tmp/adhoc.exe
830 @-$(RM) -r /tmp/cryptopp_test/
831 @-$(RM) -r *.exe.dSYM/
832 @-$(RM) -r *.dylib.dSYM/
835.PHONY: autotools-clean
837 @-$(RM) -f bootstrap.sh configure.ac configure configure.in Makefile.am Makefile.in Makefile
838 @-$(RM) -f config.guess config.status config.sub config.h.in compile depcomp
839 @-$(RM) -f install-sh stamp-h1 ar-lib *.lo *.la *.m4 local.* lt*.sh missing
840 @-$(RM) -f cryptest cryptestcwd libtool* libcryptopp.la libcryptopp.pc*
841 @-$(RM) -rf build-aux/ m4/ auto*.cache/ .deps/ .libs/
845 @-$(RM) -f $(patsubst %_simd.cpp,%_simd.cpp.neon,$(wildcard *_simd.cpp))
849distclean: clean autotools-clean android-clean
850 -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt
851 -$(RM) cryptest_all.info cryptest_debug.info cryptest_noasm.info cryptest_base.info cryptest.info cryptest_release.info
852 @-$(RM) cryptest-*.txt cryptopp.tgz libcryptopp.pc *.o *.bc *.ii *~
853 @-$(RM) -r cryptlib.lib cryptest.exe *.suo *.sdf *.pdb Win32/ x64/ ipch/
854 @-$(RM) -r $(LIBOBJS:.o=.obj) $(TESTOBJS:.o=.obj)
855 @-$(RM) -r $(LIBOBJS:.o=.lst) $(TESTOBJS:.o=.lst)
856 @-$(RM) -r TestCoverage/ ref*/
857 @-$(RM) cryptopp$(LIB_VER)\.* CryptoPPRef.zip
859# Install cryptest.exe, libcryptopp.a and libcryptopp.so.
860# The library install was broken-out into its own recipe at GH #653.
862install: cryptest.exe install-lib
863 @-$(MKDIR) $(DESTDIR)$(BINDIR)
864 $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
865 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(BINDIR)/cryptest.exe
866 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestData
867 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
868 $(CP) TestData/*.dat $(DESTDIR)$(DATADIR)/cryptopp/TestData
869 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/cryptopp/TestData/*.dat
870 $(CP) TestVectors/*.txt $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
871 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
873# A recipe to install only the library, and not cryptest.exe. Also
874# see https://github.com/weidai11/cryptopp/issues/653.
877 @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
878 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
879 $(CHMOD) u=rw,go=r $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
880ifneq ($(wildcard libcryptopp.a),)
881 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
882 $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
883 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/libcryptopp.a
885ifneq ($(wildcard libcryptopp.dylib),)
886 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
887 $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
888 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
889 -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
891ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
892 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
893 $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
894 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
895ifeq ($(HAS_SOLIB_VERSION),1)
896 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
897 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
898 $(LDCONF) $(DESTDIR)$(LIBDIR)
901ifneq ($(wildcard libcryptopp.pc),)
902 @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
903 $(CP) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig
904 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
907.PHONY: remove uninstall
909 -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
910 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
911 -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
912 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
913 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
914 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
915 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
917libcryptopp.a: $(LIBOBJS) $(ANDROID_CPU_OBJ)
918 $(AR) $(ARFLAGS) $@ $(LIBOBJS) $(ANDROID_CPU_OBJ)
921ifeq ($(HAS_SOLIB_VERSION),1)
922.PHONY: libcryptopp.so
923libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
926libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS) $(ANDROID_CPU_OBJ)
927 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) -Wl,--exclude-libs,ALL $(LIBOBJS) $(ANDROID_CPU_OBJ) $(LDFLAGS) $(LDLIBS)
928ifeq ($(HAS_SOLIB_VERSION),1)
929 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
930 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
933libcryptopp.dylib: $(LIBOBJS)
934 $(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)
936cryptest.exe: $(LINK_LIBRARY) $(TESTOBJS)
937 $(CXX) -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) $(TESTOBJS) $(LINK_LIBRARY_PATH)$(LINK_LIBRARY) $(LDFLAGS) $(LDLIBS)
939# Used to generate list of source files for Autotools, CMakeList and Android.mk
942 $(info ***** Library sources *****)
943 $(info $(filter-out $(TESTSRCS),$(SRCS)))
945 $(info ***** Library headers *****)
946 $(info $(filter-out $(TESTINCL),$(INCL)))
948 $(info ***** Test sources *****)
951 $(info ***** Test headers *****)
954adhoc.cpp: adhoc.cpp.proto
955ifeq ($(wildcard adhoc.cpp),)
956 cp adhoc.cpp.proto adhoc.cpp
961# Include dependencies, if present. You must issue `make deps` to create them.
962ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
963-include GNUmakefile.deps
966# A few recipes trigger warnings for -std=c++11 and -stdlib=c++
967NOSTD_CXXFLAGS=$(filter-out -stdlib=%,$(filter-out -std=%,$(CXXFLAGS)))
969# Cryptogams ARM asm implementation. AES needs -mthumb for Clang
970aes_armv4.o : aes_armv4.S
971 $(CXX) $(strip $(CPPFLAGS) $(ASFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARM_THUMB_FLAG) -c) $<
973# Use C++ compiler on C source after patching.
974# https://github.com/weidai11/cryptopp/issues/926
975cpu-features.o: cpu-features.h cpu-features.c
976 $(CXX) -x c $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) -c) cpu-features.c
978# SSE, NEON or POWER7 available
979blake2s_simd.o : blake2s_simd.cpp
980 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
982# SSE, NEON or POWER8 available
983blake2b_simd.o : blake2b_simd.cpp
984 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
986# SSE2 or NEON available
987chacha_simd.o : chacha_simd.cpp
988 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
991chacha_avx.o : chacha_avx.cpp
992 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
995cham_simd.o : cham_simd.cpp
996 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHAM_FLAG) -c) $<
999donna_sse.o : donna_sse.cpp
1000 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1003sse_simd.o : sse_simd.cpp
1004 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1006# SSE4.2 or ARMv8a available
1007crc_simd.o : crc_simd.cpp
1008 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CRC_FLAG) -c) $<
1010# PCLMUL or ARMv7a/ARMv8a available
1011gcm_simd.o : gcm_simd.cpp
1012 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GCM_FLAG) -c) $<
1015gf2n_simd.o : gf2n_simd.cpp
1016 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GF2N_FLAG) -c) $<
1019keccak_simd.o : keccak_simd.cpp
1020 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(KECCAK_FLAG) -c) $<
1023lea_simd.o : lea_simd.cpp
1024 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LEA_FLAG) -c) $<
1027lsh256_sse.o : lsh256_sse.cpp
1028 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_FLAG) -c) $<
1031lsh256_avx.o : lsh256_avx.cpp
1032 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_AVX2_FLAG) -c) $<
1035lsh512_sse.o : lsh512_sse.cpp
1036 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_FLAG) -c) $<
1039lsh512_avx.o : lsh512_avx.cpp
1040 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_AVX2_FLAG) -c) $<
1043neon_simd.o : neon_simd.cpp
1044 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(NEON_FLAG) -c) $<
1046# AESNI or ARMv7a/ARMv8a available
1047rijndael_simd.o : rijndael_simd.cpp
1048 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(AES_FLAG) -c) $<
1050# SSE4.2/SHA-NI or ARMv8a available
1051sha_simd.o : sha_simd.cpp
1052 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1054# Cryptogams SHA1/SHA256/SHA512 asm implementation.
1055sha%_armv4.o : sha%_armv4.S
1056 $(CXX) $(strip $(CPPFLAGS) $(ASFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARM_FLAG) -c) $<
1058# SSE4.2/SHA-NI or ARMv8a available
1059shacal2_simd.o : shacal2_simd.cpp
1060 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1062# SSSE3, NEON or POWER8 available
1063simon128_simd.o : simon128_simd.cpp
1064 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
1066# SSSE3, NEON or POWER8 available
1067speck128_simd.o : speck128_simd.cpp
1068 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
1071sm3_simd.o : sm3_simd.cpp
1072 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM3_FLAG) -c) $<
1075sm4_simd.o : sm4_simd.cpp
1076 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM4_FLAG) -c) $<
1079 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) -c) $<
1081.PHONY: dep deps depend
1082dep deps depend GNUmakefile.deps:
1083 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS)) -MM *.cpp > GNUmakefile.deps