Crypto++  5.6.5
Free C++ class library of cryptographic schemes
GNUmakefile-cross
1 CXXFLAGS ?= -DNDEBUG -g2 -Os -fPIC -pipe
2 
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
6 
7 AR ?= ar
8 ARFLAGS ?= cr
9 RANLIB ?= ranlib
10 CP ?= cp
11 MV ?= mv
12 CHMOD ?= chmod
13 MKDIR ?= mkdir
14 EGREP ?= egrep
15 LN ?= ln -sf
16 
17 CLANG_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang")
18 
19 IS_IOS ?= 0
20 IS_ANDROID ?= 0
21 IS_ARM_EMBEDDED ?= 0
22 
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
26 
27 # Default prefix for make install
28 ifeq ($(PREFIX),)
29 PREFIX = /usr/local
30 endif
31 
32 # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
33 ifeq ($(DATADIR),)
34 DATADIR := $(PREFIX)/share
35 endif
36 ifeq ($(LIBDIR),)
37 LIBDIR := $(PREFIX)/lib
38 endif
39 ifeq ($(BINDIR),)
40 BINDIR := $(PREFIX)/bin
41 endif
42 ifeq ($(INCLUDEDIR),)
43 INCLUDEDIR := $(PREFIX)/include
44 endif
45 
46 # We honor ARFLAGS, but the "v" option used by default causes a noisy make
47 ifeq ($(ARFLAGS),rv)
48 ARFLAGS = r
49 endif
50 
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)
55 CXXFLAGS += -Wall
56 endif
57 
58 # iOS cross-compile configuration.
59 # See http://www.cryptopp.com/wiki/iOS_(Command_Line).
60 ifeq ($(IS_IOS),1)
61  CXX = clang++
62 
63  CXXFLAGS += $(IOS_FLAGS) -arch $(IOS_ARCH)
64  CXXFLAGS += -isysroot $(IOS_SYSROOT) -stdlib=libc++
65 
66  AR = libtool
67  ARFLAGS = -static -o
68  RANLIB = ranlib
69 endif
70 
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)
77 
78  # c++config.h shows up in odd places at times.
79  ifneq ($(AOSP_BITS_INC),)
80  CXXFLAGS += -I$(AOSP_BITS_INC)
81  endif
82 
83  LDLIBS += $(AOSP_STL_LIB)
84 endif
85 
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)
92 endif
93 
94 # Dead code stripping. Issue 'make lean'.
95 ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
96  ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
97  CXXFLAGS += -ffunction-sections
98  endif # CXXFLAGS
99  ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
100  CXXFLAGS += -fdata-sections
101  endif # CXXFLAGS
102  ifeq ($(IS_IOS),1)
103  ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
104  LDFLAGS += -Wl,-dead_strip
105  endif # CXXFLAGS
106  else # BSD, Linux and Unix
107  ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
108  LDFLAGS += -Wl,--gc-sections
109  endif # LDFLAGS
110  endif # MAKECMDGOALS
111 endif # Dead code stripping
112 
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)
118 
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))
123 
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)
129 
130 ifeq ($(strip $(LIB_PATCH)),)
131 LIB_PATCH := 0
132 endif
133 
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
141 
142 .PHONY: all
143 all: cryptest.exe
144 
145 ifneq ($(IS_IOS),0)
146 static: libcryptopp.a
147 shared dynamic dylib: libcryptopp.dylib
148 else
149 static: libcryptopp.a
150 shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
151 endif
152 
153 test: cryptest.exe
154  ./cryptest.exe v
155 
156 # CXXFLAGS are tuned earlier. Applications must use linker flags
157 # -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X)
158 .PHONY: lean
159 lean: static dynamic cryptest.exe
160 
161 .PHONY: clean
162 clean:
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)
166 endif
167  -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(TESTOBJS)
168 ifneq ($(wildcard *.exe.dSYM),)
169  -$(RM) -r *.exe.dSYM/
170 endif
171 ifneq ($(wildcard *.dylib.dSYM),)
172  -$(RM) -r *.dylib.dSYM/
173 endif
174 
175 .PHONY: distclean
176 distclean: clean
177  -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps cryptopp.tgz *.o *.ii *.s
178 
179 .PHONY: install
180 install:
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
189 endif
190 ifneq ($(wildcard libcryptopp.a),)
191  $(MKDIR) -p $(DESTDIR)$(LIBDIR)
192  $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
193  -$(CHMOD) 644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
194 endif
195 ifneq ($(wildcard libcryptopp.dylib),)
196  $(MKDIR) -p $(DESTDIR)$(LIBDIR)
197  $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
198  -$(CHMOD) 755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
199 endif
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
205 endif
206 endif
207 
208 .PHONY: remove uninstall
209 remove uninstall:
210  -$(RM) -r $(DESTDIR)$(INCLUDEDIR)/cryptopp
211  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.a
212  -$(RM) $(DESTDIR)$(BINDIR)/cryptest.exe
213 ifneq ($(IS_IOS),0)
214  -$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
215 else
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
220 endif
221 endif
222 
223 libcryptopp.a: $(LIBOBJS)
224  $(AR) $(ARFLAGS) $@ $(LIBOBJS)
225  $(RANLIB) $@
226 
227 ifeq ($(HAS_SOLIB_VERSION),1)
228 .PHONY: libcryptopp.so
229 libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
230 endif
231 
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)
237 endif
238 
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)
241 
242 cryptest.exe: libcryptopp.a $(TESTOBJS)
243  $(CXX) -o $@ $(CXXFLAGS) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
244 
245 # Used to generate list of source files for Autotools, CMakeList and Android.mk
246 .PHONY: sources
247 sources:
248  $(info Library sources: $(filter-out fipstest.cpp $(TESTSRCS),$(SRCS)))
249  $(info )
250  $(info Test sources: $(TESTSRCS))
251 
252 adhoc.cpp: adhoc.cpp.proto
253 ifeq ($(wildcard adhoc.cpp),)
254  cp adhoc.cpp.proto adhoc.cpp
255 else
256  touch adhoc.cpp
257 endif
258 
259 # Include dependencies, if present. You must issue `make deps` to create them.
260 ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps)
261 -include GNUmakefile.deps
262 endif # Dependencies
263 
264 %.o : %.cpp
265  $(CXX) $(CXXFLAGS) -c $<
266 
267 GNUmakefile.deps:
268  $(CXX) $(CXXFLAGS) -MM *.cpp > GNUmakefile.deps