##
##  libassuan.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_assuan2  2.5.7
%define       V_assuan1  1.0.5

#   package information
Name:         libassuan
Summary:      GnuPG IPC Library
URL:          http://www.gnupg.org/related_software/libassuan/
Vendor:       Werner Koch et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Libraries
License:      GPL/LGPL
Version:      %{V_assuan2}
Release:      20240308

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

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  pth, gpg-error
PreReq:       pth, gpg-error

%description
    Libassuan is the IPC library used by some GnuPG related software.

%track
    prog libassuan:libassuan1 = {
        version   = %{V_assuan1}
        url       = ftp://ftp.gnupg.org/gcrypt/libassuan/
        regex     = libassuan-(1\.\d+\.\d+)\.tar\.bz2
    }
    prog libassuan:libassuan2 = {
        version   = %{V_assuan2}
        url       = ftp://ftp.gnupg.org/gcrypt/libassuan/
        regex     = libassuan-(2\.\d+\.\d+)\.tar\.bz2
    }

%prep
    %setup -q -c
    %setup -q -D -a 1
    %patch -p0

%build
    ( cd libassuan-%{V_assuan1}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags pth .}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --infodir=%{l_prefix}/info \
          --mandir=%{l_prefix}/man \
          --with-pth-prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?
    ( cd libassuan-%{V_assuan2}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags pth .}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --infodir=%{l_prefix}/info \
          --mandir=%{l_prefix}/man \
          --with-pth-prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?

%install
    ( cd libassuan-%{V_assuan1}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
      mv  $RPM_BUILD_ROOT%{l_prefix}/bin/libassuan-config \
          $RPM_BUILD_ROOT%{l_prefix}/bin/libassuan1-config
      %{l_shtool} subst \
          -e 's;-lassuan;-lassuan1;g' \
          $RPM_BUILD_ROOT%{l_prefix}/bin/libassuan1-config
      mv  $RPM_BUILD_ROOT%{l_prefix}/include/assuan.h \
          $RPM_BUILD_ROOT%{l_prefix}/include/assuan1.h
      mv  $RPM_BUILD_ROOT%{l_prefix}/info/assuan.info \
          $RPM_BUILD_ROOT%{l_prefix}/info/assuan1.info
      mv  $RPM_BUILD_ROOT%{l_prefix}/lib/libassuan.a \
          $RPM_BUILD_ROOT%{l_prefix}/lib/libassuan1.a
      mv  $RPM_BUILD_ROOT%{l_prefix}/lib/libassuan-pth.a \
          $RPM_BUILD_ROOT%{l_prefix}/lib/libassuan1-pth.a
      rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/libassuan.la
      mv  $RPM_BUILD_ROOT%{l_prefix}/share/aclocal/libassuan.m4 \
          $RPM_BUILD_ROOT%{l_prefix}/share/aclocal/libassuan1.m4
    ) || exit $?
    ( cd libassuan-%{V_assuan2}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?
    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

