Difference between revisions of "Compiling ScummVM/RPI"

From ScummVM :: Wiki
Jump to navigation Jump to search
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Cross-compiling ScummVM on for Raspberry Pi ==
== Cross-compiling ScummVM for Raspberry Pi ==


== Installing the official Raspberry Pi cross-compiler on PC ==
== Installing the official Raspberry Pi cross-compiler on PC ==
Line 7: Line 7:
  <nowiki>git clone https://github.com/raspberrypi/tools.git</nowiki>
  <nowiki>git clone https://github.com/raspberrypi/tools.git</nowiki>


It will get cloned to a directory called ''tools'' at your current location.
It will get cloned to a directory called ''tools'' at our current location.


Add it to the ''PATH'' environment variable so that we have the cross-compiler binaries available from our scummvm building directory. For example, if my Raspberry Pi ''tools'' repository ended cloned in ''tools'' under my ''home'' directory, I would do:
Add it to the ''PATH'' environment variable so that we have the cross-compiler binaries available from our ScummVM building directory. For example, if the Raspberry Pi ''tools'' repository was cloned in ''tools'' under our user's ''home'' directory, we would do:


  <nowiki>export PATH=$PATH:$HOME/tools/arm-bcm2708/arm-linux-gnueabihf/bin</nowiki>
  <nowiki>export PATH=$PATH:$HOME/tools/arm-bcm2708/arm-linux-gnueabihf/bin</nowiki>


After adding the cross-compiler executables directory to ''PATH'', we should be able to run ''arm-linux-gnueabihf-gcc'', ''arm-linux-gnueabihf-g++'', etc... just try. They should yield an error because you pass them no input files, but that's expected. It's just a test so we know we have the cross-compiler installed and accessible.
After adding the cross-compiler executables directory to ''PATH'', we should be able to run ''arm-linux-gnueabihf-gcc'', ''arm-linux-gnueabihf-g++'', etc. They should yield an error because we pass them no input files, but that's expected. This is just a test so we know we have the cross-compiler installed and accessible.


== Installing the needed Raspberry Pi headers and libraries on PC ==
== Installing the needed Raspberry Pi headers and libraries on PC ==


We need to copy over the '''/usr''', '''/lib''' and '''/opt''' directories from your Raspbian SD Card to your host PC (the computer were you will do the cross-compilation) for the needed headers and libraries to be available.
We need to copy over the '''/usr''', '''/lib''' and '''/opt''' directories from the Raspbian SD Card to the '''host PC''' (the computer where we will do the cross-compilation) for the needed headers and libraries to be available.


Of course, first you'll have to install any additional libraries from Raspbian running on the Pi before expecting them to be available so, if you want compile ScummVM with FLAC support, you should have installed the libflac development libraries on the Pi beforehand.
Of course, first we'll have to install any additional libraries from Raspbian running on the Pi before expecting them to be available so, eg. if we want to compile ScummVM with FLAC support, we should have installed the libflac development libraries on the Pi in advance.


As an example, on the Raspberry Pi running Raspbian (Buster) OS 3.2 (January 2020) we can execute the following to install third party libraries that ScummVM features and game engines need:
As an example, on the Raspberry Pi running Raspbian (Buster) OS 3.2 (January 2020) we can execute the following to install third party libraries that ScummVM needs for its features and various game engines:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y --no-install-recommends \
              libsdl2-dev \
              liba52-0.7.4-dev \
              libjpeg62-turbo-dev \
              libmpeg2-4-dev \
              libogg-dev \
              libvorbis-dev \
              libflac-dev \
              libmad0-dev \
              libpng-dev \
              libtheora-dev \
              libfaad-dev \
              libfluidsynth-dev \
              libfreetype6-dev \
              libcurl4-openssl-dev  \
              libsdl2-net-dev \
              libspeechd-dev \
              zlib1g-dev \
              libfribidi-dev \
              libglew-dev


  <nowiki>
On the '''host PC''' first we make sure we have some pre-requisite packages installed for the build.
sudo apt-get update
  sudo apt-get update
sudo apt-get upgrade
sudo apt-get upgrade
sudo apt-get install -y --no-install-recommends \
sudo apt-get install -y make pkg-config
            libsdl2-dev \
Then we export the path where we will copy the directories from the RPi SD card into, and then we manually copy them. One option (shown in the example commands below) is to copy the Raspberry Pi headers and libraries to ''/opt/rpi_root'', but any other path with the right permissions for our user (within common sense) should be ok:
            liba52-0.7.4-dev \
            libjpeg62-turbo-dev \
            libmpeg2-4-dev \
            libogg-dev \
            libvorbis-dev \
            libflac-dev \
            libmad0-dev \
            libpng-dev \
            libtheora-dev \
            libfaad-dev \
            libfluidsynth-dev \
            libfreetype6-dev \
            libcurl4-openssl-dev  \
            libsdl2-net-dev \
            libspeechd-dev \
            zlib1g-dev
</nowiki>


First we export the path where we will copy these into, and then we will manually copy them. I choose /opt/rpi_root, but any other path with the right permissions for your user and common sense is going to be ok:
mkdir -p /opt/rpi_root
export RPI_ROOT=/opt/rpi_root
cd <Raspbian_SD_card_mountpoint_directory>
cp -R usr lib opt $RPI_ROOT


  <nowiki>
The above copying of files has the unfortunate side-effect that many symbolic links that were copied over are now invalid, particularly those linking to absolute paths. Fortunately, we can remedy this situation by downloading and running a python script that will fix those links:
mkdir -p /opt/rpi_root
 
export RPI_ROOT=/opt/rpi_root
  <nowiki>wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
cd <SD_mountpoint_directory>
chmod +x sysroot-relativelinks.py
cp -R usr lib opt $RPI_ROOT
./sysroot-relativelinks.py $RPI_ROOT</nowiki>
</nowiki>
 
Note that the last command above is supposed to run the python script <code>sysroot-relativelinks.py</code>. You will need to have python3 installed on your host PC for that. The script assumes a location for your python binary, but that may not be a valid path on your host PC. An alternative to that would be to run:
$(which python3) ./sysroot-relativelinks.py $RPI_ROOT
Finally, update the ''PATH'' variable to be preceded by the ''RPI_ROOT'' path, since this is required for proper detection of ''libcurl'' related files by ScummVM's ''configure'' script.
<nowiki>export PATH=$RPI_ROOT:$PATH</nowiki>


== Configuring ScummVM ==
== Configuring ScummVM ==


Now we configure scummvm buildsystem so it knows what backend we want and where is our raspberry pi local sysroot living, containing the Raspberry Pi headers and libs the cross-compiler and linker will need. In this example configuration, we disable additional libs, and debug symbols since it's intended for final users.
First, we should make sure have the latest version of the ScummVM code locally (using ''git clone'' or ''git pull'' appropriately).
 
Then, navigate inside the local ''scummvm'' source code folder.
 
Now we can configure the ScummVM build system so it knows what backend we target and where our Raspberry Pi ''local sysroot'' is located, containing the Raspberry Pi headers and libraries the cross-compiler and linker will need. In this example configuration, we disable debug symbols since it's intended for final users.
 
mkdir -p ./scummvmDist
PKG_CONFIG_SYSROOT_DIR=$RPI_ROOT PKG_CONFIG_LIBDIR=$RPI_ROOT/usr/lib/arm-linux-gnueabihf/pkgconfig ./configure --host=raspberrypi --with-sdl-prefix=$RPI_ROOT/usr --with-png-prefix=$RPI_ROOT/usr --disable-debug --enable-release --prefix=$(pwd)/scummvmDist
 
Remember that we have already exported the ''RPI_ROOT'' environment variable previously and updated the ''PATH'' environment variable to be preceded by the ''RPI_ROOT'' path and succeeded by the path to the Raspberry Pi toolchain bin folder (as shown in the previous steps).
 
On the Raspberry Pi, ''SDL2'' will always be used, since it provides graphics acceleration.


./configure --host=raspberrypi --with-sdl-prefix=$RPI_ROOT/usr  --disable-debug --enable-release --enable-optimizations --disable-mt32emu --disable-flac --disable-mad --disable-vorbis --disable-tremor --disable-fluidsynth --disable-taskbar --disable-timidity --disable-alsa
Unfortunately, the official toolchain for cross-compiling for Pi is, as of yet, using an old ''gcc'' version (4.3.9) and hence, the configure script may fail to detect the ''FluidSynth'' library specifically. FluidSynth and MT-32 emulation are features that are very demanding on CPU processing power so it should be ok to skip them entirely. Alternatively, one could seek out a more up-to-date ''armhf'' toolchain for the cross-compilation, such as this [https://github.com/Pro/raspi-toolchain/releases Raspberry Pi toolchain by Stefan Profanter (Pro)] which, in its 1.0.1 version, uses ''gcc'' version 8.3.0 and reportedly "supports all new Raspberry PIs (ARMv7), and the older ones, including Zero, A, B, B+ (ARMv6) with newer GCCs."


Remember you should have exported the RPI_ROOT enviroment variable previously.
'''Note 1:''' If installing the Raspberry Pi toolchain by Stefan Profanter (Pro), it's important to read the instructions from the README file ([https://github.com/Pro/raspi-toolchain also available from the main page of the repository]). Specifically, this toolchain needs to be installed in ''/opt/cross-pi-gcc'' since it's not location independent.
On the raspberrypi host, SDL2 will be always used since it provides graphics acceleration.


''Note:'' If you are building ScummVM on your RPi itself, you might run out of memory during linking. If you use GNU ld for compiling you can try exporting LDFLAGS="-Wl,--no-keep-memory" before running configure. This tells GNU ld to optimize for memory usage.
'''Note 2:''' If building ScummVM directly on the Raspberry Pi / Raspbian itself, it's possible to run out of memory during the final linking process of the build. If GNU ''ld'' is used for compiling, then execute the following before running ''configure'':
<nowiki>export LDFLAGS="-Wl,--no-keep-memory"</nowiki>
This tells GNU ''ld'' to optimize the linking for memory usage.


== Compiling ScummVM ==
== Compiling ScummVM ==


Run the following commands:
Provided that the configure step was executed successfully, we can proceed to run the following commands in order to build ScummVM:
  <nowiki>
  make clean
make clean
make -j$(nproc)
make -j$(nproc)</nowiki>
make install


== Installing ScummVM on the Raspberry Pi ==
== Installing ScummVM on the Raspberry Pi ==


Simply copy over the resulting ''scummvm'' executable to your Raspberry Pi (Raspbian OS) SD Card. A good idea is to create a ''scummvm'' folder in your ''/home/pi'' directory on the Raspian OS SD Card, and put the executable there along with any games you want to use with it.
In this step we simply have to copy over the resulting files in our distribution folder ''scummvmDist'' to our Raspberry Pi (Raspbian OS) SD Card. A good idea is to create a ''scummvm'' folder in our ''/home/pi'' directory on the Raspian OS SD Card, and put the distribution folder contents there along with any games we want to use with it.
 
In order to have the text-to-speech feature available for ScummVM we should also install the speech-dispatcher package and a text-to-speech engine (as per the instructions in this pertinent [https://github.com/scummvm/scummvm/pull/1808 Pull Request])
 
For example we'd need to execute the following on our Raspbian OS on the Pi in order to use the espeak-ng text-to-speech engine:
<nowiki>sudo apt-get install --no-install-recommends speech-dispatcher speech-dispatcher-espeak-ng</nowiki>
 
'''Note 1:''' There's a number of optional additional files that can be copied in the ScummVM directory along with the ''scummvm'' executable, which ScummVM uses for themes, GUI translations and as auxilliary data files for some of the game engines. Such list of files is shown [[HOWTO-Release#Binaries|here]]. These files should be already present in your distribution folder scummvmDist, if you used the "prefix" switch in configure and the make install command as shown above.
 
'''Note 2:''' As of yet, there are some known issues with the ALSA sound driver especially in conjunction with the PulseAudio system on Raspbian OS (3.2). Having PulseAudio installed (by default it is not installed) may result to bad sound output in ScummVM (and other apps).
 
== External Links ==
* [https://github.com/raspberrypi/tools Official Raspberry Pi toolchain repository]
* [https://github.com/Pro/raspi-toolchain/ Alternative Raspberry Pi toolchain by Stefan Profanter (Pro)]
* [http://ulasdikme.com/projects/raspberry/Qt_for_raspberrypi.php Reference article and source for sysroot-relativelinks.py script solution]

Latest revision as of 05:05, 17 December 2020

Cross-compiling ScummVM for Raspberry Pi

Installing the official Raspberry Pi cross-compiler on PC

We will clone the Raspberry Pi tools repository which includes the cross-compiler we need:

git clone https://github.com/raspberrypi/tools.git

It will get cloned to a directory called tools at our current location.

Add it to the PATH environment variable so that we have the cross-compiler binaries available from our ScummVM building directory. For example, if the Raspberry Pi tools repository was cloned in tools under our user's home directory, we would do:

export PATH=$PATH:$HOME/tools/arm-bcm2708/arm-linux-gnueabihf/bin

After adding the cross-compiler executables directory to PATH, we should be able to run arm-linux-gnueabihf-gcc, arm-linux-gnueabihf-g++, etc. They should yield an error because we pass them no input files, but that's expected. This is just a test so we know we have the cross-compiler installed and accessible.

Installing the needed Raspberry Pi headers and libraries on PC

We need to copy over the /usr, /lib and /opt directories from the Raspbian SD Card to the host PC (the computer where we will do the cross-compilation) for the needed headers and libraries to be available.

Of course, first we'll have to install any additional libraries from Raspbian running on the Pi before expecting them to be available so, eg. if we want to compile ScummVM with FLAC support, we should have installed the libflac development libraries on the Pi in advance.

As an example, on the Raspberry Pi running Raspbian (Buster) OS 3.2 (January 2020) we can execute the following to install third party libraries that ScummVM needs for its features and various game engines:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y --no-install-recommends \
             libsdl2-dev \
             liba52-0.7.4-dev \
             libjpeg62-turbo-dev \
             libmpeg2-4-dev \
             libogg-dev \
             libvorbis-dev \
             libflac-dev \
             libmad0-dev \
             libpng-dev \
             libtheora-dev \
             libfaad-dev \
             libfluidsynth-dev \
             libfreetype6-dev \
             libcurl4-openssl-dev  \
             libsdl2-net-dev \
             libspeechd-dev \
             zlib1g-dev \
             libfribidi-dev \
             libglew-dev

On the host PC first we make sure we have some pre-requisite packages installed for the build.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y make pkg-config

Then we export the path where we will copy the directories from the RPi SD card into, and then we manually copy them. One option (shown in the example commands below) is to copy the Raspberry Pi headers and libraries to /opt/rpi_root, but any other path with the right permissions for our user (within common sense) should be ok:

mkdir -p /opt/rpi_root
export RPI_ROOT=/opt/rpi_root
cd <Raspbian_SD_card_mountpoint_directory>
cp -R usr lib opt $RPI_ROOT

The above copying of files has the unfortunate side-effect that many symbolic links that were copied over are now invalid, particularly those linking to absolute paths. Fortunately, we can remedy this situation by downloading and running a python script that will fix those links:

wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py $RPI_ROOT

Note that the last command above is supposed to run the python script sysroot-relativelinks.py. You will need to have python3 installed on your host PC for that. The script assumes a location for your python binary, but that may not be a valid path on your host PC. An alternative to that would be to run:

$(which python3) ./sysroot-relativelinks.py $RPI_ROOT

Finally, update the PATH variable to be preceded by the RPI_ROOT path, since this is required for proper detection of libcurl related files by ScummVM's configure script.

export PATH=$RPI_ROOT:$PATH

Configuring ScummVM

First, we should make sure have the latest version of the ScummVM code locally (using git clone or git pull appropriately).

Then, navigate inside the local scummvm source code folder.

Now we can configure the ScummVM build system so it knows what backend we target and where our Raspberry Pi local sysroot is located, containing the Raspberry Pi headers and libraries the cross-compiler and linker will need. In this example configuration, we disable debug symbols since it's intended for final users.

mkdir -p ./scummvmDist
PKG_CONFIG_SYSROOT_DIR=$RPI_ROOT PKG_CONFIG_LIBDIR=$RPI_ROOT/usr/lib/arm-linux-gnueabihf/pkgconfig ./configure --host=raspberrypi --with-sdl-prefix=$RPI_ROOT/usr --with-png-prefix=$RPI_ROOT/usr --disable-debug --enable-release --prefix=$(pwd)/scummvmDist

Remember that we have already exported the RPI_ROOT environment variable previously and updated the PATH environment variable to be preceded by the RPI_ROOT path and succeeded by the path to the Raspberry Pi toolchain bin folder (as shown in the previous steps).

On the Raspberry Pi, SDL2 will always be used, since it provides graphics acceleration.

Unfortunately, the official toolchain for cross-compiling for Pi is, as of yet, using an old gcc version (4.3.9) and hence, the configure script may fail to detect the FluidSynth library specifically. FluidSynth and MT-32 emulation are features that are very demanding on CPU processing power so it should be ok to skip them entirely. Alternatively, one could seek out a more up-to-date armhf toolchain for the cross-compilation, such as this Raspberry Pi toolchain by Stefan Profanter (Pro) which, in its 1.0.1 version, uses gcc version 8.3.0 and reportedly "supports all new Raspberry PIs (ARMv7), and the older ones, including Zero, A, B, B+ (ARMv6) with newer GCCs."

Note 1: If installing the Raspberry Pi toolchain by Stefan Profanter (Pro), it's important to read the instructions from the README file (also available from the main page of the repository). Specifically, this toolchain needs to be installed in /opt/cross-pi-gcc since it's not location independent.

Note 2: If building ScummVM directly on the Raspberry Pi / Raspbian itself, it's possible to run out of memory during the final linking process of the build. If GNU ld is used for compiling, then execute the following before running configure:

export LDFLAGS="-Wl,--no-keep-memory"

This tells GNU ld to optimize the linking for memory usage.

Compiling ScummVM

Provided that the configure step was executed successfully, we can proceed to run the following commands in order to build ScummVM:

make clean
make -j$(nproc)
make install

Installing ScummVM on the Raspberry Pi

In this step we simply have to copy over the resulting files in our distribution folder scummvmDist to our Raspberry Pi (Raspbian OS) SD Card. A good idea is to create a scummvm folder in our /home/pi directory on the Raspian OS SD Card, and put the distribution folder contents there along with any games we want to use with it.

In order to have the text-to-speech feature available for ScummVM we should also install the speech-dispatcher package and a text-to-speech engine (as per the instructions in this pertinent Pull Request)

For example we'd need to execute the following on our Raspbian OS on the Pi in order to use the espeak-ng text-to-speech engine:

sudo apt-get install --no-install-recommends speech-dispatcher speech-dispatcher-espeak-ng

Note 1: There's a number of optional additional files that can be copied in the ScummVM directory along with the scummvm executable, which ScummVM uses for themes, GUI translations and as auxilliary data files for some of the game engines. Such list of files is shown here. These files should be already present in your distribution folder scummvmDist, if you used the "prefix" switch in configure and the make install command as shown above.

Note 2: As of yet, there are some known issues with the ALSA sound driver especially in conjunction with the PulseAudio system on Raspbian OS (3.2). Having PulseAudio installed (by default it is not installed) may result to bad sound output in ScummVM (and other apps).

External Links