# -*- 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

name                yaws
version             2.0.6
categories          www
maintainers         {ciserlohn @ci42}
platforms           darwin
license             BSD
description         Webserver for dynamic content written in Erlang
long_description    Yaws is a high performance HTTP server for dynamic content \
                    written in Erlang. Pages can be dynamic with embedded erlang \
                    code. Yaws also features a built-in Wiki.
homepage            http://yaws.hyber.org/
master_sites        http://yaws.hyber.org/download/

checksums           rmd160  04e05a3db7e269c8c54d8464f5cfe331eab3b383 \
                    sha256  69f96f8b9bb574b129b0f258fb8437fdfd8369d55aabc2b5a94f577dde49d00e \
                    size    1644979

depends_build       port:erlang

depends_skip_archcheck  erlang

extract.post_args   | tar -xf - --exclude \
                    "${name}-${version}/www/testdir/xx*xx.jpg"

patchfiles          patch-man-yaws.1 \
                    patch-man-yaws_api.5 \
                    patch-man-yaws.conf.5 \
                    patch-scripts-yaws.conf.template \
                    patch-scripts-regular-install

# fix for systems without /usr/include
# https://trac.macports.org/ticket/57697
patchfiles-append   configure.ac.patch

# https://trac.macports.org/ticket/65723
patchfiles-append   patch-werror.diff

post-patch {
    reinplace "s|__PREFIX|${prefix}|g" \
                    ${worksrcpath}/man/yaws.1 \
                    ${worksrcpath}/man/yaws.conf.5 \
                    ${worksrcpath}/man/yaws_api.5
    # insert SDK path, goes with ticket #57697 patch above
    reinplace "s|__SDKROOT|${configure.sdkroot}|g" \
                    ${worksrcpath}/configure.ac
}

default_variants    +yapp

use_autoreconf      yes

configure.args      --sysconfdir=${prefix}/etc \
                    --localstatedir=${prefix}/var \
                    --disable-silent-rules

configure.universal_args-delete --disable-dependency-tracking

variant yapp description {Yapp application handler} {
    post-build {
        system "cd ${worksrcpath}/applications/yapp && make && make docs"
    }
    post-destroot {
        system "cd ${worksrcpath}/applications/yapp && make install DESTDIR=${destroot}"
    }
}

post-destroot {
    xinstall -d "${destroot}${prefix}/var/log/yaws/"
    system "touch ${destroot}${prefix}/var/log/yaws/.turd"
    file delete "${destroot}${prefix}/etc/yaws/yaws.conf"
}

notes "\
Copy and customize ${prefix}/etc/yaws/yaws.conf.template to ${prefix}/etc/yaws/yaws.conf\
"

startupitem.create  yes
startupitem.name    yaws
startupitem.start   "${prefix}/bin/yaws --daemon --heart --conf ${prefix}/etc/yaws/yaws.conf"
startupitem.stop    "${prefix}/bin/yaws --stop"

livecheck.type      regex
livecheck.url       http://yaws.hyber.org/download/
livecheck.regex     {<a href="yaws-(.*?).tar.gz"}
