Source code compiling/Makefiles

From SRB2 Wiki
Jump to: navigation, search

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

Prerequisites

Windows

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

Selecting the 32-bit MSYS2 shortcut.

Follow steps 1 to 6 of installation instructions at msys2.org.

NoteIcon.png Note
You must open the 32-bit shortcut to be able to use 32-bit (i686) programs.

After you've followed the steps listed there, close the MSYS2 window and open its 32-bit shortcut. Then enter these commands into the new window.

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

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

Linux

NoteIcon.png Note
SRB2 Kart does not use libopenmpt.

If you are using a 32-bit system, then you must also install NASM, or disable compiling assembler source code.

Ubuntu

Enter the following command in a terminal to install the tools and dependencies required to build SRB2.

sudo apt-get install build-essential libpng-dev zlib1g-dev libsdl2-dev libsdl2-mixer-dev libgme-dev libopenmpt-dev libcurl4-openssl-dev

To install NASM:

sudo apt-get install nasm

Arch Linux

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

libopenmpt is available as an AUR package.

To install NASM:

sudo pacman -S nasm

Download the source code

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

NoteIcon.png 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

NoteIcon.png Note
The SRB2 Kart codebase is not up to date with these instructions at the time of writing (16th of June 2021).

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 next release of the game.

To switch to the current release, enter this command.

git checkout master

Finally, enter this command to compile.

make
NoteIcon.png Note
To compile without assembler source code (applicable on 32-bit systems), add NOASM=1. For example:
make NOASM=1
NoteIcon.png 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/james/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.
NOASM=1 Do not use NASM/YASM code (software optimizations); fall back on extra C code instead of x86.
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.
NASM=yasm Compile using YASM instead of NASM.
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.