PDCurses-emscriptenを使えば、白黒で動く。
slコマンドをEmscriptenで動かそうとして、悪戦苦闘のした結果のメモです。
emscriptenのインストール場所を自分の環境に合わせて書き直して、ビルド実行
./build.sh
以下の2ファイルが以降の作業で必要となる。
- pdcfont.bmp
- libpdcurses.a
切出した関数ポインタをemscripten_set_main_loopに登録する。
この作業により、Canvasに描画するタイミングをウェブブラウザに与えることが可能になる。 これをやらないと、ビルドできて、いざ表示しても真っ黒い画面という残念な結果になる。
pdcfont.bmpとlibpdcurses.aをコピーするなりして、持ってくる
~/local/emscripten/emcc -O2 -Wall -fPIC -I. -o sl sl.c libpdcurses.a `sdl-config --libs`
cp sl sl.bc
~/local/emscripten/emcc -o sl.html sl.bc --preload-file pdcfont.bmp
cc -O2 -Wall -I.. -Dmain=SDL_main -o sl ../demos/sl.c libpdcurses.a -L/usr/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa
06:47:22.692 ReferenceError: _SDL_RWFromMem is not defined sample.html:7815
06:36:53.879 "run() called, but dependencies remain, so not running" sample.html:61
06:38:12.770 "Cannot find preloaded image pdcicon.bmp" sample.html:61
SDL_Delay called on the main thread! Potential infinite loop, quitting.
こんなエラーがブラウザのコンソールに出力される。
Implementing an asynchronous main loop in C/C++を参考に、ループ部分を関数化して、その関数ポインタを emscripten_set_main_loopに登録すれば解決。
$(BUILD) $(DEMOFLAGS) -o $@ $< $(LDFLAGS)
BUILD = $(CC) $(CFLAGS) -I$(PDCURSES_SRCDIR)
ifeq ($(DEBUG),Y)
CFLAGS = -g -Wall -DPDCDEBUG
else
CFLAGS = -O2 -Wall
endif
#wl
CFLAGS += -fPIC
ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
endif
ifeq ($(shell uname),Darwin)
DEMOFLAGS = -Dmain=SDL_main
endif
LDFLAGS = $(LIBCURSES) $(SLIBS)
LIBCURSES = libpdcurses.a
SLIBS = $(shell sdl-config --libs)