View Single Post
 05-17-2010, 09:51 PM #1 TrippHop @TrippHop Lurker   Join Date: Dec 2009 Posts: 5 [QuickFix/Guide] Compiling on Linux using GCC For this guide we will be using GCC which is a free C compiler for Linux. Also this guide is kind of a work in progress, as I am a new user of linux, GCC, and makefiles. The first thing you need to compile on linux is access to a linux platform. Access to a linux platform could be on a server or your home computer. For this guide I used the Ubuntu linux distro ( www.ubuntu.com ). A very easy way to install ubuntu on your computer is to use WUBI ( http://wubi-installer.org/ ). You can also use VirtualBox or VMWare Player to run linux on a virtual machine on your windows platform. I don't personally like this method because it runs really slow, for me at least. Also make sure you have the latest version of GCC with your linux distro. With Debian/Ubuntu distros you can do "sudo apt-get install gcc" in the terminal. Next step is to make sure you have a copy of the Jedi Academy SDK provided by Raven Software. Here is a link to download: http://jediknight3.filefront.com/fil...y_SDK_MP;20909 Off the bat, the source files will not compile with GCC without errors, so we are going to fix them. GCC will complain about instances of redefinition, which there are a few in the source files. Step 1) Find all instances of the function powf and rename it to Q_powf. in q_shared.h: change Code: `float powf ( float x, int y );` to this: Code: `float Q_powf ( float x, int y );` and in q_math.c, change this: Code: ```float powf ( float x, int y ) { float r = x; for ( y--; y>0; y-- ) r = r * r; return r; }``` to this: Code: ```float Q_powf ( float x, int y ) { float r = x; for ( y--; y>0; y-- ) r = r * r; return r; }``` Also if your mod is client side you will want to pay attention to cg_view.c since powf is used twice: at line 444: Code: `ratio = powf(dampfactor, dtime);` and line 531: Code: `ratio = powf(dampfactor, dtime);` Step 2) Fixing bg_vehicles.h In bg_vehicles.h there is a typedef redefinition. Go to line 477 where you see: Code: ```// This is the implementation of the vehicle interface and any of the other variables needed. This // is what actually represents a vehicle. -AReis. typedef struct Vehicle_s { // The entity who pilots/drives this vehicle. // NOTE: This is redundant (since m_pParentEntity->owner _should_ be the pilot). This makes things clearer though. bgEntity_t *m_pPilot;``` change it to Code: ```// This is the implementation of the vehicle interface and any of the other variables needed. This // is what actually represents a vehicle. -AReis. #ifdef __GCC__ struct Vehicle_s #else typedef struct Vehicle_s #endif { // The entity who pilots/drives this vehicle. // NOTE: This is redundant (since m_pParentEntity->owner _should_ be the pilot). This makes things clearer though. bgEntity_t *m_pPilot;``` and after this struct where: Code: ``` //the guy who was previously the pilot bgEntity_t * m_pOldPilot; } Vehicle_t;``` change it to: Code: ``` //the guy who was previously the pilot bgEntity_t * m_pOldPilot; #ifdef __GCC__ }; #else } Vehicle_t; #endif``` Step 3) Fixing bg_public.h The same type of redefinition occurs in bg_public.h Go to line 423 where you see: Code: ```typedef struct bgEntity_s { entityState_t s;``` change it to: Code: ```#ifdef __GCC__ struct bgEntity_s #else typedef struct bgEntity_s #endif { entityState_t s;``` and after the struct where you see: Code: ``` //Data type(s) must directly correspond to the head of the gentity and centity structures } bgEntity_t;``` change it to: Code: ``` //Data type(s) must directly correspond to the head of the gentity and centity structures #ifdef __GCC__ }; #else } bgEntity_t; #endif``` Step 4) Fixing g_public.h Yep, another redefinition here. Go to line 675 where you see: Code: `typedef struct Vehicle_s Vehicle_t;` change it to: Code: ```#ifndef __GCC__ typedef struct Vehicle_s Vehicle_t; #endif``` Step 5) Fixing bg_pmove.c Go to line 712 where you see: Code: ```// Following couple things don't belong in the DLL namespace! #ifdef QAGAME typedef struct gentity_s gentity_t; gentity_t *G_PlayEffectID(const int fxID, vec3_t org, vec3_t ang); #endif``` change this to: Code: ```// Following couple things don't belong in the DLL namespace! #ifdef QAGAME #ifndef __GCC__ typedef struct gentity_s gentity_t; #endif gentity_t *G_PlayEffectID(const int fxID, vec3_t org, vec3_t ang); #endif``` Step 6) Fixing g_ICARUScb.c Go to line 30 where: Code: ```#ifndef _XBOX #ifndef __linux__ enum { TK_EOF = -1, TK_UNDEFINED, TK_COMMENT,``` change it to: Code: ```#ifndef _XBOX //#ifndef __linux__ #if defined(__linux__) && defined(__GCC__) || !defined(__linux__) enum { TK_EOF = -1, TK_UNDEFINED, TK_COMMENT,``` Step 7) Fixing g_main.c Go to line 500 where: Code: ```#include "../namespace_begin.h" #ifdef __linux__ extern "C" { #endif``` change it to: Code: ```#include "../namespace_begin.h" //#ifdef __linux__ #if defined(__linux__) && !defined(__GCC__) extern "C" { #endif``` and after that function, change: Code: ```} #ifdef __linux__ } #endif``` to: Code: ```} //#ifdef __linux__ #if defined(__linux__) && !defined(__GCC__) } #endif``` Okay that ends the editing of the source files. Now it is time to create the Makefile. Makefiles provide a convenient means to building source files into executables or shared libraries. Go to the codemp/game directory and inside it make a file named "Makefile". then just copy this stuff into the makefile and save it: Code: ```# # Linux Makefile for GCC for Jedi Academy SDK # # === Variables === # Compiler - GCC CC = gcc # Compiler Flags # -D ( Used to make a define like #define mydefine ) # -w ( disable warnings ) # -I used to include headers # -fPIC ( this flag is necessary to build shared libraries ) CFLAGS = -I../qcommon -I../server -I../icarus -I../ghoul2 -fPIC -DFINAL_BUILD -DMISSION_PACK -DQAGAME -D_JK2 -D__linux__ -D__GCC__ -w # Target file TARGET = jampgamei386.so # Object Files OFILES = ai_main.o ai_util.o ai_wpnav.o AnimalNPC.o \ bg_g2_utils.o bg_lib.o bg_misc.o bg_panimate.o \ bg_pmove.o bg_saber.o bg_saberLoad.o bg_saga.o \ bg_slidemove.o bg_vehicleLoad.o bg_weapons.o \ FighterNPC.o g_active.o g_arenas.o g_bot.o \ g_client.o g_cmds.o g_combat.o g_exphysics.o \ g_ICARUScb.o g_items.o g_log.o g_main.o g_mem.o \ g_misc.o g_missile.o g_mover.o g_nav.o g_navnew.o \ g_object.o g_saga.o g_session.o g_spawn.o g_strap.o \ g_svcmds.o g_target.o g_team.o g_timer.o g_trigger.o \ g_turret.o g_turret_G2.o g_utils.o g_vehicles.o \ g_vehicleTurret.o g_weapon.o NPC.o NPC_AI_Atst.o \ NPC_AI_Default.o NPC_AI_Droid.o NPC_AI_GalakMech.o \ NPC_AI_Grenadier.o NPC_AI_Howler.o NPC_AI_ImperialProbe.o \ NPC_AI_Interrogator.o NPC_AI_Jedi.o NPC_AI_Mark1.o \ NPC_AI_Mark2.o NPC_AI_MineMonster.o NPC_AI_Rancor.o \ NPC_AI_Remote.o NPC_AI_Seeker.o NPC_AI_Sentry.o \ NPC_AI_Sniper.o NPC_AI_Stormtrooper.o NPC_AI_Utils.o \ NPC_AI_Wampa.o NPC_behavior.o NPC_combat.o NPC_goal.o \ NPC_misc.o NPC_move.o NPC_reactions.o NPC_senses.o \ NPC_sounds.o NPC_spawn.o NPC_stats.o NPC_utils.o \ q_math.o q_shared.o SpeederNPC.o tri_coll_test.o \ WalkerNPC.o w_force.o w_saber.o # === Arguments for the Makefile === # typing just "make" invokes the first target ( which in this case is \$(TARGET) ) \$(TARGET): \$(OFILES) \$(CC) -shared -o \$(TARGET) \$(OFILES) -lm .c.o: \$(CC) \$(CFLAGS) -c \$*.c -o \$*.o # "make clean" clean: rm -f \$(OFILES) rm -f \$(TARGET)``` now with a terminal go to codemp/game and type "make". This will build the shared libray jampgamei386.so which will be in codemp/game. You can use "make clean", which will remove all the object files and the libary file in codemp/game. This guide will probably change since im new to all this *nix stuff. Also, fyi. I did not test this shared library on a server yet. So I am not sure if there are any runtime errors. you may: quote & reply,