# $Id: Portfile 78228 2011-04-29 02:42:44Z ryandesign@macports.org $
PortSystem 1.0

name                lua-wsapi
version             1.4
revision            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).
homepage            http://wsapi.luaforge.net/

master_sites        https://github.com/keplerproject/wsapi/tarball/v${version}

# actual name on web server is different than ${distname} but github returns a
# tarball with the last part of URI as name
# we'll end with a ${distname}${extract.suffix} anyway but we need to strip
# first component of path in order to have a consistent tree
extract.mkdir       yes
extract.post_args   "| tar --strip-components=1 -xf -"

checksums           md5     5cfdaf867aed48e155d732f964985d3d \
                    sha1    b041148e4a13fb454c08c21de2a8f9ba9a4a3ec6 \
                    rmd160  d81aa518bf6e1a14814a778e075a3bef7b267f69

depends_lib         port:lua \
                    port:lua-luafilesystem

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}
    xinstall -m 755 -d ${destroot}${prefix}/share/examples/${name}
    
    xinstall -m 644 ${worksrcpath}/README ${destroot}${prefix}/share/doc/${name}
    eval xinstall -m 644 [glob ${worksrcpath}/doc/us/*] ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/samples ${worksrcpath}/tests ${destroot}${prefix}/share/examples/${name}
}

