# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=portfile:et:sw=4:ts=4:sts=4
# $Id$

PortSystem          1.0
PortGroup           github 1.0

github.setup        rust-lang cargo 0.11.0
categories          devel
platforms           darwin

universal_variant   no
license             {MIT Apache-2}
maintainers         sean openmaintainer

description         The Rust package manager
long_description    Cargo downloads your Rust project’s dependencies and compiles your project.
homepage            http://crates.io

# Fetch from git instead of distfile because it needs submodules
fetch.type          git

depends_lib         port:rust \
                    port:pkgconfig
depends_build       bin:python2.6:python27 \
                    bin:cmake:cmake \
                    port:cctools \
                    port:gawk

depends_skip_archcheck  python27

build.type          gnu

# the DYLD_FALLBACK_LIBRARY_PATH is ugly but currently the only way to have
# rust find the libraries installed via rpath; using install_name_tool wouldn't
# help in this situation because rust and cargo both download binaries to
# bootstrap themselves. Since this is just a build argument, I think it's fine
# for now.
build.args          VERBOSE=1 \
                    CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP="${configure.cc} -E" \
                    DYLD_FALLBACK_LIBRARY_PATH="${prefix}/lib"

destroot.args       VERBOSE=1

post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

post-destroot {
    move ${destroot}${prefix}/lib/rustlib/components ${destroot}${prefix}/lib/rustlib/components-cargo
    file delete ${destroot}${prefix}/lib/rustlib/install.log
    file delete ${destroot}${prefix}/lib/rustlib/uninstall.sh
    file delete ${destroot}${prefix}/lib/rustlib/rust-installer-version

    # move bash-completion file to new location for on-demand loading
    xinstall -d -m 0755 ${destroot}${prefix}/share/bash-completion/completions
    move ${destroot}${prefix}/etc/bash_completion.d/cargo ${destroot}${prefix}/share/bash-completion/completions/cargo
}