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

PortSystem          1.0
PortGroup           github 1.0
PortGroup           compilers 1.0

github.setup        JuliaLang julia 0.4.6 v
categories-append   lang math science
maintainers         sean openmaintainer
platforms           darwin
license             MIT
homepage            http://julialang.org

compilers.choose    fc f77 f90
compilers.setup     require_fortran -g95

description         The Julia Language: A fresh approach to technical computing.
long_description    Julia is a high-level, high-performance dynamic programming \
                    language for technical computing, with syntax that is familiar \
                    to users of other technical computing environments.

github.tarball_from releases

distfiles           ${name}-${version}-full${extract.suffix}

checksums           rmd160  332a32fb0e10750540592eb125b3f31843702333 \
                    sha256  4c23c9fc72398014bd39327c2f7efd3a301884567d4cb2a89105c984d4d633ba

# Force buildbot to skip this since julia builds its own blas; see #45101
archive_sites

set llvm_ver        3.7

depends_lib-append  port:llvm-${llvm_ver} \
    port:curl \
    port:pcre2 \
    port:gmp \
    port:mpfr \
    port:SuiteSparse \
    port:fftw-3 \
    port:fftw-3-single \
    port:ncurses \
    port:arpack \
    port:libgit2 \
    path:lib/libopenblas.dylib:OpenBLAS

use_configure       no
# use_parallel_build  no

post-extract {
    file mkdir ${worksrcpath}/usr/lib
    ln -s ${prefix}/lib/libfftw3.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libfftw3_threads.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libfftw3f.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libfftw3f_threads.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libpcre2-8.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libgmp.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libmpfr.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libumfpack.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libcholmod.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libsuitesparseconfig.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libarpack.dylib ${worksrcpath}/usr/lib/
    ln -s ${prefix}/lib/libopenblas.dylib ${worksrcpath}/usr/lib/
}

build {}

pre-destroot {
    destroot.args-append \
        CC=${configure.cc} \
        CXX=${configure.cxx} \
        FC=${configure.fc} \
        USE_SYSTEM_LLVM=1 \
        LLVM_CONFIG=llvm-config-mp-${llvm_ver} \
        USE_SYSTEM_LIBUNWIND=1 \
        USE_SYSTEM_LIBM=1 \
        USE_SYSTEM_GMP=1 \
        USE_SYSTEM_MPFR=1 \
        USE_SYSTEM_ZLIB=1 \
        USE_SYSTEM_PCRE=1 \
        USE_SYSTEM_FFTW=1 \
        USE_SYSTEM_ARPACK=1 \
        USE_SYSTEM_SUITESPARSE=1 \
        USE_SYSTEM_LIBGIT2=1 \
        USE_SYSTEM_BLAS=1 \
        USE_SYSTEM_LAPACK=1 \
        USE_BLAS64=0 \
        LIBBLAS=-lopenblas \
        LIBBLASNAME=libopenblas \
        LIBLAPACK=-lopenblas \
        LIBLAPACKNAME=libopenblas
}

post-destroot {
    # julia doesn't do destroot quite right
    set dpw ${destroot}${worksrcpath}
    delete ${destroot}${prefix}/bin
    move [glob $dpw/julia-*/bin] ${destroot}${prefix}/bin
    move [glob $dpw/julia-*/etc/julia] ${destroot}${prefix}/etc
    move [glob $dpw/julia-*/include/julia] ${destroot}${prefix}/include
    move [glob $dpw/julia-*/lib/julia] ${destroot}${prefix}/lib
    move [glob $dpw/julia-*/share/julia] ${destroot}${prefix}/share
    delete ${destroot}${prefix}/var

    foreach b {julia julia-debug} {
        system -W ${destroot}${prefix}/bin "install_name_tool -add_rpath ${prefix}/lib $b"
    }
}

variant blas64 description {Build internal OpenBLAS with 64-bit interface} {
    depends_lib-delete \
        port:OpenBLAS

    pre-destroot {
        destroot.args-delete \
            USE_SYSTEM_BLAS=1 \
            USE_SYSTEM_LAPACK=1 \
            USE_BLAS64=0 \
            LIBBLAS=-lopenblas \
            LIBBLASNAME=libopenblas \
            LIBLAPACK=-lopenblas \
            LIBLAPACKNAME=libopenblas
    }
}

livecheck.regex     archive/[join ${github.tag_prefix} ""](\[^"-\]+)${extract.suffix}