# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=5
inherit eutils

DESCRIPTION="Reorganize tables in PostgreSQL databases with minimal locks"
HOMEPAGE="http://reorg.github.io/pg_repack/"
SRC_URI="http://api.pgxn.org/dist/${PN}/${PV}/${P}.zip"
LICENSE=""
SLOT="0"
KEYWORDS="amd64"
DEPEND="dev-db/postgresql-server"
RDEPEND="${DEPEND}"

src_prepare() {
	# Fix https://github.com/reorg/pg_repack/issues/24
	sed -i '/^PG_CONFIG =/d' bin/Makefile
	sed -i '/^PG_CONFIG =/d' regress/Makefile
}

src_install() {
	local versions=$(echo /usr/bin/pg_config?*|sed 's/[^0-9 ]//g')
	for i in $versions; do
		einfo "Building for $i"
		export PG_CONFIG=pg_config${i}
		emake -j1 DESTDIR="${D}" clean all install
	done
	elog "${PN} was installed for postgres versions ${versions}."
	elog "You'll need to reinstall the package if you want to support other versions."
}

src_compile() {
	# Compilation is done during the install phase, so we can compile+install in a loop
	true
}