Difference between revisions of "Compiling ScummVM/iPhone"

From ScummVM :: Wiki
Jump to navigation Jump to search
m (Text replacement - "</source>" to "</syntaxhighlight>")
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This page explains how to compile your own version of [[ScummVM]] using the [[iPhone]] backend.
This page explains how to compile your own version of [[ScummVM]] using the [[iPhone]] or [[iOS7]] backend.


= Using Xcode =


== Setup ==
You can compile ScummVM with the official tools from Apple. This is the recommended way to compile ScummVM, and the only one which makes it possible to run ScummVM on a non-jailbroken iPhone or iPad devices!
 
== Requirements ==
You will need:
* a macOS computer
* Xcode (you can get it for free from the Mac App Store)
* A developer account. You can create one for free using your Apple ID (the same one used for iCloud or the Mac App Store) on the [https://developer.apple.com/membercenter/ Apple Developer Member Center].
* iOS libraries used by ScummVM. There is a link to a convenient package below in the build instruction.
 
''Note:'' with a free developer account iOS App that you build will only be valid for 7 days and you will thus need to recompile and reinstall them each week.
 
== Creating the Xcode project ==
Clone the ScummVM repository from GitHub to get the source code:
<syntaxhighlight lang="bash">
git clone https://github.com/scummvm/scummvm.git
</syntaxhighlight>
 
Generate the create_project tool:
<syntaxhighlight lang="bash">
cd scummvm/devtools/create_project/xcode
xcodebuild
</syntaxhighlight>
''Note:'' you may need to run xcodebuild with sudo the first time ('sudo xcodebuild') if the Xcode command line tools are not yet installed. Command line tools can also be installed from Xcode or using 'sudo xcode-select --install'
 
Create a build directory, extract the [https://www.scummvm.org/frs/build/scummvm-ios7-libs.zip iOS libraries package] and generate the Xcode project
<syntaxhighlight lang="bash">
cd ../../../..
mkdir build
cd build
</syntaxhighlight>
 
Download the [https://www.scummvm.org/frs/build/scummvm-ios7-libs.zip iOS libraries package] and extract them in the build directory:
<syntaxhighlight lang="bash">
unzip ~/Downloads/ScummVM-iOS-libraries.zip
</syntaxhighlight>
 
Generate Xcode project and open it:
<syntaxhighlight lang="bash">
../scummvm/devtools/create_project/xcode/build/Release/create_project ../scummvm --xcode --enable-fluidsynth --disable-bink --disable-mt32emu --disable-nasm --disable-opengl --disable-theora --disable-taskbar --disable-libcurl --disable-sdlnet
</syntaxhighlight>
 
At this point your build directory should contain:
* a generated '''engines''' directory
* a generated '''scummvm.xcodeproj''' project
* an '''include''' directory
* a '''lib''' directory
 
You are now ready to compile ScummVM. First open the project in Xcode:
<syntaxhighlight lang="bash">
open scummvm.xcodeproj
</syntaxhighlight>
''Note:'' you can also double-click on the ''scummvm.xcodeproj'' file in the Finder to open it with Xcode.
 
== Compile and Deploy ==
In Xcode you need to configure the scummvm project:
* Connect your iPhone or iPad to your Mac.
* Select your iOS device (iPhone or iPad) at the top of the window (in the title bar).
* In the project ''General'' settings you need to specify a unique ''Bundle Identifier'' (for example ''org.yourname.scummvm'').
* You need to configure the ``Signing`` settings. Add an account by using your Apple ID if needed and then select it.
 
Then click on the Play button in the top left of the window to start the build. The App will be automatically installed on your device at the end of the build.
 
 
'''TODO:''' Add a bit more details.
 
 
There are some outdated instructions on [http://blog.pmlabs-apps.com/scummvm-on-ios-without-jailbreak/ this blog] that may still be useful as it is illustrated and has more details.
 
= Using the command line =
 
For jailbroken devices, it is also possible to compile the project from command line. You'll need a working toolchain, and some tools, like '''ldid''', to fake the code signature.
 
Here is a script to download, and compile all the required tools. This script has been wrote for Debian 8.2, and should be run as root.
<syntaxhighlight lang="bash">
#!/bin/bash
 
if [ $UID -ne 0 ]; then
echo "This script should be run by the root user"
exit 1
fi
 
# Install the Clang compiler
apt-get install -y clang-3.4 libclang-3.4-dev llvm-3.4 libtool bison flex automake subversion git pkg-config wget libssl-dev uuid-dev libxml2-dev || exit 1
 
# Add LLVM to the linker library path
echo /usr/lib/llvm-3.4/lib > /etc/ld.so.conf.d/libllvm-3.4.conf
ldconfig
 
# Add symlinks for the LLVM headers
ln -s /usr/lib/llvm-3.4/bin/llvm-config /usr/bin/llvm-config || exit 1
ln -s /usr/include/llvm-3.4/llvm /usr/include/llvm || exit 1
ln -s /usr/include/llvm-c-3.4/llvm-c /usr/include/llvm-c || exit 1
ln -s /usr/bin/clang-3.4 /usr/bin/clang || exit 1
ln -s /usr/bin/clang++-3.4 /usr/bin/clang++ || exit 1
 
# Build the linker
svn checkout http://ios-toolchain-based-on-clang-for-linux.googlecode.com/svn/trunk/cctools-porting || exit 1
cd cctools-porting
sed -i'' 's/proz -k=20  --no-curses/wget/g' cctools-ld64.sh
./cctools-ld64.sh || exit 1
 
cd cctools-855-ld64-236.3
./autogen.sh || exit 1
./configure --prefix=/usr/local --target=arm-apple-darwin11 || exit 1
make || exit 1
make install || exit 1
cd ../..
 
# Install ios-tools
wget https://ios-toolchain-based-on-clang-for-linux.googlecode.com/files/iphonesdk-utils-2.0.tar.gz || exit 1
tar xzf iphonesdk-utils-2.0.tar.gz
cd iphonesdk-utils-2.0
patch -p0 <<_EOF
*** genLocalization2/getLocalizedStringFromFile.cpp    2015-04-02 04:45:39.309837816 +0530
--- genLocalization2/getLocalizedStringFromFile.cpp    2015-04-02 04:45:11.525700021 +0530
***************
*** 113,115 ****
      clang::HeaderSearch headerSearch(headerSearchOptions,
-                                      fileManager,
                                      *pDiagnosticsEngine,
--- 113,115 ----
      clang::HeaderSearch headerSearch(headerSearchOptions,
+                                      sourceManager,
                                      *pDiagnosticsEngine,
***************
*** 129,134 ****
                  false);
-    clang::HeaderSearch headerSearch(fileManager,
                                      *pDiagnosticsEngine,
                                      languageOptions,
-                                      pTargetInfo);
      ApplyHeaderSearchOptions(headerSearch, headerSearchOptions, languageOptions, pTargetInfo->getTriple());
--- 129,134 ----
                  false);
+    clang::HeaderSearch headerSearch(fileManager);/*,
                                      *pDiagnosticsEngine,
                                      languageOptions,
+                                      pTargetInfo);*/
      ApplyHeaderSearchOptions(headerSearch, headerSearchOptions, languageOptio
_EOF
 
./autogen.sh || exit 1
CC=clang CXX=clang++ ./configure --prefix=/usr/local || exit 1
make || exit 1
make install || exit 1
 
# Install the iOS SDK 8.1
mkdir -p /usr/share/ios-sdk
cd /usr/share/ios-sdk
wget http://iphone.howett.net/sdks/dl/iPhoneOS8.1.sdk.tbz2 || exit 1
tar xjf iPhoneOS8.1.sdk.tbz2
rm iPhoneOS8.1.sdk.tbz2
</syntaxhighlight>
 
Now, in order to compile ScummVM, execute the following commands:
<syntaxhighlight lang="bash">
export SDKROOT=/usr/share/ios-sdk/iPhoneOS8.1.sdk
export CC=ios-clang
export CXX=ios-clang++
./configure --host=ios7 --disable-mt32emu --enable-release
make ios7bundle
</syntaxhighlight>
 
At the end of the compilation, you'll find a '''ScummVM.app''' application: copy it over SSH, and reboot your device.
 
= Cross-Compilation =
 
Please note binaries generated with these instructions only work with jailbroken devices.
 
== Toolchain Setup ==


=== Toolchain ===
=== Toolchain ===
First, you'll need to set up the [http://code.google.com/p/iphone-dev/ toolchain]. We recommend 0.3 (which is the newest version at time of writing), any other and you might have to do some manual modifications to the build process.


Important: If you want to compile the ARM ASM optimizations for SMUSH and sound (and otherwise you'll have to manually change the configure script to remove them), you'll have to apply a patch to the toolchain before compiling/installing it (so it can handle our asm files).
First you need to set up a toolchain for cross-compilation. On our buildbot we use [https://github.com/lordhoto/ios-toolchain this toolchain]. It is based on LLVM/Clang and contains instructions on how to set it up.


Download the patch [http://worldsmainorganization.org/scummvm/index.php?dir=iphone%2F&download=iphone-toolkit-scummvm-1.patch here].
=== External libs ===


Apply it in the iphone-dev directory like so:
In the previously linked toolchain a script to compile all libraries used by the iOS version of ScummVM is contained. Please refer to the toolchain's README file on how to build them.
patch -p0 < iphone-toolkit-scummvm-1.patch


=== External libs ===
== Building ScummVM ==
Then, set up any of the external libs you might want. Meaning libMAD for MP3 playback, libFLAC for FLAC support and/or Tremor for Ogg support. You can add mpeg2dec as well, but it's only used for MPEG2 BS1/2 cutscene support and you really should be using the DXA versions instead (can be downloaded from [http://scummvm.org/downloads.php ScummVM's download page].


Note that you only need to add these if you need support for those filetypes, ScummVM will run fine without them.
=== Configuration ===


The below script is what I use to configure these libraries:
Before we can compile ScummVM we need to configure the source tree for building. This is usually only required once or when you want to alter build options.


#!/bin/bash
==== Choosing an iOS target ====
export CC='/usr/local/bin/arm-apple-darwin-gcc -v'
export CXX='/usr/local/bin/arm-apple-darwin-g++'
export LD=$CC
export LDFLAGS="-L/usr/local/arm-apple-darwin/lib/ -Wl,-lstdc++,-lgcc_s.1"
./configure --host=arm-darwin --prefix=/usr/local/arm-apple-darwin/


After that, 'make' and 'make install' should do the trick.
We feature two different iOS backends:
* ''iphone'': Our legacy iOS backend, which supports all iOS3+ devices.
* ''ios7'': Our modern iOS7+ backend, which only supports iOS7+ devices but features better integration for these.


=== ScummVM ===
Depending on which backend you use you will need to use a different value for the ''TARGET'' environment variable.


Then, we need to configure ScummVM itself.
* For ''iphone'' use:
<syntaxhighlight lang="bash">
export TARGET=arm-apple-darwin9
</syntaxhighlight>


Below is the script I use for this:
* For ''ios7'' use:
#!/bin/bash
<syntaxhighlight lang="bash">
export CC='/usr/local/bin/arm-apple-darwin-gcc -v'
export TARGET=arm-apple-darwin11
export CXX='/usr/local/bin/arm-apple-darwin-g++'
</syntaxhighlight>
export LD=$CC
export LDFLAGS="-L/usr/local/arm-apple-darwin/lib/ -Wl,-lstdc++,-lgcc_s.1"
export CXXFLAGS="-Wl,-lstdc++,-lgcc_s.1 -I/usr/local/arm-apple-darwin/include/"
export OBJCFLAGS="-I/usr/local/arm-apple-darwin/include/"
./configure --host=iphone --disable-mt32emu --disable-scalers  --enable-release --with-flac-prefix=/usr/local/arm-apple-darwin/


Note that the --with-flac-prefix is only necessary if you want to include FLAC support.
==== Setting up the Environment ====


If you've installed the external libs in any other place than /usr/local/arm-apple/darwin, you need to tell ScummVM where to find them at this point as well (additional flags to ./configure).
<syntaxhighlight lang="bash">
export PATH="$IOS_TOOLCHAIN_BASE/bin:$IOS_TOOLCHAIN_BASE/$TARGET/bin:$IOS_TOOLCHAIN_BASE/$TARGET/usr/bin:$PATH"
export CPPFLAGS="-isystem $IOS_TOOLCHAIN_BASE/$TARGET/usr/include"
export LDFLAGS="-L$IOS_TOOLCHAIN_BASE/$TARGET/usr/lib"
</syntaxhighlight>
Where ''IOS_TOOLCHAIN_BASE'' contains the directory where you installed the toolchain. And ''TRAGET'' has been setup from the previous step.


== Compiling ==
'''NOTE''': If you quit the shell you are using when configuring ScummVM and pick up compilation later, you will need to re-export only the ''PATH'' variable like described above.


First, you need to specify which assembler to use, since ScummVM's configure system currently doesn't do this automatically for us.
==== Configuring the Build ====


export AS=/usr/local/bin/arm-apple-darwin-as
Then configure ScummVM for the iOS version you want to target.


Then, we can start the compile:
First, navigate to a path where you want your build files to be located (this can be the ScummVM root directory but does not have to be).
Then run the following:
<syntaxhighlight lang="bash">
./path/to/scummvm/configure --host=ios7 --with-staticlib-prefix=$IOS_TOOLCHAIN_BASE/$TARGET/usr
</syntaxhighlight>
Replace ''ios7'' with ''iphone'' if you want to build the older version of our iOS backend.


make iphone
=== Compilation ===


Lastly, we want to make a ScummVM.app bundle:
You can compile ScummVM with running make:
<syntaxhighlight lang="bash">
make iphone
</syntaxhighlight>
If you simply want to test whether changes you made compile but do not plan to use the binary for deployment you can also simply run ''make''.


make iphonebundle
Please note that if you want to deploy ScummVM on your iOS device you will need to generate a bundle file. For this run either:
<syntaxhighlight lang="bash">
make ios7bundle
</syntaxhighlight>
for the ''ios7'' backend. Or
<syntaxhighlight lang="bash">
make iphonebundle
</syntaxhighlight>
for the ''iphone'' backend.


Then simply upload the whole ScummVM.app directory to your device under the /Applications folder, and you're done!
Then simply upload the whole ScummVM.app directory to your device under the /Applications folder, and you're done!

Revision as of 15:16, 25 October 2018

This page explains how to compile your own version of ScummVM using the iPhone or iOS7 backend.

Using Xcode

You can compile ScummVM with the official tools from Apple. This is the recommended way to compile ScummVM, and the only one which makes it possible to run ScummVM on a non-jailbroken iPhone or iPad devices!

Requirements

You will need:

  • a macOS computer
  • Xcode (you can get it for free from the Mac App Store)
  • A developer account. You can create one for free using your Apple ID (the same one used for iCloud or the Mac App Store) on the Apple Developer Member Center.
  • iOS libraries used by ScummVM. There is a link to a convenient package below in the build instruction.

Note: with a free developer account iOS App that you build will only be valid for 7 days and you will thus need to recompile and reinstall them each week.

Creating the Xcode project

Clone the ScummVM repository from GitHub to get the source code:

git clone https://github.com/scummvm/scummvm.git

Generate the create_project tool:

cd scummvm/devtools/create_project/xcode
xcodebuild

Note: you may need to run xcodebuild with sudo the first time ('sudo xcodebuild') if the Xcode command line tools are not yet installed. Command line tools can also be installed from Xcode or using 'sudo xcode-select --install'

Create a build directory, extract the iOS libraries package and generate the Xcode project

cd ../../../..
mkdir build
cd build

Download the iOS libraries package and extract them in the build directory:

unzip ~/Downloads/ScummVM-iOS-libraries.zip

Generate Xcode project and open it:

../scummvm/devtools/create_project/xcode/build/Release/create_project ../scummvm --xcode --enable-fluidsynth --disable-bink --disable-mt32emu --disable-nasm --disable-opengl --disable-theora --disable-taskbar --disable-libcurl --disable-sdlnet

At this point your build directory should contain:

  • a generated engines directory
  • a generated scummvm.xcodeproj project
  • an include directory
  • a lib directory

You are now ready to compile ScummVM. First open the project in Xcode:

open scummvm.xcodeproj

Note: you can also double-click on the scummvm.xcodeproj file in the Finder to open it with Xcode.

Compile and Deploy

In Xcode you need to configure the scummvm project:

  • Connect your iPhone or iPad to your Mac.
  • Select your iOS device (iPhone or iPad) at the top of the window (in the title bar).
  • In the project General settings you need to specify a unique Bundle Identifier (for example org.yourname.scummvm).
  • You need to configure the ``Signing`` settings. Add an account by using your Apple ID if needed and then select it.

Then click on the Play button in the top left of the window to start the build. The App will be automatically installed on your device at the end of the build.


TODO: Add a bit more details.


There are some outdated instructions on this blog that may still be useful as it is illustrated and has more details.

Using the command line

For jailbroken devices, it is also possible to compile the project from command line. You'll need a working toolchain, and some tools, like ldid, to fake the code signature.

Here is a script to download, and compile all the required tools. This script has been wrote for Debian 8.2, and should be run as root.

#!/bin/bash

if [ $UID -ne 0 ]; then
	echo "This script should be run by the root user"
	exit 1
fi

# Install the Clang compiler
apt-get install -y clang-3.4 libclang-3.4-dev llvm-3.4 libtool bison flex automake subversion git pkg-config wget libssl-dev uuid-dev libxml2-dev || exit 1

# Add LLVM to the linker library path
echo /usr/lib/llvm-3.4/lib > /etc/ld.so.conf.d/libllvm-3.4.conf
ldconfig

# Add symlinks for the LLVM headers
ln -s /usr/lib/llvm-3.4/bin/llvm-config /usr/bin/llvm-config || exit 1
ln -s /usr/include/llvm-3.4/llvm /usr/include/llvm || exit 1
ln -s /usr/include/llvm-c-3.4/llvm-c /usr/include/llvm-c || exit 1
ln -s /usr/bin/clang-3.4 /usr/bin/clang || exit 1
ln -s /usr/bin/clang++-3.4 /usr/bin/clang++ || exit 1

# Build the linker
svn checkout http://ios-toolchain-based-on-clang-for-linux.googlecode.com/svn/trunk/cctools-porting || exit 1
cd cctools-porting
sed -i'' 's/proz -k=20  --no-curses/wget/g' cctools-ld64.sh
./cctools-ld64.sh || exit 1

cd cctools-855-ld64-236.3
./autogen.sh || exit 1
./configure --prefix=/usr/local --target=arm-apple-darwin11 || exit 1
make || exit 1
make install || exit 1
cd ../..

# Install ios-tools
wget https://ios-toolchain-based-on-clang-for-linux.googlecode.com/files/iphonesdk-utils-2.0.tar.gz || exit 1
tar xzf iphonesdk-utils-2.0.tar.gz
cd iphonesdk-utils-2.0
patch -p0 <<_EOF
*** genLocalization2/getLocalizedStringFromFile.cpp    2015-04-02 04:45:39.309837816 +0530
--- genLocalization2/getLocalizedStringFromFile.cpp    2015-04-02 04:45:11.525700021 +0530
***************
*** 113,115 ****
      clang::HeaderSearch headerSearch(headerSearchOptions,
-                                      fileManager,
                                       *pDiagnosticsEngine,
--- 113,115 ----
      clang::HeaderSearch headerSearch(headerSearchOptions,
+                                      sourceManager,
                                       *pDiagnosticsEngine,
***************
*** 129,134 ****
                  false);
-     clang::HeaderSearch headerSearch(fileManager,
                                       *pDiagnosticsEngine,
                                       languageOptions,
-                                      pTargetInfo);
      ApplyHeaderSearchOptions(headerSearch, headerSearchOptions, languageOptions, pTargetInfo->getTriple());
--- 129,134 ----
                  false);
+     clang::HeaderSearch headerSearch(fileManager);/*,
                                       *pDiagnosticsEngine,
                                       languageOptions,
+                                      pTargetInfo);*/
      ApplyHeaderSearchOptions(headerSearch, headerSearchOptions, languageOptio
_EOF

./autogen.sh || exit 1
CC=clang CXX=clang++ ./configure --prefix=/usr/local || exit 1
make || exit 1
make install || exit 1

# Install the iOS SDK 8.1
mkdir -p /usr/share/ios-sdk
cd /usr/share/ios-sdk
wget http://iphone.howett.net/sdks/dl/iPhoneOS8.1.sdk.tbz2 || exit 1
tar xjf iPhoneOS8.1.sdk.tbz2
rm iPhoneOS8.1.sdk.tbz2

Now, in order to compile ScummVM, execute the following commands:

export SDKROOT=/usr/share/ios-sdk/iPhoneOS8.1.sdk
export CC=ios-clang
export CXX=ios-clang++
./configure --host=ios7 --disable-mt32emu --enable-release
make ios7bundle

At the end of the compilation, you'll find a ScummVM.app application: copy it over SSH, and reboot your device.

Cross-Compilation

Please note binaries generated with these instructions only work with jailbroken devices.

Toolchain Setup

Toolchain

First you need to set up a toolchain for cross-compilation. On our buildbot we use this toolchain. It is based on LLVM/Clang and contains instructions on how to set it up.

External libs

In the previously linked toolchain a script to compile all libraries used by the iOS version of ScummVM is contained. Please refer to the toolchain's README file on how to build them.

Building ScummVM

Configuration

Before we can compile ScummVM we need to configure the source tree for building. This is usually only required once or when you want to alter build options.

Choosing an iOS target

We feature two different iOS backends:

  • iphone: Our legacy iOS backend, which supports all iOS3+ devices.
  • ios7: Our modern iOS7+ backend, which only supports iOS7+ devices but features better integration for these.

Depending on which backend you use you will need to use a different value for the TARGET environment variable.

  • For iphone use:
export TARGET=arm-apple-darwin9
  • For ios7 use:
export TARGET=arm-apple-darwin11

Setting up the Environment

export PATH="$IOS_TOOLCHAIN_BASE/bin:$IOS_TOOLCHAIN_BASE/$TARGET/bin:$IOS_TOOLCHAIN_BASE/$TARGET/usr/bin:$PATH"
export CPPFLAGS="-isystem $IOS_TOOLCHAIN_BASE/$TARGET/usr/include"
export LDFLAGS="-L$IOS_TOOLCHAIN_BASE/$TARGET/usr/lib"

Where IOS_TOOLCHAIN_BASE contains the directory where you installed the toolchain. And TRAGET has been setup from the previous step.

NOTE: If you quit the shell you are using when configuring ScummVM and pick up compilation later, you will need to re-export only the PATH variable like described above.

Configuring the Build

Then configure ScummVM for the iOS version you want to target.

First, navigate to a path where you want your build files to be located (this can be the ScummVM root directory but does not have to be). Then run the following:

./path/to/scummvm/configure --host=ios7 --with-staticlib-prefix=$IOS_TOOLCHAIN_BASE/$TARGET/usr

Replace ios7 with iphone if you want to build the older version of our iOS backend.

Compilation

You can compile ScummVM with running make:

make iphone

If you simply want to test whether changes you made compile but do not plan to use the binary for deployment you can also simply run make.

Please note that if you want to deploy ScummVM on your iOS device you will need to generate a bundle file. For this run either:

make ios7bundle

for the ios7 backend. Or

make iphonebundle

for the iphone backend.

Then simply upload the whole ScummVM.app directory to your device under the /Applications folder, and you're done!