Building DOOM with scratchbox2

From WebOS Internals
Revision as of 04:38, 6 January 2010 by Destinal (talk | contribs) (packaging might actually work now)
Jump to navigation Jump to search

First, follow the tutorial ScratchBox2_cross_compiling_with_SDL to set up the cross compilation environment.

Next, download the sdlDOOM source code:

wget http://www.libsdl.org/projects/doom/src/sdldoom-1.10.tar.gz
tar xzf sdldoom-1.10.tar.gz
cd sdldoom-1.10

Now run scratchbox2 with the webos / pre mapping file:

$ sb2 -M /srv/preware/cross-compile/staging/mapping-armv7

You will get a different prompt indicating you are in a scratchbox shell, like:

[SB2 mapping-armv7 armv7] $

Run:

./configure --with-sdl-prefix=/usr/local
make 

Build should complete successfully with no problems. Download a DOOM shareware WAD:

wget http://www.libsdl.org/projects/doom/data/doom1.wad.gz
gunzip doom1.wad.gz

Copy the DOOM program binary and wad to root's home directory on the pre:

scp doom doom1.wad  root@pre:

SSH to the device (novaterm would also work to get there, or an on-device terminal)

ssh root@pre

On the device, run DOOM:

./doom


Yay, it should now run. You may want to customize the code for better controls on the device.

Now let's package it up for all your friends to install. You should be back in your sdldoom-1.1.0 directory. For this, we'll use the Palm SDK, so make sure you have it installed.

First off: Unfortunately palm-package doesn't _quite_ make game packages properly. First, we want type to be "game" and palm-package doesn't understand that (will reject it as an invalid type in the 1.3.5 SDK). Secondly, the executables need to be set with executable permissions. For all this, we need a script to fix up the ipk for you.

palm-game-fix (I put it in /usr/local/bin and chmod 755 /usr/local/bin/palm-game-fix)

#!/bin/bash
TMPDIR="fix-game-ipk-tmp.$$"
if [ ! -f "$1" ]; then echo "$1" not found; exit 1; fi
mkdir "$TMPDIR"; cd "$TMPDIR"
ar x "../$1"; tar xvzf data.tar.gz
cd usr/palm/applications/*; chmod 755 *
sed -i 's/"type":.*"web",/"type":     "game",/' appinfo.json
cd ../../../..;  tar cvzf data.tar.gz usr
rm -rf usr; rm "../$1"
ar -r "../$1" *
cd ..;rm -rf "$TMPDIR"


Once you have this, you should be ready to go. Obviously this only needs to be done once.

First make an installation directory with just the files we want to package.

mkdir package
cp doom doom1.wad package
cd package

Next, create a start script that will be launched by the icon for your application. It can do things like changing the working directory (cd) into the right directory and start your program with the right command line arguments, if any.

Create the file start-doom.sh with your favorite text editor like so:

#!/bin/sh
cd /media/cryptofs/apps/usr/palm/applications/com.example.doom
./doom


Create the file appinfo.json with your favorite text editor like so:

{
	"title":    "DOOM",
	"type":     "web",
	"main":     "start-doom.sh",
	"id":       "com.example.doom",
	"vendor":   "example.com",
        "version":  "0.1.0",
        "icon":     "icon.png"
}

Make sure you change id to a reversed domain name like com.example (example.com) but don't use example.com. Get a domain name to use or ask a friend if you can use theirs. This domain should be unique.

Now we need to package it up and fix up the package to be game-compatible. Run:

palm-package .
palm-game-fix *ipk

Now you can do a test install and launch.

palm-install com.example.doom_0.1.0_all.ipk
palm-launch com.example.doom

Hopefully, DOOM should open in all its glory.

Have fun making native apps.