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

# Keep the versions of pure and pure-docs in sync.
name                    pure
github.setup            agraef pure-lang 0.68 ${name}-
categories              lang
platforms               darwin
maintainers             {ryandesign @ryandesign} {gmail.com:aggraef @agraef}
license                 LGPL-3+ GPL-3+ BSD
use_parallel_build      yes
homepage                https://agraef.github.io/pure-lang/

description             functional programming language based on term rewriting

long_description        Pure is a functional programming language based on \
                        term rewriting. It has a modern syntax featuring \
                        curried function applications, lexical closures and \
                        equational definitions with pattern matching, and \
                        thus is somewhat similar to languages of the Haskell \
                        and ML variety. But Pure is also a very dynamic and \
                        reflective language, and is more like Lisp in this \
                        respect. The interpreter has an LLVM backend to do \
                        JIT compilation, hence programs run blazingly fast \
                        and interfacing to C modules is easy. The libraries \
                        are licensed under LGPL-3+, the interpreter is GPL-3+, \
                        and the examples are BSD-licensed.

github.tarball_from     releases
distname                ${name}-${version}

checksums               rmd160  80d85df0d3823edbfd2b8671f8f6597751025c6d \
                        sha256  cbc793490cc90e43218e177109e96ccaebf0380b39d8f2afb86b35b663e9a65f \
                        size    1517896

set llvm_version        3.4
set llvm_prefix         ${prefix}/libexec/llvm-${llvm_version}
configure.env           PATH=${llvm_prefix}/bin:$env(PATH)

if {${name} eq ${subport}} {
    revision                    2
    
    depends_lib                 port:gmp \
                                port:libiconv \
                                port:libtool \
                                port:llvm-${llvm_version} \
                                port:mpfr \
                                port:ncurses \
                                port:readline
    
    depends_run                 port:w3m
    
    configure.args              --without-elisp \
                                --with-tool-prefix=${llvm_prefix}/bin
    
    # Explicitly disable C++11 support because Pure doesn't need it and the
    # auto-detection in the configure script gets it wrong when using clang
    # 3.3 or later with libstdc++:
    # https://bitbucket.org/purelang/pure-lang/issue/28/pure-fails-to-build-on-os-x-107-and-108
    configure.args-append       --disable-c++11
    
    # Prevent build failure when old llvm port is installed
    configure.cppflags          -I${llvm_prefix}/include ${configure.cppflags}
    configure.ldflags           -L${llvm_prefix}/lib ${configure.ldflags}
    
    platform powerpc {
        configure.args-append   --disable-fastcc
    }
    
    post-destroot {
        set docdir ${destroot}${prefix}/share/doc/${name}
        xinstall -d ${docdir} ${destroot}${prefix}/share/examples
        xinstall -W ${destroot.dir} -m 644 \
            COPYING \
            COPYING.LESSER \
            ChangeLog \
            NEWS \
            README \
            TODO \
            ${docdir}
        copy ${destroot.dir}/examples ${destroot}${prefix}/share/examples/${name}
    }

    variant pcre description {Replace POSIX regular expression support with PCRE support} {
        depends_lib-append      port:pcre
        configure.args-append   --with-pcre
    }
    
    test.run                    yes
    test.target                 check
} else {
    livecheck.type              none
}

subport pure-mode.el {
    revision                    0
    
    categories-append           editors
    license                     GPL-3+
    supported_archs             noarch
    homepage                    https://github.com/agraef/pure-lang/wiki/UsingPure#pure-and-emacs
    
    description                 Emacs mode for editing Pure files
    
    long_description            ${subport} is an ${description}.
    
    depends_lib                 port:emacs
    
    extract.post_args-append    ${worksrcdir}/etc
    
    build.dir                   ${worksrcpath}/etc
    
    post-extract {
        copy ${build.dir}/pure-mode.el.in ${build.dir}/pure-mode.el
    }
    
    use_configure               no
    
    build {
        reinplace "s|@bindir@|${prefix}/bin|g" ${build.dir}/pure-mode.el
        reinplace "s|@libdir@|${prefix}/lib|g" ${build.dir}/pure-mode.el
        system -W ${build.dir} "${prefix}/bin/emacs -q --no-site-file -batch -eval \"(add-to-list 'load-path \\\".\\\")\" -eval \"(setq byte-compile-warnings '(callargs free-vars noruntime redefine))\" -f batch-byte-compile pure-mode.el"
    }
    
    destroot {
        set lispdir ${destroot}${prefix}/share/emacs/site-lisp
        xinstall -d ${lispdir}
        xinstall -m 644 -W ${destroot.dir} pure-mode.el pure-mode.elc flycheck-pure.el ${lispdir}
    }
}