User:Wunderboy/sandbox: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
''<nowiki>[prepping this before I move it to a mod page.]</nowiki>''
The following are various notes, scribbles, thoughts, etc. from doing various Source-type things. None of these are structured of "definate" - just things I write down for reference. If anything you find here is useful, great, but use it ''at your own risk!!!''
{{Namespace}}


{{AlphaModSmall|engine=Source|download=}}
=Compiling the SDK under Linux with Fedora Core 6=
[[Image:Haj_01.jpg|thumb|300px|The barn, haj_radar - Click to enlarge]]
[[Image:Haj_02.jpg|thumb|300px|The barn, haj_radar - Click to enlarge]]
[[Image:Haj_03.jpg|thumb|300px|Covered trench - Click to enlarge]]
[[Image:Haj_04.jpg|thumb|300px|Observation bunker - Click to enlarge]]
[[Image:Haj_05.jpg|thumb|300px|No-man's Land - Click to enlarge]]


==Overview==
The following are some notes on how I set-up a build environment and sucessfullly compiled the linux server for [[Ham and Jam]].
Ham and Jam is a teamplay orientated, first person WW2 mutliplayer game centred around the British and Commonwealth campaigns from 1939-45. Historically accurate missions coupled with careful balance between realistic and enjoyable gameplay makes Ham and Jam a unique experience.
This are based on the SDK codebase as of from 31st October, 2006.


==Features==
{{note|This overview was done using a '''HL2MP''' based mod method and the '''Visual Studio 2005''' project files.}}
* '''Commonwealth vs. Axis forces''' - Britain, Canada, Poland, Australia and other Free armies vs. both German and Italian armies.
* '''Objective based, historically accurate missions''' - Actual WWII battles and operations re-created with the same objectives. No random capture-the-flag gameplay.
* '''Teamwork orientated''' - Objectives that require more than one player to complete. Points and rewards are only given for completing mission goals.
* '''Realistic yet un-complicated''' - Realistic limits on movement and weapon characteristics but not at the sake of gameplay.


==History==
==Install Fedora Core 6==
Ham and Jam started out as an idea between it's two main developers as an alternative to the tired old "U.S./Russia vs. Germany, post June 6th 1944" formulae WW2 games seem to use. Fed-up with everything prior to D-Day being ignored, the North West Europe theatre and the lack of British, Commonwealth and Free Forces they decided to do something about it...


The goal was clear - to make a WW2 mod that featured all the "missing" bits of WW2 history, portray it in a historically accurate way but without detracting from the fun or playability by overdoing realism. In short the kind of game they and their friends would like to play. Rather than a deathmatch gameplay style, Ham and Jam is all about teamwork as were the real battles. Each map is set-out with objectives and as a team you must fight to complete them to win.
You'll need a working install of [http://fedora.redhat.com/ Fedora Core 6 "Zod"] (knowns as FC6 from here on) available. If you don't have a spare machine or don't want to dual-boot you can create a ''virtual machine'' under Windows using [http://www.vmware.com/products/player/ WMWare Player] and a [http://www.thoughtpolice.co.uk/vmware/ virtual appliance] image of FC6.


==Team==
If you're going the VMWare route with a pre-packaged appliance, it's a good idea to ensure you have access to the Internet from it as this will help with installing packages and updates. A couple of tips - you'll probably find setting your network to NAT will work better. Also, beware that the Linux firewall and possibly any Windows firewall software (ZoneAlarm, PeerGuardian2) might block access to the Internet too. This will become apparent later on when we have to use ''hlds_l''.
From the start, Ham and Jam has had an interesting development ethos. First of all, there is no real "team", only a few core "leaders" and everyone else is a contributor free to add whatever they like. There is no commitment to the mod full time - you can choose to work on it for a month, a week or simply donate a few textures and leave, it's entirely up to you. Those currently working on the mod include:


===Main Developers===
The actual process of installing FC6 and getting it up and running is down to the reader and beyond the scope of this article, however as a general guide, make sure you have at least installed the development packages and have around 4Gb of free disk space.
* [[User:Wunderboy|Neil "Jed" Jedrzejewski]] - Co Lead | Modelling & Animation | Coding
* John "Ginger Lord" Crewe - Co-Lead | Mapping | Coding
* [[User:Holtt|Tim "Waldo" Holt] - Mapping | Coding | Modelling
* Rob "Pierog" Lach - Coding
* David "b0b" Mendelsohn - Coding


===Contributors===
==Packages needed for the SDK==
* Mark "TheSurgeon" Edwards - Mapping
* Jean-Edouard "KominAaa" Fages -Texture Design | Modelling
* Sebastian "Steel" Tokouz - Modelling
* Jamie "Ska Wars" McClurg - Modelling
* Jeff "Jaboo224" Johnson - Texture Design
* David "DarkPenfold" Armstrong - 2D Design
* Michael "BritishTang" Jones - Sound Engineer
* Chris "Faceman" Boniface - Audio/Visual Design


===Testing Group===
There are a number of pieces of software (or packages) you'll need installed to compile the Source SDK. The following is a list and a brief outline of how to install and configure them.
* Pete "Tpr.Cow" Eveleigh - Website Design | Tester
* "Apu" - Tester
* Greg "Trp.Werewolf" Lobeck - Tester


==Other info==
===GCC 3.4.6===
* [http://www.hamandjam.org Ham and Jam Homepage]
* {{moddb|6891}}


[[Category:HL2 Third Party Mods]]
The [[Compiling under Linux]] page states that GCC 3.4.X is recommended for compiling the SDK and that GCC 4.X doesn't work.
 
FC6 comes with a compatible version of GCC 3.4.6 which works fine with the SDK and can be installed using the Software Updater tool under Gnome or via the command line as follows:
 
<pre>
yum install compat-gcc-34
yum install compat-gcc-34-g77
yum install compat-gcc-34-c++
yum install compat-libstdc++-33
yum install compat-db
yum install compat-readline43
</pre>
 
We're including some extra stuff in here like the Fortran compiler, BerkleyDB and ReadLine. Their probably not needed but it doesn't hurt to install them.
 
We can check GCC 3.4.6 is installed and the right version with the following:
 
<pre>
gcc34 -dumpversion
3.4.6
</pre>
 
We can also check we have the library files we need installed as follows:
 
<pre>
locate libstdc++.a
/usr/lib/gcc/i386-redhat-linux/3.4.6/libstdc++.a
/usr/lib/gcc/i386-redhat-linux/4.1.1/libstdc++.a
</pre>
 
 
<pre>
locate libgcc_eh.a
/usr/lib/gcc/i386-redhat-linux/3.4.6/libgcc_eh.a
/usr/lib/gcc/i386-redhat-linux/4.1.1/libgcc_eh.a
</pre>
 
In the above case, we would use the 3.4.6 versions.
 
===Xerces 2.6.0===
 
Using Xerces 2.7.0 as a pre-compiled package caused all sort of problems. The only way I could get vcpm to work was to re-build [http://archive.apache.org/dist/xml/xerces-c/Xerces-C_2_6_0/xerces-c-src_2_6_0.tar.gz Xerces 2.6.0] from source and use that instead.
 
I downloaded the 2.6.0 source from the link above and placed the <code>.tar.gz</code> file in <code>/usr/local/src/</code> and compiled it as follows:
 
<pre>
cd /usr/local/src
tar zxvf xerces-c-src_2_6_0.tar.gz
cd /usr/local/src/xerces-c-src_2_6_0/src/xerces
export XERCESCROOT=/usr/local/src/xerces-c-src_2_6_0
./runConfigure -p linux -c gcc34 -x g++34
gmake
gmake install
</pre>
 
This configures, compiles and then installs the Xerces 2.6.0 package. The lib and header files needed by vcpm are then located in <code>/usr/local/src/xerces-c-src_2_6_0/lib</code> or <code>/usr/local/lib</code> and <code>/usr/local/src/xerces-c-src_2_6_0/includes</code> respectively.
 
==Install hlds_l==
 
You'll need the [http://storefront.steampowered.com/download/hldsupdatetool.bin Half-Life Dedicated Server for Linux] (hlds_l) installed and run at least once to make a couple of library files available during compile. In this example I installed hlds_l in <code>/hlds_l</code> for simplicity.
 
Installing hlds_l goes beyond the scope of this article, but there are plenty of tutorials out there on how to do it.
 
==Copy SDK Source==
 
The next step is to copy the source code for your mod over to the Linux system. In my own case, I copied the contents of the <code>D:\HLMP2Mod\src</code> folder on my Windows machine to <code>/usr/local/src/hl2mpmod/src</code> folder on my Linux box.
 
==Set-up symbolic links==
 
We need a couple of symbolic links back to some static objects that ship with hlds_l. They should get created as part of the build process but it doesn't hurt to make them ourselves:
 
<pre>
cd /usr/local/src/hl2mpmod/src/linux_sdk
ln -s /hlds_l/bin/tier0_i486.so
ln -s /hlds_l/bin/vstdlib_i486.so
</pre>
 
==Create the Makefile==
 
Next step is to put the relevent details for our build environment into <code>/usr/local/src/hl2mpmod/src/linux_sdk/Makefile</code>. The following is a complete <code>Makefile</code> - you should recognise paths and filenames from earlier stages:
 
<pre>
#
# SDK Makefile for x86 Linux
#
#
 
#############################################################################
# Developer configurable items
#############################################################################
 
# the name of the mod binary (_i486.so is appended to the end)
NAME=server
 
# the location of the vcproj that builds the mod
MOD_PROJ=../dlls/server_hl2mp-2005.vcproj
 
# the name of the mod configuration (typically <proj name>_<build type><build target>)
MOD_CONFIG=server_hl2mp_ReleaseHL2MPWin32
 
# the directory the base binaries (tier0_i486.so, etc) are located
GAME_DIR=/hlds_l
 
# compiler options (gcc 3.4.1 or above is required)
CC=/usr/bin/gcc34
CPLUS=/usr/bin/g++34
CLINK=/usr/bin/gcc34
CPP_LIB="/usr/lib/gcc/i386-redhat-linux/3.4.6/libstdc++.a /usr/lib/gcc/i386-redhat-linux/3.4.6/libgcc_eh.a"
 
# put any compiler flags you want passed here
USER_CFLAGS=
 
# link flags for your mod, make sure to include any special libraries here
LDFLAGS="-lm -ldl tier0_i486.so vstdlib_i486.so mathlib_i486.a choreoobjects_i486.a tier1_i486.a"
 
# XERCES 2.6.0 or above ( http://xml.apache.org/xerces-c/ ) is used by the vcproj to makefile converter
# it must be installed before being able to run this makefile
XERCES_INC_DIR=/usr/local/src/xerces-c-src_2_6_0/include
XERCES_LIB_DIR=/usr/local/src/xerces-c-src_2_6_0/lib
 
 
#############################################################################
# Things below here shouldn't need to be altered
#############################################################################
MAKE=gmake
 
# the dir we want to put binaries we build into
BUILD_DIR=.
# the place to put object files
BUILD_OBJ_DIR=$(BUILD_DIR)/obj
 
# the location of the source code
SOURCE_DIR=..
 
# the CPU target for the build, must be i486 for now
ARCH=i486
ARCH_CFLAGS=-mtune=i686 -march=pentium3 -mmmx -O3
 
# -fpermissive is so gcc 3.4.x doesn't complain about some template stuff
BASE_CFLAGS=-fpermissive -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp
SHLIBEXT=so
SHLIBCFLAGS=-fPIC
SHLIBLDFLAGS=-shared -Wl,-Map,$@_map.txt -Wl
 
#flags passed to the c compiler
CFLAGS="$(USER_CFLAGS) $(DEFINES) $(ARCH_CFLAGS) $(BASE_CFLAGS) -Usprintf=use_Q_snprintf_instead_of_sprintf -Ustrncpy=use_Q_strncpy_instead -UPROTECTED_THINGS_ENABLE"
 
# define list passed to make for the sub makefile
BASE_DEFINES=CC=$(CC) CPLUS=$(CPLUS) CPP_LIB=$(CPP_LIB) \
BUILD_DIR=$(BUILD_DIR) BUILD_OBJ_DIR=$(BUILD_OBJ_DIR) \
SOURCE_DIR=$(SOURCE_DIR) SHLIBLDFLAGS=$(SHLIBLDFLAGS) SHLIBEXT=$(SHLIBEXT) \
CLINK=$(CLINK) CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) \
ARCH=$(ARCH) GAME_DIR=$(GAME_DIR) MOD_CONFIG=$(MOD_CONFIG) NAME=$(NAME) \
XERCES_INC_DIR=$(XERCES_INC_DIR) XERCES_LIB_DIR=$(XERCES_LIB_DIR)
 
# Project Makefile
MAKE_MOD=Makefile.mod
MAKE_VCPM=Makefile.vcpm
MAKE_PLUGIN=Makefile.plugin
 
all: check vcpm mod
 
check:
if [ -z "$(CC)" ]; then echo "Compiler not defined."; exit; fi
if [ ! -d $(BUILD_DIR) ];then mkdir $(BUILD_DIR);fi
cd $(BUILD_DIR)
 
vcpm:
$(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES)
 
mod: vcpm
if [ ! -f "tier0_i486.so" ]; then ln -s $(GAME_DIR)/bin/tier0_i486.so .; fi
if [ ! -f "vstdlib_i486.so" ]; then ln -s $(GAME_DIR)/bin/vstdlib_i486.so .; fi
./vcpm $(MOD_PROJ)
$(MAKE) -f $(MAKE_MOD) $(BASE_DEFINES)
 
plugin:
$(MAKE) -f $(MAKE_PLUGIN) $(BASE_DEFINES)
 
clean:
$(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES) clean
$(MAKE) -f $(MAKE_PLUGIN) $(BASE_DEFINES) clean
$(MAKE) -f $(MAKE_MOD) $(BASE_DEFINES) clean
</pre>
 
==Fixing code errors==
 
===Filename case and .vcproj errors===
 
There are a number of errors which will stop the SDK source code from compiling. These are:
 
* <code>.cpp</code> and <code>.h</code> filenames are mixed case.
* <code>#include</code> statements refer to mixed-case filenames.
* <code>.vcproj</code> filenames are mixed-case.
* <code>.vcproj</code> contains bad seperator in include paths.
* <code>Makefile.vcpm</code> contains mixed-case filnames.
 
You can fix all of the above using the following bash script. Save it as<code>/usr/local/src/hl2mpmod/src/sdk_fixes.sh</code> and run it with:
 
<pre>
cd /usr/local/src/hl2mpmod/src/
/bin/bash sdk_fixes.sh
</pre>
 
<pre>
#!/bin/bash
 
# Move command
MVCMD="mv"
 
# For subversion integration renaming (or cvs).
#MVCMD="svn mv --force"
 
# SVN directory prefix (cvs users can change this as needed)
SVNDIR=.svn
 
############################################
# Make all .cpp and .h filenames lowercase #
############################################
 
for ((i=1;i<10;i++))
{
echo Renaming dirs pass $i ...
 
IFS=$'\n'
for file in $(find -path *$SVNDIR -prune -o -type d -print)
do
file_new="$(echo $file |tr '[:upper:]' '[:lower:]')"
 
if [ "$file" != "$file_new" ]
then
echo "Rename $file to $file_new ..."
IFS=$OLDIFS
$MVCMD "$file" "$file_new"
IFS=$'\n'
fi
done
}
 
#######################################################
# Make all include statements use lowercase filenames #
#######################################################
 
IFS=$OLDIFS
for ext in cpp h
do
echo Searching .$ext ...
 
IFS=$'\n'
for file in $(find -path *$SVNDIR -prune -o -name "*.$ext" -print)
do
file_new="$(echo $file |tr '[:upper:]' '[:lower:]')"
if [ "$file" != "$file_new" ]
then
echo "Rename $file to $file_new ..."
IFS=$OLDIFS
$MVCMD "$file" "$file_new"
IFS=$'\n'
fi
echo "Parsing $file_new ..."
sed -i 's/\(#include.*"\)\(.*\)\(\.h"\)/\1\L\2\3/g' "$file_new"
sed -i 's/\(#include.*<\)\(.*\)\(\.h>\)/\1\L\2\3/g' "$file_new"
done
done
 
########################################
# Make all .vcproj filenames lowercase #
########################################
 
echo Searching .vcproj ...
 
IFS=$'\n'
for file in $(find -path *$SVNDIR -prune -o -name "*.vcproj" -print)
do
echo "Parsing $file ..."
sed -i 's/\(RelativePath="\)\(.*\)\(\.h"\)/\1\L\2\3/g' "$file"
sed -i 's/\(RelativePath="\)\(.*\)\(\.cpp"\)/\1\L\2\3/g' "$file"
done
 
###########################################
# Fix broken include path in .vcproj file #
###########################################
 
echo Searching server_hl2mp-2005.vcproj ...
 
file="$(find -path *$SVNDIR -prune -o -name server_hl2mp-2005.vcproj -print)"
echo Parsing $file ...
sed -i 's%../game_shared/hl2mp;./episodic%../game_shared/hl2mp,./episodic%g' "$file"
 
#####################################
# Make filenames lowercase for vcpm #
#####################################
 
echo Searching Makefile.vcpm ...
file="$(find -path *$SVNDIR -prune -o -name Makefile.vcpm -print)"
echo Parsing $file ...
sed -i 's/KeyValues.o/keyvalues.o/' "$file"
</pre>

Latest revision as of 12:36, 9 January 2007

The following are various notes, scribbles, thoughts, etc. from doing various Source-type things. None of these are structured of "definate" - just things I write down for reference. If anything you find here is useful, great, but use it at your own risk!!!

This is a personal page on my own namespace. If you have anything to add, questions, comments, or managed to find something I didn't, please post on the talk page instead. Thanks!

Compiling the SDK under Linux with Fedora Core 6

The following are some notes on how I set-up a build environment and sucessfullly compiled the linux server for Ham and Jam. This are based on the SDK codebase as of from 31st October, 2006.

Note.pngNote:This overview was done using a HL2MP based mod method and the Visual Studio 2005 project files.

Install Fedora Core 6

You'll need a working install of Fedora Core 6 "Zod" (knowns as FC6 from here on) available. If you don't have a spare machine or don't want to dual-boot you can create a virtual machine under Windows using WMWare Player and a virtual appliance image of FC6.

If you're going the VMWare route with a pre-packaged appliance, it's a good idea to ensure you have access to the Internet from it as this will help with installing packages and updates. A couple of tips - you'll probably find setting your network to NAT will work better. Also, beware that the Linux firewall and possibly any Windows firewall software (ZoneAlarm, PeerGuardian2) might block access to the Internet too. This will become apparent later on when we have to use hlds_l.

The actual process of installing FC6 and getting it up and running is down to the reader and beyond the scope of this article, however as a general guide, make sure you have at least installed the development packages and have around 4Gb of free disk space.

Packages needed for the SDK

There are a number of pieces of software (or packages) you'll need installed to compile the Source SDK. The following is a list and a brief outline of how to install and configure them.

GCC 3.4.6

The Compiling under Linux page states that GCC 3.4.X is recommended for compiling the SDK and that GCC 4.X doesn't work.

FC6 comes with a compatible version of GCC 3.4.6 which works fine with the SDK and can be installed using the Software Updater tool under Gnome or via the command line as follows:

yum install compat-gcc-34
yum install compat-gcc-34-g77
yum install compat-gcc-34-c++
yum install compat-libstdc++-33
yum install compat-db
yum install compat-readline43

We're including some extra stuff in here like the Fortran compiler, BerkleyDB and ReadLine. Their probably not needed but it doesn't hurt to install them.

We can check GCC 3.4.6 is installed and the right version with the following:

gcc34 -dumpversion
3.4.6

We can also check we have the library files we need installed as follows:

locate libstdc++.a
/usr/lib/gcc/i386-redhat-linux/3.4.6/libstdc++.a
/usr/lib/gcc/i386-redhat-linux/4.1.1/libstdc++.a


locate libgcc_eh.a
/usr/lib/gcc/i386-redhat-linux/3.4.6/libgcc_eh.a
/usr/lib/gcc/i386-redhat-linux/4.1.1/libgcc_eh.a

In the above case, we would use the 3.4.6 versions.

Xerces 2.6.0

Using Xerces 2.7.0 as a pre-compiled package caused all sort of problems. The only way I could get vcpm to work was to re-build Xerces 2.6.0 from source and use that instead.

I downloaded the 2.6.0 source from the link above and placed the .tar.gz file in /usr/local/src/ and compiled it as follows:

cd /usr/local/src
tar zxvf xerces-c-src_2_6_0.tar.gz
cd /usr/local/src/xerces-c-src_2_6_0/src/xerces
export XERCESCROOT=/usr/local/src/xerces-c-src_2_6_0
./runConfigure -p linux -c gcc34 -x g++34
gmake
gmake install

This configures, compiles and then installs the Xerces 2.6.0 package. The lib and header files needed by vcpm are then located in /usr/local/src/xerces-c-src_2_6_0/lib or /usr/local/lib and /usr/local/src/xerces-c-src_2_6_0/includes respectively.

Install hlds_l

You'll need the Half-Life Dedicated Server for Linux (hlds_l) installed and run at least once to make a couple of library files available during compile. In this example I installed hlds_l in /hlds_l for simplicity.

Installing hlds_l goes beyond the scope of this article, but there are plenty of tutorials out there on how to do it.

Copy SDK Source

The next step is to copy the source code for your mod over to the Linux system. In my own case, I copied the contents of the D:\HLMP2Mod\src folder on my Windows machine to /usr/local/src/hl2mpmod/src folder on my Linux box.

Set-up symbolic links

We need a couple of symbolic links back to some static objects that ship with hlds_l. They should get created as part of the build process but it doesn't hurt to make them ourselves:

cd /usr/local/src/hl2mpmod/src/linux_sdk
ln -s /hlds_l/bin/tier0_i486.so
ln -s /hlds_l/bin/vstdlib_i486.so

Create the Makefile

Next step is to put the relevent details for our build environment into /usr/local/src/hl2mpmod/src/linux_sdk/Makefile. The following is a complete Makefile - you should recognise paths and filenames from earlier stages:

#
# SDK Makefile for x86 Linux
#
#

#############################################################################
# Developer configurable items
#############################################################################

# the name of the mod binary (_i486.so is appended to the end)
NAME=server

# the location of the vcproj that builds the mod
MOD_PROJ=../dlls/server_hl2mp-2005.vcproj

# the name of the mod configuration (typically <proj name>_<build type><build target>)
MOD_CONFIG=server_hl2mp_ReleaseHL2MPWin32

# the directory the base binaries (tier0_i486.so, etc) are located
GAME_DIR=/hlds_l

# compiler options (gcc 3.4.1 or above is required)
CC=/usr/bin/gcc34
CPLUS=/usr/bin/g++34
CLINK=/usr/bin/gcc34
CPP_LIB="/usr/lib/gcc/i386-redhat-linux/3.4.6/libstdc++.a /usr/lib/gcc/i386-redhat-linux/3.4.6/libgcc_eh.a"

# put any compiler flags you want passed here
USER_CFLAGS=

# link flags for your mod, make sure to include any special libraries here
LDFLAGS="-lm -ldl tier0_i486.so vstdlib_i486.so mathlib_i486.a choreoobjects_i486.a tier1_i486.a"

# XERCES 2.6.0 or above ( http://xml.apache.org/xerces-c/ ) is used by the vcproj to makefile converter
# it must be installed before being able to run this makefile
XERCES_INC_DIR=/usr/local/src/xerces-c-src_2_6_0/include
XERCES_LIB_DIR=/usr/local/src/xerces-c-src_2_6_0/lib


#############################################################################
# Things below here shouldn't need to be altered
#############################################################################
MAKE=gmake

# the dir we want to put binaries we build into
BUILD_DIR=.
# the place to put object files
BUILD_OBJ_DIR=$(BUILD_DIR)/obj

# the location of the source code
SOURCE_DIR=..

# the CPU target for the build, must be i486 for now
ARCH=i486
ARCH_CFLAGS=-mtune=i686 -march=pentium3 -mmmx -O3

# -fpermissive is so gcc 3.4.x doesn't complain about some template stuff
BASE_CFLAGS=-fpermissive -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp
SHLIBEXT=so
SHLIBCFLAGS=-fPIC
SHLIBLDFLAGS=-shared -Wl,-Map,$@_map.txt -Wl

#flags passed to the c compiler
CFLAGS="$(USER_CFLAGS) $(DEFINES) $(ARCH_CFLAGS) $(BASE_CFLAGS) -Usprintf=use_Q_snprintf_instead_of_sprintf -Ustrncpy=use_Q_strncpy_instead -UPROTECTED_THINGS_ENABLE"

# define list passed to make for the sub makefile
BASE_DEFINES=CC=$(CC) CPLUS=$(CPLUS) CPP_LIB=$(CPP_LIB) \
	BUILD_DIR=$(BUILD_DIR) BUILD_OBJ_DIR=$(BUILD_OBJ_DIR) \
	SOURCE_DIR=$(SOURCE_DIR) SHLIBLDFLAGS=$(SHLIBLDFLAGS) SHLIBEXT=$(SHLIBEXT) \
	CLINK=$(CLINK) CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) \
	ARCH=$(ARCH) GAME_DIR=$(GAME_DIR) MOD_CONFIG=$(MOD_CONFIG) NAME=$(NAME) \
	XERCES_INC_DIR=$(XERCES_INC_DIR) XERCES_LIB_DIR=$(XERCES_LIB_DIR)

# Project Makefile
MAKE_MOD=Makefile.mod
MAKE_VCPM=Makefile.vcpm
MAKE_PLUGIN=Makefile.plugin

all: check vcpm mod

check:
	if [ -z "$(CC)" ]; then echo "Compiler not defined."; exit; fi
	if [ ! -d $(BUILD_DIR) ];then mkdir $(BUILD_DIR);fi
	cd $(BUILD_DIR)

vcpm:
	$(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES)

mod: vcpm
	if [ ! -f "tier0_i486.so" ]; then ln -s $(GAME_DIR)/bin/tier0_i486.so .; fi
	if [ ! -f "vstdlib_i486.so" ]; then ln -s $(GAME_DIR)/bin/vstdlib_i486.so .; fi
	./vcpm $(MOD_PROJ)
	$(MAKE) -f $(MAKE_MOD) $(BASE_DEFINES)

plugin:
	$(MAKE) -f $(MAKE_PLUGIN) $(BASE_DEFINES)

clean:
	 $(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES) clean
	 $(MAKE) -f $(MAKE_PLUGIN) $(BASE_DEFINES) clean
	 $(MAKE) -f $(MAKE_MOD) $(BASE_DEFINES) clean

Fixing code errors

Filename case and .vcproj errors

There are a number of errors which will stop the SDK source code from compiling. These are:

  • .cpp and .h filenames are mixed case.
  • #include statements refer to mixed-case filenames.
  • .vcproj filenames are mixed-case.
  • .vcproj contains bad seperator in include paths.
  • Makefile.vcpm contains mixed-case filnames.

You can fix all of the above using the following bash script. Save it as/usr/local/src/hl2mpmod/src/sdk_fixes.sh and run it with:

cd /usr/local/src/hl2mpmod/src/
/bin/bash sdk_fixes.sh
#!/bin/bash

# Move command
MVCMD="mv"

# For subversion integration renaming (or cvs).
#MVCMD="svn mv --force"

# SVN directory prefix (cvs users can change this as needed)
SVNDIR=.svn

############################################
# Make all .cpp and .h filenames lowercase #
############################################

for ((i=1;i<10;i++))
{
	echo Renaming dirs pass $i ...

	IFS=$'\n'
	for file in $(find -path *$SVNDIR -prune -o -type d -print)
	do
		file_new="$(echo $file |tr '[:upper:]' '[:lower:]')"

		if [ "$file" != "$file_new" ]
		then
			echo "Rename $file to $file_new ..."
			IFS=$OLDIFS
			$MVCMD "$file" "$file_new"
			IFS=$'\n'
		fi
	done
}

#######################################################
# Make all include statements use lowercase filenames #
#######################################################

IFS=$OLDIFS
for ext in cpp h
do
	echo Searching .$ext ...	

	IFS=$'\n'
	for file in $(find -path *$SVNDIR -prune -o -name "*.$ext" -print)
	do
		file_new="$(echo $file |tr '[:upper:]' '[:lower:]')"
		
		if [ "$file" != "$file_new" ]
		then
			echo "Rename $file to $file_new ..."
			IFS=$OLDIFS
			$MVCMD "$file" "$file_new"
			IFS=$'\n'
		fi
		
		echo "Parsing $file_new ..."
		sed -i 's/\(#include.*"\)\(.*\)\(\.h"\)/\1\L\2\3/g' "$file_new"
		sed -i 's/\(#include.*<\)\(.*\)\(\.h>\)/\1\L\2\3/g' "$file_new"
	done
done

########################################
# Make all .vcproj filenames lowercase #
########################################

echo Searching .vcproj ...

IFS=$'\n'
for file in $(find -path *$SVNDIR -prune -o -name "*.vcproj" -print)
do
	echo "Parsing $file ..."
	sed -i 's/\(RelativePath="\)\(.*\)\(\.h"\)/\1\L\2\3/g' "$file"
	sed -i 's/\(RelativePath="\)\(.*\)\(\.cpp"\)/\1\L\2\3/g' "$file"
done

###########################################
# Fix broken include path in .vcproj file #
###########################################

echo Searching server_hl2mp-2005.vcproj ...

file="$(find -path *$SVNDIR -prune -o -name server_hl2mp-2005.vcproj -print)"
echo Parsing $file ...
sed -i 's%../game_shared/hl2mp;./episodic%../game_shared/hl2mp,./episodic%g' "$file"

#####################################
# Make filenames lowercase for vcpm #
#####################################

echo Searching Makefile.vcpm ...
file="$(find -path *$SVNDIR -prune -o -name Makefile.vcpm -print)"
echo Parsing $file ...
sed -i 's/KeyValues.o/keyvalues.o/' "$file"