# -*- 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 92478 2012-04-29 23:29:03Z ryandesign@macports.org $

PortSystem              1.0

name                    pure
# Keep the versions of pure and pure-docs in sync.
version                 0.53
categories              lang
platforms               darwin
maintainers             ryandesign
license                 LGPL-3 GPL-3 BSD
use_parallel_build      yes
homepage                http://pure-lang.googlecode.com/
master_sites            ${homepage}files/

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.

checksums               rmd160  f864428bfae18dda1bf1e306afddd04836a6e950 \
                        sha256  5c1d2e9c2780c4c545bd210372ecc84b079edaa013377323f739232a7a76d1a3

livecheck.type          none

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

if {${name} == ${subport}} {
    depends_lib                 port:gmp \
                                port:libiconv \
                                port:libtool \
                                port:llvm-${llvm_version} \
                                port:mpfr \
                                port:readline
    
    depends_run                 path:bin/w3m:w3m
    
    patchfiles                  patch-interpreter.cc.diff
    
    post-patch {
        reinplace "s|@LLVM_PREFIX@|${llvm_prefix}|g" ${worksrcpath}/interpreter.cc
    }
    
    # llvm-${llvm_version} is not universal
    universal_variant           no
    
    configure.args              --without-elisp
    
    # 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 macosx {
        depends_run-replace s|path:bin/w3m:w3m|path:bin/openbrowser:openbrowser|
        patchfiles-append       patch-openbrowser.diff
    }
    
    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}
    }
    
    test.run                    yes
    test.target                 check
    
    livecheck.type              regex
    livecheck.url               http://code.google.com/p/pure-lang/downloads/list
    livecheck.regex             ${name}-(\[0-9.\]+\[a-z\]*)\\.tar
}

subport pure-mode.el {
    categories-append           editors
    license                     GPL-3+
    supported_archs             noarch
    homepage                    http://code.google.com/p/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 ${lispdir}
    }
}
