# Maintainer: Valeria Fadeeva <valeria@fadeeva.me>

_gitname="$(basename $(pwd))"
pkgname=("melawy-$_gitname")
pkgver=3.3.0.8
pkgrel=1
pkgdesc="$(head -n 2 README.md | tail -n 1)"
arch=("i686" "x86_64")
url="https://git.melawy.ru/Melawy-Linux/$_gitname"
license=("AGPL")

depends=('appstream-qt' 'boost' 'boost-libs' 'ckbcomp' 'cmake' 'cryptsetup' 'dmidecode' 'doxygen' 'efibootmgr' 'extra-cmake-modules' 'git' 'gptfdisk' 'gtk-update-icon-cache' 'hwinfo' 'icu' 'kconfig' 'kcoreaddons' 'kdbusaddons' 'ki18n' 'kiconthemes' 'kio' 'kparts' 'kpmcore' 'kservice' 'kwidgetsaddons' 'libpwquality' 'mkinitcpio-openswap' 'networkmanager' 'plasma-framework' 'polkit-qt5' 'python' 'python-jsonschema' 'python-pyaml' 'python-unidecode' 'qt5-quickcontrols2' 'qt5-svg' 'qt5-tools' 'qt5-translations' 'qt5-webengine' 'qt5-xmlpatterns' 'rsync' 'solid' 'squashfs-tools' 'upower' 'yaml-cpp')

makedepends=('appstream-qt' 'boost' 'boost-libs' 'ckbcomp' 'cmake' 'cryptsetup' 'dmidecode' 'doxygen' 'efibootmgr' 'extra-cmake-modules' 'git' 'gptfdisk' 'gtk-update-icon-cache' 'hwinfo' 'icu' 'kconfig' 'kcoreaddons' 'kdbusaddons' 'ki18n' 'kiconthemes' 'kio' 'kparts' 'kpmcore' 'kservice' 'kwidgetsaddons' 'libpwquality' 'mkinitcpio-openswap' 'networkmanager' 'plasma-framework' 'polkit-qt5' 'python' 'python-jsonschema' 'python-pyaml' 'python-unidecode' 'qt5-quickcontrols2' 'qt5-svg' 'qt5-tools' 'qt5-translations' 'qt5-webengine' 'qt5-xmlpatterns' 'rsync' 'solid' 'squashfs-tools' 'upower' 'yaml-cpp')

optdepends=()

backup=()
provides=("${pkgname}")
conflicts=("calamares" "${pkgname}")
options=(!strip !emptydirs)
source=("git+$url.git")
sha256sums=("SKIP")
validpgpkeys=("BC8B600E8DDA1F4CB77B10D2BA803A261A5EE6B8")

# pkgver() {
#       cd "$srcdir/$_gitname"
#       printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
# }

pkgver() {
        cd "${srcdir}/${_gitname}"
        printf "3.3.0.%s" "$(git rev-list --count HEAD)"
}

prepare() {
#   cp -rv ../modules/* ${srcdir}/$_pkgname-${pkgver}/src/modules/

  sed -i -e 's/"Install configuration files" OFF/"Install configuration files" ON/' "${srcdir}/${_gitname}/calamares/CMakeLists.txt"
  sed -i -e 's/# DEBUG_FILESYSTEMS/DEBUG_FILESYSTEMS/' "${srcdir}/${_gitname}/calamares/CMakeLists.txt"
  sed -i -e "s/desired_size = 512 \* 1024 \* 1024  \# 512MiB/desired_size = 512 \* 1024 \* 1024 \* 4  \# 2048MiB/" "${srcdir}/${_gitname}/calamares/src/modules/fstab/main.py"
  sed -i -e "s|CALAMARES_VERSION 3.3.0-alpha3|CALAMARES_VERSION $pkgver|g" "${srcdir}/${_gitname}/calamares/CMakeLists.txt"
}

build() {
  rm -rf "${_gitname}/build/*"

  mkdir -p "${_gitname}/build"

  cmake -B "${_gitname}/build" -S "${_gitname}/calamares" \
      -DWEBVIEW_FORCE_WEBKIT=OFF \
      -DWITH_PYTHONQT=ON \
      -DWITH_KF5DBus=ON \
      -DWITH_APPSTREAM=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_INSTALL_LIBDIR=/usr/lib \
      -DSKIP_MODULES="dummyprocess dummypython dummycpp dummypythonqt"

#      -DBoost_NO_BOOST_CMAKE=ON \

  export DESTDIR="${_gitname}/build"
  make -j $(nproc) -C "${_gitname}/build"
}

package() {
  make -C "${srcdir}/${_gitname}/build" DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_gitname}/calamares/melawy-linux.desktop" "${pkgdir}/usr/share/applications/melawy-linux.desktop"
  install -Dm644 "${srcdir}/${_gitname}/calamares/melawy-linux-debugging.desktop" "${pkgdir}/usr/share/applications/melawy-linux-debugging.desktop"
  install -Dm755 "${srcdir}/${_gitname}/calamares/calamares_polkit" "${pkgdir}/usr/bin/calamares_polkit"
#   rm "${pkgdir}/usr/share/applications/calamares.desktop"
#   install -dm 755 "${pkgdir}/etc"
#   cp -rp "${srcdir}/${_gitname}/calamares/configs" "${pkgdir}/etc/calamares"
#   cp -rp "${srcdir}/${_gitname}/calamares/configs/melawy-linux" "${pkgdir}/etc/calamares"
}
