# $Id$
PortSystem 1.0

name                vnstat
version             1.11
revision            2
categories          net
platforms           darwin
maintainers         nomaintainer
license             GPL-2
description         console-based network traffic monitor
long_description    \
	vnStat is a console-based network traffic monitor for Linux and BSD that keeps \
	a log of network traffic for the selected interface(s), it uses the network \
	interface statistics provided by the kernel as information source.  This means \
	that vnStat won't actually be sniffing any traffic and also ensures light use \
	of system resources. 

homepage            http://humdi.net/vnstat/
depends_lib         port:gd2       
master_sites        http://humdi.net/${name}
checksums           md5     a5a113f9176cd61fb954f2ba297f5fdb \
                    sha1    92494f38a752dcf60053af2a6d8977737da7e616 \
                    rmd160  c7a8602c6ed86c674b14b2b8708e97f5999fb0e5

post-patch {
    # fix Makefile
    reinplace "s|/usr/local|${prefix}|g"                 ${worksrcpath}/Makefile
    reinplace "s|${prefix}/man|${prefix}/share/man|g"    ${worksrcpath}/Makefile
    reinplace "s|(DESTDIR)/etc|(DESTDIR)${prefix}/etc|g" ${worksrcpath}/Makefile
    reinplace "s|(DESTDIR)/var|(DESTDIR)${prefix}/var|g" ${worksrcpath}/Makefile
    
    # fix occurrences of /var/db references in other files
    reinplace "s|/var|${prefix}/var|g"  ${worksrcpath}/src/common.h \
                                        ${worksrcpath}/cfg/vnstat.conf \
                                        ${worksrcpath}/man/vnstat.1 \
                                        ${worksrcpath}/man/vnstatd.1 \
                                        ${worksrcpath}/man/vnstati.1
    reinplace "s|/var/lib|/var/db|g"    ${worksrcpath}/man/vnstat.1 \
                                        ${worksrcpath}/man/vnstatd.1 \
                                        ${worksrcpath}/man/vnstati.1
    
    # fix occurrences of /etc/db references in other files
    reinplace "s|/etc|${prefix}/etc|g"  ${worksrcpath}/man/vnstat.1 \
                                        ${worksrcpath}/man/vnstat.conf.5 \
                                        ${worksrcpath}/man/vnstatd.1 \
                                        ${worksrcpath}/man/vnstati.1 \
                                        ${worksrcpath}/src/cfg.c
}

use_configure       no
variant universal   {}

build.args-append   CC="${configure.cc} [get_canonical_archflags]" \
                    CPP=${configure.cpp} \
                    CFLAGS="-I${prefix}/include" \
                    LDFLAGS="-L${prefix}/lib"

destroot.target     bsdinstall
destroot.keepdirs   ${destroot}${prefix}/var/db/vnstat
post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 755 -d ${destroot}${prefix}/share/examples/${name}
    
    xinstall -m 644 -W ${worksrcpath} \
        CHANGES COPYING FAQ INSTALL INSTALL_BSD README \
        ${destroot}${prefix}/share/doc/${name}

    eval file copy [glob ${worksrcpath}/examples/*] \
        ${destroot}${prefix}/share/examples/${name}
}