Source code compiling/Compiling on macOS
This tutorial demonstrates how to build SRB2 from source code on macOS and generate a playable, release-able application that can be distributed to other macOS users.
Pre-Requisites
- Before beginning, you should at least be comfortable using the command-line/Terminal and writing simple C/C++ programs.
- You will need to have XCode Command Line Tools installed.
- You can install them by running
xcode-select --install
in terminal or by downloading XCode.app through the App Store (NOTE: XCode.app is 16GB, use xcode-select if you are low on disk space).
- You can install them by running
- You will also need CMake
- You might need (TODO: are these required?)
autoconf
andpkgconfig
- You should add the following lines to your shell's rc file--typically ~/.bash_profile or ~/.zshrc for macOS:
export MACOSX_DEPLOYMENT_TARGET=10.9
export LIBRARY_PATH=/usr/local/lib
# The first line tells the compiler to support users running macOS 10.9 and later.
# This is the earliest version SRB2 compiles to.
# You will want to build for this version in order to support as many users as possible.
# When building SRB2, the linker has trouble finding the SDL2 library.
# The second line tells the linker where to find SDL2.
Miscellaneous Notes
- When installing dependencies with
make install
, they will be installed at/usr/local/
by default.- It should be possible to specify an installation prefix other than
/usr/local/
, but in my experience this is more trouble than it's worth. - The prefix
/usr/local/
does not contain any system files, so it can safely be deleted, moved, copied, backed up, etc. if needed. - The Homebrew package manager also installs packages to
/usr/local/
, but it builds packages for your current version of macOS (not 10.9 and later). In order to support as many users as possible, do not overwrite your files with Homebrew! If you do by accident, simply build the dependency again, or restore/usr/local
from a backup.
- It should be possible to specify an installation prefix other than
- There will be some minor differences between the Windows build of SRB2 and the macOS build:
- The Windows build uses SDL Mixer X, instead of SDL Mixer
- Because of this, playing MIDI music through FluidSynth sans GLib, libOPNMIDI or Timidity is not supported.
Build Process
The version numbers listed for each dependency are the latest versions at the time of this writing, unless otherwise noted. Feel free to use more recent versions, if available.
If the dependency is built using CMake, you will:
- Download the source code.
- Modify the source code, if necessary.
- Create an empty build folder.
- Open CMake and set the source and build folder.
- Set the CMake variables (usually just
CMAKE_BUILD_TYPE=Release
andCMAKE_OSX_DEPLOYMENT_TARGET=10.9
). - Run Configure: Use Unix Makefiles as the generator.
- Run Generate.
- Navigate to the build folder in terminal and run
make
, then runmake install
If the dependency is built using configure and make scripts, you will:
- Download the source code.
- Modify the source code, if necessary.
- Navigate to the build folder in terminal and run
<path-to-source>/configure
- Run
make
followed bymake install
in terminal.
Building Dependencies
libpng 1.6.37
Source Code Modifications
- Edit
<path-to-source>/png.h
and undefinePNG_IGNORE_ADLER32
- Otherwise it will use a function that only exists in macOS > 10.13.
Build Process
In CMake, set:
CMAKE_OSX_DEPLOYMENT_TARGET=10.9
CMAKE_BUILD_TYPE=Release
In the build folder, run: make
followed by make install
in Terminal.
libogg 1.3.4
Source Code Modifications
- Edit
<path-to-source>/include/ogg/os_types.h
and add#include <stdint.h>
in the__APPLE__
section.- Otherwise, you get an error when building libvorbis.
Build Process
In CMake, set:
BUILD_SHARED_LIBS=true
CMAKE_OSX_DEPLOYMENT_TARGET=10.9
CMAKE_BUILD_TYPE=Release
In the build folder, run: make
followed by make install
in Terminal.
libvorbis 1.3.6
libogg is required before building libvorbis
Build Process
In the build folder, run:
<path-to-src>/configure
make
make install
libmpg123 1.25.13
Build Process
In the build folder, run:
<path-to-src>/configure
make
make install
libmodplug master (latest commit: 48be221)
Build Process
In CMake, set:
BUILD_SHARED_LIBS=true
CMAKE_OSX_DEPLOYMENT_TARGET=10.9
CMAKE_BUILD_TYPE=Release
In the build folder, run: make
followed by make install
in Terminal.
libopenmpt 0.4.12 (autotools)
Build Process
In the build folder, run:
<path-to-src>/configure --without-portaudio --without-portaudiocpp --without-sndfile --without-flac
make
make install
libgme 0.6.2
Use version 0.6.2, not 0.6.3
Build Process
In CMake, set:
BUILD_SHARED_LIBS=true
CMAKE_OSX_DEPLOYMENT_TARGET=10.9
CMAKE_BUILD_TYPE=Release
In the build folder, run: make
followed by make install
in Terminal.
libsdl2 2.0.12
Build Process
In CMake, set:
CMAKE_OSX_DEPLOYMENT_TARGET=10.9
CMAKE_BUILD_TYPE=Release
HIDAPI=true
In the build folder, run: make
followed by make install
in Terminal.
sdl2_mixer 2.0.4
The following libraries are required before building sdl2_mixer:
- libogg
- libvorbis
- libmpg123
- libmodplug
- libsdl2
Build Process
In the build folder, run:
<path-to-src>/configure \
--disable-dependency-tracking \
--disable-music-flac \
--disable-music-flac-shared \
--enable-music-midi \
--disable-music-midi-fluidsynth \
--disable-music-midi-fluidsynth-shared \
--enable-music-midi-native \
--disable-music-midi-timidity \
--enable-music-mod \
--disable-music-mod-mikmod \
--disable-music-mod-mikmod-shared \
--enable-music-mod-modplug \
--disable-music-mod-modplug-shared \
--enable-music-mp3 \
--enable-music-mp3-mpg123 \
--disable-music-mp3-mpg123-shared \
--enable-music-ogg \
--disable-music-ogg-shared \
--disable-music-opus \
--disable-music-opus-shared \
--enable-music-wave
make
make install
Sonic Robo Blast 2 2.2.4
Source Code Modifications
- Add files from windows installer and patch to
<path-to-source>/assets/installer
. Remove the Windows executables:rm *.dll *.bat .exe
. - Edit
<path-to-source>/src/sdl/CMakeLists.txt
. Lines 365 to 373 in should be:- (These lines tell the build tools where to find the dependencies so that they can be packaged into a standalone app.)
if(${CMAKE_SYSTEM} MATCHES Darwin)
set(extra_dirs "/usr/local/lib" "/lib" "/usr/lib")
install(CODE "
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CPACK_PACKAGE_DESCRIPTION_SUMMARY}.app\"
\"\"
\"${extra_dirs}\"
)"
)
endif()
Build Process
In CMake, set:
CMAKE_OSX_DEPLOYMENT_TARGET=10.9
CMAKE_BUILD_TYPE=Release
In the build folder, run:
make
make package
Products
Running make
creates <path-to-build>/bin/Sonic Robo Blast 2.app
, which you can use to test your build; however, it links to the dependencies with an absolute path, so it will not work for other Mac users.
Running make package
creates an installer (.dmg
file) in the build folder. The app includes SRB2's dependencies so you can distribute the .dmg
file to other Mac users.