I usually use the GNU gcc/g++ compiler to compile PEBL, but have also tried the clang/llvm option as it is available under xcode on OSX. For the most part, they are interchangeable, but because of different warning levels, some of the code that might have only given a deprecated warning under GCC gives a fatal compile-time error under CLANG. So the first step was to fix any of these. The goal here was simply to compile PEBL to native code under a new compiler, and not worry yet about emscripten.
This all worked fairly easily. I forget all the things I needed to do, but many of them silenced warnings I had received as compilers and standards became more strict. There were a few times when I had to redefine char * to const char * to avoid a string literal warning, but it was mostly innocuous.
Next, I wanted to get rid of a lot of code that probably wouldn't work in emscripten (or if it would, it might be hard to handle and I'd want to take care of that some other time). The simplest way to do this was to define a c preprocessor symbol and have it cull out any classes and code that shouldn't be required. I also created a new Makefile and removed some of the class files from the compile list.
The list includes:
- Parallel port access code
- Serial port access code
- Movie playback (supported via waave)
- Networking code supporting TCP/IP (this will probably be turned back on later to support remove data saving)
- Sound recording support
With a bunch more banging, I was eventually able to compile into a version that ran natively--so far so good. The next step was to try compiling via emscripten.
~/src/emscripten-incoming/emmake make -f Makefile.em -j 6
This is all on linux. Note that I am using the '-incoming' branch of emscripten, and I have it saved in ~/src. Also, I'm pleased that the -j argument works, which allows compiling multiple files simultaneously. Within the Makefile, the only thing I really had to change (aside from defining -DPEBL_EMSCRIPTEN) was to change the target name specified with the -o option from -o bin/pebl to -o bin/pebl.bc I did this so that I could have a parallel binary and bytecode living in the same development branch. So, when the above command completed, I was left with a file called bin/pebl.bc that emscripten can deal with.
~/src/emscripten-incoming/emcc -O2 --closure 0 bin/pebl.bc --embed-file test.pbl --preload-file pebl.bmp --preload-file DejaVuSans.ttf --embed
-file pebl-lib -o bin/pebl.html
Finally, there were a few workarounds I needed to do regarding unimplemented SDL functions. These mainly involved the SDL_TTF library. In my default branch, I used the following SDL_TTF functions, which were not available:
I changed my code to (for the time being) not use these. I suspect that TTF_WasInit() is really not relevant--this is a double-checker to ensure that a library was properly loaded, but for emscripten we can probably assume it was. I'm not as sure about the other two--I changed them to use the non-UTF8 versions, but this might cause problems when trying to read translations--something to deal with down the road.
Stay tuned for future updates. The next post will describe steps I took to conform to emscripten file system limitations, which explains most of the long line above.