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