set -e

build_lib_wasm_release() {
    src=$1
    dst=$2
    backend=$3
    echo $dst
    emcc -c -O2 -DNDEBUG -DSKIP_ERROR_CHECK -sMEMORY64 -sSHARED_MEMORY -DIMPL -D$backend c/$src.c
    emar rcs $dst.a $src.o
}

build_lib_wasm_debug() {
    src=$1
    dst=$2
    backend=$3
    echo $dst
    emcc -c -g -DIMPL -sMEMORY64 -sSHARED_MEMORY -D$backend c/$src.c
    emar rcs $dst.a $src.o
}

# wasm + GL + Release
build_lib_wasm_release sokol_log         log/sokol_log_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_gfx         gfx/sokol_gfx_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_app         app/sokol_app_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_glue        glue/sokol_glue_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_time        time/sokol_time_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_audio       audio/sokol_audio_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_debugtext   debugtext/sokol_debugtext_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_shape       shape/sokol_shape_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_fontstash       fontstash/sokol_fontstash_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_fetch       fetch/sokol_fetch_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_audio       audio/sokol_audio_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release sokol_gl          gl/sokol_gl_wasm_gl_release SOKOL_GLES3
build_lib_wasm_release stb_image            stbi/stb_image SOKOL_GLES3

# wasm + GL + Debug
build_lib_wasm_debug sokol_log           log/sokol_log_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_gfx           gfx/sokol_gfx_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_app           app/sokol_app_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_glue          glue/sokol_glue_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_time          time/sokol_time_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_audio         audio/sokol_audio_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_debugtext     debugtext/sokol_debugtext_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_shape         shape/sokol_shape_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_fontstash         fontstash/sokol_fontstash_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_fetch         fetch/sokol_fetch_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_audio         audio/sokol_audio_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug sokol_gl            gl/sokol_gl_wasm_gl_debug SOKOL_GLES3
build_lib_wasm_debug stb_image            stbi/stb_image SOKOL_GLES3

rm *.o
