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

PortSystem          1.0

name                lua-lpeg
license             MIT
version             0.12.2
categories          devel
platforms           darwin
maintainers         gmail.com:andremm openmaintainer
description         Parsing Expression Grammars for Lua
long_description    LPeg is a new pattern-matching library for Lua, based on \
                    Parsing Expression Grammars (PEGs).

homepage            http://www.inf.puc-rio.br/~roberto/lpeg
master_sites        ${homepage}
distname            lpeg-${version}
# upstream archive had a stealth update, setting subdir since it's likely to happen again
dist_subdir         ${name}/${version}_1

checksums           rmd160  fb6d1613b668edbddfbffd378642827f0c1626ee \
                    sha256  6aad270b91d1b1c6fd75f68e162329a04a644e50e917d55f46cc8384b7120004

depends_build       port:pkgconfig
depends_lib         port:lua

patchfiles          patch-makefile.diff

# This should be done in post-patch, but lua is only available as a dependency
# in configure and later phases. Thus, using pkg-config to get the C and LDFLAGS
# fails miserably in trace mode.
pre-configure {
    reinplace  "s|%%CFLAGS%%|${configure.cflags}  [exec ${prefix}/bin/pkg-config lua --cflags]|" ${worksrcpath}/makefile
    reinplace "s|%%LDFLAGS%%|${configure.ldflags} [exec ${prefix}/bin/pkg-config lua --libs]|"   ${worksrcpath}/makefile

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

use_configure       no

variant universal {}

build.target        macosx
build.args          CC="${configure.cc} [get_canonical_archflags]" \
                    LUADIR=${prefix}/include 

destroot {
    set lua_cmod [exec ${prefix}/bin/pkg-config lua --variable INSTALL_CMOD]
    set lua_lmod [exec ${prefix}/bin/pkg-config lua --variable INSTALL_LMOD]
    set lua_docdir ${prefix}/share/doc/${name}
    set lua_exampledir ${prefix}/share/examples/${name}

    xinstall -m 755 -d \
        ${destroot}${lua_cmod} \
        ${destroot}${lua_lmod} \
        ${destroot}${lua_docdir} \
        ${destroot}${lua_exampledir}

    xinstall ${worksrcpath}/lpeg.so ${destroot}${lua_cmod}
    xinstall ${worksrcpath}/re.lua ${destroot}${lua_lmod}

    xinstall -m 644 -W ${worksrcpath} HISTORY lpeg-128.gif lpeg.html re.html ${destroot}${lua_docdir}
    xinstall -m 755 ${worksrcpath}/test.lua ${destroot}${lua_exampledir}
}

livecheck.regex     "lpeg-(\\d+(?:\\.\\d+)*)${extract.suffix}"