# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

EAPI=5
inherit autotools-utils pam

DESCRIPTION="pam_mysql is a module for pam to authenticate users with mysql"
HOMEPAGE="https://github.com/NigelCunningham/pam-MySQL"

SRC_URI="https://github.com/NigelCunningham/pam-MySQL/archive/v${PV}.tar.gz -> ${P}.tar.gz"
DEPEND="
	openssl? ( dev-libs/openssl:0= )
	>=sys-libs/pam-0.72:0=
	virtual/mysql:0=
	"
RDEPEND="${DEPEND}"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~ppc ~sparc ~x86"
IUSE="openssl"
S="${WORKDIR}/pam-MySQL-${PV}"

DOCS=( AUTHORS ChangeLog NEWS README )
AUTOTOOLS_AUTORECONF="yes"
AUTOTOOLS_PRUNE_LIBTOOL_FILES="modules"

# Patch from upstream:
# https://github.com/NigelCunningham/pam-MySQL/commit/6d5d20bfd2dd15662caa31412f6f9ed8c3385284
PATCHES=(
	"${FILESDIR}/${P}-link-to-pam.diff"
)

src_prepare() {
	# Update autotools deprecated macro for bug 468750, see:
	# https://github.com/NigelCunningham/pam-MySQL/pull/25
	sed -i s/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/ configure.ac || die "sed failed"
	autotools-utils_src_prepare
}

src_configure() {
	local myeconfargs=( $(use_with openssl) \
		--with-pam-mods-dir="$(getpam_mod_dir)")
	autotools-utils_src_configure
}