libnethack pr385

roll parts of pr385 into source tree

This does not take the PR as is.

Unlike the PR, this streamlines and minimizes the integration somewhat:

- use hints/include mechanism instead of creating alternative
  Makefile.dat, Makefile.src, Makefile.top, Makefile.utl in sys/lib;
  those would have been a maintenance nightmare.

- don't have alternative mkmkfile.sh and setup.sh in sys/lib.

- sys/lib/libnethackmain.c differed from sys/unix/unixmain.c by
  very little, so just place a small bit of conditional code at the
  top of sys/unix/unixmain.c instead.

- changed the conditional code bits from __EMSCRIPTEN__ to
  CROSS_TO_WASM.

- You should be able to build the wasm result by:
    cd sys/unix ; sh setup.sh hints/linux.2020 ; cd ../..
    make fetch-lua    (<-one time)
    make WANT_LIBNH all

- You should be able to build LIBNBH by:
    cd sys/unix ; sh setup.sh hints/linux.2020 ; cd ../..
    make fetch-lua    (<-one time)
    make CROSS_TO_WASM=1 all

As it is currently coded, winshim.c requires C99.
This commit is contained in:
Adam Powers
2020-08-26 19:22:00 -07:00
committed by nhmall
parent 741e6fd5b7
commit dc2d757399
28 changed files with 1555 additions and 120 deletions

77
sys/lib/hints/wasm Normal file
View File

@@ -0,0 +1,77 @@
#-PRE xxxx
# enscripten WebAssembly config
WANT_WASM=1
WASM_DEBUG=1
WASM_DATA_DIR=$(NHSROOT)/src/wasm-data
# toolchain
EMCC=emcc
EMAR=emar rcu
EMRANLIB=emranlib
# link flags
EMCC_LFLAGS=-s SINGLE_FILE=1
EMCC_LFLAGS=-s WASM=1
EMCC_LFLAGS+=-s ALLOW_TABLE_GROWTH
EMCC_LFLAGS+=-s ASYNCIFY -s ASYNCIFY_IMPORTS='["local_callback"]'
EMCC_LFLAGS+=-O3
EMCC_LFLAGS+=-s MODULARIZE
EMCC_LFLAGS+=-s EXPORTED_FUNCTIONS='["_main", "_shim_graphics_set_callback"]'
EMCC_LFLAGS+=-s EXPORTED_RUNTIME_METHODS='["cwrap", "ccall", "addFunction", "removeFunction", "UTF8ToString", "getValue", "setValue"]'
EMCC_LFLAGS+=-s ERROR_ON_UNDEFINED_SYMBOLS=0
EMCC_LFLAGS+=--embed-file wasm-data@/
# For a list of EMCC settings:
# https://github.com/emscripten-core/emscripten/blob/master/src/settings.js
# WASM C flags
EMCC_CFLAGS=
EMCC_CFLAGS+=-Wall
EMCC_CFLAGS+=-Werror
#EMCC_CFLAGS+=-s DISABLE_EXCEPTION_CATCHING=0
EMCC_DEBUG_CFLAGS+=-s ASSERTIONS=1
#EMCC_DEBUG_CFLAGS+=-s ASSERTIONS=2
EMCC_DEBUG_CFLAGS+=-s STACK_OVERFLOW_CHECK=2
EMCC_DEBUG_CFLAGS+=-s SAFE_HEAP=1
EMCC_DEBUG_CFLAGS+=-s LLD_REPORT_UNDEFINED=1
#EMCC_DEBUG_CFLAGS+=-s EXCEPTION_DEBUG=1
#EMCC_DEBUG_CFLAGS+=-fsanitize=undefined -fsanitize=address -fsanitize=leak
#EMCC_DEBUG_CFLAGS+=-s EXIT_RUNTIME
EMCC_PROD_CFLAGS+=-O3
# Nethack C flags
CFLAGS+=-DSYSCF -DSYSCF_FILE=\"/sysconf\" -DSECURE
CFLAGS+=-g -I../include -DNOTPARMDECL
CFLAGS+=-Wall
CFLAGS+=-Werror
CFLAGS+=-DGCC_WARN
# NetHack sources control
CFLAGS+=-DDLB
CFLAGS+=-DHACKDIR=\"$(HACKDIR)\"
CFLAGS+=-DDLB
#CFLAGS+=-DGREPPATH=\"/usr/bin/grep\"
CFLAGS+=-DNOMAIL
ifdef WASM_DEBUG
EMCC_CFLAGS+=$(EMCC_DEBUG_CFLAGS)
else
EMCC_CFLAGS+=$(EMCC_PROD_CFLAGS)
endif
# installation config
# hackdir is the wasm / emscripten embed data root directory
HACKDIR=/
CHOWN=/usr/bin/true
CHGRP=/usr/bin/true
GAMEPERM = 0700
VARFILEPERM = 0600
VARDIRPERM = 0700
INSTDIR=$(HACKDIR)
VARDIR=$(HACKDIR)
#-POST
# no post