Advertisement
Guest User

Crpyto++ modified makefile for OS X and mobile

a guest
Sep 8th, 2014
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 8.20 KB | None | 0 0
  1. # CXXFLAGS += -DDEBUG -g3 -O0 -fPIC
  2. CXXFLAGS += -DNDEBUG -g2 -Os -fPIC
  3.  
  4. # -O3 fails to link on Cygwin GCC version 4.5.3
  5. # -fPIC is supported. Please report any breakage of -fPIC as a bug.
  6. # CXXFLAGS += -fPIC
  7. # the following options reduce code size, but breaks link or makes link very slow on some systems
  8. # CXXFLAGS += -ffunction-sections -fdata-sections
  9. # LDFLAGS += -Wl,--gc-sections
  10. CXXFLAGS += -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable
  11. ARFLAGS = -cr   # ar needs the dash on OpenBSD
  12. RANLIB ?= ranlib
  13. CP = cp
  14. MKDIR = mkdir
  15. EGREP = egrep
  16. CHMOD = chmod
  17. UNAME = $(shell uname)
  18. ISX86 = $(shell uname -m | $(EGREP) -c "i.86|x86|i86|amd64")
  19. IS_SUN_CC = $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: Sun")
  20. IS_LINUX = $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -c "linux")
  21. IS_DARWIN = $(shell uname -s | $(EGREP) -i -c "Darwin")
  22. IS_MINGW = $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -c "mingw")
  23. CLANG_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang")
  24.  
  25. # Set in the environment
  26. ifeq ($(IS_CROSS_COMPILE),1)
  27.   ISX86=0
  28.   IS_LINUX=0
  29.   IS_MINGW=0
  30.   IS_DARWIN=0
  31.   UNAME=CrossCompile
  32. endif
  33.  
  34. # Default prefix for make install
  35. ifeq ($(PREFIX),)
  36. PREFIX = /usr
  37. endif
  38.  
  39. ifeq ($(CXX),gcc)   # for some reason CXX is gcc on cygwin 1.1.4
  40. CXX = g++
  41. endif
  42.  
  43. ifeq ($(ISX86),1)
  44.  
  45. GCC42_OR_LATER = $(shell $(CXX) -v 2>&1 | $(EGREP) -c "^gcc version (4.[2-9]|[5-9])")
  46. INTEL_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -c "\(ICC\)")
  47. ICC111_OR_LATER = $(shell $(CXX) --version 2>&1 | $(EGREP) -c "\(ICC\) ([2-9][0-9]|1[2-9]|11\.[1-9])")
  48. 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])")
  49. 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])")
  50. 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])")
  51.  
  52. ifneq ($(GCC42_OR_LATER),0)
  53. CXXFLAGS += -march=native
  54. endif
  55.  
  56. ifeq ($(IS_DARWIN),1)
  57. CXXFLAGS += -arch x86_64 -arch i386
  58. endif
  59.  
  60. ifneq ($(INTEL_COMPILER),0)
  61. CXXFLAGS += -wd68 -wd186 -wd279 -wd327
  62. ifeq ($(ICC111_OR_LATER),0)
  63. # "internal error: backend signals" occurs on some x86 inline assembly with ICC 9 and some x64 inline assembly with ICC 11.0
  64. # if you want to use Crypto++'s assembly code with ICC, try enabling it on individual files
  65. CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
  66. endif
  67. endif
  68.  
  69. ifeq ($(GAS210_OR_LATER),0) # .intel_syntax wasn't supported until GNU assembler 2.10
  70. CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
  71. else
  72. ifeq ($(GAS217_OR_LATER),0)
  73. CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
  74. else
  75. ifeq ($(GAS219_OR_LATER),0)
  76. CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
  77. endif
  78. endif
  79. ifeq ($(UNAME),SunOS)
  80. CXXFLAGS += -Wa,--divide    # allow use of "/" operator
  81. endif
  82. endif
  83.  
  84. endif   # ISX86
  85.  
  86. ifeq ($(UNAME),)    # for DJGPP, where uname doesn't exist
  87. CXXFLAGS += -mbnu210
  88. else
  89. CXXFLAGS += -pipe
  90. endif
  91.  
  92. ifeq ($(IS_MINGW),1)
  93. LDLIBS += -lws2_32
  94. endif
  95.  
  96. ifeq ($(IS_LINUX),1)
  97. LDFLAGS += -pthread
  98. ifneq ($(shell uname -i | $(EGREP) -c "(_64|d64)"),0)
  99. M32OR64 = -m64
  100. endif
  101. endif
  102.  
  103. ifeq ($(IS_DARWIN),1)
  104.   AR = libtool
  105.   ARFLAGS = -static -o
  106.   CXX = /usr/local/bin/clang++
  107. #  CXXFLAGS += -stdlib=libc++
  108.   IS_GCC2 = $(shell $(CXX) -v 2>&1 | $(EGREP) -c gcc-932)
  109.   ifeq ($(IS_GCC2),1)
  110.     CXXFLAGS += -fno-coalesce-templates -fno-coalesce-static-vtables
  111.     LDFLAGS += -flat_namespace -undefined suppress -m
  112.   endif
  113. endif
  114.  
  115. # Begin iOS cross-compile configuration.
  116. # See http://www.cryptopp.com/wiki/iOS_(Command_Line).
  117. ifeq ($(IS_IOS),1)
  118.   CXX = clang++
  119.  
  120.   CXXFLAGS = -DNDEBUG -g -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM
  121.   CXXFLAGS += -arch $(IOS_ARCH) -isysroot $(IOS_SYSROOT)
  122.   CXXFLAGS += -stdlib=libc++
  123.  
  124.   AR = libtool
  125.   ARFLAGS = -static -o
  126.   LDFLAGS += -flat_namespace
  127. endif
  128.  
  129. # Begin Android cross-compile configuration.
  130. # See http://www.cryptopp.com/wiki/Android_(Command_Line).
  131. ifeq ($(IS_ANDROID),1)
  132.   # CPP, CXX, AR, etc are set in 'setenv-android.sh'
  133.   CXXFLAGS += -fPIC -DCRYPTOPP_DISABLE_ASM --sysroot=$(ANDROID_SYSROOT) -I$(ANDROID_STL_INC)
  134.   LDLIBS += $(ANDROID_STL_LIB)
  135. endif
  136.  
  137. ifeq ($(UNAME),SunOS)
  138. LDLIBS += -lnsl -lsocket
  139. M32OR64 = -m$(shell isainfo -b)
  140. endif
  141.  
  142. ifneq ($(CLANG_COMPILER),0)
  143. CXXFLAGS += -Wno-tautological-compare -Wno-unused-value
  144. endif
  145.  
  146. ifneq ($(IS_SUN_CC),0)  # override flags for CC Sun C++ compiler
  147. CXXFLAGS = -DNDEBUG -O -g0 -native -template=no%extdef $(M32OR64)
  148. LDFLAGS =
  149. AR = $(CXX)
  150. ARFLAGS = -xar -o
  151. RANLIB = true
  152. SUN_CC10_BUGGY = $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
  153. ifneq ($(SUN_CC10_BUGGY),0)
  154. # -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
  155. # remove it if you get "already had a body defined" errors in vector.cc
  156. CXXFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
  157. endif
  158. endif
  159.  
  160. SRCS = $(wildcard *.cpp)
  161. ifeq ($(SRCS),)             # workaround wildcard function bug in GNU Make 3.77
  162. SRCS = $(shell echo *.cpp)
  163. endif
  164.  
  165. OBJS = $(SRCS:.cpp=.o)
  166. # test.o needs to be after bench.o for cygwin 1.1.4 (possible ld bug?)
  167. TESTOBJS = bench.o bench2.o test.o validat1.o validat2.o validat3.o adhoc.o datatest.o regtest.o fipsalgt.o dlltest.o
  168. LIBOBJS = $(filter-out $(TESTOBJS),$(OBJS))
  169.  
  170. DLLSRCS = algebra.cpp algparam.cpp asn.cpp basecode.cpp cbcmac.cpp channels.cpp cryptlib.cpp des.cpp dessp.cpp dh.cpp dll.cpp dsa.cpp ec2n.cpp eccrypto.cpp ecp.cpp eprecomp.cpp files.cpp filters.cpp fips140.cpp fipstest.cpp gf2n.cpp gfpcrypt.cpp hex.cpp hmac.cpp integer.cpp iterhash.cpp misc.cpp modes.cpp modexppc.cpp mqueue.cpp nbtheory.cpp oaep.cpp osrng.cpp pch.cpp pkcspad.cpp pubkey.cpp queue.cpp randpool.cpp rdtables.cpp rijndael.cpp rng.cpp rsa.cpp sha.cpp simple.cpp skipjack.cpp strciphr.cpp trdlocal.cpp
  171. DLLOBJS = $(DLLSRCS:.cpp=.export.o)
  172. LIBIMPORTOBJS = $(LIBOBJS:.o=.import.o)
  173. TESTIMPORTOBJS = $(TESTOBJS:.o=.import.o)
  174. DLLTESTOBJS = dlltest.dllonly.o
  175.  
  176. all: cryptest.exe
  177. static: libcryptopp.a
  178. dynamic: libcryptopp.so
  179.  
  180. test: cryptest.exe
  181.     ./cryptest.exe v
  182.  
  183. clean:
  184.     -$(RM) cryptest.exe libcryptopp.a libcryptopp.so $(LIBOBJS) $(TESTOBJS) cryptopp.dll libcryptopp.dll.a libcryptopp.import.a cryptest.import.exe dlltest.exe $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTI MPORTOBJS) $(DLLTESTOBJS)
  185.  
  186. install:
  187.     $(MKDIR) -p $(PREFIX)/include/cryptopp $(PREFIX)/lib $(PREFIX)/bin
  188.     -$(CP) *.h $(PREFIX)/include/cryptopp
  189.     -$(CP) *.a $(PREFIX)/lib
  190.     -$(CP) *.so $(PREFIX)/lib
  191.     -$(CP) *.exe $(PREFIX)/bin
  192.     -$(CHMOD) 0755 $(PREFIX)/include
  193.     -$(CHMOD) 0755 $(PREFIX)/include/cryptopp
  194.     -$(CHMOD) 0755 $(PREFIX)/lib
  195.     -$(CHMOD) 0755 $(PREFIX)/bin
  196.     -$(CHMOD) 0644 $(PREFIX)/include/cryptopp/*
  197.     -$(CHMOD) 0755 $(PREFIX)/lib/*
  198.     -$(CHMOD) 0755 $(PREFIX)/bin/*
  199.  
  200. remove:
  201.     -$(RM) -rf $(PREFIX)/include/cryptopp
  202.     -$(RM) $(PREFIX)/lib/libcryptopp.a
  203.     -$(RM) $(PREFIX)/lib/libcryptopp.so
  204.     -$(RM) $(PREFIX)/bin/cryptest.exe
  205.  
  206. libcryptopp.a: $(LIBOBJS)
  207.     $(AR) $(ARFLAGS) $@ $(LIBOBJS)
  208.     $(RANLIB) $@
  209.  
  210. libcryptopp.so: $(LIBOBJS)
  211.     $(CXX) $(CXXFLAGS) -shared -o $@ $(LIBOBJS) $(LDFLAGS) $(LDLIBS)
  212.  
  213. cryptest.exe: libcryptopp.a $(TESTOBJS)
  214.     $(CXX) -o $@ $(CXXFLAGS) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS) $(LDLIBS)
  215.  
  216. nolib: $(OBJS)      # makes it faster to test changes
  217.     $(CXX) -o ct $(CXXFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS)
  218.  
  219. dll: cryptest.import.exe dlltest.exe
  220.  
  221. cryptopp.dll: $(DLLOBJS)
  222.     $(CXX) -shared -o $@ $(CXXFLAGS) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcryptopp.dll.a
  223.  
  224. libcryptopp.import.a: $(LIBIMPORTOBJS)
  225.     $(AR) $(ARFLAGS) $@ $(LIBIMPORTOBJS)
  226.     $(RANLIB) $@
  227.  
  228. cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS)
  229.     $(CXX) -o $@ $(CXXFLAGS) $(TESTIMPORTOBJS) -L. -lcryptopp.dll -lcryptopp.import $(LDFLAGS) $(LDLIBS)
  230.  
  231. dlltest.exe: cryptopp.dll $(DLLTESTOBJS)
  232.     $(CXX) -o $@ $(CXXFLAGS) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS)
  233.  
  234. adhoc.cpp: adhoc.cpp.proto
  235. ifeq ($(wildcard adhoc.cpp),)
  236.     cp adhoc.cpp.proto adhoc.cpp
  237. else
  238.     touch adhoc.cpp
  239. endif
  240.  
  241. %.dllonly.o : %.cpp
  242.     $(CXX) $(CXXFLAGS) -DCRYPTOPP_DLL_ONLY -c $< -o $@
  243.  
  244. %.import.o : %.cpp
  245.     $(CXX) $(CXXFLAGS) -DCRYPTOPP_IMPORTS -c $< -o $@
  246.  
  247. %.export.o : %.cpp
  248.     $(CXX) $(CXXFLAGS) -DCRYPTOPP_EXPORTS -c $< -o $@
  249.  
  250. %.o : %.cpp
  251.     $(CXX) $(CXXFLAGS) -c $<
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement