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

pkgname=fish
pkgver=4.7.0
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=(
  '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=('gcc' 'gettext' 'pcre2-devel' 'cmake' 'pkgconf' 'rust' 'ninja' 'python-sphinx')
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=('c54a3b8cb765d3d4a452f3ec600f07dfde9a6892f7ff568fe064071d27aaa9db'
            '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} \
    -S "${pkgname}-${pkgver}" \
    -B build

  cmake --build build
}

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

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