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

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0

name                openiked
github.setup        openiked openiked-portable 7.4 v
revision            0
categories          net
license             ISC
maintainers         {@ryanakca debian.org:rak} openmaintainer
description         Internet Key Exchange (IKEv2) daemon
long_description    A free implementation of the Internet Key Exchange (IKEv2) protocol \
                    which performs mutual authentication and which establishes and maintains \
                    IPsec VPN security policies and associations (SAs) between peers. It is \
                    intended to be a lean, clean, secure, better configurable and \
                    interoperable implementation that focusses on supporting the main standards \
                    and most important features of IKEv2.
homepage            https://www.openiked.org

checksums           rmd160  311e5da3e1cad1e1b9e081265dbf96decaef4302 \
                    sha256  cc35cb5a2a6ad40d4e2ed7e269f810394068a7388c1c32e6b769247fe6b6717f \
                    size    321104
github.tarball_from archive

depends_build-append \
                    port:bison
depends_lib-append  port:libevent

# https://github.com/openiked/openiked-portable/commit/ae1369eec5157b1f32bb22718e19c9e1ae36e5d4
# https://github.com/openiked/openiked-portable/commit/8117fd9da6688c4a132c44cbddf755c9e36fa579
patchfiles-append   0001-CMakeLists-fix-detection-of-netinet6-ipsec.h.patch \
                    0002-vroute.c-include-sys-socket.h.patch

# On 10.5.8 build fails with numerous errors:
# pfkeyv2.h:276:3: error: unknown type name 'u_int8_t'; did you mean 'uint8_t'? etc.
patchfiles-append   patch-types.diff

# cc1: error: unrecognized command line option "-fstack-protector-strong"
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

startupitem.create      yes
startupitem.executable  ${prefix}/sbin/iked -d

add_users           _iked group=_iked realname=OpenIKED\ Daemon

set sysconfdir ${prefix}/etc

configure.args-append \
                    -DCMAKE_INSTALL_SYSCONFDIR=${sysconfdir} \
                    -DCMAKE_INSTALL_MANDIR=${prefix}/share/man

# At least on 10.5 ppc64 this fails with gcc14:
# pfkey.c:945:39: error: passing argument 3 of 'pfkey_map' from incompatible pointer type [-Wincompatible-pointer-types]
# pfkey.c:199:68: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'int *'
if {[string match macports-gcc* ${configure.compiler}]} {
    configure.cflags-append \
                    -Wno-error=incompatible-pointer-types
}

post-patch {
    set openssl_install_area [openssl::install_area]
    reinplace "s|/usr/local/opt/openssl|${openssl_install_area}|g" ${worksrcpath}/CMakeLists.txt
    reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/CMakeLists.txt
}

post-destroot {
    file rename ${destroot}${sysconfdir}/iked.conf ${destroot}${sysconfdir}/iked.conf.dist
}

post-activate {
    if {![file exists ${sysconfdir}/iked.conf]} {
        file copy ${sysconfdir}/iked.conf.dist ${sysconfdir}/iked.conf
    }
}
