Skip to content

Commit

Permalink
More emscripten stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed May 1, 2017
1 parent fb53eb0 commit 8d3e48c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
29 changes: 19 additions & 10 deletions 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

44 changes: 44 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions tests.cpp
Expand Up @@ -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"));
Expand All @@ -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);

Expand Down

0 comments on commit 8d3e48c

Please sign in to comment.