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

PortSystem      1.0
PortGroup       openssl  1.0
PortGroup       github   1.0

github.setup    cherokee webserver 1.2.104 v
name            cherokee
revision        2

categories      www
platforms       darwin
maintainers     nomaintainer
license         GPL-2

homepage        https://www.cherokee-project.com/

description     Cherokee web server

long_description \
  Cherokee is a relatively new HTTP server designed to be as\
  performant as Apache and lighttpd, but much easier to \
  configure and maintain.  It ships out-of-the-box SCGI \
  support, making it ideal for deploying dynamic websites.

checksums       rmd160  f5271b4b6f6be3cf70a88a3933fd90597862b289 \
                sha256  5cbd00ff48503eaf90356b2975e311c02977f9166927e57fc23f541a109efd98 \
                size    5312997

set ck_wwwroot  ${prefix}/var/www/htdocs
set ck_cgibin   ${prefix}/var/www/cgi-bin
set ck_lcl_bin  ${workpath}/bin

post-extract {
    reinplace -W ${worksrcpath} \
        "s|/Library/WebServer/Documents|${ck_wwwroot}|g" \
        admin/util.py configure.ac

    reinplace -W ${worksrcpath} \
        "s|/Library/WebServer/CGI-Executables|${ck_cgibin}|g" configure.ac

    file mkdir ${ck_lcl_bin}
    # cherokee's autogen.sh seeks a python2 symlink
    ln -s ${prefix}/bin/python2.7 ${ck_lcl_bin}/python2
}

openssl.branch 1.0
openssl.configure build_flags

configure.env-append    PATH=${ck_lcl_bin}:$env(PATH)

configure.cmd   ./autogen.sh
configure.args-append \
                --with-wwwroot=${ck_wwwroot} \
                --with-cgiroot=${ck_cgibin} \
                --with-python=${prefix}/bin/python2.7 \
                --without-ffmpeg \
                --without-mysql \
                --without-ldap \
                --with-libssl=[openssl::install_area]

depends_build-append \
                port:automake \
                port:autoconf \
                port:libtool

depends_lib     port:pcre \
                port:zlib \
                port:libgeoip \
                port:python27 \
                port:rrdtool

# Startup item.
set cherokee_config_name    cherokee.conf
set cherokee_config         ${prefix}/etc/${name}/${cherokee_config_name}
set cherokee_pidfile_name   cherokee.pid
set cherokee_pidfile        ${prefix}/var/run/${cherokee_pidfile_name}

startupitem.create          yes
startupitem.init            PIDFILE=${cherokee_pidfile}
startupitem.start           ${prefix}/sbin/cherokee -C ${cherokee_config}
startupitem.stop            kill \$(cat \$PIDFILE)

variant ffmpeg description {Enable ffmpeg support} {
    depends_lib-append      path:bin/ffmpeg:ffmpeg
    configure.args-replace  --without-ffmpeg --with-ffmpeg
}

variant ldap description {Enable LDAP support} {
    depends_lib-append      path:lib/libldap.dylib:openldap
    configure.args-replace  --without-ldap --with-ldap
}

pre-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/var/log
    destroot.keepdirs-append ${destroot}${prefix}/var/log
}

github.tarball_from archive

notes "
    Cherokee's web root is located at: ${ck_wwwroot}
"
