# -*- 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 108868 2013-08-04 01:12:54Z takeshi@macports.org $

PortSystem          1.0
PortGroup           github 1.0

github.setup        ispc ispc 1.4.4 v
categories          lang parallel               
platforms           darwin
supported_archs     x86_64
license             BSD
maintainers         takeshi openmaintainer
description         Intel SPMD program compiler
long_description \
    ${name} is a compiler for a variant of the C programming language, \
    with extensions for single program, multiple data programming. 
homepage            http://${name}.github.com
checksums           rmd160  cf19fed2fc6e7f9f949f95783f5a5856a2d69f8a \
                    sha256  075a5b26a0f95d0c875b870fdde0f9706969a9294647109162096a3ab8edac59

set llvm_version    3.3

depends_build       port:bison \
                    port:flex \
                    bin:python:python27
depends_lib         port:clang-${llvm_version}

use_configure       no

configure.compiler  macports-clang-${llvm_version}
post-patch {
    reinplace {s|clang++|${configure.cxx}|} ${worksrcpath}/Makefile
    foreach f {run_tests.py examples/common.mk \
               examples/aobench_instrumented/Makefile examples/simple/Makefile} {
        reinplace "s|g++|${configure.cxx}|" ${worksrcpath}/${f}
    }
    if {[variant_isset doc]} {
        reinplace {s|rst2html.py|rst2html-2.7.py|} ${worksrcpath}/docs/build.sh
    }
}

build.args          LLVM_CONFIG=${prefix}/bin/llvm-config-mp-${llvm_version} \
                    CLANG=${configure.cc}\
                    CXX=${configure.cxx} \
                    OPT="${configure.cxxflags} -fvisibility=hidden" \
                    LEX=${prefix}/bin/flex \
                    YACC="${prefix}/bin/bison -d -v -t" \
                    BUILD_VERSION=${version} \
                    LDFLAGS=${configure.ldflags}
build.target        ""

test.run            yes
test.cmd            {python run_tests.py}
test.target         ""

destroot {
    xinstall -m 755 ${worksrcpath}/ispc ${destroot}${prefix}/bin
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
    file copy ${worksrcpath}/examples ${destroot}${prefix}/share/${name}
    if {[variant_isset doc]} {
        system "cd ${worksrcpath}/docs; ./build.sh"
        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
        file copy ${worksrcpath}/docs ${destroot}${prefix}/share/doc/${name}
    }
}

variant doc description {build and install documentation} {
    depends_build-append    port:py27-docutils
}

livecheck.type      regex
livecheck.url       ${homepage}/downloads.html
livecheck.regex     {v([0-9]+\.[0-9]+\.[0-9])}
