2019-08-28 10:20:42 -07:00
|
|
|
#!/bin/sh
|
2019-08-27 06:36:06 -07:00
|
|
|
|
|
|
|
# Temporary compiled binary
|
|
|
|
OUT_FILE="tempbin"
|
|
|
|
|
|
|
|
# Optional temporary compiled WebAssembly
|
|
|
|
OUT_WASM="temp.wasm"
|
|
|
|
|
2020-06-30 09:40:15 -07:00
|
|
|
# Source files to compile using Emscripten.
|
|
|
|
IN_FILES="examples/emscripten.c"
|
|
|
|
|
|
|
|
# Emscripten build using emcc.
|
|
|
|
emscripten_emcc_build() {
|
|
|
|
# Compile the the same example as above
|
2020-07-29 03:33:39 -07:00
|
|
|
CC_FLAGS="-Wall -Wextra -Wshadow -Werror -Os -g0 -flto"
|
2020-06-30 09:40:15 -07:00
|
|
|
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
|
|
|
|
# Did compilation work?
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Compiling ${IN_FILES}: FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Compiling ${IN_FILES}: PASSED"
|
|
|
|
rm -f $OUT_WASM
|
|
|
|
}
|
|
|
|
|
|
|
|
# Emscripten build using docker.
|
|
|
|
emscripten_docker_build() {
|
|
|
|
docker container run --rm \
|
|
|
|
--volume $PWD:/code \
|
|
|
|
--workdir /code \
|
2020-07-07 03:10:12 -07:00
|
|
|
emscripten/emsdk:latest \
|
2020-06-30 09:40:15 -07:00
|
|
|
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
|
|
|
|
# Did compilation work?
|
|
|
|
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 using emcc or docker.
|
|
|
|
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)"
|
|
|
|
}
|
|
|
|
|
2019-08-27 06:36:06 -07:00
|
|
|
# Amalgamate the sources
|
2019-08-27 16:01:39 -07:00
|
|
|
./create_single_file_decoder.sh
|
2019-08-27 06:36:06 -07:00
|
|
|
# Did combining work?
|
|
|
|
if [ $? -ne 0 ]; then
|
2019-08-27 16:01:39 -07:00
|
|
|
echo "Single file decoder creation script: FAILED"
|
2019-08-27 06:36:06 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-08-27 16:01:39 -07:00
|
|
|
echo "Single file decoder creation script: PASSED"
|
2019-08-27 06:36:06 -07:00
|
|
|
|
|
|
|
# Compile the generated output
|
2020-07-29 03:33:39 -07:00
|
|
|
cc -Wall -Wextra -Wshadow -Werror -Os -g0 -o $OUT_FILE examples/simple.c
|
2019-08-27 06:36:06 -07:00
|
|
|
# Did compilation work?
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Compiling simple.c: FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Compiling simple.c: PASSED"
|
|
|
|
|
|
|
|
# Run then delete the compiled output
|
|
|
|
./$OUT_FILE
|
|
|
|
retVal=$?
|
|
|
|
rm -f $OUT_FILE
|
|
|
|
# Did the test work?
|
|
|
|
if [ $retVal -ne 0 ]; then
|
|
|
|
echo "Running simple.c: FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Running simple.c: PASSED"
|
|
|
|
|
2020-06-30 09:40:15 -07:00
|
|
|
# Try Emscripten build if emcc or docker command is available.
|
|
|
|
try_emscripten_build
|
2019-08-27 06:36:06 -07:00
|
|
|
|
|
|
|
exit 0
|