# $Id$
PortSystem 1.0
PortGroup           github 1.0 

github.setup        keplerproject wsapi 1.5
name                lua-${github.project}
license             GPL-3
categories          devel
platforms           darwin
maintainers         and.damore openmaintainer
description         Lua Web Server API
long_description    WSAPI is an API that abstracts the web server from Lua web applications. \
                    By coding against WSAPI your application can run on any of the supported \
                    servers and interfaces (currently CGI, FastCGI and Xavante, on Windows \
                    and UNIX-based systems).

github.tarball_from downloads
checksums           md5     5c983a1db3659ed73e28c473ffd4f4d5 \
                    sha1    8c9c86f4cb45f94afb110390c6af808ed8238fe4 \
                    rmd160  a675f92700b588771f9da977912fb0171a28e0bf

depends_lib         port:lua \
                    port:lua-luafilesystem \
                    port:lua-rings \
                    port:fcgi

patchfiles          patch-Makefile.diff \
                    patch-configure.diff \
                    patch-src-fastcgi-lfcgi.c.diff

post-patch {
    reinplace "s|\x0D||g" ${worksrcpath}/src/launcher/wsapi.cgi
    reinplace "s|#!/usr/bin/lua|#!/usr/bin/env lua|" ${worksrcpath}/src/launcher/wsapi.cgi
    reinplace "s|#!/usr/bin/lua|#!/usr/bin/env lua|" ${worksrcpath}/src/launcher/wsapi.fcgi
    reinplace "s|lua51|lua|" ${worksrcpath}/samples/cgi-example.lua
    reinplace "s|lua51|lua|" ${worksrcpath}/samples/fastcgi-example.lua
}

configure.pre_args  lua

destroot.target-append  install-fcgi
destroot.post_args-append PREFIX=${prefix}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    eval xinstall -m 644    ${worksrcpath}/README \
                            [glob ${worksrcpath}/doc/us/*] \
        ${destroot}${prefix}/share/doc/${name}

    xinstall -m 755 -d ${destroot}${prefix}/share/examples/${name}
    file copy   ${worksrcpath}/samples \
                ${worksrcpath}/tests \
        ${destroot}${prefix}/share/examples/${name}
}