Cross Compiling Plugins (Metamod:Source)
The aim of this tutorial is to allow Windows Half-Life 2 plugin coders to compile their plugins on the same machine as the windows binaries. The binaries are compatible with 99% of all linux servers and do not suffer from bulky file sizes. One of the main benefits to using this method of compiling is that your code can be left wherever you currently have it so that compile time reluctance is removed and coders can concentrate on coding the plugins instead of "How on earth am I to compile this for linux ???". All you need to get started are the base Cygwin installation, the CrossTool.tar.gz file and the makefile. Links to the latter two are included at the end of the tutorial.
This tutorial assumes the following.
- You currently have a plugin which you can compile on windows using MSVC.
- You have a copy of the HL2SDK Source Code installed on your hard drive.
- You have a copy of the Metamod:Source source code on your hard drive.
Although the cross compiler will allow for compiling of Valves standard plugins, I do not include a Makefile or instructions on how to successfully accomplish this.
First, download CygWin from www.CygWin.com by clicking on "Install Now" located in the middle of the page.
Once the download finishes, run setup.exe Click 'Next' on the introduction screen.
On the second page, select 'Install from Internet'.
The following page is all user preferances, except the 'Default Text File Type' which is recommended you use 'Unix / binary'.
After clicking next, you are prompted for a CygWin temporary folder, any folder will suffice, the default is usually the better option.
The next screen's options are firewall/proxy settings, these are specific to the Computer/Network you are currently using.
Once you click next on the previous screen, the installer will download a list of mirror sites containing the CygWin binaries. Select one which you think is closest to you for a faster installation time.
Finaly, you are presented with a 'Select Packages' screen.
I *think* it should work fine without all of the dev packages.
If anyone has gotten this to work by selecting less packages, please let me know so I can remove them from this list.
Items marked in bold are extremely important.
Click next and it should install the packages to the target path you specified.
Download the CrossCompiler from one of the mirrors below to the root cygwin folder (c:\cygwin). If it gets renamed to 'crosstool_gcc-3.4.1.tar.tar' please rename it to 'crosstool_gcc-3.4.1.tar.gz'. Download Mirrors for 'crosstool_gcc.tar.gz'
This is the most important part of the entire tutorial.
Do not try and extract 'crosstool_gcc-3.4.1.tar.gz' using any Windows Archiving utility ! They do not extract the files correctly and if you don't get errors during the extraction, you will while trying to compile ! Once the download is complete, run cygwin by navigating to the cygwin root folder, and double clicking on 'cygwin.bat'. Type the following two commands in order into the cygwin bash shell followed by the enter key:
cd / tar -xzf crosstool_gcc-3.4.1.tar.gz
This will start extracting the tar file to the '<cygroot>/opt' folder on your hard drive. And thats it, now you have the pre-compiled GCC 3.4.1 (Thanks LDuke) installed on your computer you can compile server plugins for both regular and SourceMM flavours with ease and compatibility with Valves GCC 3.4.1 requirements.
Download the Makefile by clicking on this link.
Save it to your project's root source folder and open it with a text editor like notepad.
Inside the Makefile I have shown examples on how your paths are translated into unix/cygwin hybrid paths.
So, before trying any compling just yet, you need to insert the paths for the following.
HL2SDK: The path to where your HL2SDK files are located.
SMM_ROOT: The path to where you extracted the contents of the SourceMM package
SRCDS: The path to the linux SRCDS binaries.
PLUGIN: The plugin filename.
For the convenience of those who don't have access to a Linux srcds installation, you can grab the files required at one of the mirrors below.
Extract them to a new folder which will be your SRCDS path in the Makefile.
Note:The bin folder must be inside the srcds folder for maximum compatibility. For example, your files end up being something like this 'C:\MyFiles\srcds_l\bin\vstdlib_i486.so'.
So, in your Makefile, SRCDS would be '/cygdrive/c/MyFiles/srcds_l'
Download Mirrors for 'srcds_l_binaries.zip'
Now you're ready to try compiling. Back to the cygwin bash window, and we're now going to have to navigate to your code's location. An example path could be 'C:\MyCode\MyPlugin\' so in the bash shell we type the following:
cd /cygdrive/c/MyCode/MyPlugin/ make
If all your paths are set correctly, it should start compiling the plugin. Ignore all the warnings in the HL2SDK, they are harmless. What you should be looking out for are errors and warnings located inside your own code. Unfortunately I cannot compile plugins for you, but there is a forum dedicated to helping you with hl2sdk coding problems.
- Tutorial by: Jason "c0ldfyr3" Croghan
- Cross Compiler compiled by: L. Duke
- Makefile originally written by: David "BAILOPAN" Anderson
- Converted to Wiki by: James "sslice" Gray
Original Location: http://www.c0ld.net/index.php?inc=CrossTool