# -*- 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 68235 2010-05-29 19:43:48Z mcalhoun@macports.org $

PortSystem			1.0
PortGroup           muniversal 1.0

name                qrupdate
version             1.1.1
revision            1
categories          math
maintainers         nomaintainer
description         library for fast updates of QR and Cholesky decompositions
long_description \
    a Fortran library for fast updates of QR and Cholesky decompositions
homepage            http://sourceforge.net/projects/${name}/
platforms           darwin
master_sites        sourceforge

checksums           md5     7782c7ee6c234e56a72d6b86c1856fa0 \
                    sha1    8fbaba202b0d4bf80852b2dc6c8d1d4b90b816d4 \
                    rmd160  fd63306abe91adcd5d47e408d9cd4af3e1b32b0c

depends_lib-append  port:atlas

use_configure       no
build.target        lib solib

build.args          PREFIX=${prefix} BLAS="-L${prefix}/lib" LAPACK="-L${prefix}/lib -llapack"
destroot.args       PREFIX=${prefix} BLAS="-L${prefix}/lib" LAPACK="-L${prefix}/lib -llapack"
test.args           PREFIX=${prefix} BLAS="-L${prefix}/lib" LAPACK="-L${prefix}/lib -llapack"

patchfiles          patch-Makefile.diff

post-patch {
    # Mac install program does not support -D flag.
    reinplace "s|install -D|install|"  ${worksrcpath}/src/Makefile

    # Running ranlib on static libraries make universal builds a little more complicated.
    reinplace "s|ar -cr |libtool -o |"  ${worksrcpath}/src/Makefile
}

# Fortran compilers can not cross-compile
if { ${os.arch}=="i386" } {
    set universal_archs_supported "i386 x86_64"
} else {
    set universal_archs_supported "ppc ppc64"
}

post-configure {
    if { ! [variant_isset universal] } {
        if { ${build_arch} == "x86_64" || ${build_arch} == "ppc64" } {
            reinplace "s|^FFLAGS=|FFLAGS=-m64 |"  ${worksrcpath}/Makeconf
        } else {
            reinplace "s|^FFLAGS=|FFLAGS=-m32 |"  ${worksrcpath}/Makeconf
        }
    } else {
        foreach arch ${universal_archs_to_use} {
            if { ${arch}=="x86_64" || ${arch}=="ppc64" } {
                reinplace "s|^FFLAGS=|FFLAGS=-m64 |"  ${worksrcpath}-${arch}/Makeconf
            } else {
                reinplace "s|^FFLAGS=|FFLAGS=-m32 |"  ${worksrcpath}-${arch}/Makeconf
            }
        }
    }
}

variant g95 conflicts gcc43 gcc44 universal description {build with g95} {
    depends_build-append    port:g95
    post-patch {
        reinplace "s|Makeconf|Makeconf.g95|" ${worksrcpath}/Makefile
        reinplace "s|Makeconf|Makeconf.g95|" ${worksrcpath}/src/Makefile
    }
}

variant gcc43 conflicts g95 gcc44 universal description {build with gcc43 fortran} {
    depends_build-append    port:gcc43
    post-patch {
        reinplace "s|gfortran|gfortran-mp-4.3|" ${worksrcpath}/Makeconf
    }
}

variant gcc44 conflicts g95 gcc43 description {build with gcc44 fortran} {
    depends_build-append    port:gcc44
    post-patch {
        reinplace "s|gfortran|gfortran-mp-4.4|" ${worksrcpath}/Makeconf
    }
}

if {![variant_isset gcc43] && ![variant_isset gcc44] && ![variant_isset g95]} {
    default_variants +gcc44
}

test.run yes
