# Maintainer: Juergen Hoetzel <juergen@archlinux.org>
# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>

pkgname=clisp
pkgver=2.49.95
pkgrel=3
pkgdesc="ANSI Common Lisp interpreter, compiler and debugger"
arch=('x86_64' 'aarch64')
url="https://clisp.sourceforge.io/"
license=('GPL-2.0-only')
depends=(
  'ffcall'
  'glibc'
  'libsigsegv'
  'libunistring'
  'ncurses'
  'readline'
)
makedepends=('git')
provides=('common-lisp')
options=(
  '!emptydirs'
  '!makeflags'
)
_rev=afa64df1c2bd92175159e8065117ec7286c65522
source=(
  "$pkgname::git+https://gitlab.com/gnu-clisp/clisp#commit=$_rev"
  "$pkgname-fix-build-with-gcc-15.1.patch"
  "test-fixes.patch"
  "test-fixes2.patch"
)
sha512sums=('c93e403b768e5d6e842a86835da8ccd905cc2d5461671b7b0a47def0d0a96c91cffc9c0344eef75a999f4cbddf12f191f1c42f410ebf09277d7e338dc8ffa3d6'
            '4d97d2c9d19dcf1ec58fb924e1751814ffed8231bc28a859e1bd01edc9907a5264ee6d2e37f8460db7af1b216db7b8fe4fd349aa941dd9e3a0decc127d70cecd'
            '1b8586cbb79419def7c906568d1dc6efd08cd218e3d91582ae23d7268d8df72ce349f93be77d113417376020e8d22c0938a156329a8ca02ab90d9342614b8b6e'
            'b33c81572e549e4f1b78367a2b8622b033f1cab4fd537e773cf2d985549dee8af5e945276b0ad3f777f806a0ba3cf1f6ead567103ac69ffdb704131599b66595')
b2sums=('5a9ed2744db2efebbc63218b6f51ddff7087c985a97f8720d8ec66ba771e86e4c887a9955ce20b9226706ce73b12b45cd3e9d184b33fb282e8ba04e0dab76957'
        '81241db406cf00b5c219ded3067b3734d8dc2a3e13c2604f3b87e34fd863bd5fefe3e2b3aac77f1a400a3ca58d529e8e9ac08a815d22794dd37c05f5a3fc7365'
        '0421eb333be9649d0806ec23c4f0b3e387f037a2b55c0278c4202e420e4c92acb7b1167e009181e5a7f37cb7b484d220e57131be8b01083df3acdef7ae303584'
        'bcff1e9c5f13912370f5d735c22fcdccc8daf763966b226e4836e0f77e78778a16d233912ac1868e3ca0e107002730e893106ef7aef4be4d85b72d43f7bf1fdb')

prepare() {
  cd $pkgname
  # Fix build with GCC 15.1
  patch -Np1 -i ../$pkgname-fix-build-with-gcc-15.1.patch
  # There are several issues regarding streams test:
  # https://salsa.debian.org/common-lisp-team/clisp/-/blob/master/debian/patches/test-fixes.patch?ref_type=heads
  # https://gitlab.com/gnu-clisp/clisp/-/issues/51
  # so, disable the checks. Being in a container may not help too.
  patch -Np1 -i "${srcdir}/test-fixes.patch"
  # Holo: disable test failing in CI
  # patch -Np1 -i "${srcdir}/test-fixes2.patch"
}

build() {
  cd $pkgname
  CFLAGS+=" -ffat-lto-objects" \
  ./configure --prefix=/usr --with-readline --with-ffcall --with-threads=POSIX_THREADS src

  cd src
  ./makemake --prefix=/usr --with-readline --with-ffcall --with-dynamic-ffi > Makefile
  make
}

check() {
  cd $pkgname
  make check
}

package() {
  cd $pkgname/src
  make DESTDIR="$pkgdir" install
}
