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.

11 comments:

  1. Great. Have you another idea to port any emulator on it, then?

    I could start working on UAE4Droid porting on Bada...I am a nostalgic Amiga folk. :) And SDL is the key for a human time porting of it.

    ReplyDelete
  2. Hi, I had a quick look at the UAE4Droid code and I suspect a bada port would be possible once this project is ready.

    ReplyDelete
  3. Yeah, I thought so :)

    Is there any way I could help you in this porting?

    ReplyDelete
  4. You sure can... could you please try and follow the above steps for building the libraries and let me know how you go.

    ReplyDelete
    Replies
    1. Hi,

      I have followed your instructions as promised and had no major troubles.

      I would like to add some notes for them I had to do:
      1.
      HOME environment variabled changed to /home (or cygwin translated them as /cygdrive/c/home causing troubles for bada gcc getting the sources)

      BADA_SDK environment variable on the bash profile changed to:
      export BADA_SDK=/cygdrive/c/bada/${BADA_VER}

      2. libtool cygwin package is needed for libtoolize

      3.SDL ttf and SDL image packages search for sdl_config binary before searching the includes. So even copying the SDL includes (and renaming the minimal configuration), it was not sufficient, so skipping the search on configure / Makefile file was mandatory.

      4.For jpeg, I have forced to use cs-make or the fixed make 3.81 version (https://projects.coin-or.org/BuildTools/wiki/current-issues#) for not getting the "*** multiple target patterns. Stop." message.

      5.I had to compile zlib in this way
      CHOST=arm-samsung-nucleuseabi make

      6.I have commented the generation of mkg3states for tiff library.

      7.For libpng, I have replaced the symlink created by make install onto /usr/local/include to the real file placed on /usr/local/include/libpng15. However the build worked fine without modifying the Makefile.

      8.Commented the examples build on libwebp build.

      (9. at least in libpng 1.5.12) the file is called unixddef.mk

      Delete
  5. Hi Meis,

    Glad to hear you were able to build the support libraries. I think the next step would be to create a project in the bada SDK, specifying the libraries in the linker setup page, then try to build and see what errors you get.

    The project could be loosely based on the ScummVM port where the SDL main function is run inside a bada worker thread. The outer application thread would receive events from bada and store then in some container - the SDL event function would read the events from the container and convert them into SDL events. Access to the continer needs to be controlled with a mutex.

    I'm currently in the middle of another hobby project, porting SmallBASIC to MoSync (to run on android) so might not get around to the SDL bada port for a little while - but I'd be happy to offer any assistance if you wanted to get a head start with this. I suggest storing any code on github to allow others to contribute.

    Cheers,
    Chris

    ReplyDelete
    Replies
    1. Hi,
      SmallBasic on Android? Great. Even thought I was thinking the Microsoft SmallBasic, the first time I have read your sentence...and before looking on: http://smallbasic.sourceforge.net/?q=node/1039 ..it seemed bizzare at first :)

      Well, right now, I am evaluating to substitute UAE4Droid engine from SDL/SDL-mixer to cocos2dx/cocosDenshion, since the latter have already the bada binaries. My fear is about the SDL porting is too much time consuming and too beyond my actual skills than changing the app engine.

      Good luck with the SmallBasic porting! :)
      Cheers,
      Simone

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Hi giorgos_gs,
      I have only the depedent compiled libraries following Chris instruction but still the SDL platform core files need to be implemented (third point on Chris outline).

      Personally, I suggest you to evaluate your app could be ported on cocos2dx/cocosDenshion if it is not so complex and you are targetting bada.

      If you could help me porting SDL together with the Chris assistance, it would be great.

      Ps. please remove @ from your post and use at least "-at-". I wouldn't like spammers attacking you :)

      Delete
    4. Simone,

      My app is made on SDL and its complex. I better not port it at all than port it to something else. Can anyone write (have access) on the SDL forums (http://www.sdl-forum.org/) to ask for help? I am sure someone with SDL skills will help. I want to help but my skills are limited.

      Delete
  6. Hi Simone,

    Do you think we can bring this project to life? How can I help?

    ReplyDelete