|
1 | 1 | include mk/common.mk
|
| 2 | +include mk/color.mk |
2 | 3 | include mk/toolchain.mk
|
3 | 4 |
|
4 | 5 | OUT ?= build
|
@@ -167,7 +168,7 @@ $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-s
|
167 | 168 | # to the first target after .DEFAULT_GOAL is not set.
|
168 | 169 | .DEFAULT_GOAL :=
|
169 | 170 |
|
170 |
| -WEB_FILES += $(BIN).js \ |
| 171 | +WEB_FILES := $(BIN).js \ |
171 | 172 | $(BIN).wasm \
|
172 | 173 | $(BIN).worker.js
|
173 | 174 | ifeq ("$(CC_IS_EMCC)", "1")
|
@@ -215,6 +216,69 @@ CFLAGS_emcc += -sINITIAL_MEMORY=2GB \
|
215 | 216 |
|
216 | 217 | # used to download all dependencies of elf executable and bundle into single wasm
|
217 | 218 | deps_emcc += $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)
|
| 219 | + |
| 220 | +# check browser MAJOR version if supports TCO |
| 221 | +CHROME_MAJOR := |
| 222 | +CHROME_MAJOR_VERSION_CHECK_CMD := |
| 223 | +CHROME_SUPPORT_TCO_AT_MAJOR := 112 |
| 224 | +CHROME_SUPPORT_TCO_INFO := Chrome supports TCO, you can use Chrome to request the wasm |
| 225 | +CHROME_NO_SUPPORT_TCO_WARNING := Chrome not found or Chrome must have at least version $(CHROME_SUPPORT_TCO_AT_MAJOR) in MAJOR to serve wasm |
| 226 | + |
| 227 | +FIREFOX_MAJOR := |
| 228 | +FIREFOX_MAJOR_VERSION_CHECK_CMD := |
| 229 | +FIREFOX_SUPPORT_TCO_AT_MAJOR := 121 |
| 230 | +FIREFOX_SUPPORT_TCO_INFO := Firefox supports TCO, you can use Firefox to request the wasm |
| 231 | +FIREFOX_NO_SUPPORT_TCO_WARNING := Firefox not found or Firefox must have at least version $(FIREFOX_SUPPORT_TCO_AT_MAJOR) in MAJOR to serve wasm |
| 232 | + |
| 233 | +# FIXME: for Windows |
| 234 | +ifeq ($(UNAME_S),Darwin) |
| 235 | + CHROME_MAJOR_VERSION_CHECK_CMD := "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --version | awk '{print $$3}' | cut -f1 -d. |
| 236 | + FIREFOX_MAJOR_VERSION_CHECK_CMD := /Applications/Firefox.app/Contents/MacOS/firefox --version | awk '{print $$3}' | cut -f1 -d. |
| 237 | +else ifeq ($(UNAME_S),Linux) |
| 238 | + CHROME_MAJOR_VERSION_CHECK_CMD := google-chrome --version | awk '{print $$3}' | cut -f1 -d. |
| 239 | + FIREFOX_MAJOR_VERSION_CHECK_CMD := firefox -v | awk '{print $$3}' | cut -f1 -d. |
| 240 | +endif |
| 241 | +CHROME_MAJOR := $(shell $(CHROME_MAJOR_VERSION_CHECK_CMD)) |
| 242 | +FIREFOX_MAJOR := $(shell $(FIREFOX_MAJOR_VERSION_CHECK_CMD)) |
| 243 | + |
| 244 | +# Chrome |
| 245 | +ifeq ($(shell echo $(CHROME_MAJOR)\>=$(CHROME_SUPPORT_TCO_AT_MAJOR) | bc), 1) |
| 246 | + $(info $(shell echo "$(GREEN)$(CHROME_SUPPORT_TCO_INFO)$(NC)")) |
| 247 | +else |
| 248 | + $(warning $(shell echo "$(YELLOW)$(CHROME_NO_SUPPORT_TCO_WARNING)$(NC)")) |
| 249 | +endif |
| 250 | + |
| 251 | +# Firefox |
| 252 | +ifeq ($(shell echo $(FIREFOX_MAJOR)\>=$(FIREFOX_SUPPORT_TCO_AT_MAJOR) | bc), 1) |
| 253 | + $(info $(shell echo "$(GREEN)$(FIREFOX_SUPPORT_TCO_INFO)$(NC)")) |
| 254 | +else |
| 255 | + $(warning $(shell echo "$(YELLOW)$(FIREFOX_NO_SUPPORT_TCO_WARNING)$(NC)")) |
| 256 | +endif |
| 257 | + |
| 258 | +# used to serve wasm locally |
| 259 | +DEMO_DIR := demo |
| 260 | +DEMO_IP := 127.0.0.1 |
| 261 | +DEMO_PORT := 8000 |
| 262 | + |
| 263 | +# check if demo root directory exists and create it if not |
| 264 | +check-demo-dir-exist: |
| 265 | + $(Q)if [ ! -d "$(DEMO_DIR)" ]; then \ |
| 266 | + mkdir -p "$(DEMO_DIR)"; \ |
| 267 | + fi |
| 268 | + |
| 269 | +# FIXME: without $(info) generates errors |
| 270 | +define cp-web-file |
| 271 | + $(Q)cp $(1) $(DEMO_DIR) |
| 272 | + $(info) |
| 273 | +endef |
| 274 | + |
| 275 | +# WEB_FILES could be cleaned and recompiled, thus do not mix these two files into WEB_FILES |
| 276 | +STATIC_WEB_FILES := assets/html/index.html assets/js/coi-serviceworker.min.js |
| 277 | + |
| 278 | +serve-wasm: $(BIN) check-demo-dir-exist |
| 279 | + $(foreach T, $(WEB_FILES), $(call cp-web-file, $(T))) |
| 280 | + $(foreach T, $(STATIC_WEB_FILES), $(call cp-web-file, $(T))) |
| 281 | + $(Q)python3 -m http.server --bind $(DEMO_IP) $(DEMO_PORT) --directory $(DEMO_DIR) |
218 | 282 | endif
|
219 | 283 |
|
220 | 284 | $(OUT)/%.o: src/%.c $(deps_emcc)
|
@@ -304,6 +368,7 @@ distclean: clean
|
304 | 368 | -$(RM) $(DOOM_DATA) $(QUAKE_DATA)
|
305 | 369 | $(RM) -r $(TIMIDITY_DATA)
|
306 | 370 | $(RM) -r $(OUT)/id1
|
| 371 | + $(RM) -r $(DEMO_DIR) |
307 | 372 | $(RM) *.zip
|
308 | 373 | $(RM) -r $(OUT)/mini-gdbstub
|
309 | 374 | -$(RM) $(OUT)/.config
|
|
0 commit comments