| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
if ! [ -x "$(command -v emcc)" ]; then |
| 4 |
echo "Error: emcc could not be found." >&2 |
| 5 |
exit 1 |
| 6 |
fi |
| 7 |
|
| 8 |
set -e |
| 9 |
|
| 10 |
cd "$1" |
| 11 |
shift |
| 12 |
|
| 13 |
export CFLAGS="-fPIC -O2 -I../../target/include $EXTRA_CFLAGS" |
| 14 |
export CXXFLAGS="$CFLAGS -sNO_DISABLE_EXCEPTION_CATCHING $EXTRA_CXXFLAGS" |
| 15 |
export LDFLAGS=" \ |
| 16 |
-L../../target/lib/ -lffi \ |
| 17 |
-sEXPORT_ALL \ |
| 18 |
-sMODULARIZE \ |
| 19 |
-sMAIN_MODULE \ |
| 20 |
-sNO_DISABLE_EXCEPTION_CATCHING \ |
| 21 |
-sWASM_BIGINT \ |
| 22 |
$EXTRA_LD_FLAGS \ |
| 23 |
" |
| 24 |
|
| 25 |
# Rename main functions to test__filename so we can link them together |
| 26 |
ls *c | sed 's!\(.*\)\.c!sed -i "s/main/test__\1/g" \0!g' | bash |
| 27 |
|
| 28 |
# Compile |
| 29 |
ls *.c | sed 's/\(.*\)\.c/emcc $CFLAGS -c \1.c -o \1.o /g' | bash |
| 30 |
ls *.cc | sed 's/\(.*\)\.cc/em++ $CXXFLAGS -c \1.cc -o \1.o /g' | bash |
| 31 |
|
| 32 |
# Link |
| 33 |
em++ $LDFLAGS *.o -o test.js |
| 34 |
cp ../emscripten/test.html . |