##
##  apache-perl.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:         apache-perl
Summary:      Apache Extension: Perl Scripting Language
URL:          http://perl.apache.org/
Vendor:       Doug MacEachern & Stas Bekman et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Web
License:      Artistic/GPL
Version:      2.0.13
Release:      20231023

#   list of sources
Source0:      http://www.cpan.org/authors/id/S/SH/SHAY/mod_perl-%{version}.tar.gz
Source1:      apache-perl.pl
Source2:      apache-perl.conf

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, perl-openpkg
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  apache, perl
PreReq:       apache, perl

%description
    mod_perl brings together the full power of the Perl programming
    language and the Apache HTTP server. You can use Perl to manage
    Apache, respond to requests for web pages and much more. mod_perl
    is more than CGI scripting on steroids. It is a whole new way to
    create dynamic content by utilizing the full power of the Apache web
    server to create stateful sessions, customized user authentication
    systems, smart proxies and much more. Yet, magically, your old
    CGI scripts will continue to work and work very fast indeed. With
    mod_perl you give up nothing and gain so much! mod_perl gives you
    a persistent Perl interpreter embedded in your web server. This
    lets you avoid the overhead of starting an external interpreter and
    avoids the penalty of Perl start-up time, giving you super-fast
    dynamic content.

%track
    prog apache-perl:mod_perl = {
        version   = %{version}
        url       = http://search.cpan.org/dist/mod_perl/
        regex     = mod_perl-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n mod_perl-%{version}

%build
    #   configure toolkit
    eval `%{l_prefix}/bin/perl -V:archname`
    eval `%{l_prefix}/bin/perl -V:version`
    eval `%{l_prefix}/bin/perl -V:installarchlib -V:installprivlib -V:installsitearch -V:installsitelib`
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/bin
    perl=$RPM_BUILD_ROOT%{l_prefix}/bin/perl
    echo "#!/bin/sh" >$perl
    echo "exec %{l_prefix}/bin/perl \\" >>$perl
    echo " -I${RPM_BUILD_ROOT}${installarchlib}  \\" >>$perl
    echo " -I${RPM_BUILD_ROOT}${installprivlib}  \\" >>$perl
    echo " -I${RPM_BUILD_ROOT}${installsitearch} \\" >>$perl
    echo " -I${RPM_BUILD_ROOT}${installsitelib}  \\" >>$perl
    echo " \"\$@\"" >>$perl
    chmod a+x $perl
    $perl Makefile.PL \
        MP_APXS="%{l_prefix}/sbin/apxs" \
        MP_APR_CONFIG="%{l_prefix}/bin/apr-1-config" \
        MP_COMPAT_1X=1 \
        MP_PROMPT_DEFAULT=1 \
        MP_USE_DSO=1 \
        MP_USE_STATIC=0 \
        MP_CCOPTS="%{l_cflags -O}" \
        INSTALLDIRS=vendor

    #   build toolkit
    %{l_make} %{l_mflags}

%install
    #   install toolkit
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_make} %{l_mflags} install DESTDIR="$RPM_BUILD_ROOT"
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup

    #   strip down installation
    rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/mp2bug
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/man3

    #   install default configuration file
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apache/apache.d
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE apache-perl.pl} $RPM_BUILD_ROOT%{l_prefix}/etc/apache/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE apache-perl.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/apache/apache.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files` \
        '%config %{l_prefix}/etc/apache/apache-perl.pl' \
        '%config %{l_prefix}/etc/apache/apache.d/apache-perl.conf'

%files -f files

%clean

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

