#!/usr/bin/env bash
if [ "$#" -lt 2 ]; then
    echo "Usage: $0 <build-directory-name> <sodium-install-dir>"
    exit 1
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
REPO_DIR="$SCRIPT_DIR/spectre-api-c"
BUILD_DIR_NAME="$REPO_DIR/$1"
STATIC_LIB_PATH="$BUILD_DIR_NAME/libspectre.a"

pushd "$REPO_DIR" >/dev/null
    meson setup "$BUILD_DIR_NAME" --cross-file "$SCRIPT_DIR/cross-esp32s3.txt" -Dlibsodium-install-dir="$2"
    meson compile -C "$BUILD_DIR_NAME"
    $SCRIPT_DIR/redefine-syms.sh "__spre_" "$STATIC_LIB_PATH" "$STATIC_LIB_PATH"
popd >/dev/null
