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

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
REPO_DIR="$SCRIPT_DIR/libsodium"
INSTALL_DIR_NAME="$REPO_DIR/$1"

pushd "$REPO_DIR" >/dev/null
    env CC=xtensa-esp32s3-elf-gcc \
        CFLAGS="-ffreestanding -fno-builtin -mlongcalls" \
        LDFLAGS="-nostdlib -static" \
        ./configure \
        --host xtensa-esp32s3 \
        --disable-shared \
        --enable-static \
        --prefix="$INSTALL_DIR_NAME"
    make -j
    make install
popd >/dev/null
