# $Id: Portfile 56421 2009-08-27 09:58:06Z ryandesign@macports.org $

PortSystem              1.0

name                    pure
version                 0.32
set branch              [join [lrange [split ${version} .] 0 1] .]
categories              lang
platforms               darwin
maintainers             ryandesign
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.

checksums \
    md5     0078a9dac2cb51952545a90068dc7a55 \
    sha1    33e7c96a0c99b4f223e40eed1402d2d4ab53c00d \
    rmd160  bc44de62aa21b020be8b026029a32afbdd9e7ac0

depends_build \
    path:bin/llvm-config:llvm

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

depends_run \
    path:bin/w3m:w3m

patchfiles \
    patch-Makefile.in.diff

configure.args \
    --enable-release \
    --enable-gsl

platform macosx {
    depends_run-delete  path:bin/w3m:w3m
    depends_run-append  path:bin/openbrowser:openbrowser
    patchfiles-append   patch-openbrowser.diff
}

pre-extract {
    set llvm_minimum_version 2.4
    set llvm_installed_version [exec llvm-config --version]
    if {[rpm-vercomp ${llvm_installed_version} ${llvm_minimum_version}] < 0} {
        ui_error "${name} ${version} requires llvm ${llvm_minimum_version} or later but you have llvm ${llvm_installed_version}."
        return -code error "incompatible llvm version"
    }
}

test.run                yes
test.target             check

post-destroot {
    # Check for old modules.
    set old_files {}
    foreach dir [glob -nocomplain -type d -tails -directory ${prefix}/lib pure-*] {
        if {"pure-${branch}" == ${dir}} continue
        if {![regexp "^pure-\[0-9.\]+$" ${dir}]} continue
        foreach file [glob -type f -directory ${prefix}/lib/${dir} *] {
            lappend old_files ${file}
        }
    }
    set old_ports {}
    if {[llength ${old_files}] > 0} {
        foreach provides [split [eval exec ${prefix}/bin/port provides ${old_files}] "\n"] {
            set old_port [lindex [split ${provides}] end]
            if {-1 == [lsearch -glob ${old_ports} ${old_port}]} {
                lappend old_ports ${old_port}
            }
        }
    }
    if {[llength ${old_ports}] > 0} {
        ui_msg "Some of your pure modules were built for a different version of pure."
        ui_msg "To use them with version ${branch}, you must rebuild them by running this command:"
        ui_msg ""
        ui_msg "sudo port -nf upgrade [join ${old_ports} " "]"
    }
}

livecheck.check         regex
livecheck.url           http://code.google.com/p/pure-lang/downloads/list
livecheck.regex         ${name}-(\[0-9.\]+\[a-z\]*)\\.tar
