# Maintainer: melak47 <melak47@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>
# Contributor: Beat Bolli <dev@drbeat.li>

_realname=fmt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=8.0.1
pkgrel=1
pkgdesc="A modern formatting library for C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://fmt.dev"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/fmtlib/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('b06ca3130158c625848f3fb7418f235155a4d389b2abc3a6245fb01cb0eb1e01')

build() {
  # Shared Build
  [[ -d "build-${MINGW_CHOST}-shared" ]] && rm -rf "build-${MINGW_CHOST}-shared"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}-shared
  cd ${srcdir}/build-${MINGW_CHOST}-shared
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DFMT_TEST=OFF \
    ../${_realname}-${pkgver}

  make -j1 # parallel jobs break build

  # Static Build
  [[ -d "build-${MINGW_CHOST}-static" ]] && rm -rf "build-${MINGW_CHOST}-static"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}-static
  cd ${srcdir}/build-${MINGW_CHOST}-static
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=OFF \
    -DFMT_TEST=OFF \
    ../${_realname}-${pkgver}

  make -j1 # parallel jobs break build
}

package() {
  # Shared Install
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  make DESTDIR=${pkgdir} install

  # Static Install
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  make DESTDIR=${pkgdir} install

  # Copy the source files for including
  install -m644 ${srcdir}/${_realname}-${pkgver}/src/*.cc ${pkgdir}${MINGW_PREFIX}/include/${_realname}

  # License
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.rst ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.rst
}
