Problem compiling on Linux
Good morning! I'm running into an issue when attempting to compile BrowserHack from source on Linux, specifically Fedora 24.
I've installed the latest emscripten release from the sdk tgz available on the emscripten website.
After cloning this project, I had to edit the EMCC variable in build.sh to point to my emscripten installation. After that, attempting to run ./build.sh results in:
$ ./build.sh
Copying Makefiles.
( cd src ; make )
make[1]: Entering directory '/home/mmorsi/workspace/tmp/BrowserHack/src'
touch ../src/config.h-t
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc -O3 -I../include -c monst.c
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc -O3 -I../include -c objects.c
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc -O3 -I../include -c -o alloc.o alloc.c
make[2]: Entering directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc -O3 -I../include -c -o makedefs.o makedefs.c
makedefs.c:361:14: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Data);
^~~~~~~~~~~~~~
makedefs.c:361:14: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Data);
^
"%s",
makedefs.c:560:14: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Code);
^~~~~~~~~~~~~~
makedefs.c:560:14: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Code);
^
"%s",
makedefs.c:1235:14: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Data);
^~~~~~~~~~~~~~
makedefs.c:1235:14: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Data);
^
"%s",
makedefs.c:1357:17: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Code);
^~~~~~~~~~~~~~
makedefs.c:1357:17: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Code);
^
"%s",
makedefs.c:1398:14: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Code);
^~~~~~~~~~~~~~
makedefs.c:1398:14: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Code);
^
"%s",
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc -O3 -I../include -c -o dlb.o dlb.c
makedefs.c:1714:14: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Code);
^~~~~~~~~~~~~~
makedefs.c:1714:14: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Code);
^
"%s",
makedefs.c:1869:17: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Code);
^~~~~~~~~~~~~~
makedefs.c:1869:17: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Code);
^
"%s",
makedefs.c:1894:17: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
Fprintf(ofp,Dont_Edit_Code);
^~~~~~~~~~~~~~
makedefs.c:1894:17: note: treat the string as an argument to avoid this
Fprintf(ofp,Dont_Edit_Code);
^
"%s",
8 warnings generated.
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc -O3 -I../include -c ../sys/unix/unixres.c
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc makedefs.o -o makedefs
make[2]: Leaving directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
make[2]: Entering directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
make[2]: Entering directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc --pre-js ../win/web/mount_nodefs.js -o makedefs.js makedefs.o ../src/monst.o ../src/objects.o
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc --pre-js ../win/web/mount_nodefs.js -o makedefs.js makedefs.o ../src/monst.o ../src/objects.o
make[2]: Entering directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
make[2]: Entering directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc --pre-js ../win/web/mount_nodefs.js -o makedefs.js makedefs.o ../src/monst.o ../src/objects.o
/home/mmorsi/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc --pre-js ../win/web/mount_nodefs.js -o makedefs.js makedefs.o ../src/monst.o ../src/objects.o
js ./makedefs.js -o
js ./makedefs.js -p
js ./makedefs.js -z
js ./makedefs.js -m
./makedefs.js:9: ReferenceError: require is not defined
Makefile:198: recipe for target '../include/onames.h' failed
make[2]: *** [../include/onames.h] Error 3
make[2]: Leaving directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
Makefile:488: recipe for target '../include/onames.h' failed
make[1]: *** [../include/onames.h] Error 2
make[1]: *** Waiting for unfinished jobs....
./makedefs.js:9: ReferenceError: require is not defined
Makefile:200: recipe for target '../include/pm.h' failed
make[2]: *** [../include/pm.h] Error 3
make[2]: Leaving directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
Makefile:490: recipe for target '../include/pm.h' failed
make[1]: *** [../include/pm.h] Error 2
./makedefs.js:9: ReferenceError: require is not defined
./makedefs.js:9: ReferenceError: require is not defined
Makefile:202: recipe for target '../src/monstr.c' failed
make[2]: *** [../src/monstr.c] Error 3
make[2]: Leaving directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
Makefile:492: recipe for target 'monstr.c' failed
make[1]: *** [monstr.c] Error 2
Makefile:204: recipe for target '../include/vis_tab.h' failed
make[2]: *** [../include/vis_tab.h] Error 3
make[2]: Leaving directory '/home/mmorsi/workspace/tmp/BrowserHack/util'
Makefile:494: recipe for target '../include/vis_tab.h' failed
make[1]: *** [../include/vis_tab.h] Error 2
make[1]: Leaving directory '/home/mmorsi/workspace/tmp/BrowserHack/src'
Makefile:92: recipe for target 'nethack' failed
make: *** [nethack] Error 2
Continuing on... it seems sys/unix/Makefile.utl attempts to prepend the ../win/web/mount_nodefs.js source to the 'compiled' js output. This file contains the 'require' lines throwing the interpreter off.
Additionally the unix/Makefile.utl attempts to invoke the generated js with the 'js' command, which after investigating, resolves to the mozilla js interpreter shipped w/ firefox (hence 'require' failing in this context).
Is this the intended behaviour? Any suggestions as to why this would not compile?
Thank you
I dug into this a bit a little later and realized the 'js' command in the makefiles should actually be 'node' for the nodejs interpreter.
After changes all the references from 'js' to 'node' in the sys/unix/Makefile* files (see patch below), and installing the 'byacc' and 'flex' packages for the necessary tools. I was able to get this to compile.
Unfortunately bringing it up in the web browser doesn't not result in much, yes the page loads and the browser console say 'successfull compiled asm.js code' but the main play area is unresponsive.
Looking at the emscripten code a bit, it seems the logic is pretty coupled to the "Kongregate" Web service.
Is communication w/ Kongregate a hard requirement for this project? I would be great to be able to install this in a standalone manner, so that users could run their own browserhack servers.
[mmorsi@localhost BrowserHack]$ git diff
diff --git a/build.sh b/build.sh
index 26f59c6..343f7b7 100755
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,8 @@
#!/bin/bash
set -e
-EMCC=~/src/emscripten/emcc
+#EMCC=~/src/emscripten/emcc
+EMCC=~/workspace/tmp/emsdk-portable/emscripten/1.37.9/emcc
JOBS=4
MYDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
diff --git a/sys/unix/Makefile.dat b/sys/unix/Makefile.dat
index 57837c2..44a48b2 100644
--- a/sys/unix/Makefile.dat
+++ b/sys/unix/Makefile.dat
@@ -83,60 +83,60 @@ GEM_RSC.RSC:
data: data.base ../util/makedefs.js
- js ../util/makedefs.js -d
+ node ../util/makedefs.js -d
rumors: rumors.tru rumors.fal ../util/makedefs.js
- js ../util/makedefs.js -r
+ node ../util/makedefs.js -r
quest.dat: quest.txt ../util/makedefs.js
- js ../util/makedefs.js -q
+ node ../util/makedefs.js -q
oracles: oracles.txt ../util/makedefs.js
- js ../util/makedefs.js -h
+ node ../util/makedefs.js -h
# note: 'options' should have already been made when include/date.h was created
options: ../util/makedefs.js
- js ../util/makedefs.js -v
+ node ../util/makedefs.js -v
spec_levs: ../util/lev_comp.js \
bigroom.des castle.des endgame.des gehennom.des knox.des medusa.des \
mines.des oracle.des sokoban.des tower.des yendor.des
- js ../util/lev_comp.js bigroom.des
- js ../util/lev_comp.js castle.des
- js ../util/lev_comp.js endgame.des
- js ../util/lev_comp.js gehennom.des
- js ../util/lev_comp.js knox.des
- js ../util/lev_comp.js medusa.des
- js ../util/lev_comp.js mines.des
- js ../util/lev_comp.js oracle.des
- js ../util/lev_comp.js sokoban.des
- js ../util/lev_comp.js tower.des
- js ../util/lev_comp.js yendor.des
+ node ../util/lev_comp.js bigroom.des
+ node ../util/lev_comp.js castle.des
+ node ../util/lev_comp.js endgame.des
+ node ../util/lev_comp.js gehennom.des
+ node ../util/lev_comp.js knox.des
+ node ../util/lev_comp.js medusa.des
+ node ../util/lev_comp.js mines.des
+ node ../util/lev_comp.js oracle.des
+ node ../util/lev_comp.js sokoban.des
+ node ../util/lev_comp.js tower.des
+ node ../util/lev_comp.js yendor.des
touch spec_levs
quest_levs: ../util/lev_comp.js \
Arch.des Barb.des Caveman.des Healer.des Knight.des Monk.des \
Priest.des Ranger.des Rogue.des Samurai.des Tourist.des Valkyrie.des \
Wizard.des
- js ../util/lev_comp.js Arch.des
- js ../util/lev_comp.js Barb.des
- js ../util/lev_comp.js Caveman.des
- js ../util/lev_comp.js Healer.des
- js ../util/lev_comp.js Knight.des
- js ../util/lev_comp.js Monk.des
- js ../util/lev_comp.js Priest.des
- js ../util/lev_comp.js Ranger.des
- js ../util/lev_comp.js Rogue.des
- js ../util/lev_comp.js Samurai.des
- js ../util/lev_comp.js Tourist.des
- js ../util/lev_comp.js Valkyrie.des
- js ../util/lev_comp.js Wizard.des
+ node ../util/lev_comp.js Arch.des
+ node ../util/lev_comp.js Barb.des
+ node ../util/lev_comp.js Caveman.des
+ node ../util/lev_comp.js Healer.des
+ node ../util/lev_comp.js Knight.des
+ node ../util/lev_comp.js Monk.des
+ node ../util/lev_comp.js Priest.des
+ node ../util/lev_comp.js Ranger.des
+ node ../util/lev_comp.js Rogue.des
+ node ../util/lev_comp.js Samurai.des
+ node ../util/lev_comp.js Tourist.des
+ node ../util/lev_comp.js Valkyrie.des
+ node ../util/lev_comp.js Wizard.des
touch quest_levs
dungeon: dungeon.def ../util/makedefs.js ../util/dgn_comp.js
- js ../util/makedefs.js -e
- js ../util/dgn_comp.js dungeon.pdf
+ node ../util/makedefs.js -e
+ node ../util/dgn_comp.js dungeon.pdf
spotless:
-rm -f spec_levs quest_levs *.lev $(VARDAT) dungeon dungeon.pdf
diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src
index 9da96c2..3c594db 100644
--- a/sys/unix/Makefile.src
+++ b/sys/unix/Makefile.src
@@ -509,7 +509,7 @@ tile.c: ../win/share/tilemap.c $(HACK_H)
# hack.h depends on makedefs' output, so we know makedefs will be
# up to date before being executed
../include/date.h: $(VERSOURCES) $(HACK_H)
- js ../util/makedefs.js -v
+ node ../util/makedefs.js -v
lint:
diff --git a/sys/unix/Makefile.utl b/sys/unix/Makefile.utl
index 671f99c..3c5db4f 100644
--- a/sys/unix/Makefile.utl
+++ b/sys/unix/Makefile.utl
@@ -195,13 +195,13 @@ makedefs.o: makedefs.c $(CONFIG_H) ../include/permonst.h \
../include/dlb.h ../include/patchlevel.h ../include/qtext.h
../include/onames.h: makedefs.js
- js ./makedefs.js -o
+ node ./makedefs.js -o
../include/pm.h: makedefs.js
- js ./makedefs.js -p
+ node ./makedefs.js -p
../src/monstr.c: makedefs.js
- js ./makedefs.js -m
+ node ./makedefs.js -m
../include/vis_tab.h: makedefs.js
- js ./makedefs.js -z
+ node ./makedefs.js -z
# makedefs -z makes both vis_tab.h and vis_tab.c, but writes the .h first
../src/vis_tab.c: ../include/vis_tab.h
@@ -331,7 +331,7 @@ tile2beos: tile2beos.o $(TEXT_IO)
tilemap.js: ../win/share/tilemap.c $(HACK_H)
$(CC) $(CFLAGS) $(LFLAGS) $(UTIL_CFLAGS) -o tilemap.js ../win/share/tilemap.c $(LIBS)
../src/tile.c: tilemap.js
- js ./tilemap.js
+ node ./tilemap.js
../include/tile.h: ../win/share/tile.h
cp ../win/share/tile.h ../include/tile.h