Compiling ScummVM/Windows CE

From ScummVM :: Wiki
< Compiling ScummVM
Revision as of 11:30, 29 April 2007 by Jubanka (talk | contribs) (→‎ScummVM: clarification)
Jump to navigation Jump to search

So you want to roll your own binary for the ScummVM Windows CE port? The first thing to ask yourself is do you really need to compile it? The official PocketScumm binaries are "good enough" for more than the average user. Also, bear in mind that the compilation procedure is seldom as simple as unpack-build and that, probably, you'll have to know your way around projects, makefiles and editing appropriately the source files.
Still reading? Good :-)
Many people are put off by the sheer volume of work which has to take place in order to get a successful build. Things are not that bad though as, hopefully, this document tries to describe. More than often you may find that once you set up you build environment right, there's only minimal work to be done to build any version of PocketScumm. Alright, ready? Let's go :-)

Get your gear together

The first thing you need to do is decide on the compiler and grab all required libraries.

Compilers

Versions before 0.9.0 use the Embedded Visual C development environment. More specifically you can use either evc3 or evc4 for those versions. Most of the following instructions for building with VS2005 adhere to these builds as well.

For the current 0.9.0 branch and the trunk there are two ways to compile:

The former is used for building the 0.9.0 branch. The migration from evc to VS is mandatory, as C++ templates introduced through core code evolution in the trunk of ScummVM cause the evc to compilers to crash with 'Internal compiler error'. Unfortunately the migration is not completely successful as VS2005 (no service packs) introduces incorrect optimization in release builds, leading to workarounds in the source and compilation of specific files with no optimizations at all. Also, note that Visual Studio Express does not support Windows CE.

The latter method (GCC) is slated to be used for building PocketScumm, starting with the next major release (0.10.0). As such, the trunk currently contains only the necessary Makefile for building with GCC. It does not contain any VS2005 project files, athough we may in the future opt to also provide project files for it as well.

Libraries

ScummVM depends on quite a few external libraries to handle content. These are:

Lossless audio compression for sound files.
Decoding of MPEG-2 video content.
Fixed point implementation of the OGG Vorbis algorithm, also for sound files.
MP3 sound files.
Handles all backend screen drawing.
Compressing/Decompressing files.

Arisme has done and excellent job in porting all these libraries to Windows CE, along the process of porting ScummVM itself.

For Microsoft toolchain builds, you can find all of them on his webpage both in source/patch form and as pre-built binaries. Usually, you don't need to rebuild these libraries so we recommend to use the binaries. To relieve you even further from the hassle, we have prepared a precompiled lib/header pack which is available here. This package contains all that is peripheral to ScummVM and is required for builds.

For GCC toolchain builds, the libraries need to be further patched in order to successfully compile. The patches are available here and are accumulated. This means that are direct patches to the original source versions of the libraries, that they include Arisme's patches and are not incremental to them. A precompiled lib/header pack is available for GCC builds as well and you can find it right here.

Please note that many of those libraries have been officially ported to winCE after the work done by Arisme or, newer versions are available for them. We generally cannot comment on how well they will work with ScummVM. The more adventurous of you may want to give them a shot, but we find that these work well enough for our purposes.

Compiling using Microsoft tools

  • Build libraries from source

If you downloaded prebuilt libraries, you may skip this step. We will not document the process of compiling individual libraries. Generally, you should download the source and patch from Arisme's site, perform the patch and use the included project files to build.

  • Place library files in appropriate places.

You need two things: The library header files (*.h) and the actual libraries (*.lib). There's no place in particular where it would be good to put these files. Just make sure that the VS compiler's additional include directories option points additionally to the directory (-ies) where your library header files live, and the linker's additional library directories to the *.lib files directory (-ies). For ScummVM 0.9.1, the VS2005 files assume that the directories lib and libinclude are situated in backends/wince/missing.

  • Open the Project

For versions older than 0.9.1, project files can be found in directories dists/msevc3 and dists/msevc4 of the source tree. For 0.9.1 the project files are in dists/msvc8-wince. Open PocketScumm.vcw or PocketScumm.sln, whatever is applicable. In the workspace that opens you should be able to see several projects, the main one being the "scummvm" project and the others being the scummvm engines which are built as libraries.
A common problem which occurs here stems from the requirement that the project files have to be in CR/LF format, or else the tools will error out with various errors while opening them. (This unfortunately happens as tagging usually takes place on a non-Windows machine ( :-) ), plus some shortcomings of CVS. Hopefully SVN remedies this.)
Another point to note is that evc4 can "import" evc3 project files and VS2005 can import project files from both.

  • Build

Press F7 :-)
This is not a fool proof procedure. You may get from zero fatal compilation errors to several thousand. Please be patient and try to make sense of what the tool is reporting. More than usual, the very first error the tool reports is the one you should attend to before re-trying the build. If you can't make heads or tails out of it, you may try asking for help in the forums, but *please* refrain yourself from asking if you don't know what you're doing here. The developers cannot be burdened by the task of answering questions for your specific build setup.


Compiling using the GCC toolchain

The VLC port of GCC requires some prep work before it's ready for action. There are two major problems with it: It does not honor the #pragma pack() directive and there is a store layout bug for packed structs. Hence, it needs to be rebuilt. As a welcome aside though, the procedure described in the following subsections can be applied to linux or cygwin based environment. This means that the cross compiler can be installed onto a Windows (Cygwin) machine as well.

It has been reported that the packages needed for Cygwin are: gcc, make, sed, bison, flex, texinfo, patch, cvs, gettext, gettext-devel, perl, svn. Also some CR/LF conversion may be needed by utilities such as dos2unix and unix2dos.

Cross compiler

The build process is carried out in two steps, first the binutils and then the gcc cross compiler. Begin by designating a directory where all source downloads and build will take place.

(Note: the patches by the VLC guys target specific GCC/binutils versions. We'll rebuild those exact versions as they are good enough for the time being.)

Binutils

Checkout the binutils source, as described in the GNU Binutils page but designating a revision date as well:

cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login
{enter "anoncvs" as the password}
cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co -D 20050514 binutils

CD into the root of the source tree and patch with the three VLC binutils patches (may patch with a little fuzz). Configure the build:

./configure --target=arm-wince-pe --prefix=PREFIX_TO_CROSS_COMPILER

(PREFIX_TO_CROSS_COMPILER is the path where the cross compiler will be installed. In linux it is: /usr/local/wince/cross-tools)

Make and make install. You may need to manually run ranlib on some generated libs during making.

GCC

Checkout the GCC source:

svn -q checkout -r {20050511} svn://gcc.gnu.org/svn/gcc/trunk gcc

(Note the date. It does not match the date in the VLC patches. Also, later revisions contain severe bugs)

Now come the patches.

  • First apply the VLC GCC patch (maybe a little fuzz here as well).
  • Then, patch gcc/stor-layout.c with the patch described here.
  • Finally, in gcc/config/arm/arm.h, stick the following define somewhere (before the architecture define is OK):
#define HANDLE_PRAGMA_PACK_PUSH_POP

In the root of the GCC source tree, make a directory called wince. CD into it and create a file called build.sh with the following stuff (substitute PREFIX_TO_CROSS_COMPILER), and run it:

export PATH=PREFIX_TO_CROSS_COMPILER/bin:$PATH

../configure --with-gcc --with-gnu-ld --with-gnu-as --target=arm-wince-pe --prefix=PREFIX_TO_CROSS_COMPILER --disable-threads --disable-nls --enable-languages=c++ --disable-win32-registry --disable-interwork --disable-multilib
make install

Finish up

We need to copy over some stuff from the full GCC tarball. Get the binary tarball and unpack it somewhere.

  • Copy recursively all of usr/local/wince/cross-tools/include/ into your PREFIX_TO_CROSS_COMPILER/include.
  • Copy all of the libs in usr/local/wince/cross-tools/lib into your PREFIX_TO_CROSS_COMPILER/lib (except libiberty.a).
  • CD into your PREFIX_TO_CROSS_COMPILER/arm-wince-pe/lib and make the following two symbolic links:
ln -s ../../lib/corelibc.lib crt0.o
ln -s ../../lib/coredll.lib c.lib

Done :-)

(Note: In linux, it is much easier to get the binary tarball, extract it into the root of the filesystem, and then build the binutils and GCC replacing essentially the offending files (C++ compiler etc). This final step in this case is not be required)

ScummVM

Assuming you have installed the toolchain in its default place

This is the procedure for building ScummVM, provided the compiler is patched as described above:

  • Build libraries from source

You may skip this step if you downloaded the prebuilt library package. Download the original library source tarball (those in Arisme's site are OK). As an exception, get the Tremor snapshot from here. Download the diffs from here and patch the libraries. You need to configure and make each library, except the SDL library which sports a customly created (and lame :-) ) Makefile. Here are the typical parameters to the configure scripts:

  • FLAC:
CFLAGS="-D__stdcall= -D_WIN32_WCE=300 -I/usr/local/wince/cross-tools/include" LDFLAGS=-L/usr/local/wince/cross-tools/lib CC=arm-wince-pe-gcc ./configure --host=arm-wince-pe --target=arm-wince-pe --without-ogg --without-xmms -without-libiconv --without-id3lib
  • mad:
CFLAGS="-D__stdcall= -D_OFF_T_ -I/usr/local/wince/cross-tools/include" LDFLAGS=-L/usr/local/wince/cross-tools/lib CC=arm-wince-pe-gcc ./configure --host=arm-wince-pe --target=arm-wince-pe --disable-nls
  • mpeg2dec:
CFLAGS="-D__stdcall= -D_OFF_T_ -I/usr/local/wince/cross-tools/include" LDFLAGS=-L/usr/local/wince/cross-tools/lib CC=arm-wince-pe-gcc ./configure --host=arm-wince-pe --target=arm-wince-pe
  • Tremor:
CFLAGS="-D__stdcall= -D_OFF_T_ -I/usr/local/wince/cross-tools/include" LDFLAGS=-L/usr/local/wince/cross-tools/lib CC=arm-wince-pe-gcc ./autogen.sh --host=arm-wince-pe --target=arm-wince-pe
  • libz:
CFLAGS="-D__stdcall= -D_OFF_T_ -D_WIN32_WCE -D_MSC_VER=666" CC=arm-wince-pe-gcc AR="arm-wince-pe-ar cru" RANLIB=arm-wince-pe-ranlib ./configure --libdir=/usr/local/wince/cross-tools/lib --includedir=/usr/local/wince/cross-tools/include

You may also have to do some minor manual edits to the config.h files. (libmad's one springs to mind, in which you have to undefine HAVE_STDINT_H)

You just make each library after configuring. The SDL library has no configuration script - you just make

  • Place library files in appropriate places.

Take a look at the Makefile to check out where the headers and libs are expected. Currently they need to be under backends/platform/wince/libs/ in directories include and lib. Also note that the Makefile expects the libraries to have somewhat more "funky" names than their default. This has been done for compatibility reasons with the evc built libs. Just rename the libraries according to the Makefile, or edit the Makefile to match the default naming.

  • Build

cd into backends/platform/wince/, edit the Makefile supplying the prefix to you arm-wince-gcc installation at the wince_gcc_root variable (the PREFIX_TO_CROSS_COMPILER mentioned above). Finally type make dist.