Crypto++ 8.2
Free C&
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
9SHELL = /bin/sh
10
11# If needed
12TMPDIR ?= /tmp
13# Used for feature tests
14TOUT ?= a.out
15TOUT := $(strip $(TOUT))
16
17# Command and arguments
18AR ?= ar
19ARFLAGS ?= -cr # ar needs the dash on OpenBSD
20RANLIB ?= ranlib
21
22CP ?= cp
23MV ?= mv
24RM ?= rm -f
25GREP ?= grep
26CHMOD ?= chmod
27MKDIR ?= mkdir -p
28
29LN ?= ln -sf
30LDCONF ?= /sbin/ldconfig -n
31
32# Solaris provides a non-Posix grep at /usr/bin
33ifneq ($(wildcard /usr/xpg4/bin/grep),)
34 GREP := /usr/xpg4/bin/grep
35endif
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.
40HOSTX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | cut -f 1 -d '-')
41ifeq ($(HOSTX),)
42 HOSTX := $(shell uname -m 2>/dev/null)
43endif
44
45IS_X86 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'i.86|x86|i86')
46IS_X64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E '_64|d64')
47IS_PPC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'ppc|power')
48IS_PPC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'ppc64|powerpc64|power64')
49IS_SPARC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'sun|sparc')
50IS_SPARC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'sun|sparc64')
51IS_ARM32 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'arm|armhf|arm7l|eabihf')
52IS_ARMV8 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'aarch32|aarch64|arm64|armv8')
53
54# Attempt to determine platform
55SYSTEMX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
56ifeq ($(SYSTEMX),)
57 SYSTEMX := $(shell uname -s 2>/dev/null)
58endif
59
60IS_LINUX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Linux")
61IS_HURD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c -E "GNU|Hurd")
62IS_MINGW := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "MinGW")
63IS_CYGWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Cygwin")
64IS_DARWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Darwin")
65IS_NETBSD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "NetBSD")
66IS_AIX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "aix")
67IS_SUN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c -E "SunOS|Solaris")
68
69SUN_COMPILER := $(shell $(CXX) -V 2>&1 | $(GREP) -i -c -E 'CC: (Sun|Studio)')
70GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -v -E '(llvm|clang)' | $(GREP) -i -c -E '(gcc|g\+\+)')
71XLC_COMPILER := $(shell $(CXX) -qversion 2>/dev/null |$(GREP) -i -c "IBM XL")
72CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c -E '(llvm|clang)')
73INTEL_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c '\‍(icc\‍)')
74
75# Various Port compilers on OS X
76MACPORTS_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c "macports")
77HOMEBREW_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c "homebrew")
78ifeq ($(IS_DARWIN),1)
79 ifneq ($(MACPORTS_COMPILER)$(HOMEBREW_COMPILER),00)
80 OSXPORT_COMPILER := 1
81 endif
82endif
83
84# Enable shared object versioning for Linux and Solaris
85HAS_SOLIB_VERSION ?= 0
86ifneq ($(IS_LINUX)$(IS_HURD)$(IS_SUN),000)
87 HAS_SOLIB_VERSION := 1
88endif
89
90# Formely adhoc.cpp was created from adhoc.cpp.proto when needed.
91ifeq ($(wildcard adhoc.cpp),)
92$(shell cp adhoc.cpp.proto adhoc.cpp)
93endif
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
97ifeq ($(GCC_COMPILER)$(OSXPORT_COMPILER)$(IS_PPC32)$(IS_PPC64),1100)
98 ifeq ($(findstring -Wa,-q,$(CXXFLAGS)),)
99 CXXFLAGS += -Wa,-q
100 endif
101endif
102
103# Hack to skip CPU feature tests for some recipes
104DETECT_FEATURES ?= 1
105ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),-DCRYPTOPP_DISABLE_ASM)
106 DETECT_FEATURES := 0
107else ifeq ($(findstring clean,$(MAKECMDGOALS)),clean)
108 DETECT_FEATURES := 0
109else ifeq ($(findstring distclean,$(MAKECMDGOALS)),distclean)
110 DETECT_FEATURES := 0
111else ifeq ($(findstring distclean,$(MAKECMDGOALS)),trim)
112 DETECT_FEATURES := 0
113endif
114
115# Strip out -Wall, -Wextra and friends for feature testing
116ifeq ($(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))
124endif
125
126# Fixup AIX
127ifeq ($(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
135endif
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?
140ifneq ($(IS_DARWIN),0)
141 CXX ?= c++
142 # CXXFLAGS += -stdlib=libc++
143 AR = libtool
144 ARFLAGS = -static -o
145endif
146
147###########################################################
148##### General Variables #####
149###########################################################
150
151# Base CXXFLAGS used if the user did not specify them
152ifeq ($(SUN_COMPILER),1)
153 CXXFLAGS ?= -DNDEBUG -g -xO3
154 ZOPT = -xO0
155else
156 CXXFLAGS ?= -DNDEBUG -g2 -O3
157 ZOPT = -O0
158endif
159
160# On ARM we may compile aes_armv4.S though the CC compiler
161ifeq ($(GCC_COMPILER),1)
162 CC=gcc
163else ifeq ($(CLANG_COMPILER),1)
164 CC=clang
165endif
166
167# Default prefix for make install
168ifeq ($(PREFIX),)
169PREFIX = /usr/local
170endif
171
172# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
173ifeq ($(DATADIR),)
174DATADIR := $(PREFIX)/share
175endif
176ifeq ($(LIBDIR),)
177LIBDIR := $(PREFIX)/lib
178endif
179ifeq ($(BINDIR),)
180BINDIR := $(PREFIX)/bin
181endif
182ifeq ($(INCLUDEDIR),)
183INCLUDEDIR := $(PREFIX)/include
184endif
185
186# Fix CXX on Cygwin 1.1.4
187ifeq ($(CXX),gcc)
188CXX := g++
189endif
190
191# We honor ARFLAGS, but the "v" option used by default causes a noisy make
192ifeq ($(ARFLAGS),rv)
193ARFLAGS = r
194endif
195
196# Clang integrated assembler will be used with -Wa,-q
197CLANG_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
201ifeq ($(IS_MINGW),1)
202ifeq ($(findstring -D_WIN32_WINNT,$(CXXFLAGS)),)
203ifeq ($(findstring -D_WIN32_WINDOWS,$(CXXFLAGS)),)
204ifeq ($(findstring -DWINVER,$(CXXFLAGS)),)
205ifeq ($(findstring -DNTDDI_VERSION,$(CXXFLAGS)),)
206 CXXFLAGS += -D_WIN32_WINNT=0x0501
207endif # NTDDI_VERSION
208endif # WINVER
209endif # _WIN32_WINDOWS
210endif # _WIN32_WINNT
211endif # IS_MINGW
212
213# Newlib needs _XOPEN_SOURCE=600 for signals
214TPROG = TestPrograms/test_newlib.cxx
215HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
216ifeq ($(strip $(HAVE_OPT)),0)
217 ifeq ($(findstring -D_XOPEN_SOURCE,$(CXXFLAGS)),)
218 CXXFLAGS += -D_XOPEN_SOURCE=600
219 endif
220endif
221
222###########################################################
223##### X86/X32/X64 Options #####
224###########################################################
225
226ifneq ($(IS_X86)$(IS_X64),00)
227ifeq ($(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
400endif
401
402ifneq ($(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
412endif
413
414# Allow use of "/" operator for GNU Assembler.
415# http://sourceware.org/bugzilla/show_bug.cgi?id=4572
416ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
417 ifeq ($(IS_SUN)$(GCC_COMPILER),11)
418 CXXFLAGS += -Wa,--divide
419 endif
420endif
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 .
425TPROG = TestPrograms/test_mixed_asm.cxx
426HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l)
427ifneq ($(strip $(HAVE_OPT)),0)
428 CXXFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM
429endif
430
431# IS_X86, IS_X32 and IS_X64
432endif
433
434###########################################################
435##### ARM A-32, Aach64 and NEON #####
436###########################################################
437
438ifneq ($(IS_ARM32)$(IS_ARMV8),00)
439ifeq ($(DETECT_FEATURES),1)
440
441ifneq ($(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
469endif
470
471ifeq ($(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
561endif
562
563# DETECT_FEATURES
564endif
565
566# IS_ARM32, IS_ARMV8
567endif
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.
577ifneq ($(IS_PPC32)$(IS_PPC64),00)
578ifeq ($(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
716endif
717
718# IBM XL C/C++ compiler
719ifeq ($(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
727endif
728
729# IS_PPC32, IS_PPC64
730endif
731
732###########################################################
733##### Common #####
734###########################################################
735
736# Add -fPIC for targets *except* X86, X32, Cygwin or MinGW
737ifeq ($(IS_X86)$(IS_CYGWIN)$(IS_MINGW),000)
738 ifeq ($(findstring -fpic,$(CXXFLAGS))$(findstring -fPIC,$(CXXFLAGS)),)
739 CXXFLAGS += -fPIC
740 endif
741endif
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
745ifeq ($(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
765endif # 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
769ifeq ($(SUN_COMPILER),1)
770 CXXFLAGS := $(subst -fPIC,-KPIC,$(CXXFLAGS))
771 CXXFLAGS := $(subst -fpic,-KPIC,$(CXXFLAGS))
772endif
773
774# Remove -fPIC if present. IBM XL C/C++ use -qpic
775ifeq ($(XLC_COMPILER),1)
776 CXXFLAGS := $(subst -fPIC,-qpic,$(CXXFLAGS))
777 CXXFLAGS := $(subst -fpic,-qpic,$(CXXFLAGS))
778endif
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
782ifeq ($(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
788endif # 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
792ifeq ($(XLC_COMPILER)$(SUN_COMPILER)$(IS_ARM32),000)
793 ifeq ($(findstring -save-temps,$(CXXFLAGS)),)
794 CXXFLAGS += -pipe
795 endif
796endif
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
801ifeq ($(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
807endif # 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
819ifneq ($(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
825endif # IS_LINUX or IS_HURD
826
827# Add -errtags=yes to get the name for a warning suppression
828ifneq ($(SUN_COMPILER),0) # override flags for CC Sun C++ compiler
829# Add to all Solaris
830CXXFLAGS += -template=no%extdef
831SUN_CC10_BUGGY := $(shell $(CXX) -V 2>&1 | $(GREP) -c -E "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
832ifneq ($(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
835CXXFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
836endif
837AR = $(CXX)
838ARFLAGS = -xar -o
839RANLIB = true
840endif
841
842# No ASM for Travis testing
843ifeq ($(findstring no-asm,$(MAKECMDGOALS)),no-asm)
844 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
845 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
846 endif # CXXFLAGS
847endif # No ASM
848
849# Native build testing. Issue 'make native'.
850ifeq ($(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
874endif # Native
875
876# Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
877ifeq ($(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
887endif # UBsan
888
889# Address Sanitizer (Asan) testing. Issue 'make asan'.
890ifeq ($(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
903endif # Asan
904
905# LD gold linker testing. Triggered by 'LD=ld.gold'.
906ifeq ($(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
914endif # Gold
915
916# lcov code coverage. Issue 'make coverage'.
917ifneq ($(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
927endif # GCC code coverage
928
929# gcov code coverage for Travis. Issue 'make codecov'.
930ifneq ($(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
940endif # GCC code coverage
941
942# Valgrind testing. Issue 'make valgrind'.
943ifneq ($(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
951endif # 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
955ifneq ($(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
974endif # Debug build
975
976# Dead code stripping. Issue 'make lean'.
977ifeq ($(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
993endif # Dead code stripping
994
995# For Shared Objects, Diff, Dist/Zip rules
996LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3)
997LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
998LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
999LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
1000
1001ifeq ($(strip $(LIB_PATCH)),)
1002 LIB_PATCH := 0
1003endif
1004
1005ifeq ($(HAS_SOLIB_VERSION),1)
1006# Different patchlevels and minors are compatible since 6.1
1007SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
1008# Linux uses -Wl,-soname
1009ifneq ($(IS_LINUX)$(IS_HURD),00)
1010# Linux uses full version suffix for shared library
1011SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
1012SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
1013endif
1014# Solaris uses -Wl,-h
1015ifeq ($(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
1019SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR)
1020SOLIB_FLAGS=-Wl,-h,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
1021endif
1022endif # 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
1030ifeq ($(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
1038endif
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.
1045SRCS := 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
1047INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
1048
1049ifneq ($(IS_MINGW),0)
1050INCL += resource.h
1051endif
1052
1053# Cryptogams AES for ARMv4 and above. We couple to ARMv7.
1054# Avoid iOS. It cannot consume the assembly.
1055ifeq ($(IS_ARM32),1)
1056 CRYPTOGAMS_AES_FLAG = -march=armv7-a
1057 CRYPTOGAMS_AES_FLAG += -Wa,--noexecstack
1058 SRCS += aes_armv4.S
1059endif
1060
1061# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
1062OBJS := $(SRCS:.cpp=.o)
1063OBJS := $(OBJS:.S=.o)
1064
1065# List test.cpp first to tame C++ static initialization problems.
1066TESTSRCS := 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
1067TESTINCL := bench.h factory.h validate.h
1068
1069# Test objects
1070TESTOBJS := $(TESTSRCS:.cpp=.o)
1071LIBOBJS := $(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.
1076DLLSRCS := $(SRCS)
1077DLLOBJS := $(DLLSRCS:.cpp=.export.o)
1078DLLOBJS := $(DLLOBJS:.S=.export.o)
1079
1080# Import lib testing
1081LIBIMPORTOBJS := $(LIBOBJS:.o=.import.o)
1082TESTIMPORTOBJS := $(TESTOBJS:.o=.import.o)
1083DLLTESTOBJS := dlltest.dllonly.o
1084
1085###########################################################
1086##### Targets and Recipes #####
1087###########################################################
1088
1089# Default builds program with static library only
1090.PHONY: default
1091default: cryptest.exe
1092
1093.PHONY: all static dynamic
1094all: static dynamic cryptest.exe
1095
1096ifneq ($(IS_DARWIN),0)
1097static: libcryptopp.a
1098shared dynamic dylib: libcryptopp.dylib
1099else
1100static: libcryptopp.a
1101shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
1102endif
1103
1104.PHONY: dep deps depend
1105dep 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
1110native 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
1115lean: static dynamic cryptest.exe
1116
1117# May want to export CXXFLAGS="-g3 -O1"
1118.PHONY: lcov coverage
1119lcov 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
1134gcov 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
1142valgrind: cryptest.exe
1143 valgrind --track-origins=yes --suppressions=cryptopp.supp ./cryptest.exe v
1144
1145.PHONY: test check
1146test 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
1151sources: 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)
1165DOCUMENT_DIRECTORY := ref$(LIB_VER)
1166# Directory Doxygen uses (specified in Doygen config file)
1167ifeq ($(wildcard Doxyfile),Doxyfile)
1168DOXYGEN_DIRECTORY := $(strip $(shell $(GREP) "OUTPUT_DIRECTORY" Doxyfile | $(GREP) -v "\#" | cut -d "=" -f 2))
1169endif
1170# Default directory (in case its missing in the config file)
1171ifeq ($(strip $(DOXYGEN_DIRECTORY)),)
1172DOXYGEN_DIRECTORY := html-docs
1173endif
1174
1175# Builds the documentation. Directory name is ref563, ref570, etc.
1176.PHONY: docs html
1177docs 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
1185clean:
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
1197autotools-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
1205cmake-clean:
1206 @-$(RM) -f cryptopp-config.cmake CMakeLists.txt
1207 @-$(RM) -rf cmake_build/
1208
1209.PHONY: distclean
1210distclean: 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
1222install: 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
1238install-lib:
1239 @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
1240 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
1241 $(CHMOD) 0644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
1242ifneq ($(wildcard libcryptopp.a),)
1243 @-$(MKDIR) $(DESTDIR)$(LIBDIR)
1244 $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
1245 $(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
1246endif
1247ifneq ($(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
1252endif
1253ifneq ($(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)
1257ifeq ($(HAS_SOLIB_VERSION),1)
1258 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
1259 $(LDCONF) $(DESTDIR)$(LIBDIR)
1260endif
1261endif
1262ifneq ($(wildcard libcryptopp.pc),)
1263 @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
1264 $(CP) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig
1265 $(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
1266endif
1267
1268.PHONY: remove uninstall
1269remove 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
1280libcryptopp.a: $(LIBOBJS)
1281 $(AR) $(ARFLAGS) $@ $(LIBOBJS)
1282ifeq ($(IS_SUN),0)
1283 $(RANLIB) $@
1284endif
1285
1286ifeq ($(HAS_SOLIB_VERSION),1)
1287.PHONY: libcryptopp.so
1288libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX) | so_warning
1289endif
1290
1291libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS)
1292ifeq ($(XLC_COMPILER),1)
1293 $(CXX) -qmkshrobj $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
1294else
1295 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
1296endif
1297ifeq ($(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)
1300endif
1301
1302libcryptopp.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
1305cryptest.exe:libcryptopp.a $(TESTOBJS)
1306 $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
1307
1308# Makes it faster to test changes
1309nolib: $(OBJS)
1310 $(CXX) -o ct $(strip $(CXXFLAGS)) $(OBJS) $(LDFLAGS) $(LDLIBS)
1311
1312dll: cryptest.import.exe dlltest.exe
1313
1314cryptopp.dll: $(DLLOBJS)
1315 $(CXX) -shared -o $@ $(strip $(CXXFLAGS)) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcryptopp.dll.a
1316
1317libcryptopp.import.a: $(LIBIMPORTOBJS)
1318 $(AR) $(ARFLAGS) $@ $(LIBIMPORTOBJS)
1319ifeq ($(IS_SUN),0)
1320 $(RANLIB) $@
1321endif
1322
1323cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS)
1324 $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTIMPORTOBJS) -L. -lcryptopp.dll -lcryptopp.import $(LDFLAGS) $(LDLIBS)
1325
1326dlltest.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.
1332libcryptopp.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
1348TEXT_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
1349EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ TestScripts/ TestPrograms/
1350
1351ifeq ($(wildcard Filelist.txt),Filelist.txt)
1352DIST_FILES := $(shell cat Filelist.txt)
1353endif
1354
1355.PHONY: trim
1356trim:
1357ifneq ($(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
1362else
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
1367endif
1368
1369.PHONY: convert
1370convert:
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
1377ifneq ($(IS_DARWIN),0)
1378 @-xattr -c *
1379endif
1380
1381# Build the ZIP file with source files. No documentation.
1382.PHONY: zip dist
1383zip 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
1388iso: | zip
1389ifneq ($(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)
1394else 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)
1399endif
1400
1401# CRYPTOPP_CPU_FREQ in GHz
1402CRYPTOPP_CPU_FREQ ?= 0.0
1403.PHONY: bench benchmark benchmarks
1404bench benchmark benchmarks: cryptest.exe
1405 @-$(RM) -f benchmarks.html
1406 ./cryptest.exe b 2 $(CRYPTOPP_CPU_FREQ)
1407
1408adhoc.cpp: adhoc.cpp.proto
1409ifeq ($(wildcard adhoc.cpp),)
1410 cp adhoc.cpp.proto adhoc.cpp
1411else
1412 touch adhoc.cpp
1413endif
1414
1415# Include dependencies, if present. You must issue `make deps` to create them.
1416ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
1417-include GNUmakefile.deps
1418endif # Dependencies
1419
1420# Cryptogams ARM asm implementation.
1421aes_armv4.o : aes_armv4.S
1422 $(CC) $(strip $(CXXFLAGS) $(CRYPTOGAMS_AES_FLAG) -c) $<
1423
1424# SSSE3 or NEON available
1425aria_simd.o : aria_simd.cpp
1426 $(CXX) $(strip $(CXXFLAGS) $(ARIA_FLAG) -c) $<
1427
1428# SSE, NEON or POWER7 available
1429blake2s_simd.o : blake2s_simd.cpp
1430 $(CXX) $(strip $(CXXFLAGS) $(BLAKE2S_FLAG) -c) $<
1431
1432# SSE, NEON or POWER8 available
1433blake2b_simd.o : blake2b_simd.cpp
1434 $(CXX) $(strip $(CXXFLAGS) $(BLAKE2B_FLAG) -c) $<
1435
1436# SSE2 or NEON available
1437chacha_simd.o : chacha_simd.cpp
1438 $(CXX) $(strip $(CXXFLAGS) $(CHACHA_FLAG) -c) $<
1439
1440# AVX2 available
1441chacha_avx.o : chacha_avx.cpp
1442 $(CXX) $(strip $(CXXFLAGS) $(CHACHA_AVX2_FLAG) -c) $<
1443
1444# SSSE3 available
1445cham_simd.o : cham_simd.cpp
1446 $(CXX) $(strip $(CXXFLAGS) $(CHAM_FLAG) -c) $<
1447
1448# SSE4.2 or ARMv8a available
1449crc_simd.o : crc_simd.cpp
1450 $(CXX) $(strip $(CXXFLAGS) $(CRC_FLAG) -c) $<
1451
1452# Power9 available
1453darn.o : darn.cpp
1454 $(CXX) $(strip $(CXXFLAGS) $(DARN_FLAG) -c) $<
1455
1456# SSE2 on i686
1457donna_sse.o : donna_sse.cpp
1458 $(CXX) $(strip $(CXXFLAGS) $(SSE2_FLAG) -c) $<
1459
1460# Carryless multiply
1461gcm_simd.o : gcm_simd.cpp
1462 $(CXX) $(strip $(CXXFLAGS) $(GCM_FLAG) -c) $<
1463
1464# Carryless multiply
1465gf2n_simd.o : gf2n_simd.cpp
1466 $(CXX) $(strip $(CXXFLAGS) $(GF2N_FLAG) -c) $<
1467
1468# SSSE3 available
1469keccak_simd.o : keccak_simd.cpp
1470 $(CXX) $(strip $(CXXFLAGS) $(KECCAK_FLAG) -c) $<
1471
1472# SSSE3 available
1473lea_simd.o : lea_simd.cpp
1474 $(CXX) $(strip $(CXXFLAGS) $(LEA_FLAG) -c) $<
1475
1476# NEON available
1477neon_simd.o : neon_simd.cpp
1478 $(CXX) $(strip $(CXXFLAGS) $(NEON_FLAG) -c) $<
1479
1480# AltiVec available
1481ppc_simd.o : ppc_simd.cpp
1482 $(CXX) $(strip $(CXXFLAGS) $(ALTIVEC_FLAG) -c) $<
1483
1484# Power7 available
1485ppc_power7.o : ppc_power7.cpp
1486 $(CXX) $(strip $(CXXFLAGS) $(POWER7_FLAG) -c) $<
1487
1488# Power8 available
1489ppc_power8.o : ppc_power8.cpp
1490 $(CXX) $(strip $(CXXFLAGS) $(POWER8_FLAG) -c) $<
1491
1492# Power9 available
1493ppc_power9.o : ppc_power9.cpp
1494 $(CXX) $(strip $(CXXFLAGS) $(POWER9_FLAG) -c) $<
1495
1496# AESNI or ARMv7a/ARMv8a available
1497rijndael_simd.o : rijndael_simd.cpp
1498 $(CXX) $(strip $(CXXFLAGS) $(AES_FLAG) -c) $<
1499
1500# SSE4.2/SHA-NI or ARMv8a available
1501sha_simd.o : sha_simd.cpp
1502 $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
1503
1504sha3_simd.o : sha3_simd.cpp
1505 $(CXX) $(strip $(CXXFLAGS) $(SHA3_FLAG) -c) $<
1506
1507# SSE4.2/SHA-NI or ARMv8a available
1508shacal2_simd.o : shacal2_simd.cpp
1509 $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
1510
1511# SSSE3 or NEON available
1512simeck_simd.o : simeck_simd.cpp
1513 $(CXX) $(strip $(CXXFLAGS) $(SIMECK_FLAG) -c) $<
1514
1515# SSE4.1, NEON or POWER7 available
1516simon64_simd.o : simon64_simd.cpp
1517 $(CXX) $(strip $(CXXFLAGS) $(SIMON64_FLAG) -c) $<
1518
1519# SSSE3, NEON or POWER8 available
1520simon128_simd.o : simon128_simd.cpp
1521 $(CXX) $(strip $(CXXFLAGS) $(SIMON128_FLAG) -c) $<
1522
1523# SSE4.1, NEON or POWER7 available
1524speck64_simd.o : speck64_simd.cpp
1525 $(CXX) $(strip $(CXXFLAGS) $(SPECK64_FLAG) -c) $<
1526
1527# SSSE3, NEON or POWER8 available
1528speck128_simd.o : speck128_simd.cpp
1529 $(CXX) $(strip $(CXXFLAGS) $(SPECK128_FLAG) -c) $<
1530
1531# ARMv8.4 available
1532sm3_simd.o : sm3_simd.cpp
1533 $(CXX) $(strip $(CXXFLAGS) $(SM3_FLAG) -c) $<
1534
1535# AESNI available
1536sm4_simd.o : sm4_simd.cpp
1537 $(CXX) $(strip $(CXXFLAGS) $(SM4_FLAG) -c) $<
1538
1539# IBM XLC -O3 optimization bug
1540ifeq ($(XLC_COMPILER),1)
1541sm3.o : sm3.cpp
1542 $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1543donna_32.o : donna_32.cpp
1544 $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1545donna_64.o : donna_64.cpp
1546 $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1547endif
1548
1549# SSE2 on i686
1550sse_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.
1554ifneq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
1555rijndael.o : rijndael.cpp
1556 $(CXX) $(strip $(subst -fsanitize=undefined,,$(CXXFLAGS)) -c) $<
1557endif
1558
1559# Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS
1560ifeq ($(findstring -DCRYPTOPP_DATA_DIR, $(strip $(CXXFLAGS))),)
1561ifneq ($(strip $(CRYPTOPP_DATA_DIR)),)
1562validat%.o : validat%.cpp
1563 $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1564bench%.o : bench%.cpp
1565 $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1566datatest.o : datatest.cpp
1567 $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1568test.o : test.cpp
1569 $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1570endif
1571endif
1572
1573validat1.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
1592so_warning:
1593ifeq ($(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 )
1598endif