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

PortSystem 1.0

name                cgit
version             1.2.3
revision            2

# See Makefile GIT_VER
set git_version     2.25.1

categories          www devel
platforms           darwin
license             GPL-2
maintainers         nomaintainer

description         A hyperfast web frontend for git repositories written in C.
long_description    cgit is an attempt to create a fast web interface for the Git SCM \
                    (Source Code Management) using a builtin cache to decrease server \
                    io-pressure. It can run on any CGI-capable web server.

homepage            https://git.zx2c4.com/cgit/
master_sites        ${homepage}snapshot:cgit \
                    https://www.kernel.org/pub/software/scm/git:git

dist_subdir         git
use_xz              yes

set cgit_distfile   ${distfiles}
set git_distname    git-${git_version}
set git_distfile    ${git_distname}${extract.suffix}
distfiles           ${cgit_distfile}:cgit ${git_distfile}:git

checksums           ${cgit_distfile} \
                    rmd160  4884b999302eb89afa67c73f07e8853f9402e681 \
                    sha256  5a5f12d2f66bd3629c8bc103ec8ec2301b292e97155d30a9a61884ea414a6da4 \
                    size    90632 \
                    ${git_distfile} \
                    rmd160  a8ab476982440c2cc94c7d21f619320d74f117d2 \
                    sha256  222796cc6e3bf2f9fd765f8f097daa3c3999bb7865ac88a8c974d98182e29f26 \
                    size    5875548

# Patch for memrch: https://trac.macports.org/ticket/60967
patchfiles          patch-add-memrchr.diff \
                    patch-config-mak-uname.diff

depends_lib         port:libiconv \
                    port:zlib

depends_run         path:lib/libssl.dylib:openssl \
                    port:bzip2 \
                    port:git \
                    port:lzip \
                    port:xz \
                    port:zstd

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
    reinplace "s|@GIT_URL@|file://${distpath}/${git_distfile}|g" ${worksrcpath}/cgit.conf
}

set user_group  [expr {${os.platform} eq "darwin" && ${os.major} <= 8 ? "www" : "_www"}]
set user        ${user_group}
set group       ${user_group}

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      prefix=${prefix} \
                CC="${configure.cc} [get_canonical_archflags cc]" \
                NO_GETTEXT=1 \
                NO_LUA=1 \
                V=1
build.env       CFLAGS=${configure.cflags} \
                LDFLAGS=${configure.ldflags}

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

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

notes "
A sample config file have been placed in:
  » ${prefix}/etc/cgitrc.sample
"
