#!/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=rhash
PKGVERSION=1.3.8
PKGREVISION=1
PKGLICENSE="CUSTOM"
PKGSUMMARY="utility for computing hash sums"
PKGDOWNLOAD="https://github.com/rhash/RHash/archive/v$PKGVERSION.tar.gz"
PKGOPTIONS="NLS SSL"
PKGPROTECT="etc/rhashrc"

: ${CTARGET:=$(uname -m)-linux-musl}
: ${CC:=clang}
: ${CFLAGS:=-O2}
: ${LDFLAGS:=}
: ${NLS:=yes}
: ${SSL:=yes}

if [ "$NLS" = "yes" ]; then
	PKGDEPENDS="core/gettext:build $PKGDEPENDS"
	with_nls="--enable-gettext"
else
	with_nls="--disable-gettext"
fi

if [ "$SSL" = "yes" ]; then
	PKGDEPENDS="network/openssl $PKGDEPENDS"
	with_ssl="--enable-openssl"
else
	with_ssl="--disable-openssl"
fi

build()
{
	rm -rf RHash-$PKGVERSION
	tar xvf v$PKGVERSION.tar.gz
	cd RHash-$PKGVERSION

	CC="$CC" \
	CFLAGS="$CFLAGS" \
	LDFLAGS="$LDFLAGS" \
	LIBS="$LIBS" \
	./configure \
		--target=$CTARGET \
		--prefix= \
		--disable-static \
		--extra-cflags="$CFLAGS" \
		--extra-ldflags="$LDFLAGS" \
		$with_nls \
		$with_ssl
	make
	make install DESTDIR=$DESTDIR
	make -C librhash DESTDIR=$DESTDIR \
		install-lib-headers \
		install-lib-shared \
		install-so-link

	cd ..
	rm -rf RHash-$PKGVERSION
}
