# $Id: Portfile 89875 2012-02-13 19:06:00Z and.damore@macports.org $
PortSystem          1.0

name                lua-lpeg
version             0.10.2
revision            1
categories          devel
platforms           darwin
maintainers         and.damore openmaintainer
description         Parsing Expression Grammars For Lua
long_description    LPeg is a new pattern-matching library for Lua, based on Parsing \
                    Expression Grammars (PEGs). This text is a reference manual for the \
                    library

homepage            http://www.inf.puc-rio.br/~roberto/lpeg
master_sites        ${homepage}
distname            lpeg-${version}
checksums           md5     1402433f02e37ddadff04a3d4118b026 \
                    sha1    f2cd5857efb6e1bb02dfb9fbd68e74a451467462 \
                    rmd160  77dc2f7ca88ac84e6f185cf6077aaf88a130c3af

depends_lib         port:lua
use_configure       no

patchfiles          patch-makefile.diff
post-patch {
    reinplace   "s|%PREFIX%|${prefix}|"             ${worksrcpath}/makefile
    reinplace "s|%COMPILER%|${configure.compiler}|" ${worksrcpath}/makefile

    reinplace "s|/usr/bin/env lua5.1|${prefix}/bin/lua|" ${worksrcpath}/test.lua
}

build.env-append    CFLAGS="${configure.cflags}" \
                    LDFLAGS="${configure.ldflags} -llua -lm"G

build.target        lpeg.so

# makefile is missing install target, override destroot
destroot {
    xinstall -d 755 ${destroot}${prefix}/lib/lua/5.1
    xinstall -m 644 ${worksrcpath}/lpeg.so ${destroot}${prefix}/lib/lua/5.1

    xinstall -d 755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 \
        -W ${worksrcpath} lpeg.html re.html lpeg-128.gif HISTORY \
        ${destroot}${prefix}/share/doc/${name}

    xinstall -d 755 ${destroot}${prefix}/share/examples/${name}
    xinstall -m 755 ${worksrcpath}/test.lua ${destroot}${prefix}/share/examples/${name}
    xinstall -m 644 ${worksrcpath}/re.lua   ${destroot}${prefix}/share/examples/${name}
}

