# $Id: Portfile 77653 2011-04-07 22:57:34Z mfeiri@macports.org $

PortSystem 1.0

name                    clang
version                 2.9
categories              lang
platforms               darwin
maintainers             mfeiri
license                 UIUC/NCSA
description             C, C++, Objective C and Objective C++ compiler
long_description        Clang is an "LLVM native" C/C++/Objective-C compiler, \
                        which aims to deliver amazingly fast compiles (e.g. \
                        about 3x faster than GCC when compiling Objective-C \
                        code in a debug configuration), extremely useful error \
                        and warning messages and to provide a platform for \
                        building great source level tools. The included Clang \
                        Static Analyzer is a tool automatically finds bugs in \
                        your code, and is a great example of the sort of tool \
                        that can be built using the Clang frontend as a \
                        library to parse C/C++ code.

homepage                http://clang.llvm.org/
master_sites            http://llvm.org/releases/${version}/
extract.suffix          .tgz

worksrcdir              llvm-${version}
distfiles-append        llvm-${version}${extract.suffix}
checksums               ${distname}${extract.suffix} \
                            md5     634de18d04b7a4ded19ec4c17d23cfca \
                            sha1    5fd3b5cec050ec12858c1602b23cf096282ad4a4 \
                            rmd160  4ab79cbd0e2ad25a2272e6ee2fbbf546818dbd73 \
                        llvm-${version}${extract.suffix} \
                            md5     793138412d2af2c7c7f54615f8943771 \
                            sha1    500f587f840199ac53c4fc7572839d08fa9d9123 \
                            rmd160  caeaa067fda1eb34196b356a087645f83731cfb7

depends_lib             port:llvm port:libffi

default_variants        +analyzer
universal_variant       no
build.env-append        REQUIRE_RTTI=1

build.target            clang-only
destroot.target         install-clang-c
configure.cppflags      
configure.ldflags       
configure.args          --enable-optimized --enable-shared \
                        --enable-bindings=none --enable-libffi \
                        --disable-assertions

platform darwin {
    if {${build_arch} == "i386" } {
        configure.pre_args-append --build=i686-apple-darwin${os.major}
    } else {
        configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
    }

    depends_run-append      port:ld64

    # clang uses hardcoded paths to find ld, see lib/Driver/ToolChains.cpp
    post-destroot {
        file mkdir ${destroot}${prefix}/libexec/gcc/i686-apple-darwin${os.major}/4.2.1
        ln -s ../../../../bin/ld ${destroot}${prefix}/libexec/gcc/i686-apple-darwin${os.major}/4.2.1/ld
    }

}

post-extract {
    file rename ${workpath}/${distname} ${worksrcpath}/tools/clang
}

variant analyzer description {Install clang static analyzer} {
    depends_run-append  bin:python:python26 bin:perl:perl5
    post-destroot {
        reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
            ${worksrcpath}/tools/clang/tools/scan-build/ccc-analyzer \
            ${worksrcpath}/tools/clang/tools/scan-build/c++-analyzer \
            ${worksrcpath}/tools/clang/tools/scan-build/scan-build
        reinplace "s|/usr/bin/env python|${prefix}/bin/python2.6|g" \
            ${worksrcpath}/tools/clang/tools/scan-build/set-xcode-analyzer \
            ${worksrcpath}/tools/clang/tools/scan-view/scan-view

        file rename ${worksrcpath}/tools/clang/tools/scan-build ${destroot}${prefix}/libexec/
        file rename ${worksrcpath}/tools/clang/tools/scan-view ${destroot}${prefix}/libexec/

        ln -s ${prefix}/libexec/scan-build/scan-build ${destroot}${prefix}/bin/scan-build
        ln -s ${prefix}/libexec/scan-view/scan-view ${destroot}${prefix}/bin/scan-view
        ln -s ${prefix}/bin ${destroot}${prefix}/libexec/scan-build/bin
    }
}

livecheck.type  regex
livecheck.url   http://llvm.org/releases/
livecheck.regex {'(\d+\.\d+)'}
