Crypto++  5.6.5
Free C++ class library of cryptographic schemes
GNUmakefile
1 ###########################################################
2 ##### System Attributes and Programs #####
3 ###########################################################
4 
5 AR ?= ar
6 ARFLAGS ?= -cr # ar needs the dash on OpenBSD
7 RANLIB ?= ranlib
8 
9 CP ?= cp
10 MV ?= mv
11 EGREP ?= egrep
12 CHMOD ?= chmod
13 MKDIR ?= mkdir
14 LN ?= ln -sf
15 LDCONF ?= /sbin/ldconfig -n
16 UNAME := $(shell uname)
17 
18 IS_X86 := $(shell uname -m | $(EGREP) -v "x86_64" | $(EGREP) -i -c "i.86|x86|i86")
19 IS_X32 ?= 0
20 IS_X64 := $(shell uname -m | $(EGREP) -i -c "(_64|d64)")
21 IS_PPC := $(shell uname -m | $(EGREP) -i -c "ppc|power")
22 IS_ARM32 := $(shell uname -m | $(EGREP) -i -c "arm")
23 IS_ARM64 := $(shell uname -m | $(EGREP) -i -c "aarch64")
24 
25 IS_SUN := $(shell uname | $(EGREP) -i -c "SunOS")
26 IS_LINUX := $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -i -c "Linux")
27 IS_MINGW := $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -i -c "MinGW")
28 IS_CYGWIN := $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -i -c "Cygwin")
29 IS_DARWIN := $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -i -c "Darwin")
30 IS_NETBSD := $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -i -c "NetBSD")
31 
32 SUN_COMPILER := $(shell $(CXX) -V 2>&1 | $(EGREP) -i -c "CC: (Sun|Studio)")
33 GCC_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -v "clang" | $(EGREP) -i -c "(gcc|g\+\+)")
34 CLANG_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang")
35 INTEL_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "\(icc\)")
36 MACPORTS_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "macports")
37 
38 # Sun Studio 12.0 provides SunCC 0x0510; and Sun Studio 12.3 provides SunCC 0x0512
39 SUNCC_510_OR_LATER := $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: (Sun|Studio) .* (5\.1[0-9]|5\.[2-9]|6\.)")
40 SUNCC_511_OR_LATER := $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: (Sun|Studio) .* (5\.1[1-9]|5\.[2-9]|6\.)")
41 SUNCC_512_OR_LATER := $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: (Sun|Studio) .* (5\.1[2-9]|5\.[2-9]|6\.)")
42 SUNCC_513_OR_LATER := $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: (Sun|Studio) .* (5\.1[3-9]|5\.[2-9]|6\.)")
43 
44 HAS_SOLIB_VERSION := $(IS_LINUX)
45 
46 # Fixup SunOS
47 ifeq ($(IS_SUN),1)
48 IS_X86 := $(shell isainfo -k 2>/dev/null | grep -i -c "i386")
49 IS_X64 := $(shell isainfo -k 2>/dev/null | grep -i -c "amd64")
50 endif
51 
52 ###########################################################
53 ##### General Variables #####
54 ###########################################################
55 
56 # Base CXXFLAGS used if the user did not specify them
57 ifeq ($(SUN_COMPILER),1)
58  ifeq ($(SUNCC_512_OR_LATER),1)
59  CXXFLAGS ?= -DNDEBUG -g3 -xO2
60  else
61  CXXFLAGS ?= -DNDEBUG -g -xO2
62  endif
63 else
64  CXXFLAGS ?= -DNDEBUG -g2 -O2
65 endif
66 
67 # Default prefix for make install
68 ifeq ($(PREFIX),)
69 PREFIX = /usr/local
70 endif
71 
72 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
73 ifeq ($(DATADIR),)
74 DATADIR := $(PREFIX)/share
75 endif
76 ifeq ($(LIBDIR),)
77 LIBDIR := $(PREFIX)/lib
78 endif
79 ifeq ($(BINDIR),)
80 BINDIR := $(PREFIX)/bin
81 endif
82 ifeq ($(INCLUDEDIR),)
83 INCLUDEDIR := $(PREFIX)/include
84 endif
85 
86 # Fix CXX on Cygwin 1.1.4
87 ifeq ($(CXX),gcc)
88 CXX := g++
89 endif
90 
91 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
92 ifeq ($(ARFLAGS),rv)
93 ARFLAGS = r
94 endif
95 
96 ###########################################################
97 ##### X86/X32/X64 Options #####
98 ###########################################################
99 
100 ifneq ($(IS_X86)$(IS_X32)$(IS_X64),000)
101 
102 # Fixup. Clang integrated assembler will be used (-Wa,-q)
103 ifneq ($(MACPORTS_COMPILER),1)
104  IS_GAS := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler")
105 endif
106 
107 ifneq ($(GCC_COMPILER),0)
108  IS_GCC_29 := $(shell $(CXX) -v 2>&1 | $(EGREP) -i -c gcc-9[0-9][0-9])
109  GCC42_OR_LATER := $(shell $(CXX) -v 2>&1 | $(EGREP) -i -c "gcc version (4\.[2-9]|[5-9]\.)")
110  GCC46_OR_LATER := $(shell $(CXX) -v 2>&1 | $(EGREP) -i -c "gcc version (4\.[6-9]|[5-9]\.)")
111 endif
112 
113 ifneq ($(IS_GAS),0)
114  GAS210_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.[1-9][0-9]|[3-9])")
115  GAS217_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.1[7-9]|2\.[2-9]|[3-9])")
116  GAS219_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.19|2\.[2-9]|[3-9])")
117 endif
118 
119 ICC111_OR_LATER := $(shell $(CXX) --version 2>&1 | $(EGREP) -c "\(ICC\) ([2-9][0-9]|1[2-9]|11\.[1-9])")
120 
121 # Add -fPIC for targets *except* X86, X32, Cygwin or MinGW
122 ifeq ($(IS_X86)$(IS_X32)$(IS_CYGWIN)$(IS_MINGW)$(SUN_COMPILER),00000)
123  ifeq ($(findstring -fPIC,$(CXXFLAGS)),)
124  CXXFLAGS += -fPIC
125  endif
126 endif
127 
128 # Guard use of -march=native
129 ifeq ($(GCC42_OR_LATER)$(IS_NETBSD),10)
130  CXXFLAGS += -march=native
131 else ifneq ($(CLANG_COMPILER)$(INTEL_COMPILER),00)
132  CXXFLAGS += -march=native
133 else
134  # GCC 3.3 and "unknown option -march="
135  # Ubuntu GCC 4.1 compiler crash with -march=native
136  # NetBSD GCC 4.8 compiler and "bad value (native) for -march= switch"
137  # Sun compiler is handled below
138  ifeq ($(SUN_COMPILER)$(IS_X64),01)
139  CXXFLAGS += -m64
140  else ifeq ($(SUN_COMPILER)$(IS_X86),01)
141  CXXFLAGS += -m32
142  endif # X86/X32/X64
143 endif
144 
145 # Aligned access required for -O3 and above due to vectorization
146 UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h)
147 ifneq ($(UNALIGNED_ACCESS),0)
148 ifeq ($(findstring -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS,$(CXXFLAGS)),)
149 ifeq ($(findstring -O3,$(CXXFLAGS)),-O3)
150 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
151 endif # -O3
152 ifeq ($(findstring -O5,$(CXXFLAGS)),-O5)
153 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
154 endif # -O5
155 ifeq ($(findstring -Ofast,$(CXXFLAGS)),-Ofast)
156 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
157 endif # -Ofast
158 endif # CRYPTOPP_NO_UNALIGNED_DATA_ACCESS
159 endif # UNALIGNED_ACCESS
160 
161 ifneq ($(INTEL_COMPILER),0)
162 CXXFLAGS += -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180
163 ifeq ($(ICC111_OR_LATER),0)
164 # "internal error: backend signals" occurs on some x86 inline assembly with ICC 9 and some x64 inline assembly with ICC 11.0
165 # if you want to use Crypto++'s assembly code with ICC, try enabling it on individual files
166 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
167 endif
168 endif
169 
170 # .intel_syntax wasn't supported until GNU assembler 2.10
171 ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER)$(GAS210_OR_LATER),100)
172 CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
173 else
174 ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER)$(GAS217_OR_LATER),100)
175 CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
176 else
177 ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER)$(GAS219_OR_LATER),100)
178 CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
179 endif
180 endif
181 endif
182 
183 # Tell MacPorts GCC to use Clang integrated assembler
184 # http://github.com/weidai11/cryptopp/issues/190
185 ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER),11)
186 ifneq ($(findstring -Wa,-q,$(CXXFLAGS)),-Wa,-q)
187 CXXFLAGS += -Wa,-q
188 endif
189 ifneq ($(findstring -Wa,-q,$(CXXFLAGS)),-DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER)
190 CXXFLAGS += -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER=1
191 endif
192 endif
193 
194 # GCC on Solaris needs -m64. Otherwise, i386 is default
195 # http://github.com/weidai11/cryptopp/issues/230
196 ifeq ($(IS_SUN)$(GCC_COMPILER)$(IS_X64),111)
197 CXXFLAGS += -m64
198 endif
199 
200 # Allow use of "/" operator for GNU Assembler.
201 # http://sourceware.org/bugzilla/show_bug.cgi?id=4572
202 ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
203 ifeq ($(IS_SUN)$(GCC_COMPILER),11)
204 CXXFLAGS += -Wa,--divide
205 endif
206 endif
207 
208 ifeq ($(UNAME),) # for DJGPP, where uname doesn't exist
209 CXXFLAGS += -mbnu210
210 else ifneq ($(findstring -save-temps,$(CXXFLAGS)),-save-temps)
211 ifeq ($(SUN_COMPILER),0)
212 CXXFLAGS += -pipe
213 endif
214 endif
215 
216 else
217 
218 ###########################################################
219 ##### Not X86/X32/X64 #####
220 ###########################################################
221 
222 # Add PIC
223 ifeq ($(findstring -fPIC,$(CXXFLAGS)),)
224  CXXFLAGS += -fPIC
225 endif
226 
227 # Add -pipe for everything except ARM (allow ARM-64 because they seems to have > 1 GB of memory)
228 ifeq ($(IS_ARM32),0)
229 ifeq ($(findstring -save-temps,$(CXXFLAGS)),)
230 CXXFLAGS += -pipe
231 endif
232 endif
233 
234 # Aligned access required for -O3 and above due to vectorization
235 UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h)
236 ifneq ($(UNALIGNED_ACCESS),0)
237 ifeq ($(findstring -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS,$(CXXFLAGS)),)
238 ifeq ($(findstring -O3,$(CXXFLAGS)),-O3)
239 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
240 endif # -O3
241 ifeq ($(findstring -O5,$(CXXFLAGS)),-O5)
242 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
243 endif # -O5
244 ifeq ($(findstring -Ofast,$(CXXFLAGS)),-Ofast)
245 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
246 endif # -Ofast
247 endif # CRYPTOPP_NO_UNALIGNED_DATA_ACCESS
248 endif # UNALIGNED_ACCESS
249 
250 endif # IS_X86
251 
252 ###########################################################
253 ##### Common #####
254 ###########################################################
255 
256 ifneq ($(IS_MINGW),0)
257 LDLIBS += -lws2_32
258 endif
259 
260 ifneq ($(IS_SUN),0)
261 LDLIBS += -lnsl -lsocket
262 endif
263 
264 ifeq ($(IS_LINUX),1)
265 LDFLAGS += -pthread
266 ifeq ($(findstring -fopenmp,$(CXXFLAGS)),-fopenmp)
267 ifeq ($(findstring -lgomp,$(LDLIBS)),)
268 LDLIBS += -lgomp
269 endif # LDLIBS
270 endif # OpenMP
271 endif # IS_LINUX
272 
273 ifneq ($(IS_DARWIN),0)
274 AR = libtool
275 ARFLAGS = -static -o
276 CXX ?= c++
277 ifeq ($(IS_GCC_29),1)
278 CXXFLAGS += -fno-coalesce-templates -fno-coalesce-static-vtables
279 LDLIBS += -lstdc++
280 LDFLAGS += -flat_namespace -undefined suppress -m
281 endif
282 endif
283 
284 # Add -errtags=yes to get the name for a warning suppression
285 ifneq ($(SUN_COMPILER),0) # override flags for CC Sun C++ compiler
286 IS_64 := $(shell isainfo -b 2>/dev/null | grep -i -c "64")
287 ifeq ($(IS_64),1)
288 CXXFLAGS += -m64
289 else ifeq ($(IS_64),0)
290 CXXFLAGS += -m32
291 endif
292 ifneq ($(SUNCC_513_OR_LATER),0)
293 CXXFLAGS += -native
294 endif
295 # Add for non-i386
296 ifneq ($(IS_X86),1)
297 CXXFLAGS += -KPIC
298 endif
299 # Add to all Solaris
300 CXXFLAGS += -template=no%extdef
301 SUN_CC10_BUGGY := $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
302 ifneq ($(SUN_CC10_BUGGY),0)
303 # -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
304 # remove it if you get "already had a body defined" errors in vector.cc
305 CXXFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
306 endif
307 #ifneq ($SUNCC_512_OR_LATER),0)
308 #CXXFLAGS += -xarch=aes -D__AES__=1 -xarch=no%sse4_1 -xarch=no%sse4_2
309 #endif
310 AR = $(CXX)
311 ARFLAGS = -xar -o
312 RANLIB = true
313 endif
314 
315 # Undefined Behavior Sanitizer (UBsan) testing. There's no sense in
316 # allowing unaligned data access. There will too many findings.
317 ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
318 ifeq ($(findstring -fsanitize=undefined,$(CXXFLAGS)),)
319 CXXFLAGS += -fsanitize=undefined
320 endif # CXXFLAGS
321 ifeq ($(findstring -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS,$(CXXFLAGS)),)
322 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
323 endif # CXXFLAGS
324 endif # UBsan
325 
326 # Address Sanitizer (Asan) testing. Issue 'make asan'.
327 ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
328 ifeq ($(findstring -fsanitize=address,$(CXXFLAGS)),)
329 CXXFLAGS += -fsanitize=address
330 endif # CXXFLAGS
331 ifeq ($(findstring -fno-omit-frame-pointer,$(CXXFLAGS)),)
332 CXXFLAGS += -fno-omit-frame-pointer
333 endif # CXXFLAGS
334 endif # Asan
335 
336 # LD gold linker testing. Triggered by 'LD=ld.gold'.
337 ifeq ($(findstring ld.gold,$(LD)),ld.gold)
338 ifeq ($(findstring -fuse-ld=gold,$(CXXFLAGS)),)
339 ELF_FORMAT := $(shell file `which ld.gold` 2>&1 | cut -d":" -f 2 | $(EGREP) -i -c "elf")
340 ifneq ($(ELF_FORMAT),0)
341 LDFLAGS += -fuse-ld=gold
342 endif # ELF/ELF64
343 endif # CXXFLAGS
344 endif # Gold
345 
346 # Aligned access testing. Issue 'make aligned'.
347 ifneq ($(filter align aligned,$(MAKECMDGOALS)),)
348 ifeq ($(findstring -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS,$(CXXFLAGS)),)
349 CXXFLAGS += -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
350 endif # CXXFLAGS
351 endif # Aligned access
352 
353 # GCC code coverage. Issue 'make coverage'.
354 ifneq ($(filter coverage,$(MAKECMDGOALS)),)
355 ifeq ($(findstring -coverage,$(CXXFLAGS)),)
356 CXXFLAGS += -coverage
357 endif # -coverage
358 endif # GCC code coverage
359 
360 # Debug testing on GNU systems. Triggered by -DDEBUG.
361 # Newlib test due to http://sourceware.org/bugzilla/show_bug.cgi?id=20268
362 ifneq ($(filter -DDEBUG -DDEBUG=1,$(CXXFLAGS)),)
363 USING_GLIBCXX := $(shell $(CXX) -x c++ $(CXXFLAGS) -E adhoc.cpp.proto 2>&1 | $(EGREP) -i -c "__GLIBCXX__")
364 ifneq ($(USING_GLIBCXX),0)
365 HAS_NEWLIB := $(shell $(CXX) -x c++ $(CXXFLAGS) -E adhoc.cpp.proto 2>&1 | $(EGREP) -i -c "__NEWLIB__")
366 ifeq ($(HAS_NEWLIB),0)
367 ifeq ($(findstring -D_GLIBCXX_DEBUG,$(CXXFLAGS)),)
368 CXXFLAGS += -D_GLIBCXX_DEBUG
369 endif # CXXFLAGS
370 endif # NAS_NEWLIB
371 endif # USING_GLIBCXX
372 endif # GNU Debug build
373 
374 # Dead code stripping. Issue 'make lean'.
375 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
376 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
377 CXXFLAGS += -ffunction-sections
378 endif # CXXFLAGS
379 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
380 CXXFLAGS += -fdata-sections
381 endif # CXXFLAGS
382 ifneq ($(IS_DARWIN),0)
383 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
384 LDFLAGS += -Wl,-dead_strip
385 endif # CXXFLAGS
386 else # BSD, Linux and Unix
387 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
388 LDFLAGS += -Wl,--gc-sections
389 endif # LDFLAGS
390 endif # MAKECMDGOALS
391 endif # Dead code stripping
392 
393 # For Shared Objects, Diff, Dist/Zip rules
394 LIB_VER := $(shell $(EGREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3)
395 LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
396 LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
397 LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
398 
399 ifeq ($(strip $(LIB_PATCH)),)
400 LIB_PATCH := 0
401 endif
402 
403 ifeq ($(HAS_SOLIB_VERSION),1)
404 # Full version suffix for shared library
405 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
406 # Different patchlevels are compatible, minor versions are not
407 SOLIB_COMPAT_SUFFIX=.6
408 SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
409 endif # HAS_SOLIB_VERSION
410 
411 ###########################################################
412 ##### Source and object files #####
413 ###########################################################
414 
415 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
416 SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp winpipes.cpp cryptlib_bds.cpp,$(wildcard *.cpp))
417 
418 # Need CPU for X86/X64/X32 and ARM
419 ifeq ($(IS_X86)$(IS_X64)$(IS_ARM32)$(IS_ARM64),0000)
420  SRCS := $(filter-out cpu.cpp, $(SRCS))
421 endif
422 # Need RDRAND for X86/X64/X32
423 ifeq ($(IS_X86)$(IS_X64),00)
424  SRCS := $(filter-out rdrand.cpp, $(SRCS))
425 endif
426 
427 ifneq ($(IS_MINGW),0)
428 SRCS += winpipes.cpp
429 endif
430 
431 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
432 OBJS := $(SRCS:.cpp=.o)
433 
434 # List test.cpp first to tame C++ static initialization problems.
435 TESTSRCS := test.cpp bench1.cpp bench2.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp
436 TESTOBJS := $(TESTSRCS:.cpp=.o)
437 LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
438 
439 # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
440 DLLSRCS := cryptlib.cpp cpu.cpp integer.cpp shacal2.cpp md5.cpp shark.cpp zinflate.cpp gf2n.cpp salsa.cpp xtr.cpp oaep.cpp polynomi.cpp rc2.cpp default.cpp wait.cpp wake.cpp twofish.cpp iterhash.cpp adler32.cpp elgamal.cpp marss.cpp blowfish.cpp ecp.cpp filters.cpp strciphr.cpp camellia.cpp ida.cpp zlib.cpp des.cpp crc.cpp algparam.cpp dessp.cpp tea.cpp eax.cpp network.cpp emsa2.cpp pkcspad.cpp squaretb.cpp idea.cpp authenc.cpp hmac.cpp zdeflate.cpp xtrcrypt.cpp queue.cpp mars.cpp rc5.cpp blake2.cpp hrtimer.cpp eprecomp.cpp hex.cpp dsa.cpp sha.cpp fips140.cpp gzip.cpp seal.cpp files.cpp base32.cpp vmac.cpp tigertab.cpp sharkbox.cpp safer.cpp randpool.cpp esign.cpp arc4.cpp osrng.cpp skipjack.cpp seed.cpp sha3.cpp sosemanuk.cpp bfinit.cpp rabin.cpp 3way.cpp rw.cpp rdrand.cpp rsa.cpp rdtables.cpp gost.cpp socketft.cpp tftables.cpp nbtheory.cpp panama.cpp modes.cpp rijndael.cpp casts.cpp chacha.cpp gfpcrypt.cpp poly1305.cpp dll.cpp ec2n.cpp blumshub.cpp algebra.cpp basecode.cpp base64.cpp cbcmac.cpp rc6.cpp dh2.cpp gf256.cpp mqueue.cpp misc.cpp pssr.cpp channels.cpp tiger.cpp cast.cpp rng.cpp square.cpp asn.cpp whrlpool.cpp md4.cpp dh.cpp ccm.cpp md2.cpp mqv.cpp gf2_32.cpp ttmac.cpp luc.cpp trdlocal.cpp pubkey.cpp gcm.cpp ripemd.cpp eccrypto.cpp serpent.cpp cmac.cpp
441 DLLOBJS := $(DLLSRCS:.cpp=.export.o)
442 
443 # Import lib testing
444 LIBIMPORTOBJS := $(LIBOBJS:.o=.import.o)
445 TESTIMPORTOBJS := $(TESTOBJS:.o=.import.o)
446 DLLTESTOBJS := dlltest.dllonly.o
447 
448 ###########################################################
449 ##### Targets and Recipes #####
450 ###########################################################
451 
452 .PHONY: all
453 all: cryptest.exe
454 
455 ifneq ($(IS_DARWIN),0)
456 static: libcryptopp.a
457 shared dynamic dylib: libcryptopp.dylib
458 else
459 static: libcryptopp.a
460 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
461 endif
462 
463 .PHONY: deps
464 deps GNUmakefile.deps:
465  $(CXX) $(CXXFLAGS) -MM *.cpp > GNUmakefile.deps
466 
467 # CXXFLAGS are tuned earlier.
468 .PHONY: asan ubsan align aligned
469 asan ubsan align aligned: libcryptopp.a cryptest.exe
470 
471 # CXXFLAGS are tuned earlier. Applications must use linker flags
472 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
473 .PHONY: lean
474 lean: static dynamic cryptest.exe
475 
476 # May want to export CXXFLAGS="-g3 -O1"
477 .PHONY: coverage
478 coverage: libcryptopp.a cryptest.exe
479  lcov --base-directory . --directory . --zerocounters -q
480  ./cryptest.exe v
481  ./cryptest.exe tv all
482  lcov --base-directory . --directory . -c -o cryptest.info
483  lcov --remove cryptest.info "*test.*" "bench*.cpp" "validat*.*" "/usr/*" -o cryptest.info
484  rm -rf ./TestCoverage/
485  genhtml -o ./TestCoverage/ -t "cryptest.exe test coverage" --num-spaces 4 cryptest.info
486 
487 .PHONY: test check
488 test check: cryptest.exe
489  ./cryptest.exe v
490 
491 # Used to generate list of source files for Autotools, CMakeList, Android.mk, etc
492 .PHONY: sources
493 sources:
494  $(info Library sources: $(filter-out fipstest.cpp $(TESTSRCS),$(SRCS)))
495  $(info )
496  $(info Test sources: $(TESTSRCS))
497 
498 # Directory we want (can't specify on Doygen command line)
499 DOCUMENT_DIRECTORY := ref$(LIB_VER)
500 # Directory Doxygen uses (specified in Doygen config file)
501 ifeq ($(wildcard Doxyfile),Doxyfile)
502 DOXYGEN_DIRECTORY := $(strip $(shell $(EGREP) "OUTPUT_DIRECTORY" Doxyfile | grep -v "\#" | cut -d "=" -f 2))
503 endif
504 # Default directory (in case its missing in the config file)
505 ifeq ($(strip $(DOXYGEN_DIRECTORY)),)
506 DOXYGEN_DIRECTORY := html-docs
507 endif
508 
509 # Builds the documentation. Directory name is ref563, ref570, etc.
510 .PHONY: docs html
511 docs html:
512  -$(RM) -r $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/ html-docs/
513  doxygen Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
514  $(MV) $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/
515  -$(RM) CryptoPPRef.zip
516  zip -9 CryptoPPRef.zip -x ".*" -x "*/.*" -r $(DOCUMENT_DIRECTORY)/
517 
518 .PHONY: clean
519 clean:
520  -$(RM) libcryptopp.a libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
521 ifeq ($(HAS_SOLIB_VERSION),1)
522  -$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
523 endif
524  -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
525  -$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct rdrand-???.o
526  -$(RM) *.gcno *.gcda *.stackdump core-*
527  -$(RM) /tmp/adhoc.exe
528 ifneq ($(wildcard /tmp/cryptopp_test/),)
529  -$(RM) -r /tmp/cryptopp_test/
530 endif
531 ifneq ($(wildcard *.exe.dSYM),)
532  -$(RM) -r *.exe.dSYM/
533 endif
534 ifneq ($(wildcard *.dylib.dSYM),)
535  -$(RM) -r *.dylib.dSYM/
536 endif
537 ifneq ($(wildcard cov-int/),)
538  -$(RM) -r cov-int/
539 endif
540 
541 .PHONY: distclean
542 distclean: clean
543  -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt cryptest-*.txt
544  -$(RM) CMakeCache.txt Makefile CTestTestfile.cmake cmake_install.cmake cryptopp-config-version.cmake
545  -$(RM) cryptopp.tgz *.o *.bc *.ii *.s *~
546 ifneq ($(wildcard CMakeFiles/),)
547  -$(RM) -r CMakeFiles/
548 endif
549 ifneq ($(wildcard $(DOCUMENT_DIRECTORY)/),)
550  -$(RM) -r $(DOCUMENT_DIRECTORY)/
551 endif
552 ifneq ($(wildcard TestCoverage/),)
553  -$(RM) -r TestCoverage/
554 endif
555 ifneq ($(wildcard cryptopp$(LIB_VER)\.*),)
556  -$(RM) cryptopp$(LIB_VER)\.*
557 endif
558 ifneq ($(wildcard $(DOC_DIRECTORY)),)
559  -$(RM) -r $(DOC_DIRECTORY)
560 endif
561 ifneq ($(wildcard CryptoPPRef.zip),)
562  -$(RM) CryptoPPRef.zip
563 endif
564 
565 .PHONY: install
566 install:
567  $(MKDIR) -p $(DESTDIR)$(INCLUDEDIR)/cryptopp
568  $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
569  -$(CHMOD) 0755 $(DESTDIR)$(INCLUDEDIR)/cryptopp
570  -$(CHMOD) 0644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
571 ifneq ($(wildcard libcryptopp.a),)
572  $(MKDIR) -p $(DESTDIR)$(LIBDIR)
573  $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
574  -$(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
575 endif
576 ifneq ($(wildcard cryptest.exe),)
577  $(MKDIR) -p $(DESTDIR)$(BINDIR)
578  $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
579  -$(CHMOD) 0755 $(DESTDIR)$(BINDIR)/cryptest.exe
580  $(MKDIR) -p $(DESTDIR)$(DATADIR)/cryptopp
581  $(CP) -r TestData $(DESTDIR)$(DATADIR)/cryptopp
582  $(CP) -r TestVectors $(DESTDIR)$(DATADIR)/cryptopp
583  -$(CHMOD) 0755 $(DESTDIR)$(DATADIR)/cryptopp
584  -$(CHMOD) 0755 $(DESTDIR)$(DATADIR)/cryptopp/TestData
585  -$(CHMOD) 0755 $(DESTDIR)$(DATADIR)/cryptopp/TestVectors
586  -$(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestData/*.dat
587  -$(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
588 endif
589 ifneq ($(wildcard libcryptopp.dylib),)
590  $(MKDIR) -p $(DESTDIR)$(LIBDIR)
591  $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
592  -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
593  -$(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
594 endif
595 ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
596  $(MKDIR) -p $(DESTDIR)$(LIBDIR)
597  $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
598  -$(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
599 ifeq ($(HAS_SOLIB_VERSION),1)
600  -$(LN) -sf libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
601  $(LDCONF) $(DESTDIR)$(LIBDIR)
602 endif
603 endif
604 
605 .PHONY: remove uninstall
606 remove uninstall:
607  -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
608  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
609  -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
610  -$(RM) -r $(DESTDIR)$(DATADIR)/cryptopp
611 ifneq ($(IS_DARWIN),0)
612  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
613 else
614  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
615 ifeq ($(HAS_SOLIB_VERSION),1)
616  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
617  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
618  $(LDCONF) $(DESTDIR)$(LIBDIR)
619 endif
620 endif
621 
622 libcryptopp.a: $(LIBOBJS)
623  $(AR) $(ARFLAGS) $@ $(LIBOBJS)
624 ifeq ($(IS_SUN),0)
625  $(RANLIB) $@
626 endif
627 
628 ifeq ($(HAS_SOLIB_VERSION),1)
629 .PHONY: libcryptopp.so
630 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX) | so_warning
631 endif
632 
633 libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS)
634  $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(CXXFLAGS) $(LDFLAGS) $(LIBOBJS) $(LDLIBS)
635 ifeq ($(HAS_SOLIB_VERSION),1)
636  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
637  -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
638 endif
639 
640 libcryptopp.dylib: $(LIBOBJS)
641  $(CXX) -dynamiclib -o $@ $(CXXFLAGS) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS)
642 
643 cryptest.exe: libcryptopp.a $(TESTOBJS)
644  $(CXX) -o $@ $(CXXFLAGS) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
645 
646 # Makes it faster to test changes
647 nolib: $(OBJS)
648  $(CXX) -o ct $(CXXFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS)
649 
650 dll: cryptest.import.exe dlltest.exe
651 
652 cryptopp.dll: $(DLLOBJS)
653  $(CXX) -shared -o $@ $(CXXFLAGS) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcryptopp.dll.a
654 
655 libcryptopp.import.a: $(LIBIMPORTOBJS)
656  $(AR) $(ARFLAGS) $@ $(LIBIMPORTOBJS)
657 ifeq ($(IS_SUN),0)
658  $(RANLIB) $@
659 endif
660 
661 cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS)
662  $(CXX) -o $@ $(CXXFLAGS) $(TESTIMPORTOBJS) -L. -lcryptopp.dll -lcryptopp.import $(LDFLAGS) $(LDLIBS)
663 
664 dlltest.exe: cryptopp.dll $(DLLTESTOBJS)
665  $(CXX) -o $@ $(CXXFLAGS) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS)
666 
667 # This recipe prepares the distro files
668 TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt CMakeLists.txt config.compat Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcxproj *.filters cryptopp.rc TestVectors/*.txt TestData/*.dat TestScripts/*.sh TestScripts/*.pl TestScripts/*.cmd
669 EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ TestScripts/
670 
671 ifeq ($(wildcard Filelist.txt),Filelist.txt)
672 DIST_FILES := $(shell cat Filelist.txt)
673 endif
674 
675 .PHONY: trim
676 trim:
677 ifneq ($(IS_DARWIN),0)
678  sed -i '' -e's/[[:space:]]*$$//' *.compat *.sh *.h *.cpp *.sln *.vcxproj GNUmakefile GNUmakefile-cross
679  make convert
680 else
681  sed -i -e's/[[:space:]]*$$//' *.compat *.sh *.h *.cpp *.sln *.vcxproj GNUmakefile GNUmakefile-cross
682  make convert
683 endif
684 
685 .PHONY: convert
686 convert:
687  -$(CHMOD) 0700 TestVectors/ TestData/ TestScripts/
688  -$(CHMOD) 0600 $(TEXT_FILES) *.asm *.S *.zip *.cmake TestVectors/*.txt TestData/*.dat
689  -$(CHMOD) 0700 $(EXEC_FILES) *.sh *.cmd TestScripts/*.sh TestScripts/*.pl TestScripts/*.cmd
690  -$(CHMOD) 0700 *.cmd *.sh GNUmakefile GNUmakefile-cross TestScripts/*.sh TestScripts/*.pl
691  -unix2dos --keepdate --quiet $(TEXT_FILES) *.asm *.cmd *.cmake TestScripts/*.pl TestScripts/*.cmd
692  -dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.S *.sh TestScripts/*.sh
693 ifneq ($(IS_DARWIN),0)
694  -xattr -c *
695 endif
696 
697 # Build the ZIP file with source files. No documentation.
698 .PHONY: zip dist
699 zip dist: | distclean convert
700  zip -q -9 cryptopp$(LIB_VER).zip $(DIST_FILES)
701 
702 # Build the ISO to transfer the ZIP to old distros via CDROM
703 .PHONY: iso
704 iso: | zip
705 ifneq ($(IS_DARWIN),0)
706  $(MKDIR) -p $(PWD)/cryptopp$(LIB_VER)
707  $(CP) cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER)
708  hdiutil makehybrid -iso -joliet -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER)
709  -$(RM) -r $(PWD)/cryptopp$(LIB_VER)
710 else ifneq ($(IS_LINUX),0)
711  $(MKDIR) -p $(PWD)/cryptopp$(LIB_VER)
712  $(CP) cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER)
713  genisoimage -q -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER)
714  -$(RM) -r $(PWD)/cryptopp$(LIB_VER)
715 endif
716 
717 # CRYPTOPP_CPU_SPEED in GHz
718 CRYPTOPP_CPU_SPEED ?= 2.4
719 .PHONY: bench benchmark benchmarks
720 bench benchmark benchmarks: cryptest.exe
721  rm -f benchmarks.html
722  echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">" >> benchmarks.html
723  echo "<HTML>" >> benchmarks.html
724  echo "<HEAD>" >> benchmarks.html
725  echo "<TITLE>Speed Comparison of Popular Crypto Algorithms</TITLE>" >> benchmarks.html
726  echo "</HEAD>" >> benchmarks.html
727  echo "<BODY>" >> benchmarks.html
728  echo "<H1><a href=\"http://www.cryptopp.com\">Crypto++</a>" $(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH) "Benchmarks</H1>" >> benchmarks.html
729  echo "<P>Here are speed benchmarks for some commonly used cryptographic algorithms.</P>" >> benchmarks.html
730  ./cryptest.exe b 3 $(CRYPTOPP_CPU_SPEED) >> benchmarks.html
731  echo "</BODY>" >> benchmarks.html
732  echo "</HTML>" >> benchmarks.html
733 
734 adhoc.cpp: adhoc.cpp.proto
735 ifeq ($(wildcard adhoc.cpp),)
736  cp adhoc.cpp.proto adhoc.cpp
737 else
738  touch adhoc.cpp
739 endif
740 
741 # Include dependencies, if present. You must issue `make deps` to create them.
742 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
743 -include GNUmakefile.deps
744 endif # Dependencies
745 
746 # MacPorts/GCC issue with init_priority. Apple/GCC and Fink/GCC are fine; limit to MacPorts.
747 # Also see http://lists.macosforge.org/pipermail/macports-users/2015-September/039223.html
748 ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER),11)
749 ifeq ($(findstring -DMACPORTS_GCC_COMPILER,$(CXXFLAGS)),)
750 cryptlib.o:
751  $(CXX) $(CXXFLAGS) -DMACPORTS_GCC_COMPILER=1 -c cryptlib.cpp
752 cpu.o:
753  $(CXX) $(CXXFLAGS) -DMACPORTS_GCC_COMPILER=1 -c cpu.cpp
754 endif
755 endif
756 
757 # Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS
758 ifeq ($(findstring -DCRYPTOPP_DATA_DIR,$(CXXFLAGS)),)
759 ifneq ($(strip $(CRYPTOPP_DATA_DIR)),)
760 validat%.o : validat%.cpp
761  $(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c $<
762 bench%.o : bench%.cpp
763  $(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c $<
764 datatest.o : datatest.cpp
765  $(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c $<
766 test.o : test.cpp
767  $(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR=\"$(CRYPTOPP_DATA_DIR)\" -c $<
768 endif
769 endif
770 
771 %.dllonly.o : %.cpp
772  $(CXX) $(CXXFLAGS) -DCRYPTOPP_DLL_ONLY -c $< -o $@
773 
774 %.import.o : %.cpp
775  $(CXX) $(CXXFLAGS) -DCRYPTOPP_IMPORTS -c $< -o $@
776 
777 %.export.o : %.cpp
778  $(CXX) $(CXXFLAGS) -DCRYPTOPP_EXPORTS -c $< -o $@
779 
780 %.bc : %.cpp
781  $(CXX) $(CXXFLAGS) -c $<
782 
783 %.o : %.cpp
784  $(CXX) $(CXXFLAGS) -c $<
785 
786 .PHONY: so_warning
787 so_warning:
788 ifeq ($(HAS_SOLIB_VERSION),1)
789  $(info WARNING: Only the symlinks to the shared-object library have been updated.)
790  $(info WARNING: If the library is installed in a system directory you will need)
791  $(info WARNING: to run 'ldconfig' to update the shared-object library cache.)
792  $(info )
793 endif