# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=portfile:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           qmake 1.0

github.setup        pstavirs ostinato 1.0 v
revision            0
maintainers         nomaintainer
license             GPL-3+

categories          net devel
description         Ostinato is an open-source, cross-platform network packet \
                    crafter/traffic generator and analyzer with a friendly GUI.
long_description    {*}${description} Craft and send packets of several streams \
                    with different protocols at different rates.

checksums           rmd160  560cfff0b50d25896880feaac178c1b30f3e57bb \
                    sha256  d85d934d381c547829dc6e7bc91d0d596414285a97d1e6de050cb3cd231b906c \
                    size    597517
github.tarball_from archive

worksrcdir          ${name}-${version}

patchfiles-append   patch-Qt4.diff

set protoport       protobuf3-cpp
set protoroot       ${prefix}/libexec/${protoport}

# This would be a neat solution, but the build does not seem to be able to use pkg-config.
# configure.pkg_config_path-prepend \
                    ${protoroot}/lib/pkgconfig

post-patch {
    reinplace "s|@PROTOROOT@|${protoroot}|" \
                    ${worksrcpath}/client/ostinato.pro \
                    ${worksrcpath}/rpc/pbrpc.pro \
                    ${worksrcpath}/server/drone.pro
}

depends_lib-append  port:libpcap \
                    port:${protoport}

# ${protoport} requires at least C++11
compiler.cxx_standard 2011
configure.cxxflags-append -std=c++11

# bsdport.cpp:211:25: error: invalid conversion from 'caddr_t' {aka 'char*'}
# to 'const uchar*' {aka 'const unsigned char*'} [-fpermissive]
if {[string match *gcc* ${configure.compiler}]} {
    configure.cxxflags-append \
                    -fpermissive
}

configure.cppflags-append \
                    -I${protoroot}/include

# TODO: do we still need this?
# Force ${protoport} into the no_threadlocal mode
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    configure.cxxflags-append \
                    -DGOOGLE_PROTOBUF_NO_THREADLOCAL
}

# qmake is not automatically passing in the stdlib on link
if {${configure.cxx_stdlib} eq "libc++"} {
    configure.ldflags-append \
                    -stdlib=${configure.cxx_stdlib}
}

# make[1]: protoc: Command not found
build.cmd-prepend   PATH="${protoroot}/bin:\$PATH"

post-extract {
    move   ${worksrcpath}/extra/qhexedit2/src/VERSION \
           ${worksrcpath}/extra/qhexedit2/src/VERSION.txt
}

post-destroot {
    move ${destroot}${prefix}/Ostinato ${destroot}${applications_dir}
}
