Source code compiling/Makefiles
|This article or section is badly written and in need of a rewrite. You can help the SRB2 Wiki by Manual of Style.this article to meet with the standards described by the|
Below are the instructions for compiling using Makefiles. SRB2's source code includes a Makefile to compile with, but one can also be generated using CMake if necessary – this article generally assumes you are using the Makefile in SRB2's source code. This is the current method of compilation internally.
Compiling on Windows (MinGW)
| To do|
MinGW recently moved to ODSN: . Figure out which release(s) exactly to link from there (just the Installation Manager perhaps?) in this page, and check if we need
To compile SRB2 for Windows, you have to install MinGW and various dependencies for it. The MinGW Installer can be downloaded from here. Note: Do NOT install MinGW into a pathname with spaces! This will not allow the compiler to function properly. The sufficient packages needed to compile SRB2 should all be under the "Basic Setup" category in the installer, though
mingw32-libmingwex (dev and
libmingwex-0.dll?) is also needed to prevent a compiling error. The packages may take a while to download. As soon as the downloads are complete, move onto the next step.
SRB2's assembly code relies on the Netwide Assembler (NASM) for compiling on Windows, which can be downloaded here. All of SRB2's other main dependencies (libpng, zlib, libgme, SDL2 and SDL2_mixer) are included with SRB2's source code, and will build provided you have NASM.
Compiling builds with the deprecated DirectDraw interface additionally requires the DirectX 8 devpack, which can be found here. Extract
directx8.zip into the folder where you installed MinGW (
C:\MinGW by default). Merge all folders prompted and replace all files that conflict. Place
dxguid.lib in the same folder after the merge and replace operations are complete. Note that SRB2's source code includes the FMODex library for sound in the DirectDraw version.
Setting up your build environment
Now you will have to change your system's environment variables. To do this, click on the start button, right-click on "Computer" and then on "Properties". From there, go to "Advanced System Settings" and press the button called "Environment Variables". Under "System Variables", search for a variable called "Path" and double-click on it. Now add
;C:\MinGW\bin;C:\Users\(Username)\AppData\Local\bin\nasm to the end of the variable's value. Substitute
(Username) with the name of your Windows account. If you changed the path where you installed either MinGW or NASM, you have to specify those paths instead of the default ones given here. After changing the value, click OK until you closed all the windows.
Compiling is typically done via the command line. If you're on Windows XP, click the "Start" button in the bottom left corner, then click "Run..." and enter
cmd. On Windows Vista/7, click the "Start" button, then type
cmd into the search bar and press "enter" when a result appears. This will open up the command line. Navigate to the folder where your SRB2 source is located by entering
cd <path of source folder>. Now enter
cd src to change to the "src" subfolder. On Windows Vista onwards, you can also open up command line at the "src" subfolder directly by holding shift and right-clicking on the folder from outside, then selecting "Open command window here".
From here, use the following command syntax to compile the source:
mingw32-make MINGW=1 CC=gcc WINDOWSHELL=1 SDL=1 NOOBJDUMP=1
For DirectDraw builds:
mingw32-make MINGW=1 CC=gcc WINDOWSHELL=1 NOOBJDUMP=1
If the build succeeded, you can find the compiled executable (
srb2win.exe for SDL2,
srb2dd.exe for DirectDraw + FMOD) and, if you didn't compile with SDL2,
r_opengl.dll in the
bin/Mingw/Release subfolder of your source folder. If not, check to make sure your path is configured properly and that you have all of the necessary dependencies. If the problem is still not solved, then please contact Alam or Logan via SRB2Fun. Remember, even if you get errors, the game may have still compiled. A good practice is to check
bin/Mingw/Release anyway just in case the compile was successful even with the errors.
Cross-compiling from Linux
It is possible to build SRB2 for Windows by using the MinGW toolchain on Linux. In order to set this up, you will need to install your OS's MinGW package and install the development libraries manually. The compiling process should be the similar to Windows. When cross-compiling, it is not necessary to use the
CC=gcc flag and you should not use the
WINDOWSHELL=1 flag, since it will cause the compile to fail.
make -C src/ MINGW=1
Compiling on Linux
To compile on Linux, you need to have the development libraries for SDL2 at minimum, as well as the GCC toolchain (make, GCC, etc), but it is recommended to have NASM and SDL2_mixer as well. Navigate to the source folder, then run this command:
make -C src/ LINUX=1
Keep in mind that
LINUX=1 is the flag for compiling on an i686 machine and will not compile on an x86_64 machine. x86_64 machines must use the
LINUX64=1 flag instead. This syntax also relies on NASM and SDL2_mixer. To compile without them, refer to the compilation flags below.
Ubuntu and Debian-specific
The packages for compiling on Ubuntu/Debian are as follows:
Compiling a clean build (
If, after compiling, you have modified a header file (a file with the
.h ending), and you need to compile again, you may need to compile a "clean" build. Compiling a "clean" build means that all object files created for your executable from the last time you compiled are removed and rebuilt from scratch. This prevents glitches in the final executable caused by old settings that you have since removed from the source code.
Compiling a "clean" build of SRB2 can be done with the Makefile by adding on the word
clean to the end of your compiling command.
For example, on Windows the following command creates a "clean" version of SRB2:
mingw32-make MINGW=1 CC=gcc WINDOWSHELL=1 SDL=1 NOOBJDUMP=1 clean
On Windows, however, compiling with
clean will not work correctly without
rm.exe, which is not included with Windows by default. A port of
rm.exe to Windows is included with MSYS, an optional component of MinGW. On Linux,
rm is already included.
Alternatively, one can remove the object files manually by going into the
objs folder of your source folder, going to the corresponding sub-folder for the port and type of build you are making until you see files ending in
.o, and deleting all files except
.gitignore inside it. When compiling normal release builds for Windows for instance, you must navigate to
objs/Mingw/SDL/Release to do this; for DirectDraw builds, you must navigate to
objs/Mingw/Release instead. After deleting the files, compiling normally will re-build all object files, resulting in a "clean" build of SRB2.
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.
||Compile for i686 Linux.|
||Compile for x86_64 Linux.|
||Compile for Windows using MinGW.|
||Compile with SDL.|
||Windows only; use comptime.bat instead of comptime.sh, don't use certain gzip commands.|
||Windows only; compiles using GCC, which is default on Linux.|
||Disable OpenGL and OpenAL.|
||Fall back on |
||Do not use NASM/YASM code (software optimizations); fall back on extra C code instead of x86.|
||Do not use libpng; fall back on PCX/TGA code instead of PNG for screenshots.|
||Do not use UPX when compiling.|
||Compile using YASM instead of NASM.|
||Compile debug binaries.|
||Have more flags for warnings when compiling.|
||Have all warnings register as errors.|
||Compiles with profiling information. After running the executable and exiting normally, the profile data for it is written into a file named |
||Compile with dummy interface code.|
||Print detailed information during the compiling process.|
For a detailed list of these flags and many more, check here.