##
##  perl-kerberos.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.
##

#   versions of individual parts
%define       V_perl                     5.22
%define       V_authen_krb5              1.9
%define       V_authen_krb5_admin        0.11
%define       V_authen_krb5_simple       0.43
%define       V_authen_krb5_easy         0.90
%define       V_authen_krb5password      1.03

#   package information
Name:         perl-kerberos
Summary:      Perl Modules for use with MIT Kerberos
URL:          http://www.cpan.org/
Vendor:       Perl Community
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Perl
License:      GPL/Artistic
Version:      %{V_perl}
Release:      20150603

#   list of sources
Source0:      http://www.cpan.org/authors/id/J/JH/JHORWITZ/Krb5-%{V_authen_krb5}.tar.gz
Source1:      http://www.cpan.org/authors/id/K/KO/KORTY/Authen-Krb5-Admin-%{V_authen_krb5_admin}.tar.gz
Source2:      http://www.cpan.org/authors/id/D/DS/DSTUART/Authen-Krb5-Simple-%{V_authen_krb5_simple}.tar.gz
Source3:      http://www.cpan.org/authors/id/S/SC/SCHALLEE/Authen-Krb5-Easy-%{V_authen_krb5_easy}.tar.gz
Source4:      http://www.cpan.org/authors/id/S/SH/SHUQUE/Authen-Krb5Password-%{V_authen_krb5password}.tar.gz
Patch0:       perl-kerberos.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, perl >= %{V_perl}, perl-openpkg >= %{V_perl}
PreReq:       OpenPKG, openpkg >= 20160101, perl >= %{V_perl}
BuildPreReq:  kerberos
PreReq:       kerberos

%description
    Perl modules for use with MIT Kerberos:
    - Authen::Krb5 (%{V_authen_krb5})
    - Authen::Krb5::Admin (%{V_authen_krb5_admin})
    - Authen::Krb5::Simple (%{V_authen_krb5_simple})
    - Authen::Krb5::Easy (%{V_authen_krb5_easy})
    - Authen::Krb5Password (%{V_authen_krb5password})

%track
    prog perl-kerberos:Authen-Krb5 = {
        version   = %{V_authen_krb5}
        url       = http://www.cpan.org/authors/id/J/JH/JHORWITZ/
        regex     = Krb5-(__VER__)\.tar\.gz
    }
    prog perl-kerberos:Authen-Krb5-Admin = {
        version   = %{V_authen_krb5_admin}
        url       = http://www.cpan.org/authors/id/K/KO/KORTY/
        regex     = Authen-Krb5-Admin-(__VER__)\.tar\.gz
    }
    prog perl-kerberos:Authen-Krb5-Simple = {
        version   = %{V_authen_krb5_simple}
        url       = http://www.cpan.org/authors/id/D/DS/DSTUART/
        regex     = Authen-Krb5-Simple-(__VER__)\.tar\.gz
    }
    prog perl-kerberos:Authen-Krb5-Easy = {
        version   = %{V_authen_krb5_easy}
        url       = http://www.cpan.org/authors/id/S/SC/SCHALLEE/
        regex     = Authen-Krb5-Easy-(__VER__)\.tar\.gz
    }
    prog perl-kerberos:Authen-Krb5Password = {
        version   = %{V_authen_krb5password}
        url       = http://www.cpan.org/authors/id/S/SH/SHUQUE/
        regex     = Authen-Krb5Password-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %patch -p0

%build

%install
    %{l_prefix}/bin/perl-openpkg prepare
    kerberos_cflags="`%{l_prefix}/bin/krb5-config --cflags`"
    kerberos_libs="`%{l_prefix}/bin/krb5-config --libs`"
    ( cd Krb5-%{V_authen_krb5}
      %{l_shtool} subst \
          -e 's;/usr/include;%{l_prefix}/include/kerberos;g' \
          -e 's;/usr/lib;%{l_prefix}/lib/kerberos;g' \
          -e 's;/usr/local/krb5/lib;%{l_prefix}/lib/kerberos;g' \
          -e 's;/usr/local/krb5/include;%{l_prefix}/include/kerberos;g' \
          -e "s;-lresolv;$kerberos_libs -lresolv;g" \
          Makefile.PL
      %{l_prefix}/bin/perl-openpkg configure build install
    ) || exit $?
    ( cd Authen-Krb5-Admin-%{V_authen_krb5_admin}
      %{l_shtool} subst %{l_value -s -a} \
          Makefile.PL
      %{l_prefix}/bin/perl-openpkg configure build install
    ) || exit $?
    ( cd Authen-Krb5-Simple-%{V_authen_krb5_simple}
      export KRB5_INCLUDE=%{l_prefix}/include/kerberos
      export KRB5_LIB=%{l_prefix}/lib/kerberos
      %{l_prefix}/bin/perl-openpkg configure build install
    ) || exit $?
    ( cd Authen-Krb5-Easy-%{V_authen_krb5_easy}
      export KRB5_INCLUDE=%{l_prefix}/include/kerberos
      export KRB5_LIB=%{l_prefix}/lib/kerberos
      %{l_prefix}/bin/perl-openpkg configure build install
    ) || exit $?
    ( cd Authen-Krb5Password-%{V_authen_krb5password}
      %{l_shtool} subst %{l_value -s -a} \
          -e "s;-I/usr/local/include;$kerberos_cflags;g" \
          -e "s;-L/usr/local/lib -lkrb5 -lcom_err;$kerberos_libs;g" \
          Makefile.PL
      %{l_prefix}/bin/perl-openpkg configure build install
    ) || exit $?
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

