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