# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=mbedtls2
pkgver=2.28.9
pkgrel=1
pkgdesc='An open source, portable, easy to use, readable and flexible TLS library'
arch=(x86_64)
url=https://tls.mbed.org
license=(Apache-2.0)
depends=(glibc)
checkdepends=(python)
makedepends=(
  cmake
  git
  ninja
)
provides=(
  libmbedcrypto.so
  libmbedtls.so
  libmbedx509.so
)
_tag=b102d44b8500344336ddb5fdc6333aab18a99a34
source=(git+https://github.com/ARMmbed/mbedtls.git#tag=${_tag})
b2sums=('607ea3600ee6466a85919c6e6b6c66120fe8dd6033983e4cd782884fcf1178a587cd8556c78239718cc23686ed64f8349f4ff45d23510d90ae8d6837a05b83bd')

pkgver() {
  cd mbedtls
  git describe --tags | sed 's/^v//; s/^mbedtls-//'
}

build() {
  export CFLAGS+=' -ffat-lto-objects'
  cmake -S mbedtls -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_INCLUDEDIR=include/mbedtls2 \
    -DCMAKE_INSTALL_LIBDIR=lib/mbedtls2 \
    -DCMAKE_SKIP_RPATH=ON \
    -DENABLE_PROGRAMS=OFF \
    -DMBEDTLS_FATAL_WARNINGS=OFF \
    -DUSE_SHARED_MBEDTLS_LIBRARY=ON \
    -DUSE_STATIC_MBEDTLS_LIBRARY=OFF \
    -Wno-dev
  cmake --build build
}

check() {
  LD_LIBRARY_PATH="${srcdir}"/build/library ctest --test-dir build
}

package() {
  DESTDIR="${pkgdir}" cmake --install build
  install -dm 755 "${pkgdir}"/usr/include/mbedtls2
  mv "${pkgdir}"/usr/include/{everest,mbedtls,psa} "${pkgdir}"/usr/include/mbedtls2/
  mv "${pkgdir}"/usr/lib/mbedtls2/*.so.* "${pkgdir}"/usr/lib/
  ln -sf ../libmbedcrypto.so.7 "${pkgdir}"/usr/lib/mbedtls2/libmbedcrypto.so
  ln -sf ../libmbedtls.so.14 "${pkgdir}"/usr/lib/mbedtls2/libmbedtls.so
  ln -sf ../libmbedx509.so.1 "${pkgdir}"/usr/lib/mbedtls2/libmbedx509.so
}

# vim: ts=2 sw=2 et:
