# Maintainer: John Murray <john@menaceinc.com>

_realname=soil
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.16.0
pkgrel=3
pkgdesc="C library used for loading image files into OpenGL (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://lonesock.net/soil.html'
license=('Public Domain')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
# https://www.lonesock.net/files/${_realname}.zip
source=("${_realname}-${pkgver}.zip::https://web.archive.org/web/20160319195722if_/http://www.lonesock.net/files/soil.zip")
sha256sums=('a2305b8d64f6d636e36d669bbdb0ca5445d1345c754b3d61d3f037dad2e5f701')

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM}/obj
  mkdir -p "${srcdir}"/build-${MSYSTEM}/lib

  if [[ ${CC} == clang ]]; then
    CXXFLAGS+=" -Wno-c++11-narrowing"
  fi

  cd "${srcdir}/Simple OpenGL Image Library/projects/makefile"
  make \
    OBJDIR="${srcdir}"/build-${MSYSTEM}/obj \
    LIBDIR="${srcdir}"/build-${MSYSTEM}/lib \
    CXX="${CXX}" \
    CXXFLAGS="${CXXFLAGS}"
}

package() {
  cd "${srcdir}/Simple OpenGL Image Library/projects/makefile"

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include/SOIL
  make \
    LOCAL="${pkgdir}"${MINGW_PREFIX} \
    OBJDIR="${srcdir}"/build-${MSYSTEM}/obj \
    LIBDIR="${srcdir}"/build-${MSYSTEM}/lib install

  mv "${pkgdir}"${MINGW_PREFIX}/include/SOIL.h "${pkgdir}"${MINGW_PREFIX}/include/SOIL/
  
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/doc/SOIL
  cp -r "$srcdir/Simple OpenGL Image Library/soil.html" \
   "${pkgdir}"${MINGW_PREFIX}/share/doc/SOIL

  find "${pkgdir}"${MINGW_PREFIX} -type f -exec chmod 644 {} \;
  find "${pkgdir}"${MINGW_PREFIX} -type d -exec chmod 755 {} \;
}

