--- /dev/null
+--- polyml-5.6-1-orig/sha1/build 2015-09-09 03:05:54.000000000 +1000
++++ polyml-5.6-1/sha1/build 2016-12-28 19:10:36.148579115 +1100
+@@ -32,34 +32,34 @@
+
+ case "$target" in
+ x86-linux)
+- CFLAGS="-fPIC -I. -m32"
+- LDFLAGS="-fPIC -m32 -shared"
++ CFLAGS="-O2 -march=native -ggdb -fvar-tracking-assignments -fvar-tracking -pipe -fPIC -I. -m32"
++ LDFLAGS="-Wl,-O1 -Wl,--as-needed -fPIC -m32 -shared"
+ library="$target/libsha1.so"
+ test_sha1="test_sha1"
+ ;;
+ x86_64-linux)
+- CFLAGS="-fPIC -I. -m64"
+- LDFLAGS="-fPIC -m64 -shared"
++ CFLAGS="-O2 -march=native -ggdb -fvar-tracking-assignments -fvar-tracking -pipe -fPIC -I. -m64"
++ LDFLAGS="-Wl,-O1 -Wl,--as-needed -fPIC -m64 -shared"
+ library="$target/libsha1.so"
+ test_sha1="test_sha1"
+ ;;
+ x86-darwin)
+ LD=libtool
+- CFLAGS="-fPIC -I. -m32"
+- LDFLAGS="-dynamic -lc"
++ CFLAGS="-O2 -march=native -ggdb -fvar-tracking-assignments -fvar-tracking -pipe -fPIC -I. -m32"
++ LDFLAGS="-Wl,-O1 -Wl,--as-needed -dynamic -lc"
+ library="$target/libsha1.so"
+ test_sha1="test_sha1"
+ ;;
+ x86_64-darwin)
+ LD=libtool
+- CFLAGS="-fPIC -I. -m64"
+- LDFLAGS="-dynamic -lc"
++ CFLAGS="-O2 -march=native -ggdb -fvar-tracking-assignments -fvar-tracking -pipe -fPIC -I. -m64"
++ LDFLAGS="-Wl,-O1 -Wl,--as-needed -dynamic -lc"
+ library="$target/libsha1.so"
+ test_sha1="test_sha1"
+ ;;
+ x86-cygwin)
+- CFLAGS="-I. -m32"
+- LDFLAGS="-shared"
++ CFLAGS="-O2 -march=native -ggdb -fvar-tracking-assignments -fvar-tracking -pipe -I. -m32"
++ LDFLAGS="-Wl,-O1 -Wl,--as-needed -shared"
+ library="$target/sha1.dll"
+ test_sha1="test_sha1.exe"
+ ;;
+@@ -105,10 +105,6 @@
+ $CC $CFLAGS -o $test_sha1 test_sha1.c -ldl
+ [ "$?" -ne 0 ] && { exit 1; }
+
+-echo "Running tests ..."
+-./$test_sha1 $library
+-[ "$?" -ne 0 ] && { exit 1; }
+-
+-rm test_sha1 sha1.o
++exit 0
+
+ fi
+\ No newline at end of file
--- /dev/null
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI="6"
+
+inherit multilib toolchain-funcs
+
+MY_PN="polyml"
+MY_PV="5.6-1"
+MY_P="${MY_PN}-${MY_PV}"
+
+DESCRIPTION="implementation of SHA1 is taken from the GNU coreutils package"
+HOMEPAGE="http://isabelle.in.tum.de/"
+SRC_URI="http://isabelle.in.tum.de/components/${MY_P}.tar.gz"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="~x86 ~amd64"
+IUSE=""
+
+RDEPEND=""
+DEPEND="${RDEPEND}"
+
+S="${WORKDIR}/${MY_P}/sha1"
+
+# sci-mathematics/isabelle requires sci-mathematics/sha1-polyml, to avoid
+# this warning:
+# ### load_lib </usr/bin/libsha1.so> : /usr/bin/libsha1.so: cannot open shared
+# object file: No such file or directory
+# ### Using slow ML implementation of SHA1.digest
+# sci-mathematics/sha1-polyml supplies the library libsha1.so. Which
+# is the implementation of SHA1 taken from the GNU coreutils package
+# as described in the sci-mathematics/sha1-polyml README. Isabelle
+# builds libsha1.so in the contrib/polyml/$ML_PLATFORM directory.
+# isabelle dynamically loads libsha1.so as a plugin. The Isabelle-2012
+# linux binary bundle places libsha1.so in the contrib/polyml directory, which
+# is referred to as ML_HOME in the Isabelle Pure/General/sha1_polyml.ML source file.
+# ML_HOME is /usr/bin on Gentoo, and we want isabelle to depend o sha1-polyml.
+# For these reasons isabelle is patched to load it from
+# /usr/$(get_libdir)/sha1-polyml/libsha1.so
+
+src_compile() {
+ $(tc-getCC) \
+ ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -I. -fPIC -shared \
+ -o libsha1.so sha1.c || die "compile libsha1.so failed"
+ $(tc-getCC) \
+ ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -I. \
+ -o test_sha1 test_sha1.c -ldl || die "compile test_sha1 failed"
+}
+
+src_test() {
+ ./test_sha1 ./libsha1.so || die "tests failed"
+}
+
+src_install() {
+ dodoc README
+ local ld="${ROOT}usr/"$(get_libdir)"/${PN}"
+ dodir ${ld}
+ exeinto ${ld}
+ doexe libsha1.so
+}