Difference between revisions of "Compiling the Source Code"
(Added instructions for cross-compiling) |
|||
Line 1: | Line 1: | ||
− | + | = Current version = | |
− | + | - | |
− | + | = Legacy version = | |
+ | |||
+ | The instructions below help you compile the legacy version of Open Surge (0.2.0). These instructions are no longer applicable to the current version of Open Surge, but have been kept for historical purposes. Unlike the current version, the legacy version used Allegro 4. | ||
+ | |||
+ | == Compiling on Windows == | ||
− | From here on, when GAMEDIR is mentioned, it means only the directory where you unpacked the game. GAMEDIR stores, among other things, a readme.html page and a file called CMakeLists.txt | + | At some point you may want to compile the game/engine on your own, mostly if you are modifying the sources. From here on, when GAMEDIR is mentioned, it means only the directory where you unpacked the game. GAMEDIR stores, among other things, a readme.html page and a file called CMakeLists.txt. |
=== Preparing the environment === | === Preparing the environment === | ||
Line 36: | Line 40: | ||
Now we should download all the dependencies. It is recommendable that you extract the files in an easy to read folder structure. For example, on a main folder called "src", extract each dependency to its separate folder. | Now we should download all the dependencies. It is recommendable that you extract the files in an easy to read folder structure. For example, on a main folder called "src", extract each dependency to its separate folder. | ||
− | Let's go to http:// | + | Let's go to [http://liballeg.org liballeg.org] and download Allegro 4.4. Extract the contents of the file into the folder where we are going to keep the dependencies. |
It is now recommended that we compile Allegro. To avoid any errors, we should go to the folder where Allegro was extracted, and delete the CMakeCache.txt file before compiling. | It is now recommended that we compile Allegro. To avoid any errors, we should go to the folder where Allegro was extracted, and delete the CMakeCache.txt file before compiling. |
Revision as of 14:38, 2 April 2019
Current version
-
Legacy version
The instructions below help you compile the legacy version of Open Surge (0.2.0). These instructions are no longer applicable to the current version of Open Surge, but have been kept for historical purposes. Unlike the current version, the legacy version used Allegro 4.
Compiling on Windows
At some point you may want to compile the game/engine on your own, mostly if you are modifying the sources. From here on, when GAMEDIR is mentioned, it means only the directory where you unpacked the game. GAMEDIR stores, among other things, a readme.html page and a file called CMakeLists.txt.
Preparing the environment
We will first need two programs:
- CMake - Cross platform compiler - http://www.cmake.org/
- MinGW - Minimalist GNU for Windows - http://sourceforge.net/projects/mingw/
Download and install both of them, the latest versions. It will be better if you install MinGW in your C: disk, under C:\MinGW.
Also, make sure your CMake is installed with this option (or the one under) selected:
Setting the PATH
In order for the compiler to know where to get the liraries, we need to add two variables to your system; right-click on "My Computer", select "Properties", then "Advanced System Settings", and then "Environment Variables".
Now, in the lower box, we select the variable called "Path" and then click "Edit". If it doesn't exist, we should create it.
If it exists, add this at the end:
;C:\MinGW\bin;C:\MinGW\lib
If you're creating it, ignore the ; at the beginning and paste the rest. Give OK to all open dialog boxes.
Getting the dependencies
Now we should download all the dependencies. It is recommendable that you extract the files in an easy to read folder structure. For example, on a main folder called "src", extract each dependency to its separate folder.
Let's go to liballeg.org and download Allegro 4.4. Extract the contents of the file into the folder where we are going to keep the dependencies.
It is now recommended that we compile Allegro. To avoid any errors, we should go to the folder where Allegro was extracted, and delete the CMakeCache.txt file before compiling.
Now it's time to run CMake GUI.
Use this image as a reference on how to configure:
Now we need
- Modified Alfont - http://opensnc.sourceforge.net/alfont/
Make sure you follow the Generic installation instructions. For ease of access, here are the download links:
http://opensnc.sourceforge.net/alfont/AlFont209.rar (Original Alfont)
http://opensnc.sourceforge.net/alfont/alfont.c (Modified Alfont, conveniently prepared for download).
Now, after downloading and extracting the Original Alfont, replace alfont/src/alfont.c with the modified alfont.c you just downloaded.
Next, follow the compilation process described in alfont/README.txt: with a text editor, modify Makefile and set TARGET=MINGW32_STATIC
Now you should
- Compile Alfont.
After running make, copy alfont/lib/mingw32/libalfont.a and alfont/include/* to the MingW directories, normally C:/MingW/lib , and C:/MingW/include .
You should now be ready for the final step.
Compiling Open Surge
When using MinGW, make sure both lib\ and bin\ folders are listed on your PATH. If MinGW is installed on C:\MinGW\, simply open a Command Prompt (cmd) and type:
set PATH=%PATH%;C:\MinGW\bin;C:\MinGW\lib
On the same Command Prompt, please go to GAMEDIR and run the following commands:
cmake -G "MinGW Makefiles" . mingw32-make
Note that little '.' at the end of the first command. If everything works well, opensurge.exe will be in GAMEDIR.
Cross-compiling (advanced)
We'll learn how to compile the Windows version from a Linux box. This is more advanced and more complete (we show you how to compile everything, including the libs). You can adapt these instructions to compile Open Surge in other systems (particularly on *nix). If you came here from the web, you can follow these instructions to cross compile Allegro 4.4 as well:
Install MinGW
First of all, we need to install the cross-compiler. Get MinGW on its website or, on Debian-based distributions, simply run:
sudo apt-get install mingw-w64-i686-dev
Now, check where the cross-compiler has been installed. Then, run the following commands (adapt as necessary):
TOOLSET="i686-w64-mingw32" MINGDIR="/usr/i686-w64-mingw32"
Note: the 32-bit version of the compiler is required for Allegro 4.4.
Install CMake
Get CMake if you haven't yet. Download it on its website or, on Debian-based distributions, run:
sudo apt-get install cmake
We'll use this tool to help us compile some things.
Compile zlib
Compiling zlib is pretty straighforward:
wget https://zlib.net/zlib-1.2.11.tar.gz tar xvzf zlib-1.2.11.tar.gz cd zlib-1.2.11 sed -e s/"PREFIX ="/"PREFIX = ${TOOLSET}-"/ -i win32/Makefile.gcc make -f win32/Makefile.gcc sudo BINARY_PATH=${MINGDIR}/bin \ INCLUDE_PATH=${MINGDIR}/include \ LIBRARY_PATH=${MINGDIR}/lib \ make -f win32/Makefile.gcc install cd ..
Compile libpng
You'll need libpng version 1.2:
wget https://download.sourceforge.net/libpng/libpng-1.2.59.tar.gz tar xvzf libpng-1.2.59.tar.gz cd libpng-1.2.59 ./configure \ CC="${TOOLSET}-gcc" \ AR="${TOOLSET}-ar" \ STRIP="${TOOLSET}-strip" \ RANLIB="${TOOLSET}-ranlib" \ CFLAGS="-I${MINGDIR}/include/" \ LDFLAGS="-L${MINGDIR}/lib/" \ --disable-shared \ --target=$TOOLSET \ --host=$TOOLSET \ --prefix=$MINGDIR make sudo make install
Compile libogg
Run this:
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.gz tar xvzf libogg-1.3.3.tar.gz cd libogg-1.3.3 ./configure \ CC="${TOOLSET}-gcc" \ AR="${TOOLSET}-ar" \ STRIP="${TOOLSET}-strip" \ RANLIB="${TOOLSET}-ranlib" \ CFLAGS="-I${MINGDIR}/include/" \ LDFLAGS="-L${MINGDIR}/lib/" \ --disable-shared \ --target=$TOOLSET \ --host=$TOOLSET \ --prefix=$MINGDIR make sudo make install
Compile libvorbis
Run that:
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.6.tar.gz tar xvzf libvorbis-1.3.6.tar.gz cd libvorbis-1.3.6 ./configure \ CC="${TOOLSET}-gcc" \ AR="${TOOLSET}-ar" \ STRIP="${TOOLSET}-strip" \ RANLIB="${TOOLSET}-ranlib" \ CFLAGS="-I${MINGDIR}/include/" \ LDFLAGS="-L${MINGDIR}/lib/" \ --disable-shared \ --target=$TOOLSET \ --host=$TOOLSET \ --prefix=$MINGDIR make sudo make install
Install the DirectX SDK for MinGW
This will install the DirectX SDK for MinGW:
wget https://download.tuxfamily.org/allegro/files/dx70_mgw.zip sudo unzip -a -d$MINGDIR dx70_mgw.zip
Compile Allegro 4.4.2
To compile Allegro 4.4, first run:
wget https://github.com/liballeg/allegro5/releases/download/4.4.2/allegro-4.4.2.zip unzip -a allegro-4.4.2.zip cd allegro
In cmake/Toolchain-mingw.cmake, adjust CMAKE_C_COMPILER, CMAKE_CXX_COMPILER and CMAKE_FIND_ROOT_PATH to ${which i686-w64-mingw32-gcc}, ${which i686-w64-mingw32-g++} and $MINGDIR, respectively (evaluate these values yourself and write their paths on the toolchain file). Additionally, set CMAKE_RC_COMPILER to ${which i686-w64-mingw32-windres} and add the command link_libraries("-static-libgcc") to the file. The result will be like this:
# # Values to be placed in cmake/Toolchain-mingw.cmake # set(CMAKE_C_COMPILER /usr/bin/i686-w64-mingw32-gcc) set(CMAKE_CXX_COMPILER /usr/bin/i686-w64-mingw32-g++) set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) set(CMAKE_RC_COMPILER /usr/bin/i686-w64-mingw32-windres) link_libraries("-static-libgcc")
Then, run:
mkdir build && cd build cmake \ -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake \ -DCMAKE_INSTALL_PREFIX=$MINGDIR \ -DWANT_EXAMPLES=ON \ -DWANT_ALLEGROGL=OFF \ .. make -j`nproc` sudo make install
You're done compiling Allegro! Additionally, run:
sudo ln -s $MINGDIR/lib/liballeg44.dll.a $MINGDIR/lib/liballeg.dll.a
Compile Modified Alfont 2.0.9
Compiling Modified Alfont is a bit more tricky. See its website for more information. Run the commands:
wget http://opensnc.sourceforge.net/alfont/AlFont209.rar unrar x AlFont209.rar cd alfont wget http://opensnc.sourceforge.net/alfont/alfont.c -O src/alfont.c sh ./fixunix.sh sed -e s/"TARGET=DJGPP_STATIC"/"TARGET=MINGW32_STATIC"/ -i Makefile sed -e s/"CC=gcc"/"CC=${TOOLSET}-gcc"/ -i Makefile make sudo install -m 755 lib/mingw32/libalfont.a ${MINGDIR}/lib sudo install -m 644 include/alfont*.h ${MINGDIR}/include
Compile Open Surge
If you've managed to come so far, congratulations. We're almost there!
Get the source code of the game (a recent version) and unpack it to $HOME/opensurge (preferably). Then:
cd ~/opensurge mkdir build && cd build cmake \ -DCMAKE_SYSTEM_NAME=Windows \ -DCMAKE_FIND_ROOT_PATH=$MINGDIR \ -DCMAKE_RC_COMPILER=${TOOLSET}-windres \ -DCMAKE_C_COMPILER=${TOOLSET}-gcc \ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ .. make
If everything went well, the opensurge executable will be in the opensurge folder. Make sure to include the Allegro DLL in the folder:
cp $MINGDIR/bin/alleg44.dll ~/opensurge
That's it!
Testing
Optional: if you have wine installed in your system, you can test the executable by running
wine ~/opensurge/opensurge.exe