#!/usr/bin/env bash

here=$(dirname "$0")

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

set -ex
if [[ ! -f "$here"/platform-tools-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"/platform-tools-sdk/cargo-build-sbf/Cargo.toml -- $maybe_sbf_sdk "$@"
