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),)
260 TPROG = TestPrograms/test_x86_ssse3.cpp
262 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
263 ifeq ($(strip $(HAVE_OPT)),0)
264 ARIA_FLAG = $(SSSE3_FLAG)
265 CHAM_FLAG = $(SSSE3_FLAG)
266 KECCAK_FLAG = $(SSSE3_FLAG)
267 LEA_FLAG = $(SSSE3_FLAG)
268 LSH256_FLAG = $(SSSE3_FLAG)
269 LSH512_FLAG = $(SSSE3_FLAG)
270 SIMON128_FLAG = $(SSSE3_FLAG)
271 SPECK128_FLAG = $(SSSE3_FLAG)
276 # The first Apple MacBooks were Core2's with SSE4.1
277 ifneq ($(IS_DARWIN),0)
278 # Add SSE2 algo's here as required
279 # They get a free upgrade
282 TPROG = TestPrograms/test_x86_sse41.cpp
284 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
285 ifeq ($(strip $(HAVE_OPT)),0)
286 BLAKE2B_FLAG = $(SSE41_FLAG)
287 BLAKE2S_FLAG = $(SSE41_FLAG)
292 TPROG = TestPrograms/test_x86_sse42.cpp
294 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
295 ifeq ($(strip $(HAVE_OPT)),0)
296 CRC_FLAG = $(SSE42_FLAG)
301 TPROG = TestPrograms/test_x86_clmul.cpp
303 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
304 ifeq ($(strip $(HAVE_OPT)),0)
305 GCM_FLAG = $(SSSE3_FLAG) $(CLMUL_FLAG)
306 GF2N_FLAG = $(CLMUL_FLAG)
311 TPROG = TestPrograms/test_x86_aes.cpp
313 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
314 ifeq ($(strip $(HAVE_OPT)),0)
315 AES_FLAG = $(SSE41_FLAG) $(AESNI_FLAG)
316 SM4_FLAG = $(SSSE3_FLAG) $(AESNI_FLAG)
321 TPROG = TestPrograms/test_x86_avx.cpp
323 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
324 ifeq ($(strip $(HAVE_OPT)),0)
325 # XXX_FLAG = $(AVX_FLAG)
330 TPROG = TestPrograms/test_x86_avx2.cpp
332 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
333 ifeq ($(strip $(HAVE_OPT)),0)
334 CHACHA_AVX2_FLAG = $(AVX2_FLAG)
335 LSH256_AVX2_FLAG = $(AVX2_FLAG)
336 LSH512_AVX2_FLAG = $(AVX2_FLAG)
341 TPROG = TestPrograms/test_x86_sha.cpp
343 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
344 ifeq ($(strip $(HAVE_OPT)),0)
345 SHA_FLAG = $(SSE42_FLAG) $(SHANI_FLAG)
351 CPPFLAGS += -DCRYPTOPP_DISABLE_SSE3
352 else ifeq ($(SSSE3_FLAG),)
353 CPPFLAGS += -DCRYPTOPP_DISABLE_SSSE3
354 else ifeq ($(SSE41_FLAG),)
355 CPPFLAGS += -DCRYPTOPP_DISABLE_SSE4
356 else ifeq ($(SSE42_FLAG),)
357 CPPFLAGS += -DCRYPTOPP_DISABLE_SSE4
360 ifneq ($(SSE42_FLAG),)
361 # Unusual GCC/Clang on Macports. It assembles AES, but not CLMUL.
362 # test_x86_clmul.s:15: no such instruction: 'pclmulqdq $0, %xmm1,%xmm0'
363 ifeq ($(CLMUL_FLAG),)
364 CPPFLAGS += -DCRYPTOPP_DISABLE_CLMUL
366 ifeq ($(AESNI_FLAG),)
367 CPPFLAGS += -DCRYPTOPP_DISABLE_AESNI
371 CPPFLAGS += -DCRYPTOPP_DISABLE_AVX
372 else ifeq ($(AVX2_FLAG),)
373 CPPFLAGS += -DCRYPTOPP_DISABLE_AVX2
375 # SHANI independent of AVX per GH #1045
376 ifeq ($(SHANI_FLAG),)
377 CPPFLAGS += -DCRYPTOPP_DISABLE_SHANI
381 # Drop to SSE2 if available
383 GCM_FLAG = $(SSE2_FLAG)
386 # Most Clang cannot handle mixed asm with positional arguments, where the
387 # body is Intel style with no prefix and the templates are AT&T style.
388 # Also see https://bugs.llvm.org/show_bug.cgi?id=39895 .
390 # CRYPTOPP_DISABLE_MIXED_ASM is now being added in config_asm.h for all
391 # Clang compilers. This test will need to be re-enabled if Clang fixes it.
392 #TPROG = TestPrograms/test_asm_mixed.cpp
394 #HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
395 #ifneq ($(strip $(HAVE_OPT)),0)
396 # CPPFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM
408###########################################################
409##### ARM A-32 and NEON #####
410###########################################################
414# No need for feature detection on this platform if NEON is disabled
415ifneq ($(findstring -DCRYPTOPP_DISABLE_ARM_NEON,$(CPPFLAGS)$(CXXFLAGS)),)
419ifeq ($(DETECT_FEATURES),1)
421 # Android needs -c compile flag for NEON. Otherwise there's an odd linker message.
422 ifeq ($(IS_ANDROID),1)
423 NEON_FLAG = -march=armv7-a -mfpu=vfpv3-d16 -mfpu=neon
425 NEON_FLAG = -march=armv7-a -mfpu=neon
428 # Clang needs an option to include <arm_neon.h>
429 TPROG = TestPrograms/test_arm_neon_header.cpp
430 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1 $(NEON_FLAG)
431 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
432 ifeq ($(strip $(HAVE_OPT)),0)
433 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
436 TPROG = TestPrograms/test_arm_neon.cpp
438 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
439 ifeq ($(strip $(HAVE_OPT)),0)
440 ARIA_FLAG = $(NEON_FLAG)
441 AES_FLAG = $(NEON_FLAG)
442 CRC_FLAG = $(NEON_FLAG)
443 GCM_FLAG = $(NEON_FLAG)
444 BLAKE2B_FLAG = $(NEON_FLAG)
445 BLAKE2S_FLAG = $(NEON_FLAG)
446 CHACHA_FLAG = $(NEON_FLAG)
447 CHAM_FLAG = $(NEON_FLAG)
448 LEA_FLAG = $(NEON_FLAG)
449 SHA_FLAG = $(NEON_FLAG)
450 SIMON128_FLAG = $(NEON_FLAG)
451 SPECK128_FLAG = $(NEON_FLAG)
452 SM4_FLAG = $(NEON_FLAG)
454 # Make does not have useful debugging facilities. Show the user
455 # what happened by compiling again without the pipe.
456 #$(info Running make again to see what failed)
457 #$(info $(shell $(TCOMMAND)))
462 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_NEON
470###########################################################
471##### Aach32 and Aarch64 #####
472###########################################################
475ifeq ($(DETECT_FEATURES),1)
478 ASIMD_FLAG = -arch arm64
479 CRC_FLAG = -arch arm64
480 AES_FLAG = -arch arm64
481 PMUL_FLAG = -arch arm64
482 SHA_FLAG = -arch arm64
484 ASIMD_FLAG = -march=armv8-a
485 CRC_FLAG = -march=armv8-a+crc
486 AES_FLAG = -march=armv8-a+crypto
487 GCM_FLAG = -march=armv8-a+crypto
488 GF2N_FLAG = -march=armv8-a+crypto
489 SHA_FLAG = -march=armv8-a+crypto
492 TPROG = TestPrograms/test_arm_neon_header.cpp
493 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1
494 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
495 ifeq ($(strip $(HAVE_OPT)),0)
496 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
499 TPROG = TestPrograms/test_arm_acle_header.cpp
500 TOPT = -DCRYPTOPP_ARM_ACLE_HEADER=1 $(ASIMD_FLAG)
501 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
502 ifeq ($(strip $(HAVE_OPT)),0)
503 TEXTRA += -DCRYPTOPP_ARM_ACLE_HEADER=1
506 TPROG = TestPrograms/test_arm_asimd.cpp
508 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
509 ifeq ($(strip $(HAVE_OPT)),0)
510 ARIA_FLAG = $(ASIMD_FLAG)
511 BLAKE2B_FLAG = $(ASIMD_FLAG)
512 BLAKE2S_FLAG = $(ASIMD_FLAG)
513 CHACHA_FLAG = $(ASIMD_FLAG)
514 CHAM_FLAG = $(ASIMD_FLAG)
515 LEA_FLAG = $(ASIMD_FLAG)
516 NEON_FLAG = $(ASIMD_FLAG)
517 SIMON128_FLAG = $(ASIMD_FLAG)
518 SPECK128_FLAG = $(ASIMD_FLAG)
519 SM4_FLAG = $(ASIMD_FLAG)
521 # Make does not have useful debugging facilities. Show the user
522 # what happened by compiling again without the pipe.
523 $(info Running make again to see what failed)
524 $(info $(shell $(TCOMMAND)))
528 ifeq ($(ASIMD_FLAG),)
529 CPPFLAGS += -DCRYPTOPP_DISABLE_ASM
532 ifneq ($(ASIMD_FLAG),)
534 TPROG = TestPrograms/test_arm_crc.cpp
536 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
537 ifneq ($(strip $(HAVE_OPT)),0)
539 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_CRC32
542 TPROG = TestPrograms/test_arm_aes.cpp
544 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
545 ifneq ($(strip $(HAVE_OPT)),0)
547 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_AES
550 TPROG = TestPrograms/test_arm_pmull.cpp
552 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
553 ifneq ($(strip $(HAVE_OPT)),0)
556 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_PMULL
559 TPROG = TestPrograms/test_arm_sha1.cpp
561 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
562 ifneq ($(strip $(HAVE_OPT)),0)
564 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA1
567 TPROG = TestPrograms/test_arm_sha256.cpp
569 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
570 ifneq ($(strip $(HAVE_OPT)),0)
572 CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA2
575 TPROG = TestPrograms/test_arm_sm3.cpp
576 TOPT = -march=armv8.4-a+sm3
577 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
578 ifeq ($(strip $(HAVE_OPT)),0)
579 SM3_FLAG = -march=armv8.4-a+sm3
580 SM4_FLAG = -march=armv8.4-a+sm3
582 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SM3
583 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SM4
586 TPROG = TestPrograms/test_arm_sha3.cpp
587 TOPT = -march=armv8.4-a+sha3
588 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
589 ifeq ($(strip $(HAVE_OPT)),0)
590 SHA3_FLAG = -march=armv8.4-a+sha3
592 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA3
595 TPROG = TestPrograms/test_arm_sha512.cpp
596 TOPT = -march=armv8.4-a+sha512
597 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
598 ifeq ($(strip $(HAVE_OPT)),0)
599 SHA512_FLAG = -march=armv8.4-a+sha512
601 #CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA512
612###########################################################
614###########################################################
616# Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
617ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
618 ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
619 CXXFLAGS += -fsanitize=undefined
621 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CPPFLAGS)$(CXXFLAGS)),)
622 CPPFLAGS += -DCRYPTOPP_COVERAGE
626# Address Sanitizer (Asan) testing. Issue 'make asan'.
627ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
628 ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
629 CXXFLAGS += -fsanitize=address
631 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CPPFLAGS)$(CXXFLAGS)),)
632 CPPFLAGS += -DCRYPTOPP_COVERAGE
634 ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
635 CXXFLAGS += -fno-omit-frame-pointer
639# LD gold linker testing. Triggered by 'LD=ld.gold'.
640ifeq ($(findstring ld.gold,$(LD)),ld.gold)
641 ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
642 ELF_FORMAT := $(shell file `which ld.gold` 2>&1 | cut -d":" -f 2 | $(GREP) -i -c "elf")
643 ifneq ($(ELF_FORMAT),0)
644 LDFLAGS += -fuse-ld=gold
649# Valgrind testing. Issue 'make valgrind'.
650ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
651 # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
652 CXXFLAGS := $(CXXFLAGS:-g%=-g3)
653 CXXFLAGS := $(CXXFLAGS:-O%=-O1)
654 CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
655 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CPPFLAGS)$(CXXFLAGS)),)
656 CPPFLAGS += -DCRYPTOPP_COVERAGE
660# Debug testing on GNU systems. Triggered by -DDEBUG.
661# Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
662ifneq ($(filter -DDEBUG -DDEBUG=1,$(CPPFLAGS) $(CXXFLAGS)),)
663 USING_GLIBCXX := $(shell $(CXX) $(CPPFLAGS) $(CXXFLAGS) -E pch.cpp 2>&1 | $(GREP) -i -c "__GLIBCXX__")
664 ifneq ($(USING_GLIBCXX),0)
665 ifeq ($(HAS_NEWLIB),0)
666 ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CPPFLAGS)$(CXXFLAGS)),)
667 CPPFLAGS += -D_GLIBCXX_DEBUG
670 endif # USING_GLIBCXX
671endif # GNU Debug build
673# Dead code stripping. Issue 'make lean'.
674ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
675 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
676 CXXFLAGS += -ffunction-sections
678 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
679 CXXFLAGS += -fdata-sections
682 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
683 LDFLAGS += -Wl,-dead_strip
685 else # BSD, Linux and Unix
686 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
687 LDFLAGS += -Wl,--gc-sections
690endif # Dead code stripping
692###########################################################
693##### Source and object files #####
694###########################################################
696# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
697SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp,$(sort $(wildcard *.cpp)))
698# For Makefile.am; resource.h is Windows
699INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
701# Cryptogams source files. We couple to ARMv7 and NEON.
702# Limit to Linux. The source files target the GNU assembler.
703# Also see https://www.cryptopp.com/wiki/Cryptogams.
704ifeq ($(IS_ARM32)$(IS_LINUX),11)
705 ifeq ($(filter -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_ARM_NEON,$(CPPFLAGS)$(CXXFLAGS)),)
706 # Do not use -march=armv7 if the compiler is already targeting the ISA.
707 # Also see https://github.com/weidai11/cryptopp/issues/1094
708 ifeq ($(shell $(CXX) -dM -E TestPrograms/test_cxx.cpp 2>/dev/null | grep -E '__ARM_ARCH 7|__ARM_ARCH_7A__'),)
709 CRYPTOGAMS_ARMV7_FLAG = -march=armv7-a
711 ifeq ($(CLANG_COMPILER),1)
712 CRYPTOGAMS_ARM_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
713 CRYPTOGAMS_ARM_THUMB_FLAG = $(CRYPTOGAMS_ARMV7_FLAG) -mthumb
715 # -mfpu=auto due to https://github.com/weidai11/cryptopp/issues/1094
716 CRYPTOGAMS_ARM_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
717 CRYPTOGAMS_ARM_THUMB_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
719 SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S sha512_armv4.S
723# Remove unneeded arch specific files to speed build time.
724ifeq ($(IS_PPC32)$(IS_PPC64),00)
725 SRCS := $(filter-out %_ppc.cpp,$(SRCS))
727ifeq ($(IS_ARM32)$(IS_ARMV8),00)
728 SRCS := $(filter-out arm_%,$(SRCS))
729 SRCS := $(filter-out neon_%,$(SRCS))
730 SRCS := $(filter-out %_armv4.S,$(SRCS))
732ifeq ($(IS_X86)$(IS_X64),00)
733 SRCS := $(filter-out sse_%,$(SRCS))
734 SRCS := $(filter-out %_sse.cpp,$(SRCS))
735 SRCS := $(filter-out %_avx.cpp,$(SRCS))
738# If ASM is disabled we can remove the SIMD files, too.
739ifneq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
740 SRCS := $(filter-out arm_%,$(SRCS))
741 SRCS := $(filter-out ppc_%,$(SRCS))
742 SRCS := $(filter-out neon_%,$(SRCS))
743 SRCS := $(filter-out sse_%,$(SRCS))
744 SRCS := $(filter-out %_sse.cpp,$(SRCS))
745 SRCS := $(filter-out %_avx.cpp,$(SRCS))
746 SRCS := $(filter-out %_ppc.cpp,$(SRCS))
747 SRCS := $(filter-out %_simd.cpp,$(SRCS))
748 SRCS := $(filter-out %_armv4.S,$(SRCS))
751# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
752OBJS := $(SRCS:.cpp=.o)
755# List test.cpp first to tame C++ static initialization problems.
756TESTSRCS := 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
757TESTINCL := bench.h factory.h validate.h
760TESTOBJS := $(TESTSRCS:.cpp=.o)
761LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
763# Clean recipe, Issue 998. Don't filter-out some artifacts from the list of objects
764# The *.S is a hack. It makes the ASM appear like C++ so the object files make the CLEAN_OBJS list
765CLEAN_SRCS := $(wildcard *.cpp) $(patsubst %.S,%.cpp,$(wildcard *.S))
766CLEAN_OBJS := $(CLEAN_SRCS:.cpp=.o) $(CLEAN_SRCS:.cpp=.import.o) $(CLEAN_SRCS:.cpp=.export.o)
768# For Shared Objects, Diff, Dist/Zip rules
769LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config_ver.h | cut -d" " -f 3)
770LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
771LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
772LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
774ifeq ($(strip $(LIB_PATCH)),)
778ifeq ($(HAS_SOLIB_VERSION),1)
779# Full version suffix for shared library
780SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
781# Different patchlevels and minors are compatible since 6.1
782SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
783SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
784endif # HAS_SOLIB_VERSION
786###########################################################
787##### Targets and Recipes #####
788###########################################################
790# Default builds program with static library only
794.PHONY: all static dynamic
795all: static dynamic cryptest.exe
799shared dynamic dylib: libcryptopp.dylib
802shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
806test check: cryptest.exe
809# CXXFLAGS are tuned earlier. Applications must use linker flags
810# -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
812lean: static dynamic cryptest.exe
816 -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(CLEAN_OBJS) $(ANDROID_CPU_OBJ) rdrand-*.o
817 @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
818 @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
819 @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.dat ct et
820 @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
821 @-$(RM) /tmp/adhoc.exe
822 @-$(RM) -r /tmp/cryptopp_test/
823 @-$(RM) -r *.exe.dSYM/
824 @-$(RM) -r *.dylib.dSYM/
827.PHONY: autotools-clean
829 @-$(RM) -f bootstrap.sh configure.ac configure configure.in Makefile.am Makefile.in Makefile
830 @-$(RM) -f config.guess config.status config.sub config.h.in compile depcomp
831 @-$(RM) -f install-sh stamp-h1 ar-lib *.lo *.la *.m4 local.* lt*.sh missing
832 @-$(RM) -f cryptest cryptestcwd libtool* libcryptopp.la libcryptopp.pc*
833 @-$(RM) -rf build-aux/ m4/ auto*.cache/ .deps/ .libs/
837 @-$(RM) -f $(patsubst %_simd.cpp,%_simd.cpp.neon,$(wildcard *_simd.cpp))
841distclean: clean autotools-clean android-clean
842 -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt
843 -$(RM) cryptest_all.info cryptest_debug.info cryptest_noasm.info cryptest_base.info cryptest.info cryptest_release.info
844 @-$(RM) cryptest-*.txt cryptopp.tgz libcryptopp.pc *.o *.bc *.ii *~
845 @-$(RM) -r cryptlib.lib cryptest.exe *.suo *.sdf *.pdb Win32/ x64/ ipch/
846 @-$(RM) -r $(LIBOBJS:.o=.obj) $(TESTOBJS:.o=.obj)
847 @-$(RM) -r $(LIBOBJS:.o=.lst) $(TESTOBJS:.o=.lst)
848 @-$(RM) -r TestCoverage/ ref*/
849 @-$(RM) cryptopp$(LIB_VER)\.* CryptoPPRef.zip
851# Install cryptest.exe, libcryptopp.a and libcryptopp.so.
852# The library install was broken-out into its own recipe at GH #653.
854install: cryptest.exe install-lib
855 @-$(MKDIR) $(DESTDIR)$(BINDIR)
856 $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
857 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(BINDIR)/cryptest.exe
858 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestData
859 @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
860 $(CP) TestData/*.dat $(DESTDIR)$(DATADIR)/cryptopp/TestData
861 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/cryptopp/TestData/*.dat
862 $(CP) TestVectors/*.txt $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
863 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
865# A recipe to install only the library, and not cryptest.exe. Also
866# see https://github.com/weidai11/cryptopp/issues/653.
869 @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
870 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
871 $(CHMOD) u=rw,go=r $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
872ifneq ($(wildcard libcryptopp.a),)
873 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
874 $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
875 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/libcryptopp.a
877ifneq ($(wildcard libcryptopp.dylib),)
878 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
879 $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
880 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
881 -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
883ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
884 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
885 $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
886 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
887ifeq ($(HAS_SOLIB_VERSION),1)
888 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
889 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
890 $(LDCONF) $(DESTDIR)$(LIBDIR)
893ifneq ($(wildcard libcryptopp.pc),)
894 @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
895 $(CP) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig
896 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
899.PHONY: remove uninstall
901 -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
902 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
903 -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
904 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
905 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
906 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
907 @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
909libcryptopp.a: $(LIBOBJS) $(ANDROID_CPU_OBJ)
910 $(AR) $(ARFLAGS) $@ $(LIBOBJS) $(ANDROID_CPU_OBJ)
913ifeq ($(HAS_SOLIB_VERSION),1)
914.PHONY: libcryptopp.so
915libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
918libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS) $(ANDROID_CPU_OBJ)
919 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) -Wl,--exclude-libs,ALL $(LIBOBJS) $(ANDROID_CPU_OBJ) $(LDFLAGS) $(LDLIBS)
920ifeq ($(HAS_SOLIB_VERSION),1)
921 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
922 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
925libcryptopp.dylib: $(LIBOBJS)
926 $(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)
928cryptest.exe: $(LINK_LIBRARY) $(TESTOBJS)
929 $(CXX) -o $@ $(strip $(CPPFLAGS) $(CXXFLAGS)) $(TESTOBJS) $(LINK_LIBRARY_PATH)$(LINK_LIBRARY) $(LDFLAGS) $(LDLIBS)
931# Used to generate list of source files for Autotools, CMakeList and Android.mk
934 $(info ***** Library sources *****)
935 $(info $(filter-out $(TESTSRCS),$(SRCS)))
937 $(info ***** Library headers *****)
938 $(info $(filter-out $(TESTINCL),$(INCL)))
940 $(info ***** Test sources *****)
943 $(info ***** Test headers *****)
946adhoc.cpp: adhoc.cpp.proto
947ifeq ($(wildcard adhoc.cpp),)
948 cp adhoc.cpp.proto adhoc.cpp
953# Include dependencies, if present. You must issue `make deps` to create them.
954ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
955-include GNUmakefile.deps
958# A few recipes trigger warnings for -std=c++11 and -stdlib=c++
959NOSTD_CXXFLAGS=$(filter-out -stdlib=%,$(filter-out -std=%,$(CXXFLAGS)))
961# Cryptogams ARM asm implementation. AES needs -mthumb for Clang
962aes_armv4.o : aes_armv4.S
963 $(CXX) $(strip $(CPPFLAGS) $(ASFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARM_THUMB_FLAG) -c) $<
965# Use C++ compiler on C source after patching.
966# https://github.com/weidai11/cryptopp/issues/926
967cpu-features.o: cpu-features.h cpu-features.c
968 $(CXX) -x c $(strip $(CPPFLAGS) $(NOSTD_CXXFLAGS) -c) cpu-features.c
970# SSSE3 or NEON available
971aria_simd.o : aria_simd.cpp
972 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(ARIA_FLAG) -c) $<
974# SSE, NEON or POWER7 available
975blake2s_simd.o : blake2s_simd.cpp
976 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
978# SSE, NEON or POWER8 available
979blake2b_simd.o : blake2b_simd.cpp
980 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
982# SSE2 or NEON available
983chacha_simd.o : chacha_simd.cpp
984 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
987chacha_avx.o : chacha_avx.cpp
988 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
991cham_simd.o : cham_simd.cpp
992 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHAM_FLAG) -c) $<
995donna_sse.o : donna_sse.cpp
996 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
999sse_simd.o : sse_simd.cpp
1000 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1002# SSE4.2 or ARMv8a available
1003crc_simd.o : crc_simd.cpp
1004 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CRC_FLAG) -c) $<
1006# PCLMUL or ARMv7a/ARMv8a available
1007gcm_simd.o : gcm_simd.cpp
1008 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GCM_FLAG) -c) $<
1011gf2n_simd.o : gf2n_simd.cpp
1012 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GF2N_FLAG) -c) $<
1015keccak_simd.o : keccak_simd.cpp
1016 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(KECCAK_FLAG) -c) $<
1019lea_simd.o : lea_simd.cpp
1020 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LEA_FLAG) -c) $<
1023lsh256_sse.o : lsh256_sse.cpp
1024 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_FLAG) -c) $<
1027lsh256_avx.o : lsh256_avx.cpp
1028 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_AVX2_FLAG) -c) $<
1031lsh512_sse.o : lsh512_sse.cpp
1032 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_FLAG) -c) $<
1035lsh512_avx.o : lsh512_avx.cpp
1036 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_AVX2_FLAG) -c) $<
1039neon_simd.o : neon_simd.cpp
1040 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(NEON_FLAG) -c) $<
1042# AESNI or ARMv7a/ARMv8a available
1043rijndael_simd.o : rijndael_simd.cpp
1044 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(AES_FLAG) -c) $<
1046# SSE4.2/SHA-NI or ARMv8a available
1047sha_simd.o : sha_simd.cpp
1048 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1050# Cryptogams SHA1/SHA256/SHA512 asm implementation.
1051sha%_armv4.o : sha%_armv4.S
1052 $(CXX) $(strip $(CPPFLAGS) $(ASFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARM_FLAG) -c) $<
1054# SSE4.2/SHA-NI or ARMv8a available
1055shacal2_simd.o : shacal2_simd.cpp
1056 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1058# SSSE3, NEON or POWER8 available
1059simon128_simd.o : simon128_simd.cpp
1060 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
1062# SSSE3, NEON or POWER8 available
1063speck128_simd.o : speck128_simd.cpp
1064 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
1067sm3_simd.o : sm3_simd.cpp
1068 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM3_FLAG) -c) $<
1071sm4_simd.o : sm4_simd.cpp
1072 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM4_FLAG) -c) $<
1075 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) -c) $<
1077.PHONY: dep deps depend
1078dep deps depend GNUmakefile.deps:
1079 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS)) -MM *.cpp > GNUmakefile.deps