#!/bin/sh
# Copyright 2000 BSDi, Inc. Concord, CA, USA
# Copyright 2001, 2002 Slackware Linux, Inc.  Concord, CA, USA
# All rights reserved.
#
# Modified for Tukaani by Lasse Collin <lasse.collin@tukaani.org>.
#
# 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.

NAME=( openssl  openssl-solibs )
VERSION=( 0.9.8b  0.9.8b )
SOURCE=http://www.openssl.org/source/openssl-$VERSION.tar.gz
SOURCE_MD5=12cedbeb6813a0d7919dbf1f82134b86
SOURCE_SHA1=99565db630a044fa484d4f91006a31908f262246
PATCH=openssl.soname.diff.gz
BUILD=${BUILD:-1}
OPTIMIZE=${OPTIMIZE:-"-O3 -fomit-frame-pointer"}

build() {
	_explode 0
	cd openssl-$VERSION

	# Use .so.0, not .so.0.9.8. This patch is questionable, maybe it
	# needs to be omitted later.
	_patch 0 -p0 --backup --verbose --suffix=.orig

	# Set CFLAGS:
	sed -i "/linux-elf/{s#-m486##;s#-O3 -fomit-frame-pointer#$CFLAGS#}" Configure

	_doc 0 openssl-$VERSION  CHANGES CHANGES.SSLeay FAQ INSTALL \
		NEWS README README.ENGINE doc
	_doc 1 openssl-$VERSION  LICENSE
	find $PKG$DOCDIR/openssl-$VERSION -type d -exec chmod 755 {} \;
	find $PKG$DOCDIR/openssl-$VERSION -type f -exec chmod 644 {} \;

	# 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.
	./config --prefix=$PREFIX --openssldir=$SYSCONFDIR/ssl no-mdc2 no-idea no-rc5 shared
	make -j$NUMOBJS
	
	# MANSUFFIX added because some man pages would otherwise conflict
	# with other man pages e.g. passwd(1), rand(1), thread(3) and
	# err(3). The "ssl" suffix is used on other distros like Debian.
	make install INSTALL_PREFIX=$PKG MANDIR=$MANDIR MANSUFFIX=ssl

	_new 0 ${SYSCONFDIR#/}/ssl/openssl.cnf
	ln -sf $(basename $PKG$LIBDIR/libcrypto.so.0.*) $PKG$LIBDIR/libcrypto.so.0
	ln -sf $(basename $PKG$LIBDIR/libssl.so.0.*) $PKG$LIBDIR/libssl.so.0
	ln -sf libcrypto.so.0 $PKG$LIBDIR/libcrypto.so
	ln -sf libssl.so.0 $PKG$LIBDIR/libssl.so

	# Make the runtime package:
	mkdir -p ${PKG[1]}$LIBDIR
	mv -v $PKG$LIBDIR/lib*.so* $PKG$LIBDIR/engines ${PKG[1]}$LIBDIR
	mv -v $PKG$SYSCONFDIR ${PKG[1]}$SYSCONFDIR
	mv -v $PKG/install/doinst.sh ${PKG[1]}/install

	_chfix
	_chgrp_bin
}
