dev-libs/pkcs11-helper: Upgrade package to v1.21

This is required by the latest openvpn ebuilds.

BUG=chromium:716913
TEST=manually emerge + deploy to samus; connect to a cert based VPN

Change-Id: I437bfd4c5859efd60b334c2d690a356380f64042
Reviewed-on: https://chromium-review.googlesource.com/491070
Commit-Ready: Kevin Cernekee <cernekee@chromium.org>
Tested-by: Kevin Cernekee <cernekee@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/dev-libs/pkcs11-helper/Manifest b/dev-libs/pkcs11-helper/Manifest
index 4674635..25f7e2f 100644
--- a/dev-libs/pkcs11-helper/Manifest
+++ b/dev-libs/pkcs11-helper/Manifest
@@ -1 +1 @@
-DIST pkcs11-helper-1.07.tar.bz2 339147 RMD160 e2f5d1af5d09c927af96557cae89678de71659cd SHA1 45dea4081f3d2bc9aa68211b63ead3a2b6c978c9 SHA256 7849ddd06a4f3996358264ca6f92fbb4980d40aefaf6cda67a05f524476c345f
+DIST pkcs11-helper-1.21.tar.bz2 417527 SHA256 7bc455915590fec1a85593171f08a73ef343b1e7a73e60378d8744d54523e17c SHA512 064b04c1ece2db0757e14263955c0f7488edde5f5f4415ebda9c4370e608d7df681706ddefcdba2392e5642d00ebd4c211f15266bb39baf8da46ffaec4f3e572 WHIRLPOOL b6825820218f7335030e28ea9b49127d6ec7eddcdc435a0d01785e359b1ba621c51ed1e8f248e48d7cb55b3a756ee04d8fc9071db4d55f19faf0848b5a349328
diff --git a/dev-libs/pkcs11-helper/metadata.xml b/dev-libs/pkcs11-helper/metadata.xml
index 57a9ee6..668ec94 100644
--- a/dev-libs/pkcs11-helper/metadata.xml
+++ b/dev-libs/pkcs11-helper/metadata.xml
@@ -1,8 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
 <pkgmetadata>
-<herd>crypto</herd>
-<use>
-  <flag name='nss'>Enable NSS crypto engine</flag>
-</use>
+	<maintainer type="project">
+		<email>crypto@gentoo.org</email>
+		<name>Crypto</name>
+	</maintainer>
+	<use>
+		<flag name="nss">Enable NSS crypto engine</flag>
+	</use>
+	<upstream>
+		<remote-id type="sourceforge">opensc</remote-id>
+	</upstream>
 </pkgmetadata>
diff --git a/dev-libs/pkcs11-helper/pkcs11-helper-1.07.ebuild b/dev-libs/pkcs11-helper/pkcs11-helper-1.07.ebuild
deleted file mode 100644
index aa10c5e..0000000
--- a/dev-libs/pkcs11-helper/pkcs11-helper-1.07.ebuild
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright 1999-2009 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/dev-libs/pkcs11-helper/pkcs11-helper-1.07.ebuild,v 1.7 2009/06/09 02:23:38 jer Exp $
-
-DESCRIPTION="PKCS#11 helper library"
-HOMEPAGE="http://www.opensc-project.org/pkcs11-helper"
-SRC_URI="http://www.opensc-project.org/files/${PN}/${P}.tar.bz2"
-
-LICENSE="|| ( BSD GPL-2 )"
-SLOT="0"
-KEYWORDS="*"
-IUSE="doc gnutls nss"
-RESTRICT="test"
-
-RDEPEND=">=dev-libs/openssl-0.9.7
-	gnutls? ( >=net-libs/gnutls-1.4.4 )
-	nss? ( dev-libs/nss )"
-DEPEND="${RDEPEND}
-	dev-util/pkgconfig
-	doc? ( >=app-doc/doxygen-1.4.7 )"
-
-src_compile() {
-	econf \
-		--docdir="/usr/share/doc/${PF}" \
-		$(use_enable doc) \
-		$(use_enable gnutls crypto-engine-gnutls) \
-		$(use_enable nss crypto-engine-nss)
-	emake || die "emake failed"
-}
-
-src_install() {
-	emake DESTDIR="${D}" install || die "emake install failed"
-	mv "${D}/usr/share/doc/${PF}/api" "${T}"
-	prepalldocs
-	mv "${T}/api" "${D}/usr/share/doc/${PF}"
-}
diff --git a/dev-libs/pkcs11-helper/pkcs11-helper-1.21.ebuild b/dev-libs/pkcs11-helper/pkcs11-helper-1.21.ebuild
new file mode 100644
index 0000000..2d0c10c
--- /dev/null
+++ b/dev-libs/pkcs11-helper/pkcs11-helper-1.21.ebuild
@@ -0,0 +1,37 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="5"
+
+inherit ltprune
+
+DESCRIPTION="PKCS#11 helper library"
+HOMEPAGE="https://github.com/OpenSC/pkcs11-helper"
+SRC_URI="https://github.com/OpenSC/${PN}/releases/download/${P}/${P}.tar.bz2"
+
+LICENSE="|| ( BSD GPL-2 )"
+SLOT="0"
+KEYWORDS="*"
+IUSE="doc gnutls libressl nss static-libs"
+
+RDEPEND="
+	!libressl? ( >=dev-libs/openssl-0.9.7:= )
+	libressl? ( dev-libs/libressl )
+	gnutls? ( >=net-libs/gnutls-1.4.4 )
+	nss? ( dev-libs/nss )"
+DEPEND="${RDEPEND}
+	virtual/pkgconfig
+	doc? ( >=app-doc/doxygen-1.4.7 )"
+
+src_configure() {
+	econf \
+		$(use_enable doc) \
+		$(use_enable gnutls crypto-engine-gnutls) \
+		$(use_enable nss crypto-engine-nss) \
+		$(use_enable static-libs static)
+}
+
+src_install() {
+	default
+	prune_libtool_files
+}
diff --git a/eclass/ltprune.eclass b/eclass/ltprune.eclass
new file mode 100644
index 0000000..6b3e939
--- /dev/null
+++ b/eclass/ltprune.eclass
@@ -0,0 +1,167 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: ltprune.eclass
+# @MAINTAINER:
+# MichaƂ Górny <mgorny@gentoo.org>
+# @BLURB: Smart .la file pruning
+# @DESCRIPTION:
+# A function to locate and remove unnecessary .la files.
+#
+# Discouraged. Whenever possible, please use much simpler:
+# @CODE
+# find "${D}" -name '*.la' -delete || die
+# @CODE
+
+if [[ -z ${_LTPRUNE_ECLASS} ]]; then
+
+inherit toolchain-funcs
+
+# @FUNCTION: prune_libtool_files
+# @USAGE: [--all|--modules]
+# @DESCRIPTION:
+# Locate unnecessary libtool files (.la) and libtool static archives
+# (.a) and remove them from installation image.
+#
+# By default, .la files are removed whenever the static linkage can
+# either be performed using pkg-config or doesn't introduce additional
+# flags.
+#
+# If '--modules' argument is passed, .la files for modules (plugins) are
+# removed as well. This is usually useful when the package installs
+# plugins and the plugin loader does not use .la files.
+#
+# If '--all' argument is passed, all .la files are removed without
+# performing any heuristic on them. You shouldn't ever use that,
+# and instead report a bug in the algorithm instead.
+#
+# The .a files are only removed whenever corresponding .la files state
+# that they should not be linked to, i.e. whenever these files
+# correspond to plugins.
+#
+# Note: if your package installs both static libraries and .pc files
+# which use variable substitution for -l flags, you need to add
+# pkg-config to your DEPEND.
+prune_libtool_files() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	local removing_all removing_modules opt
+	for opt; do
+		case "${opt}" in
+			--all)
+				removing_all=1
+				removing_modules=1
+				;;
+			--modules)
+				removing_modules=1
+				;;
+			*)
+				die "Invalid argument to ${FUNCNAME}(): ${opt}"
+		esac
+	done
+
+	local f
+	local queue=()
+	while IFS= read -r -d '' f; do # for all .la files
+		local archivefile=${f/%.la/.a}
+
+		# The following check is done by libtool itself.
+		# It helps us avoid removing random files which match '*.la',
+		# see bug #468380.
+		if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
+			continue
+		fi
+
+		[[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
+		local reason= pkgconfig_scanned=
+		local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
+
+		if [[ ${snotlink} == yes ]]; then
+
+			# Remove static libs we're not supposed to link against.
+			if [[ -f ${archivefile} ]]; then
+				einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
+				queue+=( "${archivefile}" )
+			fi
+
+			# The .la file may be used by a module loader, so avoid removing it
+			# unless explicitly requested.
+			if [[ ${removing_modules} ]]; then
+				reason='module'
+			fi
+
+		else
+
+			# Remove .la files when:
+			# - user explicitly wants us to remove all .la files,
+			# - respective static archive doesn't exist,
+			# - they are covered by a .pc file already,
+			# - they don't provide any new information (no libs & no flags).
+
+			if [[ ${removing_all} ]]; then
+				reason='requested'
+			elif [[ ! -f ${archivefile} ]]; then
+				reason='no static archive'
+			elif [[ ! $(sed -nre \
+					"s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
+					"${f}") ]]; then
+				reason='no libs & flags'
+			else
+				if [[ ! ${pkgconfig_scanned} ]]; then
+					# Create a list of all .pc-covered libs.
+					local pc_libs=()
+					if [[ ! ${removing_all} ]]; then
+						local pc
+						local tf=${T}/prune-lt-files.pc
+						local pkgconf=$(tc-getPKG_CONFIG)
+
+						while IFS= read -r -d '' pc; do # for all .pc files
+							local arg libs
+
+							# Use pkg-config if available (and works),
+							# fallback to sed.
+							if ${pkgconf} --exists "${pc}" &>/dev/null; then
+								sed -e '/^Requires:/d' "${pc}" > "${tf}"
+								libs=$(${pkgconf} --libs "${tf}")
+							else
+								libs=$(sed -ne 's/^Libs://p' "${pc}")
+							fi
+
+							for arg in ${libs}; do
+								if [[ ${arg} == -l* ]]; then
+									if [[ ${arg} == '*$*' ]]; then
+										eerror "${FUNCNAME}: variable substitution likely failed in ${pc}"
+										eerror "(arg: ${arg})"
+										eerror "Most likely, you need to add virtual/pkgconfig to DEPEND."
+										die "${FUNCNAME}: unsubstituted variable found in .pc"
+									fi
+
+									pc_libs+=( lib${arg#-l}.la )
+								fi
+							done
+						done < <(find "${D}" -type f -name '*.pc' -print0)
+
+						rm -f "${tf}"
+					fi
+
+					pkgconfig_scanned=1
+				fi # pkgconfig_scanned
+
+				has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
+			fi # removal due to .pc
+
+		fi # shouldnotlink==no
+
+		if [[ ${reason} ]]; then
+			einfo "Removing unnecessary ${f#${D%/}} (${reason})"
+			queue+=( "${f}" )
+		fi
+	done < <(find "${D}" -xtype f -name '*.la' -print0)
+
+	if [[ ${queue[@]} ]]; then
+		rm -f "${queue[@]}"
+	fi
+}
+
+_LTPRUNE_ECLASS=1
+fi #_LTPRUNE_ECLASS