# $Id: Portfile,v 1.4 2005/09/20 23:09:26 toby Exp $
PortSystem		1.0

name	    	gpsbabel
version	    	1.2.7
categories  	textproc comms
maintainers 	thomas+darwinports@stromberg.org
description    	GPSBabel converts/uploads GPS waypoints, tracks, and routes
long_description   	GPSBabel converts GPS waypoints, tracks, and routes \
					from one format to another, whether that format is a \
					common mapping format like Delorme, Streets and \
					Trips, or even a serial upload or download to a GPS \
					unit such as those from Garmin and Magellan. 
homepage		http://gpsbabel.sourceforge.net
platforms		darwin
master_sites	sourceforge
checksums		md5 535da9798714e53a9584e22ac7d651d3

depends_lib		lib:libexpat.0:expat

# Note: Not yet supported on MacOSX, but may work on others
variant usb {
	depends_lib-append	lib:libusb-0.1.4:libusb
	build.args-delete	LIBUSB="" \
	                    INHIBIT_USB="-DNO_USB"
	build.args-append	LIBUSB="-lusb /System/Library/Frameworks/CoreFoundation.framework/Versions/Current/CoreFoundation /System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit" \
	                    INHIBIT_USB="" \
						
}

variant tk {
	depends_run			bin:wish:tk
	patchfiles-append	patch-guibabel
	post-destroot {
		xinstall -m 0755 ${worksrcpath}/guibabel ${destroot}${prefix}/bin
	}
}

use_configure	no
build.args		EXTRA_CFLAGS="-I${prefix}/include" \
				LIBEXPAT="-L${prefix}/lib -lexpat" \
				LIBUSB="" \
				INHIBIT_USB="-DNO_USB"

destroot {
	cd ${worksrcpath}
	xinstall -m 0755 -d ${destroot}${prefix}/bin
	xinstall -m 0755 gpsbabel ${destroot}${prefix}/bin/
	xinstall -m 0755 -d ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 README README.contrib README.magnav \
		README.mapconverter README.psp README.xmapwpt \
		${destroot}${prefix}/share/doc/${name}
	xinstall -m 0755 -d ${destroot}${prefix}/share/doc/${name}/contrib
	xinstall -m 0644 contrib/correctCoordinates.pl contrib/gpx2xfig \
		${destroot}${prefix}/share/doc/${name}/contrib
}

platform darwin {
	post-patch {
		# Patch with version from pre-compiled application for now.
		# Authors have been notified of these changes for future
		# release.
		file copy -force ${filespath}/objects.nib \
			${worksrcpath}/macgpsbabel/English.lproj/MainMenu.nib
		file copy -force ${filespath}/InfoPlist.strings \
			${worksrcpath}/macgpsbabel/English.lproj
		reinplace "s|__VERSION|${version}_${revision} (DarwinPorts)|" \
			${worksrcpath}/macgpsbabel/English.lproj/InfoPlist.strings
	}
	post-configure {
		# test whether or not we can compile AppleScript
		ui_info "Checking for AppleScript support ..."
		cd ${worksrcpath}/macgpsbabel
		if {[catch "exec osacompile -o conftest -e nop" output]} {
			ui_info "$output"
			ui_info "... MacGPSBabel.app will NOT be built."
		} else {
			ui_info "... MacGPSBabel.app can be built."
		}
	}
	post-build {
		if {[file exist ${worksrcpath}/macgpsbabel/conftest]} {
			build.dir		"${worksrcpath}/macgpsbabel"
			build.type		pbx
			build.target	-buildstyle Deployment -target MacGPSBabel
			build.args
			system "[command build]"
		}
	}
	post-destroot {
		if {[file exist ${worksrcpath}/macgpsbabel/conftest]} {
			if {$xcodeversion == "2.1"} {
			    cd ${worksrcpath}/macgpsbabel/build/Deployment
			} else {
			    cd ${worksrcpath}/macgpsbabel/build
			}
			xinstall -d -m 0755 ${destroot}/Applications/DarwinPorts
			system "cp -R MacGPSBabel.app ${destroot}/Applications/DarwinPorts"
		}
	}
}

