##
##  statsite.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 version
%define       V_release  0.8.0
%define       V_snapshot 20190712

#   package information
Name:         statsite
Summary:      Statistics Aggregator
URL:          http://armon.github.io/statsite
Vendor:       Armon Dadgar
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      BSD
Version:      %{V_release}.%{V_snapshot}
Release:      20190712

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/statsite/statsite-%{V_snapshot}.tar.xz
Source1:      statsite.ini
Source2:      statsite-influxdb.ini
Source3:      fsl.statsite
Source4:      rc.statsite
Patch0:       statsite.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, autoconf, automake, libtool
PreReq:       OpenPKG, openpkg >= 20160101

%description
    Statsite is a metrics aggregation server. Statsite is based heavily
    on the popular StatsD, and is wire compatible with it.

%track
    prog statsite:release = {
        version   = %{V_release}
        url       = https://github.com/armon/statsite/releases
        regex     = v(__VER__)\.tar\.gz
    }
    prog statsite:snapshot = {
        version   = %{V_snapshot}
        url       = http://download.openpkg.org/components/versioned/statsite/
        regex     = statsite-(__VER__)\.tar\.xz
    }

%prep
    %setup -q -n statsite
    %patch -p0

%build
    #   configure program
    sh autogen.sh
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
    LIBS="%{l_fsl_libs}" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --disable-shared

    #   build program
    %{l_make} %{l_mflags -O}

%install
    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   strip down installation
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   install default configurations
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/statsite
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE statsite.ini} \
        %{SOURCE statsite-influxdb.ini} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/statsite/

    #   install OSSP fsl configuration
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.statsite} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    #   install run-command configuration
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.statsite} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   create run-time directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/statsite/log \
        $RPM_BUILD_ROOT%{l_prefix}/var/statsite/run

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/statsite/*' \
        '%config %{l_prefix}/etc/fsl/*' \
        '%attr(755,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/statsite'

%files -f files

%clean

