Difference between revisions of "Compiling ScummVM/Windows CE"

From ScummVM :: Wiki
Jump to navigation Jump to search
(WIP save)
(updated instructions for the new cegcc compiler in the trunk)
Line 88: Line 88:
you can find it right [http://users.uoa.gr/~knakos/scummvm/libraries/wince-gcc-libs.tar.bz2 here].
you can find it right [http://users.uoa.gr/~knakos/scummvm/libraries/wince-gcc-libs.tar.bz2 here].


Please note that many of those libraries have been officially ported to winCE
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.
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.
We generally cannot comment on how well they will work with ScummVM.
Line 145: Line 145:
== Compiling using the GCC toolchain ==
== Compiling using the GCC toolchain ==


The VLC port of GCC requires some prep work before it's ready for action.
First, you need to download and install the [http://cegcc.sf.net/ cegcc] cross compiler. More specifically, you need the mingw32 variety (without the posix layer emulation that is). The package also includes a working gdb debugger for debugging the applications.
There are two major problems with it:
It does not honor the <tt>#pragma pack()</tt> 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 ([http://www.cygwin.org 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 [http://www.gnu.org/software/binutils/ 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
[http://download.videolan.org/pub/testing/wince/patches/ 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: <tt>/usr/local/wince/cross-tools</tt>)
 
Make and make install. You may need to manually run ranlib on some generated libs
during making.
 
==== GCC ====
 
Checkout the [http://gcc.gnu.org/ 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 [http://download.videolan.org/pub/testing/wince/patches/ GCC patch] (maybe a little fuzz here as well).
:* Then, patch <tt>gcc/stor-layout.c</tt> with the patch described [http://gcc.gnu.org/ml/gcc-patches/2006-10/msg01115.html here].
:* Finally, in <tt>gcc/config/arm/arm.h</tt>, 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 <tt>wince</tt>.
CD into it and create a file called <tt>build.sh</tt> with the following stuff (substitute PREFIX_TO_CROSS_COMPILER), and run it:<br>
{| style="padding: 1em; border: 1px dashed #2f6fab; color: black; background-color: #f9f9f9; line-height: 1.1em"
|<tt>export PATH=PREFIX_TO_CROSS_COMPILER/bin:$PATH</tt><br>
<tt>../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</tt><br>
<tt>make install</tt>
|}
 
==== Finish up ====
 
We need to copy over some stuff from the full GCC tarball.
Get [http://download.videolan.org/pub/testing/wince/wince-arm-gcc4.0.0-cvs-linux-crosscompiler-20050517.tar.bz2 the binary tarball] and unpack it somewhere.
:* Copy recursively all of <tt>usr/local/wince/cross-tools/include/</tt> into your <tt>PREFIX_TO_CROSS_COMPILER/include</tt>.
:* Copy all of the libs in <tt>usr/local/wince/cross-tools/lib</tt> into your <tt>PREFIX_TO_CROSS_COMPILER/lib</tt> (except libiberty.a).
:* CD into your <tt>PREFIX_TO_CROSS_COMPILER/arm-wince-pe/lib</tt> 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 ===
=== ScummVM ===
''Assuming you have installed the toolchain in its default place''
Here is the procedure for building ScummVM:
 
This is the procedure for building ScummVM, provided the compiler is patched as described above:


* Build libraries from source
* Build libraries from source
Line 256: Line 186:
|}
|}
''Try <tt>make libz.a</tt> for libz. Also DrMcCoy reported that he had to include "<tt>typedef long _off_t; typedef _off_t  off_t;</tt>" into <tt>unistd.h</tt>''
''Try <tt>make libz.a</tt> for libz. Also DrMcCoy reported that he had to include "<tt>typedef long _off_t; typedef _off_t  off_t;</tt>" into <tt>unistd.h</tt>''
''WARNING: These instructions have been written with the VLC GCC compiler in mind. Exact command lines may differ slightly from these shown aboe''




Line 273: Line 204:


* Build
* Build
cd into <tt>backends/platform/wince/</tt>, edit the Makefile supplying the prefix to you arm-wince-gcc installation at the <tt>wince_gcc_root</tt> variable (the <tt>PREFIX_TO_CROSS_COMPILER</tt> mentioned above). Finally type <tt>make dist</tt>.
cd into <tt>backends/platform/wince/</tt>, edit the Makefile to your needs (usually you don't have to do this). Finally type <tt>make dist</tt> if you have edited the Makefile for a non-plugin build, <tt>make dist-plugins</tt> for the plugin case, or more simply <tt>make all</tt> which invokes the required build automatically.

Revision as of 15:09, 6 November 2007

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 Microsoft 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 versions equal to 0.9.0 or 0.9.1 there are two ways to compile:

Version 0.10.0 builds with the VLC GCC cross compiler.


For the current builds (trunk), official ScummVM releases use the cegcc GCC cross compiler. We try not to break builds with VS2005 but this can in no way be guaranteed as we do not longer use those tools. With some minor tweaking the code should be able to compile with VS tools too.


Now you may be asking yourselves why we have been through so many compiler changes. There are absolutely critical reasons for switching between them. For example, the migration from evc to VS is mandatory, as C++ templates introduced through core code evolution in the trunk of ScummVM cause the evc 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 (which is free) does not support Windows CE (at least at the time of writing this). Further, the latest change from our semi-custom VLC GCC port to cegcc is mandated because building dlls which are required by the plugins is broken in the former. Fortunately we do not perceive any more compiler changes in the future. CEGCC is well maintained and even if it is not updated in the future (which seems unlikely) it is a darn good wince cross compiler as it is :-)

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 often, 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 from asking if you don't know what you're doing here. The developers cannot be burdened with the task of answering questions for your specific build setup; the community although may provide you with answers.

Compiling using the GCC toolchain

First, you need to download and install the cegcc cross compiler. More specifically, you need the mingw32 variety (without the posix layer emulation that is). The package also includes a working gdb debugger for debugging the applications.

ScummVM

Here is the procedure for building ScummVM:

  • 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

Try make libz.a for libz. Also DrMcCoy reported that he had to include "typedef long _off_t; typedef _off_t off_t;" into unistd.h WARNING: These instructions have been written with the VLC GCC compiler in mind. Exact command lines may differ slightly from these shown aboe


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 to your needs (usually you don't have to do this). Finally type make dist if you have edited the Makefile for a non-plugin build, make dist-plugins for the plugin case, or more simply make all which invokes the required build automatically.