%define pkg_name    mbedtls
%define pkg_version 2.8.0
%define pkg_release 1%{?_dist_release}

Summary: Light-weight cryptographic and SSL/TLS library
Name:    %{pkg_name}
Version: %{pkg_version}
Release: %{pkg_release}

Group:   System Environment/Libraries
License: ASL 2.0
URL:     https://tls.mbed.org/

Source0: https://tls.mbed.org/download/%{name}-%{version}-apache.tgz

# mbed TLS way of enabling features
Patch0: mbedtls-2.4-config-enable-pkcs11.patch
Patch1: mbedtls-2.7-config-enable-threading-pthread.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: cmake
# BuildRequires: perl-interpreter
BuildRequires: doxygen
# BuildRequires: graphviz
BuildRequires: pkcs11-helper-devel

Requires: pkcs11-helper


%description
Mbed TLS is a light-weight open source cryptographic and SSL/TLS
library written in C. Mbed TLS makes it easy for developers to include
cryptographic and SSL/TLS capabilities in their (embedded)
applications with as little hassle as possible.
FOSS License Exception: https://tls.mbed.org/foss-license-exception

%package        utils
Summary:        Utilities for %{name}
Group:          Applications/System
Requires:       %{name}%{?_isa} = %{version}-%{release}
Obsoletes:      polarssl-utils < 1.3.10
Provides:       polarssl-utils = %{version}-%{release}

%description    utils
Cryptographic utilities based on %{name}.

%package        devel
Summary:        Development files for %{name}
Group:          Development/Libraries
Requires:       %{name}%{?_isa} = %{version}-%{release}
Obsoletes:      polarssl-devel < 1.3.10
Provides:       polarssl-devel = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%package        static
Summary:        Static files for %{name}
Group:          Development/Libraries
Requires:       %{name}-devel%{?_isa} = %{version}-%{release}

%description    static
The %{name}-static package contains static files for
developing applications that use %{name}.


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q
%patch0
%patch1

%build
%{cmake} -D CMAKE_BUILD_TYPE:String="Release" \
         -D USE_SHARED_MBEDTLS_LIBRARY:BOOL=1 \
         -D USE_PKCS11_HELPER_LIBRARY:BOOL=1 \
         .
%{__make} %{?_smp_mflags} all apidoc

%install
%{make_install}
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_libexecdir}
%{__mv} ${RPM_BUILD_ROOT}%{_bindir} ${RPM_BUILD_ROOT}%{_libexecdir}/mbedtls

%check
LD_LIBRARY_PATH=$PWD/library ctest --output-on-failure -V

%clean
%{__rm} -rf ${RPM_BUILD_ROOT}

%post -p %{_syssbindir}/ldconfig

%postun -p %{_syssbindir}/ldconfig


%files
%doc ChangeLog LICENSE
%{_libdir}/*.so.*
%doc apidoc/*

%files utils
%{_libexecdir}/%{name}/

%files devel
%{_includedir}/mbedtls/
%{_libdir}/*.so

%files static
%{_libdir}/*.a


%changelog
* Wed Jun 13 2018 Toshiaki Ara <ara_t@384.jp> 2.8.0-1
- initial build for Vine Linux

* Fri Apr 06 2018 Morten Stevens <mstevens@fedoraproject.org> - 2.8.0-1
- Update to 2.8.0

* Tue Feb 06 2018 Morten Stevens <mstevens@fedoraproject.org> - 2.7.0-1
- Update to 2.7.0
- Enable pthread support (#1533435)
- Security Advisory 2018-01 (CVE-2018-0488)

* Tue Aug 29 2017 Morten Stevens <mstevens@fedoraproject.org> - 2.6.0-1
- Update to 2.6.0

* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.5.1-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

* Wed Jul 26 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.5.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Mon Jun 26 2017 Morten Stevens <mstevens@fedoraproject.org> - 2.5.1-3
- Reenable ctest

* Fri Jun 23 2017 Morten Stevens <mstevens@fedoraproject.org> - 2.5.1-2
- Disable ctest due a bug on s390x

* Wed Jun 21 2017 Morten Stevens <mstevens@fedoraproject.org> - 2.5.1-1
- Update to 2.5.1

* Wed Mar 29 2017 David Sommerseth <davids@openvpn.net> - 2.4.2-2
- Enable PKCS#11 support

* Sat Mar 11 2017 Morten Stevens <mstevens@fedoraproject.org> - 2.4.2-1
- Update to 2.4.2

* Fri Feb 10 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.4.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Mon Oct 31 2016 Morten Stevens <mstevens@fedoraproject.org> - 2.4.0-1
- Update to 2.4.0

* Thu Jun 30 2016 Morten Stevens <mstevens@fedoraproject.org> - 2.3.0-1
- Update to 2.3.0

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 2.2.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Sat Jan 09 2016 Morten Stevens <mstevens@fedoraproject.org> - 2.2.1-1
- Update to 2.2.1

* Sun Dec 27 2015 Morten Stevens <mstevens@fedoraproject.org> - 2.2.0-1
- Update to 2.2.0

* Mon Oct 12 2015 Morten Stevens <mstevens@fedoraproject.org> - 2.1.2-1
- Update to 2.1.2
- CVE-2015-5291

* Fri Sep 11 2015 Morten Stevens <mstevens@fedoraproject.org> - 2.1.0-1
- Update to 2.1.0

* Wed Jul 22 2015 Morten Stevens <mstevens@fedoraproject.org> - 2.0.0-1
- Update to 2.0.0

* Wed Jun 17 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.3.11-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Fri Jun 05 2015 Morten Stevens <mstevens@fedoraproject.org> - 1.3.11-1
- Update to 1.3.11

* Mon Jun 01 2015 Robert Scheck <robert@fedoraproject.org> - 1.3.10-2
- Spec file changes to cover Red Hat Enterprise Linux 5 and 6

* Thu May 14 2015 Morten Stevens <mstevens@fedoraproject.org> - 1.3.10-1
- Initial Fedora Package
- Added subpackage for documentation files
- Added subpackage for static files
