1#!/bin/sh 2 3# Temporary compiled binary 4OUT_FILE="tempbin" 5 6# Optional temporary compiled WebAssembly 7OUT_WASM="temp.wasm" 8 9# Source files to compile using Emscripten. 10IN_FILES="examples/emscripten.c" 11 12# Emscripten build using emcc. 13emscripten_emcc_build() { 14 # Compile the the same example as above 15 CC_FLAGS="-Wall -Wextra -Wshadow -Werror -Os -g0 -flto" 16 emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES 17 # Did compilation work? 18 if [ $? -ne 0 ]; then 19 echo "Compiling ${IN_FILES}: FAILED" 20 exit 1 21 fi 22 echo "Compiling ${IN_FILES}: PASSED" 23 rm -f $OUT_WASM 24} 25 26# Emscripten build using docker. 27emscripten_docker_build() { 28 docker container run --rm \ 29 --volume $PWD:/code \ 30 --workdir /code \ 31 emscripten/emsdk:latest \ 32 emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES 33 # Did compilation work? 34 if [ $? -ne 0 ]; then 35 echo "Compiling ${IN_FILES} (using docker): FAILED" 36 exit 1 37 fi 38 echo "Compiling ${IN_FILES} (using docker): PASSED" 39 rm -f $OUT_WASM 40} 41 42# Try Emscripten build using emcc or docker. 43try_emscripten_build() { 44 which emcc > /dev/null 45 if [ $? -eq 0 ]; then 46 emscripten_emcc_build 47 return $? 48 fi 49 50 which docker > /dev/null 51 if [ $? -eq 0 ]; then 52 emscripten_docker_build 53 return $? 54 fi 55 56 echo "(Skipping Emscripten test)" 57} 58 59# Amalgamate the sources 60./create_single_file_decoder.sh 61# Did combining work? 62if [ $? -ne 0 ]; then 63 echo "Single file decoder creation script: FAILED" 64 exit 1 65fi 66echo "Single file decoder creation script: PASSED" 67 68# Compile the generated output 69cc -Wall -Wextra -Wshadow -Werror -Os -g0 -o $OUT_FILE examples/simple.c 70# Did compilation work? 71if [ $? -ne 0 ]; then 72 echo "Compiling simple.c: FAILED" 73 exit 1 74fi 75echo "Compiling simple.c: PASSED" 76 77# Run then delete the compiled output 78./$OUT_FILE 79retVal=$? 80rm -f $OUT_FILE 81# Did the test work? 82if [ $retVal -ne 0 ]; then 83 echo "Running simple.c: FAILED" 84 exit 1 85fi 86echo "Running simple.c: PASSED" 87 88# Try Emscripten build if emcc or docker command is available. 89try_emscripten_build 90 91exit 0 92