# -*- 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 78627 2011-05-14 21:53:03Z ryandesign@macports.org $

PortSystem              1.0

name                    pure
conflicts               pure-devel
# Keep the versions of pure, pure-mode.el, and pure-docs in sync.
version                 0.47
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.

use_autoreconf          yes

checksums               sha1    f47915ffa9fd0c7dee40f364a5751bfd4f945bf1 \
                        rmd160  58267f5e876775f9a1af5e4990c51d9061e60d70

depends_lib \
    port:llvm \
    port:gmp \
    port:libiconv \
    port:libtool \
    port:readline

depends_run \
    path:bin/w3m:w3m

# llvm is not universal
universal_variant       no

configure.args          --without-elisp

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
}

pre-configure {
    if {"i386" == ${os.arch}} {
        set arch Intel
        set llvm_minimum_version 2.5
    } else {
        set arch PowerPC
        set llvm_minimum_version 2.6
    }
    set llvm_installed_version [exec ${prefix}/bin/llvm-config --version]
    if {[rpm-vercomp ${llvm_installed_version} ${llvm_minimum_version}] < 0} {
        ui_error "${name} ${version} requires llvm ${llvm_minimum_version} or later on ${arch} but you have llvm ${llvm_installed_version}."
        return -code error "incompatible llvm version"
    }
    set llvm_cflags [exec ${prefix}/bin/llvm-config --cflags]
    if {-1 != [string first -mdynamic-no-pic ${llvm_cflags}]} {
        ui_error "${name} ${version} requires llvm be compiled using position-independent code (PIC)"
        return -code error "incompatible llvm installation"
    }
    
    # http://groups.google.com/group/pure-lang/msg/109b9577a084bc08
    if {[file exists ${prefix}/lib/libLLVM-${llvm_installed_version}.dylib]} {
        configure.ldflags-append -lLLVM-${llvm_installed_version}
    }
}

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
