# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: $

IUSE="gtk gtk2 qt"

SRC_URI="http://roadmap.digitalomaha.net/roadmap/${PN}_${PV//./_}_src.tar.gz
	http://roadmap.digitalomaha.net/maps/usdir.rdm.tgz"

DESCRIPTION="RoadMap provides street mapping functionality using a GPS reciever and data provided by the US Census Bureau"
HOMEPAGE="http://roadmap.digitalomaha.net/"
LICENSE="GPL-2"

SLOT="0"
KEYWORDS="~x86"

DEPEND="gtk2? ( >=x11-libs/gtk+-2 ) : ( =x11-libs/gtk+-1.2* )
	>=media-gfx/imagemagick-5.5.6-r1"

RDEPEND="${DEPEND}
	>=app-misc/gpsdrive-2.04"

S=${WORKDIR}/${PN}/src

src_unpack() {
	unpack ${A}
	cd ${S}

	sed -i qt/Makefile \
		-e "s:/usr/local:${D}/usr:g" \
		-e '/ln -s $(INSTALLDIR)\/bin\//d' \
		|| die "error patching \"qt/Makefile\""
	sed -i gtk/Makefile \
		-e "s:/usr/local:${D}/usr:g" \
		-e '/ln -s $(INSTALLDIR)\/bin\//d' \
		|| die "error patching \"gtk/Makefile\""
	sed -i gtk2/Makefile \
		-e "s:/usr/local:${D}/usr:g" \
		-e '/ln -s $(INSTALLDIR)\/bin\//d' \
		|| die "error patching \"gtk2/Makefile\""
	sed -i Makefile \
		-e 's:\(cd $(INSTALLDIR)/bin ; rm -f $(BUILD) $(SCRIPTS)\):mkdir -p $(INSTALLDIR)/bin ; \1:' \
		-e 's:\(cp -f roadmap.desktop $(INSTALLDIR)/applications\):mkdir -p $(INSTALLDIR)/applications ; \1:' \
		-e "s:/usr/local:${D}/usr:g" \
		-e 's:/applications:/share/applications/:g' \
		|| die "error patching \"Makefile\""
}

src_compile() {
	cd ${S}
	make build || die "make build failed"

	cd ${S}/gtk2
	use qt && cd ${S}/qt
	use gtk && cd ${S}/gtk
	use gtk2 && cd ${S}/gtk2
	make || die "make failed"
}

src_install() {
	dodir /usr/share/${PN}
	insinto /usr/share/${PN}
	doins ${WORKDIR}/usdir.rdm

	cd ${S}/gtk2
	use qt && cd ${S}/qt
	use gtk && cd ${S}/gtk
	use gtk2 && cd ${S}/gtk2
	make install || die "make install failed"

	dodir /usr/bin
	insinto /usr/bin
	MY_INTERFACE="gtk"
	use qt && MY_INTERFACE="qt"
	use gtk && MY_INTERFACE="gtk"
	use gtk2 && MY_INTERFACE="gtk"
	dosym /usr/bin/${MY_INTERFACE}roadmap /usr/bin/roadmap
	dosym /usr/bin/${MY_INTERFACE}roadgps /usr/bin/roadgps
}

pkg_postinst() {
	einfo
	einfo "If this is a new install, you will need to visit the homepage for"
	einfo "RoadMap and read the documentation on generating maps from US Census"
	einfo "Bureau data, ${HOMEPAGE}"
	einfo
}