forked from EmulatorJS/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.emscripten
255 lines (208 loc) · 6.56 KB
/
Makefile.emscripten
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
HAVE_STATIC_DUMMY ?= 0
ifeq ($(TARGET),)
ifeq ($(LIBRETRO),)
TARGET := retroarch.js
LIBRETRO = dummy
else
TARGET := $(LIBRETRO)_libretro.js
endif
endif
EOPT = USE_ZLIB=1 # Emscripten specific options
EOPTS = $(addprefix -s $(EMPTY), $(EOPT)) # Add '-s ' to each option
OS = Emscripten
OBJ :=
DEFINES := -DRARCH_INTERNAL -DHAVE_MAIN
DEFINES += -DHAVE_FILTERS_BUILTIN
HAVE_PATCH = 1
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_OVERLAY = 1
HAVE_GLSL = 1
HAVE_SCREENSHOTS = 1
HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_CC_RESAMPLER = 1
HAVE_EGL = 1
HAVE_OPENGLES = 1
HAVE_RJPEG = 0
HAVE_RPNG = 1
HAVE_EMSCRIPTEN = 1
HAVE_MENU = 1
HAVE_GFX_WIDGETS = 1
HAVE_RGUI = 1
HAVE_SDL = 0
HAVE_SDL2 = 0
HAVE_ZLIB = 1
HAVE_SHADERPIPELINE = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_STB_FONT = 1
HAVE_CONFIGFILE = 1
HAVE_COMMAND = 1
HAVE_STDIN_CMD = 1
HAVE_CHEATS = 1
HAVE_IBXM = 1
HAVE_CORE_INFO_CACHE = 1
HAVE_7ZIP = 1
HAVE_BSV_MOVIE = 1
HAVE_AL = 1
# WARNING -- READ BEFORE ENABLING
# The rwebaudio driver is known to have several audio bugs, such as
# minor crackling, or the entire page freezing/crashing.
# It works perfectly on chrome, but even firefox has really bad audio quality.
# I should also note, the driver on iOS is completely broken (crashes the page).
# You have been warned.
HAVE_RWEBAUDIO = 0
EMULATORJS = 1
ASYNC ?= 0
PTHREAD ?= 0
LTO ?= 0
WASM ?= 1
DEBUG ?= 0
DEFINES := -DRARCH_INTERNAL -DHAVE_MAIN
DEFINES += -DHAVE_FILTERS_BUILTIN -DNO_MISSING_ASSET_WARNING -DNO_AUTO_CANVAS_RESIZE -DWEB_SCALING -DNO_CANVAS_FULLSCREEN -DNO_INITIAL_CANVAS_RESIZE -DEMULATORJS
HAVE_OPENGL = 0 # not supported
EM_OPENGL ?= 0
HAVE_REGAL ?= 0
HAVE_OPENGLES ?= 1
HAVE_OPENGLES3 ?= 0 #3D cores only
GL_DEBUG ?= 0 # help diagnose GLSL problems (can cause errors in normal operation)
GENERATE_SOURCEMAP ?= 0
FS_DEBUG = 0
# default value: 5242880 (5 MiB)
STACK_MEMORY ?= 8388608
# default value: 16777216 (16 MiB)
HEAP_MEMORY ?= 536870912
# 8388608 ----- 8 MiB (Stack: recommended)
# 16777216 ---- 16 MiB
# 33554432 ---- 32 MiB
# 67108864 ---- 64 MiB
# 134217728 --- 128 MiB
# 268435456 --- 256 MiB (Heap: recommended) (Stack: recommended for some cores [mupen64plus_next])
# 536870912 --- 512 MiB (Heap: needed for some cores [mednafen_psx(_hw), mupen64plus_next])
# 1073741824 -- 1 GiB
# 1610612736 -- 1.5 GiB
# 2147483648 -- 2 GiB
# 4294967296 -- 4 GiB
ifeq ($(LIBRETRO), tyrquake)
LTO = 0
endif
PTHREAD ?= 0
MEMORY ?= 134217728
PRECISE_F32 = 1
OBJDIR := obj-emscripten
#if you compile with SDL2 flag add this Emscripten flag "-s USE_SDL=2" to LDFLAGS:
ifeq ($(HAVE_SDL2), 1)
LIBS += -s USE_SDL=2
DEFINES += -DHAVE_SDL2
endif
LIBS := -s USE_ZLIB=1
LDFLAGS := -L. --no-heap-copy $(LIBS) -s TOTAL_STACK=$(STACK_MEMORY) -s TOTAL_MEMORY=$(HEAP_MEMORY) -s NO_EXIT_RUNTIME=1 -s EXPORTED_RUNTIME_METHODS="['callMain', 'cwrap', 'getValue', 'FS', 'PATH', 'ERRNO_CODES']" \
-s EXPORTED_FUNCTIONS=['_main','_malloc','_load_state','_ejs_set_variable','_simulate_input','_shader_enable','_save_state_info','_set_cheat','_cmd_take_screenshot','_system_restart','_cmd_savefiles','_get_core_options','_cmd_save_state','_supports_states','_reset_cheat','_toggleMainLoop','_save_file_path','_get_disk_count','_set_current_disk','_get_current_disk','_refresh_save_files','_toggle_fastforward','_set_ff_ratio','_toggle_slow_motion','_set_sm_ratio','_toggle_rewind','_set_rewind_granularity','_get_current_frame_count','_ejs_set_keyboard_enabled','_set_vsync'] \
-lidbfs.js \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s GL_ENABLE_GET_PROC_ADDRESS=1 \
-s ALLOW_MEMORY_GROWTH=1 \
--js-library emscripten/library_rwebcam.js \
--js-library emscripten/library_errno_codes.js \
-s MODULARIZE=1 -s 'EXPORT_NAME="EJS_Runtime"'
ifneq (,$(findstring same_cdi,$(TARGET)))
LDFLAGS += -s ASSERTIONS -s DISABLE_EXCEPTION_CATCHING=0
endif
ifeq ($(HAVE_RWEBAUDIO), 1)
LDFLAGS += --js-library emscripten/library_rwebaudio.js
DEFINES += -DHAVE_RWEBAUDIO
endif
ifeq ($(HAVE_AL), 1)
LDFLAGS += -lopenal
DEFINES += -DHAVE_AL
ASYNC = 1
endif
ifeq ($(HAVE_OPENGLES), 1)
ifeq ($(HAVE_OPENGLES3), 1)
LDFLAGS += -s FULL_ES3=1 -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2
else
LDFLAGS += -s FULL_ES2=1 -s MAX_WEBGL_VERSION=2
endif
endif
ifeq ($(EM_OPENGL), 1)
DEFINES += -DEM_OPENGL
ifeq ($(HAVE_REGAL), 1)
LDFLAGS += -s USE_REGAL=1
DEFINES += -DHAVE_REGAL
else
LDFLAGS += -s LEGACY_GL_EMULATION=1 -s GL_UNSAFE_OPTS=0
endif
endif
ifeq ($(GL_DEBUG), 1)
LDFLAGS += -s GL_ASSERTIONS=1 -s GL_DEBUG=1
endif
ifeq ($(FS_DEBUG), 1)
LDFLAGS += -s FS_DEBUG=1
endif
ifneq ($(PTHREAD), 0)
LDFLAGS += -s WASM_MEM_MAX=4294967296 -pthread -s PTHREAD_POOL_SIZE=$(PTHREAD)
CFLAGS += -pthread
HAVE_THREADS=1
else
HAVE_THREADS=0
endif
ifeq ($(ASYNC), 1)
LDFLAGS += -s ASYNCIFY=$(ASYNC) -s ASYNCIFY_STACK_SIZE=131072
ifeq ($(DEBUG), 1)
LDFLAGS += -s ASYNCIFY_DEBUG=1 # -s ASYNCIFY_ADVISE
endif
endif
ifeq ($(GENERATE_SOURCEMAP), 1)
CFLAGS += -g4
CXXFLAGS += -g4
LDFLAGS += -g4 --source-map-base http://localhost:8000/cores/ # -gsource-map
endif
include Makefile.common
CFLAGS += $(DEF_FLAGS) -Ideps -Ideps/stb
libretro :=
ifeq ($(HAVE_STATIC_DUMMY),1)
DEFINES += -DHAVE_STATIC_DUMMY
else
libretro += libretro_emscripten.a
endif
ifeq ($(WASM), 1)
LDFLAGS += -s WASM=1
else
LDFLAGS += -s WASM=0
endif
ifneq ($(V), 1)
Q := @
endif
ifeq ($(DEBUG), 1)
LDFLAGS += -O0 -g -gsource-map -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2 -s ASSERTIONS=1
CFLAGS += -O0 -g -gsource-map -s SAFE_HEAP=1 -s SAFE_HEAP_LOG=1 -s STACK_OVERFLOW_CHECK=2 -s ASSERTIONS=1
else
LDFLAGS += -O3
# WARNING: some optimizations can break some cores (ex: LTO breaks tyrquake)
LDFLAGS += -s PRECISE_F32=$(PRECISE_F32)
ifeq ($(LTO), 1)
LDFLAGS += --llvm-lto 3
endif
CFLAGS += -O3
endif
LDFLAGS += -s STACK_SIZE=131072
#LDFLAGS += --extern-pre-js emscripten/pre.js
CFLAGS += -Wall -Wunused-function -Wno-unused-command-line-argument -I. -Ilibretro-common/include -std=gnu99 $(LIBS)
RARCH_OBJ := $(addprefix $(OBJDIR)/,$(OBJ))
all: $(TARGET)
$(TARGET): $(RARCH_OBJ) $(libretro)
@$(if $(Q), $(shell echo echo LD $@),)
$(Q)$(LD) -o $@ $(RARCH_OBJ) $(libretro) $(LIBS) $(LDFLAGS)
$(OBJDIR)/%.o: %.c
@mkdir -p $(dir $@)
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CC) $(CFLAGS) $(DEFINES) $(EOPTS) -c -o $@ $<
$(OBJDIR)/%.o: %.cpp
@mkdir -p $(dir $@)
@$(if $(Q), $(shell echo echo CXX $<),)
$(Q)$(CXX) $(CXXFLAGS) $(DEFINES) $(EOPTS) -c -o $@ $<
clean:
rm -rf $(OBJDIR)
rm -f $(TARGET)
.PHONY: all clean