# $Id: Portfile 67586 2010-05-13 13:31:29Z jmr@macports.org $

PortSystem 1.0

name			tuntaposx
version			20090913
revision		1
categories		net
maintainers		nomaintainer
description		Tun and tap virtual devices.
long_description	Unix-style tun and tap virtual network interfaces for Mac OS X. \
	You typically use these for VPN and OS virtualization.
homepage                http://tuntaposx.sourceforge.net/
platforms		darwin
master_sites		sourceforge
distname                tuntap_${version}_src
worksrcdir              tuntap
checksums		sha1 1a9fb5e077c6d21b7715c8cb26f2ebdcbd681202
destroot.violate_mtree  yes
destroot.args           BASE=${destroot}${prefix}

patchfiles		patch-src__tap__Makefile patch-src__tun__Makefile

configure {
	reinplace "s|CCP = g++|CCP = ${configure.cxx}|" ${worksrcpath}/src/tun/Makefile \
	                                                ${worksrcpath}/src/tap/Makefile
	reinplace "s|CC = gcc|CC = ${configure.cc}|" ${worksrcpath}/src/tun/Makefile \
	                                             ${worksrcpath}/src/tap/Makefile
	if {[variant_isset universal]} {
		reinplace "s|__CFLAGS__|${configure.universal_cflags}|" ${worksrcpath}/src/tun/Makefile \
		                                              ${worksrcpath}/src/tap/Makefile
	} else {
		reinplace "s|__CFLAGS__|${configure.cflags}|" ${worksrcpath}/src/tun/Makefile \
		                                              ${worksrcpath}/src/tap/Makefile
	}
}

startupitem.create      yes
startupitem.pidfile     none
set kext_dir            ${prefix}/Library/Extensions
startupitem.start       "kextload ${kext_dir}/tap.kext ; kextload  ${kext_dir}/tun.kext"
startupitem.stop        "kextunload ${kext_dir}/tap.kext ; kextunload  ${kext_dir}/tun.kext"

post-destroot {
	set docs ${destroot}${prefix}/share/doc/${name}-${version}
	xinstall -m 755 -d ${docs}
	xinstall -m 644 -W ${worksrcpath} README Changelog ${docs}
}

post-activate {
	set tap_loaded [expr [string length [exec kextstat -lb foo.tap]] > 0]
	set tun_loaded [expr [string length [exec kextstat -lb foo.tun]] > 0]

	if {${tap_loaded} || ${tun_loaded}} {
		ui_msg "**********************************************************************"
		ui_msg "* Warning: tuntaposx virtual device kernel extension loaded already. *"
		ui_msg "* Maybe you have installed the tuntaposx package already without     *"
		ui_msg "* using MacPorts, e.g. by installing Tunnelblick openvpn GUI. See    *"
		ui_msg "* kextstat(8), kextload(8) and kextunload(8) for manual handling.    *"
		ui_msg "**********************************************************************"
	}
}

if {${os.major} <= 9} {
    patchfiles-append patch-leopard.diff
}

platform darwin 10 {
    # Kernel can be 32-bit or 64-bit, so build both
    default_variants +universal
    configure.universal_archs i386 x86_64
}
