# $Id$

# TODO:
#  * Update clang subport to build against installed llvm

PortSystem              1.0
PortGroup select        1.0
PortGroup compiler_blacklist_versions 1.0
PortGroup active_variants 1.1
PortGroup cmake         1.0

set llvm_version        devel
set llvm_version_no_dot devel
set clang_executable_version 4.0
set lldb_executable_version 4.0.0
name                    llvm-${llvm_version}
revision                0
subport                 clang-${llvm_version} {}
subport                 lldb-${llvm_version} {}
set suffix              mp-${llvm_version}
set sub_prefix          ${prefix}/libexec/llvm-${llvm_version}
dist_subdir             llvm
categories              lang
platforms               darwin
license                 NCSA
maintainers             jeremyhu larryv

if {${subport} eq "llvm-${llvm_version}"} {
    homepage            http://llvm.org/
    description         llvm is a next generation compiler infrastructure
    long_description    The LLVM Core libraries provide a modern source- and \
                        target-independent optimizer, along with code \
                        generation support for many popular CPUs (as well as \
                        some less common ones!) These libraries are built \
                        around a well specified code representation known as \
                        the LLVM intermediate representation ("LLVM IR").

    depends_lib         port:libedit port:libffi port:ncurses port:zlib
    depends_run         bin:perl:perl5 port:llvm_select
} elseif {${subport} eq "clang-${llvm_version}"} {
    homepage            http://clang.llvm.org/
    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 that 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.

    depends_lib         port:libxml2 port:libomp port:llvm-${llvm_version} port:python27
    depends_run         port:clang_select port:ld64
    depends_build-append port:cctools
    depends_skip_archcheck-append cctools ld64 subversion

    # Clang doesn't actually use any of these, but the LLVM makefile
    # system overlinks its binaries. Remove (or convert to build deps?)
    # after #46040 is resolved.
    depends_lib-append  port:libedit port:libffi port:ncurses port:zlib

    default_variants    +analyzer
} elseif {${subport} eq "lldb-${llvm_version}"} {
    homepage            http://lldb.llvm.org/
    description         the LLVM debugger
    long_description    Lldb is the "LLVM native" debugger.

    depends_lib         port:libxml2 port:libomp port:llvm-${llvm_version} port:python27 \
                        port:ncurses
    depends_build-append port:cctools port:swig-python port:doxygen
    depends_skip_archcheck-append cctools

    # Clang doesn't actually use any of these, but the LLVM makefile
    # system overlinks its binaries. Remove (or convert to build deps?)
    # after #46040 is resolved.
    depends_lib-append  port:libedit port:libffi port:ncurses port:zlib
}

fetch.type              svn
svn.revision            284098

depends_extract-append  port:subversion

set compiler_rt_rev     ${svn.revision}
set libcxx_rev          ${svn.revision}
set clang-modernize_rev ${svn.revision}
version                 ${llvm_version}-r${svn.revision}
worksrcdir              trunk
svn.url                 https://llvm.org/svn/llvm-project/llvm/trunk
#worksrcdir              release_${llvm_version_no_dot}
#svn.url                 https://llvm.org/svn/llvm-project/llvm/branches/release_${llvm_version_no_dot}
default_variants-append +assertions
default_variants-append +debug

#version                 ${llvm_version}.0
#epoch                   1
#master_sites            http://llvm.org/releases/${version}
#use_xz                  yes
#extract.suffix          .tar.xz
#distfiles               llvm-${version}.src${extract.suffix}
#worksrcdir              llvm-${version}.src

if {${distfiles} ne ""} {
    if {${subport} eq "llvm-${llvm_version}"} {
        if {[variant_isset polly]} {
            distfiles-append     polly-${version}.src${extract.suffix}
        }
    } elseif {${subport} eq "clang-${llvm_version}"} {
        distfiles-append     cfe-${version}.src${extract.suffix} compiler-rt-${version}.src${extract.suffix} libcxx-${version}.src${extract.suffix} clang-tools-extra-${version}.src${extract.suffix}
    } elseif {${subport} eq "lldb-${llvm_version}"} {
        distfiles-append     cfe-${version}.src${extract.suffix} lldb-${version}.src${extract.suffix}
    }
}

patch.pre_args  -p1
patchfiles \
        0001-Set-the-Mach-O-CPU-Subtype-to-ppc7400-when-targeting.patch \
        0002-Define-EXC_MASK_CRASH-and-MACH_EXCEPTION_CODES-if-th.patch \
        0003-MacPorts-Only-Don-t-embed-the-deployment-target-in-t.patch

if {${subport} eq "clang-${llvm_version}"} {
    patchfiles-append \
        1001-MacPorts-Only-Prepare-clang-format-for-replacement-w.patch \
        1002-MacPorts-Only-Fix-name-of-scan-view-executable-insid.patch \
        1003-Default-to-ppc7400-for-OSX-10.5.patch \
        1004-Only-call-setpriority-PRIO_DARWIN_THREAD-0-PRIO_DARW.patch \
        1005-Default-to-fragile-ObjC-runtime-when-targeting-darwi.patch \
        2001-MacPorts-Only-Don-t-check-for-the-macosx.internal-SD.patch \
        3001-buildit-build-fix-for-Leopard.patch \
        3002-buildit-Set-compatibility-version-to-RC_ProjectSourc.patch \
        3003-Fix-local-and-iterator-when-building-with-Lion-and-n.patch \
        3004-Fix-missing-long-long-math-prototypes-when-using-the.patch \
        3005-implement-atomic-using-mutex-lock_guard-for-64b-ops-.patch \
        openmp-locations.patch

    # https://llvm.org/bugs/show_bug.cgi?id=25681
    if {${worksrcdir} eq "trunk" || ${worksrcdir} eq "release_${llvm_version_no_dot}"} {
        # Cannot set cppflags due to https://cmake.org/Bug/view.php?id=12928
        # Cannot set cxxflags due to https://llvm.org/bugs/show_bug.cgi?id=25904
        #configure.cxxflags-append -DSVN_REVISION='"${svn.revision}"'

        post-patch {
            reinplace "1 i \\                             
                #define SVN_REVISION \"${svn.revision}\"
            " ${worksrcpath}/tools/clang/lib/Basic/Version.cpp
        }
    }
}
if {${subport} eq "lldb-${llvm_version}"} {
    # lldb needs the clang sources present, so we apply the applicable patches.
    patchfiles-append \
        1001-MacPorts-Only-Prepare-clang-format-for-replacement-w.patch \
        1002-MacPorts-Only-Fix-name-of-scan-view-executable-insid.patch \
        1003-Default-to-ppc7400-for-OSX-10.5.patch \
        1004-Only-call-setpriority-PRIO_DARWIN_THREAD-0-PRIO_DARW.patch \
        1005-Default-to-fragile-ObjC-runtime-when-targeting-darwi.patch \
        openmp-locations.patch

    # https://llvm.org/bugs/show_bug.cgi?id=25681
    if {${worksrcdir} eq "trunk" || ${worksrcdir} eq "release_${llvm_version_no_dot}"} {
        # Cannot set cppflags due to https://cmake.org/Bug/view.php?id=12928
        # Cannot set cxxflags due to https://llvm.org/bugs/show_bug.cgi?id=25904
        #configure.cxxflags-append -DSVN_REVISION='"${svn.revision}"'

        post-patch {
            reinplace "1 i \\                             
                #define SVN_REVISION \"${svn.revision}\"
            " ${worksrcpath}/tools/clang/lib/Basic/Version.cpp
        }
    }
}

configure.post_args         ../${worksrcdir}
default configure.dir       {${workpath}/build}
default build.dir           {${workpath}/build}

# https://llvm.org/bugs/show_bug.cgi?id=25664
configure.ldflags-append    -Wl,-rpath,@loader_path

# https://trac.macports.org/ticket/51542
configure.ldflags-append    -Wl,-rpath,@loader_path/

configure.args-append \
    -DLLVM_LINK_LLVM_DYLIB=ON \
    -DCMAKE_INSTALL_PREFIX="${sub_prefix}" \
    -DLLVM_ENABLE_ASSERTIONS=OFF \
    -DLLVM_ENABLE_RTTI=ON \
    -DLLVM_INCLUDE_TESTS=OFF \
    -DLLVM_INCLUDE_EXAMPLES=OFF \
    -DLLVM_ENABLE_FFI=ON \
    -DLLVM_BINDINGS_LIST=none \
    -DFFI_INCLUDE_DIR=${prefix}/include \
    -DFFI_LIBRARY_DIR=${prefix}/lib

if {${subport} eq "llvm-${llvm_version}"} {
    select.group        llvm
    select.file         ${filespath}/mp-${subport}
} elseif {${subport} eq "clang-${llvm_version}"} {
    select.group        clang
    select.file         ${filespath}/mp-${subport}

    configure.args-append \
        -DCLANG_INCLUDE_TESTS=OFF \
        -DCLANG_ENABLE_STATIC_ANALYZER=OFF \
        -DLLVM_BUILD_RUNTIME=ON \
        -DLIBCXX_ENABLE_SHARED=OFF \
        -DLIBCXX_INSTALL_LIBRARY=OFF

    # TODO: libc++ shouldn't be built at all.
    #       https://llvm.org/bugs/show_bug.cgi?id=25666

    if {${os.major} <= 12} {
        # We unfortunately don't have an option to just turn off tsan
        # https://llvm.org/bugs/show_bug.cgi?id=27715
        configure.args-append \
            -DCOMPILER_RT_BUILD_SANITIZERS=OFF
    }
} elseif {${subport} eq "lldb-${llvm_version}"} {
    #select.group        lldb
    #select.file         ${filespath}/mp-${subport}

    configure.args-append \
        -DLLDB_CODESIGN_IDENTITY=- \
        -DCLANG_ENABLE_ARCMT=OFF \
        -DCLANG_INCLUDE_TESTS=OFF \
        -DCLANG_ENABLE_STATIC_ANALYZER=OFF \
        -DLLVM_BUILD_RUNTIME=ON \
        -DLIBCXX_ENABLE_SHARED=OFF \
        -DLIBCXX_INSTALL_LIBRARY=OFF \
        -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7 \
        -DPYTHON_INCLUDE_DIR=${prefix}/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
}

# llvm-3.5 and later requires a C++11 runtime
# XCode 4.3's clang (318.x) fails per https://trac.macports.org/ticket/44161
# XCode 4.5's clang (421.11.66) fails due to http://llvm.org/bugs/show_bug.cgi?id=20184
# Xcode 4.6.3's clang (425.0.28) fails due to http://trac.macports.org/ticket/46897
# Xcode 4.6.3's clang (425.0.28) fails due to https://llvm.org/bugs/show_bug.cgi?id=30384
compiler.blacklist *gcc* {clang < 500}

if {${subport} eq "clang-${llvm_version}"} {
    # Xcode 6.2's clang (600.0.57) fails due to https://llvm.org/bugs/show_bug.cgi?id=25753
    # clang older than 3.5 fail due to https://llvm.org/bugs/show_bug.cgi?id=25753
    compiler.blacklist-append {clang < 602} macports-clang-3.3 macports-clang-3.4
 
    # Remove this when loosening the blacklist above or when a newer base is released
    compiler.fallback-append macports-clang-3.7 macports-clang-3.6 macports-clang-3.5

    # Don't self-host.  We may have issues if we have a slightly newer llvm version that
    # is not binary compatible with the older clang version we're trying to use.

    compiler.blacklist-append macports-clang-${llvm_version}
}

# blacklist current and future versions if they're not available in order to
# help break potential dependency cycles.
foreach ver {devel} {
    if {![file exists ${prefix}/bin/clang-mp-${ver}]} {
        compiler.blacklist-append macports-clang-${ver}
    }
}

platform darwin {
    # Note that we are forcing this choice.  This means that anything linking
    # against llvm-3.5 needs to also be using libc++.  This is possibly
    # problematic, but luckily there is just a limited set of such dependents.

    configure.cxx_stdlib libc++
    depends_lib-append port:libcxx
    supported_archs i386 x86_64

    pre-fetch {
        if {![file exists /usr/lib/libc++.dylib]} {
            ui_error "$name requires a C++11 runtime, which your configuration does not allow"
            error "unsupported configuration"
        }
    }
}

variant universal {
    post-extract {
        # workaround a bug in Apple's shipped gcc driver-driver, patched in
        # ours with driverdriver-num_infiles.patch
        if {${configure.compiler} eq "gcc-4.0" ||
            ${configure.compiler} eq "gcc-4.2" ||
            ${configure.compiler} eq "llvm-gcc-4.2"} {
            system "echo \"static int ___ignoreme;\" > ${worksrcpath}/tools/llvm-shlib/ignore.c"
        }
    }
}

variant assertions description "Enable assertions for error detection (has performance impacts, especially on JIT)" {
    configure.args-delete -DLLVM_ENABLE_ASSERTIONS=OFF
    configure.args-append -DLLVM_ENABLE_ASSERTIONS=ON
}

platform darwin {
    if {[string match "*ppc*" [get_canonical_archs]]} {
        # http://trac.macports.org/ticket/33987
        configure.optflags    -Os
    }

    if {${subport} eq "clang-${llvm_version}" && [vercmp $xcodeversion 5.0] < 0} {
        # https://llvm.org/bugs/show_bug.cgi?id=13671
        patchfiles-append leopard-no-asan.patch
        configure.args-append -DCOMPILER_RT_BUILD_SANITIZERS=OFF
    }

    if {${subport} eq "clang-${llvm_version}" && ${os.major} <= 9} {
        patchfiles-append leopard-no-blocks.patch
    }

    if {${os.major} < 11} {
        # Proxy for eliminating the dependency on native TLS
        # http://trac.macports.org/ticket/46887
        configure.args-append -DLLVM_ENABLE_BACKTRACES=OFF

        # https://llvm.org/bugs/show_bug.cgi?id=25680
        configure.cxxflags-append -U__STRICT_ANSI__
    }

    # https://llvm.org/bugs/show_bug.cgi?id=25674
    configure.cxxflags-append -std=c++11
}

post-extract {
    # Get HTTP proxy arguments if required, assuming we can use the same proxy for all repositories
    set proxy_args [portfetch::svn_proxy_args https://llvm.org/svn/llvm-project/cfe/trunk]
    if {${subport} eq "llvm-${llvm_version}"} {
        if {[variant_isset polly]} {
            if {${worksrcdir} eq "trunk"} {
                system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/polly/trunk polly"
            } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
                system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/polly/branches/release_${llvm_version_no_dot} polly"
            } else {
                file rename ${workpath}/polly-${version}.src ${worksrcpath}/tools/polly
            }
        }
    } elseif {${subport} eq "clang-${llvm_version}"} {
        if {${worksrcdir} eq "trunk"} {
            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/cfe/trunk clang"
            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${compiler_rt_rev} https://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt"
            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${libcxx_rev} https://llvm.org/svn/llvm-project/libcxx/trunk libcxx"
            system -W ${worksrcpath}/tools/clang/tools "svn ${proxy_args} co -r ${clang-modernize_rev} https://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra"
        } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/cfe/branches/release_${llvm_version_no_dot} clang"
            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${compiler_rt_rev} https://llvm.org/svn/llvm-project/compiler-rt/branches/release_${llvm_version_no_dot} compiler-rt"
            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${libcxx_rev} https://llvm.org/svn/llvm-project/libcxx/branches/release_${llvm_version_no_dot} libcxx"
            system -W ${worksrcpath}/tools/clang/tools "svn ${proxy_args} co -r ${clang-modernize_rev} https://llvm.org/svn/llvm-project/clang-tools-extra/branches/release_${llvm_version_no_dot} extra"
        } else {
            file rename ${workpath}/cfe-${version}.src ${worksrcpath}/tools/clang
            file rename ${workpath}/compiler-rt-${version}.src ${worksrcpath}/projects/compiler-rt
            file rename ${workpath}/libcxx-${version}.src ${worksrcpath}/projects/libcxx
            file rename ${workpath}/clang-tools-extra-${version}.src ${worksrcpath}/tools/clang/tools/extra
        }
    } elseif {${subport} eq "lldb-${llvm_version}"} {
        if {${worksrcdir} eq "trunk"} {
            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/cfe/trunk clang"
            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/lldb/trunk lldb"
        } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/cfe/branches/release_${llvm_version_no_dot} clang"
            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} https://llvm.org/svn/llvm-project/lldb/branches/release_${llvm_version_no_dot} lldb"
        } else {
            file rename ${workpath}/cfe-${version}.src ${worksrcpath}/tools/clang
            file rename ${workpath}/lldb-${version}.src ${worksrcpath}/tools/lldb
        }
    }
}

if {${subport} eq "clang-${llvm_version}"} {
    destroot {
        system "cd ${destroot.dir}/tools/clang && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"
        system "cd ${destroot.dir}/projects/compiler-rt && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"
        system "cd ${destroot.dir}/projects/libcxx && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"

        delete ${destroot}${sub_prefix}/bin/clang
        file rename ${destroot}${sub_prefix}/bin/clang-${clang_executable_version} ${destroot}${sub_prefix}/bin/clang
    }
}

if {${subport} eq "lldb-${llvm_version}"} {
    post-patch {
        reinplace "s|@@PREFIX@@|${prefix}|" \
            ${worksrcpath}/tools/clang/lib/Driver/Tools.cpp

        reinplace "s|@CLANG_FORMAT_PATH@|${prefix}/bin/clang-format-${suffix}|g" \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-bbedit.applescript \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-diff.py            \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-sublime.py         \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.el                 \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.py
    }

    build.dir   ${build.dir}/tools/lldb

    destroot {
        destroot.target     install/fast
        system "cd ${destroot.dir} && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"

        foreach bin {lldb lldb-mi lldb-server} {
            delete ${destroot}${sub_prefix}/bin/${bin}
            file rename ${destroot}${sub_prefix}/bin/${bin}-${lldb_executable_version} ${destroot}${sub_prefix}/bin/${bin}
        }

        xinstall -m 755 -d ${destroot}${prefix}/share/doc/lldb-${llvm_version}
        xinstall -m 644 ${worksrcpath}/tools/lldb/docs/code-signing.txt ${destroot}${prefix}/share/doc/lldb-${llvm_version}/
    }
    post-activate {
        ui_msg "Please follow the instructions in ${prefix}/lldb-${llvm_version}/code-signing.txt and then codesign the debugserver with:"
        ui_msg "   sudo codesign --force --deep --preserve-metadata=identifier,entitlements,resource-rules,requirements,flags,team-identifier --sign <identity> ${sub_prefix}/bin/debugserver"
    }
}

post-destroot {
    foreach bin [glob ${destroot}${sub_prefix}/bin/*] {
        set bin_filename [string map "${sub_prefix} ${prefix}" ${bin}]-${suffix}
        set exec_path [string map "${destroot}${sub_prefix} ${sub_prefix}" ${bin}]

        xinstall -m 755 "${filespath}/llvm-bin" "${bin_filename}"
        reinplace "s:EXEC_PATH:${exec_path}:" "${bin_filename}"
    }

    if {${subport} eq "llvm-${llvm_version}"} {
        # r156389 (a5d2435409858728970202226d0bbbee508fe408) temporarilary removed llvm man pages
        #foreach man [glob ${destroot}${sub_prefix}/share/man/man1/*.1] {
        #    set basename [string map "${destroot}${sub_prefix}/share/man/man1/ {}" ${man}]
        #    file rename ${man} ${destroot}${prefix}/share/man/man1/[string map ".1 -${suffix}.1" ${basename}]
        #}

        # https://llvm.org/bugs/show_bug.cgi?id=19465
        if {[variant_isset polly]} {
            ln -s LLVMPolly.so ${destroot}${sub_prefix}/lib/LLVMPolly.dylib
        }
    } elseif {${subport} eq "clang-${llvm_version}"} {
        system "ditto ${worksrcpath}/projects/libcxx/include ${destroot}${sub_prefix}/lib/c++/v1"

        # http://trac.macports.org/ticket/33207
        ln -s ${prefix}/libexec/ld64/ld ${destroot}${sub_prefix}/bin/ld
    } elseif {${subport} eq "lldb-${llvm_version}"} {
        delete ${destroot}${prefix}/bin/debugserver-${suffix}
    }
}

if {${subport} eq "llvm-${llvm_version}"} {
    variant polly description {Provide the polly polyhedral optimizer} {}

    # Unless upstream reverts to their old OCaml detection mechanism,
    # this variant will be broken until #46161 is resolved.
    variant ocaml description {Enable generation of OCaml binding} {
        depends_lib-append   port:ocaml

        configure.args-delete -DLLVM_BINDINGS_LIST=none
        configure.args-append -DLLVM_BINDINGS_LIST=ocaml

        destroot.args-append  OVERRIDE_libdir=${sub_prefix}/lib
    }
} elseif {${subport} eq "clang-${llvm_version}"} {
    if {[variant_isset assertions]} {
        # Need to match llvm +-assertions
        require_active_variants port:llvm-${llvm_version} assertions
    } else {
        # Need to match llvm +-assertions
        require_active_variants port:llvm-${llvm_version} {} assertions
    }

    variant analyzer description {Install clang static analyzer} {
        configure.args-delete \
            -DCLANG_ENABLE_STATIC_ANALYZER=OFF
        configure.args-append \
            -DCLANG_ENABLE_STATIC_ANALYZER=ON

        depends_run-append port:perl5

        post-patch {
            reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
                ${worksrcpath}/tools/clang/tools/scan-build/libexec/ccc-analyzer \
                ${worksrcpath}/tools/clang/tools/scan-build/libexec/c++-analyzer \
                ${worksrcpath}/tools/clang/tools/scan-build/bin/scan-build
            reinplace "s|/usr/bin/env python|${prefix}/bin/python2.7|g" \
                ${worksrcpath}/tools/clang/tools/scan-build/bin/set-xcode-analyzer \
                ${worksrcpath}/tools/clang/tools/scan-view/bin/scan-view
        }
    }

    post-patch {
        reinplace "s|@@PREFIX@@|${prefix}|" \
            ${worksrcpath}/tools/clang/lib/Driver/Tools.cpp

        reinplace "s|@CLANG_FORMAT_PATH@|${prefix}/bin/clang-format-${suffix}|g" \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-bbedit.applescript \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-diff.py            \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-sublime.py         \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.el                 \
            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.py
    }

    post-destroot {
        file mkdir ${destroot}${sub_prefix}/libexec
        file copy ${worksrcpath}/tools/clang/tools/clang-format ${destroot}${sub_prefix}/libexec/clang-format

        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/.svn
        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Makefile
        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Release+Debug+Asserts
        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/CMakeLists.txt
        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/ClangFormat.cpp
    }
}

livecheck.type          none