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

EAPI=5

DESCRIPTION="a C library for inspecting DWARF debugging data"
HOMEPAGE="http://www.prevanders.net/dwarf.html"
SRC_URI="http://www.prevanders.net/libdwarf-${PV}.tar.gz"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

DEPEND=""
RDEPEND="${DEPEND}"

S="${WORKDIR}/${P/lib/}"

src_configure() {
	econf --enable-shared || die "econf failed"
}

src_compile() {
	# TODO: .so building seems to be broken currently (on amd64 atleast)
	# needs --enable-shared to econf, but after that you still get
	# ./tag_tree_build: error while loading shared libraries: libdwarf.so: cannot open shared object file: No such file or directory
	# so it needs to be added temporarily to LD_LIBRARY_PATH, the emake line below doesn't work anymore though
	# fix?
	# Going just with static linking for now
	#cd "${S}/libdwarf"
	#econf --enable-shared || die "econf failed"
	cd "${S}/libdwarf"
	emake || die "emake of libdwarf failed"
	#emake libdwarf.so || die "emake of libdwarf.so failed"

	cd "${S}/dwarfdump"
	#econf || die "econf of dwarfdump failed"
	LD_LIBRARY_PATH="../libdwarf" emake || die "emake of dwarfdump died"
	cd "${S}/dwarfgen"
	emake || die "emake dwarfgen failed"
}

src_install() {
	cd "${S}"
	dolib.a libdwarf/libdwarf.a || die "installing libdwarf.a failed"
	dolib.so libdwarf/libdwarf.so || die "installing libdwarf.so failed"
	insinto /usr/include/libdwarf
	doins libdwarf/dwarf.h libdwarf/libdwarf.h \
		|| die "installing headers failed"

	dobin dwarfdump/dwarfdump
	dobin dwarfgen/dwarfgen

	dodoc libdwarf/README libdwarf/libdwarf2.1.pdf libdwarf/libdwarf2p.1.pdf libdwarf/mips_extensions.pdf dwarfgen/dwarf-generator.txt
}

