commit 93dbfd0695909b7f41a8d52e0dc2fd69c8da0688 Author: mittorn Date: Thu Dec 3 01:42:13 2015 +0600 Gcc build diff --git a/rehlds/engine/Makefile.dep b/rehlds/engine/Makefile.dep new file mode 100644 index 0000000..e69de29 diff --git a/rehlds/engine/Makefile.linux b/rehlds/engine/Makefile.linux new file mode 100644 index 0000000..90c830f --- /dev/null +++ b/rehlds/engine/Makefile.linux @@ -0,0 +1,54 @@ +CC ?= gcc +CXX ?= g++ +CFLAGS ?= -Og -ggdb -msse4.1 +LDFLAGS = +LIBS = -lm +LBITS := $(shell getconf LONG_BIT) +ifeq ($(LBITS),64) + LDFLAGS += -m32 + CFLAGS += -m32 +endif +TOPDIR = $(PWD)/.. +XASHXT ?= $(TOPDIR)/../xashXT +HLSDK ?= $(TOPDIR)/../halflife/ +INCLUDES = -Icommon -I../common -I. -I../pm_shared -I../rehlds -I../hookers -I../ -I../public -I../public/rehlds -I../testsuite +DEFINES = -D_stricmp=strcasecmp -fpermissive -w -DREHLDS_SELF -D_vsnprintf=vsnprintf -D_strnicmp=strncasecmp -DSWDS -DNOCPUID -DREHLDS_GCC -DSYSTEM_BZIP2 -DNOBREAKPAD -std=c++11 -D_strdup=strdup -D_unlink=unlink -mavx + +%.o : %.c + $(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -fPIC -c $< -o $@ + +%.o : %.cpp + $(CXX) $(CFLAGS) $(INCLUDES) $(DEFINES) -fPIC -c $< -o $@ + +SRCS_CPP = $(wildcard *.cpp) ../public/registry.cpp ../public/tier0/dbg.cpp ../public/steamid.cpp ../public/utlbuffer.cpp $(wildcard ../rehlds/*.cpp) +#ifeq ($(XASH_VGUI),1) +# SRCS_CPP += $(wildcard client/vgui/*.cpp) +#endif + +OBJS_CPP = $(SRCS_CPP:.cpp=.o) +# ../rehlds/rehlds_api_impl.o ../rehlds/flight_recorder.o +SRCS = $(wildcard *.c) +OBJS = $(SRCS:.c=.o) + +engine.so : $(OBJS) $(OBJS_CPP) + $(CXX) -o engine.so $(LDFLAGS) -shared $(OBJS) $(OBJS_CPP) $(LIBS) libsteam_api.so -lbz2 -Wl,--no-undefined -ldl + + +.PHONY: depend clean list + +clean: + $(RM) $(OBJS) $(OBJS_CPP) engine.so + +list: + @echo Sources: + @echo $(SRCS) + @echo C++ Sources: + @echo $(SRCS_CPP) + @echo Objects: + @echo $(OBJS) $(OBJS_CPP) + +depend: $(SRCS) $(SRCS_CPP) + touch Makefile.dep + makedepend -fMakefile.dep -- $(DEFINES) -Icommon -I../common -I. -I../pm_shared -Iclient -Iserver -Iclient/vgui -- $^ + +include Makefile.dep diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 87ea03e..f26ac57 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -467,6 +467,7 @@ qboolean __declspec(naked) SV_IsPlayerIndex_wrapped(int index) // Original SV_IsPlayerIndex in swds.dll doesn't modify ecx nor edx. // During the compilation of original swds.dll compiler was assuming that these registers wouldn't be modified during call to SV_IsPlayerIndex(). // This is not true for code produced by msvc2013 (which uses ecx even in Release config). That's why we need a wrapper here that preserves ecx and edx before call to reversed SV_IsPlayerIndex(). +#ifndef REHLDS_GCC __asm { mov eax, dword ptr[esp + 4]; @@ -479,6 +480,9 @@ qboolean __declspec(naked) SV_IsPlayerIndex_wrapped(int index) pop ecx; retn; } +#else +#warning Stub on gcc +#endif } /* ../engine/sv_main.c:514 */ @@ -5139,6 +5143,7 @@ void SV_WriteVoiceCodec(sizebuf_t *pBuf) */ void __invokeValvesBuggedCreateBaseline(void* func, int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec_t* pmins, vec_t* pmaxs) { +#ifndef REHLDS_GCC __asm { mov ecx, func push 0 @@ -5155,6 +5160,7 @@ void __invokeValvesBuggedCreateBaseline(void* func, int player, int eindex, stru call ecx add esp, 0x2C } +#endif } /* ../engine/sv_main.c:6866 */ @@ -5187,7 +5193,11 @@ void SV_CreateBaseline(void) else g_psv.baselines[entnum].entityType = ENTITY_NORMAL; +#ifndef REHLDS_GCC __invokeValvesBuggedCreateBaseline((void *)gEntityInterface.pfnCreateBaseline, player, entnum, &(g_psv.baselines[entnum]), svent, sv_playermodel, player_mins[0], player_maxs[0]); +#else + gEntityInterface.pfnCreateBaseline(player, entnum, &(g_psv.baselines[entnum]), svent, sv_playermodel, player_mins[0], player_maxs[0]); +#endif sv_lastnum = entnum; } } diff --git a/rehlds/engine/sv_steam3.cpp b/rehlds/engine/sv_steam3.cpp index 4c69b08..6396830 100644 --- a/rehlds/engine/sv_steam3.cpp +++ b/rehlds/engine/sv_steam3.cpp @@ -63,6 +63,8 @@ void CSteam3Server::OnLogonSuccess(SteamServersConnected_t *pLogonSuccess) /* ../engine/sv_steam3.cpp:128 */ uint64 CSteam3Server::GetSteamID() { + if(!this) + return 0; // may happend sometimes if (m_bLanOnly) return CSteamID(0, k_EUniversePublic, k_EAccountTypeInvalid).ConvertToUint64(); else @@ -831,7 +833,9 @@ qboolean Steam_GSBSecure(void) { //useless call //Steam3Server(); - return CRehldsPlatformHolder::get()->SteamGameServer()->BSecure(); + if(CRehldsPlatformHolder::get()->SteamGameServer()) + return CRehldsPlatformHolder::get()->SteamGameServer()->BSecure(); + return false; } /* ../engine/sv_steam3.cpp:1036 */ diff --git a/rehlds/public/asmlib.h b/rehlds/public/asmlib.h index d95d13d..e3b50f2 100644 --- a/rehlds/public/asmlib.h +++ b/rehlds/public/asmlib.h @@ -104,7 +104,10 @@ void A_DebugBreak(void); // Makes a debug #endif void cpuid_ex (int abcd[4], int eax, int ecx); // call CPUID instruction static inline void cpuid_abcd (int abcd[4], int eax) { - cpuid_ex(abcd, eax, 0);} +#ifndef NOCPUID + cpuid_ex(abcd, eax, 0); +#endif + } #ifdef __cplusplus } // end of extern "C" diff --git a/rehlds/public/basetypes.h b/rehlds/public/basetypes.h index 5f3a677..e750876 100644 --- a/rehlds/public/basetypes.h +++ b/rehlds/public/basetypes.h @@ -47,13 +47,20 @@ // In case this ever changes #define M_PI 3.14159265358979323846 -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) +#ifndef REHLDS_GCC +#ifndef min + +#define min(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) +#ifndef max + +#define max(a,b) (((a) > (b)) ? (a) : (b)) #endif +#else +#define max(a,b) ((a)>(b)?(a):(b)) +#define min(a,b) ((a)<(b)?(a):(b)) +#endif #ifdef __cplusplus template diff --git a/rehlds/public/rehlds/osconfig.h b/rehlds/public/rehlds/osconfig.h index 54bb0c8..249f1af 100644 --- a/rehlds/public/rehlds/osconfig.h +++ b/rehlds/public/rehlds/osconfig.h @@ -126,6 +126,8 @@ #ifndef PAGESIZE #define PAGESIZE 4096 #endif +#include + #define __int64 int64_t #define ALIGN(addr) (size_t)((size_t)addr & ~(PAGESIZE-1)) #define ARRAYSIZE(p) (sizeof(p)/sizeof(p[0])) @@ -166,7 +168,13 @@ #define WSAENOPROTOOPT ENOPROTOOPT +#ifdef REHLDS_GCC +#include + inline unsigned long _byteswap_ulong(unsigned long val) { return bswap_32(val); } +#else inline unsigned long _byteswap_ulong(unsigned long val) { return _bswap(val); } +#endif + #ifndef FALSE #define FALSE 0 @@ -174,6 +182,10 @@ #ifndef TRUE #define TRUE 1 #endif +#ifdef REHLDS_GCC + #define __FUNCTION__ "" +// __func__ is not a macro +#endif #endif // _WIN32 #ifdef _WIN32 @@ -186,6 +198,7 @@ #define EXT_FUNC FORCE_STACK_ALIGN +#define __declspec(x) extern void __declspec(noreturn) rehlds_syserror(const char* fmt, ...); #endif // _OSCONFIG_H diff --git a/rehlds/public/rehlds/sys_shared.cpp b/rehlds/public/rehlds/sys_shared.cpp index 58981d6..da21929 100644 --- a/rehlds/public/rehlds/sys_shared.cpp +++ b/rehlds/public/rehlds/sys_shared.cpp @@ -39,9 +39,10 @@ #define AVX2_FLAG (1<<5) cpuinfo_t cpuinfo; - + void Sys_CheckCpuInstructionsSupport(void) { +#ifndef NOCPUID int cpuid_data[4]; cpuid_ex(cpuid_data, 1, 0); @@ -55,4 +56,7 @@ void Sys_CheckCpuInstructionsSupport(void) cpuid_ex(cpuid_data, 7, 0); cpuinfo.avx2 = (cpuid_data[1] & AVX2_FLAG) ? 1 : 0; // ebx -} \ No newline at end of file +#else +/// TODO: fill cpu flags +#endif +} diff --git a/rehlds/public/tier0/fasttimer.h b/rehlds/public/tier0/fasttimer.h index d6ef979..3be0aff 100644 --- a/rehlds/public/tier0/fasttimer.h +++ b/rehlds/public/tier0/fasttimer.h @@ -246,7 +246,8 @@ inline void CCycleCount::Init(float initTimeMsec) inline void CCycleCount::Sample() { unsigned long* pSample = (unsigned long *)&m_Int64; - __asm +#ifndef REHLDS_GCC +__asm { // force the cpu to synchronize the instruction queue // NJS: CPUID can really impact performance in tight loops. @@ -258,6 +259,10 @@ inline void CCycleCount::Sample() mov[ecx], eax mov[ecx + 4], edx } +#else +/// Is it correct? But it works now +usleep(1000); +#endif } diff --git a/rehlds/rehlds/platform.cpp b/rehlds/rehlds/platform.cpp index 1d01106..a44a960 100644 --- a/rehlds/rehlds/platform.cpp +++ b/rehlds/rehlds/platform.cpp @@ -143,11 +143,15 @@ int CSimplePlatform::WSAGetLastError() { #endif //WIN32 void CSimplePlatform::SteamAPI_SetBreakpadAppID(uint32 unAppID) { +#ifndef NOBREAKPAD return ::SteamAPI_SetBreakpadAppID(unAppID); +#endif } void CSimplePlatform::SteamAPI_UseBreakpadCrashHandler(char const *pchVersion, char const *pchDate, char const *pchTime, bool bFullMemoryDumps, void *pvContext, PFNPreMinidumpCallback m_pfnPreMinidumpCallback) { +#ifndef NOBREAKPAD ::SteamAPI_UseBreakpadCrashHandler(pchVersion, pchDate, pchTime, bFullMemoryDumps, pvContext, m_pfnPreMinidumpCallback); +#endif } void CSimplePlatform::SteamAPI_RegisterCallback(CCallbackBase *pCallback, int iCallback) { diff --git a/rehlds/rehlds/precompiled.h b/rehlds/rehlds/precompiled.h index 89439d8..f78ad8d 100644 --- a/rehlds/rehlds/precompiled.h +++ b/rehlds/rehlds/precompiled.h @@ -43,7 +43,11 @@ #include "player.h" #include "anonymizer.h" -#include "bzip2/bzlib.h" +#ifdef SYSTEM_BZIP2 +#include +#else +#include "bzip2/bzlib.h" +#endif #include "igame.h" #include "sys_linuxwnd.h"