# Contributor: 王宇逸 <Strawberry_Str@hotmail.com>

pkgname='fish'
pkgver=4.9.2
pkgrel=1
pkgdesc='Smart and user friendly shell intended mostly for interactive use'
arch=('x86_64')
url='https://fishshell.com/'
msys2_repository_url='https://github.com/fish-shell/fish-shell'
msys2_changelog_url='https://fishshell.com/docs/current/relnotes.html'
msys2_references=(
  'anitya: 815'
  'archlinux: fish'
  'cpe: cpe:/a:fishshell:fish'
  'cygwin: fish'
  'gentoo: app-shells/fish'
)
license=('spdx:GPL-2.0-only')
depends=(
  'gcc-libs'
  'libpcre2_32'
  'libpcre2_8'
  'man-db'
)
makedepends=(
  'cmake'
  'gcc'
  'gettext'
  'ninja'
  'pcre2-devel'
  'pkgconf'
  'python-sphinx'
  'rust'
)
optdepends=('python: for manual page completion parser and web configuration tool')
install='fish.install'
backup=(
  'etc/fish/config.fish'
  'etc/fish/msys2.fish'
  'etc/fish/perlbin.fish'
)
source=(
  "https://github.com/fish-shell/fish-shell/releases/download/${pkgver}/${pkgname}-${pkgver}.tar.xz"
  'config.fish'
  'msys2.fish'
  'msystem.fish'
  'perlbin.fish'
)
sha256sums=('26b95769ce17a8962b220ba3f20771117dbfe9cb2c3ba6f4ed139e0cbfdf02b1'
            '1cd3d051b679e8cd10eae2bc6ff7f9c7fff43150b640eef3885fb19d26f98c38'
            'cafb7cd33e86357ccf1e2264019b0906c1a7007778e070875713321dd7f36862'
            '284dbc3c996dd035da692297f9aa269f0748719177604d1930c332c69948bce7'
            '90fe7e709aad25661829a997035ec15ba2b10e4982960dad888197f77c73c0ce')

prepare() {
  cd "${pkgname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  export CXXFLAGS+=" ${CPPFLAGS}"
  export FISH_BUILD_VERSION="${pkgver}-${pkgrel} (Built by MSYS2 project)"

  cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc \
    -DCMAKE_BUILD_TYPE=Release \
    -Wno-dev \
    -DRust_COMPILER=/usr/bin/rustc \
    -DRust_CARGO=/usr/bin/cargo \
    -DRust_CARGO_TARGET="${RUST_CHOST}" \
    -DWITH_MESSAGE_LOCALIZATION=ON \
    -S "${pkgname}-${pkgver}" \
    -B build

  cmake --build build
}

package() {
  DESTDIR="${pkgdir}" cmake --install build

  install -Dm644 "config.fish" "${pkgdir}/etc/fish/config.fish"
  install -Dm644 "msys2.fish" "${pkgdir}/etc/fish/msys2.fish"
  install -Dm644 "msystem.fish" "${pkgdir}/etc/fish/msystem.fish"
  install -Dm644 "perlbin.fish" "${pkgdir}/etc/fish/perlbin.fish"
}
