##
##  gnutls.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 version
%define       V_base  3.6
%define       V_dist  3.6.16

#   package information
Name:         gnutls
Summary:      GNU SSL/TLS Library
URL:          http://www.gnutls.org/
Vendor:       Free Software Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        SSL
License:      LGPL
Version:      %{V_dist}
Release:      20210525

#   package options
%option       with_cxx   no

#   list of sources
Source0:      https://www.gnupg.org/ftp/gcrypt/gnutls/v%{V_base}/gnutls-%{version}.tar.xz
Patch0:       gnutls.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  gcc
%if "%{with_cxx}" == "yes"
BuildPreReq:  gcc::with_cxx = yes
%endif
BuildPreReq:  gcrypt, libtasn1, zlib, nettle, p11kit, libiconv, libidn
PreReq:       gcrypt, libtasn1, zlib, nettle, p11kit, libiconv, libidn

%description
    GnuTLS is a project that aims to develop a library which provides a
    secure layer, over a reliable transport layer. Currently the GnuTLS
    library implements the proposed standards by the IETF's TLS working
    group (RFC2246, TLS 1.0).

%track
    prog gnutls = {
        version   = %{version}
        url       = https://www.gnupg.org/ftp/gcrypt/gnutls/v%{V_base}/
        regex     = gnutls-(\d+(?:\.\d+)+)\.tar\.xz
    }

%prep
    %setup -q
    %patch -p0

%build
    find . -type f -name "*.[ch]" -print | \
    xargs %{l_shtool} subst \
        -e 's;secure_getenv;gnutls_secure_getenv;g'
    libs=""
    case "%{l_platform -t}" in
        *-sunos* ) libs="-lsocket -lnsl" ;;
    esac
    echo 'ac_cv_type_ptrdiff_t=yes' >config.cache
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
%if "%{with_cxx}" == "yes"
    CXX="%{l_cxx}" \
    CXXFLAGS="%{l_cxxflags -O}" \
%endif
    CPPFLAGS="%{l_cppflags} %{l_cppflags p11-kit-1 libidn .}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="$libs `%{l_prefix}/bin/gpg-error-config --libs` -lz" \
    GREP="grep" \
    ./configure \
        --cache-file=config.cache \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --infodir=%{l_prefix}/info \
        --with-libz-prefix=%{l_prefix} \
        --with-libiconv-prefix=%{l_prefix} \
        --with-zlib \
%if "%{with_cxx}" == "yes"
        --enable-cxx \
%else
        --disable-cxx \
%endif
        --disable-guile \
        --disable-tests \
        --disable-doc \
        --disable-gtk-doc \
        --disable-nls \
        --disable-shared
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std}

%files -f files

%clean

