#!/bin/sh
# Copyright 2000 BSDi, Inc. Concord, CA, USA
# Copyright 2001, 2002 Slackware Linux, Inc.  Concord, CA, USA
# Copyright 2005, 2006, 2007  Patrick J. Volkerding, Sebeka, MN, USA
# Copyright 2006, 2007 Frederick P. Emmott <mail@fredemmott.co.uk>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Set initial variables:
CWD=$(pwd)
TMP=${TMP:-/tmp}


VERSION=${VERSION:-0.9.8g}
ARCH=${ARCH:-x86_64}
BUILD=${BUILD:-1}


PKG=$TMP/package-devel32

# So that ls has the right field counts for parsing...
export LC_ALL=C

cd $TMP
rm -rf openssl-$VERSION
tar xjvf $CWD/openssl-$VERSION.tar.bz2
cd openssl-$VERSION
# Use .so.0, not .so.0.9.8:
zcat $CWD/openssl.soname.diff.gz | patch -p1 --backup --verbose --suffix=.orig || exit 1
  # Build with -march=i486 -mtune=i686:
  zcat $CWD/openssl.optsx86.diff.gz | patch -p1 --backup --verbose --suffix=.orig || exit 1
chown -R root:root .

# These are the known patent issues with OpenSSL:
# name   #         expires
# MDC-2: 4,908,861 13/03/2007, not included.
# IDEA:  5,214,703 25/05/2010, not included.
# RC5:   5,724,428 03/03/2015, not included.

linux32 \
./config \
 --prefix=/usr \
 --openssldir=/etc/ssl \
 no-idea \
 no-rc5 \
 no-sse2 \
 shared

make depend || exit 1

# Use -j1 here if you know what's good for you.
make || exit 1

make install INSTALL_PREFIX=$PKG || exit 1

rm $PKG/usr/bin/openssl*
mkdir -p $PKG/usr/bin/32
mv $PKG/usr/bin/* $PKG/usr/bin/32
rm -rf $PKG/etc/ssl
strip --strip-unneeded $PKG/usr/lib/lib*.so.*.*.* $PKG/usr/bin/32/*

( cd $PKG1/usr/lib ; ldconfig -l * 2> /dev/null )
( cd $PKG1/usr/lib ; ln -sf libcrypto.so.0 libcrypto.so )
( cd $PKG1/usr/lib ; ln -sf libssl.so.0 libssl.so )

cd $PKG
