# -*- 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: Portfile 119474 2014-04-26 20:38:28Z snc@macports.org $

PortSystem          1.0
PortGroup           github 1.0

github.setup        diegonehab luasocket 3.0-rc1 v
name                lua-luasocket
revision            1
categories          devel
license             MIT
platforms           darwin
maintainers         gmail.com:emmett.shear

description         The luasocket library extends lua with TCP, UDP, and DNS support
long_description    LuaSocket is a Lua extension library that is composed by two parts: \
                    a C core that provides support for the TCP and UDP transport layers, \
                    and a set of Lua modules that add support for functionality commonly \
                    needed by applications that deal with the Internet.

homepage            http://www.cs.princeton.edu/~diego/professional/luasocket/

checksums           md5     24b3532037c30ba3372578d9dbe23d0e \
                    sha1    2549ccfa6c4f90e78b3f2db9b99558232f902987 \
                    rmd160  4001930542a2eb7a4b3ba5bf90f73346b2a23a71

depends_lib         port:lua
depends_build       path:bin/pkg-config:pkgconfig

# Old luaforge livecheck. For now, use github-livecheck, but maybe luaforge
# will be more up to date some day or other.
#livecheck.type      regex
#livecheck.url       http://luaforge.net/frs/?group_id=23
#livecheck.regex     {luasocket-([0-9.]+)\.tar\.gz}

patchfiles          patch-Makefiles.diff

use_configure       no

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/src/makefile
    reinplace "s|@CC@|${configure.cc}|g" ${worksrcpath}/src/makefile
    reinplace "s|@CFLAGS@|${configure.cppflags} ${configure.cflags}|g" ${worksrcpath}/src/makefile
}

build {
    set lua_version "[exec -- ${prefix}/bin/pkg-config --variable V lua]"
    system "cd ${worksrcpath} && make DEBUG=DEBUG macosx LUAV=${lua_version}"
}

destroot {
    set lua_version "[exec -- ${prefix}/bin/pkg-config --variable V lua]"
    system "cd ${worksrcpath} && make DEBUG=DEBUG LUAV=${lua_version} DESTDIR=${destroot} PREFIX=${prefix} PLAT=macosx install-unix"
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 755 -d ${destroot}${prefix}/share/examples/${name}

    eval xinstall -m 644 [glob ${worksrcpath}/doc/*] ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 ${worksrcpath}/LICENSE ${worksrcpath}/NEW \
        ${worksrcpath}/README ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/etc ${worksrcpath}/samples ${worksrcpath}/test \
        ${destroot}${prefix}/share/examples/${name}
}
