Source code compiling/Makefiles

From SRB2 Wiki
Jump to navigation Jump to search

The Makefile is the preferred method of compiling SRB2, except on macOS. It has been tested on Windows and Linux.

Note
Some of these instructions may not apply to full conversion derivatives such as SRB2 Kart. Check their documentation first.

Prerequisites

Windows

On Windows, you must install MinGW. This guide uses the MSYS2 method.

Selecting the 32-bit MSYS2 shortcut.


First, follow steps 1 to 6 of installation instructions at msys2.org.

After you've followed the steps on the website, close the MSYS2 window and open MSYS2 MinGW 32-bit. Refer to the screenshot on the right.

Once you have closed the original window and opened MSYS2 MinGW 32-bit you must enter this command into the new window:

pacman -S git make mingw-w64-i686-gcc

This will install Git for downloading the source code, as well as Make and GCC for compiling the source code.

Linux

By default, compiling SRB2 requires the following development libraries: libpng, zlib, libsdl2, libsdl2_mixer, libgme, libcurl, and libopenmpt, and libminiupnpc.

If your distribution is listed below, you can simply enter the given command in a terminal to install everything you need to build SRB2 2.2.13.

Distribution specific commands

Debian/Ubuntu

sudo apt-get install make git gcc libsdl2-mixer-dev libpng-dev libcurl4-openssl-dev libgme-dev libopenmpt-dev libminiupnpc-dev

Arch Linux

sudo pacman -S base-devel git libpng zlib sdl2 sdl2_mixer libgme curl libopenmpt libminiupnpc

Fedora

sudo dnf install make gcc git libpng-devel zlib-devel SDL2-devel SDL2_mixer-devel game-music-emu-devel libcurl-devel libopenmpt-devel miniupnpc-devel

openSUSE

sudo zypper install make gcc git libpng-devel zlib-devel SDL2-devel SDL2_mixer-devel libgme-devel libcurl-devel libopenmpt-devel libminiupnpc-devel

Gentoo

Install the following as root/superuser.

emerge -avn dev-vcs/git media-libs/libpng sys-libs/zlib media-libs/libsdl2 media-libs/sdl2-mixer media-libs/game-music-emu media-libs/libopenmpt net-misc/curl net-libs/miniupnpc

Alpine Linux

Install the following as root/superuser.

apk add make git gcc zlib-dev libpng-dev curl-dev sdl2-dev sdl2_mixer-dev libgme-dev libopenmpt-dev alpine-sdk miniupnpc-dev

Download the source code

Find a suitable folder on your hard drive. Git will download the source code into a subfolder there.

Note
Windows path names under MSYS2 follow a different convention than that of most programs (such as Windows Explorer). For example, if the path is C:\Users\King\My Documents, then use /c/Users/King/My Documents under MSYS2. Enter this command to go there.
cd '/c/Users/King/My Documents'
Git clone URLs
Codebase git.do.srb2.org (preferred) GitHub
SRB2 https://git.do.srb2.org/STJr/SRB2.git https://github.com/STJr/SRB2.git
SRB2 Kart https://git.do.srb2.org/KartKrew/Kart-Public.git https://github.com/STJr/Kart-Public.git

Enter this command to download the source code. You may substitute one of the above URLs.

git clone https://git.do.srb2.org/STJr/SRB2.git

Compile the source code

Enter the subfolder in which Git downloaded the source code.

cd SRB2

By default, the source code is "checked out" on the next branch. This is the code for the upcoming release of the game and will often be unstable.

To switch to the current stable release, enter this command:

git checkout master

Finally, enter this command to compile (see below if it doesn't work).

make

If you are compiling on Ubuntu or Debian, you may need to enter this command instead:

LIBGME_CFLAGS= LIBGME_LDFLAGS=-lgme make
Note
If you're using a multi-core processor, you may try adding -j, followed by the number of cores, to compile multiple files at once. This speeds up building significantly. For example, on a four-core processor:
make -j 4

Once the executable is ready, a line like the following will be printed, alerting you to its location.

=== Build is done, look for lsdl2srb2 at /home/username/proj/srb2/srb2/bin ===

Updating your copy of the source code

Your copy of the source code may eventually become outdated, such as with each new release of the game. Instead of downloading an entirely new copy of the source code, you may enter the following command to only download those changes since the last time that you updated.

git pull

Compilation flags

In order to compile for an operating system different from your own, remove certain dependencies, or perform other operations, you must add certain compilation flags from the list below.

Flag Description
LINUX=1 Compile for i686 Linux.
LINUX64=1 Compile for x86_64 Linux.
MINGW=1 Compile for Windows using MinGW.
SDL=1 Compile with SDL.
WINDOWSHELL=1 Windows only; use comptime.bat instead of comptime.sh, don't use certain gzip commands.
set CC=gcc Windows only; make32-make by default, set CC to cc.exe, use gcc.exe to compiles using GCC
NOHW=1 Disable OpenGL and OpenAL.
NOMIXER=1 Fall back on sdl_sound.c code; do not use SDL_mixer.
NOPNG=1 Do not use libpng; fall back on PCX/TGA code instead of PNG for screenshots.
NOUPX=1 Do not use UPX when compiling.
DEBUGMODE=1 Compile debug binaries.
WARNINGMODE=1 Have more flags for warnings when compiling.
ERRORMODE=1 Have all warnings register as errors.
PROFILEMODE=1 Compiles with profiling information. After running the executable and exiting normally, the profile data for it is written into a file named gmon.out, which can be read using the gprof tool.
DUMMY=1 Compile with dummy interface code.
ECHO=1 Print detailed information during the compiling process.

For a detailed list of these flags and many more, check here.

Linux Installation

In order to run the game after building from source as described above, the asset files are needed, which can be found in the Windows zipfile or in a separate git repository.

The following is examples of two ways to install SRB2 after building from source with Makefile.

Getting the Assets for Linux

Depends: sudo git git-lfs

Git LFS is an extension for cloning repositories that contain large resources. It's required here to obtain the assets for SRB2 in order to avoid file corruption.

Debian/Ubuntu

sudo apt-get install git-lfs

TODO: add git-lfs install instructions for other OSes

Clone the Assets Repository

This will download the latest version of SRB2 2.2 to keep things simple, but the repository also contains assets for older versions as well.

1. Clone the SRB2Assets-Public Repository.

Git clone URLs
Codebase git.do.srb2.org
SRB2 https://git.do.srb2.org/STJr/SRB2Assets-Public.git
SRB2 Kart None as of now, use the alternative method
git lfs clone https://git.do.srb2.org/STJr/srb2assets-public.git -b SRB2_2.2 "$HOME"/SRB2Assets-Public

2. Create the .srb2 folder and copy the assets to a location that SRB2 can read from. If you get an error saying that it can't create the directory, you should be fine.

mkdir "$HOME"/.srb2; cp -r "$HOME"/SRB2Assets-Public/* "$HOME"/.srb2/

Alternative Method for Getting the Assets on Linux

This method uses a much more complicated way to get the assets, but it is here if you don't want to keep the assets in multiple places or are trying to run SRB2 Kart.

If you didn't clone SRB2 repo in $HOME, or don't have a Downloads folder, adjust paths as necessary. If the first command fails, there is probably a newer version available to download instead.

Depends: sudo wget unzip

Assumes FHS (Filesystem Hierarchy Standard), POSIX Compliant shell

1. Download Windows zipfile (linked on srb2 website).

Codebase Command
SRB2 wget https://github.com/STJr/SRB2/releases/download/SRB2_release_$(cat "$HOME"/SRB2/src/version.h | grep SRB2VERSION | sed "s/#define SRB2VERSION \"//g" | sed "s/\".*//g")/SRB2-v$(cat "$HOME"/SRB2/src/version.h | grep SRB2VERSION | sed "s/#define SRB2VERSION \"//g" | sed 's/[^0-9]*//g' )-Full.zip -P "$HOME"/Downloads
SRB2 Kart wget https://github.com/STJr/Kart-Public/releases/download/$(cat "$HOME"/kart-public/src/doomdef.h | tac | grep "#define VERSIONSTRING " | head -1 | sed "s/#define VERSIONSTRING \"//g" | sed "s/\".*//g")/AssetsLinuxOnly.zip -P "$HOME"/Downloads

2. Put the dta and pk3 files from the zip into a folder in your home dir called ".srb2".

Codebase Command
SRB2 unzip "$HOME"/Downloads/SRB2-v$(cat "$HOME"/SRB2/src/version.h | grep SRB2VERSION | sed "s/#define SRB2VERSION \"//g" | sed 's/[^0-9]*//g' )-Full.zip *.dta *.pk3 -d "$HOME"/.srb2
SRB2 Kart unzip "$HOME"/Downloads/AssetsLinuxOnly.zip *.srb *.dta *.pk3 -d "$HOME"/.srb2kart

Optional steps for Linux

1. Add link to path so you can launch with SRB2 from anywhere on the command line.

sudo ln -s "$HOME"/SRB2/bin/lsdl2srb2 /usr/local/games/srb2

2. Copy PNG to pixmaps folder for menu icon.

sudo cp "$HOME"/SRB2/srb2.png /usr/share/pixmaps/

3. Create Desktop File (Menu Entry/Launcher Shortcut).

cat <<EOF > "$HOME"/.local/share/applications/srb2.desktop
[Desktop Entry]
Type=Application
Name=Sonic Robo Blast 2
Exec=srb2
Icon=srb2
Categories=Game;
EOF