#!/bin/sh
OUT_FILE="tempbin"
OUT_WASM="temp.wasm"
IN_FILES="examples/emscripten.c"
emscripten_emcc_build() {
CC_FLAGS="-Wall -Wextra -Wshadow -Werror -Os -g0 -flto"
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
if [ $? -ne 0 ]; then
echo "Compiling ${IN_FILES}: FAILED"
exit 1
fi
echo "Compiling ${IN_FILES}: PASSED"
rm -f $OUT_WASM
}
emscripten_docker_build() {
docker container run --rm \
--volume $PWD:/code \
--workdir /code \
emscripten/emsdk:latest \
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
if [ $? -ne 0 ]; then
echo "Compiling ${IN_FILES} (using docker): FAILED"
exit 1
fi
echo "Compiling ${IN_FILES} (using docker): PASSED"
rm -f $OUT_WASM
}
try_emscripten_build() {
which emcc > /dev/null
if [ $? -eq 0 ]; then
emscripten_emcc_build
return $?
fi
which docker > /dev/null
if [ $? -eq 0 ]; then
emscripten_docker_build
return $?
fi
echo "(Skipping Emscripten test)"
}
./create_single_file_decoder.sh
if [ $? -ne 0 ]; then
echo "Single file decoder creation script: FAILED"
exit 1
fi
echo "Single file decoder creation script: PASSED"
cc -Wall -Wextra -Wshadow -Werror -Os -g0 -o $OUT_FILE examples/simple.c
if [ $? -ne 0 ]; then
echo "Compiling simple.c: FAILED"
exit 1
fi
echo "Compiling simple.c: PASSED"
./$OUT_FILE
retVal=$?
rm -f $OUT_FILE
if [ $retVal -ne 0 ]; then
echo "Running simple.c: FAILED"
exit 1
fi
echo "Running simple.c: PASSED"
try_emscripten_build
exit 0