diff --git a/Makefile b/Makefile index 567b098..9a19b1d 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,25 @@ -# Quick and dirty Makefile for Desktop + Emscripten build +CC := g++ + +CXXFLAGS := -O3 -std=c++11 -W -Wall -Wextra + +SOURCES := $(wildcard src/*.cpp) $(wildcard src/TypeHandlers/*.cpp) tests.cpp + +OUTPUT := tivars_test + +OBJS = $(patsubst %.cpp, %.o, $(SOURCES)) -EMCC := em++ -GCC := g++ -CPPFLAGS := -O3 -std=c++11 -Wall -SOURCES := tests.cpp src/*.cpp src/TypeHandlers/*.cpp OUTPUT := tivars_test -lib: - $(GCC) $(CPPFLAGS) -o $(OUTPUT) $(SOURCES) +all: $(OUTPUT) + +%.o: %.cpp + $(CC) $(CXXFLAGS) -c $< -o $@ -js: - $(EMCC) -s DISABLE_EXCEPTION_CATCHING=1 $(CPPFLAGS) $(SOURCES) -o $(OUTPUT).html --preload-file assets +$(OUTPUT): $(OBJS) + $(CC) $(CXXFLAGS) $(LFLAGS) $^ -o $@ clean: - rm -rf *.o cmake_install.cmake CMakeCache.txt CMakeFiles $(OUTPUT).html $(OUTPUT).js $(OUTPUT).data $(OUTPUT).html.mem + $(RM) -f $(OBJS) $(OUTPUT) + +.PHONY: all clean + diff --git a/Makefile.emscripten b/Makefile.emscripten new file mode 100644 index 0000000..0eb724a --- /dev/null +++ b/Makefile.emscripten @@ -0,0 +1,44 @@ +CC := em++ + +# Emscripten stuff - todo: add -s INVOKE_RUN=0 for lib version (not .html) +EMFLAGS := --bind --llvm-lto 3 -s ASSERTIONS=0 -s DISABLE_EXCEPTION_CATCHING=1 --preload-file assets + +CXXFLAGS := -O3 -std=c++11 -W -Wall -Wextra $(EMFLAGS) + +asmjs: CXXFLAGS += --closure 1 -s WASM=0 +asmjs-html: CXXFLAGS += --closure 1 -s WASM=0 + +wasm: CXXFLAGS += --closure 0 -s WASM=1 -s "BINARYEN_METHOD='native-wasm,asmjs'" +wasm-html: CXXFLAGS += --closure 0 -s WASM=1 -s "BINARYEN_METHOD='native-wasm,asmjs'" + +SOURCES := $(wildcard src/*.cpp) $(wildcard src/TypeHandlers/*.cpp) tests.cpp + +OUTPUT := tivars_test + +OBJS = $(patsubst %.cpp, %.bc, $(SOURCES)) + +OUTPUT := tivars_test + +asmjs: $(OUTPUT).html +wasm: $(OUTPUT).html + +$(OUTPUT).html: $(OUTPUT).js + +asmjs-html: $(OBJS) + $(CC) $(CXXFLAGS) $(LFLAGS) $^ -o $(OUTPUT).html + +wasm-html: $(OBJS) + $(CC) $(CXXFLAGS) $(LFLAGS) $^ -o $(OUTPUT).html + +all: asmjs-html + +%.bc: %.cpp + $(CC) $(CXXFLAGS) -c $< -o $@ + +$(OUTPUT).js: $(OBJS) + $(CC) $(CXXFLAGS) $(LFLAGS) $^ -o $@ + +clean: + $(RM) -f $(OBJS) $(OUTPUT).js* $(OUTPUT).html* $(OUTPUT).data $(OUTPUT).asm.js $(OUTPUT).was* + +.PHONY: all clean asmjs wasm asmjs-html wasm-html diff --git a/tests.cpp b/tests.cpp index c4a7c2d..45c1704 100644 --- a/tests.cpp +++ b/tests.cpp @@ -75,7 +75,7 @@ testReal42.saveVarToFile("assets/testData", "Real_new"); string test = "Disp 42:Wait 5:toString(42):Pause\nInput A,\"?\":Asdf(123)\nFor(I,1,10)\nThen\nDisp I:For(J,1,10)\nThen\nDisp J\nEnd\nEnd"; cout << "Indented code:" << endl << TH_0x05::reindentCodeString(test) << endl; - +#ifndef __EMSCRIPTEN__ try { auto goodTypeForCalc = TIVarFile::createNew(TIVarType::createFromName("Program"), "Bla", TIModel::createFromName("83PCE")); @@ -89,7 +89,7 @@ testReal42.saveVarToFile("assets/testData", "Real_new"); } catch (runtime_error& e) { cout << "Caught expected exception: " << e.what() << endl; } - +#endif assert(TIVarTypes::getIDFromName("ExactRealPi") == 32);