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

inherit eutils

DESCRIPTION="GPSBabel reads and writes GPS waypoints in a variety of forms. \
Backends include GPX, Magellan and Garmin serial protocols, Geocaching.com \
*.loc, GPSMan, Garmin Mapsource *.mps, Magellan Mapsend *.wpt, and many others."

HOMEPAGE="http://www.gpsbabel.org/"

SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="GPL-2"

SLOT="0"

KEYWORDS="~x86"

IUSE="usb doc"

DEPEND="dev-libs/expat 
		usb? (dev-libs/libusb)
		doc? (app-text/tetex)"

S=${WORKDIR}/${P}

src_compile() {
	if use usb; then
		einfo "Usb support will be enabled"
	else
		cd ${S}
		sed -i "s/USB=#/USB=/" Makefile
		sed -i "s/LIBUSB=/LIBUSB=#/" Makefile
	fi
	emake || die "emake failed"
}

src_install() {
	cd ${S}
	dobin gpsbabel
	if use doc ; then
		cd ${S}/doc/
		make
		dodoc doc.dvi
	fi
	dodoc README* COPYING ChangeLog
	local MY_DOCS
	MY_DOCS="contrib reference reference/route reference/track"
	for i in ${MY_DOCS}; do
		insinto /usr/share/doc/${PF}/${i}
		doins ${i}/* || die "${i} doc creation failed"
	done
}