summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 44ee9a92d96f90d45aa9fc9f789f849703a648b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Maintainer: Lucas Gabriel <g at 11xx dot org>

_hkgname=mpd-current-json
pkgname=${_hkgname}
pkgver=2.1.0.0
pkgrel=6
pkgdesc="Print current MPD song and status as JSON"
url="https://codeberg.org/useless-utils/mpd-current-json"
license=("Unlicense")
arch=('x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-aeson-pretty' 'haskell-libmpd' 'haskell-optparse-applicative')
makedepends=('ghc' 'uusi')
source=("https://hackage.haskell.org/packages/archive/$_hkgname/$pkgver/$_hkgname-$pkgver.tar.gz")
sha256sums=('a2ee161ab01b7332ef55d86c0c52eadce524ca52f5676d9f4094c1ed82399145')

# From https://gitlab.archlinux.org/archlinux/packaging/packages/arch-hs/-/blob/main/PKGBUILD?ref_type=heads
# The use of `${1}' is for generating/installing completion for multiple executables with a suffixed name.
_gen_comp(){
  LD_LIBRARY_PATH="$PWD/dist/build" dist/build/${_hkgname}${1}/${_hkgname}${1} --bash-completion-script "/usr/bin/${_hkgname}${1}" > bash${1}
  LD_LIBRARY_PATH="$PWD/dist/build" dist/build/${_hkgname}${1}/${_hkgname}${1} --zsh-completion-script  "/usr/bin/${_hkgname}${1}" > zsh${1}
  LD_LIBRARY_PATH="$PWD/dist/build" dist/build/${_hkgname}${1}/${_hkgname}${1} --fish-completion-script "/usr/bin/${_hkgname}${1}" > fish${1}
}

_install_comp(){
  install -D -m644 bash${1} "$pkgdir/usr/share/bash-completion/completions/${_hkgname}${1}"
  install -D -m644 zsh${1}  "$pkgdir/usr/share/zsh/site-functions/_${_hkgname}${1}"
  install -D -m644 fish${1} "$pkgdir/usr/share/fish/vendor_completions.d/${_hkgname}${1}.fish"
}

prepare() {
  # -O2 makes a big difference in Cabal's default 'semi-static'
  # compilation (not 'fully-static'). Since Arch uses fully-dynamic
  # and it doesn't seem to make a difference here, remove it:
  uusi --all --remove-options-all=-O2 $_hkgname-$pkgver/$_hkgname.cabal

  # remove type definition of KeyValue that conflicts with `aeson <2.2'
  sed -i '/(.=?) :: (KeyValue e a, ToJSON v) => Key -> Maybe v -> Maybe a/d' $_hkgname-$pkgver/lib/Network/MPD/JSON.hs
}

build() {
  cd $_hkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  runhaskell Setup build
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh

  _gen_comp
}

package() {
  cd $_hkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 UNLICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/UNLICENSE

  _install_comp
}