Crypto++  6.1
Free C++ class library of cryptographic schemes
GNUmakefile
1 ###########################################################
2 ##### System Attributes and Programs #####
3 ###########################################################
4 
5 # https://www.gnu.org/software/make/manual/make.html#Makefile-Conventions
6 # and https://www.gnu.org/prep/standards/standards.html
7 
8 SHELL = /bin/sh
9 
10 # If needed
11 TMPDIR ?= /tmp
12 # Used for ARMv7 and NEON.
13 FP_ABI ?= hard
14 
15 # Command and arguments
16 AR ?= ar
17 ARFLAGS ?= -cr # ar needs the dash on OpenBSD
18 RANLIB ?= ranlib
19 
20 CP ?= cp
21 MV ?= mv
22 RM ?= rm -f
23 CHMOD ?= chmod
24 MKDIR ?= mkdir -p
25 
26 LN ?= ln -sf
27 LDCONF ?= /sbin/ldconfig -n
28 
29 INSTALL = install
30 INSTALL_PROGRAM = $(INSTALL)
31 INSTALL_DATA = $(INSTALL) -m 644
32 
33 # Solaris provides a non-Posix shell at /usr/bin
34 ifneq ($(wildcard /usr/xpg4/bin),)
35  GREP ?= /usr/xpg4/bin/grep
36 else
37  GREP ?= grep
38 endif
39 
40 # Attempt to determine host machine, fallback to "this" machine.
41 # The host machine is the one the package runs on. Most people
42 # call this the "target", but not Autotools.
43 HOSTX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | cut -f 1 -d '-')
44 ifeq ($(HOSTX),)
45  HOSTX := $(shell uname -m 2>/dev/null)
46 endif
47 
48 IS_X86 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'i.86|x86|i86')
49 IS_X64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E '_64|d64')
50 IS_PPC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c -E 'ppc|power')
51 IS_PPC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'ppc64|power64')
52 IS_ARM32 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'arm|armhf|arm7l|eabihf')
53 IS_ARMV8 := $(shell echo "$(HOSTX)" | $(GREP) -i -c -E 'aarch32|aarch64')
54 IS_SPARC32 := $(shell echo "$(HOSTX)" | $(GREP) -v "64" | $(GREP) -i -c 'sparc')
55 IS_SPARC64 := $(shell echo "$(HOSTX)" | $(GREP) -i -c 'sparc64')
56 
57 IS_NEON := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null | $(GREP) -i -c -E 'armv7|armhf|arm7l|eabihf|armv8|aarch32|aarch64')
58 
59 SYSTEMX := $(shell $(CXX) $(CXXFLAGS) -dumpmachine 2>/dev/null)
60 IS_LINUX := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Linux")
61 IS_MINGW := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "MinGW")
62 IS_CYGWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Cygwin")
63 IS_DARWIN := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "Darwin")
64 IS_NETBSD := $(shell echo "$(SYSTEMX)" | $(GREP) -i -c "NetBSD")
65 
66 UNAMEX := $(shell uname -s 2>&1)
67 IS_AIX := $(shell echo "$(UNAMEX)" | $(GREP) -i -c "aix")
68 IS_SUN := $(shell echo "$(UNAMEX)" | $(GREP) -i -c "SunOS")
69 
70 SUN_COMPILER := $(shell $(CXX) -V 2>&1 | $(GREP) -i -c -E 'CC: (Sun|Studio)')
71 GCC_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -v -E '(llvm|clang)' | $(GREP) -i -c -E '(gcc|g\+\+)')
72 XLC_COMPILER := $(shell $(CXX) -qversion 2>/dev/null |$(GREP) -i -c "IBM XL")
73 CLANG_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c -E '(llvm|clang)')
74 INTEL_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c '\(icc\)')
75 
76 # Various Port compilers on OS X
77 MACPORTS_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c "macports")
78 HOMEBREW_COMPILER := $(shell $(CXX) --version 2>/dev/null | $(GREP) -i -c "homebrew")
79 ifeq ($(IS_DARWIN),1)
80  ifneq ($(MACPORTS_COMPILER)$(HOMEBREW_COMPILER),00)
81  OSXPORT_COMPILER := 1
82  endif
83 endif
84 
85 # Sun Studio 12.0 provides SunCC 0x0510; and Sun Studio 12.3 provides SunCC 0x0512
86 SUNCC_VERSION := $(subst `,',$(shell $(CXX) -V 2>&1))
87 SUNCC_510_OR_LATER := $(shell echo "$(SUNCC_VERSION)" | $(GREP) -i -c -E "CC: (Sun|Studio) .* (5\.1[0-9]|5\.[2-9]|6\.)")
88 SUNCC_511_OR_LATER := $(shell echo "$(SUNCC_VERSION)" | $(GREP) -i -c -E "CC: (Sun|Studio) .* (5\.1[1-9]|5\.[2-9]|6\.)")
89 SUNCC_512_OR_LATER := $(shell echo "$(SUNCC_VERSION)" | $(GREP) -i -c -E "CC: (Sun|Studio) .* (5\.1[2-9]|5\.[2-9]|6\.)")
90 SUNCC_513_OR_LATER := $(shell echo "$(SUNCC_VERSION)" | $(GREP) -i -c -E "CC: (Sun|Studio) .* (5\.1[3-9]|5\.[2-9]|6\.)")
91 
92 # Enable shared object versioning for Linux
93 HAS_SOLIB_VERSION := $(IS_LINUX)
94 
95 # Fixup SunOS
96 ifeq ($(IS_SUN),1)
97 IS_X86 := $(shell isainfo -k 2>/dev/null | $(GREP) -i -c "i386")
98 IS_X64 := $(shell isainfo -k 2>/dev/null | $(GREP) -i -c "amd64")
99 endif
100 
101 # Fixup AIX
102 ifeq ($(IS_AIX),1)
103  # https://www-01.ibm.com/support/docview.wss?uid=swg21256116
104  IS_64BIT := $(shell getconf KERNEL_BITMODE | $(GREP) -i -c "64")
105  ifeq ($(IS_64BIT),1)
106  IS_PPC32 := 0
107  IS_PPC64 := 1
108  else
109  IS_PPC32 := 1
110  IS_PPC64 := 0
111  endif
112 endif
113 
114 # Newlib needs _XOPEN_SOURCE=600 for signals
115 HAS_NEWLIB := $(shell $(CXX) -x c++ $(CXXFLAGS) -dM -E adhoc.cpp.proto 2>&1 | $(GREP) -i -c "__NEWLIB__")
116 
117 ###########################################################
118 ##### General Variables #####
119 ###########################################################
120 
121 # Base CXXFLAGS used if the user did not specify them
122 ifeq ($(SUN_COMPILER),1)
123  ifeq ($(SUNCC_512_OR_LATER),1)
124  CXXFLAGS ?= -DNDEBUG -g3 -xO3
125  else
126  CXXFLAGS ?= -DNDEBUG -g -xO3
127  endif
128 else
129  CXXFLAGS ?= -DNDEBUG -g2 -O3
130 endif
131 
132 # Default prefix for make install
133 ifeq ($(PREFIX),)
134 PREFIX = /usr/local
135 endif
136 
137 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
138 ifeq ($(DATADIR),)
139 DATADIR := $(PREFIX)/share
140 endif
141 ifeq ($(LIBDIR),)
142 LIBDIR := $(PREFIX)/lib
143 endif
144 ifeq ($(BINDIR),)
145 BINDIR := $(PREFIX)/bin
146 endif
147 ifeq ($(INCLUDEDIR),)
148 INCLUDEDIR := $(PREFIX)/include
149 endif
150 
151 # Fix CXX on Cygwin 1.1.4
152 ifeq ($(CXX),gcc)
153 CXX := g++
154 endif
155 
156 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
157 ifeq ($(ARFLAGS),rv)
158 ARFLAGS = r
159 endif
160 
161 ifneq ($(HAS_NEWLIB),0)
162  ifeq ($(findstring -D_XOPEN_SOURCE,$(CXXFLAGS)),)
163  CXXFLAGS += -D_XOPEN_SOURCE=600
164  endif
165 endif
166 
167 # Clang integrated assembler will be used with -Wa,-q
168 CLANG_INTEGRATED_ASSEMBLER ?= 0
169 
170 # original MinGW targets Win2k by default, but lacks proper Win2k support
171 # if target Windows version is not specified, use Windows XP instead
172 ifeq ($(IS_MINGW),1)
173 ifeq ($(findstring -D_WIN32_WINNT,$(CXXFLAGS)),)
174 ifeq ($(findstring -D_WIN32_WINDOWS,$(CXXFLAGS)),)
175 ifeq ($(findstring -DWINVER,$(CXXFLAGS)),)
176 ifeq ($(findstring -DNTDDI_VERSION,$(CXXFLAGS)),)
177  CXXFLAGS += -D_WIN32_WINNT=0x0501
178 endif # NTDDI_VERSION
179 endif # WINVER
180 endif # _WIN32_WINDOWS
181 endif # _WIN32_WINNT
182 endif # IS_MINGW
183 
184 ###########################################################
185 ##### X86/X32/X64 Options #####
186 ###########################################################
187 
188 ifneq ($(IS_X86)$(IS_X64),00)
189 
190 # Fixup. Clang reports an error rather than "LLVM assembler" or similar.
191 ifneq ($(OSXPORT_COMPILER),1)
192  HAVE_GAS := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c "GNU assembler")
193 endif
194 
195 ifneq ($(GCC_COMPILER),0)
196  IS_GCC_29 := $(shell $(CXX) -v 2>&1 | $(GREP) -i -c -E gcc-9[0-9][0-9])
197  GCC42_OR_LATER := $(shell $(CXX) -v 2>&1 | $(GREP) -i -c -E "gcc version (4\.[2-9]|[5-9]\.)")
198  GCC46_OR_LATER := $(shell $(CXX) -v 2>&1 | $(GREP) -i -c -E "gcc version (4\.[6-9]|[5-9]\.)")
199 endif
200 
201 ifneq ($(HAVE_GAS),0)
202  GAS210_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.[1-9][0-9]|[3-9])")
203  GAS217_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.1[7-9]|2\.[2-9]|[3-9])")
204  GAS218_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.1[8-9]|2\.[2-9]|[3-9])")
205  GAS219_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.19|2\.[2-9]|[3-9])")
206  GAS224_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.2[4-9]|2\.[3-9]|[3-9])")
207 endif
208 
209 ICC111_OR_LATER := $(shell $(CXX) --version 2>&1 | $(GREP) -c -E "\(ICC\) ([2-9][0-9]|1[2-9]|11\.[1-9])")
210 
211 # Add -fPIC for targets *except* X86, X32, Cygwin or MinGW
212 ifeq ($(IS_X86)$(IS_CYGWIN)$(IS_MINGW)$(SUN_COMPILER),0000)
213  ifeq ($(findstring -fPIC,$(CXXFLAGS)),)
214  CXXFLAGS += -fPIC
215  endif
216 endif
217 
218 # .intel_syntax wasn't supported until GNU assembler 2.10
219 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
220 ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10)
221 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
222 else
223 ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10)
224 CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
225 else
226 ifeq ($(HAVE_GAS)$(GAS218_OR_LATER),10)
227 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
228 else
229 ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10)
230 CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
231 else
232 ifeq ($(HAVE_GAS)$(GAS224_OR_LATER),10)
233 CXXFLAGS += -DCRYPTOPP_DISABLE_SHA
234 
235 endif # -DCRYPTOPP_DISABLE_SHA
236 endif # -DCRYPTOPP_DISABLE_AESNI
237 endif # -DCRYPTOPP_DISABLE_SSE4
238 endif # -DCRYPTOPP_DISABLE_SSSE3
239 endif # -DCRYPTOPP_DISABLE_ASM
240 endif # CXXFLAGS
241 
242 # SSE2 is a core feature of x86_64
243 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
244  ifeq ($(IS_X86),1)
245  SSE_FLAG = -msse2
246  endif
247 endif
248 ifeq ($(findstring -DCRYPTOPP_DISABLE_SSSE3,$(CXXFLAGS)),)
249  HAVE_SSSE3 = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mssse3 -dM -E - 2>/dev/null | $(GREP) -i -c __SSSE3__)
250  ifeq ($(HAVE_SSSE3),1)
251  ARIA_FLAG = -mssse3
252  SSSE3_FLAG = -mssse3
253  SIMON_FLAG = -mssse3
254  SPECK_FLAG = -mssse3
255  endif
256 ifeq ($(findstring -DCRYPTOPP_DISABLE_SSE4,$(CXXFLAGS)),)
257  HAVE_SSE4 = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -msse4.1 -dM -E - 2>/dev/null | $(GREP) -i -c __SSE4_1__)
258  ifeq ($(HAVE_SSE4),1)
259  BLAKE2_FLAG = -msse4.1
260  SIMON_FLAG = -msse4.1
261  SPECK_FLAG = -msse4.1
262  endif
263  HAVE_SSE4 = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -msse4.2 -dM -E - 2>/dev/null | $(GREP) -i -c __SSE4_2__)
264  ifeq ($(HAVE_SSE4),1)
265  CRC_FLAG = -msse4.2
266  endif
267 ifeq ($(findstring -DCRYPTOPP_DISABLE_AESNI,$(CXXFLAGS)),)
268  HAVE_CLMUL = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mssse3 -mpclmul -dM -E - 2>/dev/null | $(GREP) -i -c __PCLMUL__ )
269  ifeq ($(HAVE_CLMUL),1)
270  GCM_FLAG = -mssse3 -mpclmul
271  endif
272  HAVE_AES = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -msse4.1 -maes -dM -E - 2>/dev/null | $(GREP) -i -c __AES__)
273  ifeq ($(HAVE_AES),1)
274  AES_FLAG = -msse4.1 -maes
275  endif
276 ifeq ($(findstring -DCRYPTOPP_DISABLE_SHA,$(CXXFLAGS)),)
277  HAVE_SHA = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -msse4.2 -msha -dM -E - 2>/dev/null | $(GREP) -i -c __SHA__)
278  ifeq ($(HAVE_SHA),1)
279  SHA_FLAG = -msse4.2 -msha
280  endif
281 endif # -DCRYPTOPP_DISABLE_SHA
282 endif # -DCRYPTOPP_DISABLE_AESNI
283 endif # -DCRYPTOPP_DISABLE_SSE4
284 endif # -DCRYPTOPP_DISABLE_SSSE3
285 
286 # Begin SunCC
287 ifeq ($(SUN_COMPILER),1)
288  COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=ssse3 -xdumpmacros /dev/null 2>&1 | $(GREP) -i -c "illegal")
289  ifeq ($(COUNT),0)
290  SSSE3_FLAG = -xarch=ssse3 -D__SSSE3__=1
291  ARIA_FLAG = -xarch=ssse3 -D__SSSE3__=1
292  SIMON_FLAG = -xarch=ssse3 -D__SSSE3__=1
293  SPECK_FLAG = -xarch=ssse3 -D__SSSE3__=1
294  LDFLAGS += -xarch=ssse3
295  endif
296  COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=sse4_1 -xdumpmacros /dev/null 2>&1 | $(GREP) -i -c "illegal")
297  ifeq ($(COUNT),0)
298  BLAKE2_FLAG = -xarch=sse4_1 -D__SSE4_1__=1
299  SIMON_FLAG = -xarch=sse4_1 -D__SSE4_1__=1
300  SPECK_FLAG = -xarch=sse4_1 -D__SSE4_1__=1
301  LDFLAGS += -xarch=sse4_1
302  endif
303  COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=sse4_2 -xdumpmacros /dev/null 2>&1 | $(GREP) -i -c "illegal")
304  ifeq ($(COUNT),0)
305  CRC_FLAG = -xarch=sse4_2 -D__SSE4_2__=1
306  LDFLAGS += -xarch=sse4_2
307  endif
308  COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=aes -xdumpmacros /dev/null 2>&1 | $(GREP) -i -c "illegal")
309  ifeq ($(COUNT),0)
310  GCM_FLAG = -xarch=aes -D__PCLMUL__=1
311  AES_FLAG = -xarch=aes -D__AES__=1
312  LDFLAGS += -xarch=aes
313  endif
314  COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=sha -xdumpmacros /dev/null 2>&1 | $(GREP) -i -c "illegal")
315  ifeq ($(COUNT),0)
316  SHA_FLAG = -xarch=sha -D__SHA__=1
317  LDFLAGS += -xarch=sha
318  endif
319 endif
320 # End SunCC
321 
322 ifneq ($(INTEL_COMPILER),0)
323  CXXFLAGS += -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180
324  ifeq ($(ICC111_OR_LATER),0)
325  # "internal error: backend signals" occurs on some x86 inline assembly with ICC 9 and some x64 inline assembly with ICC 11.0
326  # if you want to use Crypto++'s assembly code with ICC, try enabling it on individual files
327  CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
328  endif
329 endif
330 
331 # Tell MacPorts and Homebrew GCC to use Clang integrated assembler
332 # http://github.com/weidai11/cryptopp/issues/190
333 ifeq ($(GCC_COMPILER)$(OSXPORT_COMPILER),11)
334  ifeq ($(findstring -Wa,-q,$(CXXFLAGS)),)
335  CXXFLAGS += -Wa,-q
336  endif
337  ifeq ($(findstring -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER,$(CXXFLAGS)),)
338  CLANG_INTEGRATED_ASSEMBLER := 1
339  CXXFLAGS += -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER=1
340  endif
341 endif
342 
343 # GCC on Solaris needs -m64. Otherwise, i386 is default
344 # http://github.com/weidai11/cryptopp/issues/230
345 HAVE_BITS=$(shell echo $(CXXFLAGS) | $(GREP) -i -c -E '\-m32|\-m64')
346 ifeq ($(IS_SUN)$(GCC_COMPILER)$(IS_X64)$(HAVE_BITS),1110)
347  CXXFLAGS += -m64
348 endif
349 
350 # Allow use of "/" operator for GNU Assembler.
351 # http://sourceware.org/bugzilla/show_bug.cgi?id=4572
352 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
353 ifeq ($(IS_SUN)$(GCC_COMPILER),11)
354 CXXFLAGS += -Wa,--divide
355 endif
356 endif
357 
358 else
359 
360 ###########################################################
361 ##### Not X86/X32/X64 #####
362 ###########################################################
363 
364 # Add PIC
365 ifeq ($(findstring -fPIC,$(CXXFLAGS)),)
366  CXXFLAGS += -fPIC
367 endif
368 
369 ifeq ($(IS_NEON),1)
370  HAVE_NEON = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon -dM -E - 2>/dev/null | $(GREP) -i -c -E '<__ARM_NEON>')
371  ifeq ($(HAVE_NEON),1)
372  NEON_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
373  AES_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
374  GCM_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
375  ARIA_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
376  BLAKE2_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
377  SIMON_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
378  SPECK_FLAG = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon
379  endif
380 endif
381 
382 ifeq ($(IS_ARMV8),1)
383  HAVE_NEON = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a -dM -E - 2>/dev/null | $(GREP) -i -c __ARM_NEON)
384  ifeq ($(HAVE_NEON),1)
385  ARIA_FLAG = -march=armv8-a
386  BLAKE2_FLAG = -march=armv8-a
387  NEON_FLAG = -march=armv8-a
388  SIMON_FLAG = -march=armv8-a
389  SPECK_FLAG = -march=armv8-a
390  endif
391  HAVE_CRC = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a+crc -dM -E - 2>/dev/null | $(GREP) -i -c __ARM_FEATURE_CRC32)
392  ifeq ($(HAVE_CRC),1)
393  CRC_FLAG = -march=armv8-a+crc
394  endif
395  HAVE_CRYPTO = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a+crypto -dM -E - 2>/dev/null | $(GREP) -i -c __ARM_FEATURE_CRYPTO)
396  ifeq ($(HAVE_CRYPTO),1)
397  AES_FLAG = -march=armv8-a+crypto
398  GCM_FLAG = -march=armv8-a+crypto
399  SHA_FLAG = -march=armv8-a+crypto
400  endif
401 endif
402 
403 # PowerPC and PowerPC-64
404 # Altivec is available with Power4
405 ifneq ($(IS_PPC32)$(IS_PPC64)$(IS_AIX),000)
406  # GCC and some compatibles
407  HAVE_ALTIVEC = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mcpu=power4 -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c '__ALTIVEC__')
408  ifneq ($(HAVE_ALTIVEC),0)
409  ALTIVEC_FLAG = -mcpu=power4 -maltivec
410  ARIA_FLAG = -mcpu=power4 -maltivec
411  BLAKE2_FLAG = -mcpu=power4 -maltivec
412  SIMON_FLAG = -mcpu=power4 -maltivec
413  SPECK_FLAG = -mcpu=power4 -maltivec
414  endif
415  # GCC and some compatibles
416  HAVE_CRYPTO = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mcpu=power8 -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c -E '_ARCH_PWR8|_ARCH_PWR9|__CRYPTO')
417  ifneq ($(HAVE_CRYPTO),0)
418  ALTIVEC_FLAG = -mcpu=power8 -maltivec
419  AES_FLAG = -mcpu=power8 -maltivec
420  GCM_FLAG = -mcpu=power8 -maltivec
421  SHA_FLAG = -mcpu=power8 -maltivec
422  SIMON_FLAG = -mcpu=power8 -maltivec
423  SPECK_FLAG = -mcpu=power8 -maltivec
424  endif
425  # IBM XL C/C++
426  HAVE_ALTIVEC = $(shell $(CXX) $(CXXFLAGS) -qshowmacros -qarch=pwr7 -qaltivec -E adhoc.cpp.proto 2>/dev/null | $(GREP) -i -c '__ALTIVEC__')
427  ifneq ($(HAVE_ALTIVEC),0)
428  ALTIVEC_FLAG = -qarch=pwr7 -qaltivec
429  ARIA_FLAG = -qarch=pwr7 -qaltivec
430  BLAKE2_FLAG = -qarch=pwr7 -qaltivec
431  SIMON_FLAG = -qarch=pwr7 -qaltivec
432  SPECK_FLAG = -qarch=pwr7 -qaltivec
433  endif
434  # IBM XL C/C++
435  HAVE_CRYPTO = $(shell $(CXX) $(CXXFLAGS) -qshowmacros -qarch=pwr8 -qaltivec -E adhoc.cpp.proto 2>/dev/null | $(GREP) -i -c -E '_ARCH_PWR8|_ARCH_PWR9|__CRYPTO')
436  ifneq ($(HAVE_CRYPTO),0)
437  ALTIVEC_FLAG = -qarch=pwr8 -qaltivec
438  AES_FLAG = -qarch=pwr8 -qaltivec
439  GCM_FLAG = -qarch=pwr8 -qaltivec
440  SHA_FLAG = -qarch=pwr8 -qaltivec
441  ARIA_FLAG = -qarch=pwr8 -qaltivec
442  BLAKE2_FLAG = -qarch=pwr8 -qaltivec
443  SIMON_FLAG = -qarch=pwr8 -qaltivec
444  SPECK_FLAG = -qarch=pwr8 -qaltivec
445  endif
446 endif
447 
448 # IBM XL C/C++ compiler
449 ifeq ($(XLC_COMPILER),1)
450  # http://www-01.ibm.com/support/docview.wss?uid=swg21007500
451  ifeq ($(findstring -qrtti,$(CXXFLAGS)),)
452  CXXFLAGS += -qrtti
453  endif
454  # -fPIC causes link errors dues to unknown option
455  ifneq ($(findstring -fPIC,$(CXXFLAGS)),)
456  CXXFLAGS := $(CXXFLAGS:-fPIC=-qpic)
457  endif
458  HAVE_BITS=$(shell echo $(CXXFLAGS) | $(GREP) -i -c -E '\-q32|\-q64')
459  ifeq ($(IS_PPC64)$(XLC_COMPILER)$(HAVE_BITS),110)
460  CXXFLAGS += -q64
461  else
462  ifeq ($(IS_PPC32)$(XLC_COMPILER)$(HAVE_BITS),110)
463  CXXFLAGS += -q32
464  endif
465  endif
466 endif
467 
468 endif # X86, X64, ARM32, ARM64, PPC32, PPC64, etc
469 
470 ###########################################################
471 ##### Common #####
472 ###########################################################
473 
474 # Use -pthread whenever it is available. See http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf
475 # http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling
476 ifneq ($(IS_LINUX)$(GCC_COMPILER)$(CLANG_COMPILER)$(INTEL_COMPILER),0000)
477  CXXFLAGS += -pthread
478 endif # CXXFLAGS
479 
480 # Add -pipe for everything except IBM XL C/C++, SunCC and ARM.
481 # Allow ARM-64 because they seems to have >1 GB of memory
482 ifeq ($(XLC_COMPILER)$(SUN_COMPILER)$(IS_ARM32),000)
483  ifeq ($(findstring -save-temps,$(CXXFLAGS)),)
484  CXXFLAGS += -pipe
485  endif
486 endif
487 
488 # For SunOS, create a Mapfile that allows our object files
489 # to contain additional bits (like SSE4 and AES on old Xeon)
490 # http://www.oracle.com/technetwork/server-storage/solaris/hwcap-modification-139536.html
491 ifeq ($(IS_SUN)$(SUN_COMPILER),11)
492  ifneq ($(IS_X86)$(IS_X64),00)
493  ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
494  LDFLAGS += -M cryptopp.mapfile
495  endif # No CRYPTOPP_DISABLE_ASM
496  endif # X86/X32/X64
497 endif # SunOS
498 
499 ifneq ($(IS_MINGW),0)
500  LDLIBS += -lws2_32
501 endif
502 
503 ifneq ($(IS_SUN),0)
504  LDLIBS += -lnsl -lsocket
505 endif
506 
507 ifeq ($(IS_LINUX),1)
508  ifeq ($(findstring -fopenmp,$(CXXFLAGS)),-fopenmp)
509  ifeq ($(findstring -lgomp,$(LDLIBS)),)
510  LDLIBS += -lgomp
511  endif # LDLIBS
512  endif # OpenMP
513 endif # IS_LINUX
514 
515 ifneq ($(IS_DARWIN),0)
516  AR = libtool
517  ARFLAGS = -static -o
518  CXX ?= c++
519 endif
520 
521 # Add -errtags=yes to get the name for a warning suppression
522 ifneq ($(SUN_COMPILER),0) # override flags for CC Sun C++ compiler
523 IS_64 := $(shell isainfo -b 2>/dev/null | $(GREP) -i -c "64")
524 HAVE_BITS=$(shell echo $(CXXFLAGS) | $(GREP) -i -c -E '\-m32|\-m64')
525 ifeq ($(IS_64)$(HAVE_BITS),10)
526 CXXFLAGS += -m64
527 else ifeq ($(IS_64)$(HAVE_BITS),00)
528 CXXFLAGS += -m32
529 endif
530 # Add for non-i386
531 ifneq ($(IS_X86),1)
532 CXXFLAGS += -KPIC
533 endif
534 # Add to all Solaris
535 CXXFLAGS += -template=no%extdef
536 # http://github.com/weidai11/cryptopp/issues/403
537 ifneq ($(IS_SPARC32)$(IS_SPARC64),00)
538 CXXFLAGS += -xmemalign=4i
539 endif
540 SUN_CC10_BUGGY := $(shell $(CXX) -V 2>&1 | $(GREP) -c -E "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
541 ifneq ($(SUN_CC10_BUGGY),0)
542 # -DCRYPTOPP_INCLUDE_VECTOR_CC is needed for Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 and was fixed in May 2010
543 # remove it if you get "already had a body defined" errors in vector.cc
544 CXXFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
545 endif
546 AR = $(CXX)
547 ARFLAGS = -xar -o
548 RANLIB = true
549 endif
550 
551 # No ASM for Travis testing
552 ifeq ($(findstring no-asm,$(MAKECMDGOALS)),no-asm)
553 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
554 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
555 endif # CXXFLAGS
556 endif # No ASM
557 
558 # Native build testing. Issue 'make native'.
559 ifeq ($(findstring native,$(MAKECMDGOALS)),native)
560  ifeq ($(findstring -march=native,$(CXXFLAGS)),)
561  ifeq ($(IS_SUN)$(SUN_COMPILER),11)
562  CXXFLAGS += -native
563  else
564  CXXFLAGS += -march=native
565  endif # CXXFLAGS
566  endif # Sun
567 endif # Native
568 
569 # Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.
570 ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
571  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
572  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
573  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
574  ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
575  CXXFLAGS += -fsanitize=undefined
576  endif # CXXFLAGS
577  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
578  CXXFLAGS += -DCRYPTOPP_COVERAGE
579  endif # CXXFLAGS
580 endif # UBsan
581 
582 # Address Sanitizer (Asan) testing. Issue 'make asan'.
583 ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
584  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
585  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
586  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
587  ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
588  CXXFLAGS += -fsanitize=address
589  endif # CXXFLAGS
590  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
591  CXXFLAGS += -DCRYPTOPP_COVERAGE
592  endif # CXXFLAGS
593  ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
594  CXXFLAGS += -fno-omit-frame-pointer
595  endif # CXXFLAGS
596 endif # Asan
597 
598 # LD gold linker testing. Triggered by 'LD=ld.gold'.
599 ifeq ($(findstring ld.gold,$(LD)),ld.gold)
600  ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
601  LD_GOLD = $(shell command -v ld.gold)
602  ELF_FORMAT := $(shell file $(LD_GOLD) 2>&1 | cut -d":" -f 2 | $(GREP) -i -c "elf")
603  ifneq ($(ELF_FORMAT),0)
604  LDFLAGS += -fuse-ld=gold
605  endif # ELF/ELF64
606  endif # CXXFLAGS
607 endif # Gold
608 
609 # lcov code coverage. Issue 'make coverage'.
610 ifneq ($(filter lcov coverage,$(MAKECMDGOALS)),)
611  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
612  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
613  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
614  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
615  CXXFLAGS += -DCRYPTOPP_COVERAGE
616  endif # CRYPTOPP_COVERAGE
617  ifeq ($(findstring -coverage,$(CXXFLAGS)),)
618  CXXFLAGS += -coverage
619  endif # -coverage
620 endif # GCC code coverage
621 
622 # gcov code coverage for Travis. Issue 'make codecov'.
623 ifneq ($(filter gcov codecov,$(MAKECMDGOALS)),)
624  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
625  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
626  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
627  ifeq ($(findstring -DCRYPTOPP_COVERAGE,$(CXXFLAGS)),)
628  CXXFLAGS += -DCRYPTOPP_COVERAGE
629  endif # CRYPTOPP_COVERAGE
630  ifeq ($(findstring -coverage,$(CXXFLAGS)),)
631  CXXFLAGS += -coverage
632  endif # -coverage
633 endif # GCC code coverage
634 
635 # Valgrind testing. Issue 'make valgrind'.
636 ifneq ($(filter valgrind,$(MAKECMDGOALS)),)
637  # Tune flags; see http://valgrind.org/docs/manual/quick-start.html
638  CXXFLAGS := $(CXXFLAGS:-g%=-g3)
639  CXXFLAGS := $(CXXFLAGS:-O%=-O1)
640  CXXFLAGS := $(CXXFLAGS:-xO%=-xO1)
641  ifeq ($(findstring -DCRYPTOPP_VALGRIND,$(CXXFLAGS)),)
642  CXXFLAGS += -DCRYPTOPP_VALGRIND
643  endif # -DCRYPTOPP_VALGRIND
644 endif # Valgrind
645 
646 # Debug testing on GNU systems. Triggered by -DDEBUG.
647 # Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
648 ifneq ($(filter -DDEBUG -DDEBUG=1,$(CXXFLAGS)),)
649  USING_GLIBCXX := $(shell $(CXX) -x c++ $(CXXFLAGS) -E adhoc.cpp.proto 2>&1 | $(GREP) -i -c "__GLIBCXX__")
650  ifneq ($(USING_GLIBCXX),0)
651  ifeq ($(HAS_NEWLIB),0)
652  ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CXXFLAGS)),)
653  CXXFLAGS += -D_GLIBCXX_DEBUG
654  endif # CXXFLAGS
655  endif # HAS_NEWLIB
656  endif # USING_GLIBCXX
657 endif # GNU Debug build
658 
659 # Dead code stripping. Issue 'make lean'.
660 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
661  ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
662  CXXFLAGS += -ffunction-sections
663  endif # CXXFLAGS
664  ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
665  CXXFLAGS += -fdata-sections
666  endif # CXXFLAGS
667  ifneq ($(IS_DARWIN),0)
668  ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
669  LDFLAGS += -Wl,-dead_strip
670  endif # CXXFLAGS
671  else # BSD, Linux and Unix
672  ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
673  LDFLAGS += -Wl,--gc-sections
674  endif # LDFLAGS
675  endif # MAKECMDGOALS
676 endif # Dead code stripping
677 
678 # For Shared Objects, Diff, Dist/Zip rules
679 LIB_VER := $(shell $(GREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3)
680 LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
681 LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
682 LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
683 
684 ifeq ($(strip $(LIB_PATCH)),)
685  LIB_PATCH := 0
686 endif
687 
688 ifeq ($(HAS_SOLIB_VERSION),1)
689 # Full version suffix for shared library
690 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
691 # Different patchlevels and minors are compatible since 6.1
692 SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR)
693 SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
694 endif # HAS_SOLIB_VERSION
695 
696 ###########################################################
697 ##### Source and object files #####
698 ###########################################################
699 
700 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
701 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)))
702 # For Makefile.am; resource.h is Windows
703 INCL := $(filter-out resource.h,$(sort $(wildcard *.h)))
704 
705 ifneq ($(IS_MINGW),0)
706 SRCS += winpipes.cpp
707 INCL += resource.h
708 endif
709 
710 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
711 OBJS := $(SRCS:.cpp=.o)
712 
713 # List test.cpp first to tame C++ static initialization problems.
714 TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp datatest.cpp regtest1.cpp regtest2.cpp regtest3.cpp dlltest.cpp fipsalgt.cpp
715 TESTINCL := bench.h factory.h validate.h
716 # Test objects
717 TESTOBJS := $(TESTSRCS:.cpp=.o)
718 LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
719 
720 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
721 DLLSRCS := cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp arc4.cpp aria-simd.cpp aria.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64.cpp basecode.cpp bfinit.cpp blake2-simd.cpp blake2.cpp blowfish.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cpp channels.cpp cmac.cpp crc-simd.cpp crc.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp ecp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips140.cpp fipstest.cpp gcm-simd.cpp gcm.cpp gf256.cpp gf2_32.cpp gf2n.cpp gfpcrypt.cpp gost.cpp gzip.cpp hex.cpp hmac.cpp hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon-simd.cpp network.cpp oaep.cpp ospstore.cpp osrng.cpp panama.cpp pkcspad.cpp poly1305.cpp polynomi.cpp pssr.cpp pubkey.cpp queue.cpp rabin.cpp randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdrand.cpp rdtables.cpp rijndael.cpp ripemd.cpp rng.cpp rsa.cpp rw.cpp safer.cpp salsa.cpp seal.cpp seed.cpp serpent.cpp sha-simd.cpp sha.cpp sha3.cpp shacal2-simd.cpp shacal2.cpp shark.cpp sharkbox.cpp skipjack.cpp socketft.cpp sosemanuk.cpp square.cpp squaretb.cpp strciphr.cpp tea.cpp tftables.cpp threefish.cpp tiger.cpp tigertab.cpp trdlocal.cpp ttmac.cpp twofish.cpp vmac.cpp wait.cpp wake.cpp whrlpool.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zlib.cpp
722 
723 DLLOBJS := $(DLLSRCS:.cpp=.export.o)
724 
725 # Import lib testing
726 LIBIMPORTOBJS := $(LIBOBJS:.o=.import.o)
727 TESTIMPORTOBJS := $(TESTOBJS:.o=.import.o)
728 DLLTESTOBJS := dlltest.dllonly.o
729 
730 ###########################################################
731 ##### Targets and Recipes #####
732 ###########################################################
733 
734 # Default builds program with static library only
735 .PHONY: default
736 default: cryptest.exe
737 
738 .PHONY: all
739 all: static dynamic cryptest.exe
740 
741 ifneq ($(IS_DARWIN),0)
742 static: libcryptopp.a
743 shared dynamic dylib: libcryptopp.dylib
744 else
745 static: libcryptopp.a
746 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
747 endif
748 
749 .PHONY: dep deps depend
750 dep deps depend GNUmakefile.deps:
751  $(CXX) $(strip $(CXXFLAGS)) -MM *.cpp > GNUmakefile.deps
752 
753 # CXXFLAGS are tuned earlier.
754 .PHONY: native no-asm asan ubsan
755 native no-asm asan ubsan: cryptest.exe
756 
757 # CXXFLAGS are tuned earlier. Applications must use linker flags
758 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
759 .PHONY: lean
760 lean: static dynamic cryptest.exe
761 
762 # May want to export CXXFLAGS="-g3 -O1"
763 .PHONY: lcov coverage
764 lcov coverage: cryptest.exe
765  @-$(RM) -r ./TestCoverage/
766  lcov --base-directory . --directory . --zerocounters -q
767  ./cryptest.exe v
768  ./cryptest.exe tv all
769  lcov --base-directory . --directory . -c -o cryptest.info
770  lcov --remove cryptest.info "adhoc.cpp" "wait.*" "network.*" "socketft.*" "fips140.*" "*test.*" "bench*.cpp" "validat*.*" "/usr/*" -o cryptest.info
771  genhtml -o ./TestCoverage/ -t "cryptest.exe test coverage" --num-spaces 4 cryptest.info
772 
773 # Travis CI and CodeCov rule
774 .PHONY: gcov codecov
775 gcov codecov: cryptest.exe
776  @-$(RM) -r ./TestCoverage/
777  ./cryptest.exe v
778  ./cryptest.exe tv all
779  gcov -r $(SRCS)
780 
781 # Should use CXXFLAGS="-g3 -O1"
782 .PHONY: valgrind
783 valgrind: cryptest.exe
784  valgrind --track-origins=yes --suppressions=cryptopp.supp ./cryptest.exe v
785 
786 .PHONY: test check
787 test check: cryptest.exe
788  ./cryptest.exe v
789 
790 # Used to generate list of source files for Autotools, CMakeList, Android.mk, etc
791 .PHONY: sources
792 sources: adhoc.cpp
793  $(info Library sources: $(filter-out $(TESTSRCS),$(SRCS)))
794  $(info )
795  $(info Library headers: $(filter-out $(TESTINCL),$(INCL)))
796  $(info )
797  $(info Test sources: $(TESTSRCS))
798  $(info )
799  $(info Test headers: $(TESTINCL))
800 
801 # Directory we want (can't specify on Doygen command line)
802 DOCUMENT_DIRECTORY := ref$(LIB_VER)
803 # Directory Doxygen uses (specified in Doygen config file)
804 ifeq ($(wildcard Doxyfile),Doxyfile)
805 DOXYGEN_DIRECTORY := $(strip $(shell $(GREP) "OUTPUT_DIRECTORY" Doxyfile | $(GREP) -v "\#" | cut -d "=" -f 2))
806 endif
807 # Default directory (in case its missing in the config file)
808 ifeq ($(strip $(DOXYGEN_DIRECTORY)),)
809 DOXYGEN_DIRECTORY := html-docs
810 endif
811 
812 # Builds the documentation. Directory name is ref563, ref570, etc.
813 .PHONY: docs html
814 docs html:
815  @-$(RM) -r $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/ html-docs/
816  @-$(RM) CryptoPPRef.zip
817  doxygen Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
818  $(MV) $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/
819  zip -9 CryptoPPRef.zip -x ".*" -x "*/.*" -r $(DOCUMENT_DIRECTORY)/
820 
821 .PHONY: clean
822 clean:
823  -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) rdrand-*.o $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
824  @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
825  @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
826  @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct et
827  @-$(RM) *.la *.lo *.gcov *.gcno *.gcda *.stackdump core core-*
828  @-$(RM) /tmp/adhoc.exe
829  @-$(RM) -r /tmp/cryptopp_test/
830  @-$(RM) -r *.exe.dSYM/
831  @-$(RM) -r *.dylib.dSYM/
832  @-$(RM) -r cov-int/
833 
834 .PHONY: distclean
835 distclean: clean
836  -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt cryptest-*.txt
837  @-$(RM) libcryptopp.pc cryptopp.tgz *.o *.bc *.ii *~
838  @-$(RM) -r $(SRCS:.cpp=.obj) cryptlib.lib cryptest.exe *.suo *.sdf *.pdb Win32/ x64/ ipch/
839  @-$(RM) -r $(DOCUMENT_DIRECTORY)/
840  @-$(RM) -f configure.ac configure configure.in Makefile.am Makefile.in Makefile
841  @-$(RM) -f config.guess config.status config.sub depcomp install-sh compile
842  @-$(RM) -f stamp-h1 ar-lib *.m4 local.* lt*.sh missing libtool* libcryptopp.pc*
843  @-$(RM) -rf m4/ auto*.cache/ .deps/ .libs/
844  @-$(RM) -r TestCoverage/
845  @-$(RM) cryptopp$(LIB_VER)\.*
846  @-$(RM) CryptoPPRef.zip
847 
848 # Some users already have a libcryptopp.pc. We install it if the file
849 # is present. If you want one, then issue 'make libcryptopp.pc'.
850 .PHONY: install
851 install:
852  @-$(MKDIR) $(DESTDIR)$(INCLUDEDIR)/cryptopp
853  $(INSTALL_DATA) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
854 ifneq ($(wildcard libcryptopp.a),)
855  @-$(MKDIR) $(DESTDIR)$(LIBDIR)
856  $(INSTALL_DATA) libcryptopp.a $(DESTDIR)$(LIBDIR)
857 endif
858 ifneq ($(wildcard cryptest.exe),)
859  @-$(MKDIR) $(DESTDIR)$(BINDIR)
860  $(INSTALL_PROGRAM) cryptest.exe $(DESTDIR)$(BINDIR)
861  @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestData
862  @-$(MKDIR) $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
863  $(INSTALL_DATA) TestData/*.dat $(DESTDIR)$(DATADIR)/cryptopp/TestData
864  $(INSTALL_DATA) TestVectors/*.txt $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
865 endif
866 ifneq ($(wildcard libcryptopp.dylib),)
867  @-$(MKDIR) $(DESTDIR)$(LIBDIR)
868  $(INSTALL_PROGRAM) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
869  -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
870 endif
871 ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
872  @-$(MKDIR) $(DESTDIR)$(LIBDIR)
873  $(INSTALL_PROGRAM) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
874 ifeq ($(HAS_SOLIB_VERSION),1)
875  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
876  $(LDCONF) $(DESTDIR)$(LIBDIR)
877 endif
878 endif
879 ifneq ($(wildcard libcryptopp.pc),)
880  @-$(MKDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
881  $(INSTALL_DATA) libcryptopp.pc $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
882 endif
883 
884 .PHONY: remove uninstall
885 remove uninstall:
886  -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
887  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
888  -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
889  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
890  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
891  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
892  @-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
893  @-$(RM) $(DESTDIR)$(LIBDIR)/pkgconfig/libcryptopp.pc
894  @-$(RM) -r $(DESTDIR)$(DATADIR)/cryptopp
895 
896 libcryptopp.a: $(LIBOBJS)
897  $(AR) $(ARFLAGS) $@ $(LIBOBJS)
898 ifeq ($(IS_SUN),0)
899  $(RANLIB) $@
900 endif
901 
902 ifeq ($(HAS_SOLIB_VERSION),1)
903 .PHONY: libcryptopp.so
904 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX) | so_warning
905 endif
906 
907 libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS)
908 ifeq ($(XLC_COMPILER),1)
909  $(CXX) -qmkshrobj $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
910 else
911  $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
912 endif
913 ifeq ($(HAS_SOLIB_VERSION),1)
914  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
915  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
916 endif
917 
918 libcryptopp.dylib: $(LIBOBJS)
919  $(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)
920 
921 cryptest.exe: libcryptopp.a $(TESTOBJS)
922  $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
923 
924 # Makes it faster to test changes
925 nolib: $(OBJS)
926  $(CXX) -o ct $(strip $(CXXFLAGS)) $(OBJS) $(LDFLAGS) $(LDLIBS)
927 
928 dll: cryptest.import.exe dlltest.exe
929 
930 cryptopp.dll: $(DLLOBJS)
931  $(CXX) -shared -o $@ $(strip $(CXXFLAGS)) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcryptopp.dll.a
932 
933 libcryptopp.import.a: $(LIBIMPORTOBJS)
934  $(AR) $(ARFLAGS) $@ $(LIBIMPORTOBJS)
935 ifeq ($(IS_SUN),0)
936  $(RANLIB) $@
937 endif
938 
939 cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS)
940  $(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTIMPORTOBJS) -L. -lcryptopp.dll -lcryptopp.import $(LDFLAGS) $(LDLIBS)
941 
942 dlltest.exe: cryptopp.dll $(DLLTESTOBJS)
943  $(CXX) -o $@ $(strip $(CXXFLAGS)) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS)
944 
945 # Some users already have a libcryptopp.pc. We install it if the file
946 # is present. If you want one, then issue 'make libcryptopp.pc'. Be sure
947 # to use/verify PREFIX and LIBDIR below after writing the file.
948 libcryptopp.pc:
949  @echo '# Crypto++ package configuration file' > libcryptopp.pc
950  @echo '' >> libcryptopp.pc
951  @echo 'prefix=$(PREFIX)' >> libcryptopp.pc
952  @echo 'libdir=$(LIBDIR)' >> libcryptopp.pc
953  @echo 'includedir=$${prefix}/include' >> libcryptopp.pc
954  @echo '' >> libcryptopp.pc
955  @echo 'Name: Crypto++' >> libcryptopp.pc
956  @echo 'Description: Crypto++ cryptographic library' >> libcryptopp.pc
957  @echo 'Version: 6.1.0' >> libcryptopp.pc
958  @echo 'URL: https://cryptopp.com/' >> libcryptopp.pc
959  @echo '' >> libcryptopp.pc
960  @echo 'Cflags: -I$${includedir}' >> libcryptopp.pc
961  @echo 'Libs: -L$${libdir} -lcryptopp' >> libcryptopp.pc
962 
963 # This recipe prepares the distro files
964 TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcxproj *.filters cryptopp.rc TestVectors/*.txt TestData/*.dat TestScripts/*.sh TestScripts/*.cmd
965 EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ TestScripts/
966 
967 ifeq ($(wildcard Filelist.txt),Filelist.txt)
968 DIST_FILES := $(shell cat Filelist.txt)
969 endif
970 
971 .PHONY: trim
972 trim:
973 ifneq ($(IS_DARWIN),0)
974  sed -i '' -e's/[[:space:]]*$$//' *.supp *.txt *.sh .*.yml *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
975  sed -i '' -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestScripts/*.*
976  make convert
977 else
978  sed -i -e's/[[:space:]]*$$//' *.supp *.txt *.sh .*.yml *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
979  sed -i -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestScripts/*.*
980  make convert
981 endif
982 
983 .PHONY: convert
984 convert:
985  @-$(CHMOD) 0700 TestVectors/ TestData/ TestScripts/
986  @-$(CHMOD) 0600 $(TEXT_FILES) *.supp .*.yml *.asm *.s *.zip TestVectors/*.txt TestData/*.dat TestScripts/*.*
987  @-$(CHMOD) 0700 $(EXEC_FILES) *.sh *.cmd TestScripts/*.sh TestScripts/*.cmd
988  @-$(CHMOD) 0700 *.cmd *.sh GNUmakefile GNUmakefile-cross TestScripts/*.sh
989  -unix2dos --keepdate --quiet $(TEXT_FILES) .*.yml *.asm *.cmd TestScripts/*.*
990  -dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.supp *.s *.sh *.mapfile TestScripts/*.sh TestScripts/*.patch
991 ifneq ($(IS_DARWIN),0)
992  @-xattr -c *
993 endif
994 
995 # Build the ZIP file with source files. No documentation.
996 .PHONY: zip dist
997 zip dist: | distclean convert
998  zip -q -9 cryptopp$(LIB_VER).zip $(DIST_FILES)
999 
1000 # Build the ISO to transfer the ZIP to old distros via CDROM
1001 .PHONY: iso
1002 iso: | zip
1003 ifneq ($(IS_DARWIN),0)
1004  $(MKDIR) $(PWD)/cryptopp$(LIB_VER)
1005  $(CP) cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER)
1006  hdiutil makehybrid -iso -joliet -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER)
1007  @-$(RM) -r $(PWD)/cryptopp$(LIB_VER)
1008 else ifneq ($(IS_LINUX),0)
1009  $(MKDIR) $(PWD)/cryptopp$(LIB_VER)
1010  $(CP) cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER)
1011  genisoimage -q -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER)
1012  @-$(RM) -r $(PWD)/cryptopp$(LIB_VER)
1013 endif
1014 
1015 # CRYPTOPP_CPU_FREQ in GHz
1016 CRYPTOPP_CPU_FREQ ?= 0.0
1017 .PHONY: bench benchmark benchmarks
1018 bench benchmark benchmarks: cryptest.exe
1019  @-$(RM) -f benchmarks.html
1020  ./cryptest.exe b 2 $(CRYPTOPP_CPU_FREQ)
1021 
1022 adhoc.cpp: adhoc.cpp.proto
1023 ifeq ($(wildcard adhoc.cpp),)
1024  cp adhoc.cpp.proto adhoc.cpp
1025 else
1026  touch adhoc.cpp
1027 endif
1028 
1029 # Include dependencies, if present. You must issue `make deps` to create them.
1030 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
1031 -include GNUmakefile.deps
1032 endif # Dependencies
1033 
1034 # IBM XLC -O3 optimization bug
1035 ifeq ($(XLC_COMPILER),1)
1036 sm3.o : sm3.cpp
1037  $(CXX) $(strip $(subst -O3,-O2,$(CXXFLAGS)) -c) $<
1038 endif
1039 
1040 # SSSE3 or NEON available
1041 aria-simd.o : aria-simd.cpp
1042  $(CXX) $(strip $(CXXFLAGS) $(ARIA_FLAG) -c) $<
1043 
1044 # SSE4.1 or ARMv8a available
1045 blake2-simd.o : blake2-simd.cpp
1046  $(CXX) $(strip $(CXXFLAGS) $(BLAKE2_FLAG) -c) $<
1047 
1048 # SSE2 on i586
1049 sse-simd.o : sse-simd.cpp
1050  $(CXX) $(strip $(CXXFLAGS) $(SSE_FLAG) -c) $<
1051 
1052 # SSE4.2 or ARMv8a available
1053 crc-simd.o : crc-simd.cpp
1054  $(CXX) $(strip $(CXXFLAGS) $(CRC_FLAG) -c) $<
1055 
1056 # PCLMUL or ARMv7a/ARMv8a available
1057 gcm-simd.o : gcm-simd.cpp
1058  $(CXX) $(strip $(CXXFLAGS) $(GCM_FLAG) -c) $<
1059 
1060 # NEON available
1061 neon-simd.o : neon-simd.cpp
1062  $(CXX) $(strip $(CXXFLAGS) $(NEON_FLAG) -c) $<
1063 
1064 # AltiVec, Power7, Power8 available
1065 ppc-simd.o : ppc-simd.cpp
1066  $(CXX) $(strip $(CXXFLAGS) $(ALTIVEC_FLAG) -c) $<
1067 
1068 # AESNI or ARMv7a/ARMv8a available
1069 rijndael-simd.o : rijndael-simd.cpp
1070  $(CXX) $(strip $(CXXFLAGS) $(AES_FLAG) -c) $<
1071 
1072 # SSE4.2/SHA-NI or ARMv8a available
1073 sha-simd.o : sha-simd.cpp
1074  $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
1075 
1076 # SSE4.2/SHA-NI or ARMv8a available
1077 shacal2-simd.o : shacal2-simd.cpp
1078  $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<
1079 
1080 # SSSE3 or NEON available
1081 simon-simd.o : simon-simd.cpp
1082  $(CXX) $(strip $(CXXFLAGS) $(SIMON_FLAG) -c) $<
1083 
1084 # SSSE3 or NEON available
1085 speck-simd.o : speck-simd.cpp
1086  $(CXX) $(strip $(CXXFLAGS) $(SPECK_FLAG) -c) $<
1087 
1088 # Don't build Rijndael with UBsan. Too much noise due to unaligned data accesses.
1089 ifneq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
1090 rijndael.o : rijndael.cpp
1091  $(CXX) $(strip $(subst -fsanitize=undefined,,$(CXXFLAGS)) -c) $<
1092 endif
1093 
1094 # Don't build VMAC and friends with Asan. Too many false positives.
1095 ifneq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
1096 vmac.o : vmac.cpp
1097  $(CXX) $(strip $(subst -fsanitize=address,,$(CXXFLAGS)) -c) $<
1098 endif
1099 
1100 # Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS
1101 ifeq ($(findstring -DCRYPTOPP_DATA_DIR, $(strip $(CXXFLAGS))),)
1102 ifneq ($(strip $(CRYPTOPP_DATA_DIR)),)
1103 validat%.o : validat%.cpp
1104  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1105 bench%.o : bench%.cpp
1106  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1107 datatest.o : datatest.cpp
1108  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1109 test.o : test.cpp
1110  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c) $<
1111 endif
1112 endif
1113 
1114 %.dllonly.o : %.cpp
1115  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_DLL_ONLY -c) $< -o $@
1116 
1117 %.import.o : %.cpp
1118  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_IMPORTS -c) $< -o $@
1119 
1120 %.export.o : %.cpp
1121  $(CXX) $(strip $(CXXFLAGS) -DCRYPTOPP_EXPORTS -c) $< -o $@
1122 
1123 %.bc : %.cpp
1124  $(CXX) $(strip $(CXXFLAGS) -c) $<
1125 
1126 %.o : %.cpp
1127  $(CXX) $(strip $(CXXFLAGS) -c) $<
1128 
1129 .PHONY: so_warning
1130 so_warning:
1131 ifeq ($(HAS_SOLIB_VERSION),1)
1132  $(info WARNING: Only the symlinks to the shared-object library have been updated.)
1133  $(info WARNING: If the library is installed in a system directory you will need)
1134  $(info WARNING: to run 'ldconfig' to update the shared-object library cache.)
1135  $(info )
1136 endif