# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=allegro
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.6.0
pkgrel=1
pkgdesc="Portable library mainly aimed at video game and multimedia programming (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://liballeg.org/"
license=("ZLIB")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-dumb"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-flac"
             "${MINGW_PACKAGE_PREFIX}-freetype"
             "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
             "${MINGW_PACKAGE_PREFIX}-libpng"
             "${MINGW_PACKAGE_PREFIX}-libvorbis"
             "${MINGW_PACKAGE_PREFIX}-libwebp"
             "${MINGW_PACKAGE_PREFIX}-openal"
             "${MINGW_PACKAGE_PREFIX}-opusfile"
             "${MINGW_PACKAGE_PREFIX}-physfs"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
optdepends=("${MINGW_PACKAGE_PREFIX}-dumb: allegro_audio"
            "${MINGW_PACKAGE_PREFIX}-flac: allegro_audio"
            "${MINGW_PACKAGE_PREFIX}-opusfile: allegro_audio"
            "${MINGW_PACKAGE_PREFIX}-freetype: allegro_font"
            "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo: allegro_image"
            "${MINGW_PACKAGE_PREFIX}-libpng: allegro_image"
            "${MINGW_PACKAGE_PREFIX}-libvorbis: allegro_audio"
            "${MINGW_PACKAGE_PREFIX}-libwebp: allegro_image"
            "${MINGW_PACKAGE_PREFIX}-openal: allegro_audio"
            "${MINGW_PACKAGE_PREFIX}-physfs: allegro_physfs")
options=('strip' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/liballeg/allegro5/archive/${pkgver}.tar.gz)
conflicts=("${MINGW_PACKAGE_PREFIX}-allegro-static")
provides=("${MINGW_PACKAGE_PREFIX}-allegro-static")
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('053b7e00d0ad5411d887e8241914337099c3b0aa53c237b77a92a8a3b68967c1')

prepare() {
  cd ${srcdir}
  rm -rf ${_realname}5-${pkgver}
  tar -xzvf ${_realname}-${pkgver}.tar.gz || true
  cd "${srcdir}/${_realname}5-${pkgver}"
  sed -i "s,DS3DALG_DEFAULT,GUID_NULL,g" "addons/audio/dsound.cpp"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWANT_DEMO=OFF \
    -DWANT_DOCS=OFF \
    -DWANT_EXAMPLES=OFF \
    -DINSTALL_PKG_CONFIG_FILES=ON \
    ../${_realname}5-${pkgver}
  make
}

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