# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 57727 2009-09-15 18:40:12Z mnick@macports.org $

PortSystem          1.0

name                tbb
set rel_date        20090809
set vers            2.2
version             ${vers}-${rel_date}
revision            1
maintainers         mnick openmaintainer

categories          devel
description         Intel Threading Building Blocks offers a rich and complete approach to parallelism in C++
long_description    ${description} \
                    It represents a higher-level, task-based parallelism that abstracts \
                    platform details and threading mechanisms for scalability and performance
license             GPL
platforms           darwin

homepage            http://www.threadingbuildingblocks.org
master_sites        ${homepage}/uploads/77/142/${vers}/
worksrcdir          ${name}22_${rel_date}oss
distname            ${worksrcdir}_src
extract.suffix      .tgz

checksums           md5     c621053887c7ee86932da43e2deb3bff \
                    sha1    12af8e2bdddb51aa62312523a70ebf2a0f6de8d6 \
                    rmd160  2c0fac8c9ef3648dcf3d1f2b03a56672ab4eaab2

universal_variant   no
build.target        tbb tbbmalloc

configure {
    if {${build_arch} eq "i386"} {
        set arch_flag intel32
    } elseif {${build_arch} eq "x86_64"} {
        set arch_flag intel64
    }
    build.env-append    arch=${arch_flag}
    test.env-append     arch=${arch_flag}
}

destroot {
    set build_dir [exec sh -c "cd ${worksrcpath} && ${build.env} make info | grep build_prefix | cut -f2 -d'='"]
    set build_dir "${worksrcpath}/build/${build_dir}_release"
    
    # fix paths
    reinplace "s|\\(TBB22_INSTALL_DIR.\\)\".*\"|\\1\"${prefix}\"|g" \
        ${build_dir}/tbbvars.sh ${build_dir}/tbbvars.csh
    reinplace "s|\\(tbb_bin.\\)\".*\"|\\1\"${prefix}/lib\"|g" \
        ${build_dir}/tbbvars.sh ${build_dir}/tbbvars.csh

    # copy lib, include & bin
    eval file copy [glob ${build_dir}/lib*.dylib] ${destroot}${prefix}/lib
    eval file copy [glob ${build_dir}/tbbvars.*sh] ${destroot}${prefix}/bin
    file copy ${worksrcpath}/include/tbb ${destroot}${prefix}/include/tbb
    
    # fix install_name paths
    system "install_name_tool -id ${prefix}/lib/libtbb.dylib ${destroot}${prefix}/lib/libtbb.dylib"
    system "install_name_tool -id ${prefix}/lib/libtbbmalloc.dylib ${destroot}${prefix}/lib/libtbbmalloc.dylib"
    
    # copy examples & docs
    file mkdir ${destroot}${prefix}/share/${name}
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/${name}/doc
    file copy ${worksrcpath}/examples ${destroot}${prefix}/share/${name}/examples
}

test.run            yes
test.cmd            make
test.target         test

livecheck.type      regex
livecheck.url       ${homepage}/file.php?fid=77
livecheck.version   [join [split [lrange [split ${version} -] 0 0] .] ""]_${rel_date}
livecheck.regex     <a href='ver.php\\?fid=\\d+'>${name}(\[\\d_\]+)oss</a>
