800722ccd9a4948e2fb064d4a2fc2a51ba983ebe
[henge/webcc.git] / src / .make / buildc_emcc.mk
1 ##################################################
2 #Desc: Web Build System
3 #Author: Mihrtec LLC
4 #Date: 2016
5 ##################################################
6 #Compile Overrides for web
7 ##################################################
8 #redefine EXE directory for web platform
9 EXEDIR := $(BINDIR)/web/js
10 #EMCC targets .js "executables"
11 APPSUFFIX := .js
12 #EMCC provides ports of each of these, so remove them
13 #and recalculate CLIBS
14 LIBS := $(filter-out SDL2 SDL2_image SDL2_ttf, $(LIBS))
15 CLIBS := $(patsubst %,-l%,$(LIBS))
16 #Override targets to make .bc files
17 CTARG := $(CTARG:.o=.bc)
18 #Expand the list of plain-text functions into what emcc expects
19 EXPORT_FUNCS := $(patsubst %,'_%',$(EXPORT_FUNCS))
20 EXPORT_LIST := $(shell echo "$(EXPORT_FUNCS)" | sed -e 's@ @, @g')
21 #Mark all remaining libs "missing" since they need to be built for emcc
22 MISSINGLIBS := $(LIBS)
23 #Set XTLibDir to one for bytecodes
24 XTLIBDIR := $(XTLIBDIR)/bc
25 #Override Automake vars
26 AMGEN := emconfigure $(AMGEN)
27 AMCONF := emconfigure $(AMCONF)
28 AMMAKE := emmake
29
30 #Set up emscripten APPFLAGS
31 APPFLAGS += --separate-asm
32 APPFLAGS += -s ALLOW_MEMORY_GROWTH=1
33 APPFLAGS += -s FORCE_FILESYSTEM=1
34 #APPLFAGS += --pre-js pre.js
35
36 #Set up emscripten flags for CC
37 CFLAGS += -s EXPORTED_FUNCTIONS="[$(EXPORT_LIST)]"
38 CFLAGS += -I$(XTDIR) -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s USE_SDL_TTF=2
39
40 #Directory structure for web targets
41 #Dirs for source files
42 HTSRCDIR := $(REPOROOT)/html
43 JSSRCDIR := $(HTSRCDIR)/js
44 #Dirs for targets
45 HTDIR := $(EXEDIR)
46 JSDIR := $(HTDIR)/js
47
48 #Discover each type of object supported
49 HTSRC := $(wildcard $(HTSRCDIR)/*.html)
50 JSSRC := $(wildcard $(JSSRCDIR)/*.js)
51 WEBSRC := $(HTSRC) $(JSSRC)
52
53 #Translate sources into their required targets in APPDIR
54 WEBTARG := $(patsubst $(HTSRCDIR)/%,$(HTDIR)/%,$(WEBSRC))
55
56 #Add APPDEPS for all web objects so they must be created
57 #at build time, before compilation of the main executable
58 APPDEPS += $(WEBOBJ)
59
60 #Later, we will use WEBTARG to define rules for "making"
61 #these targets (with a cp action) and cleaning (with rm)
62