1 CXXFLAGS ?= -DNDEBUG -g2 -Os -fPIC -pipe
3 # The following options reduce code size, but breaks link or makes link very slow on some systems
4 # CXXFLAGS += -ffunction-sections -fdata-sections
5 # LDFLAGS += -Wl,--gc-sections
17 CLANG_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang")
23 # Can be used by Android and Embeeded cross-compiles. Disable by default because
24 # Android and embedded users typically don't run this configuration.
25 HAS_SOLIB_VERSION ?= 0
27 # Default prefix for make install
32 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
34 DATADIR := $(PREFIX)/share
37 LIBDIR := $(PREFIX)/lib
40 BINDIR := $(PREFIX)/bin
43 INCLUDEDIR := $(PREFIX)/include
46 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
51 # Sadly, we can't actually use GCC_PRAGMA_AWARE because of GCC bug 53431.
52 # Its a shame because GCC has so much to offer by the way of analysis.
53 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431
54 ifneq ($(CLANG_COMPILER),0)
58 # iOS cross-compile configuration.
59 # See http://www.cryptopp.com/wiki/iOS_(Command_Line).
63 CXXFLAGS += $(IOS_FLAGS) -arch $(IOS_ARCH)
64 CXXFLAGS += -isysroot $(IOS_SYSROOT) -stdlib=libc++
71 # Android cross-compile configuration.
72 # See http://www.cryptopp.com/wiki/Android_(Command_Line).
73 ifeq ($(IS_ANDROID),1)
74 # CPP, CXX, AR, RANLIB, LD, etc are set in 'setenv-android.sh'
75 CXXFLAGS += $(AOSP_FLAGS) -DANDROID --sysroot=$(AOSP_SYSROOT)
76 CXXFLAGS += -Wa,--noexecstack -I$(AOSP_STL_INC)
78 # c++config.h shows up in odd places at times.
79 ifneq ($(AOSP_BITS_INC),)
80 CXXFLAGS += -I$(AOSP_BITS_INC)
83 LDLIBS += $(AOSP_STL_LIB)
86 # ARM embedded cross-compile configuration.
87 # See http://www.cryptopp.com/wiki/ARM_Embedded_(Command_Line)
88 # and http://www.cryptopp.com/wiki/ARM_Embedded_(Bare Metal).
89 ifeq ($(IS_ARM_EMBEDDED),1)
90 # CPP, CXX, AR, RANLIB, LD, etc are set in 'setenv-embedded.sh'
91 CXXFLAGS += $(ARM_EMBEDDED_FLAGS) --sysroot=$(ARM_EMBEDDED_SYSROOT)
94 # Dead code stripping. Issue 'make lean'.
95 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
96 ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
97 CXXFLAGS += -ffunction-sections
99 ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
100 CXXFLAGS += -fdata-sections
103 ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
104 LDFLAGS += -Wl,-dead_strip
106 else # BSD, Linux and Unix
107 ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
108 LDFLAGS += -Wl,--gc-sections
111 endif # Dead code stripping
113 # List cryptlib.cpp first and cpu.cpp second in an attempt to tame C++ static initialization problems.
114 # The issue spills into POD data types of cpu.cpp due to the storage class of the bools, so cpu.cpp
115 # is the second candidate for explicit initialization order.
116 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))
117 OBJS := $(SRCS:.cpp=.o)
119 # test.o needs to be after bench.o for cygwin 1.1.4 (possible ld bug?)
120 TESTSRCS := bench1.cpp bench2.cpp test.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp
121 TESTOBJS := $(TESTSRCS:.cpp=.o)
122 LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
124 # For Shared Objects, Diff, Dist/Zip rules
125 LIB_VER := $(shell $(EGREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3)
126 LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1)
127 LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2)
128 LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3)
130 ifeq ($(strip $(LIB_PATCH)),)
134 ifeq ($(HAS_SOLIB_VERSION),1)
135 # Full version suffix for shared library
136 SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)
137 # Different patchlevels are compatible, minor versions are not
138 SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR)
139 SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
140 endif # HAS_SOLIB_VERSION
146 static: libcryptopp.a
147 shared dynamic dylib: libcryptopp.dylib
149 static: libcryptopp.a
150 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
156 # CXXFLAGS are tuned earlier. Applications must use linker flags
157 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
159 lean: static dynamic cryptest.exe
163 -$(RM) cryptest.exe libcryptopp.a libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.dylib
164 ifeq ($(HAS_SOLIB_VERSION),1)
165 -$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
167 -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(TESTOBJS)
168 ifneq ($(wildcard *.exe.dSYM),)
169 -$(RM) -r *.exe.dSYM/
171 ifneq ($(wildcard *.dylib.dSYM),)
172 -$(RM) -r *.dylib.dSYM/
177 -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps cryptopp.tgz *.o *.ii *.s
181 $(MKDIR) -p $(DESTDIR)$(INCLUDEDIR)/cryptopp
182 $(CP) *.h $(DESTDIR)$(INCLUDEDIR)/cryptopp
183 -$(CHMOD) 755 $(DESTDIR)$(INCLUDEDIR)/cryptopp
184 -$(CHMOD) 644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
185 ifneq ($(wildcard cryptest.exe),)
186 $(MKDIR) -p $(DESTDIR)$(BINDIR)
187 $(CP) cryptest.exe $(DESTDIR)$(BINDIR)
188 -$(CHMOD) 755 $(DESTDIR)$(BINDIR)/cryptest.exe
190 ifneq ($(wildcard libcryptopp.a),)
191 $(MKDIR) -p $(DESTDIR)$(LIBDIR)
192 $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
193 -$(CHMOD) 644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
195 ifneq ($(wildcard libcryptopp.dylib),)
196 $(MKDIR) -p $(DESTDIR)$(LIBDIR)
197 $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
198 -$(CHMOD) 755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
200 ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
201 $(CP) libcryptopp.so $(DESTDIR)$(LIBDIR)
202 -$(CHMOD) 755 $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
203 ifeq ($(HAS_SOLIB_VERSION),1)
204 -$(LN) -sf libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)/libcryptopp.so
208 .PHONY: remove uninstall
210 -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
211 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
212 -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
214 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
216 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
217 ifeq ($(HAS_SOLIB_VERSION),1)
218 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
219 -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
223 libcryptopp.a: $(LIBOBJS)
224 $(AR) $(ARFLAGS) $@ $(LIBOBJS)
227 ifeq ($(HAS_SOLIB_VERSION),1)
228 .PHONY: libcryptopp.so
229 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
232 libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS)
233 $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(CXXFLAGS) -Wl,--exclude-libs,ALL $(LIBOBJS) $(LDFLAGS) $(LDLIBS)
234 ifeq ($(HAS_SOLIB_VERSION),1)
235 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
236 -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
239 libcryptopp.dylib: $(LIBOBJS)
240 $(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)
242 cryptest.exe: libcryptopp.a $(TESTOBJS)
243 $(CXX) -o $@ $(CXXFLAGS) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
245 # Used to generate list of source files for Autotools, CMakeList and Android.mk
248 $(info Library sources: $(filter-out fipstest.cpp $(TESTSRCS),$(SRCS)))
250 $(info Test sources: $(TESTSRCS))
252 adhoc.cpp: adhoc.cpp.proto
253 ifeq ($(wildcard adhoc.cpp),)
254 cp adhoc.cpp.proto adhoc.cpp
259 # Include dependencies, if present. You must issue `make deps` to create them.
260 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
261 -include GNUmakefile.deps
265 $(CXX) $(CXXFLAGS) -c $<
268 $(CXX) $(CXXFLAGS) -MM *.cpp > GNUmakefile.deps