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