#!/bin/sh
# Rebuild against Codec2 1.2.0, commit 06d4c11e699b0351765f10398abb4f663a984f36.
# Activate Emscripten 4.0.19 before running; output stays in the selected build dir.
set -eu
codec2_source=${1:?Codec2 source directory required}
codec2_build=${2:?Empty build directory required}
emcmake cmake -S "$codec2_source" -B "$codec2_build" -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DUNITTEST=OFF
cmake --build "$codec2_build" --target codec2 -j 4
emcc "$codec2_build/src/libcodec2.a" -O3 -sMODULARIZE=1 -sEXPORT_NAME=StegoCodec2 -sSINGLE_FILE=1 -sENVIRONMENT=web,worker,node -sFILESYSTEM=0 -sALLOW_MEMORY_GROWTH=1 '-sEXPORTED_FUNCTIONS=["_codec2_create","_codec2_destroy","_codec2_encode","_codec2_decode","_codec2_samples_per_frame","_codec2_bits_per_frame","_malloc","_free"]' '-sEXPORTED_RUNTIME_METHODS=["HEAP16","HEAPU8"]' -o "$codec2_build/codec2.js"
