# -*- mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# $Id: Portfile 98328 2012-10-03 01:31:44Z ryandesign@macports.org $

PortSystem 1.0

name            cgit
version         0.9.0.3
set git_version 1.7.4
categories      www devel
maintainers     sfiera openmaintainer
description     A fast web interface for the git source code management system
homepage        http://hjemli.net/git/cgit/
platforms       darwin
dist_subdir     git-core

long_description \
    cgit is an attempt to create a fast web interface for the git scm, using a \
    builtin cache to decrease server io-pressure. It can run on any \
    CGI-capable web server.

use_bzip2       yes
set cgit_distfile   ${distfiles}
set git_distname    git-${git_version}
set git_distfile    [suffix ${git_distname}]
distfiles       ${cgit_distfile}:cgit ${git_distfile}:git
master_sites    ${homepage}snapshot:cgit \
                http://www.kernel.org/pub/software/scm/git:git
checksums       ${cgit_distfile} \
                    rmd160  a426468889aff48a19849acd01c9660b37cb0c0f \
                    sha256  53ccf0c826f91c2184ec29b1b9ab8a6f42e0ef2e6fa9042c3759e2a2dc81baa5 \
                ${git_distfile} \
                    rmd160  a064d7a5b2d3fae6171ca91a03082eb46d7bb9b7 \
                    sha256  8e260b9e5dfb46a35f26e3db450c2dabb4d1df254bfb2820779945a1ecbcef51

depends_lib     port:git-core \
                port:openssl \
                port:zlib \
                port:libiconv

post-extract {
    delete ${worksrcpath}/git
    move ${workpath}/${git_distname} ${worksrcpath}/git
}

post-patch {
    file copy ${filespath}/cgit.conf ${worksrcpath}/cgit.conf
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/cgit.conf
    reinplace "s|@GIT_VER@|${git_version}|g" ${worksrcpath}/cgit.conf
}

set user _www
set group _www

if {${os.platform} == "darwin" && ${os.major} <= 8} {
    set user www
    set group www
}

post-destroot {
    xinstall -m 444 ${worksrcpath}/cgitrc.5.txt ${destroot}${prefix}/etc/cgitrc.sample
    xinstall -m 700 -o ${user} -g ${group} -d ${destroot}${prefix}/var/cache/cgit
    destroot.keepdirs ${destroot}${prefix}/var/cache/cgit
}

use_configure   no
variant universal {}
configure.ldflags-append -liconv

build.args      CC="${configure.cc} [get_canonical_archflags cc]"
build.env       CFLAGS="${configure.cflags}" \
                LDFLAGS="${configure.ldflags}"

eval destroot.args ${build.args}
eval destroot.env ${build.env}

livecheck.type  regex
livecheck.url   ${homepage}log/?h=stable
livecheck.regex {>v([0-9.]+)<}
