#!/usr/bin/bash

mkdir build
cd build

if [ ! -f "metaprogram.exe" ]; then
    clang ../src/metaprogram/metaprogram.cpp ../src/basic/unix.cpp -o metaprogram.exe \
        -nostdlib++ -fno-exceptions -fdiagnostics-absolute-paths -g \
        -Wno-writable-strings \
        -I../src
fi
./metaprogram.exe

emcc -o ../text_editor.html \
    -nostdlib++ -fno-exceptions -fdiagnostics-absolute-paths -g -gsource-map \
    --shell-file=../data/shell.html\
    $profile_flags \
    -Wno-writable-strings \
    -I../src/external/SDL/include \
    -I../src/external/lua/src \
    -I../src/external/glad \
    -I../src/ \
    -L../src/external/SDL/build_web \
    -lm \
    -lSDL3 \
    -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=1gb -msimd128 -s TOTAL_STACK=5MB -s INITIAL_MEMORY=256mb \
    ../src/text_editor/text_editor.cpp \
    ../src/basic/unix.cpp \
    ../src/external/lua/src/lbaselib.c \
    ../src/external/lua/src/lctype.c \
    ../src/external/lua/src/ldo.c \
    ../src/external/lua/src/lgc.c \
    ../src/external/lua/src/liolib.c \
    ../src/external/lua/src/lmem.c \
    ../src/external/lua/src/lopcodes.c \
    ../src/external/lua/src/lstate.c \
    ../src/external/lua/src/ltable.c \
    ../src/external/lua/src/lundump.c \
    ../src/external/lua/src/lzio.c \
    ../src/external/lua/src/lapi.c \
    ../src/external/lua/src/lcode.c \
    ../src/external/lua/src/ldblib.c \
    ../src/external/lua/src/ldump.c \
    ../src/external/lua/src/llex.c \
    ../src/external/lua/src/loadlib.c \
    ../src/external/lua/src/loslib.c \
    ../src/external/lua/src/lstring.c \
    ../src/external/lua/src/ltablib.c \
    ../src/external/lua/src/lutf8lib.c \
    ../src/external/lua/src/lauxlib.c \
    ../src/external/lua/src/lcorolib.c \
    ../src/external/lua/src/ldebug.c \
    ../src/external/lua/src/lfunc.c \
    ../src/external/lua/src/linit.c \
    ../src/external/lua/src/lmathlib.c \
    ../src/external/lua/src/lobject.c \
    ../src/external/lua/src/lparser.c \
    ../src/external/lua/src/lstrlib.c \
    ../src/external/lua/src/ltm.c \
    ../src/external/lua/src/lvm.c \
    ../src/external/glad/glad.c \


cd ..