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

pkgname=fish
pkgver=4.1.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=(
  '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')
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=('52873934fc1ee21a1496e9f4521409013e540f77cbf29142a1b17ab93ffaafac'
            '983c3273e0249957ed6c40785e005739da30f31d4f029383f257f9990d38811a'
            '8bb0d28df47b66e6785f7db00a2c4316bc15960e67bdec0daca7f811f5bf3895'
            '71c6990b39caf5d50c10f10074283adfc6a36aafff30fd54f7eb451d4e007496'
            'b136a9fa94abf53e302f7a1cc28def03b58dd2326990c5f02ceb4988341a5ac6')

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

  cargo fetch --locked --target 'x86_64-pc-cygwin'
}

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=x86_64-pc-cygwin \
    -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"
}
