##
##  trafficserver.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:         trafficserver
Summary:      Apache Traffic Server
URL:          http://trafficserver.apache.org/
Vendor:       Yahoo!, Apache Software Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      ASL
Version:      3.2.0
Release:      20120622

#   list of sources
Source0:      http://www.apache.org/dist/trafficserver/trafficserver-%{version}.tar.bz2
Source1:      rc.trafficserver
Patch0:       trafficserver.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  libiconv, libexecinfo, openssl, zlib, expat, xz, pcre, tcl
PreReq:       libiconv, libexecinfo, openssl, zlib, expat, xz, pcre, tcl

%description
    Apache Traffic Server is a fast, scalable and extensible HTTP/1.1
    compliant caching and reverse proxy server, originally developed at
    Yahoo!

%track
    prog trafficserver = {
        version   = %{version}
        url       = http://www.apache.org/dist/trafficserver/
        regex     = trafficserver-(__VER__)\.tar\.bz2
    }

%prep
    %setup -q
    %patch -p0

%build
    #   configure program
    %{l_shtool} subst \
        -e 's;-Wall;;' -e 's;-Werror;;' -e 's;-O3;;' \
        configure
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-lm" \
    ./configure \
        --cache-file=./config.cache \
        --prefix=%{l_prefix} \
        --with-openssl=%{l_prefix} \
        --with-zlib=%{l_prefix} \
        --with-lzma=%{l_prefix} \
        --with-expat=%{l_prefix} \
        --with-pcre=%{l_prefix} \
        --with-tcl=%{l_prefix}/lib

    #   build program
    %{l_make} %{l_mflags}

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

    #   install run-command script
    %{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.trafficserver} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

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

%files -f files

%clean

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

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

