Monday, June 25, 2012

Simple Directmedia Layer (SDL) is a popular library that many games and applications use to access sound and video capabilities on end-user machines. Bada is an operating system for smartphones developed by Samsung Electronics. This article shows how to make SDL work on the bada platform based on my experience with porting ScummVM to bada. The steps involved are:
  • Download and install tools.
  • Compile dependent libraries.
  • Implement missing SDL platform functionality.
  • Create your project using the bada SDK.

Download and install tools

Download the bada SDK.
http://developer.bada.com/apis/index.do

Cygwin. This will be used to build the bibraries.
www.cygwin.com

Download and run setup.exe. You will need to select the following packages: make, autoconf, automake, binutils, pkg-config (maybe others?)

I previously suggested using MingW as the build tool. This almost works well but has a major problem with cross-compiling - the directive AC_CHECK_LIB builds a .EXE and then tests whether the result is executable using test -x. MingW always returns false so the configure script assumes the result was false.

Note the cygwin "make" command sometimes fails handling .po files. You can alternatively use the MingW make, or else use "cs-make" which is part of the bada toolchain.

Next, create the HOME environment variable using Win7 System properties / Advanced / Environment variables.

HOME=c:/home

Then create the file: c:/home/.bash_profile:


BADA_VER=2.0.5
alias mmake=/cygdrive/c/MinGW/bin/mingw32-make.exe
export BADA_SDK=/c/bada/${BADA_VER}
export BADA_LIBS=${BADA_SDK}/Model/WaveWVGA/Target
export ARM_BIN=c:/bada/${BADA_VER}/Tools/Toolchains/ARM/bin
export PATH=${BADA_SDK}/Tools/Toolchains/ARM/bin:~/utils:${PATH}
export CPPFLAGS="-fpic -fshort-wchar -mcpu=cortex-a8 -mfpu=vfpv3 \
                 -mfloat-abi=hard -mlittle-endian -mthumb-interwork -Wno-psabi \
                 -fno-strict-aliasing -fno-short-enums \
                 -I/usr/local/include -Ic:/cygwin/usr/local/include \
                 -Ic:/cygwin/usr/local/include/SDL"
export LDFLAGS="-Wl,--no-enum-size-warning -Lc:/cygwin/usr/local/lib"

Move the bada toolchain versions of rm, ranlib and ar out of the way. You will find these files in the c:/bada/2.0.5/Tools/Toolchains/ARM/bin directory with the following names:
arm-samsung-nucleuseabi-rm.exe
arm-samsung-nucleuseabi-ranlib.exe
arm-samsung-nucleuseabi-ar.exe

These should be moved to a temporary directory or can just be deleted.

Compile dependent libraries

In the ScummVM bada project I used FLAC, libmad, libogg, libpng and zlib. SDL needs a different set of opensource libraries but these should work just as well on bada. Some of the libraries try to build test executables but this cannot work with cross compiling, so the build scripts need a few minor changes.

1. Free Type
http://sourceforge.net/projects/freetype/files/freetype2
edit builds/unix/unix-def.mk

#TOP_DIR := $(shell cd $(TOP_DIR); pwd)
TOP_DIR = .
./configure --host=arm-samsung-nucleuseabi
make

2. SDL ttf
http://www.libsdl.org/projects/SDL_ttf
Edit Makefile.am, comment out showfont and glfont:

#noinst_PROGRAMS = showfont glfont
#showfont_LDADD = libSDL_ttf.la
#glfont_LDADD = libSDL_ttf.la @GL_LIBS@ @MATHLIB@
./configure --host=arm-samsung-nucleuseabi
make

3. JPEG
http://www.ijg.org/
Edit Makefile.am, comment out building sample (non-library) programs

# Executables to build
#bin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom

# Executable sources & libs
#cjpeg_SOURCES    = cjpeg.c rdppm.c rdgif.c rdtarga.c rdrle.c rdbmp.c \
#        rdswitch.c cdjpeg.c
#cjpeg_LDADD      = libjpeg.la
#djpeg_SOURCES    = djpeg.c wrppm.c wrgif.c wrtarga.c wrrle.c wrbmp.c \
#        rdcolmap.c cdjpeg.c
#djpeg_LDADD      = libjpeg.la
#jpegtran_SOURCES = jpegtran.c rdswitch.c cdjpeg.c transupp.c
#jpegtran_LDADD   = libjpeg.la
#rdjpgcom_SOURCES = rdjpgcom.c
#wrjpgcom_SOURCES = wrjpgcom.c
rm ltmain.sh
rm aclocal.m4
libtoolize
autoreconf
./configure --host=arm-samsung-nucleuseabi --disable-shared
make

4. zlib
http://www.zlib.net
Unzip the source code in a folder, open MSYS, go to the zlib folder and issue this command to compile the library:

make LOC="${CPPFLAGS}" -f win32/Makefile.gcc
After compilation, copy zlib.h and zconf.h inside MinGW's include folder and libz.a inside MinGW's lib folder. You can do this using Explorer or by typing these commands in MSYS inside the zlib folder:
cp -p libz.a /usr/local/lib
cp -p zlib.h zconf.h /usr/local/include

5. PNG
http://www.libpng.org/pub/png/libpng.html
Edit configure.ac, comment out the zlib check:

#AC_CHECK_LIB(z, zlibVersion, ,
#    AC_CHECK_LIB(z, ${ZPREFIX}zlibVersion, ,
#                 AC_ERROR([zlib not installed])))
rm ltmain.sh
rm aclocal.m4
libtoolize
autoreconf
./configure --host=arm-samsung-nucleuseabi --disable-shared
make
Note: for some reason I also need to edit the generated Makefile:
DEFAULT_INCLUDES = -I. -I/usr/local/include
6. Tiff library
http://www.remotesensing.org/libtiff
./configure --host=arm-samsung-nucleuseabi --disable-shared
make
7. WEBP library
http://code.google.com/intl/en-US/speed/webp/index.html

8. SDL image
http://www.libsdl.org/projects/SDL_image

./configure --host=arm-samsung-nucleuseabi --disable-shared
make

Implement missing SDL platform functionality.


Create your project using the bada SDK.