# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Frederik Schwan <freswa at archlinux dot org>

pkgname=wasi-libc
pkgver=0+392+b9ef79d7
_commit=b9ef79d7dbd47c6c5bafdae760823467c2f60b70 # tags/wasi-sdk-24
pkgrel=1.1
epoch=1
pkgdesc='WASI libc implementation for WebAssembly'
url='https://github.com/WebAssembly/wasi-libc'
arch=(any)
license=('Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT')
makedepends=(
  'clang'
  'git'
  'llvm'
)
options=('staticlibs')
source=("git+https://github.com/WebAssembly/wasi-libc.git#commit=${_commit}")
b2sums=('2b5ffd88ba75a484c9e4bb665013e7bed0f2e4aaf13473ea4711db2958a80c172d4dca0c40f28c813a58bf2a549305a183ae8b31b95d0a772e0f6c1a9f06776e')

pkgver() {
  cd ${pkgname}
  printf "0+%s+%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  local target= make_options=(
    WASM_CC=/usr/bin/clang
    WASM_AR=/usr/bin/llvm-ar
    WASM_NM=/usr/bin/llvm-nm
  )
  local -A targets=(
    wasm32-wasi           ''
    wasm32-wasip1         ''
    wasm32-wasip1-threads 'THREAD_MODEL=posix'
    wasm32-wasip2         'WASI_SNAPSHOT=p2'
  )

  unset CC CFLAGS

  cd ${pkgname}

  for target in "${!targets[@]}"; do
    make "${make_options[@]}" TARGET_TRIPLE="$target" ${targets[$target]}
  done
}

package() {
  cd ${pkgname}
  install -dm755 "${pkgdir}"/usr/share
  cp -dr --preserve=mode,timestamp sysroot "${pkgdir}"/usr/share/wasi-sysroot
  install -Dm644 LICENSE* -t "${pkgdir}"/usr/share/licenses/${pkgname}
}

# vim:set sw=2 sts=-1 et:
