# Maintainer: DarkMatterCore <pabloacurielz@gmail.com>

pkgbasename=lwext4
pkgname=switch-${pkgbasename}
pkgver=733b2c40d7121900e339bee8784977467a9fe8c9
pkgrel=3
pkgdesc='ext2/ext3/ext4 filesystem library for microcontrollers'
url='https://github.com/gkostka/lwext4'
license=('GPL')
arch=('any')
options=(!strip libtool staticlibs)
makedepends=('devkitA64' 'dkp-toolchain-vars' 'switch-cmake')
groups=('switch-portlibs')
source=(
  "${url}/archive/${pkgver}.zip"
  "${pkgname}-${pkgver}.patch"
)
sha256sums=(
  '7840f378f39483e5de25dbd7271652b187263c4d7e116db395effe7c6a5e692e'
  '6bddc3ded6ba6c00c31346f48397699557c699126327afccff880004b2e755c5'
)

prepare() {
  cd "${pkgbasename}-${pkgver}"
  patch -Np1 -i "${srcdir}/${pkgname}-${pkgver}.patch"

  source "${DEVKITPRO}/switchvars.sh"

  mv include lwext4
  mkdir -p include
  mv lwext4 include/lwext4

  make lib_only

  cp -fr build_lib_only/include/lwext4/generated include/lwext4/generated
}

build() {
  cd "${pkgbasename}-${pkgver}"
  make -C build_lib_only
}

package() {
  cd "${pkgbasename}-${pkgver}"

  install -Dm644 build_lib_only/src/liblwext4.a "${pkgdir}${PORTLIBS_PREFIX}/lib/liblwext4.a"
  install -Dm644 LICENSE "${pkgdir}${PORTLIBS_PREFIX}/licenses/${pkgname}/LICENSE"

  cp -fr include "${pkgdir}${PORTLIBS_PREFIX}/include"
  chmod -R u=rwX,go=rX "${pkgdir}${PORTLIBS_PREFIX}/include"
}
