Crypto++  8.0
Free C++ class library of cryptographic schemes
GNUmakefile
1 
2 ###########################################################
3 ##### System Attributes and Programs #####
4 ###########################################################
5 
6 # https://www.gnu.org/software/make/manual/make.html#Makefile-Conventions
7 # and https://www.gnu.org/prep/standards/standards.html
8 
9 SHELL = /bin/sh
10 
11 # If needed
12 TMPDIR ?= /tmp
13 # Used for ARMv7 and NEON.
14 FP_ABI ?= hard
15 # Used for feature tests
16 TOUT ?= a.out
17 TOUT := $(strip $(TOUT))
18 
19 # Command and arguments
20 AR ?= ar
21 ARFLAGS ?= -cr # ar needs the dash on OpenBSD
22 RANLIB ?= ranlib
23 
24 CP ?= cp
25 MV ?= mv
26 RM ?= rm -f
27 GREP ?= grep
28 CHMOD ?= chmod
29 MKDIR ?= mkdir -p
30 
31 LN ?= ln -sf
32 LDCONF ?= /sbin/ldconfig -n
33 
34 # Solaris provides a non-Posix grep at /usr/bin
35 ifneq ($(wildcard /usr/xpg4/bin/grep),)
36  GREP := /usr/xpg4/bin/grep
37 endif
38 
39 # Attempt to determine target machine, fallback to "this" machine.
40 # The target machine is the one the package runs on. Most people
41 # call this the "target", but not Autotools.
42 HOSTX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | cut -f 1 -d '-')
43 ifeq ($(HOSTX),)
44  HOSTX := $(shell uname -m 2>/dev/null)
45 endif
46 
47 IS_X86 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'i.86|x86|i86')
48 IS_X64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E '_64|d64')
49 IS_PPC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'ppc|power')
50 IS_PPC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'ppc64|powerpc64|power64')
51 IS_SPARC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'sun|sparc')
52 IS_SPARC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'sun|sparc64')
53 IS_ARM32 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'arm|armhf|arm7l|eabihf')
54 IS_ARMV8 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
55 
56 IS_NEON := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | $(GREP) -i -c -E 'armv7|armhf|arm7l|eabihf|armv8|aarch32|aarch64')
57 
58 # Attempt to determine platform
59 SYSTEMX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
60 ifeq ($(SYSTEMX),)
61  SYSTEMX := $(shell uname -s 2>/dev/null)
62 endif
63 
64 IS_LINUX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Linux")
65 IS_HURD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c -E "GNU|Hurd")
66 IS_MINGW := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "MinGW")
67 IS_CYGWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Cygwin")
68 IS_DARWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Darwin")
69 IS_NETBSD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "NetBSD")
70 IS_AIX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "aix")
71 IS_SUN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c -E "SunOS|Solaris")
72 
73 SUN_COMPILER := $(shell $(CXX) -V 2>&1 | $(GREP) -i -c -E 'CC: (Sun|Studio)')
74 GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -v -E '(llvm|clang)' | $(GREP) -i -c -E '(gcc|g\+\+)')
75 XLC_COMPILER := $(shell $(CXX) -qversion 2>/dev/null |$(GREP) -i -c "IBM XL")
76 CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c -E '(llvm|clang)')
77 INTEL_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c '\(icc\)')
78 
79 # Various Port compilers on OS X
80 MACPORTS_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c "macports")
81 HOMEBREW_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c "homebrew")
82 ifeq ($(IS_DARWIN),1)
83  ifneq ($(MACPORTS_COMPILER)$(HOMEBREW_COMPILER),00)
84  OSXPORT_COMPILER := 1
85  endif
86 endif
87 
88 # Enable shared object versioning for Linux and Solaris
89 HAS_SOLIB_VERSION ?= 0
90 ifneq ($(IS_LINUX)$(IS_HURD)$(IS_SUN),000)
91  HAS_SOLIB_VERSION := 1
92 endif
93 
94 # Formely adhoc.cpp was created from adhoc.cpp.proto when needed.
95 ifeq ($(wildcard adhoc.cpp),)
96 $(shell cp adhoc.cpp.proto adhoc.cpp)
97 endif
98 
99 # Tell MacPorts and Homebrew GCC to use Clang integrated assembler (only on Intel-based Macs)
100 # http://github.com/weidai11/cryptopp/issues/190
101 ifeq ($(GCC_COMPILER)$(OSXPORT_COMPILER)$(IS_PPC32)$(IS_PPC64),1100)
102  ifeq ($(findstring -Wa,-q,$(CXXFLAGS)),)
103  CXXFLAGS += -Wa,-q
104  endif
105 endif
106 
107 # Hack to skip CPU feature tests for some recipes
108 DETECT_FEATURES ?= 1
109 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),-DCRYPTOPP_DISABLE_ASM)
110  DETECT_FEATURES := 0
111 else ifeq ($(findstring clean,$(MAKECMDGOALS)),clean)
112  DETECT_FEATURES := 0
113 else ifeq ($(findstring distclean,$(MAKECMDGOALS)),distclean)
114  DETECT_FEATURES := 0
115 else ifeq ($(findstring distclean,$(MAKECMDGOALS)),trim)
116  DETECT_FEATURES := 0
117 endif
118 
119 # Strip out -Wall, -Wextra and friends for feature testing
120 ifeq ($(DETECT_FEATURES),1)
121  TCXXFLAGS := $(filter-out -Wall -Wextra -Werror% -Wunused -Wconversion -Wp%, $(CXXFLAGS))
122  ifneq ($(strip $(TCXXFLAGS)),)
123  $(info Using testing flags: $(TCXXFLAGS))
124  endif
125  #TPROG = TestPrograms/test_cxx.cxx
126  #$(info Testing compile... )
127  #$(info $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 1>/dev/null))
128 endif
129 
130 # Fixup AIX
131 ifeq ($(IS_AIX),1)
132  TPROG = TestPrograms/test_64bit.cxx
133  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
134  ifeq ($(strip $(HAVE_OPT)),0)
135  IS_PPC64=1
136  else
137  IS_PPC32=1
138  endif
139 endif
140 
141 # libc++ is LLVM's standard C++ library. If we add libc++
142 # here then all user programs must use it too. The open
143 # question is, which choice is easier on users?
144 ifneq ($(IS_DARWIN),0)
145  CXX ?= c++
146  # CXXFLAGS += -stdlib=libc++
147  AR = libtool
148  ARFLAGS = -static -o
149 endif
150 
151 ###########################################################
152 ##### General Variables #####
153 ###########################################################
154 
155 # Base CXXFLAGS used if the user did not specify them
156 ifeq ($(SUN_COMPILER),1)
157  CXXFLAGS ?= -DNDEBUG -g -xO3
158  ZOPT = -xO0
159 else
160  CXXFLAGS ?= -DNDEBUG -g2 -O3
161  ZOPT = -O0
162 endif
163 
164 # On ARM we may compile aes_armv4.S though the CC compiler
165 ifeq ($(GCC_COMPILER),1)
166  CC=gcc
167 else ifeq ($(CLANG_COMPILER),1)
168  CC=clang
169 endif
170 
171 # Default prefix for make install
172 ifeq ($(PREFIX),)
173 PREFIX = /usr/local
174 endif
175 
176 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
177 ifeq ($(DATADIR),)
178 DATADIR := $(PREFIX)/share
179 endif
180 ifeq ($(LIBDIR),)
181 LIBDIR := $(PREFIX)/lib
182 endif
183 ifeq ($(BINDIR),)
184 BINDIR := $(PREFIX)/bin
185 endif
186 ifeq ($(INCLUDEDIR),)
187 INCLUDEDIR := $(PREFIX)/include
188 endif
189 
190 # Fix CXX on Cygwin 1.1.4
191 ifeq ($(CXX),gcc)
192 CXX := g++
193 endif
194 
195 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
196 ifeq ($(ARFLAGS),rv)
197 ARFLAGS = r
198 endif
199 
200 # Clang integrated assembler will be used with -Wa,-q
201 CLANG_INTEGRATED_ASSEMBLER ?= 0
202 
203 # Original MinGW targets Win2k by default, but lacks proper Win2k support
204 # if target Windows version is not specified, use Windows XP instead
205 ifeq ($(IS_MINGW),1)
206 ifeq ($(findstring -D_WIN32_WINNT,$(CXXFLAGS)),)
207 ifeq ($(findstring -D_WIN32_WINDOWS,$(CXXFLAGS)),)
208 ifeq ($(findstring -DWINVER,$(CXXFLAGS)),)
209 ifeq ($(findstring -DNTDDI_VERSION,$(CXXFLAGS)),)
210  CXXFLAGS += -D_WIN32_WINNT=0x0501
211 endif # NTDDI_VERSION
212 endif # WINVER
213 endif # _WIN32_WINDOWS
214 endif # _WIN32_WINNT
215 endif # IS_MINGW
216 
217 # Newlib needs _XOPEN_SOURCE=600 for signals
218 TPROG = TestPrograms/test_newlib.cxx
219 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
220 ifeq ($(strip $(HAVE_OPT)),0)
221  ifeq ($(findstring -D_XOPEN_SOURCE,$(CXXFLAGS)),)
222  CXXFLAGS += -D_XOPEN_SOURCE=600
223  endif
224 endif
225 
226 ###########################################################
227 ##### X86/X32/X64 Options #####
228 ###########################################################
229 
230 ifneq ($(IS_X86)$(IS_X64),00)
231 ifeq ($(DETECT_FEATURES),1)
232 
233  ifeq ($(SUN_COMPILER),1)
234  SSE2_FLAG = -xarch=sse2
235  SSE3_FLAG = -xarch=sse3
236  SSSE3_FLAG = -xarch=ssse3
237  SSE41_FLAG = -xarch=sse4_1
238  SSE42_FLAG = -xarch=sse4_2
239  CLMUL_FLAG = -xarch=aes
240  AESNI_FLAG = -xarch=aes
241  AVX_FLAG = -xarch=avx
242  AVX2_FLAG = -xarch=avx2
243  SHANI_FLAG = -xarch=sha
244  else
245  SSE2_FLAG = -msse2
246  SSE3_FLAG = -msse3
247  SSSE3_FLAG = -mssse3
248  SSE41_FLAG = -msse4.1
249  SSE42_FLAG = -msse4.2
250  CLMUL_FLAG = -mpclmul
251  AESNI_FLAG = -maes
252  AVX_FLAG = -mavx
253  AVX2_FLAG = -mavx2
254  SHANI_FLAG = -msha
255  endif
256 
257  TPROG = TestPrograms/test_x86_sse2.cxx
258  TOPT = $(SSE2_FLAG)
259  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
260  ifeq ($(strip $(HAVE_OPT)),0)
261  CHACHA_FLAG = $(SSE2_FLAG)
262  SUN_LDFLAGS += $(SSE2_FLAG)
263  else
264  SSE2_FLAG =
265  endif
266 
267  TPROG = TestPrograms/test_x86_ssse3.cxx
268  TOPT = $(SSSE3_FLAG)
269  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
270  ifeq ($(strip $(HAVE_OPT)),0)
271  ARIA_FLAG = $(SSSE3_FLAG)
272  CHAM_FLAG = $(SSSE3_FLAG)
273  KECCAK_FLAG = $(SSSE3_FLAG)
274  LEA_FLAG = $(SSSE3_FLAG)
275  SIMECK_FLAG = $(SSSE3_FLAG)
276  SIMON64_FLAG = $(SSSE3_FLAG)
277  SIMON128_FLAG = $(SSSE3_FLAG)
278  SPECK64_FLAG = $(SSSE3_FLAG)
279  SPECK128_FLAG = $(SSSE3_FLAG)
280  SUN_LDFLAGS += $(SSSE3_FLAG)
281  else
282  SSSE3_FLAG =
283  endif
284 
285  TPROG = TestPrograms/test_x86_sse41.cxx
286  TOPT = $(SSE41_FLAG)
287  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
288  ifeq ($(strip $(HAVE_OPT)),0)
289  BLAKE2B_FLAG = $(SSE41_FLAG)
290  BLAKE2S_FLAG = $(SSE41_FLAG)
291  SIMON64_FLAG = $(SSE41_FLAG)
292  SPECK64_FLAG = $(SSE41_FLAG)
293  SUN_LDFLAGS += $(SSE41_FLAG)
294  else
295  SSE41_FLAG =
296  endif
297 
298  TPROG = TestPrograms/test_x86_sse42.cxx
299  TOPT = $(SSE42_FLAG)
300  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
301  ifeq ($(strip $(HAVE_OPT)),0)
302  CRC_FLAG = $(SSE42_FLAG)
303  SUN_LDFLAGS += $(SSE42_FLAG)
304  else
305  SSE42_FLAG =
306  endif
307 
308  TPROG = TestPrograms/test_x86_clmul.cxx
309  TOPT = $(CLMUL_FLAG)
310  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
311  ifeq ($(strip $(HAVE_OPT)),0)
312  GCM_FLAG = $(SSSE3_FLAG) $(CLMUL_FLAG)
313  GF2N_FLAG = $(CLMUL_FLAG)
314  SUN_LDFLAGS += $(CLMUL_FLAG)
315  else
316  CLMUL_FLAG =
317  endif
318 
319  TPROG = TestPrograms/test_x86_aes.cxx
320  TOPT = $(AESNI_FLAG)
321  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
322  ifeq ($(strip $(HAVE_OPT)),0)
323  AES_FLAG = $(SSE41_FLAG) $(AESNI_FLAG)
324  SM4_FLAG = $(SSSE3_FLAG) $(AESNI_FLAG)
325  SUN_LDFLAGS += $(AESNI_FLAG)
326  else
327  AESNI_FLAG =
328  endif
329 
330  TPROG = TestPrograms/test_x86_avx.cxx
331  TOPT = $(AVX_FLAG)
332  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
333  ifeq ($(strip $(HAVE_OPT)),0)
334  # XXX_FLAG = $(AVX_FLAG)
335  SUN_LDFLAGS += $(AVX_FLAG)
336  else
337  AVX_FLAG =
338  endif
339 
340  TPROG = TestPrograms/test_x86_avx2.cxx
341  TOPT = $(AVX2_FLAG)
342  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
343  ifeq ($(strip $(HAVE_OPT)),0)
344  CHACHA_AVX2_FLAG = $(AVX2_FLAG)
345  SUN_LDFLAGS += $(AVX2_FLAG)
346  else
347  AVX2_FLAG =
348  endif
349 
350  TPROG = TestPrograms/test_x86_sha.cxx
351  TOPT = $(SHANI_FLAG)
352  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
353  ifeq ($(strip $(HAVE_OPT)),0)
354  SHA_FLAG = $(SSE42_FLAG) $(SHANI_FLAG)
355  SUN_LDFLAGS += $(SHANI_FLAG)
356  else
357  SHANI_FLAG =
358  endif
359 
360  ifeq ($(SUN_COMPILER),1)
361  LDFLAGS += $(SUN_LDFLAGS)
362  endif
363 
364  ifeq ($(SSE2_FLAG),)
365  CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
366  else ifeq ($(SSE3_FLAG),)
367  CXXFLAGS += -DCRYPTOPP_DISABLE_SSE3
368  else ifeq ($(SSSE3_FLAG),)
369  CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
370  else ifeq ($(SSE41_FLAG),)
371  CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
372  else ifeq ($(SSE42_FLAG),)
373  CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
374  endif
375 
376  ifneq ($(SSE42_FLAG),)
377 
378  # Unusual GCC/Clang on Macports. It assembles AES, but not CLMUL.
379  # test_x86_clmul.s:15: no such instruction: 'pclmulqdq $0, %xmm1,%xmm0'
380  ifeq ($(CLMUL_FLAG),)
381  CXXFLAGS += -DCRYPTOPP_DISABLE_CLMUL
382  endif
383  ifeq ($(AESNI_FLAG),)
384  CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
385  endif
386 
387  ifeq ($(AVX_FLAG),)
388  CXXFLAGS += -DCRYPTOPP_DISABLE_AVX
389  else ifeq ($(AVX2_FLAG),)
390  CXXFLAGS += -DCRYPTOPP_DISABLE_AVX2
391  else ifeq ($(SHANI_FLAG),)
392  CXXFLAGS += -DCRYPTOPP_DISABLE_SHANI
393  endif
394  endif
395 
396  # Drop to SSE2 if available
397  ifeq ($(GCM_FLAG),)
398  ifneq ($(SSE2_FLAG),)
399  GCM_FLAG = $(SSE2_FLAG)
400  endif
401  endif
402 
403 # DETECT_FEATURES
404 endif
405 
406 ifneq ($(INTEL_COMPILER),0)
407  CXXFLAGS += -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180
408 
409  ICC111_OR_LATER := $(shell $(CXX) --version 2>&1 | $(GREP) -c -E "\(ICC\) ([2-9][0-9]|1[2-9]|11\.[1-9])")
410  ifeq ($(ICC111_OR_LATER),0)
411  # "internal error: backend signals" occurs on some x86 inline assembly with ICC 9 and
412  # some x64 inline assembly with ICC 11.0. If you want to use Crypto++'s assembly code
413  # with ICC, try enabling it on individual files
414  CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
415  endif
416 endif
417 
418 # Allow use of "/" operator for GNU Assembler.
419 # http://sourceware.org/bugzilla/show_bug.cgi?id=4572
420 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
421  ifeq ($(IS_SUN)$(GCC_COMPILER),11)
422  CXXFLAGS += -Wa,--divide
423  endif
424 endif
425 
426 # Most Clang cannot handle mixed asm with positional arguments, where the
427 # body is Intel style with no prefix and the templates are AT&T style.
428 # Also see https://bugs.llvm.org/show_bug.cgi?id=39895 .
429 TPROG = TestPrograms/test_mixed_asm.cxx
430 HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
431 ifneq ($(strip $(HAVE_OPT)),0)
432  CXXFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM
433 endif
434 
435 # IS_X86, IS_X32 and IS_X64
436 endif
437 
438 ###########################################################
439 ##### ARM A-32, Aach64 and NEON #####
440 ###########################################################
441 
442 ifneq ($(IS_ARM32)$(IS_ARMV8)$(IS_NEON),000)
443 ifeq ($(DETECT_FEATURES),1)
444 
445 ifeq ($(IS_ARM32)$(IS_NEON),11)
446 
447  TPROG = TestPrograms/test_arm_neon.cxx
448  TOPT = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
449  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
450  ifeq ($(strip $(HAVE_OPT)),0)
451  NEON_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
452  ARIA_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
453  AES_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
454  CRC_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
455  GCM_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
456  BLAKE2B_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
457  BLAKE2S_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
458  CHACHA_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
459  CHAM_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
460  LEA_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
461  SHA_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
462  SIMECK_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
463  SIMON64_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
464  SIMON128_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
465  SPECK64_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
466  SPECK128_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
467  SM4_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
468  else
469  CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
470  endif
471 
472 # IS_NEON
473 endif
474 
475 ifeq ($(IS_ARMV8),1)
476 
477  TPROG = TestPrograms/test_arm_acle.cxx
478  TOPT = -march=armv8-a
479  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
480  ifeq ($(strip $(HAVE_OPT)),0)
481  ACLE_FLAG += -DCRYPTOPP_ARM_ACLE_AVAILABLE=1
482  else
483  CXXFLAGS += -DCRYPTOPP_ARM_ACLE_AVAILABLE=0
484  endif
485 
486  TPROG = TestPrograms/test_arm_asimd.cxx
487  TOPT = -march=armv8-a
488  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
489  ifeq ($(strip $(HAVE_OPT)),0)
490  ASIMD_FLAG = -march=armv8-a
491  ARIA_FLAG = -march=armv8-a
492  BLAKE2B_FLAG = -march=armv8-a
493  BLAKE2S_FLAG = -march=armv8-a
494  CHACHA_FLAG = -march=armv8-a
495  CHAM_FLAG = -march=armv8-a
496  LEA_FLAG = -march=armv8-a
497  NEON_FLAG = -march=armv8-a
498  SIMECK_FLAG = -march=armv8-a
499  SIMON64_FLAG = -march=armv8-a
500  SIMON128_FLAG = -march=armv8-a
501  SPECK64_FLAG = -march=armv8-a
502  SPECK128_FLAG = -march=armv8-a
503  SM4_FLAG = -march=armv8-a
504  else
505  CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
506  endif
507 
508  ifneq ($(ASIMD_FLAG),)
509  TPROG = TestPrograms/test_arm_crc.cxx
510  TOPT = -march=armv8-a+crc
511  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
512  ifeq ($(strip $(HAVE_OPT)),0)
513  CRC_FLAG = -march=armv8-a+crc
514  else
515  CXXFLAGS += -DCRYPTOPP_ARM_CRC32_AVAILABLE=0
516  endif
517 
518  TPROG = TestPrograms/test_arm_aes.cxx
519  TOPT = -march=armv8-a+crypto
520  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
521  ifeq ($(strip $(HAVE_OPT)),0)
522  AES_FLAG = -march=armv8-a+crypto
523  else
524  CXXFLAGS += -DCRYPTOPP_ARM_AES_AVAILABLE=0
525  endif
526 
527  TPROG = TestPrograms/test_arm_pmull.cxx
528  TOPT = -march=armv8-a+crypto
529  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
530  ifeq ($(strip $(HAVE_OPT)),0)
531  GCM_FLAG = -march=armv8-a+crypto
532  GF2N_FLAG = -march=armv8-a+crypto
533  else
534  CXXFLAGS += -DCRYPTOPP_ARM_PMULL_AVAILABLE=0
535  endif
536 
537  TPROG = TestPrograms/test_arm_sha.cxx
538  TOPT = -march=armv8-a+crypto
539  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
540  ifeq ($(strip $(HAVE_OPT)),0)
541  SHA_FLAG = -march=armv8-a+crypto
542  else
543  CXXFLAGS += -DCRYPTOPP_ARM_SHA_AVAILABLE=0
544  endif
545 
546  TPROG = TestPrograms/test_arm_sm3.cxx
547  TOPT = -march=armv8.4-a+crypto
548  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
549  ifeq ($(strip $(HAVE_OPT)),0)
550  SM3_FLAG = -march=armv8.4-a+crypto
551  SM4_FLAG = -march=armv8.4-a+crypto
552  endif
553 
554  TPROG = TestPrograms/test_arm_sha3.cxx
555  TOPT = -march=armv8.4-a+crypto
556  HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
557  ifeq ($(strip $(HAVE_OPT)),0)
558  SHA3_FLAG = -march=armv8.4-a+crypto
559  endif
560 
561  # ASIMD_FLAG
562  endif
563 
564 # IS_ARMV8
565 endif
566 
567 # DETECT_FEATURES
568 endif
569 
570 # IS_ARM32, IS_ARMV8, IS_NEON
571 endif
572 
573 ###########################################################
574 ##### PowerPC #####
575 ###########################################################
576 
577 # PowerPC and PowerPC-64. Altivec is available with POWER4 with GCC and
578 # POWER6 with XLC. The tests below are crafted for IBM XLC and the LLVM
579 # front-end. XLC/LLVM only supplies POWER8 so we have to set the flags for
580 # XLC/LLVM to POWER8. I've got a feeling LLVM is going to cause trouble.
581 ifneq ($(IS_PPC32)$(IS_PPC64),00)
582 ifeq ($(DETECT_FEATURES),1)
583 
584  ifeq ($(XLC_COMPILER),1)
585  POWER9_FLAG = -qarch=pwr9 -qaltivec
586  POWER8_FLAG = -qarch=pwr8 -qaltivec
587  POWER7_FLAG = -qarch=pwr7 -qaltivec
588  POWER6_FLAG = -qarch=pwr6 -qaltivec
589  POWER5_FLAG = -qarch=pwr5 -qaltivec
590  POWER4_FLAG = -qarch=pwr4 -qaltivec
591  ALTIVEC_FLAG = -qaltivec
592  else
593  POWER9_FLAG = -mcpu=power9 -maltivec
594  POWER8_FLAG = -mcpu=power8 -maltivec
595  POWER7_FLAG = -mcpu=power7 -maltivec
596  ALTIVEC_FLAG = -maltivec
597  endif
598 
599  # XLC with LLVM front-ends failed to define XLC defines.
600  #ifeq ($(findstring -qxlcompatmacros,$(CXXFLAGS)),)
601  # TPROG = TestPrograms/test_ppc_altivec.cxx
602  # TOPT = -qxlcompatmacros
603  # HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
604  # ifeq ($(strip $(HAVE_OPT)),0)
605  # CXXFLAGS += -qxlcompatmacros
606  # endif
607  #endif
608 
609  #####################################################################
610  # Looking for a POWER8 option
611 
612  TPROG = TestPrograms/test_ppc_power9.cxx
613  TOPT = $(POWER9_FLAG)
614  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
615  ifeq ($(strip $(HAVE_OPT)),0)
616  # DARN_FLAG = $(POWER9_FLAG)
617  else
618  POWER9_FLAG =
619  endif
620 
621  TPROG = TestPrograms/test_ppc_power8.cxx
622  TOPT = $(POWER8_FLAG)
623  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
624  ifeq ($(strip $(HAVE_OPT)),0)
625  BLAKE2B_FLAG = $(POWER8_FLAG)
626  CRC_FLAG = $(POWER8_FLAG)
627  GCM_FLAG = $(POWER8_FLAG)
628  GF2N_FLAG = $(POWER8_FLAG)
629  AES_FLAG = $(POWER8_FLAG)
630  SHA_FLAG = $(POWER8_FLAG)
631  SHACAL2_FLAG = $(POWER8_FLAG)
632  SIMON128_FLAG = $(POWER8_FLAG)
633  SPECK128_FLAG = $(POWER8_FLAG)
634  else
635  POWER8_FLAG =
636  endif
637 
638  #####################################################################
639  # Looking for a POWER7 option
640 
641  TPROG = TestPrograms/test_ppc_power7.cxx
642  TOPT = $(POWER7_FLAG)
643  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
644  ifeq ($(strip $(HAVE_OPT)),0)
645  ARIA_FLAG = $(POWER7_FLAG)
646  BLAKE2S_FLAG = $(POWER7_FLAG)
647  CHACHA_FLAG = $(POWER7_FLAG)
648  CHAM_FLAG = $(POWER7_FLAG)
649  LEA_FLAG = $(POWER7_FLAG)
650  SIMECK_FLAG = $(POWER7_FLAG)
651  SIMON64_FLAG = $(POWER7_FLAG)
652  SPECK64_FLAG = $(POWER7_FLAG)
653  else
654  POWER7_FLAG =
655  endif
656 
657  #####################################################################
658  # Looking for an Altivec option
659 
660  TPROG = TestPrograms/test_ppc_altivec.cxx
661  TOPT = $(ALTIVEC_FLAG)
662  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
663  ifneq ($(strip $(HAVE_OPT)),0)
664  ALTIVEC_FLAG =
665  endif
666 
667  # XLC fixup
668  ifeq ($(XLC_COMPILER)$(ALTIVEC_FLAG),1)
669  TPROG = TestPrograms/test_ppc_altivec.cxx
670  TOPT = $(POWER4_FLAG)
671  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
672  ifeq ($(strip $(HAVE_OPT)),0)
673  ALTIVEC_FLAG = $(POWER4_FLAG)
674  else
675  TPROG = TestPrograms/test_ppc_altivec.cxx
676  TOPT = $(POWER5_FLAG)
677  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
678  ifeq ($(strip $(HAVE_OPT)),0)
679  ALTIVEC_FLAG = $(POWER5_FLAG)
680  else
681  TPROG = TestPrograms/test_ppc_altivec.cxx
682  TOPT = $(POWER6_FLAG)
683  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
684  ifeq ($(strip $(HAVE_OPT)),0)
685  ALTIVEC_FLAG = $(POWER6_FLAG)
686  else
687  ALTIVEC_FLAG =
688  endif
689  endif
690  endif
691  endif
692 
693  #####################################################################
694  # Fixups for algorithms that can drop to a lower ISA, if needed
695 
696  # Drop to Power7 if Power8 is not available.
697  ifeq ($(POWER8_FLAG),)
698  ifneq ($(POWER7_FLAG),)
699  GCM_FLAG = $(POWER7_FLAG)
700  endif
701  endif
702 
703  # Drop to Power4 if Power7 not available
704  ifeq ($(POWER7_FLAG),)
705  ifneq ($(ALTIVEC_FLAG),)
706  BLAKE2S_FLAG = $(ALTIVEC_FLAG)
707  CHACHA_FLAG = $(ALTIVEC_FLAG)
708  SIMON64_FLAG = $(ALTIVEC_FLAG)
709  SPECK64_FLAG = $(ALTIVEC_FLAG)
710  endif
711  endif
712 
713  #####################################################################
714  # Fixups for missing ISAs
715 
716  ifeq ($(ALTIVEC_FLAG),)
717  CXXFLAGS += -DCRYPTOPP_DISABLE_ALTIVEC
718  else ifeq ($(POWER8_FLAG)$(POWER7_FLAG),)
719  CXXFLAGS += -DCRYPTOPP_DISABLE_POWER7
720  else ifeq ($(POWER8_FLAG),)
721  CXXFLAGS += -DCRYPTOPP_DISABLE_POWER8
722  else ifeq ($(POWER9_FLAG),)
723  CXXFLAGS += -DCRYPTOPP_DISABLE_POWER9
724  endif
725 
726 # DETECT_FEATURES
727 endif
728 
729 # IBM XL C/C++ compiler
730 ifeq ($(XLC_COMPILER),1)
731  ifeq ($(findstring -qmaxmem,$(CXXFLAGS)),)
732  CXXFLAGS += -qmaxmem=-1
733  endif
734  # http://www-01.ibm.com/support/docview.wss?uid=swg21007500
735  ifeq ($(findstring -qrtti,$(CXXFLAGS)),)
736  CXXFLAGS += -qrtti
737  endif
738 endif
739 
740 # IS_PPC32, IS_PPC64
741 endif
742 
743 ###########################################################
744 ##### Common #####
745 ###########################################################
746 
747 # Add -fPIC for targets *except* X86, X32, Cygwin or MinGW
748 ifeq ($(IS_X86)$(IS_CYGWIN)$(IS_MINGW),000)
749  ifeq ($(findstring -fpic,$(CXXFLAGS))$(findstring -fPIC,$(CXXFLAGS)),)
750  CXXFLAGS += -fPIC
751  endif
752 endif
753 
754 # Use -pthread whenever it is available. See http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf
755 # http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling
756 ifeq ($(DETECT_FEATURES),1)
757  ifeq ($(XLC_COMPILER),1)
758  ifeq ($(findstring -qthreaded,$(CXXFLAGS)),)
759  TPROG = TestPrograms/test_pthreads.cxx
760  TOPT = -qthreaded
761  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
762  ifeq ($(strip $(HAVE_OPT)),0)
763  CXXFLAGS += -qthreaded
764  endif # CXXFLAGS
765  endif # qthreaded
766  else
767  ifeq ($(findstring -pthread,$(CXXFLAGS)),)
768  TPROG = TestPrograms/test_pthreads.cxx
769  TOPT = -pthread
770  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
771  ifeq ($(strip $(HAVE_OPT)),0)
772  CXXFLAGS += -pthread
773  endif # CXXFLAGS
774  endif # pthread
775  endif # XLC/GCC and friends
776 endif # DETECT_FEATURES
777 
778 # Remove -fPIC if present. SunCC use -KPIC, and needs the larger GOT table
779 # https://docs.oracle.com/cd/E19205-01/819-5267/bkbaq/index.html
780 ifeq ($(SUN_COMPILER),1)
781  CXXFLAGS := $(subst -fPIC,-KPIC,$(CXXFLAGS))
782  CXXFLAGS := $(subst -fpic,-KPIC,$(CXXFLAGS))
783 endif
784 
785 # Remove -fPIC if present. IBM XL C/C++ use -qpic
786 ifeq ($(XLC_COMPILER),1)
787  CXXFLAGS := $(subst -fPIC,-qpic,$(CXXFLAGS))
788  CXXFLAGS := $(subst -fpic,-qpic,$(CXXFLAGS))
789 endif
790 
791 # Add -xregs=no%appl SPARC. SunCC should not use certain registers in library code.
792 # https://docs.oracle.com/cd/E18659_01/html/821-1383/bkamt.html
793 ifeq ($(IS_SUN)$(SUN_COMPILER),11)
794  ifneq ($(IS_SPARC32)$(IS_SPARC64),00)
795  ifeq ($(findstring -xregs=no%appl,$(CXXFLAGS)),)
796  CXXFLAGS += -xregs=no%appl
797  endif # -xregs
798  endif # Sparc
799 endif # SunOS
800 
801 # Add -pipe for everything except IBM XL C/C++, SunCC and ARM.
802 # Allow ARM-64 because they seems to have >1 GB of memory
803 ifeq ($(XLC_COMPILER)$(SUN_COMPILER)$(IS_ARM32),000)
804  ifeq ($(findstring -save-temps,$(CXXFLAGS)),)
805  CXXFLAGS += -pipe
806  endif
807 endif
808 
809 # For SunOS, create a Mapfile that allows our object files
810 # to contain additional bits (like SSE4 and AES on old Xeon)
811 # http://www.oracle.com/technetwork/server-storage/solaris/hwcap-modification-139536.html
812 ifeq ($(IS_SUN)$(SUN_COMPILER),11)
813  ifneq ($(IS_X86)$(IS_X64),00)
814  ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
815  LDFLAGS += -M cryptopp.mapfile
816  endif # No CRYPTOPP_DISABLE_ASM
817  endif # X86/X32/X64
818 endif # SunOS
819 
820 # TODO: can we remove this since removing sockets?
821 #ifneq ($(IS_MINGW),0)
822 # LDLIBS += -lws2_32
823 #endif
824 
825 # TODO: can we remove this since removing sockets?
826 #ifneq ($(IS_SUN),0)
827 # LDLIBS += -lnsl -lsocket
828 #endif
829 
830 ifneq ($(IS_LINUX)$(IS_HURD),00)
831  ifeq ($(findstring -fopenmp,$(CXXFLAGS)),-fopenmp)
832  ifeq ($(findstring -lgomp,$(LDLIBS)),)
833  LDLIBS += -lgomp
834  endif # LDLIBS
835  endif # OpenMP
836 endif # IS_LINUX or IS_HURD
837 
838 # Add -errtags=yes to get the name for a warning suppression
839 ifneq ($(SUN_COMPILER),0) # override flags for CC Sun C++ compiler
840 # Add to all Solaris
841 CXXFLAGS += -template=no%extdef
842 SUN_CC10_BUGGY := $(shell $(CXX) -V 2>&1 | $(GREP) -c -E "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
843 ifneq ($(SUN_CC10_BUGGY),0)
844 # -DCRYPTOPP_INCLUDE_VECTOR_CC is needed for Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21
845 # and was fixed in May 2010. Remove it if you get "already had a body defined" errors in vector.cc
846 CXXFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
847 endif
848 AR = $(CXX)
849 ARFLAGS = -xar -o
850 RANLIB = true
851 endif
852 
853 # No ASM for Travis testing
854 ifeq ($(findstring no-asm,$(MAKECMDGOALS)),no-asm)
855  ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
856  CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
857  endif # CXXFLAGS
858 endif # No ASM
859 
860 # Native build testing. Issue 'make native'.
861 ifeq ($(findstring native,$(MAKECMDGOALS)),native)
862  NATIVE_OPT =
863 
864  # Try GCC and compatibles first
865  TPROG = TestPrograms/test_cxx.cxx
866  TOPT = -march=native
867  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
868  ifeq ($(strip $(HAVE_OPT)),0)
869  NATIVE_OPT = -march=native
870  endif # NATIVE_OPT
871 
872  # Try SunCC next
873  ifeq ($(NATIVE_OPT),)
874  TOPT = -native
875  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
876  ifeq ($(strip $(HAVE_OPT)),0)
877  NATIVE_OPT = -native
878  endif # NATIVE_OPT
879  endif
880 
881  ifneq ($(NATIVE_OPT),)
882  CXXFLAGS += $(NATIVE_OPT)
883  endif
884 
885 endif # Native
886 
887 # Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
888 ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
889  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
890  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
891  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
892  ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
893  CXXFLAGS += -fsanitize=undefined
894  endif # CXXFLAGS
895  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
896  CXXFLAGS += -DCRYPTOPP_COVERAGE
897  endif # CXXFLAGS
898 endif # UBsan
899 
900 # Address Sanitizer (Asan) testing. Issue 'make asan'.
901 ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
902  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
903  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
904  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
905  ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
906  CXXFLAGS += -fsanitize=address
907  endif # CXXFLAGS
908  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
909  CXXFLAGS += -DCRYPTOPP_COVERAGE
910  endif # CXXFLAGS
911  ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
912  CXXFLAGS += -fno-omit-frame-pointer
913  endif # CXXFLAGS
914 endif # Asan
915 
916 # LD gold linker testing. Triggered by 'LD=ld.gold'.
917 ifeq ($(findstring ld.gold,$(LD)),ld.gold)
918  ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
919  LD_GOLD = $(shell command -v ld.gold)
920  ELF_FORMAT := $(shell file $(LD_GOLD) 2>&1 | cut -d":" -f 2 | $(GREP) -i -c "elf")
921  ifneq ($(ELF_FORMAT),0)
922  LDFLAGS += -fuse-ld=gold
923  endif # ELF/ELF64
924  endif # CXXFLAGS
925 endif # Gold
926 
927 # lcov code coverage. Issue 'make coverage'.
928 ifneq ($(filter lcov coverage,$(MAKECMDGOALS)),)
929  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
930  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
931  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
932  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
933  CXXFLAGS += -DCRYPTOPP_COVERAGE
934  endif # CRYPTOPP_COVERAGE
935  ifeq ($(findstring -coverage,$(CXXFLAGS)),)
936  CXXFLAGS += -coverage
937  endif # -coverage
938 endif # GCC code coverage
939 
940 # gcov code coverage for Travis. Issue 'make codecov'.
941 ifneq ($(filter gcov codecov,$(MAKECMDGOALS)),)
942  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
943  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
944  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
945  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
946  CXXFLAGS += -DCRYPTOPP_COVERAGE
947  endif # CRYPTOPP_COVERAGE
948  ifeq ($(findstring -coverage,$(CXXFLAGS)),)
949  CXXFLAGS += -coverage
950  endif # -coverage
951 endif # GCC code coverage
952 
953 # Valgrind testing. Issue 'make valgrind'.
954 ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
955  # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
956  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
957  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
958  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
959  ifeq ($(findstring -DCRYPTOPP_VALGRIND,$(CXXFLAGS)),)
960  CXXFLAGS += -DCRYPTOPP_VALGRIND
961  endif # -DCRYPTOPP_VALGRIND
962 endif # Valgrind
963 
964 # Debug testing on GNU systems. Triggered by -DDEBUG.
965 # Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
966 ifneq ($(filter -DDEBUG -DDEBUG=1,$(CXXFLAGS)),)
967  TPROG = TestPrograms/test_cxx.cxx
968  USING_GLIBCXX := $(shell $(CXX) $(CXXFLAGS) -E $(TPROG) -o $(TOUT) 2>&1 | $(GREP) -i -c "__GLIBCXX__")
969  ifneq ($(USING_GLIBCXX),0)
970  ifeq ($(HAS_NEWLIB),0)
971  ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CXXFLAGS)),)
972  CXXFLAGS += -D_GLIBCXX_DEBUG
973  endif # CXXFLAGS
974  endif # HAS_NEWLIB
975  endif # USING_GLIBCXX
976 
977  ifeq ($(XLC_COMPILER),1)
978  TPROG = TestPrograms/test_cxx.cxx
979  TOPT = -qheapdebug -qro
980  HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
981  ifeq ($(strip $(HAVE_OPT)),0)
982  CXXFLAGS += -qheapdebug -qro
983  endif # CXXFLAGS
984  endif # XLC_COMPILER
985 endif # Debug build
986 
987 # Dead code stripping. Issue 'make lean'.
988 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
989  ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
990  CXXFLAGS += -ffunction-sections
991  endif # CXXFLAGS
992  ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
993  CXXFLAGS += -fdata-sections
994  endif # CXXFLAGS
995  ifneq ($(IS_DARWIN),0)
996  ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
997  LDFLAGS += -Wl,-dead_strip
998  endif # CXXFLAGS
999  else # BSD, Linux and Unix
1000  ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
1001  LDFLAGS += -Wl,--gc-sections
1002  endif # LDFLAGS
1003  endif # MAKECMDGOALS
1004 endif # Dead code stripping
1005 
1006 # For Shared Objects, Diff, Dist/Zip rules
1007 LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3)
1008 LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
1009 LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
1010 LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
1011 
1012 ifeq ($(strip $(LIB_PATCH)),)
1013  LIB_PATCH := 0
1014 endif
1015 
1016 ifeq ($(HAS_SOLIB_VERSION),1)
1017 # Different patchlevels and minors are compatible since 6.1
1018 SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
1019 # Linux uses -Wl,-soname
1020 ifneq ($(IS_LINUX)$(IS_HURD),00)
1021 # Linux uses full version suffix for shared library
1022 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
1023 SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
1024 endif
1025 # Solaris uses -Wl,-h
1026 ifeq ($(IS_SUN),1)
1027 # Solaris uses major version suffix for shared library, but we use major.minor
1028 # The minor version allows previous version to remain and not overwritten.
1029 # https://blogs.oracle.com/solaris/how-to-name-a-solaris-shared-object-v2
1030 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR)
1031 SOLIB_FLAGS=-Wl,-h,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
1032 endif
1033 endif # HAS_SOLIB_VERSION
1034 
1035 ###########################################################
1036 ##### Temp file cleanup #####
1037 ###########################################################
1038 
1039 # After this point no more test programs should be run.
1040 # https://github.com/weidai11/cryptopp/issues/738
1041 ifeq ($(findstring /dev/null,$(TOUT)),)
1042  # $(info TOUT is not /dev/null, cleaning $(TOUT))
1043  ifeq ($(wildcard $(TOUT)),$(TOUT))
1044  UNUSED := $(shell $(RM) $(TOUT) 2>/dev/null)
1045  endif
1046  ifeq ($(wildcard $(TOUT).dSYM/),$(TOUT).dSYM/)
1047  UNUSED := $(shell $(RM) -r $(TOUT).dSYM/ 2>/dev/null)
1048  endif
1049 endif
1050 
1051 ###########################################################
1052 ##### Source and object files #####
1053 ###########################################################
1054 
1055 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
1056 SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp winpipes.cpp cryptlib_bds.cpp,$(sort $(wildcard *.cpp)))
1057 # For Makefile.am; resource.h is Windows
1058 INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
1059 
1060 ifneq ($(IS_MINGW),0)
1061 INCL += resource.h
1062 endif
1063 
1064 # Cryptogams AES for ARMv4 and above. We couple to ARMv7.
1065 # Avoid iOS. It cannot consume the assembly.
1066 ifeq ($(IS_ARM32),1)
1067  CRYPTOGAMS_AES_FLAG = -march=armv7-a
1068  CRYPTOGAMS_AES_FLAG += -Wa,--noexecstack
1069  SRCS += aes_armv4.S
1070 endif
1071 
1072 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
1073 OBJS := $(SRCS:.cpp=.o)
1074 OBJS := $(OBJS:.S=.o)
1075 
1076 # List test.cpp first to tame C++ static initialization problems.
1077 TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp bench3.cpp datatest.cpp dlltest.cpp fipsalgt.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp validat5.cpp validat6.cpp validat7.cpp validat8.cpp validat9.cpp validat10.cpp regtest1.cpp regtest2.cpp regtest3.cpp regtest4.cpp
1078 TESTINCL := bench.h factory.h validate.h
1079 
1080 # Test objects
1081 TESTOBJS := $(TESTSRCS:.cpp=.o)
1082 LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
1083 
1084 # In Crypto++ 5.6.2 these were the source and object files for the FIPS DLL.
1085 # Since the library is on the Historical Validation List we add all files.
1086 # The 5.6.2 list is at https://github.com/weidai11/cryptopp/blob/789f81f048c9.
1087 DLLSRCS := $(SRCS)
1088 DLLOBJS := $(DLLSRCS:.cpp=.export.o)
1089 DLLOBJS := $(DLLOBJS:.S=.export.o)
1090 
1091 # Import lib testing
1092 LIBIMPORTOBJS := $(LIBOBJS:.o=.import.o)
1093 TESTIMPORTOBJS := $(TESTOBJS:.o=.import.o)
1094 DLLTESTOBJS := dlltest.dllonly.o
1095 
1096 ###########################################################
1097 ##### Targets and Recipes #####
1098 ###########################################################
1099 
1100 # Default builds program with static library only
1101 .PHONY: default
1102 default: cryptest.exe
1103 
1104 .PHONY: all static dynamic
1105 all: static dynamic cryptest.exe
1106 
1107 ifneq ($(IS_DARWIN),0)
1108 static: libcryptopp.a
1109 shared dynamic dylib: libcryptopp.dylib
1110 else
1111 static: libcryptopp.a
1112 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
1113 endif
1114 
1115 .PHONY: dep deps depend
1116 dep deps depend GNUmakefile.deps:
1117  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DISABLE_ASM) -MM *.cpp > GNUmakefile.deps
1118 
1119 # CXXFLAGS are tuned earlier.
1120 .PHONY: native no-asm asan ubsan
1121 native no-asm asan ubsan: cryptest.exe
1122 
1123 # CXXFLAGS are tuned earlier. Applications must use linker flags
1124 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
1125 .PHONY: lean
1126 lean: static dynamic cryptest.exe
1127 
1128 # May want to export CXXFLAGS="-g3 -O1"
1129 .PHONY: lcov coverage
1130 lcov coverage: cryptest.exe
1131  @-$(RM) -r ./TestCoverage/
1132  lcov --base-directory . --directory . --zerocounters -q
1133  ./cryptest.exe v
1134  ./cryptest.exe tv all
1135  ./cryptest.exe b 0.25
1136  lcov --base-directory . --directory . -c -o cryptest.info
1137  lcov --remove cryptest.info "adhoc.*" -o cryptest.info
1138  lcov --remove cryptest.info "fips140.*" -o cryptest.info
1139  lcov --remove cryptest.info "*test.*" -o cryptest.info
1140  lcov --remove cryptest.info "/usr/*" -o cryptest.info
1141  genhtml -o ./TestCoverage/ -t "Crypto++ test coverage" --num-spaces 4 cryptest.info
1142 
1143 # Travis CI and CodeCov rule
1144 .PHONY: gcov codecov
1145 gcov codecov: cryptest.exe
1146  @-$(RM) -r ./TestCoverage/
1147  ./cryptest.exe v
1148  ./cryptest.exe tv all
1149  gcov -r $(SRCS)
1150 
1151 # Should use CXXFLAGS="-g3 -O1"
1152 .PHONY: valgrind
1153 valgrind: cryptest.exe
1154  valgrind --track-origins=yes --suppressions=cryptopp.supp ./cryptest.exe v
1155 
1156 .PHONY: test check
1157 test check: cryptest.exe
1158  ./cryptest.exe v
1159 
1160 # Used to generate list of source files for Autotools, CMakeList, Android.mk, etc
1161 .PHONY: sources
1162 sources: adhoc.cpp
1163  $(info ***** Library sources *****)
1164  $(info $(filter-out $(TESTSRCS),$(SRCS)))
1165  $(info )
1166  $(info ***** Library headers *****)
1167  $(info $(filter-out $(TESTINCL),$(INCL)))
1168  $(info )
1169  $(info ***** Test sources *****)
1170  $(info $(TESTSRCS))
1171  $(info )
1172  $(info ***** Test headers *****)
1173  $(info $(TESTINCL))
1174 
1175 # Directory we want (can't specify on Doygen command line)
1176 DOCUMENT_DIRECTORY := ref$(LIB_VER)
1177 # Directory Doxygen uses (specified in Doygen config file)
1178 ifeq ($(wildcard Doxyfile),Doxyfile)
1179 DOXYGEN_DIRECTORY := $(strip $(shell $(GREP) "OUTPUT_DIRECTORY" Doxyfile | $(GREP) -v "\#" | cut -d "=" -f 2))
1180 endif
1181 # Default directory (in case its missing in the config file)
1182 ifeq ($(strip $(DOXYGEN_DIRECTORY)),)
1183 DOXYGEN_DIRECTORY := html-docs
1184 endif
1185 
1186 # Builds the documentation. Directory name is ref563, ref570, etc.
1187 .PHONY: docs html
1188 docs html:
1189  @-$(RM) -r $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/ html-docs/
1190  @-$(RM) CryptoPPRef.zip
1191  doxygen Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
1192  $(MV) $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/
1193  zip -9 CryptoPPRef.zip -x ".*" -x "*/.*" -r $(DOCUMENT_DIRECTORY)/
1194 
1195 .PHONY: clean
1196 clean:
1197  -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) rdrand-*.o $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
1198  @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
1199  @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
1200  @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct et
1201  @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
1202  @-$(RM) /tmp/adhoc.exe
1203  @-$(RM) -r /tmp/cryptopp_test/
1204  @-$(RM) -r *.exe.dSYM/ *.dylib.dSYM/
1205  @-$(RM) -r cov-int/
1206 
1207 .PHONY: autotools-clean
1208 autotools-clean:
1209  @-$(RM) -f configure.ac configure configure.in Makefile.am Makefile.in Makefile
1210  @-$(RM) -f config.guess config.status config.sub config.h.in compile depcomp
1211  @-$(RM) -f install-sh stamp-h1 ar-lib *.lo *.la *.m4 local.* lt*.sh missing
1212  @-$(RM) -f cryptest cryptestcwd libtool* libcryptopp.la libcryptopp.pc*
1213  @-$(RM) -rf m4/ auto*.cache/ .deps/ .libs/
1214 
1215 .PHONY: cmake-clean
1216 cmake-clean:
1217  @-$(RM) -f cryptopp-config.cmake CMakeLists.txt
1218  @-$(RM) -rf cmake_build/
1219 
1220 .PHONY: distclean
1221 distclean: clean autotools-clean cmake-clean
1222  -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt
1223  @-$(RM) cryptest-*.txt cryptopp.tgz libcryptopp.pc *.o *.bc *.ii *~
1224  @-$(RM) -r cryptlib.lib cryptest.exe *.suo *.sdf *.pdb Win32/ x64/ ipch/
1225  @-$(RM) -r $(LIBOBJS:.o=.obj) $(TESTOBJS:.o=.obj)
1226  @-$(RM) -r $(LIBOBJS:.o=.lst) $(TESTOBJS:.o=.lst)
1227  @-$(RM) -r TestCoverage/ ref*/
1228  @-$(RM) cryptopp$(LIB_VER)\.* CryptoPPRef.zip
1229 
1230 # Install cryptest.exe, libcryptopp.a, libcryptopp.so and libcryptopp.pc.
1231 # The library install was broken-out into its own recipe at GH #653.
1232 .PHONY: install
1233 install: cryptest.exe install-lib
1234  @-$(MKDIR) $(DESTDIR)$(BINDIR)
1235  $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
1236  $(CHMOD) 0755 $(DESTDIR)$(BINDIR)/cryptest.exe
1237  @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestData
1238  @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
1239  $(CP) TestData/*.dat $(DESTDIR)$(DATADIR)/cryptopp/TestData
1240  $(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestData/*.dat
1241  $(CP) TestVectors/*.txt $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
1242  $(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
1243 
1244 # A recipe to install only the library, and not cryptest.exe. Also
1245 # see https://github.com/weidai11/cryptopp/issues/653. Some users
1246 # already have a libcryptopp.pc. Install the *.pc file if the file
1247 # is present. If you want one, then issue 'make libcryptopp.pc'.
1248 .PHONY: install-lib
1249 install-lib:
1250  @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
1251  $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
1252  $(CHMOD) 0644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
1253 ifneq ($(wildcard libcryptopp.a),)
1254  @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1255  $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
1256  $(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
1257 endif
1258 ifneq ($(wildcard libcryptopp.dylib),)
1259  @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1260  $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
1261  $(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
1262  -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
1263 endif
1264 ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
1265  @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1266  $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
1267  $(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
1268 ifeq ($(HAS_SOLIB_VERSION),1)
1269  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
1270  $(LDCONF) $(DESTDIR)$(LIBDIR)
1271 endif
1272 endif
1273 ifneq ($(wildcard libcryptopp.pc),)
1274  @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
1275  $(CP) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig
1276  $(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
1277 endif
1278 
1279 .PHONY: remove uninstall
1280 remove uninstall:
1281  -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
1282  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
1283  -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
1284  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
1285  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
1286  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
1287  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
1288  @-$(RM) $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
1289  @-$(RM) -r $(DESTDIR)$(DATADIR)/cryptopp
1290 
1291 libcryptopp.a: $(LIBOBJS)
1292  $(AR) $(ARFLAGS) $@ $(LIBOBJS)
1293 ifeq ($(IS_SUN),0)
1294  $(RANLIB) $@
1295 endif
1296 
1297 ifeq ($(HAS_SOLIB_VERSION),1)
1298 .PHONY: libcryptopp.so
1299 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX) | so_warning
1300 endif
1301 
1302 libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS)
1303 ifeq ($(XLC_COMPILER),1)
1304  $(CXX) -qmkshrobj $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
1305 else
1306  $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
1307 endif
1308 ifeq ($(HAS_SOLIB_VERSION),1)
1309  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
1310  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
1311 endif
1312 
1313 libcryptopp.dylib: $(LIBOBJS)
1314  $(CXX) -dynamiclib -o $@ $(strip $(CXXFLAGS)) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS)
1315 
1316 cryptest.exe:libcryptopp.a $(TESTOBJS)
1317  $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
1318 
1319 # Makes it faster to test changes
1320 nolib: $(OBJS)
1321  $(CXX) -o ct $(strip $(CXXFLAGS)) $(OBJS) $(LDFLAGS) $(LDLIBS)
1322 
1323 dll: cryptest.import.exe dlltest.exe
1324 
1325 cryptopp.dll: $(DLLOBJS)
1326  $(CXX) -shared -o $@ $(strip $(CXXFLAGS)) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcryptopp.dll.a
1327 
1328 libcryptopp.import.a: $(LIBIMPORTOBJS)
1329  $(AR) $(ARFLAGS) $@ $(LIBIMPORTOBJS)
1330 ifeq ($(IS_SUN),0)
1331  $(RANLIB) $@
1332 endif
1333 
1334 cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS)
1335  $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTIMPORTOBJS) -L. -lcryptopp.dll -lcryptopp.import $(LDFLAGS) $(LDLIBS)
1336 
1337 dlltest.exe: cryptopp.dll $(DLLTESTOBJS)
1338  $(CXX) -o $@ $(strip $(CXXFLAGS)) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS)
1339 
1340 # Some users already have a libcryptopp.pc. We install it if the file
1341 # is present. If you want one, then issue 'make libcryptopp.pc'. Be sure
1342 # to use/verify PREFIX and LIBDIR below after writing the file.
1343 libcryptopp.pc:
1344  @echo '# Crypto++ package configuration file' > libcryptopp.pc
1345  @echo '' >> libcryptopp.pc
1346  @echo 'prefix=$(PREFIX)' >> libcryptopp.pc
1347  @echo 'libdir=$(LIBDIR)' >> libcryptopp.pc
1348  @echo 'includedir=$${prefix}/include' >> libcryptopp.pc
1349  @echo '' >> libcryptopp.pc
1350  @echo 'Name: Crypto++' >> libcryptopp.pc
1351  @echo 'Description: Crypto++ cryptographic library' >> libcryptopp.pc
1352  @echo 'Version: 8.1' >> libcryptopp.pc
1353  @echo 'URL: https://cryptopp.com/' >> libcryptopp.pc
1354  @echo '' >> libcryptopp.pc
1355  @echo 'Cflags: -I$${includedir}' >> libcryptopp.pc
1356  @echo 'Libs: -L$${libdir} -lcryptopp' >> libcryptopp.pc
1357 
1358 # This recipe prepares the distro files
1359 TEXT_FILES := *.h *.cpp adhoc.cpp License.txt Readme.txt Install.txt Filelist.txt Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.s *.S *.vcxproj *.filters cryptopp.rc TestVectors/*.txt TestData/*.dat TestPrograms/*.cxx TestScripts/*.sh TestScripts/*.cmd
1360 EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ TestScripts/ TestPrograms/
1361 
1362 ifeq ($(wildcard Filelist.txt),Filelist.txt)
1363 DIST_FILES := $(shell cat Filelist.txt)
1364 endif
1365 
1366 .PHONY: trim
1367 trim:
1368 ifneq ($(IS_DARWIN),0)
1369  sed -i '' -e's/[[:space:]]*$$//' *.supp *.txt *.sh .*.yml *.h *.cpp *.asm *.s *.S
1370  sed -i '' -e's/[[:space:]]*$$//' *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
1371  sed -i '' -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestPrograms/*.cxx TestScripts/*.*
1372  make convert
1373 else
1374  sed -i -e's/[[:space:]]*$$//' *.supp *.txt *.sh .*.yml *.h *.cpp *.asm *.s *.S
1375  sed -i -e's/[[:space:]]*$$//' *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
1376  sed -i -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestPrograms/*.cxx TestScripts/*.*
1377  make convert
1378 endif
1379 
1380 .PHONY: convert
1381 convert:
1382  @-$(CHMOD) 0700 TestVectors/ TestData/ TestPrograms/ TestScripts/
1383  @-$(CHMOD) 0600 $(TEXT_FILES) *.supp .*.yml *.asm *.s *.zip TestVectors/*.txt TestData/*.dat TestPrograms/*.cxx TestScripts/*.*
1384  @-$(CHMOD) 0700 $(EXEC_FILES) *.sh *.cmd TestScripts/*.sh TestScripts/*.cmd
1385  @-$(CHMOD) 0700 *.cmd *.sh GNUmakefile GNUmakefile-cross TestScripts/*.sh
1386  -unix2dos --keepdate --quiet $(TEXT_FILES) .*.yml *.asm *.cmd TestScripts/*.*
1387  -dos2unix --keepdate --quiet GNUmakefile* *.supp *.s *.S *.sh *.mapfile TestScripts/*.sh
1388 ifneq ($(IS_DARWIN),0)
1389  @-xattr -c *
1390 endif
1391 
1392 # Build the ZIP file with source files. No documentation.
1393 .PHONY: zip dist
1394 zip dist: | distclean convert
1395  zip -q -9 cryptopp$(LIB_VER).zip $(DIST_FILES)
1396 
1397 # Build the ISO to transfer the ZIP to old distros via CDROM
1398 .PHONY: iso
1399 iso: | zip
1400 ifneq ($(IS_DARWIN),0)
1401  $(MKDIR) $(PWD)/cryptopp$(LIB_VER)
1402  $(CP) cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER)
1403  hdiutil makehybrid -iso -joliet -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER)
1404  @-$(RM) -r $(PWD)/cryptopp$(LIB_VER)
1405 else ifneq ($(IS_LINUX)$(IS_HURD),00)
1406  $(MKDIR) $(PWD)/cryptopp$(LIB_VER)
1407  $(CP) cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER)
1408  genisoimage -q -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER)
1409  @-$(RM) -r $(PWD)/cryptopp$(LIB_VER)
1410 endif
1411 
1412 # CRYPTOPP_CPU_FREQ in GHz
1413 CRYPTOPP_CPU_FREQ ?= 0.0
1414 .PHONY: bench benchmark benchmarks
1415 bench benchmark benchmarks: cryptest.exe
1416  @-$(RM) -f benchmarks.html
1417  ./cryptest.exe b 2 $(CRYPTOPP_CPU_FREQ)
1418 
1419 adhoc.cpp: adhoc.cpp.proto
1420 ifeq ($(wildcard adhoc.cpp),)
1421  cp adhoc.cpp.proto adhoc.cpp
1422 else
1423  touch adhoc.cpp
1424 endif
1425 
1426 # Include dependencies, if present. You must issue `make deps` to create them.
1427 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
1428 -include GNUmakefile.deps
1429 endif # Dependencies
1430 
1431 # Cryptogams ARM asm implementation.
1432 aes_armv4.o : aes_armv4.S
1433  $(CC) $(strip $(CXXFLAGS) $(CRYPTOGAMS_AES_FLAG) -mfloat-abi=$(FP_ABI) -c) $<
1434 
1435 # SSSE3 or NEON available
1436 aria_simd.o : aria_simd.cpp
1437  $(CXX) $(strip $(CXXFLAGS) $(ARIA_FLAG) -c) $<
1438 
1439 # SSE, NEON or POWER7 available
1440 blake2s_simd.o : blake2s_simd.cpp
1441  $(CXX) $(strip $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
1442 
1443 # SSE, NEON or POWER8 available
1444 blake2b_simd.o : blake2b_simd.cpp
1445  $(CXX) $(strip $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
1446 
1447 # SSE2 or NEON available
1448 chacha_simd.o : chacha_simd.cpp
1449  $(CXX) $(strip $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
1450 
1451 # AVX2 available
1452 chacha_avx.o : chacha_avx.cpp
1453  $(CXX) $(strip $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
1454 
1455 # SSSE3 available
1456 cham_simd.o : cham_simd.cpp
1457  $(CXX) $(strip $(CXXFLAGS) $(CHAM_FLAG) -c) $<
1458 
1459 # SSE4.2 or ARMv8a available
1460 crc_simd.o : crc_simd.cpp
1461  $(CXX) $(strip $(CXXFLAGS) $(CRC_FLAG) -c) $<
1462 
1463 # Power9 available
1464 darn.o : darn.cpp
1465  $(CXX) $(strip $(CXXFLAGS) $(DARN_FLAG) -c) $<
1466 
1467 # SSE2 on i686
1468 donna_sse.o : donna_sse.cpp
1469  $(CXX) $(strip $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1470 
1471 # Carryless multiply
1472 gcm_simd.o : gcm_simd.cpp
1473  $(CXX) $(strip $(CXXFLAGS) $(GCM_FLAG) -c) $<
1474 
1475 # Carryless multiply
1476 gf2n_simd.o : gf2n_simd.cpp
1477  $(CXX) $(strip $(CXXFLAGS) $(GF2N_FLAG) -c) $<
1478 
1479 # SSSE3 available
1480 keccak_simd.o : keccak_simd.cpp
1481  $(CXX) $(strip $(CXXFLAGS) $(KECCAK_FLAG) -c) $<
1482 
1483 # SSSE3 available
1484 lea_simd.o : lea_simd.cpp
1485  $(CXX) $(strip $(CXXFLAGS) $(LEA_FLAG) -c) $<
1486 
1487 # NEON available
1488 neon_simd.o : neon_simd.cpp
1489  $(CXX) $(strip $(CXXFLAGS) $(NEON_FLAG) -c) $<
1490 
1491 # AltiVec available
1492 ppc_simd.o : ppc_simd.cpp
1493  $(CXX) $(strip $(CXXFLAGS) $(ALTIVEC_FLAG) -c) $<
1494 
1495 # Power7 available
1496 ppc_power7.o : ppc_power7.cpp
1497  $(CXX) $(strip $(CXXFLAGS) $(POWER7_FLAG) -c) $<
1498 
1499 # Power8 available
1500 ppc_power8.o : ppc_power8.cpp
1501  $(CXX) $(strip $(CXXFLAGS) $(POWER8_FLAG) -c) $<
1502 
1503 # Power9 available
1504 ppc_power9.o : ppc_power9.cpp
1505  $(CXX) $(strip $(CXXFLAGS) $(POWER9_FLAG) -c) $<
1506 
1507 # AESNI or ARMv7a/ARMv8a available
1508 rijndael_simd.o : rijndael_simd.cpp
1509  $(CXX) $(strip $(CXXFLAGS) $(AES_FLAG) -c) $<
1510 
1511 # SSE4.2/SHA-NI or ARMv8a available
1512 sha_simd.o : sha_simd.cpp
1513  $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
1514 
1515 sha3_simd.o : sha3_simd.cpp
1516  $(CXX) $(strip $(CXXFLAGS) $(SHA3_FLAG) -c) $<
1517 
1518 # SSE4.2/SHA-NI or ARMv8a available
1519 shacal2_simd.o : shacal2_simd.cpp
1520  $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
1521 
1522 # SSSE3 or NEON available
1523 simeck_simd.o : simeck_simd.cpp
1524  $(CXX) $(strip $(CXXFLAGS) $(SIMECK_FLAG) -c) $<
1525 
1526 # SSE4.1, NEON or POWER7 available
1527 simon64_simd.o : simon64_simd.cpp
1528  $(CXX) $(strip $(CXXFLAGS) $(SIMON64_FLAG) -c) $<
1529 
1530 # SSSE3, NEON or POWER8 available
1531 simon128_simd.o : simon128_simd.cpp
1532  $(CXX) $(strip $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
1533 
1534 # SSE4.1, NEON or POWER7 available
1535 speck64_simd.o : speck64_simd.cpp
1536  $(CXX) $(strip $(CXXFLAGS) $(SPECK64_FLAG) -c) $<
1537 
1538 # SSSE3, NEON or POWER8 available
1539 speck128_simd.o : speck128_simd.cpp
1540  $(CXX) $(strip $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
1541 
1542 # ARMv8.4 available
1543 sm3_simd.o : sm3_simd.cpp
1544  $(CXX) $(strip $(CXXFLAGS) $(SM3_FLAG) -c) $<
1545 
1546 # AESNI available
1547 sm4_simd.o : sm4_simd.cpp
1548  $(CXX) $(strip $(CXXFLAGS) $(SM4_FLAG) -c) $<
1549 
1550 # IBM XLC -O3 optimization bug
1551 ifeq ($(XLC_COMPILER),1)
1552 sm3.o : sm3.cpp
1553  $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1554 donna_32.o : donna_32.cpp
1555  $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1556 donna_64.o : donna_64.cpp
1557  $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1558 endif
1559 
1560 # SSE2 on i686
1561 sse_simd.o : sse_simd.cpp
1562  $(CXX) $(strip $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1563 
1564 # Don't build Rijndael with UBsan. Too much noise due to unaligned data accesses.
1565 ifneq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
1566 rijndael.o : rijndael.cpp
1567  $(CXX) $(strip $(subst -fsanitize=undefined,,$(CXXFLAGS)) -c) $<
1568 endif
1569 
1570 # Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS
1571 ifeq ($(findstring -DCRYPTOPP_DATA_DIR, $(strip $(CXXFLAGS))),)
1572 ifneq ($(strip $(CRYPTOPP_DATA_DIR)),)
1573 validat%.o : validat%.cpp
1574  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1575 bench%.o : bench%.cpp
1576  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1577 datatest.o : datatest.cpp
1578  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1579 test.o : test.cpp
1580  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1581 endif
1582 endif
1583 
1584 validat1.o : validat1.cpp
1585  $(CXX) $(strip $(CXXFLAGS) $(ALTIVEC_FLAG) -c) $<
1586 
1587 %.dllonly.o : %.cpp
1588  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DLL_ONLY -c) $< -o $@
1589 
1590 %.import.o : %.cpp
1591  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_IMPORTS -c) $< -o $@
1592 
1593 %.export.o : %.cpp
1594  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_EXPORTS -c) $< -o $@
1595 
1596 %.bc : %.cpp
1597  $(CXX) $(strip $(CXXFLAGS) -c) $<
1598 
1599 %.o : %.cpp
1600  $(CXX) $(strip $(CXXFLAGS) -c) $<
1601 
1602 .PHONY: so_warning
1603 so_warning:
1604 ifeq ($(HAS_SOLIB_VERSION),1)
1605  $(info WARNING: Only the symlinks to the shared-object library have been updated.)
1606  $(info WARNING: If the library is installed in a system directory you will need)
1607  $(info WARNING: to run 'ldconfig' to update the shared-object library cache.)
1608  $(info )
1609 endif