##
##  icecast.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:         icecast
Summary:      Multimedia Server
URL:          http://www.icecast.org/
Vendor:       Jack Moffitt, Michael Smith, Karl Heyes
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Audio
License:      GPL
Version:      2.4.4
Release:      20181101

#   list of sources
Source0:      http://downloads.xiph.org/releases/icecast/icecast-%{version}.tar.gz
Source1:      icecast.xml
Source2:      rc.icecast

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  libxml, libxslt, vorbis-libs, speex, curl, openssl, theora
PreReq:       libxml, libxslt, vorbis-libs, speex, curl, openssl, theora

%description
    Icecast is a server software for streaming multimedia data (audio
    and video) over the network.

%track
    prog icecast = {
        version   = %{version}
        url       = http://www.icecast.org/download.php
        regex     = icecast-(__VER__)\.tar\.gz
    }

%prep
    %setup -q

%build
    #   configure program
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/icecast \
        --with-xslt-config=%{l_prefix}/bin/xslt-config \
        --with-theora=%{l_prefix} \
        --with-ogg=%{l_prefix} \
        --with-vorbis=%{l_prefix} \
        --with-speex=%{l_prefix} \
        --with-curl=%{l_prefix} \
        --with-openssl=%{l_prefix}

    #   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
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc >/dev/null 2>&1 || true
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/icecast/doc >/dev/null 2>&1 || true

    #   install default configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE icecast.xml} $RPM_BUILD_ROOT%{l_prefix}/etc/icecast/

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

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

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

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} icecast status 2>/dev/null`
    [ ".$icecast_active" = .yes ] && %{l_rc} icecast restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} icecast stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/icecast/* >/dev/null 2>&1 || true
    exit 0

