#!/usr/bin/env bash
#
# Compile dr_mp3 + dr_flac wrapper into a static library.
#
# Output: ../linux/decoders.a (or ../macos/decoders.a)
#
# Run from anywhere — this script cd's to its own directory first.
#

set -euo pipefail
cd "$(dirname "$0")"

CC="${CC:-clang}"
case "$(uname -s)" in
    Linux*)   OUT_DIR=../linux ;;
    Darwin*)  OUT_DIR=../macos ;;
    *)        echo "unsupported platform"; exit 1 ;;
esac

mkdir -p "$OUT_DIR"

echo "compiling decoders.c..."
"$CC" -O2 -fPIC -Wno-everything -c -o decoders.o decoders.c
ar rcs "$OUT_DIR/decoders.a" decoders.o
rm decoders.o

echo "wrote $OUT_DIR/decoders.a"
