Crypto++ 7.0 Free C++ class library of cryptographic schemes

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