##
##  analog.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:         analog
Summary:      Website Logfile Analysing and Reporting
URL:          http://www.analog.cx/
Vendor:       Stephen Turner
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Logfile
License:      GPL
Version:      6.0
Release:      20160305

#   list of sources
Source0:      http://www.analog.cx/analog-%{version}.tar.gz
Patch0:       analog.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  gd, png, jpeg, zlib, pcre
PreReq:       gd, png, jpeg, zlib, pcre

%description
    Analog is a program to measure the usage on your web server. It
    tells you which pages are most popular, which countries people are
    visiting from, which sites they tried to follow broken links from,
    and all sorts of other useful information.

%track
    prog analog = {
        disabled
        comment   = "domain no longer exists"
        version   = %{version}
        url       = http://www.analog.cx/download.html
        regex     = analog-(\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0
    %{l_shtool} subst \
        -e 's;^\(#define CONFIGDIR \).*$;\1"%{l_prefix}/etc/analog/";' \
        -e 's;^\(#define LANGDIR \).*$;\1"%{l_prefix}/share/analog/lang/";' \
        -e 's;^\(#define LOGSDIR \).*$;\1"/tmp/";' \
        -e 's;^\(#define CACHEDIR \).*$;\1"/tmp/";' \
        -e 's;^\(#define OUTDIR \).*$;\1"/tmp/";' \
        -e 's;^\(#define HEADERDIR \).*$;\1"/tmp/";' \
        -e 's;^\(#define DNSDIR \).*$;\1"/tmp/";' \
        -e 's;^\(#define LOCKDIR \).*$;\1"/tmp/";' \
        -e 's;^\(#define ERRDIR \).*$;\1"/tmp/";' \
        src/anlghead.h

%build
    cd src
    libs="-lgd -lpng -ljpeg -lz -lpcre -lm"
    case "%{l_platform -t}" in
        *-sunos5* ) libs="-lnsl $libs" ;;
    esac
    %{l_make} %{l_mflags} \
        CC="%{l_cc}" \
        CFLAGS='%{l_cflags -O} %{l_cppflags} %{l_ldflags} -DDEFAULTCONFIGFILE=\"%{l_prefix}/etc/analog/analog.cfg\"' \
        DEFS="-DHAVE_GD -DHAVE_ZLIB -DHAVE_PCRE" \
        LIBS="$libs"

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/analog \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/share/analog/image \
        $RPM_BUILD_ROOT%{l_prefix}/share/analog/lang
    %{l_shtool} install -c -s -m 755 \
        analog $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -m 644 \
        -e 's;^# LANGFILE uk.lng;LANGFILE %{l_prefix}/share/analog/lang/uk.lng;' \
        -e 's;^# DOMAINSFILE ukdom.tab;DOMAINSFILE %{l_prefix}/share/analog/lang/ukdom.tab;' \
        -e 's;^# DESCFILE ukdesc.txt;DESCFILE %{l_prefix}/share/analog/lang/ukdesc.txt;' \
        examples/big.cfg $RPM_BUILD_ROOT%{l_prefix}/etc/analog/analog.cfg
    %{l_shtool} install -c -m 644 \
        analog.man $RPM_BUILD_ROOT%{l_prefix}/man/man1/analog.1
    %{l_shtool} install -c -m 644 \
        images/* $RPM_BUILD_ROOT%{l_prefix}/share/analog/image/
    %{l_shtool} install -c -m 644 \
        lang/* $RPM_BUILD_ROOT%{l_prefix}/share/analog/lang/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/analog/analog.cfg'

%files -f files

%clean

