From 0973910fbbfae2e173fcbe524069058844fc171f Mon Sep 17 00:00:00 2001
From: =?utf8?q?Ulf=20M=C3=B6ller?= <ulf@openssl.org>
Date: Wed, 28 Apr 1999 16:16:31 +0000
Subject: [PATCH] Linux shared libraries.

---
 CHANGES      |  3 +++
 Configure    | 24 ++++++++++++++++++++++--
 Makefile.org | 23 ++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES
index dacdb63c4d..90992da73e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@
 
  Changes between 0.9.2b and 0.9.3
 
+  *) "make linux-shared" to build shared libraries.
+      [Niels Poppe <niels@netbox.org>]
+
   *) New Configure option no-<cipher> (rsa, idea, rc5, ...).
      [Ulf Möller]
 
diff --git a/Configure b/Configure
index 349bc7f7f7..3c720c3a87 100755
--- a/Configure
+++ b/Configure
@@ -229,8 +229,8 @@ my %table=(
 "CygWin32", "gcc:-DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall::BN_LLONG $x86_gcc_des $x86_gcc_opts:",
 
 # Ultrix from Bernhard Simon <simon@zid.tuwien.ac.at>
-"ultrix","cc:-std1 -O -Olimit 1000 -DL_ENDIAN::::::",
-"ultrix-gcc","cc:-O3 -DL_ENDIAN::::::",
+"ultrix-cc","cc:-std1 -O -Olimit 1000 -DL_ENDIAN::::::",
+"ultrix-gcc","gcc:-O3 -DL_ENDIAN::::::",
 # K&R C is no longer supported; you need gcc on old Ultrix installations
 ##"ultrix","cc:-O2 -DNOPROTO -DNOCONST -DL_ENDIAN::::::",
 
@@ -391,6 +391,23 @@ if ($rmd160_obj =~ /\.o$/)
 	$cflags.=" -DRMD160_ASM";
 	}
 
+my $version = "unknown";
+my $major = "unknown";
+my $minor = "unknown";
+
+open(IN,'<crypto/opensslv.h') || die "unable to read opensslv.h:$!\n";
+while (<IN>)
+	{
+	$version=$1 if /OPENSSL.VERSION.TEXT.*OpenSSL (\S+) /;
+	}
+close(IN);
+
+if ($version =~ /(^[0-9]*)\.([\0-9\.]*)/)
+	{
+	$major=$1;
+	$minor=$2;
+	}
+
 open(IN,'<Makefile.org') || die "unable to read Makefile.org:$!\n";
 open(OUT,">$Makefile") || die "unable to create $Makefile:$!\n";
 my $sdirs=0;
@@ -405,6 +422,9 @@ while (<IN>)
 			s/$dir//;
 			}
 		}
+	s/^VERSION=.*/VERSION=$version/;
+	s/^MAJOR=.*/MAJOR=$major/;
+	s/^MINOR=.*/MINOR=$minor/;
 	s/^INSTALLTOP=.*$/INSTALLTOP=$installprefix/;
 	s/^OPENSSLDIR=.*$/OPENSSLDIR=$openssldir/;
 	s/^PLATFORM=.*$/PLATFORM=$target/;
diff --git a/Makefile.org b/Makefile.org
index 09648b2c20..97bf3cf3fe 100644
--- a/Makefile.org
+++ b/Makefile.org
@@ -2,7 +2,9 @@
 ## Makefile for OpenSSL
 ##
 
-VERSION = 0.9.2b
+VERSION=
+MAJOR=
+MINOR=
 PLATFORM=dist
 INSTALLTOP=/usr/local/ssl
 
@@ -136,6 +138,8 @@ RMD160_ASM_OBJ= asm/rm86-out.o
 #RMD160_ASM_OBJ= asm/rm86bsdi.o       # bsdi
 
 DIRS=   crypto ssl rsaref apps test tools
+SHLIBDIRS= crypto ssl
+
 # dirs in crypto to build
 SDIRS=  \
 	md2 md5 sha mdc2 hmac ripemd \
@@ -179,6 +183,23 @@ sub_all:
 	$(MAKE) CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='${CFLAG}' SDIRS='$(SDIRS)' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' all ) || exit 1; \
 	done;
 
+linux-shared:
+	for i in ${SHLIBDIRS}; do \
+	rm -f lib$$i.a lib$$i.so \
+		lib$$i.so.${MAJOR} lib$$i.so.${MAJOR}.${MINOR}; \
+	${MAKE} CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='-fPIC ${CFLAG}' SDIRS='${SDIRS}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' AR='${AR}' DIRS=$$i clean all || exit 1; \
+	( set -x; ${CC}  -shared -o lib$$i.so.${MAJOR}.${MINOR} \
+		-Wl,-S,-soname=lib$$i.so.${MAJOR} \
+		-Wl,--whole-archive lib$$i.a \
+		-Wl,--no-whole-archive -lc ) || exit 1; \
+	rm -f lib$$i.a; make -C $$i clean || exit 1 ;\
+	done;
+	@set -x; \
+	for i in ${SHLIBDIRS}; do \
+	ln -s lib$$i.so.${MAJOR}.${MINOR} lib$$i.so.${MAJOR}; \
+	ln -s lib$$i.so.${MAJOR} lib$$i.so; \
+	done;
+
 Makefile.ssl: Makefile.org
 	@echo "Makefile.ssl is older than Makefile.org."
 	@echo "Reconfigure the source tree (via 'perl Configure' or 'sh config')"
-- 
2.25.1