#!/bin/sh
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

PKGNAME=openssl
PKGVERSION=1.1.1a
PKGREVISION=1
PKGLICENSE="CUSTOM"
PKGSUMMARY="toolkit for SSL/TLS"
PKGDOWNLOAD="https://www.openssl.org/source/$PKGNAME-$PKGVERSION.tar.gz"

: ${CC:=clang}
: ${CFLAGS:=-O2}

case $(uname -m) in
x86_64)
	TRIPLET="linux-x86_64"
	;;
arm*)
	TRIPLET="linux-armv4"
	;;
aarch*)
	TRIPLET="linux-aarch64"
	;;
esac

build()
{
	rm -rf $PKGNAME-$PKGVERSION
	tar xvaf $PKGNAME-$PKGVERSION.tar.gz
	pushd $PKGNAME-$PKGVERSION

	patch -p0 < ../ca-directory.patch
	./Configure \
		--prefix= \
		--openssldir=/etc/ssl \
		--libdir=lib \
		shared linux-x86_64
		CC="$CC" CFLAGS="$CFLAGS"
	make depend
	make
	make install DESTDIR=$DESTDIR
	rm -f $DESTDIR/lib/lib{crypto,ssl}.a

	popd
	rm -rf $PKGNAME-$PKGVERSION
}
