#!/usr/bin/env bash

here=$(dirname "$0")

maybe_sbf_sdk="--sbf-sdk $here/sdk/sbf"
for a in "$@"; do
  if [[ $a = --sbf-sdk ]]; then
    maybe_sbf_sdk=
  fi
done

set -ex
if [[ ! -f "$here"/sdk/sbf/syscalls.txt ]]; then
  cargo build --manifest-path "$here"/programs/bpf_loader/gen-syscall-list/Cargo.toml
fi
exec cargo run --manifest-path "$here"/sdk/cargo-build-sbf/Cargo.toml -- $maybe_sbf_sdk "$@"
