Skip to content

Building the Emscripten port

Mátyás Mustoha edited this page Mar 19, 2016 · 11 revisions

1. Build SDL2_mixer

I'll download it to dependencies/SDL2_mixer, build in dependencies/SDL2_mixer/build, and make install to dependencies/SDL2_mixer/installdir. You can use different locations, just don't forget to change the paths in the following steps.

cd dependencies
hg clone https://hg.libsdl.org/SDL_mixer SDL2_mixer
cd SDL2_mixer
mkdir build && cd build
emconfigure ../configure \
  CFLAGS="-O3 -s USE_OGG=1 -s USE_VORBIS=1" \
  --prefix=`pwd`/../installdir \
  --disable-sdltest --enable-shared \
  --enable-music-ogg --disable-music-mp3 \
  --disable-music-flac --disable-music-midi --disable-music-mod
emmake make install

The SDL2_mixer lib should be now in installdir/lib/.

2. Add the include path

You have to tell where SDL_mixer.h is:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb20bb5..cddfdcf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -133,6 +133,10 @@ if (BUILD_STATIC_LIBS)
 	set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "YAML: Build testing and parse tools" FORCE)
 	set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "YAML: Build contrib stuff in library" FORCE)
 	add_subdirectory(dependencies/yaml-cpp-noboost)
+
+	# SDL2_mixer
+	include_directories(dependencies/SDL2_mixer/installdir/include/SDL2)
 else()
 	find_package(ENet REQUIRED)
 	find_package(yaml-cpp REQUIRED)

3. Build SMW

unzip data.zip
mkdir build_js && cd build_js
emconfigure cmake .. -DNO_NETWORK=1 -DDISABLE_SYSLIB_CHECKS=1 -DUSE_SDL2_LIBS=1
emmake make smw

This will create smw.bc.

4. Link SDL2_mixer to SMW

You have to use all the same C/C++ build flags for linking too:

emcc -o smw.html \
  ./Binaries/Release/smw.bc \
  ../dependencies/SDL2_mixer/installdir/lib/libSDL2_mixer.so \
  -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png","bmp"]' \
  -s USE_ZLIB=1 -s USE_OGG=1 -s USE_VORBIS=1 \
  -s ALLOW_MEMORY_GROWTH=1 -s DISABLE_EXCEPTION_CATCHING=0 -s EXCEPTION_DEBUG=1 \
  -O3 --preload-file ../data@data

(Don't worry about the unresolved symbol: _Exit warning)

5. Enjoy

You should now have smw.html, ready to play!

Clone this wiki locally