1###########################################################
2##### System Attributes and Programs #####
3###########################################################
5# https://www.gnu.org/software/make/manual/make.html#Makefile-Conventions
6# and https://www.gnu.org/prep/standards/standards.html
12# Used for feature tests
14TOUT := $(strip $(TOUT))
16# Allow override for the cryptest recipe. Change to
17# ./libcrypto++.so or ./libcrypto++.dylib to suit your
18# taste. https://github.com/weidai11/crypto++/issues/866
19LINK_LIBRARY ?= libcrypto++.a
20LINK_LIBRARY_PATH ?= ./
22# Command and arguments
24ARFLAGS ?= -cr # ar needs the dash on OpenBSD
36LDCONF ?= /sbin/ldconfig -n
38# Solaris provides a non-Posix sed and grep at /usr/bin
39# Solaris 10 is missing AR in /usr/bin
40ifneq ($(wildcard /usr/xpg4/bin/grep),)
41 GREP := /usr/xpg4/bin/grep
43ifneq ($(wildcard /usr/xpg4/bin/sed),)
44 SED := /usr/xpg4/bin/sed
46ifneq ($(wildcard /usr/xpg4/bin/ar),)
47 AR := /usr/xpg4/bin/ar
50# Clang is reporting armv8l-unknown-linux-gnueabihf
51# for ARMv7 images on Aarch64 hardware.
52MACHINEX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
53HOSTX := $(shell echo $(MACHINEX) | cut -f 1 -d '-')
55 HOSTX := $(shell uname -m 2>/dev/null)
58IS_X86 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'i.86|x86|i86')
59IS_X64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E '_64|d64')
60IS_PPC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'ppc|power')
61IS_PPC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'ppc64|powerpc64|power64')
62IS_SPARC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'sun|sparc')
63IS_SPARC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'sun|sparc64')
64IS_ARM32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'arm|armhf|armv7|eabihf|armv8')
65IS_ARMV8 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'aarch32|aarch64|arm64')
67# Attempt to determine platform
68SYSTEMX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
70 SYSTEMX := $(shell uname -s 2>/dev/null)
73IS_LINUX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Linux")
74IS_HURD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c -E "GNU|Hurd")
75IS_MINGW := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "MinGW")
76IS_CYGWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Cygwin")
77IS_DARWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Darwin")
78IS_NETBSD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "NetBSD")
79IS_AIX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "aix")
80IS_SUN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c -E "SunOS|Solaris")
82SUN_COMPILER := $(shell $(CXX) -V 2>&1 | $(GREP) -i -c -E 'CC: (Sun|Studio)')
83GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -v -E '(llvm|clang)' | $(GREP) -i -c -E '(gcc|g\+\+)')
84XLC_COMPILER := $(shell $(CXX) -qversion 2>/dev/null |$(GREP) -i -c "IBM XL")
85CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c -E '(llvm|clang)')
86INTEL_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c '\(icc\)')
88# Enable shared object versioning for Linux and Solaris
90ifneq ($(IS_LINUX)$(IS_HURD)$(IS_SUN),000)
91 HAS_SOLIB_VERSION := 1
94# Formerly adhoc.cpp was created from adhoc.cpp.proto when needed.
95ifeq ($(wildcard adhoc.cpp),)
96$(shell cp adhoc.cpp.proto adhoc.cpp)
99# Hack to skip CPU feature tests for some recipes
101ifneq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
103else ifneq ($(findstring clean,$(MAKECMDGOALS)),)
105else ifneq ($(findstring distclean,$(MAKECMDGOALS)),)
107else ifneq ($(findstring trim,$(MAKECMDGOALS)),)
109else ifneq ($(findstring zip,$(MAKECMDGOALS)),)
113# Strip out -Wall, -Wextra and friends for feature testing. FORTIFY_SOURCE is removed
114# because it requires -O1 or higher, but we use -O0 to tame the optimizer.
115# Always print testing flags since some tests always happen, like 64-bit.
116TCXXFLAGS := $(filter-out -D_FORTIFY_SOURCE=% -M -MM -Wall -Wextra -Werror% -Wunused -Wconversion -Wp%, $(CPPFLAGS) $(CXXFLAGS))
117ifneq ($(strip $(TCXXFLAGS)),)
118 $(info Using testing flags: $(TCXXFLAGS))
121# TCOMMAND is used for just about all tests. Make will lazy-evaluate
122# the variables when executed by $(shell $(TCOMMAND) ...).
123TCOMMAND = $(CXX) -I. $(TCXXFLAGS) $(TEXTRA) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT)
127 TPROG = TestPrograms/test_64bit.cpp
129 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
130 ifeq ($(strip $(HAVE_OPT)),0)
137# Uncomment for debugging
138# $(info Here's what we found... IS_X86: $(IS_X86), IS_X64: $(IS_X64), IS_ARM32: $(IS_ARM32), IS_ARMV8: $(IS_ARMV8))
140###########################################################
141##### General Variables #####
142###########################################################
144# Base CPPFLAGS and CXXFLAGS used if the user did not specify them
145ifeq ($(filter -DDEBUG -DNDEBUG,$(CPPFLAGS)$(CXXFLAGS)),)
146 CRYPTOPP_CPPFLAGS += -DNDEBUG
148ifeq ($(filter -g%,$(CPPFLAGS)$(CXXFLAGS)),)
149 ifeq ($(SUN_COMPILER),1)
150 CRYPTOPP_CXXFLAGS += -g
152 CRYPTOPP_CXXFLAGS += -g2
155ifeq ($(filter -O% -xO%,$(CPPFLAGS)$(CXXFLAGS)),)
156 ifeq ($(SUN_COMPILER),1)
157 CRYPTOPP_CXXFLAGS += -xO3
160 CRYPTOPP_CXXFLAGS += -O3
165# Needed when the assembler is invoked
166ifeq ($(findstring -Wa,--noexecstack,$(ASFLAGS)$(CXXFLAGS)),)
167 CRYPTOPP_ASFLAGS += -Wa,--noexecstack
170# Fix CXX on Cygwin 1.1.4
175# On ARM we may compile aes_armv4.S, sha1_armv4.S, sha256_armv4.S, and
176# sha512_armv4.S through the CC compiler
177ifeq ($(GCC_COMPILER),1)
179else ifeq ($(CLANG_COMPILER),1)
183# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
186 PC_PREFIX = /usr/local
188 PC_PREFIX = $(PREFIX)
191 LIBDIR := $(PREFIX)/lib
192 PC_LIBDIR = $${prefix}/lib
194 PC_LIBDIR = $(LIBDIR)
197 DATADIR := $(PREFIX)/share
198 PC_DATADIR = $${prefix}/share
200 PC_DATADIR = $(DATADIR)
203 INCLUDEDIR := $(PREFIX)/include
204 PC_INCLUDEDIR = $${prefix}/include
206 PC_INCLUDEDIR = $(INCLUDEDIR)
209 BINDIR := $(PREFIX)/bin
212# We honor ARFLAGS, but the "v" option used by default causes a noisy make
217# Original MinGW targets Win2k by default, but lacks proper Win2k support
218# if target Windows version is not specified, use Windows XP instead
220ifeq ($(findstring -D_WIN32_WINNT,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
221ifeq ($(findstring -D_WIN32_WINDOWS,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
222ifeq ($(findstring -DWINVER,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
223ifeq ($(findstring -DNTDDI_VERSION,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
224 CRYPTOPP_CPPFLAGS += -D_WIN32_WINNT=0x0501
227endif # _WIN32_WINDOWS
231# Newlib needs _XOPEN_SOURCE=600 for signals
232TPROG = TestPrograms/test_newlib.cpp
234HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
235ifeq ($(strip $(HAVE_OPT)),0)
236 ifeq ($(findstring -D_XOPEN_SOURCE,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
237 CRYPTOPP_CPPFLAGS += -D_XOPEN_SOURCE=600
241###########################################################
242##### X86/X32/X64 Options #####
243###########################################################
245ifneq ($(IS_X86)$(IS_X64)$(IS_MINGW),000)
246ifeq ($(DETECT_FEATURES),1)
248 ifeq ($(SUN_COMPILER),1)
249 SSE2_FLAG = -xarch=sse2
250 SSE3_FLAG = -xarch=sse3
251 SSSE3_FLAG = -xarch=ssse3
252 SSE41_FLAG = -xarch=sse4_1
253 SSE42_FLAG = -xarch=sse4_2
254 CLMUL_FLAG = -xarch=aes
255 AESNI_FLAG = -xarch=aes
256 AVX_FLAG = -xarch=avx
257 AVX2_FLAG = -xarch=avx2
258 SHANI_FLAG = -xarch=sha
263 SSE41_FLAG = -msse4.1
264 SSE42_FLAG = -msse4.2
265 CLMUL_FLAG = -mpclmul
272 # Tell MacPorts and Homebrew GCC to use Clang integrated assembler
273 # Intel-based Macs. http://github.com/weidai11/crypto++/issues/190
274 ifneq ($(IS_DARWIN),0)
275 ifeq ($(findstring -Wa,-q,$(CXXFLAGS)),)
276 TPROG = TestPrograms/test_cxx.cpp
278 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
279 ifeq ($(strip $(HAVE_OPT)),0)
281 CRYPTOPP_CXXFLAGS += -Wa,-q
286 TPROG = TestPrograms/test_x86_sse2.cpp
288 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
289 ifeq ($(strip $(HAVE_OPT)),0)
290 CHACHA_FLAG = $(SSE2_FLAG)
291 SUN_LDFLAGS += $(SSE2_FLAG)
293 # Make does not have useful debugging facilities. Show the user
294 # what happened by compiling again without the pipe.
295 $(info Running make again to see what failed)
296 $(info $(shell $(TCOMMAND)))
301 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ASM
304 # Need SSE2 or higher for these tests
305 ifneq ($(SSE2_FLAG),)
307 TPROG = TestPrograms/test_x86_ssse3.cpp
309 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
310 ifeq ($(strip $(HAVE_OPT)),0)
311 ARIA_FLAG = $(SSSE3_FLAG)
312 CHAM_FLAG = $(SSSE3_FLAG)
313 KECCAK_FLAG = $(SSSE3_FLAG)
314 LEA_FLAG = $(SSSE3_FLAG)
315 LSH256_FLAG = $(SSSE3_FLAG)
316 LSH512_FLAG = $(SSSE3_FLAG)
317 SIMON128_FLAG = $(SSSE3_FLAG)
318 SPECK128_FLAG = $(SSSE3_FLAG)
319 SUN_LDFLAGS += $(SSSE3_FLAG)
324 # The first Apple MacBooks were Core2's with SSE4.1
325 ifneq ($(IS_DARWIN),0)
326 # Add SSE2 algo's here as required
327 # They get a free upgrade
330 TPROG = TestPrograms/test_x86_sse41.cpp
332 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
333 ifeq ($(strip $(HAVE_OPT)),0)
334 BLAKE2B_FLAG = $(SSE41_FLAG)
335 BLAKE2S_FLAG = $(SSE41_FLAG)
336 SUN_LDFLAGS += $(SSE41_FLAG)
341 TPROG = TestPrograms/test_x86_sse42.cpp
343 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
344 ifeq ($(strip $(HAVE_OPT)),0)
345 CRC_FLAG = $(SSE42_FLAG)
346 SUN_LDFLAGS += $(SSE42_FLAG)
351 TPROG = TestPrograms/test_x86_clmul.cpp
353 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
354 ifeq ($(strip $(HAVE_OPT)),0)
355 GCM_FLAG = $(SSSE3_FLAG) $(CLMUL_FLAG)
356 GF2N_FLAG = $(CLMUL_FLAG)
357 SUN_LDFLAGS += $(CLMUL_FLAG)
362 TPROG = TestPrograms/test_x86_aes.cpp
364 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
365 ifeq ($(strip $(HAVE_OPT)),0)
366 AES_FLAG = $(SSE41_FLAG) $(AESNI_FLAG)
367 SM4_FLAG = $(SSSE3_FLAG) $(AESNI_FLAG)
368 SUN_LDFLAGS += $(AESNI_FLAG)
373 TPROG = TestPrograms/test_x86_avx.cpp
375 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
376 ifeq ($(strip $(HAVE_OPT)),0)
377 # XXX_FLAG = $(AVX_FLAG)
378 SUN_LDFLAGS += $(AVX_FLAG)
383 TPROG = TestPrograms/test_x86_avx2.cpp
385 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
386 ifeq ($(strip $(HAVE_OPT)),0)
387 CHACHA_AVX2_FLAG = $(AVX2_FLAG)
388 LSH256_AVX2_FLAG = $(AVX2_FLAG)
389 LSH512_AVX2_FLAG = $(AVX2_FLAG)
390 SUN_LDFLAGS += $(AVX2_FLAG)
395 TPROG = TestPrograms/test_x86_sha.cpp
397 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
398 ifeq ($(strip $(HAVE_OPT)),0)
399 SHA_FLAG = $(SSE42_FLAG) $(SHANI_FLAG)
400 SUN_LDFLAGS += $(SHANI_FLAG)
405 ifeq ($(SUN_COMPILER),1)
406 CRYPTOPP_LDFLAGS += $(SUN_LDFLAGS)
410 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_SSE3
411 else ifeq ($(SSSE3_FLAG),)
412 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_SSSE3
413 else ifeq ($(SSE41_FLAG),)
414 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_SSE4
415 else ifeq ($(SSE42_FLAG),)
416 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_SSE4
419 ifneq ($(SSE42_FLAG),)
420 # Unusual GCC/Clang on Macports. It assembles AES, but not CLMUL.
421 # test_x86_clmul.s:15: no such instruction: 'pclmulqdq $0, %xmm1,%xmm0'
422 ifeq ($(CLMUL_FLAG),)
423 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_CLMUL
425 ifeq ($(AESNI_FLAG),)
426 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_AESNI
430 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_AVX
431 else ifeq ($(AVX2_FLAG),)
432 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_AVX2
434 # SHANI independent of AVX per GH #1045
435 ifeq ($(SHANI_FLAG),)
436 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_SHANI
440 # Drop to SSE2 if available
442 GCM_FLAG = $(SSE2_FLAG)
445 # Most Clang cannot handle mixed asm with positional arguments, where the
446 # body is Intel style with no prefix and the templates are AT&T style.
447 # Also see https://bugs.llvm.org/show_bug.cgi?id=39895 .
449 # CRYPTOPP_DISABLE_MIXED_ASM is now being added in config_asm.h for all
450 # Clang compilers. This test will need to be re-enabled if Clang fixes it.
451 #TPROG = TestPrograms/test_asm_mixed.cpp
453 #HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
454 #ifneq ($(strip $(HAVE_OPT)),0)
455 # CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM
463ifneq ($(INTEL_COMPILER),0)
464 CRYPTOPP_CXXFLAGS += -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180
466 ICC111_OR_LATER := $(shell $(CXX) --version 2>&1 | $(GREP) -c -E "\(ICC\) ([2-9][0-9]|1[2-9]|11\.[1-9])")
467 ifeq ($(ICC111_OR_LATER),0)
468 # "internal error: backend signals" occurs on some x86 inline assembly with ICC 9 and
469 # some x64 inline assembly with ICC 11.0. If you want to use Crypto++'s assembly code
470 # with ICC, try enabling it on individual files
471 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ASM
475# Allow use of "/" operator for GNU Assembler.
476# http://sourceware.org/bugzilla/show_bug.cgi?id=4572
477ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
478 ifeq ($(IS_SUN)$(GCC_COMPILER),11)
479 CRYPTOPP_CXXFLAGS += -Wa,--divide
486###########################################################
487##### ARM A-32 and NEON #####
488###########################################################
492# No need for feature detection on this platform if NEON is disabled
493ifneq ($(findstring -DCRYPTOPP_DISABLE_ARM_NEON,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
497ifeq ($(DETECT_FEATURES),1)
499 # Clang needs an option to include <arm_neon.h>
500 TPROG = TestPrograms/test_arm_neon_header.cpp
501 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1 -march=armv7-a -mfpu=neon
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_neon.cpp
508 TOPT = -march=armv7-a -mfpu=neon
509 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
510 ifeq ($(strip $(HAVE_OPT)),0)
511 NEON_FLAG = -march=armv7-a -mfpu=neon
512 ARIA_FLAG = -march=armv7-a -mfpu=neon
513 GCM_FLAG = -march=armv7-a -mfpu=neon
514 BLAKE2B_FLAG = -march=armv7-a -mfpu=neon
515 BLAKE2S_FLAG = -march=armv7-a -mfpu=neon
516 CHACHA_FLAG = -march=armv7-a -mfpu=neon
517 CHAM_FLAG = -march=armv7-a -mfpu=neon
518 LEA_FLAG = -march=armv7-a -mfpu=neon
519 SIMON128_FLAG = -march=armv7-a -mfpu=neon
520 SPECK128_FLAG = -march=armv7-a -mfpu=neon
521 SM4_FLAG = -march=armv7-a -mfpu=neon
523 # Make does not have useful debugging facilities. Show the user
524 # what happened by compiling again without the pipe.
525 # $(info Running make again to see what failed)
526 # $(info $(shell $(TCOMMAND)))
531 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_NEON
539###########################################################
540##### Aach32 and Aarch64 #####
541###########################################################
544ifeq ($(DETECT_FEATURES),1)
546 TPROG = TestPrograms/test_arm_neon_header.cpp
547 TOPT = -DCRYPTOPP_ARM_NEON_HEADER=1
548 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
549 ifeq ($(strip $(HAVE_OPT)),0)
550 TEXTRA += -DCRYPTOPP_ARM_NEON_HEADER=1
553 TPROG = TestPrograms/test_arm_acle_header.cpp
554 TOPT = -DCRYPTOPP_ARM_ACLE_HEADER=1 -march=armv8-a
555 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
556 ifeq ($(strip $(HAVE_OPT)),0)
557 TEXTRA += -DCRYPTOPP_ARM_ACLE_HEADER=1
560 TPROG = TestPrograms/test_arm_asimd.cpp
561 TOPT = -march=armv8-a
562 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
563 ifeq ($(strip $(HAVE_OPT)),0)
564 ASIMD_FLAG = -march=armv8-a
565 ARIA_FLAG = -march=armv8-a
566 BLAKE2B_FLAG = -march=armv8-a
567 BLAKE2S_FLAG = -march=armv8-a
568 CHACHA_FLAG = -march=armv8-a
569 CHAM_FLAG = -march=armv8-a
570 LEA_FLAG = -march=armv8-a
571 NEON_FLAG = -march=armv8-a
572 SIMON128_FLAG = -march=armv8-a
573 SPECK128_FLAG = -march=armv8-a
574 SM4_FLAG = -march=armv8-a
576 # Make does not have useful debugging facilities. Show the user
577 # what happened by compiling again without the pipe.
578 $(info Running make again to see what failed)
579 $(info $(shell $(TCOMMAND)))
583 ifeq ($(ASIMD_FLAG),)
584 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ASM
587 ifneq ($(ASIMD_FLAG),)
588 TPROG = TestPrograms/test_arm_crc.cpp
589 TOPT = -march=armv8-a+crc
590 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
591 ifeq ($(strip $(HAVE_OPT)),0)
592 CRC_FLAG = -march=armv8-a+crc
594 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_CRC32
597 TPROG = TestPrograms/test_arm_aes.cpp
598 TOPT = -march=armv8-a+crypto
599 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
600 ifeq ($(strip $(HAVE_OPT)),0)
601 AES_FLAG = -march=armv8-a+crypto
603 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_AES
606 TPROG = TestPrograms/test_arm_pmull.cpp
607 TOPT = -march=armv8-a+crypto
608 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
609 ifeq ($(strip $(HAVE_OPT)),0)
610 GCM_FLAG = -march=armv8-a+crypto
611 GF2N_FLAG = -march=armv8-a+crypto
613 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_PMULL
616 TPROG = TestPrograms/test_arm_sha1.cpp
617 TOPT = -march=armv8-a+crypto
618 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
619 ifeq ($(strip $(HAVE_OPT)),0)
620 SHA_FLAG = -march=armv8-a+crypto
622 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA1
625 TPROG = TestPrograms/test_arm_sha256.cpp
626 TOPT = -march=armv8-a+crypto
627 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
628 ifeq ($(strip $(HAVE_OPT)),0)
629 SHA_FLAG = -march=armv8-a+crypto
631 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA2
634 TPROG = TestPrograms/test_arm_sm3.cpp
635 TOPT = -march=armv8.4-a+sm3
636 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
637 ifeq ($(strip $(HAVE_OPT)),0)
638 SM3_FLAG = -march=armv8.4-a+sm3
639 SM4_FLAG = -march=armv8.4-a+sm3
641 #CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SM3
642 #CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SM4
645 TPROG = TestPrograms/test_arm_sha3.cpp
646 TOPT = -march=armv8.4-a+sha3
647 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
648 ifeq ($(strip $(HAVE_OPT)),0)
649 SHA3_FLAG = -march=armv8.4-a+sha3
651 #CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA3
654 TPROG = TestPrograms/test_arm_sha512.cpp
655 TOPT = -march=armv8.4-a+sha512
656 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
657 ifeq ($(strip $(HAVE_OPT)),0)
658 SHA512_FLAG = -march=armv8.4-a+sha512
660 #CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ARM_SHA512
671###########################################################
673###########################################################
675# PowerPC and PowerPC64. Altivec is available with POWER4 with GCC and
676# POWER6 with XLC. The tests below are crafted for IBM XLC and the LLVM
677# front-end. XLC/LLVM only supplies POWER8 so we have to set the flags for
678# XLC/LLVM to POWER8. I've got a feeling LLVM is going to cause trouble.
680ifneq ($(IS_PPC32)$(IS_PPC64),00)
681ifeq ($(DETECT_FEATURES),1)
683 # IBM XL C/C++ has the -qaltivec flag really screwed up. We can't seem
684 # to get it enabled without an -qarch= option. And -qarch= produces an
685 # error on later versions of the compiler. The only thing that seems
686 # to work consistently is -qarch=auto. -qarch=auto is equivalent to
687 # GCC's -march=native, which we don't really want.
689 # XLC requires -qaltivec in addition to Arch or CPU option
690 ifeq ($(XLC_COMPILER),1)
691 # POWER9_FLAG = -qarch=pwr9 -qaltivec
692 POWER8_FLAG = -qarch=pwr8 -qaltivec
693 POWER7_VSX_FLAG = -qarch=pwr7 -qvsx -qaltivec
694 POWER7_PWR_FLAG = -qarch=pwr7 -qaltivec
695 ALTIVEC_FLAG = -qarch=auto -qaltivec
697 # POWER9_FLAG = -mcpu=power9
698 POWER8_FLAG = -mcpu=power8
699 POWER7_VSX_FLAG = -mcpu=power7 -mvsx
700 POWER7_PWR_FLAG = -mcpu=power7
701 ALTIVEC_FLAG = -maltivec
704 # GCC 10 is giving us trouble in CPU_ProbePower9() and
705 # CPU_ProbeDARN(). GCC is generating POWER9 instructions
706 # on POWER8 for ppc_power9.cpp. The compiler folks did
707 # not think through the consequences of requiring us to
708 # use -mcpu=power9 to unlock the ISA. Epic fail.
709 # https:#github.com/weidai11/crypto++/issues/986
712 # XLC with LLVM front-ends failed to define XLC defines.
713 #ifeq ($(findstring -qxlcompatmacros,$(CXXFLAGS)),)
714 # TPROG = TestPrograms/test_ppc_altivec.cpp
715 # TOPT = -qxlcompatmacros
716 # HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
717 # ifeq ($(strip $(HAVE_OPT)),0)
718 # CRYPTOPP_CXXFLAGS += -qxlcompatmacros
722 #####################################################################
723 # Looking for a POWER9 option
725 #TPROG = TestPrograms/test_ppc_power9.cpp
726 #TOPT = $(POWER9_FLAG)
727 #HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
728 #ifeq ($(strip $(HAVE_OPT)),0)
729 # DARN_FLAG = $(POWER9_FLAG)
734 #####################################################################
735 # Looking for a POWER8 option
737 TPROG = TestPrograms/test_ppc_power8.cpp
738 TOPT = $(POWER8_FLAG)
739 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
740 ifeq ($(strip $(HAVE_OPT)),0)
741 AES_FLAG = $(POWER8_FLAG)
742 BLAKE2B_FLAG = $(POWER8_FLAG)
743 CRC_FLAG = $(POWER8_FLAG)
744 GCM_FLAG = $(POWER8_FLAG)
745 GF2N_FLAG = $(POWER8_FLAG)
746 LEA_FLAG = $(POWER8_FLAG)
747 SHA_FLAG = $(POWER8_FLAG)
748 SHACAL2_FLAG = $(POWER8_FLAG)
753 #####################################################################
754 # Looking for a POWER7 option
756 # GCC needs -mvsx for Power7 to enable 64-bit vector elements.
757 # XLC provides 64-bit vector elements without an option.
759 TPROG = TestPrograms/test_ppc_power7.cpp
760 TOPT = $(POWER7_VSX_FLAG)
761 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
762 ifeq ($(strip $(HAVE_OPT)),0)
763 POWER7_FLAG = $(POWER7_VSX_FLAG)
765 TPROG = TestPrograms/test_ppc_power7.cpp
766 TOPT = $(POWER7_PWR_FLAG)
767 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
768 ifeq ($(strip $(HAVE_OPT)),0)
769 POWER7_FLAG = $(POWER7_PWR_FLAG)
775 #####################################################################
776 # Looking for an Altivec option
778 TPROG = TestPrograms/test_ppc_altivec.cpp
779 TOPT = $(ALTIVEC_FLAG)
780 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
781 ifeq ($(strip $(HAVE_OPT)),0)
782 ALTIVEC_FLAG := $(ALTIVEC_FLAG)
784 # Make does not have useful debugging facilities. Show the user
785 # what happened by compiling again without the pipe.
786 $(info Running make again to see what failed)
787 $(info $(shell $(TCOMMAND)))
791 ifneq ($(ALTIVEC_FLAG),)
792 BLAKE2S_FLAG = $(ALTIVEC_FLAG)
793 CHACHA_FLAG = $(ALTIVEC_FLAG)
794 SPECK128_FLAG = $(ALTIVEC_FLAG)
795 SIMON128_FLAG = $(ALTIVEC_FLAG)
798 #####################################################################
799 # Fixups for algorithms that can drop to a lower ISA, if needed
801 # Drop to Altivec if higher Power is not available
802 ifneq ($(ALTIVEC_FLAG),)
804 GCM_FLAG = $(ALTIVEC_FLAG)
808 #####################################################################
809 # Fixups for missing ISAs
811 ifeq ($(ALTIVEC_FLAG),)
812 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_ALTIVEC
813 else ifeq ($(POWER7_FLAG),)
814 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_POWER7
815 else ifeq ($(POWER8_FLAG),)
816 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_POWER8
817 #else ifeq ($(POWER9_FLAG),)
818 # CRYPTOPP_CPPFLAGS += -DCRYPTOPP_DISABLE_POWER9
825ifeq ($(XLC_COMPILER),1)
826 ifeq ($(findstring -qmaxmem,$(CXXFLAGS)),)
827 CRYPTOPP_CXXFLAGS += -qmaxmem=-1
829 # http://www-01.ibm.com/support/docview.wss?uid=swg21007500
830 ifeq ($(findstring -qrtti,$(CXXFLAGS)),)
831 CRYPTOPP_CXXFLAGS += -qrtti
838###########################################################
840###########################################################
842# Add -fPIC for targets *except* X86, X32, Cygwin or MinGW
843ifeq ($(IS_X86)$(IS_CYGWIN)$(IS_MINGW),000)
844 ifeq ($(findstring -fpic,$(CXXFLAGS))$(findstring -fPIC,$(CXXFLAGS)),)
845 CRYPTOPP_CXXFLAGS += -fPIC
849# Fix for GH #1134 and GH #1141. We need to add -fno-devirtualize because GCC is removing
850# code we are using. https://github.com/weidai11/crypto++/issues/1134 and
851# https://github.com/weidai11/crypto++/issues/1141
852ifeq ($(findstring -fno-devirtualize,$(CXXFLAGS)),)
853 TPROG = TestPrograms/test_nodevirtualize.cpp
854 TOPT = -fno-devirtualize
855 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
856 ifeq ($(strip $(HAVE_OPT)),0)
857 CRYPTOPP_CXXFLAGS += -fno-devirtualize
858 endif # CRYPTOPP_CXXFLAGS
859endif # -fno-devirtualize
861# Use -pthread whenever it is available. See http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf
862# http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling
863ifeq ($(DETECT_FEATURES),1)
864 ifeq ($(XLC_COMPILER),1)
865 ifeq ($(findstring -qthreaded,$(CXXFLAGS)),)
866 TPROG = TestPrograms/test_pthreads.cpp
868 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
869 ifeq ($(strip $(HAVE_OPT)),0)
870 CRYPTOPP_CXXFLAGS += -qthreaded
871 endif # CRYPTOPP_CXXFLAGS
874 ifeq ($(findstring -pthread,$(CXXFLAGS)),)
875 TPROG = TestPrograms/test_pthreads.cpp
877 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
878 ifeq ($(strip $(HAVE_OPT)),0)
879 CRYPTOPP_CXXFLAGS += -pthread
880 endif # CRYPTOPP_CXXFLAGS
882 endif # XLC/GCC and friends
883endif # DETECT_FEATURES
885# Remove -fPIC if present. SunCC use -KPIC, and needs the larger GOT table
886# https://docs.oracle.com/cd/E19205-01/819-5267/bkbaq/index.html
887ifeq ($(SUN_COMPILER),1)
888 CRYPTOPP_CXXFLAGS := $(subst -fPIC,-KPIC,$(CRYPTOPP_CXXFLAGS))
889 CRYPTOPP_CXXFLAGS := $(subst -fpic,-KPIC,$(CRYPTOPP_CXXFLAGS))
892# Remove -fPIC if present. IBM XL C++ uses -qpic
893ifeq ($(XLC_COMPILER),1)
894 CRYPTOPP_CXXFLAGS := $(subst -fPIC,-qpic,$(CRYPTOPP_CXXFLAGS))
895 CRYPTOPP_CXXFLAGS := $(subst -fpic,-qpic,$(CRYPTOPP_CXXFLAGS))
898# Disable IBM XL C++ "1500-036: (I) The NOSTRICT option (default at OPT(3))
899# has the potential to alter the semantics of a program."
900ifeq ($(XLC_COMPILER),1)
901 TPROG = TestPrograms/test_cxx.cpp
902 TOPT = -qsuppress=1500-036
903 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
904 ifeq ($(strip $(HAVE_OPT)),0)
905 CRYPTOPP_CXXFLAGS += -qsuppress=1500-036
907endif # IBM XL C++ compiler
909# libc++ is LLVM's standard C++ library. If we add libc++
910# here then all user programs must use it too. The open
911# question is, which choice is easier on users?
912ifneq ($(IS_DARWIN),0)
914 # CRYPTOPP_CXXFLAGS += -stdlib=libc++
915 ifeq ($(findstring -fno-common,$(CXXFLAGS)),)
916 CRYPTOPP_CXXFLAGS += -fno-common
918 IS_APPLE_LIBTOOL=$(shell libtool -V 2>&1 | $(GREP) -i -c 'Apple')
919 ifeq ($(IS_APPLE_LIBTOOL),1)
922 AR = /usr/bin/libtool
927# Add -xregs=no%appl SPARC. SunCC should not use certain registers in library code.
928# https://docs.oracle.com/cd/E18659_01/html/821-1383/bkamt.html
929ifneq ($(IS_SPARC32)$(IS_SPARC64),00)
930 ifeq ($(SUN_COMPILER),1)
931 ifeq ($(findstring -xregs=no%appl,$(CXXFLAGS)),)
932 CRYPTOPP_CXXFLAGS += -xregs=no%appl
935 ifeq ($(GCC_COMPILER),1)
936 ifeq ($(findstring -mno-app-regs,$(CXXFLAGS)),)
937 CRYPTOPP_CXXFLAGS += -mno-app-regs
942# Add -pipe for everything except IBM XL C++, SunCC and ARM.
943# Allow ARM-64 because they seems to have >1 GB of memory
944ifeq ($(XLC_COMPILER)$(SUN_COMPILER)$(IS_ARM32),000)
945 ifeq ($(findstring -save-temps,$(CXXFLAGS)),)
946 CRYPTOPP_CXXFLAGS += -pipe
950# For SunOS, create a Mapfile that allows our object files
951# to contain additional bits (like SSE4 and AES on old Xeon)
952# http://www.oracle.com/technetwork/server-storage/solaris/hwcap-modification-139536.html
953ifeq ($(IS_SUN)$(SUN_COMPILER),11)
954 ifneq ($(IS_X86)$(IS_X64),00)
955 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
956 CRYPTOPP_LDFLAGS += -M crypto++.mapfile
957 endif # No CRYPTOPP_DISABLE_ASM
961ifneq ($(IS_LINUX)$(IS_HURD),00)
962 ifeq ($(findstring -fopenmp,$(CXXFLAGS)),-fopenmp)
963 ifeq ($(findstring -lgomp,$(LDLIBS)),)
967endif # IS_LINUX or IS_HURD
969# Add -errtags=yes to get the name for a warning suppression
970ifneq ($(SUN_COMPILER),0) # override flags for CC Sun C++ compiler
972CRYPTOPP_CXXFLAGS += -template=no%extdef
973SUN_CC10_BUGGY := $(shell $(CXX) -V 2>&1 | $(GREP) -c -E "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
974ifneq ($(SUN_CC10_BUGGY),0)
975# -DCRYPTOPP_INCLUDE_VECTOR_CC is needed for Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21
976# and was fixed in May 2010. Remove it if you get "already had a body defined" errors in vector.cc
977CRYPTOPP_CPPFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
984# Native build testing. Issue 'make native'.
985ifeq ($(findstring native,$(MAKECMDGOALS)),native)
988 # Try GCC and compatibles first
989 TPROG = TestPrograms/test_cxx.cpp
991 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
992 ifeq ($(strip $(HAVE_OPT)),0)
993 NATIVE_OPT = -march=native
997 ifeq ($(NATIVE_OPT),)
999 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
1000 ifeq ($(strip $(HAVE_OPT)),0)
1001 NATIVE_OPT = -mtune=native
1006 ifeq ($(NATIVE_OPT),)
1008 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
1009 ifeq ($(strip $(HAVE_OPT)),0)
1010 NATIVE_OPT = -native
1014 ifneq ($(NATIVE_OPT),)
1015 CRYPTOPP_CXXFLAGS += $(NATIVE_OPT)
1020# Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
1021ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
1022 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-g%=-g3)
1023 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-O%=-O1)
1024 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-xO%=-xO1)
1025 ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
1026 CRYPTOPP_CXXFLAGS += -fsanitize=undefined
1027 endif # CRYPTOPP_CPPFLAGS
1028 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1029 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_COVERAGE
1030 endif # CRYPTOPP_CPPFLAGS
1033# Address Sanitizer (Asan) testing. Issue 'make asan'.
1034ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
1035 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-g%=-g3)
1036 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-O%=-O1)
1037 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-xO%=-xO1)
1038 ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
1039 CRYPTOPP_CXXFLAGS += -fsanitize=address
1040 endif # CRYPTOPP_CXXFLAGS
1041 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1042 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_COVERAGE
1043 endif # CRYPTOPP_CPPFLAGS
1044 ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
1045 CRYPTOPP_CXXFLAGS += -fno-omit-frame-pointer
1046 endif # CRYPTOPP_CXXFLAGS
1049# LD gold linker testing. Triggered by 'LD=ld.gold'.
1050ifeq ($(findstring ld.gold,$(LD)),ld.gold)
1051 ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
1052 LD_GOLD = $(shell command -v ld.gold)
1053 ELF_FORMAT := $(shell file $(LD_GOLD) 2>&1 | cut -d":" -f 2 | $(GREP) -i -c "elf")
1054 ifneq ($(ELF_FORMAT),0)
1055 CRYPTOPP_LDFLAGS += -fuse-ld=gold
1060# lcov code coverage. Issue 'make coverage'.
1061ifneq ($(filter lcov coverage,$(MAKECMDGOALS)),)
1062 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-g%=-g3)
1063 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-O%=-O1)
1064 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-xO%=-xO1)
1065 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1066 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_COVERAGE
1067 endif # CRYPTOPP_COVERAGE
1068 ifeq ($(findstring -coverage,$(CXXFLAGS)),)
1069 CRYPTOPP_CXXFLAGS += -coverage
1071endif # GCC code coverage
1073# gcov code coverage for Travis. Issue 'make codecov'.
1074ifneq ($(filter gcov codecov,$(MAKECMDGOALS)),)
1075 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-g%=-g3)
1076 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-O%=-O1)
1077 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-xO%=-xO1)
1078 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1079 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_COVERAGE
1080 endif # CRYPTOPP_COVERAGE
1081 ifeq ($(findstring -coverage,$(CXXFLAGS)),)
1082 CRYPTOPP_CXXFLAGS += -coverage
1084endif # GCC code coverage
1086# Valgrind testing. Issue 'make valgrind'.
1087ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
1088 # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
1089 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-g%=-g3)
1090 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-O%=-O1)
1091 CRYPTOPP_CXXFLAGS := $(CRYPTOPP_CXXFLAGS:-xO%=-xO1)
1092 ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1093 CRYPTOPP_CPPFLAGS += -DCRYPTOPP_COVERAGE
1094 endif # CRYPTOPP_CPPFLAGS
1097# Debug testing on GNU systems. Triggered by -DDEBUG.
1098# Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
1099ifneq ($(filter -DDEBUG -DDEBUG=1,$(CPPFLAGS)$(CXXFLAGS)),)
1100 TPROG = TestPrograms/test_cxx.cpp
1102 USING_GLIBCXX := $(shell $(CXX) $(CPPFLAGS) $(CXXFLAGS) -E $(TPROG) -c 2>&1 | $(GREP) -i -c "__GLIBCXX__")
1103 ifneq ($(USING_GLIBCXX),0)
1104 ifeq ($(HAS_NEWLIB),0)
1105 ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1106 CRYPTOPP_CPPFLAGS += -D_GLIBCXX_DEBUG
1107 endif # CRYPTOPP_CPPFLAGS
1109 endif # USING_GLIBCXX
1111 ifeq ($(XLC_COMPILER),1)
1112 TPROG = TestPrograms/test_cxx.cpp
1113 TOPT = -qheapdebug -qro
1114 HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w)
1115 ifeq ($(strip $(HAVE_OPT)),0)
1116 CRYPTOPP_CXXFLAGS += -qheapdebug -qro
1117 endif # CRYPTOPP_CXXFLAGS
1118 endif # XLC_COMPILER
1121# Dead code stripping. Issue 'make lean'.
1122ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
1123 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
1124 CRYPTOPP_CXXFLAGS += -ffunction-sections
1125 endif # CRYPTOPP_CXXFLAGS
1126 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
1127 CRYPTOPP_CXXFLAGS += -fdata-sections
1128 endif # CRYPTOPP_CXXFLAGS
1129 ifneq ($(IS_DARWIN),0)
1130 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
1131 CRYPTOPP_LDFLAGS += -Wl,-dead_strip
1132 endif # CRYPTOPP_CXXFLAGS
1133 else # BSD, Linux and Unix
1134 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
1135 CRYPTOPP_LDFLAGS += -Wl,--gc-sections
1137 endif # MAKECMDGOALS
1138endif # Dead code stripping
1140# For Shared Objects, Diff, Dist/Zip rules
1141LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config_ver.h | cut -d" " -f 3)
1142LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
1143LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
1144LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
1146ifeq ($(strip $(LIB_PATCH)),)
1150ifeq ($(HAS_SOLIB_VERSION),1)
1151# Different patchlevels and minors are compatible since 6.1
1152SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
1153# Linux uses -Wl,-soname
1154ifneq ($(IS_LINUX)$(IS_HURD),00)
1155# Linux uses full version suffix for shared library
1156SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
1157SOLIB_FLAGS=-Wl,-soname,libcrypto++.so$(SOLIB_COMPAT_SUFFIX)
1159# Solaris uses -Wl,-h
1161# Solaris uses major version suffix for shared library, but we use major.minor
1162# The minor version allows previous version to remain and not overwritten.
1163# https://blogs.oracle.com/solaris/how-to-name-a-solaris-shared-object-v2
1164SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR)
1165SOLIB_FLAGS=-Wl,-h,libcrypto++.so$(SOLIB_COMPAT_SUFFIX)
1167endif # HAS_SOLIB_VERSION
1169###########################################################
1170##### Temp file cleanup #####
1171###########################################################
1173# After this point no more test programs should be run.
1174# https://github.com/weidai11/crypto++/issues/738
1175ifeq ($(findstring /dev/null,$(TOUT)),)
1176 # $(info TOUT is not /dev/null, cleaning $(TOUT))
1177 ifeq ($(wildcard $(TOUT)),$(TOUT))
1178 UNUSED := $(shell $(RM) $(TOUT) 2>/dev/null)
1180 ifeq ($(wildcard $(TOUT).dSYM/),$(TOUT).dSYM/)
1181 UNUSED := $(shell $(RM) -r $(TOUT).dSYM/ 2>/dev/null)
1185###########################################################
1186##### Source and object files #####
1187###########################################################
1189# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
1190SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp,$(sort $(wildcard *.cpp)))
1191# For Makefile.am; resource.h is Windows
1192INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
1194ifneq ($(IS_MINGW),0)
1198# Cryptogams source files. We couple to ARMv7 and NEON due to SHA using NEON.
1199# Limit to Linux. The source files target the GNU assembler.
1200# Also see https://www.crypto++.com/wiki/Cryptogams.
1201ifeq ($(IS_ARM32)$(IS_LINUX),11)
1202 ifeq ($(filter -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_ARM_NEON,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1203 # Do not use -march=armv7 if the compiler is already targeting the ISA.
1204 # Also see https://github.com/weidai11/crypto++/issues/1094
1205 ifeq ($(shell $(CXX) -dM -E TestPrograms/test_cxx.cpp 2>/dev/null | grep -E '__ARM_ARCH 7|__ARM_ARCH_7A__'),)
1206 CRYPTOGAMS_ARMV7_FLAG = -march=armv7-a
1208 ifeq ($(CLANG_COMPILER),1)
1209 CRYPTOGAMS_ARM_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
1210 CRYPTOGAMS_ARM_THUMB_FLAG = $(CRYPTOGAMS_ARMV7_FLAG) -mthumb
1212 # -mfpu=auto due to https://github.com/weidai11/crypto++/issues/1094
1213 CRYPTOGAMS_ARM_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
1214 CRYPTOGAMS_ARM_THUMB_FLAG = $(CRYPTOGAMS_ARMV7_FLAG)
1216 SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S sha512_armv4.S
1220# Remove unneeded arch specific files to speed build time.
1221ifeq ($(IS_PPC32)$(IS_PPC64),00)
1222 SRCS := $(filter-out %_ppc.cpp,$(SRCS))
1224ifeq ($(IS_ARM32)$(IS_ARMV8),00)
1225 SRCS := $(filter-out arm_%,$(SRCS))
1226 SRCS := $(filter-out neon_%,$(SRCS))
1227 SRCS := $(filter-out %_armv4.S,$(SRCS))
1229ifeq ($(IS_X86)$(IS_X64),00)
1230 SRCS := $(filter-out sse_%,$(SRCS))
1231 SRCS := $(filter-out %_sse.cpp,$(SRCS))
1232 SRCS := $(filter-out %_avx.cpp,$(SRCS))
1235# If ASM is disabled we can remove the SIMD files, too.
1236ifneq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CRYPTOPP_CPPFLAGS)$(CPPFLAGS)$(CXXFLAGS)),)
1237 SRCS := $(filter-out arm_%,$(SRCS))
1238 SRCS := $(filter-out ppc_%,$(SRCS))
1239 SRCS := $(filter-out neon_%,$(SRCS))
1240 SRCS := $(filter-out sse_%,$(SRCS))
1241 SRCS := $(filter-out %_sse.cpp,$(SRCS))
1242 SRCS := $(filter-out %_avx.cpp,$(SRCS))
1243 SRCS := $(filter-out %_ppc.cpp,$(SRCS))
1244 SRCS := $(filter-out %_simd.cpp,$(SRCS))
1245 SRCS := $(filter-out %_armv4.S,$(SRCS))
1248# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
1249OBJS := $(SRCS:.cpp=.o)
1250OBJS := $(OBJS:.S=.o)
1252# List test.cpp first to tame C++ static initialization problems.
1253TESTSRCS := 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
1254TESTINCL := bench.h factory.h validate.h
1257TESTOBJS := $(TESTSRCS:.cpp=.o)
1258LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
1260# In Crypto++ 5.6.2 these were the source and object files for the FIPS DLL.
1261# Since the library is on the Historical Validation List we add all files.
1262# The 5.6.2 list is at https://github.com/weidai11/crypto++/blob/789f81f048c9.
1264DLLOBJS := $(DLLSRCS:.cpp=.export.o)
1265DLLOBJS := $(DLLOBJS:.S=.export.o)
1268LIBIMPORTOBJS := $(LIBOBJS:.o=.import.o)
1269TESTIMPORTOBJS := $(TESTOBJS:.o=.import.o)
1270DLLTESTOBJS := dlltest.dllonly.o
1272# Clean recipe, Issue 998. Don't filter-out some artifacts from the list of objects
1273# The *.S is a hack. It makes the ASM appear like C++ so the object files make the CLEAN_OBJS list
1274CLEAN_SRCS := $(wildcard *.cpp) $(patsubst %.S,%.cpp,$(wildcard *.S))
1275CLEAN_OBJS := $(CLEAN_SRCS:.cpp=.o) $(CLEAN_SRCS:.cpp=.import.o) $(CLEAN_SRCS:.cpp=.export.o)
1277###########################################################
1278##### Add our flags to user flags #####
1279###########################################################
1281# This ensures we don't add flags when the user forbids
1282# use of customary library flags, like -fPIC. Make will
1283# ignore this assignment when CXXFLAGS is passed as an
1284# argument to the make program: make CXXFLAGS="..."
1285CPPFLAGS := $(strip $(CRYPTOPP_CPPFLAGS) $(CPPFLAGS))
1286CXXFLAGS := $(strip $(CRYPTOPP_CXXFLAGS) $(CXXFLAGS))
1287ASFLAGS := $(strip $(CRYPTOPP_ASFLAGS) $(ASFLAGS))
1288LDFLAGS := $(strip $(CRYPTOPP_LDFLAGS) $(LDFLAGS))
1290###########################################################
1291##### Targets and Recipes #####
1292###########################################################
1294# Default builds program with static library only
1298.PHONY: all static dynamic
1299all: static dynamic cryptest
1301ifneq ($(IS_DARWIN),0)
1302static: libcrypto++.a
1303shared dynamic dylib: libcrypto++.dylib
1305static: libcrypto++.a
1306shared dynamic: libcrypto++.so$(SOLIB_VERSION_SUFFIX)
1309# CXXFLAGS are tuned earlier.
1310.PHONY: native no-asm asan ubsan
1311native no-asm asan ubsan: cryptest
1313# CXXFLAGS are tuned earlier. Applications must use linker flags
1314# -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
1316lean: static dynamic cryptest
1318# May want to export CXXFLAGS="-g3 -O1"
1319.PHONY: lcov coverage
1320lcov coverage: cryptest
1321 @-$(RM) -r ./TestCoverage/
1322 lcov --base-directory . --directory . --zerocounters -q
1326 lcov --base-directory . --directory . -c -o cryptest.info
1327 lcov --remove cryptest.info "adhoc.*" -o cryptest.info
1328 lcov --remove cryptest.info "fips140.*" -o cryptest.info
1329 lcov --remove cryptest.info "*test.*" -o cryptest.info
1330 lcov --remove cryptest.info "/usr/*" -o cryptest.info
1331 genhtml -o ./TestCoverage/ -t "Crypto++ test coverage" --num-spaces 4 cryptest.info
1333# Travis CI and CodeCov rule
1335gcov codecov: cryptest
1336 @-$(RM) -r ./TestCoverage/
1341# Should use CXXFLAGS="-g3 -O1"
1344 valgrind --track-origins=yes --suppressions=crypto++.supp ./cryptest v
1350# Used to generate list of source files for Autotools, CMakeList, Android.mk, etc
1353 $(info ***** Library sources *****)
1354 $(info $(filter-out $(TESTSRCS),$(SRCS)))
1356 $(info ***** Library headers *****)
1357 $(info $(filter-out $(TESTINCL),$(INCL)))
1359 $(info ***** Test sources *****)
1362 $(info ***** Test headers *****)
1365# Directory we want (can't specify on Doygen command line)
1366DOCUMENT_DIRECTORY := ref$(LIB_VER)
1367# Directory Doxygen uses (specified in Doygen config file)
1368ifeq ($(wildcard Doxyfile),Doxyfile)
1369DOXYGEN_DIRECTORY := $(strip $(shell $(GREP) "OUTPUT_DIRECTORY" Doxyfile | $(GREP) -v "\#" | cut -d "=" -f 2))
1371# Default directory (in case its missing in the config file)
1372ifeq ($(strip $(DOXYGEN_DIRECTORY)),)
1373DOXYGEN_DIRECTORY := html-docs
1376# Builds the documentation. Directory name is ref563, ref570, etc.
1379 @-$(RM) -r $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/ html-docs/
1380 @-$(RM) CryptoPPRef.zip
1381 doxygen Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
1382 $(MV) $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/
1383 zip -9 CryptoPPRef.zip -x ".*" -x "*/.*" -r $(DOCUMENT_DIRECTORY)/
1387 -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(CLEAN_OBJS) rdrand-*.o
1388 @-$(RM) libcrypto++.a libcrypto++.dylib crypto++.dll libcrypto++.dll.a libcrypto++.import.a
1389 @-$(RM) libcrypto++.so libcrypto++.so$(SOLIB_COMPAT_SUFFIX) libcrypto++.so$(SOLIB_VERSION_SUFFIX)
1390 @-$(RM) cryptest dlltest.exe cryptest.import.exe cryptest.dat ct et
1391 @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
1392 @-$(RM) /tmp/adhoc.exe
1393 @-$(RM) -r /tmp/crypto++_test/
1394 @-$(RM) -r *.exe.dSYM/ *.dylib.dSYM/
1397.PHONY: autotools-clean
1399 @-$(RM) -f bootstrap.sh configure.ac configure configure.in Makefile.am Makefile.in Makefile
1400 @-$(RM) -f config.guess config.status config.sub config.h.in compile depcomp
1401 @-$(RM) -f install-sh stamp-h1 ar-lib *.lo *.la *.m4 local.* lt*.sh missing
1402 @-$(RM) -f cryptest cryptestcwd libtool* libcrypto++.la libcrypto++.pc*
1403 @-$(RM) -rf build-aux/ m4/ auto*.cache/ .deps/ .libs/
1405.PHONY: android-clean
1407 @-$(RM) -f $(patsubst %_simd.cpp,%_simd.cpp.neon,$(wildcard *_simd.cpp))
1411distclean: clean autotools-clean android-clean
1412 -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt
1413 -$(RM) cryptest_all.info cryptest_debug.info cryptest_noasm.info cryptest_base.info cryptest.info cryptest_release.info
1414 @-$(RM) cryptest-*.txt crypto++.tgz libcrypto++.pc *.o *.bc *.ii *~
1415 @-$(RM) -r cryptlib.lib cryptest *.suo *.sdf *.pdb Win32/ x64/ ipch/
1416 @-$(RM) -r $(LIBOBJS:.o=.obj) $(TESTOBJS:.o=.obj)
1417 @-$(RM) -r $(LIBOBJS:.o=.lst) $(TESTOBJS:.o=.lst)
1418 @-$(RM) -r TestCoverage/ ref*/
1419 @-$(RM) crypto++$(LIB_VER)\.* CryptoPPRef.zip
1421# Install cryptest, libcrypto++.a, libcrypto++.so and libcrypto++.pc.
1422# The library install was broken-out into its own recipe at GH #653.
1424install: cryptest install-lib
1425 @-$(MKDIR) $(DESTDIR)$(BINDIR)
1426 $(CP) cryptest $(DESTDIR)$(BINDIR)
1427 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(BINDIR)/cryptest
1428 @-$(MKDIR) $(DESTDIR)$(DATADIR)/crypto++/TestData
1429 @-$(MKDIR) $(DESTDIR)$(DATADIR)/crypto++/TestVectors
1430 $(CP) TestData/*.dat $(DESTDIR)$(DATADIR)/crypto++/TestData
1431 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/crypto++/TestData/*.dat
1432 $(CP) TestVectors/*.txt $(DESTDIR)$(DATADIR)/crypto++/TestVectors
1433 $(CHMOD) u=rw,go=r $(DESTDIR)$(DATADIR)/crypto++/TestVectors/*.txt
1435# A recipe to install only the library, and not cryptest. Also
1436# see https://github.com/weidai11/crypto++/issues/653. Some users
1437# already have a libcrypto++.pc. Install the *.pc file if the file
1438# is present. If you want one, then issue 'make libcrypto++.pc'.
1441 @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/crypto++
1442 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/crypto++
1443 $(CHMOD) u=rw,go=r $(DESTDIR)$(INCLUDEDIR)/crypto++/*.h
1444ifneq ($(wildcard libcrypto++.a),)
1445 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1446 $(CP) libcrypto++.a $(DESTDIR)$(LIBDIR)
1447 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/libcrypto++.a
1449ifneq ($(wildcard libcrypto++.dylib),)
1450 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1451 $(CP) libcrypto++.dylib $(DESTDIR)$(LIBDIR)
1452 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcrypto++.dylib
1453 -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcrypto++.dylib $(DESTDIR)$(LIBDIR)/libcrypto++.dylib
1455ifneq ($(wildcard libcrypto++.so$(SOLIB_VERSION_SUFFIX)),)
1456 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1457 $(CP) libcrypto++.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
1458 $(CHMOD) u=rwx,go=rx $(DESTDIR)$(LIBDIR)/libcrypto++.so$(SOLIB_VERSION_SUFFIX)
1459ifeq ($(HAS_SOLIB_VERSION),1)
1460 -$(LN) libcrypto++.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcrypto++.so
1461 -$(LN) libcrypto++.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcrypto++.so$(SOLIB_COMPAT_SUFFIX)
1462 $(LDCONF) $(DESTDIR)$(LIBDIR)
1465ifneq ($(wildcard libcrypto++.pc),)
1466 @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
1467 $(CP) libcrypto++.pc $(DESTDIR)$(LIBDIR)/pkgconfig
1468 $(CHMOD) u=rw,go=r $(DESTDIR)$(LIBDIR)/pkgconfig/libcrypto++.pc
1471.PHONY: remove uninstall
1473 -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/crypto++
1474 -$(RM) $(DESTDIR)$(LIBDIR)/libcrypto++.a
1475 -$(RM) $(DESTDIR)$(BINDIR)/cryptest
1476ifneq ($(wildcard $(DESTDIR)$(LIBDIR)/libcrypto++.dylib),)
1477 -$(RM) $(DESTDIR)$(LIBDIR)/libcrypto++.dylib
1479ifneq ($(wildcard $(DESTDIR)$(LIBDIR)/libcrypto++.so),)
1480 -$(RM) $(DESTDIR)$(LIBDIR)/libcrypto++.so
1482 @-$(RM) $(DESTDIR)$(LIBDIR)/libcrypto++.so$(SOLIB_VERSION_SUFFIX)
1483 @-$(RM) $(DESTDIR)$(LIBDIR)/libcrypto++.so$(SOLIB_COMPAT_SUFFIX)
1484 @-$(RM) $(DESTDIR)$(LIBDIR)/pkgconfig/libcrypto++.pc
1485 @-$(RM) -r $(DESTDIR)$(DATADIR)/crypto++
1487libcrypto++.a: $(LIBOBJS) | osx_warning
1488 $(AR) $(ARFLAGS) $@ $(LIBOBJS)
1493ifeq ($(HAS_SOLIB_VERSION),1)
1494.PHONY: libcrypto++.so
1495libcrypto++.so: libcrypto++.so$(SOLIB_VERSION_SUFFIX) | so_warning
1498libcrypto++.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS)
1499ifeq ($(XLC_COMPILER),1)
1500 $(CXX) -qmkshrobj $(SOLIB_FLAGS) -o $@ $(CXXFLAGS) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
1502 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(CXXFLAGS) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
1504ifeq ($(HAS_SOLIB_VERSION),1)
1505 -$(LN) libcrypto++.so$(SOLIB_VERSION_SUFFIX) libcrypto++.so
1506 -$(LN) libcrypto++.so$(SOLIB_VERSION_SUFFIX) libcrypto++.so$(SOLIB_COMPAT_SUFFIX)
1509libcrypto++.dylib: $(LIBOBJS) | osx_warning
1510 $(CXX) -dynamiclib -o $@ $(CXXFLAGS) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS)
1512cryptest: $(LINK_LIBRARY) $(TESTOBJS) | osx_warning
1513 $(CXX) -o $@ $(CXXFLAGS) $(TESTOBJS) $(LINK_LIBRARY_PATH)$(LINK_LIBRARY) $(LDFLAGS) $(LDLIBS)
1515# Makes it faster to test changes
1517 $(CXX) -o ct $(CXXFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS)
1519dll: cryptest.import.exe dlltest.exe
1521crypto++.dll: $(DLLOBJS)
1522 $(CXX) -shared -o $@ $(CXXFLAGS) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcrypto++.dll.a
1524libcrypto++.import.a: $(LIBIMPORTOBJS)
1525 $(AR) $(ARFLAGS) $@ $(LIBIMPORTOBJS)
1530cryptest.import.exe: crypto++.dll libcrypto++.import.a $(TESTIMPORTOBJS)
1531 $(CXX) -o $@ $(CXXFLAGS) $(TESTIMPORTOBJS) -L. -lcrypto++.dll -lcrypto++.import $(LDFLAGS) $(LDLIBS)
1533dlltest.exe: crypto++.dll $(DLLTESTOBJS)
1534 $(CXX) -o $@ $(CXXFLAGS) $(DLLTESTOBJS) -L. -lcrypto++.dll $(LDFLAGS) $(LDLIBS)
1536# Some users already have a libcrypto++.pc. We install it if the file
1537# is present. If you want one, then issue 'make libcrypto++.pc'. Be sure
1538# to use/verify PREFIX and LIBDIR below after writing the file.
1539crypto++.pc libcrypto++.pc:
1540 @echo '# Crypto++ package configuration file' > libcrypto++.pc
1541 @echo '' >> libcrypto++.pc
1542 @echo 'prefix=$(PC_PREFIX)' >> libcrypto++.pc
1543 @echo 'libdir=$(PC_LIBDIR)' >> libcrypto++.pc
1544 @echo 'includedir=$(PC_INCLUDEDIR)' >> libcrypto++.pc
1545 @echo 'datadir=$(PC_DATADIR)' >> libcrypto++.pc
1546 @echo '' >> libcrypto++.pc
1547 @echo 'Name: Crypto++' >> libcrypto++.pc
1548 @echo 'Description: Crypto++ cryptographic library' >> libcrypto++.pc
1549 @echo 'Version: 8.7' >> libcrypto++.pc
1550 @echo 'URL: https://crypto++.com/' >> libcrypto++.pc
1551 @echo '' >> libcrypto++.pc
1552 @echo 'Cflags: -I$${includedir}' >> libcrypto++.pc
1553 @echo 'Libs: -L$${libdir} -lcrypto++' >> libcrypto++.pc
1555# This recipe prepares the distro files
1556TEXT_FILES := *.h *.cpp *.S GNUmakefile GNUmakefile-cross License.txt Readme.txt Install.txt Filelist.txt Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcxproj *.filters crypto++.rc TestVectors/*.txt TestData/*.dat TestPrograms/*.cpp
1557EXEC_FILES := TestScripts/*.sh TestScripts/*.cmd
1558ifneq ($(wildcard *.sh),)
1559 EXEC_FILES += $(wildcard *.sh)
1561EXEC_DIRS := TestData/ TestVectors/ TestScripts/ TestPrograms/
1563ifeq ($(wildcard Filelist.txt),Filelist.txt)
1564DIST_FILES := $(shell cat Filelist.txt)
1569ifneq ($(IS_DARWIN),0)
1570 $(SED) -i '' -e's/[[:space:]]*$$//' *.supp *.txt .*.yml *.h *.cpp *.asm *.S
1571 $(SED) -i '' -e's/[[:space:]]*$$//' *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
1572 $(SED) -i '' -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestPrograms/*.cpp TestScripts/*.*
1575 $(SED) -i -e's/[[:space:]]*$$//' *.supp *.txt .*.yml *.h *.cpp *.asm *.S
1576 $(SED) -i -e's/[[:space:]]*$$//' *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
1577 $(SED) -i -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestPrograms/*.cpp TestScripts/*.*
1583 @-$(CHMOD) u=rwx,go=rx $(EXEC_DIRS)
1584 @-$(CHMOD) u=rw,go=r $(TEXT_FILES) *.supp .*.yml *.asm *.zip TestVectors/*.txt TestData/*.dat TestPrograms/*.cpp
1585 @-$(CHMOD) u=rwx,go=rx $(EXEC_FILES)
1586 -unix2dos --keepdate --quiet $(TEXT_FILES) .*.yml *.asm TestScripts/*.cmd TestScripts/*.txt TestScripts/*.cpp
1587 -dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.sh *.S *.supp *.mapfile TestScripts/*.sh
1588ifneq ($(IS_DARWIN),0)
1592# Build the ZIP file with source files. No documentation.
1594zip dist: | distclean convert
1595 zip -q -9 crypto++$(LIB_VER).zip $(DIST_FILES)
1597# Build the ISO to transfer the ZIP to old distros via CDROM
1600ifneq ($(IS_DARWIN),0)
1601 $(MKDIR) $(PWD)/crypto++$(LIB_VER)
1602 $(CP) crypto++$(LIB_VER).zip $(PWD)/crypto++$(LIB_VER)
1603 hdiutil makehybrid -iso -joliet -o crypto++$(LIB_VER).iso $(PWD)/crypto++$(LIB_VER)
1604 @-$(RM) -r $(PWD)/crypto++$(LIB_VER)
1605else ifneq ($(IS_LINUX)$(IS_HURD),00)
1606 $(MKDIR) $(PWD)/crypto++$(LIB_VER)
1607 $(CP) crypto++$(LIB_VER).zip $(PWD)/crypto++$(LIB_VER)
1608 genisoimage -q -o crypto++$(LIB_VER).iso $(PWD)/crypto++$(LIB_VER)
1609 @-$(RM) -r $(PWD)/crypto++$(LIB_VER)
1612# CRYPTOPP_CPU_FREQ in GHz
1613CRYPTOPP_CPU_FREQ ?= 0.0
1614.PHONY: bench benchmark benchmarks
1615bench benchmark benchmarks: cryptest
1616 @-$(RM) -f benchmarks.html
1617 ./cryptest b 2 $(CRYPTOPP_CPU_FREQ)
1619adhoc.cpp: adhoc.cpp.proto
1620ifeq ($(wildcard adhoc.cpp),)
1621 cp adhoc.cpp.proto adhoc.cpp
1626# Include dependencies, if present. You must issue `make deps` to create them.
1627ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
1628-include GNUmakefile.deps
1631# A few recipes trigger warnings for -std=c++11 and -stdlib=c++
1632NOSTD_CXXFLAGS=$(filter-out -stdlib=%,$(filter-out -std=%,$(CXXFLAGS)))
1634# Cryptogams ARM asm implementation. AES needs -mthumb for Clang
1635aes_armv4.o : aes_armv4.S
1636 $(CXX) $(strip $(CPPFLAGS) $(ASFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARM_THUMB_FLAG) -c) $<
1638# SSSE3 or NEON available
1639aria_simd.o : aria_simd.cpp
1640 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(ARIA_FLAG) -c) $<
1642# SSE, NEON or POWER7 available
1643blake2s_simd.o : blake2s_simd.cpp
1644 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
1646# SSE, NEON or POWER8 available
1647blake2b_simd.o : blake2b_simd.cpp
1648 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
1650# SSE2 or NEON available
1651chacha_simd.o : chacha_simd.cpp
1652 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
1655chacha_avx.o : chacha_avx.cpp
1656 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
1659cham_simd.o : cham_simd.cpp
1660 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CHAM_FLAG) -c) $<
1662# SSE4.2 or ARMv8a available
1663crc_simd.o : crc_simd.cpp
1664 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(CRC_FLAG) -c) $<
1668 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(DARN_FLAG) -c) $<
1671donna_sse.o : donna_sse.cpp
1672 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1675gcm_simd.o : gcm_simd.cpp
1676 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GCM_FLAG) -c) $<
1679gf2n_simd.o : gf2n_simd.cpp
1680 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(GF2N_FLAG) -c) $<
1683keccak_simd.o : keccak_simd.cpp
1684 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(KECCAK_FLAG) -c) $<
1687lea_simd.o : lea_simd.cpp
1688 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LEA_FLAG) -c) $<
1691lsh256_sse.o : lsh256_sse.cpp
1692 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_FLAG) -c) $<
1695lsh256_avx.o : lsh256_avx.cpp
1696 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH256_AVX2_FLAG) -c) $<
1699lsh512_sse.o : lsh512_sse.cpp
1700 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_FLAG) -c) $<
1703lsh512_avx.o : lsh512_avx.cpp
1704 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(LSH512_AVX2_FLAG) -c) $<
1707neon_simd.o : neon_simd.cpp
1708 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(NEON_FLAG) -c) $<
1711ppc_simd.o : ppc_simd.cpp
1712 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(ALTIVEC_FLAG) -c) $<
1714# AESNI or ARMv7a/ARMv8a available
1715rijndael_simd.o : rijndael_simd.cpp
1716 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(AES_FLAG) -c) $<
1718# SSE4.2/SHA-NI or ARMv8a available
1719sha_simd.o : sha_simd.cpp
1720 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1722# Cryptogams SHA1/SHA256/SHA512 asm implementation.
1723sha%_armv4.o : sha%_armv4.S
1724 $(CXX) $(strip $(CPPFLAGS) $(ASFLAGS) $(NOSTD_CXXFLAGS) $(CRYPTOGAMS_ARM_FLAG) -c) $<
1726sha3_simd.o : sha3_simd.cpp
1727 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA3_FLAG) -c) $<
1729# SSE4.2/SHA-NI or ARMv8a available
1730shacal2_simd.o : shacal2_simd.cpp
1731 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SHA_FLAG) -c) $<
1733# SSSE3, NEON or POWER8 available
1734simon128_simd.o : simon128_simd.cpp
1735 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
1737# SSSE3, NEON or POWER8 available
1738speck128_simd.o : speck128_simd.cpp
1739 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
1742sm3_simd.o : sm3_simd.cpp
1743 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM3_FLAG) -c) $<
1746sm4_simd.o : sm4_simd.cpp
1747 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SM4_FLAG) -c) $<
1749# IBM XLC -O3 optimization bug
1750ifeq ($(XLC_COMPILER),1)
1752 $(CXX) $(strip $(CPPFLAGS) $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1753donna_32.o : donna_32.cpp
1754 $(CXX) $(strip $(CPPFLAGS) $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1755donna_64.o : donna_64.cpp
1756 $(CXX) $(strip $(CPPFLAGS) $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1760sse_simd.o : sse_simd.cpp
1761 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1763# Don't build Rijndael with UBsan. Too much noise due to unaligned data accesses.
1764ifneq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
1765rijndael.o : rijndael.cpp
1766 $(CXX) $(strip $(subst -fsanitize=undefined,,$(CXXFLAGS)) -c) $<
1769# Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS
1770ifeq ($(findstring -DCRYPTOPP_DATA_DIR, $(CPPFLAGS)$(CXXFLAGS)),)
1771ifneq ($(strip $(CRYPTOPP_DATA_DIR)),)
1772validat%.o : validat%.cpp
1773 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" $(CXXFLAGS) -c) $<
1774bench%.o : bench%.cpp
1775 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" $(CXXFLAGS) -c) $<
1776datatest.o : datatest.cpp
1777 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" $(CXXFLAGS) -c) $<
1779 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" $(CXXFLAGS) -c) $<
1783validat1.o : validat1.cpp
1784 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) $(ALTIVEC_FLAG) -c) $<
1787 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_DLL_ONLY $(CXXFLAGS) -c) $< -o $@
1790 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_IMPORTS $(CXXFLAGS) -c) $< -o $@
1793 $(CXX) $(strip $(CPPFLAGS) -DCRYPTOPP_EXPORTS $(CXXFLAGS) -c) $< -o $@
1796 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) -c) $<
1799 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS) -c) $<
1803ifeq ($(HAS_SOLIB_VERSION),1)
1805 $(info WARNING: Only the symlinks to the shared-object library have been updated.)
1806 $(info WARNING: If the library is installed in a system directory you will need)
1807 $(info WARNING: to run 'ldconfig' to update the shared-object library cache.)
1813ifeq ($(IS_DARWIN)$(CLANG_COMPILER),11)
1814 ifeq ($(findstring -stdlib=libc++,$(CRYPTOPP_CXXFLAGS)$(CXXFLAGS)),)
1816 $(info INFO: Crypto++ was built without LLVM's libc++. If you are using the library)
1817 $(info INFO: with modern Xcode, then you should add -stdlib=libc++ to CXXFLAGS. It is)
1818 $(info INFO: already present in the makefile, and you only need to uncomment it.)
1823.PHONY: dep deps depend
1824dep deps depend GNUmakefile.deps:
1825 $(CXX) $(strip $(CPPFLAGS) $(CXXFLAGS)) -MM *.cpp > GNUmakefile.deps