# Maintainer: Frederik Schwan <freswa at archlinux dot org>

pkgname=wasi-libc
pkgver=0+503+ac020b86
_commit=ac020b86fd44bafe60aa4fa12f407d16e3731329 # tags/wasi-sdk-29
pkgrel=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=('5c4f370377368c9139fed92c57735dbfac56804c778c9c043785b3f0dc36ec5992d15ddb96cfe7e6e9b67f1b0e16d641cae924f4eab818768c62d1d958aafd0e')

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'
  )

  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:
