# -*- 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
PortGroup           github 1.0

github.setup        keplerproject luarocks 2.3.0 v
license             MIT
categories          devel
platforms           darwin
maintainers         nomaintainer
supported_archs     noarch

description         Manager for rocks, lua extensions.
long_description    \
    LuaRocks is a deployment and management system for Lua modules that allows \
    you to install self-contained modules (\"rocks\") which also contain \
    version dependency information. It handles both install time dependencies \
    and runtime version check. LuaRocks supports local and remote \
    repositories, and multiple local rocks trees.

homepage            http://www.luarocks.org/
depends_lib         port:lua

checksums           rmd160  7b435a44d738aac1a37436cb8fab6b14ae5deb10 \
                    sha256  0e44e4246ee602dcc623b4a2c329a2c57627a598018d3474e30c28a91fe5276d

configure.args      --with-lua=${prefix} \
                    --rocks-tree=${prefix}/share/${name}

patchfiles          patch-src_luarocks_cfg.diff
post-patch {
    reinplace   "s|%PREFIX%|${prefix}|g"       ${worksrcpath}/src/luarocks/cfg.lua
    reinplace "s|%COMPILER%|${configure.cc}|g" ${worksrcpath}/src/luarocks/cfg.lua
}

pre-configure {
    configure.args-append  --lua-version=[string range [lindex [lindex [registry_active lua] 0] 1] 0 2]
}

post-configure {
    reinplace -E "/ln -nfs/s|\\\$\\\(DESTDIR\\\)\\\$\\\(BINDIR\\\)/|${prefix}/bin/|" ${worksrcpath}/Makefile
}

use_parallel_build  no

variant md5 conflicts openssl description { Use md5 as checker } {
    configure.args-append   --with-md5-checker=md5sum
}
    
variant openssl conflicts md5 description { Use openssl as checker } {
    configure.args-append   --with-md5-checker=openssl
    depends_run-append  path:lib/libssl.dylib:openssl
}

if {![variant_isset md5]} {
    default_variants +openssl
}

variant wget conflicts curl description { Use wget as downloader } {
    configure.args-append   --with-downloader=wget
    depends_run-append  port:wget
}

variant curl conflicts wget description { Use curl as downloader } {
    configure.args-append   --with-downloader=curl
    depends_run-append  port:curl
}

if {![variant_isset wget]} {
    default_variants +curl
}

destroot.keepdirs  ${destroot}${prefix}/share/luarocks/
post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/luarocks/
}
notes "If you upgraded lua from 5.1 to 5.2 you'll need to reinstall your rocks, you can find a list of the previous installed rocks in ${prefix}/share/${name}/lib/lua/5.1 and in ~/.luarocks/ . Note that these previously installed rocks may be listed as installed but luarocks.require function will not be able to load them"