#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LLVM_ARCHIVE="$ROOT/vendor-sources/llvm-project-22.1.8.src.tar.xz"
LLVM_SHA256="922f1817a0df7b1489272d18134ee0087a8b068828f87ac63b9861b1a9965888"

if [[ ! -s "$LLVM_ARCHIVE" ]]; then
  echo "error: included LLVM source archive is missing: $LLVM_ARCHIVE" >&2
  exit 1
fi
actual_sha256="$(shasum -a 256 "$LLVM_ARCHIVE" | awk '{print $1}')"
if [[ "$actual_sha256" != "$LLVM_SHA256" ]]; then
  echo "error: included LLVM source checksum mismatch" >&2
  echo "expected: $LLVM_SHA256" >&2
  echo "actual:   $actual_sha256" >&2
  exit 1
fi

export FILMBUDDY_LLVM_SOURCE_ARCHIVE="$LLVM_ARCHIVE"
export FILMBUDDY_LLVM_SOURCE_CACHE="${FILMBUDDY_LLVM_SOURCE_CACHE:-$ROOT/build/llvm-source-cache}"
exec "$ROOT/tools/build_libraw_decoder.sh"
