# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 80547 2011-07-14 16:06:50Z jmr@macports.org $

PortSystem        1.0

name              git-core
version           1.7.6
description       A fast version control system
long_description  Git is a fast, scalable, distributed open source version \
                  control system focusing on speed and efficiency.
maintainers       gmail.com:maccheck openmaintainer
categories        devel
license           GPL-2 LGPL-2.1+
platforms         darwin
homepage          http://git-scm.com
use_bzip2         yes
master_sites      http://www.kernel.org/pub/software/scm/git/
distname          git-${version}
distfiles         git-${version}${extract.suffix} \
                  git-manpages-${version}${extract.suffix}

checksums           git-${version}${extract.suffix} \
                    sha1    c519b0765c419c84b561bb4a2a86526b16d95cde \
                    rmd160  9ba5daa7bf56b6a242b3302e12c8ced7d3abc77a \
                    git-manpages-${version}${extract.suffix} \
                    sha1    45e0759597d649b13f684f55a186d46dafb7d414 \
                    rmd160  9534cf6540c3be85c6f3b5dfca8ca0cf3f2f366f

depends_run  port:rsync port:p5-error
depends_lib  path:bin/perl:perl5 port:curl port:zlib port:openssl port:expat port:libiconv

patchfiles   patch-Makefile.diff

extract.only   git-${version}${extract.suffix} \
               git-manpages-${version}${extract.suffix}

use_configure  no

set CFLAGS     "-Wall -O2 -I${prefix}/include"
set LDFLAGS    "-L${prefix}/lib"

variant universal {}
if {[variant_isset universal]} {
    set CFLAGS "${CFLAGS} ${configure.universal_cflags}"
    set LDFLAGS "${LDFLAGS} ${configure.universal_ldflags}"
} else {
    set CFLAGS "${CFLAGS} ${configure.cc_archflags}"
    set LDFLAGS "${LDFLAGS} ${configure.ld_archflags}"
}

build.args     CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
               CC=${configure.cc} \
               prefix=${prefix} CURLDIR=${prefix} OPENSSLDIR=${prefix} ICONVDIR=${prefix} \
               PERL_PATH="${prefix}/bin/perl" NO_FINK=1 NO_DARWIN_PORTS=1 \
               NO_R_TO_GCC_LINKER=1

test.run       yes
test.cmd       make
test.target    test
test.dir       ${worksrcpath}
test.args      CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
               CC=${configure.cc} \
               prefix=${prefix} CURLDIR=${prefix} OPENSSLDIR=${prefix} ICONVDIR=${prefix} \
               PERL_PATH="${prefix}/bin/perl" NO_FINK=1 NO_DARWIN_PORTS=1 \
               NO_R_TO_GCC_LINKER=1

destroot.target   install
destroot.args     CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
                  CC=${configure.cc} \
                  prefix=${prefix} CURLDIR=${prefix} OPENSSLDIR=${prefix} ICONVDIR=${prefix} \
                  PERL_PATH="${prefix}/bin/perl" NO_FINK=1 NO_DARWIN_PORTS=1 \
                  NO_R_TO_GCC_LINKER=1

post-destroot {
    foreach f {1 5 7} {
        xinstall -d ${destroot}${prefix}/share/man/man${f}
        foreach m [glob -directory ${workpath} man${f}/*.${f}] {
            xinstall ${m} ${destroot}${prefix}/share/man/man${f}
        }
    }
    if {![variant_isset svn]} {
        system "rm ${destroot}${prefix}/libexec/git-core/git-svn*"
    }
    set docdestroot ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdestroot}
    if {[variant_isset doc]} {
        system "cd ${docdestroot} && ${extract.cmd} ${extract.pre_args} \
            ${distpath}/git-htmldocs-${version}${extract.suffix} \
            ${extract.post_args}"
    }

    file copy ${worksrcpath}/contrib ${docdestroot}

    foreach badfile [exec find ${destroot} -name perllocal.pod] {
        ui_info "Removing ${badfile}"
        file delete ${badfile}
    }
}

if {![variant_isset python26] && ![variant_isset python27]} {
    default_variants    +python27
}

variant python26 conflicts python27 description {Use Python 2.6} {
    build.args-append       PYTHON_PATH="${prefix}/bin/python2.6"
    destroot.args-append    PYTHON_PATH="${prefix}/bin/python2.6"
    test.args-append        PYTHON_PATH="${prefix}/bin/python2.6"
    depends_lib-append      port:python26
}

variant python27 conflicts python26 description {Use Python 2.7} {
    build.args-append       PYTHON_PATH="${prefix}/bin/python2.7"
    destroot.args-append    PYTHON_PATH="${prefix}/bin/python2.7"
    test.args-append        PYTHON_PATH="${prefix}/bin/python2.7"
    depends_lib-append      port:python27
}

variant doc description {Install HTML and plaintext documentation} {
    distfiles-append    git-htmldocs-${version}${extract.suffix}
    checksums-append    git-htmldocs-${version}${extract.suffix} \
                    sha1    926168673669d7568b94af6dec35b9ef10ecaedc \
                    rmd160  0c396a95126670a67c3e61ea69196508b88ef195
}

variant gitweb description {Install gitweb.cgi} {
    build.target-append        gitweb/gitweb.cgi

    post-destroot {
        xinstall -d ${destroot}${prefix}/share/${name}/gitweb
        xinstall -W ${worksrcpath}/gitweb \
            gitweb.cgi \
            ${destroot}${prefix}/share/${name}/gitweb
        xinstall -m 444 -W ${worksrcpath}/gitweb/static \
            gitweb.css \
            gitweb.js \
            git-favicon.png \
            git-logo.png \
            ${destroot}${prefix}/share/${name}/gitweb
        xinstall -d ${destroot}${prefix}/share/doc/${name}/gitweb
        xinstall -m 444 -W ${worksrcpath}/gitweb README INSTALL \
            ${destroot}${prefix}/share/doc/${name}/gitweb
    }
}

variant svn description {Bi-directional subversion repository support} {
    depends_run-append  port:subversion port:p5-libwww-perl port:p5-svn-simple port:p5-term-readkey
}

variant bash_completion {
    depends_run-append  port:bash-completion

    post-destroot {
        xinstall -d ${destroot}${prefix}/etc/bash_completion.d
        xinstall -m 644 ${worksrcpath}/contrib/completion/git-completion.bash \
            ${destroot}${prefix}/etc/bash_completion.d/git
    }
}

default_variants    +doc

livecheck.type          regex
livecheck.regex         {<div id="ver">v([0-9.]+)}
