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

PortSystem              1.0
PortGroup               github 1.0

github.setup            mruby mruby 2.1.2

categories              lang
license                 MIT
platforms               darwin

description             Lightweight Ruby

long_description        mruby is the lightweight implementation of the Ruby \
                        language complying to (part of) the ISO standard. \
                        Its syntax is Ruby 2.x compatible.  mruby can be \
                        linked and embedded within your application. We \
                        provide the interpreter program \"mruby\" and the \
                        interactive mruby shell \"mirb\" as examples. You can \
                        also compile Ruby programs into compiled byte code \
                        using the mruby compiler \"mrbc\". \"mrbc\" is also \
                        able to generate compiled byte code in a C source file.

maintainers             {gmail.com:herby.gillot @herbygillot} \
                        openmaintainer

checksums               rmd160  9092772bb2e6bbb6e924a59e57b9978256233199 \
                        sha256  4dc0017e36d15e81dc85953afb2a643ba2571574748db0d8ede002cefbba053b \
                        size    663068

patchfiles              patch-build-config.rb.diff

depends_build-append    port:bison \
                        port:cctools \
                        port:ruby27

depends_lib-append      port:ncurses \
                        port:readline

build.env-append        AR=${prefix}/bin/ar \
                        CC=${configure.cc} \
                        CXX=${configure.cxx} \
                        CPP=${configure.cpp} \
                        YACC=${prefix}/bin/bison

build.cmd               ${prefix}/bin/rake2.7
build.pre_args
build.args

github.tarball_from     archive
use_configure           no

set mrb_build_path      ${worksrcpath}/build/host
set mrb_build_mak_file  ${mrb_build_path}/lib/libmruby.flags.mak
set mrb_lib_path        ${prefix}/lib/mruby

post-build {
    # Remove Makefile generated .d files
    system -W "${mrb_build_path}" "find . -type f -iname *.d -delete"

    # Change build local paths to point to the proper MacPorts prefix paths
    reinplace "s|${worksrcpath}/include|${prefix}/include|g" \
        ${mrb_build_mak_file}

    reinplace "s|${mrb_build_path}/lib|${mrb_lib_path}|g" \
        ${mrb_build_mak_file}
}

destroot {

    foreach mrb_bin [glob ${mrb_build_path}/bin/*] {
        copy ${mrb_bin} ${destroot}${prefix}/bin/
    }

    copy ${worksrcpath}/include/mruby.h     ${destroot}${prefix}/include/
    copy ${worksrcpath}/include/mrbconf.h   ${destroot}${prefix}/include/
    copy ${worksrcpath}/include/mruby       ${destroot}${prefix}/include/

    xinstall -d ${destroot}${mrb_lib_path}

    copy {*}[glob ${mrb_build_path}/lib/*]  ${destroot}${mrb_lib_path}/

    copy ${mrb_build_path}/mrbgems          ${destroot}${mrb_lib_path}/
    copy ${mrb_build_path}/mrblib           ${destroot}${mrb_lib_path}/
    copy ${mrb_build_path}/src              ${destroot}${mrb_lib_path}/

    copy {*}[glob ${worksrcpath}/src/*]     ${destroot}${mrb_lib_path}/src/
}

notes "
    After intallation/activation, build flags for mruby can be found in this file:

    ${mrb_lib_path}/libmruby.flags.mak
"
