%if 0%{?gitcount} > 0
%define gitsuffix -%{gitcount}-g%{gitrev}
%define relsuffix .git%{gitcount}_%{gitrev}
%endif

%define use_libproxy 1
%define use_tokens 1

%define use_tokens 0
%define use_ocserv 0
%define use_softhsm 0

%define use_tss2_esys 1

%{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{name}-%{version}}
Name:                openconnect
Version:             9.01
Release:             1
Summary:             Open client for Cisco AnyConnect VPN, Juniper Network Connect/Pulse, PAN GlobalProtect
License:             LGPLv2+
URL:                 http://www.infradead.org/openconnect.html
Source0:             https://www.infradead.org/openconnect/download/openconnect-%{version}%{?gitsuffix}.tar.gz
%if 0%{?gitcount} == 0
Source1:             https://www.infradead.org/openconnect/download/openconnect-%{version}%{?gitsuffix}.tar.gz.asc
%endif
Source2:             gpgkey-BE07D9FD54809AB2C4B0FF5F63762CDA67E2F359.asc
Source3:             gpgverify
BuildRequires:       pkgconfig(libxml-2.0) pkgconfig(libpcsclite) krb5-devel gnupg2
BuildRequires:       autoconf automake libtool gettext pkgconfig(liblz4)
BuildRequires:       pkgconfig(uid_wrapper) pkgconfig(socket_wrapper)
%if %{use_softhsm}
BuildRequires:       softhsm
%endif
Obsoletes:           openconnect-lib-compat < %{version}-%{release}
Requires:            vpnc-script
BuildRequires:       pkgconfig(gnutls) trousers-devel
%if %{use_ocserv}
BuildRequires:       ocserv
%endif

%if %{use_libproxy}
BuildRequires:       pkgconfig(libproxy-1.0)
%endif
%if %{use_tokens}
BuildRequires:       pkgconfig(stoken) pkgconfig(libpskc)
%endif
%if %{use_tss2_esys}
BuildRequires:       pkgconfig(tss2-esys) libgcrypt-devel
%endif
%description
This package provides a multiprotocol VPN client for Cisco AnyConnect,
Juniper SSL VPN / Pulse Connect Secure, and Palo Alto Networks GlobalProtect
SSL VPN.

%package devel
Summary:             Development package for OpenConnect VPN authentication tools
Requires:            %{name}%{?_isa} = %{version}-%{release}

%description devel
This package provides the core HTTP and authentication support from
the OpenConnect VPN client, to be used by GUI authentication dialogs
for NetworkManager etc.

%prep
%if 0%{?gitcount} == 0
cp %{SOURCE3} .
sh gpgverify --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}'
%endif
%autosetup -n openconnect-%{version}%{?gitsuffix} -p1

%build
%configure    --with-vpnc-script=/etc/vpnc/vpnc-script \
        --disable-dsa-tests \
        --with-default-gnutls-priority="@OPENCONNECT,SYSTEM" \
        --without-gnutls-version-check \
        --htmldir=%{_pkgdocdir}
make %{?_smp_mflags} V=1

%install
%make_install
mkdir -p $RPM_BUILD_ROOT/%{_pkgdocdir}
rm -f $RPM_BUILD_ROOT/%{_libdir}/libopenconnect.la
rm -f $RPM_BUILD_ROOT/%{_libexecdir}/openconnect/tncc-wrapper.py
rm -f $RPM_BUILD_ROOT/%{_libexecdir}/openconnect/hipreport-android.sh
%find_lang %{name}

%check
make VERBOSE=1 check
%ldconfig_scriptlets

%files -f %{name}.lang
%{_libdir}/libopenconnect.so.5*
%{_sbindir}/openconnect
%{_libexecdir}/openconnect/
%{_mandir}/man8/*
%{_datadir}/bash-completion/completions/openconnect
%doc TODO COPYING.LGPL
%doc %{_pkgdocdir}

%files devel
%{_libdir}/libopenconnect.so
%{_includedir}/openconnect.h
%{_libdir}/pkgconfig/openconnect.pc

%changelog
* Thu Apr 20 2023 xu_ping <707078654@qq.com> - 9.01-1
- Upgrade package to 9.01 version

* Tue Feb 07 2023 wangkai <wangkai385@h-partners.com> - 8.10-2
- modify the gpg verification method

* Mon Sep 6 2021 wulei <wulei80@huawei.com> - 8.10-1
- package init
