##
##  cgit.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         cgit
Summary:      Git Repository Web Frontend
URL:          http://hjemli.net/git/cgit/
Vendor:       Lars Hjemli
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        SCM
License:      GPL
Version:      0.9.0.3
Release:      20120319

#   list of sources
Source0:      http://hjemli.net/git/cgit/snapshot/cgit-%{version}.tar.gz
Source1:      cgitrc
Source2:      cgit.conf
Source3:      cgit.passwd
Source4:      cgit.groups
Patch0:       cgit.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  git, openssl, libiconv, zlib
PreReq:       git, openssl, libiconv, zlib

%description
    CGit is a CGI-based web frontend to the Git distributed version
    control system.

%track
    prog cgit = {
        version   = %{version}
        url       = http://hjemli.net/git/cgit/refs/tags
        regex     = cgit-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;#!/bin/sh;#!%{l_bash};g' \
        -e 's;exec highlight;exec %{l_prefix}/bin/highlight;g' \
        filters/syntax-highlighting.sh
    %{l_make} %{l_mflags} \
        CC="%{l_cc} %{l_cflags -O} %{l_cppflags git .} '-DSHA1_HEADER=<openssl/sha.h>'" \
        EXTLIBS="%{l_ldflags} -lgit -lgit-xdiff -liconv -lcrypto -lz" \
        prefix=%{l_prefix} \
        CGIT_SCRIPT_PATH=%{l_prefix}/cgi \
        CGIT_DATA_PATH=%{l_prefix}/share/cgit \
        CGIT_CONFIG=%{l_prefix}/etc/cgit/cgitrc \
        CACHE_ROOT=%{l_prefix}/var/cgit/cache

%install
    %{l_make} %{l_mflags} install \
        DESTDIR=$RPM_BUILD_ROOT \
        prefix=%{l_prefix} \
        CGIT_SCRIPT_PATH=%{l_prefix}/cgi \
        CGIT_DATA_PATH=%{l_prefix}/share/cgit \
        CGIT_CONFIG=%{l_prefix}/etc/cgit/cgitrc \
        CACHE_ROOT=%{l_prefix}/var/cgit/cache
    strip $RPM_BUILD_ROOT%{l_prefix}/cgi/* >/dev/null 2>&1 || true
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/cgit \
        $RPM_BUILD_ROOT%{l_prefix}/var/cgit/cache \
        $RPM_BUILD_ROOT%{l_prefix}/var/cgit/repo \
        $RPM_BUILD_ROOT%{l_prefix}/man/cat5
    %{l_shtool} install -c -m 644 \
        cgitrc.5.txt $RPM_BUILD_ROOT%{l_prefix}/man/cat5/cgitrc.5
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE cgitrc} $RPM_BUILD_ROOT%{l_prefix}/etc/cgit/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE cgit.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/cgit/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE cgit.passwd} $RPM_BUILD_ROOT%{l_prefix}/etc/cgit/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE cgit.groups} $RPM_BUILD_ROOT%{l_prefix}/etc/cgit/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/cgit/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/cgit' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/cgit/*'

%files -f files

%clean

