##
##  gnupg.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:         gnupg
Summary:      GNU Privacy Guard
URL:          http://www.gnupg.org/
Vendor:       Werner Koch
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        PGP
License:      GPL
Version:      2.4.5
Release:      20240308

#   package options
%option       with_setuid yes
%option       with_curl   yes
%option       with_ldap   no

#   list of sources
Source0:      ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-%{version}.tar.bz2
Patch0:       gnupg.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make
PreReq:       OpenPKG, openpkg >= 20160101, pinentry
BuildPreReq:  gcrypt >= 1.2.3, libksba >= 1.3.4, libassuan >= 2.0.0, gpg-error >= 1.11
PreReq:       gcrypt >= 1.2.3, libksba >= 1.3.4, libassuan >= 2.0.0, gpg-error >= 1.11
BuildPreReq:  zlib, bzip2, readline, npth, libiconv
PreReq:       zlib, bzip2, readline, npth, libiconv
%if "%{with_curl}" == "yes"
BuildPreReq:  curl, openssl
PreReq:       curl, openssl
%endif
%if "%{with_ldap}" == "yes"
BuildPreReq:  openldap, openssl
PreReq:       openldap, openssl
%endif

%description
    GnuPG (GNU Privacy Guard) is a GNU utility for encrypting data and
    creating digital signatures. GnuPG has advanced key management
    capabilities and is compliant with the proposed OpenPGP Internet
    standard described in RFC2440. Since GnuPG doesn't use any patented
    algorithm, it is not compatible with any version of PGP2 (PGP2.x
    uses only IDEA, patented worldwide).

%track
    prog gnupg = {
        version   = %{version}
        url       = ftp://ftp.gnupg.org/gcrypt/gnupg/
        regex     = gnupg-(2\.__VER__)\.tar\.(gz|bz2)
    }

%prep
    %setup -q
    %patch -p0
    %{l_shtool} subst \
        -e 's;PRINTABLE_OS_NAME;"%{l_openpkg_release}";g' \
        g10/armor.c

%build
    #   configure program
    export LIBS=""
    echo "int main(int argc, char *argv[]) { return 0; }" >dummy.c
    for lib in termcap termlib curses ncurses; do
        rc=0; %{l_cc} -o dummy dummy.c -l$lib >/dev/null 2>&1 || rc=1
        if [ $rc -eq 0 ]; then LIBS="$LIBS -l$lib"; break; fi
    done
%if "%{with_curl}" == "yes" || "%{with_ldap}" == "yes"
    LIBS="$LIBS -lssl -lcrypto"
%endif
%if "%{with_curl}" == "yes"
    LIBS="$LIBS -lz"
%endif
    LIBS="$LIBS -liconv `npth-config --libs`"
    export CC="%{l_cc} -pthread"
    export CFLAGS="%{l_cflags -O} `npth-config --cflags`"
    export CPPFLAGS="%{l_cppflags}"
    export LDFLAGS="%{l_ldflags}"
    ./configure \
        --prefix=%{l_prefix} \
        --libexecdir=%{l_prefix}/libexec/gnupg \
        --mandir=%{l_prefix}/man \
        --infodir=%{l_prefix}/info \
        --with-zlib=%{l_prefix} \
        --with-bzip2=%{l_prefix} \
        --with-readline=%{l_prefix} \
        --with-libiconv-prefix=%{l_prefix} \
        --with-gpg-error-prefix=%{l_prefix} \
        --with-libgcrypt-prefix=%{l_prefix} \
        --with-libassuan-prefix=%{l_prefix} \
        --with-ksba-prefix=%{l_prefix} \
        --with-npth-prefix=%{l_prefix} \
        --with-agent-pgm=%{l_prefix}/bin/gpg-agent \
        --with-pinentry-pgm=%{l_prefix}/bin/pinentry \
        --with-dirmngr-pgm=%{l_prefix}/bin/dirmngr \
        --disable-dirmngr \
%if "%{with_curl}" == "yes"
        --with-libcurl=%{l_prefix} \
%else
        --without-libcurl \
%endif
        --without-libintl-prefix \
        --disable-nls \
        --disable-scdaemon \
        --enable-generic \
        --enable-finger \
        --enable-hkp \
%if "%{with_ldap}" == "yes"
        --enable-ldap \
%else
        --disable-ldap \
%endif
%if "%{with_curl}" == "yes"
        --with-libcurl=%{l_prefix} \
%else
        --without-libcurl \
%endif
        --enable-exec \
        --enable-keyserver-helpers \
        --with-mailprog="%{l_prefix}/sbin/sendmail" \
        --disable-mailto

    #   build program
    %{l_make} %{l_mflags}

%install
    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   strip down and post-adjust installation files
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true
    strip $RPM_BUILD_ROOT%{l_prefix}/libexec/gnupg/* 2>/dev/null || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/scdaemon.1

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
%if "%{with_setuid}" == "yes"
        '%attr(4755,%{l_susr},%{l_mgrp}) %{l_prefix}/bin/gpg'
%else
        '%attr(0755,%{l_susr},%{l_mgrp}) %{l_prefix}/bin/gpg'
%endif

%files -f files

%clean

