##
##  rrdtool.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_rrdtool          1.7.0
%define       V_rrdtool_oo       0.36
%define       V_rrdtool_creator  1.0
%define       V_rrd_simple       1.44

#   package information
Name:         rrdtool
Summary:      Round Robin Database
URL:          http://www.rrdtool.org/
Vendor:       Tobias Oetiker
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Database
License:      LGPL
Version:      %{V_rrdtool}
Release:      20170516

#   package options
%option       with_perl        no
%option       with_python      no

#   list of sources
Source0:      http://oss.oetiker.ch/rrdtool/pub/rrdtool-%{V_rrdtool}.tar.gz
Source1:      http://www.cpan.org/authors/id/M/MS/MSCHILLI/RRDTool-OO-%{V_rrdtool_oo}.tar.gz
Source2:      http://www.cpan.org/authors/id/J/JA/JACQUELIN/RRDTool-Creator-%{V_rrdtool_creator}.tar.gz
Source3:      http://www.cpan.org/authors/id/N/NI/NICOLAW/RRD-Simple-%{V_rrd_simple}.tar.gz
Patch0:       rrdtool.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make, pkgconfig, perl-openpkg >= 5.8.3-20040126, perl-module, intltool
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  png, zlib, freetype, pango, cairo, libxml
PreReq:       png, zlib, freetype, pango, cairo, libxml
%if "%{with_perl}" == "yes"
BuildPreReq:  perl
PreReq:       perl
%endif
%if "%{with_python}" == "yes"
BuildPreReq:  python
PreReq:       python
%endif

%description
    RRD is the Acronym for Round Robin Database. RRD is a system
    to store and display time-series data (i.e. network bandwidth,
    machine-room temperature, server load average). It stores the
    data in a very compact way that will not expand over time, and it
    presents useful graphs by processing the data to enforce a certain
    data density. It can be used either via simple wrapper scripts (from
    shell or Perl) or via frontends that poll network devices and put a
    friendly user interface on it.

%track
    prog rrdtool = {
        version   = %{V_rrdtool}
        url       = http://oss.oetiker.ch/rrdtool/pub/
        regex     = rrdtool-(__VER__)\.tar\.gz
    }
    prog rrdtool:RRDTool-OO = {
        version   = %{V_rrdtool_oo}
        url       = http://www.cpan.org/authors/id/M/MS/MSCHILLI/
        regex     = RRDTool-OO-(__VER__)\.tar\.gz
    }
    prog rrdtool:RRDTool-Creator = {
        version   = %{V_rrdtool_creator}
        url       = http://www.cpan.org/authors/id/J/JA/JACQUELIN/
        regex     = RRDTool-Creator-(__VER__)\.tar\.gz
    }
    prog rrdtool:RRD-Simple = {
        version   = %{V_rrd_simple}
        url       = http://www.cpan.org/authors/id/N/NI/NICOLAW/
        regex     = RRD-Simple-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -D -T -a 1
    %setup -q -D -T -a 2
    %setup -q -D -T -a 3
    %patch -p0
    rm -f bindings/perl-shared/ntmake.pl
    rm -rf RRDTool-Creator-*/_build

%build
    #   configure package
    echo "ac_cv_path_PERL=no" >config.cache
    CC="%{l_cc}" \
    CPPFLAGS="%{l_cppflags cairo .}" \
    CFLAGS="%{l_cflags -O}" \
    LDLAGS="%{l_ldflags}" \
    LIBS="`pkg-config pangocairo --libs`" \
    ./configure \
        --cache-file=./config.cache \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
%if "%{with_python}" == "yes"
        --enable-python \
%else
        --disable-python \
%endif
        --disable-tcl \
        --disable-ruby \
        --disable-shared \
        --disable-nls \
        --enable-rrdcgi

    #   build package
    %{l_make} %{l_mflags}

    #   build Perl part
%if "%{with_perl}" == "yes"
    export TOP_SRCDIR=`pwd`
    export TOP_BUILDDIR=`pwd`
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_prefix}/bin/perl-openpkg -d bindings/perl-piped  configure build
    %{l_prefix}/bin/perl-openpkg -d bindings/perl-shared configure build
    %{l_prefix}/bin/perl-openpkg -d RRDTool-OO-%{V_rrdtool_oo} configure build
    %{l_prefix}/bin/perl-openpkg -d RRDTool-Creator-%{V_rrdtool_creator} configure build
    %{l_prefix}/bin/perl-openpkg -d RRD-Simple-%{V_rrd_simple} configure build
%endif

%install

    #   install package
    %{l_shtool} subst \
        -e 's/^\(install-data-am:\).*/\1/' \
        Makefile
    %{l_make} %{l_mflags} install \
        DESTDIR=$RPM_BUILD_ROOT AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   install Perl part
%if "%{with_perl}" == "yes"
    export TOP_SRCDIR=`pwd`
    export TOP_BUILDDIR=`pwd`
    %{l_prefix}/bin/perl-openpkg -d bindings/perl-piped  install
    %{l_prefix}/bin/perl-openpkg -d bindings/perl-shared install
    %{l_prefix}/bin/perl-openpkg -d RRDTool-OO-%{V_rrdtool_oo} install
    %{l_prefix}/bin/perl-openpkg -d RRDTool-Creator-%{V_rrdtool_creator} install
    %{l_prefix}/bin/perl-openpkg -d RRD-Simple-%{V_rrd_simple} install
%endif

    #   strip down installation hierarchy
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
%if "%{with_python}" == "no"
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/python
%endif
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/rrdtool-*
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/rrdtutorial.es.1
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true

    #   post-process Perl part
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

