User:Wolfy/Source code compiling
Welcome to the source code compiling tutorial. This tutorial teaches you how to compile SRB2's source code to create an executable you can launch. The compiling process is necessary for creating custom source code modifications. This tutorial won't teach you how to modify the source code, it will only explain the process of compiling for several platforms.
Compiling on Windows
If you're on Windows, you have the highest selection of tools to compile with.
MinGW
MinGW is the most stable and recommended method for compiling on Windows.
For this method 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. The packages may take a while to download. As soon as the downloads are complete, move onto the next step.
Dependencies
SRB2 relies on two separate dependencies for compiling on Windows: The Netwide Assembler (or NASM for short) and DirectX 8. The first dependency, NASM, can be downloaded here. After the installation is complete, you need to download the next dependency: the DirectX 8 devpack for SRB2, 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.
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\nasm;C:\MinGW\msys\1.0\bin
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
There are now two ways you can compile SRB2. The first is 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. From here, use the following command syntax to compile the source:
make MINGW=1 CC=gcc WINDOWSHELL=1 NOUPX=1
MSYS bash
If you'd prefer not to put MSYS in your path to compile, you must launch the MSYS bash terminal instead. Navigate to the directory you installed MinGW into (usually C:\MinGW), and navigate through to msys/1.0. From here, launch msys.bat
to bring up MSYS bash. You'll be greeted with a Unix-style command prompt upon opening it. The next step is similar to the command line, navigate to the source folder with the cd
command, but you don't need to navigate into the "src" folder. From here, you can compile the game using the same command syntax as shown above.
SDL2
The process for compiling SRB2 with SDL2 is somewhat different from compiling normally. You'll first need two more dependencies, the SDL2 Development Library, and the SDL2_mixer Development Library. After these are downloaded, navigate to the first directory inside. From here, you should see a folder titled "i686-w64-mingw32". Enter the folder, extract all of its contents into your MinGW directory, and merge all folders that prompt you to. Do this for both SDL2 and SDL2_mixer. As of the stable release of SDL2 version 2.0.3, compiling on Windows will only function properly on Windows 8 due to a bug with one of the library files. A patch for this bug can be found here. Extract the contents to your MinGW directory, merge all folders prompted, and replace all files prompted.
If you installed MinGW in a directory other than C:\MinGW, you must edit MinGW\bin\sdl2-config to correspond to your directory. Open the file in any text editor of your choice. You should see a line reading
prefix=/C/MinGW
on line 3 of the file. Change the directory listed by this to correspond to your MinGW directory and save the file.
Now, you're ready to compile. Navigate to the source directory, and compile with the following syntax:
make -C src CC=gcc MINGW=1 SDL=1 WINDOWSHELL=1 NOUPX=1
If either method worked, you can find the compiled executable (srb2win.exe normally, srb2sdl.exe for SDL2) 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 anyways 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 same as MSYS. When cross-compiling, it is not necessary to use the CC=gcc flag and you should not use the WINDOWSHELL=1 or NOUPX=1 flags, since they will cause compile failures.
Visual C++
Visual C++ (MSVC) is Microsoft's C/C++ compiler and IDE (a tool that allows an easy and integrated development of software). While there exist projects for compiling SRB2 with MSVC, Windows builds with MSVC cannot play multiplayer games with gcc builds due to differences in each compiler's struct packing schemes. As such, it is usually advised to use MinGW instead as the official builds are compiled under gcc.
Download Visual C++ 2010 Express first from here. Visual C++ Express is a free version of Visual C++ and is ideal for SRB2.
You then need to get the required libraries and headers. You'll need the DirectX SDK in order to compile under MSVC. If you have no luck finding this, please ask in SRB2Fun.
For compiling SDL2 builds, you'll also need the SDL2 Development Library for MSVC and the SDL2_mixer Development Library for MSVC. As SRB2's SDL2 port is not configured to compile with MSVC by default, you will need to manually include the libraries in the project.
Simply open the project file and press a little green arrow in the toolbar, and the compiled EXE and r_opengl.dll (if you didn't use SDL2) will be placed in bin/VC/Release or bin/VC/Debug. If this failed, please contact Alam in SRB2Fun.
Compiling on Linux
General
To compile on Linux, you need to have the development libraries for SDL at minimum, as well as the gcc toolchain (make, gcc, etc), but it is recommended to have NASM and SDL_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 SDL_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: build-essential nasm libpng12-dev zlib1g-dev libsdl-mixer1.2-dev
For the SDL2 port: build-essential nasm libpng12-dev zlib1g-dev libsdl2-mixer-dev
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.
LINUX=1 -- Compile for i686 Linux LINUX64=1 -- Compile for x86_64 Linux WINDOWS=1 -- Compile an executable for Windows, only necessary when compiling Windows builds on Linux. MINGW=1 -- Compile for Windows using MinGW SDL=1 -- Compile with SDL WINDOWSHELL=1 -- Windows only, don't use certain gzip commands CC=gcc -- Windows only, compiles using gcc which is default on Linux 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), will fall back with extra C code instead of x86 NOPNG=1 -- Do not use libpng for screenshots (also removes zlib dependency) NOUPX=1 -- Do not use UPX when compiling, removes one of the errors on Windows NASM=yasm -- Compiles 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 DUMMY=1 -- Compile with dummy interface code ECHO=1 -- Gives you detailed information during the compiling process.
It should be noted that SRB2 already includes libpng and zlib in the source code, making the NOPNG flag unnecessary.