Difference between revisions of "Building SourceMod"

From AlliedModders Wiki
Jump to: navigation, search
m (A few windows-only ones are in here.)
(Added more directories/symlinks for Linux compilation)
Line 73: Line 73:
 
SourceMod's Makefiles have strict directory organizational rules.  You must have a top-level folder.  For this document, we'll assume it is called <tt>sourcemod</tt>, though it can be named anything.  The layout of <tt>sourcemod</tt> must be:
 
SourceMod's Makefiles have strict directory organizational rules.  You must have a top-level folder.  For this document, we'll assume it is called <tt>sourcemod</tt>, though it can be named anything.  The layout of <tt>sourcemod</tt> must be:
 
*<tt>sourcemod</tt>/
 
*<tt>sourcemod</tt>/
**<tt>hl2sdk</tt> - symlink or folder containing the HL2SDK
+
**<tt>hl2sdk</tt> - symlink or folder containing the HL2SDK for Original/Episode 1
**<tt>hl2sdk-ob</tt> - symlink or folder containing the HL2SDK for Orange Box/TF
+
**<tt>hl2sdk-ob</tt> - symlink or folder containing the HL2SDK for Orange Box
 +
**<tt>hl2sdk-css</tt> - symlink or folder containing the HL2SDK for CS:S
 +
**<tt>hl2sdk-ob-valve</tt> - symlink or folder containing the HL2SDK for Source 2009 (HL2:DM, DoD:S, TF2)
 +
**<tt>hl2sdk-l4d</tt> - symlink or folder containing the HL2SDK for Left 4 Dead
 +
**<tt>hl2sdk-l4d2</tt> - symlink or folder containing the HL2SDK for Left 4 Dead 2
 +
**<tt>hl2sdk-csgo</tt> - symlink or folder containing the HL2SDK for CS:GO
 
**<tt>mmsource-central</tt> - symlink or folder containing any Metamod:Source version 1.7 or higher (1.9 or newer recommended for CS:S and CS:GO support)
 
**<tt>mmsource-central</tt> - symlink or folder containing any Metamod:Source version 1.7 or higher (1.9 or newer recommended for CS:S and CS:GO support)
 
**<tt>sourcemod-central</tt> - folder containing SourceMod's source code tree.  This can be named anything, as long as it's a valid SourceMod tree (like [http://hg.alliedmods.net/sourcemod-central sourcemod-central]).  You can also use [http://hg.alliedmods.net/sourcemod-1.1 sourcemod-1.1].
 
**<tt>sourcemod-central</tt> - folder containing SourceMod's source code tree.  This can be named anything, as long as it's a valid SourceMod tree (like [http://hg.alliedmods.net/sourcemod-central sourcemod-central]).  You can also use [http://hg.alliedmods.net/sourcemod-1.1 sourcemod-1.1].
Line 143: Line 148:
  
 
===Dependent Binaries===
 
===Dependent Binaries===
Binaries that have an Engine or MM:S dependency require one extra parameter, <tt>ENGINE</tt>.  It must be <tt>original</tt>, <tt>orangebox</tt>, <tt>css</tt>, <tt>orangeboxvalve</tt>, <tt>left4dead</tt>, <tt>left4dead2</tt>, or <tt>csgo</tt>.  For example, to build a TF-compatible binary in debug mode:
+
Binaries that have an Engine or MM:S dependency require one extra parameter, <tt>ENGINE</tt>.  It must be <tt>original</tt>, <tt>orangebox</tt>, <tt>css</tt>, <tt>orangeboxvalve</tt>, <tt>left4dead</tt>, <tt>left4dead2</tt>, or <tt>csgo</tt>.  For example, to build a TF2-compatible binary in debug mode:
  
 
<pre>make ENGINE=orangeboxvalve DEBUG=true</pre>
 
<pre>make ENGINE=orangeboxvalve DEBUG=true</pre>

Revision as of 16:58, 6 December 2012

Compiling SourceMod is not difficult, but requires a number of prerequisites. This article details the requirements and steps to being able to build working SourceMod binaries. These directions may change any time and may be updated as SourceMod's build process improves.

Note: You cannot use MingW to build working SourceMod Windows binaries. It is not ABI compatible with Visual C++ which is what Valve uses for the Source engine. You can only use GCC to build Linux binaries.

Requirements

Windows

  • Microsoft Visual C++ 2010 (Express or higher) is supported and used for official builds.
  • Microsoft Visual C++ 2008 (Express or higher) is supported.
  • Microsoft Visual C++ 2005 (Express or higher) is unsupported.
  • Microsoft Visual C++ 2003 7.1 or higher may not build out-of-box, but can build compatible binaries.
  • Microsoft Visual C++ 2003 7.0 or lower cannot be used.

If you are installing Visual C++ 2005 Express, it may not come with Microsoft's Platform SDK installed. If this is the case, you must manually install the Platform SDK. You can find directions on how to do this and test your setup here. Visual C++ 2008 "streamlines" the Platform SDK installation according to Microsoft.

Linux

For Linux, SourceMod requires the GNU C/C++ Compiler (from GCC):

  • Version 4.4 is used for official binaries and is guaranteed to build.
  • Versions 3.4 through 4.3 are guaranteed to be binary (ABI) compatible, although SourceMod may not necessarily build out-of-box against them.
  • Any GCC version below 3.4 cannot be used.

CPU

SourceMod is strictly a 32-bit x86 (IA32) product. You should not try to force a compiler to build 64-bit binaries of SourceMod.

Your CPU and its compiler must support SSE in order to build SourceMod. To build without needing or having a dependency against SSE, please see the Removing SSE section near the bottom.

Approximate compiling times for SourceMod's Core are roughly in September 2008:

  • Windows, Core 2 Quad E6600: 30 seconds (using /MP)
  • Windows, Core 2 Duo E6600: 75 seconds
  • Windows, Centrino 1.8GHz: 5 minutes
  • Linux, Core 2 Duo E6600: <= 1 minute
  • Linux, P3 Dual 500MHz: >= 7 minutes

Setup

This section describes how to set up your computer for compiling.

Getting the Files

This section describes which files you must obtain and how to obtain them. Do not worry about where to place them yet -- that will be discussed on a per-platform basis. You can download the files anywhere you'd like.

The recommended method of getting the required files is via Mercurial. We have our own Mercurial_Tutorial if you prefer that method. Although you do not need all HL2SDK versions (unless you wish to build binaries against all of them), you do need Metamod:Source. Extensions don't necessarily require Metamod:Source (or even the Source Engine) but its template library is used extensively in SourceMod.

  • SourceMod. For full download options, see the SourceMod Downloads page. Obviously, you must download the source code and not a binary package.
  • Download the appropriate Source SDK for the game you want to compile for or download it from the list below:
    • HL2SDK Original. As of this writing (Dec 2012) this engine is only used by Half-Life: Source Deathmatch (not HL2:DM) and third-party mods. Repository: hl2sdk
    • HL2SDK OrangeBox. As of this writing (Dec 2012) this engine is only used by third-party mods. Repository: hl2sdk-ob
    • HL2DSK OrangeBox Valve. As of this writing (Dec 2012) this engine is used for Source 2009 games (HL2:DM, DoD:S, and TF2). Repository: hl2sdk-ob-valve
    • HL2SDK Alien Swarm. This engine is used for Alien Swarm. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-swarm
    • HL2SDK BGT. This engine is used for Bloody Good Time. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-bgt
    • HL2SDK CS:GO. This engine is used for CS:GO. Repository: hl2sdk-csgo
    • HL2SDK CS:S. This engine is used for CS:S. Repository: hl2sdk-css
    • HL2SDK DarkM. This engine is used for Dark Messiah. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-darkm
    • HL2SDK EYE. This engine is used for E.Y.E. Divine Cybermancy. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-eye
    • HL2SDK Gmod12. This engine is used for GMod12. As of this writing (Dec 2012), SourceMod does not support GMod13. Repository: hl2sdk-gmod
    • HL2SDK Left4Dead. This engine is used for L4D. Repository: hl2sdk-l4d
    • HL2SDK Left4Dead2. This engine is used for L4D2. Repository: hl2sdk-l4d2
    • HL2SDK Portal 2. This engine is used for Portal 2. As of this writing (Dec 2012), SourceMod does not support Portal 2. Repository: hl2sdk-portal2
  • Metamod:Source Source Code. Visit Metamod:Source downloads. Right now SourceMod builds against Metamod:Source 1.9.

Note that when we refer to "Metamod:Source" in this article, we are referring to its source code tree, not a binary package.

If you intend to compile the MySQL extension, you must also download MySQL 5.0. You can use any version. For simplicity, here are the versions we use:

  • Linux: We use the 5.0.45 binary from the "Linux (non RPM packages)" for "Linux (x86)." You can also use this direct link (may not be valid in the future).
  • Windows: Due to a MySQL build change we use 5.0.24a which is an older download. The file name was "mysql-5.0.24a-win32.zip," if you can't find it you can use this direct link (may not be valid in the future).

You can remove all folders from the distribution except for the "lib" and "include" folders which comprise the MySQL SDK.

Linux

As of this writing, SourceMod's Makefiles are hardcoded to use a binary called "gcc" You can override this, for example:

make CPP=gcc-4.4

Note that you must use gcc and not g++.

SourceMod's Makefiles have strict directory organizational rules. You must have a top-level folder. For this document, we'll assume it is called sourcemod, though it can be named anything. The layout of sourcemod must be:

  • sourcemod/
    • hl2sdk - symlink or folder containing the HL2SDK for Original/Episode 1
    • hl2sdk-ob - symlink or folder containing the HL2SDK for Orange Box
    • hl2sdk-css - symlink or folder containing the HL2SDK for CS:S
    • hl2sdk-ob-valve - symlink or folder containing the HL2SDK for Source 2009 (HL2:DM, DoD:S, TF2)
    • hl2sdk-l4d - symlink or folder containing the HL2SDK for Left 4 Dead
    • hl2sdk-l4d2 - symlink or folder containing the HL2SDK for Left 4 Dead 2
    • hl2sdk-csgo - symlink or folder containing the HL2SDK for CS:GO
    • mmsource-central - symlink or folder containing any Metamod:Source version 1.7 or higher (1.9 or newer recommended for CS:S and CS:GO support)
    • sourcemod-central - folder containing SourceMod's source code tree. This can be named anything, as long as it's a valid SourceMod tree (like sourcemod-central). You can also use sourcemod-1.1.
    • mysql-5.0 - symlink or folder containing a MySQL 5.0 distribution

If you are using a 64-bit version of Linux, you may need to install extra packages to be able to compile SourceMod. On Debian-based distros, these are typically:

#prerequisites
#apt-get install g++-4.1 gcc-4.1 make subversion
#apt-get install libz libz-dev
#only needed if you want to use the build tool
#apt-get install mono mono-devel
#32-bit support
apt-get install ia32-libs
apt-get install lib32z1 lib32z1-dev
apt-get install libc6-dev-i386 libc6-i386

Windows

On Windows we don't require a particular directory layout. Instead, environment variables are used. The directions below apply to Windows XP, and are assumed to be similar for other versions of Windows.

  • Open the Control Panel (for example, via Start -> Settings).
  • Open the System control. If you don't see it, you may need to switch to "Classic view" (either via the left-hand pane or by going to Tools -> Folder Options).
  • Click the Advanced tab.
  • Click the Environment Variables button.

You can add your environment variables to either your User settings or your System settings. Create a new variable for each item in the list below. The item names are in fixed-width font and their value descriptions follow.

  • MMSOURCE19 - Path to Metamod:Source 1.9+
  • HL2SDK - Path to HL2SDK Ep1/Original
  • HL2SDKOB - Path to HL2SDK Ep2/OrangeBox for mods
  • HL2SDKOBVALVE - Path to HL2SDK Source 2009 (HL2:DM, DoD:S, TF2)
  • HL2SDK-SWARM - Path to HL2SDK Alien Swarm
  • HL2SDK-BGT - Path to HL2SDK for Bloody Good Time
  • HL2SDKCSGO - Path to HL2SDK CS:GO
  • HL2SDKCSS - Path to HL2SDK CS:S
  • HL2SDK-DARKM - Path to HL2SDK Dark Messiah
  • HL2SDK-EYE - Path to HL2SDK E.Y.E.: Divine Cybermancy
  • HL2SDKL4D - Path to HL2SDK L4D1
  • HL2SDKL4D2 - Path to HL2SDK L4D2

Note that the Windows project does not have entries for Portal 2 or GMod.

Building

SourceMod has two types of binaries: those with an engine/MM:S dependence, and those without ("normal" binaries). Normal binaries have two modes:

  • Release - Optimized binary for release.
  • Debug - Unoptimized binary with debugging checks.

Engine/MM:S dependent binaries have three build modes, each paired with either Release or Debug, meaning there are six build options total. They are:

  • Original - Building against MM:S 1.4 API with HL2SDK
  • Episode2 - Building against MM:S 1.6 API with HL2SDK-OB or higher

Linux

For both Normal and Engine/MM:S dependent binaries, the object files and the final binary are placed in a folder called Release or Debug (in the same level as the Makefile) depending on which building mechanism you chose.

Note: Our Makefiles are not set up to detect changes in header files. If you change a header file, you must clean your build.

Note that the Linux Makefile does not have entries for Dark Messiah, E.Y.E. Divine Cybermancy, Bloody Good Time, Portal 2, or GMod.

Normal Binaries

For normal binaries, you can build simply with:

make

You can clean stale object files with:

make clean

Or build debug builds with:

make DEBUG=true

Dependent Binaries

Binaries that have an Engine or MM:S dependency require one extra parameter, ENGINE. It must be original, orangebox, css, orangeboxvalve, left4dead, left4dead2, or csgo. For example, to build a TF2-compatible binary in debug mode:

make ENGINE=orangeboxvalve DEBUG=true

Dependent binaries are dropped into one of the following folders:

  • Debug.original
  • Debug.orangebox
  • Debug.css
  • Debug.orangeboxvalve
  • Debug.left4dead
  • Debug.left4dead2
  • Debug.csgo
  • Release.original
  • Release.orangebox
  • Release.css
  • Release.orangeboxvalve
  • Release.left4dead
  • Release.left4dead2
  • Release.csgo

Windows

Windows project files end with .vcproj and are found in an msvc10 folder that resides inside each binary's main source folder. For example, Core is located in core/msvc10/sourcemod_mm.sln.

Once the file is opened, you can select which build to use by using the Solution Configurations listbox near the top of the screen. As of MetaMod: Source 1.9, those are:

  • CrazyDebug - Alien Swarm
  • CrazyDebug - Bloody Good Time
  • CrazyDebug - CS GO
  • CrazyDebug - CSS
  • CrazyDebug - Dark Messiah
  • CrazyDebug - Episode 1
  • CrazyDebug - EYE
  • CrazyDebug - Left 4 Dead 2
  • CrazyDebug - Left 4 Dead
  • CrazyDebug - Old Metamod
  • CrazyDebug - Orange Box Valve
  • CrazyDebug - Orange Box
  • Debug - Alien Swarm
  • Debug - Bloody Good Time
  • Debug - CS GO
  • Debug - CSS
  • Debug - Dark Messiah
  • Debug - Episode 1
  • Debug - EYE
  • Debug - Left 4 Dead 2
  • Debug - Left 4 Dead
  • Debug - Old Metamod
  • Debug - Orange Box Valve
  • Debug - Orange Box
  • Release - Alien Swarm
  • Release - Bloody Good Time
  • Release - CS GO
  • Release - CSS
  • Release - Dark Messiah
  • Release - Episode 1
  • Release - EYE
  • Release - Left 4 Dead 2
  • Release - Left 4 Dead
  • Release - Old Metamod
  • Release - Orange Box Valve
  • Release - Orange Box

Once you have selected a configuration, you can compile by going to Build -> Build Solution. The binaries and object files will be written to a folder inside msvc10 named after the full configuration name. For example, using "Debug - Old Metamod" with the "sdktools" extension will result in the binary: extensions/sdktools/msvc10/Debug - Old Metamod/sdktools.ext.dll

Note: Visual Studio detects changes to header files intelligently. It is usually not necessary to rebuild a solution.

Binary Organization

Although SourceMod has a somewhat unified building mechanism, each of the binaries has a different purpose. They can be separated into the following classes:

  • Core-Related: Binaries which are required or loaded intrinsically by Core.
  • Extensions: Binaries which are loaded via the extension mechanism.
  • External: Binaries which are standalone or unrelated to SourceMod's live operation (for example, the compiler).

This article is only concerned with the first two types.

Core-Related Binaries

Binaries related to Core are spread throughout the source code tree. They are always placed in sourcemod/bin for packaging. The projects files related to Core are:

  • loader - This is a very small wrapper binary responsible for detecting the MM:S version and game engine, and deciding which SourceMod version to load. The output binary is sourcemod_mm_i486.so or sourcemod_mm.dll.
  • core - This is Core itself, and is a dependent binary. It has eleven outputs:
    • Original/Episode 1: sourcemod.1.ep1.so/sourcemod.1.ep1.dll
    • Orange Box: sourcemod.2.ep2.so/sourcemod.2.ep2.dll
    • Orange Box Valve: sourcemod.2.ep2v.so/sourcemod.2.ep2v.dll
    • Alien Swarm: sourcemod.2.swarm.so/sourcemod.2.swarm.dll
    • Bloody Good Time: sourcemod.2.bgt.so/sourcemod.2.bgt.dll
    • CS:GO: sourcemod.2.csgo.so/sourcemod.2.csgo.dll
    • CS:S: sourcemod.2.css.so/sourcemod.2.css.dll
    • Dark Messiah: sourcemod.2.darkm.so/sourcemod.2.darkm.dll
    • E.Y.E.: sourcemod.2.eye.so/sourcemod.2.eye.dll
    • Left 4 Dead: sourcemod.2.l4d.so/sourcemod.2.l4d.dll
    • Left 4 Dead 2: sourcemod.2.l4d2.so/sourcemod.2.l4d2.dll
  • sourcepawn/jit/x86 - This is the SourcePawn JIT for generating IA32/x86 instructions from .smx files. Currently the source code for this is not made available. It is built as sourcepawn.jit.x86.so/sourcepawn.jit.x86.dll.

It is technically not necessary to use the loader. It is provided as a convenience so users do not have to perform extra steps while installing SourceMod. However, it is highly recommend that you do use it in order to maintain similarity with the default SourceMod package.

Extensions

Extensions are found in the extensions folder of the source tree. SDKTools, Cstrike, and the TF2 extension are engine/MM:S dependent (and the rest are generally not).

Normal extensions are named name.ext.so or name.ext.dll where name is a unique identifier. Dependent extensions will be named like core above.


For example, the SDKTools binary on Counter-Strike: Source for Window would be loaded from extensions/sdktools.ext.2.css.dll, but the GeoIP binary (which is not dependent) would be loaded from extensions/geoip.ext.dll.

Removing SSE

SourceMod binaries are built against SSE by default. SSE is an important set of optimizations, that, according to Valve's hardware survey, are supported on 99.6% percent of respondents' computers. If you are in this 0.4% which does not have SSE support, you should consider buying a newer processor. Only early Pentium 3-grade processors did not have SSE support (for example, the very early Durons), and it is likely your Source server will not perform adequately to support more than few players.

Nonetheless, SourceMod's binaries can all be recompiled to remove its SSE dependence.

Linux

Edit the Makefile of the binary you are trying to compile. Remove all instances of these flags. They can simply be erased, there is no need to replace them with anything.

  • -msse
  • -mfpmath=sse

Make sure to clean the build after changing the Makefile.

Windows

Load the project file into Visual Studio. Go to Project -> Properties. Expand "Configuration Properties," and then "C/C++" under it. Select "Code Generation." Change the setting "Enable Enhanced Instruction Set" to "Not Set."

Note: You must change this setting for each build configuration that you wish to use.