From 65849072f4bece0e4e3cd91271f692bd1d8c8d81 Mon Sep 17 00:00:00 2001 From: Todd Knarr Date: Sun, 8 Nov 2015 12:29:56 -0800 Subject: [PATCH 1/3] Linux shared-object library versioning --- GNUmakefile | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 08f4f63d..8dbed505 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,6 +18,7 @@ CP ?= cp CHMOD ?= chmod MKDIR ?= mkdir EGREP ?= egrep +LN ?= ln -sf UNAME := $(shell uname) IS_X86 := $(shell uname -m | $(EGREP) -i -c "i.86|x86|i86|amd64") @@ -35,6 +36,8 @@ CLANG_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang") INTEL_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -c "\(ICC\)") MACPORTS_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "macports") +HAS_SOLIB_VERSION := $(IS_LINUX) + # Default prefix for make install ifeq ($(PREFIX),) PREFIX = /usr @@ -260,6 +263,12 @@ LIB_VER := $(shell $(EGREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3) LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1) LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2) LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3) +ifeq ($(HAS_SOLIB_VERSION),1) +SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH) +SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR) +# Different patchlevels are compatible, minor versions are not +SOLIB_FLAGS=-Wl,-soname,libcryptopp.so.$(LIB_MAJOR).$(LIB_MINOR) +endif # HAS_SOLIB_VERSION all: cryptest.exe @@ -268,7 +277,7 @@ static: libcryptopp.a shared dynamic dylib: libcryptopp.dylib else static: libcryptopp.a -shared dynamic: libcryptopp.so +shared dynamic: libcryptopp.so$(SOLIB_VERSION_SUFFIX) endif .PHONY: deps @@ -296,7 +305,10 @@ docs html: .PHONY: clean clean: - -$(RM) libcryptopp.a libcryptopp.so libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a + -$(RM) libcryptopp.a libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a +ifeq ($(HAS_SOLIB_VERSION),1) + -$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) +endif -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS) *.stackdump core-* -$(RM) cryptest.exe dlltest.exe cryptest.import.exe ct ifneq ($(wildcard *.exe.dSYM),) @@ -318,6 +330,7 @@ endif .PHONY: install install: + -$(RM) -r $(PREFIX)/include/cryptopp $(MKDIR) -p $(PREFIX)/include/cryptopp $(PREFIX)/lib $(PREFIX)/bin -$(CP) *.h $(PREFIX)/include/cryptopp -$(CHMOD) 755 $(PREFIX)/include/cryptopp @@ -330,8 +343,14 @@ ifneq ($(IS_DARWIN),0) -$(CP) libcryptopp.dylib $(PREFIX)/lib -$(CHMOD) 755 $(PREFIX)/lib/libcryptopp.dylib else - -$(CP) libcryptopp.so $(PREFIX)/lib - -$(CHMOD) 755 $(PREFIX)/lib/libcryptopp.so +ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),) + -$(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(PREFIX)/lib + -$(CHMOD) 755 $(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) +ifeq ($(HAS_SOLIB_VERSION),1) + -$(LN) -sf libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(PREFIX)/lib/libcryptopp.so + ldconfig +endif +endif endif .PHONY: remove uninstall @@ -342,15 +361,23 @@ remove uninstall: ifneq ($(IS_DARWIN),0) -$(RM) $(PREFIX)/lib/libcryptopp.dylib else + -$(RM) $(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) +ifeq ($(HAS_SOLIB_VERSION),1) -$(RM) $(PREFIX)/lib/libcryptopp.so + ldconfig +endif endif libcryptopp.a: public_service | $(LIBOBJS) $(AR) $(ARFLAGS) $@ $(LIBOBJS) $(RANLIB) $@ -libcryptopp.so: public_service | $(LIBOBJS) - $(CXX) -shared -o $@ $(CXXFLAGS) $(GOLD_OPTION) $(LIBOBJS) $(LDLIBS) +libcryptopp.so$(SOLIB_VERSION_SUFFIX): public_service | $(LIBOBJS) + $(CXX) -shared $(SOLIB_FLAGS) -o $@ $(CXXFLAGS) $(GOLD_OPTION) $(LIBOBJS) $(LDLIBS) +ifeq ($(HAS_SOLIB_VERSION),1) + -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so + -$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX) +endif libcryptopp.dylib: $(LIBOBJS) $(CXX) -dynamiclib -o $@ $(CXXFLAGS) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" $(LIBOBJS) @@ -468,4 +495,4 @@ ifneq (x$(UNALIGNED_ACCESS)$(NO_INIT_PRIORITY)$(COMPATIBILITY_562),x000) $(info WARNING: You can 'mv config.recommend config.h', but it breaks versioning.) $(info WARNING: See http://cryptopp.com/wiki/config.h for more details.) $(info ) -endif \ No newline at end of file +endif From 08e88dfbd3424b83ae8522453f9f6c191364eb79 Mon Sep 17 00:00:00 2001 From: Todd Knarr Date: Tue, 24 Nov 2015 20:14:53 -0800 Subject: [PATCH 2/3] Changes per noloader's comments in pull #65 --- GNUmakefile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 527616cc..bb62531f 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -19,6 +19,7 @@ CHMOD ?= chmod MKDIR ?= mkdir EGREP ?= egrep LN ?= ln -sf +LDCONF ?= /sbin/ldconfig -n UNAME := $(shell uname) IS_X86 := $(shell uname -m | $(EGREP) -i -c "i.86|x86|i86|amd64") @@ -272,10 +273,11 @@ LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1) LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2) LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3) ifeq ($(HAS_SOLIB_VERSION),1) +# Full version suffix for shared library SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH) -SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR) # Different patchlevels are compatible, minor versions are not -SOLIB_FLAGS=-Wl,-soname,libcryptopp.so.$(LIB_MAJOR).$(LIB_MINOR) +SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR) +SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX) endif # HAS_SOLIB_VERSION ifeq ($(strip $(LIB_PATCH)),) @@ -373,7 +375,7 @@ ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),) -$(CHMOD) 755 $(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) ifeq ($(HAS_SOLIB_VERSION),1) -$(LN) -sf libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(PREFIX)/lib/libcryptopp.so - ldconfig + $(LDCONF) $(PREFIX)/lib endif endif endif @@ -388,8 +390,9 @@ ifneq ($(IS_DARWIN),0) else -$(RM) $(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) ifeq ($(HAS_SOLIB_VERSION),1) + -$(RM) $(PREFIX)/lib/libcryptopp.so$(SOLIB_COMPAT_SUFFIX) -$(RM) $(PREFIX)/lib/libcryptopp.so - ldconfig + $(LDCONF) $(PREFIX)/lib endif endif @@ -529,3 +532,9 @@ ifneq ($(UNALIGNED_ACCESS)$(NO_INIT_PRIORITY)$(COMPATIBILITY_562),000) $(info WARNING: See http://cryptopp.com/wiki/config.h for more details.) $(info ) endif +ifeq ($(HAS_SOLIB_VERSION),1) + $(info WARNING: Only the symlinks to the shared-object library have been updated.) + $(info WARNING: If the library is installed in a system directory you will need) + $(info WARNING: to run 'ldconfig' to update the shared-object library cache.) + $(info ) +endif From a3ac556e37b43a6d32ed817e2e701c7582a710a5 Mon Sep 17 00:00:00 2001 From: Todd Knarr Date: Fri, 25 Dec 2015 13:06:43 -0800 Subject: [PATCH 3/3] Resolve conflicts between master and version_shlib --- GNUmakefile | 129 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 48 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 9ec29790..dc5c5187 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -12,8 +12,9 @@ CXXFLAGS ?= -DNDEBUG -g2 -O2 # LDFLAGS += -Wl,--gc-sections AR ?= ar -ARFLAGS ?= -cr # ar needs the dash on OpenBSD +ARFLAGS ?= -cr # ar needs the dash on OpenBSD RANLIB ?= ranlib + CP ?= cp CHMOD ?= chmod MKDIR ?= mkdir @@ -42,7 +43,7 @@ HAS_SOLIB_VERSION := $(IS_LINUX) # Default prefix for make install ifeq ($(PREFIX),) -PREFIX = /usr +PREFIX = /usr/local endif ifeq ($(CXX),gcc) # for some reason CXX is gcc on cygwin 1.1.4 @@ -129,6 +130,13 @@ CXXFLAGS += -Wa,--divide # allow use of "/" operator endif endif +else # Not IS_X86 + +# Add PIC +ifeq ($(findstring -fPIC,$(CXXFLAGS)),) + CXXFLAGS += -fPIC +endif + endif # IS_X86 ifeq ($(UNAME),) # for DJGPP, where uname doesn't exist @@ -256,7 +264,8 @@ endif OBJS := $(SRCS:.cpp=.o) # test.o needs to be after bench.o for cygwin 1.1.4 (possible ld bug?) -TESTOBJS := bench.o bench2.o test.o validat1.o validat2.o validat3.o adhoc.o datatest.o regtest.o fipsalgt.o dlltest.o +TESTSRCS := bench.cpp bench2.cpp test.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp +TESTOBJS := $(TESTSRCS:.cpp=.o) LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS)) # List cryptlib.cpp first in an attempt to tame C++ static initialization problems @@ -273,6 +282,11 @@ LIB_VER := $(shell $(EGREP) "define CRYPTOPP_VERSION" config.h | cut -d" " -f 3) LIB_MAJOR := $(shell echo $(LIB_VER) | cut -c 1) LIB_MINOR := $(shell echo $(LIB_VER) | cut -c 2) LIB_PATCH := $(shell echo $(LIB_VER) | cut -c 3) + +ifeq ($(strip $(LIB_PATCH)),) +LIB_PATCH := 0 +endif + ifeq ($(HAS_SOLIB_VERSION),1) # Full version suffix for shared library SOLIB_VERSION_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH) @@ -281,10 +295,6 @@ SOLIB_COMPAT_SUFFIX=.$(LIB_MAJOR).$(LIB_MINOR) SOLIB_FLAGS=-Wl,-soname,libcryptopp.so$(SOLIB_COMPAT_SUFFIX) endif # HAS_SOLIB_VERSION -ifeq ($(strip $(LIB_PATCH)),) -LIB_PATCH := 0 -endif - all: cryptest.exe ifneq ($(IS_DARWIN),0) @@ -306,6 +316,13 @@ asan ubsan align aligned: libcryptopp.a cryptest.exe test check: cryptest.exe ./cryptest.exe v +# Used to generate list of source files for Autotools, CMakeList and Android.mk +.PHONY: sources +sources: + $(info Library sources: $(filter-out fipstest.cpp $(TESTSRCS),$(SRCS))) + $(info ) + $(info Test sources: $(TESTSRCS)) + # Directory we want (can't specify on Doygen command line) DOCUMENT_DIRECTORY := ref$(LIB_VER) # Directory Doxygen uses (specified in Doygen config file) @@ -317,6 +334,7 @@ ifeq ($(strip $(DOXYGEN_DIRECTORY)),) DOXYGEN_DIRECTORY := html-docs endif +# Builds the documentation. Directory name is ref563, ref570, etc. .PHONY: docs html docs html: -$(RM) -r $(DOXYGEN_DIRECTORY)/ $(DOCUMENT_DIRECTORY)/ html-docs/ @@ -358,41 +376,48 @@ endif .PHONY: install install: - -$(RM) -r $(PREFIX)/include/cryptopp - $(MKDIR) -p $(PREFIX)/include/cryptopp $(PREFIX)/lib $(PREFIX)/bin - -$(CP) *.h $(PREFIX)/include/cryptopp - -$(CHMOD) 755 $(PREFIX)/include/cryptopp - -$(CHMOD) 644 $(PREFIX)/include/cryptopp/*.h - -$(CP) libcryptopp.a $(PREFIX)/lib - -$(CHMOD) 644 $(PREFIX)/lib/libcryptopp.a - -$(CP) cryptest.exe $(PREFIX)/bin - -$(CHMOD) 755 $(PREFIX)/bin/cryptest.exe -ifneq ($(IS_DARWIN),0) - -$(CP) libcryptopp.dylib $(PREFIX)/lib - -$(CHMOD) 755 $(PREFIX)/lib/libcryptopp.dylib -else -ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),) - -$(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(PREFIX)/lib - -$(CHMOD) 755 $(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) -ifeq ($(HAS_SOLIB_VERSION),1) - -$(LN) -sf libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(PREFIX)/lib/libcryptopp.so - $(LDCONF) $(PREFIX)/lib + $(MKDIR) -p $(DESTDIR)$(PREFIX)/include/cryptopp + -$(CP) *.h $(DESTDIR)$(PREFIX)/include/cryptopp + -$(CHMOD) 755 $(DESTDIR)$(PREFIX)/include/cryptopp + -$(CHMOD) 644 $(DESTDIR)$(PREFIX)/include/cryptopp/*.h +ifneq ($(wildcard libcryptopp.a),) + $(MKDIR) -p $(DESTDIR)$(PREFIX)/lib + -$(CP) libcryptopp.a $(DESTDIR)$(PREFIX)/lib + -$(CHMOD) 644 $(DESTDIR)$(PREFIX)/lib/libcryptopp.a endif +ifneq ($(wildcard cryptest.exe),) + $(MKDIR) -p $(DESTDIR)$(PREFIX)/bin + -$(CP) cryptest.exe $(DESTDIR)$(PREFIX)/bin + -$(CHMOD) 755 $(DESTDIR)$(PREFIX)/bin/cryptest.exe +endif +ifneq ($(wildcard libcryptopp.dylib),) + $(MKDIR) -p $(DESTDIR)$(PREFIX)/lib + -$(CP) libcryptopp.dylib $(DESTDIR)$(PREFIX)/lib + -install_name_tool -id $(DESTDIR)$(PREFIX)/lib/libcryptopp.dylib $(DESTDIR)$(PREFIX)/lib/libcryptopp.dylib + -$(CHMOD) 755 $(DESTDIR)$(PREFIX)/lib/libcryptopp.dylib +endif +ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),) + $(MKDIR) -p $(DESTDIR)$(PREFIX)/lib + -$(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(PREFIX)/lib + -$(CHMOD) 755 $(DESTDIR)$(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) +ifeq ($(HAS_SOLIB_VERSION),1) + -$(LN) -sf libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(PREFIX)/lib/libcryptopp.so + $(LDCONF) $(DESTDIR)$(PREFIX)/lib endif endif .PHONY: remove uninstall remove uninstall: - -$(RM) -r $(PREFIX)/include/cryptopp - -$(RM) $(PREFIX)/lib/libcryptopp.a - -$(RM) $(PREFIX)/bin/cryptest.exe + -$(RM) -r $(DESTDIR)$(PREFIX)/include/cryptopp + -$(RM) $(DESTDIR)$(PREFIX)/lib/libcryptopp.a + -$(RM) $(DESTDIR)$(PREFIX)/bin/cryptest.exe ifneq ($(IS_DARWIN),0) - -$(RM) $(PREFIX)/lib/libcryptopp.dylib + -$(RM) $(DESTDIR)$(PREFIX)/lib/libcryptopp.dylib else - -$(RM) $(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) + -$(RM) $(DESTDIR)$(PREFIX)/lib/libcryptopp.so$(SOLIB_VERSION_SUFFIX) ifeq ($(HAS_SOLIB_VERSION),1) - -$(RM) $(PREFIX)/lib/libcryptopp.so$(SOLIB_COMPAT_SUFFIX) - -$(RM) $(PREFIX)/lib/libcryptopp.so + -$(RM) $(DESTDIR)$(PREFIX)/lib/libcryptopp.so$(SOLIB_COMPAT_SUFFIX) + -$(RM) $(DESTDIR)$(PREFIX)/lib/libcryptopp.so $(LDCONF) $(PREFIX)/lib endif endif @@ -432,15 +457,9 @@ cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS) dlltest.exe: cryptopp.dll $(DLLTESTOBJS) $(CXX) -o $@ $(CXXFLAGS) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS) -# This recipe requires a previous "svn co -r 541 http://svn.code.sf.net/p/cryptopp/code/trunk/c5" -.PHONY: diff -diff: - -$(RM) cryptopp$(LIB_VER).diff - -svn diff -r 541 > cryptopp$(LIB_VER).diff - # This recipe prepares the distro files TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt config.recommend Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcproj *.dsw *.dsp cryptopp.rc TestVectors/*.txt TestData/*.dat -EXEC_FILES := GNUmakefile GNUmakefile-cross cryptest.sh rdrand-nasm.sh TestData/ TestVectors/ +EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ ifeq ($(wildcard Filelist.txt),Filelist.txt) DIST_FILES := $(shell cat Filelist.txt) @@ -448,20 +467,34 @@ endif .PHONY: convert convert: - chmod 0700 TestVectors/ TestData/ - chmod 0600 $(TEXT_FILES) *.zip - chmod 0700 $(EXEC_FILES) - chmod u+x *.cmd *.sh - unix2dos --keepdate --quiet $(TEXT_FILES) *.asm *.cmd - dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.S *.sh + -chmod 0700 TestVectors/ TestData/ + -chmod 0600 $(TEXT_FILES) *.asm *.S *.zip + -chmod 0700 $(EXEC_FILES) *.sh *.cmd + -chmod 0700 *.cmd *.sh GNUmakefile GNUmakefile-cross + -unix2dos --keepdate --quiet $(TEXT_FILES) *.asm *.cmd + -dos2unix --keepdate --quiet GNUmakefile GNUmakefile-cross *.S *.sh ifneq ($(IS_DARWIN),0) - xattr -c * + -xattr -c * endif .PHONY: zip dist -zip dist: | distclean convert diff +zip dist: | distclean convert zip -q -9 cryptopp$(LIB_VER).zip $(DIST_FILES) +.PHONY: iso +iso: | zip +ifneq ($(IS_DARWIN),0) + mkdir -p $(PWD)/cryptopp$(LIB_VER) + cp cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER) + hdiutil makehybrid -iso -joliet -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER) + -rm -rf $(PWD)/cryptopp$(LIB_VER) +else ifneq ($(IS_LINUX),0) + mkdir -p $(PWD)/cryptopp$(LIB_VER) + cp cryptopp$(LIB_VER).zip $(PWD)/cryptopp$(LIB_VER) + genisoimage -q -o cryptopp$(LIB_VER).iso $(PWD)/cryptopp$(LIB_VER) + -rm -rf $(PWD)/cryptopp$(LIB_VER) +endif + .PHONY: bench benchmark benchmarks bench benchmark benchmarks: cryptest.exe rm -f benchmarks.html