diff --git a/linux_sdk/Makefile b/linux_sdk/Makefile index 84095e08..96bba24e 100644 --- a/linux_sdk/Makefile +++ b/linux_sdk/Makefile @@ -30,12 +30,13 @@ ifeq "$(OS)" "Darwin" CC = /usr/bin/clang CPLUS = /usr/bin/clang++ CLINK = /usr/bin/clang +CPP_LIB = else CC = /usr/bin/gcc CPLUS = /usr/bin/g++ CLINK = /usr/bin/gcc +CPP_LIB = "$(SRCDS_DIR)/bin/libstdc++.so.6 $(SRCDS_DIR)/bin/libgcc_s.so.1" endif -CPP_LIB = "libstdc++.a libgcc_eh.a" # put any compiler flags you want passed here USER_CFLAGS = @@ -56,7 +57,16 @@ DEBUG = false ############################################################################# # Things below here shouldn't need to be altered ############################################################################# -OS := $(shell uname -s) +IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0") + +ifeq "$(IS_CLANG)" "1" +CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/") +CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/") +else +CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1) +CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3) +endif + MAKE = make AR = "ar rvs" @@ -80,20 +90,30 @@ ARCH = i486 ARCH_CFLAGS = -mtune=i686 -march=pentium3 -mmmx -msse -msse2 -m32 ifeq "$(OS)" "Darwin" -DEFINES = -D_OSX -DOSX +DEFINES = -D_OSX -DOSX -D_DLL_EXT=.dylib ARCH_CFLAGS += -mmacosx-version-min=10.7 +SHLIBEXT = dylib +SHLIBLDFLAGS = -dynamiclib -mmacosx-version-min=10.7 +SHLIBSUFFIX = else -DEFINES = -D_LINUX -DLINUX +DEFINES = -D_LINUX -DLINUX -D_DLL_EXT=.so +SHLIBEXT = so +SHLIBLDFLAGS = -shared -Wl,-Map,$@_map.txt +SHLIBSUFFIX = endif -DEFINES += -DCOMPILER_GCC -DPOSIX -DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp \ - -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp +DEFINES +=-DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ + -Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -DPOSIX -DGNUC -DCOMPILER_GCC -DNO_MALLOC_OVERRIDE UNDEF = -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE -BASE_CFLAGS = -fno-strict-aliasing -Wall -Werror -Wno-conversion -Wno-overloaded-virtual -Wno-non-virtual-dtor -Wno-invalid-offsetof -SHLIBEXT = so +BASE_CFLAGS = -fno-strict-aliasing -Wall -Wsign-compare -Werror -Wno-conversion -Wno-overloaded-virtual -Wno-non-virtual-dtor -Wno-invalid-offsetof \ + -Wno-unknown-pragmas -Wno-unused SHLIBCFLAGS = -fPIC -SHLIBLDFLAGS = -shared -Wl,-Map,$@_map.txt -Wl + +# Clang >= 3 || GCC >= 4.7 +ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1" +BASE_CFLAGS += -Wno-delete-non-virtual-dtor -Wno-narrowing +endif # Flags passed to the c compiler CFLAGS = $(DEFINES) $(ARCH_CFLAGS) -O3 $(BASE_CFLAGS) @@ -109,7 +129,7 @@ DBG_CFLAGS = "$(DEFINES) $(ARCH_CFLAGS) -g -ggdb $(BASE_CFLAGS) $(UNDEF)" # define list passed to make for the sub makefile BASE_DEFINES = CC=$(CC) AR=$(AR) CPLUS=$(CPLUS) CPP_LIB=$(CPP_LIB) DEBUG=$(DEBUG) \ BUILD_DIR=$(BUILD_DIR) BUILD_OBJ_DIR=$(BUILD_OBJ_DIR) SRC_DIR=$(SRC_DIR) \ - LIB_DIR=$(LIB_DIR) SHLIBLDFLAGS=$(SHLIBLDFLAGS) SHLIBEXT=$(SHLIBEXT) \ + LIB_DIR=$(LIB_DIR) SHLIBLDFLAGS="$(SHLIBLDFLAGS)" SHLIBEXT=$(SHLIBEXT) SHLIBSUFFIX=$(SHLIBSUFFIX) \ CLINK=$(CLINK) CFLAGS="$(CFLAGS)" DBG_CFLAGS=$(DBG_CFLAGS) LDFLAGS=$(LDFLAGS) \ DEFINES="$(DEFINES)" DBG_DEFINES=$(DBG_DEFINES) \ ARCH=$(ARCH) SRCDS_DIR=$(SRCDS_DIR) MOD_CONFIG=$(MOD_CONFIG) NAME=$(NAME) \ @@ -133,10 +153,10 @@ check: cd $(BUILD_DIR) if [ ! -e "$(LIB_DIR)/tier1_i486.a" ]; then $(MAKE) tier1;fi if [ ! -e "$(LIB_DIR)/mathlib_i486.a" ]; then $(MAKE) mathlib;fi - if [ ! -e "$(LIB_DIR)/choreoobjects_i486.a" ]; then $(MAKE) choreo;fi - if [ ! -f "tier0_i486.so" ]; then ln -s $(SRCDS_DIR)/bin/tier0_i486.so .; fi - if [ ! -f "vstdlib_i486.so" ]; then ln -s $(SRCDS_DIR)/bin/vstdlib_i486.so .; fi - if [ ! -f "steam_api_i486.so" ]; then ln -s $(SRCDS_DIR)/bin/steam_api_i486.so .; fi + if [ ! -e "$(LIB_DIR)/interfaces_i486.a" ]; then $(MAKE) interfaces;fi + if [ ! -f "libtier0$(SHLIBSUFFIX).$(SHLIBEXT)" ]; then ln -fs $(LIB_DIR)/libtier0$(SHLIBSUFFIX).$(SHLIBEXT) .; fi + if [ ! -f "libvstdlib$(SHLIBSUFFIX).$(SHLIBEXT)" ]; then ln -fs $(LIB_DIR)/libvstdlib$(SHLIBSUFFIX).$(SHLIBEXT) .; fi + if [ ! -f "libsteam_api.$(SHLIBEXT)" ]; then ln -fs $(LIB_DIR)/libsteam_api.$(SHLIBEXT) .; fi vcpm: check if [ ! -e "vcpm" ]; then $(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES);fi diff --git a/public/appframework/IAppSystemGroup.h b/public/appframework/IAppSystemGroup.h index 89c4d8e6..b5cad8ba 100644 --- a/public/appframework/IAppSystemGroup.h +++ b/public/appframework/IAppSystemGroup.h @@ -23,7 +23,7 @@ #include "tier1/interface.h" #include "tier1/utlvector.h" #include "tier1/utldict.h" -#include "tier1/utlstringmap.h" +#include "tier1/UtlStringMap.h" #include "IAppSystem.h" //----------------------------------------------------------------------------- diff --git a/public/datacache/idatacache.h b/public/datacache/idatacache.h index 0ff98db4..9c9bc509 100644 --- a/public/datacache/idatacache.h +++ b/public/datacache/idatacache.h @@ -351,6 +351,7 @@ public: case DC_AGE_DISCARD: case DC_FLUSH_DISCARD: case DC_REMOVED: + default: Assert ( 0 ); return false; } @@ -536,6 +537,7 @@ public: case DC_AGE_DISCARD: case DC_FLUSH_DISCARD: case DC_REMOVED: + default: STORAGE_TYPE *p = (STORAGE_TYPE *)notification.clientId; p->DestroyResource(); return true; diff --git a/public/filesystem/IQueuedLoader.h b/public/filesystem/IQueuedLoader.h index 428a05e8..8f5f8c9f 100644 --- a/public/filesystem/IQueuedLoader.h +++ b/public/filesystem/IQueuedLoader.h @@ -12,7 +12,7 @@ #endif #include "tier0/platform.h" -#include "appframework/iappsystem.h" +#include "appframework/IAppSystem.h" enum LoaderError_t { diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index 6a9f45f3..eb1f18ec 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -23,9 +23,8 @@ #include "tier1/strtools.h" #include "filesystem_init.h" #include "tier0/icommandline.h" -#include "tier0/stacktools.h" -#include "keyvalues.h" -#include "appframework/iappsystemgroup.h" +#include "KeyValues.h" +#include "appframework/IAppSystemGroup.h" #include "tier1/smartptr.h" #if defined( _X360 ) #include "xbox\xbox_win32stubs.h" @@ -546,7 +545,7 @@ bool IsLowViolenceBuild( void ) return retVal; #elif POSIX return false; -#elif +#else #error "Fix me" #endif } @@ -620,21 +619,6 @@ static void FileSystem_AddLoadedSearchPath( initInfo.m_pFileSystem->AddSearchPath( fullLocationPath, pPathID, PATH_ADD_TO_TAIL ); } - -bool FileSystem_IsHldsUpdateToolDedicatedServer() -{ - // To determine this, we see if the directory our executable was launched from is "orangebox". - // We only are under "orangebox" if we're run from hldsupdatetool. - char baseDir[MAX_PATH]; - if ( !FileSystem_GetBaseDir( baseDir, sizeof( baseDir ) ) ) - return false; - - V_FixSlashes( baseDir ); - V_StripTrailingSlash( baseDir ); - const char *pLastDir = V_UnqualifiedFileName( baseDir ); - return ( pLastDir && V_stricmp( pLastDir, "orangebox" ) == 0 ); -} - #ifdef ENGINE_DLL extern void FileSystem_UpdateAddonSearchPaths( IFileSystem *pFileSystem ); #endif @@ -690,14 +674,6 @@ FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) // Add the Orange-box path (which also will include whatever the depots mapped in as well if we're // running a Steam-launched app). FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence ); - - if ( FileSystem_IsHldsUpdateToolDedicatedServer() ) - { - // If we're using the hldsupdatetool dedicated server, then go up a directory to get the ep1-era files too. - char ep1EraPath[MAX_PATH]; - V_snprintf( ep1EraPath, sizeof( ep1EraPath ), "..%c%s", CORRECT_PATH_SEPARATOR, pLocation ); - FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, ep1EraPath, bLowViolence ); - } } else { diff --git a/public/icvar.h b/public/icvar.h index ebab8531..00d83c82 100644 --- a/public/icvar.h +++ b/public/icvar.h @@ -175,7 +175,7 @@ inline ICvar::Iterator::Iterator(ICvar *icvar) inline ICvar::Iterator::~Iterator( void ) { - g_pMemAlloc->Free(m_pIter); + free(m_pIter); } inline void ICvar::Iterator::SetFirst( void ) diff --git a/public/tier0/memalloc.h b/public/tier0/memalloc.h index 627aaf95..a189ab64 100644 --- a/public/tier0/memalloc.h +++ b/public/tier0/memalloc.h @@ -36,9 +36,11 @@ // Undefine this if using a compiler lacking threadsafe RTTI (like vc6) #define MEM_DEBUG_CLASSNAME 1 -#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) - #include +#if defined(OSX) +#include +#endif + #ifdef LINUX #undef offsetof #define offsetof(s,m) (size_t)&(((s *)0)->m) @@ -46,6 +48,8 @@ #include "tier0/mem.h" +#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) + struct _CrtMemState; #define MEMALLOC_VERSION 1 @@ -488,15 +492,59 @@ struct MemAllocFileLine_t //----------------------------------------------------------------------------- +#elif defined( POSIX ) + +#if defined( OSX ) +// Mac always aligns allocs, don't need to call posix_memalign which doesn't exist in 10.5.8 which TF2 still needs to run on +//inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; posix_memalign(&pTmp, alignment, size); return pTmp;} +inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; pTmp = malloc(size); return pTmp;} +#endif + +inline void *_aligned_malloc( size_t nSize, size_t align ) { return memalign( align, nSize ); } +inline void _aligned_free( void *ptr ) { free( ptr ); } + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName = NULL, int nLine = 0 ) { return malloc( nSize ); } +inline void MemAlloc_Free( void *ptr, const char *pFileName = NULL, int nLine = 0 ) { free( ptr ); } + +inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); } +inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); } +inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile = NULL, int nLine = 0 ) { free( pMemBlock ); } + +#if defined( OSX ) +inline size_t _msize( void *ptr ) { return malloc_size( ptr ); } +#else +inline size_t _msize( void *ptr ) { return malloc_usable_size( ptr ); } +#endif + +inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align ) +{ + void *ptr_new_aligned = memalign( align, size ); + + if( ptr_new_aligned ) + { + size_t old_size = _msize( ptr ); + size_t copy_size = ( size < old_size ) ? size : old_size; + + memcpy( ptr_new_aligned, ptr, copy_size ); + free( ptr ); + } + + return ptr_new_aligned; +} +#else +#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize() +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo ) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo ) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) + #endif // !STEAM && !NO_MALLOC_OVERRIDE //----------------------------------------------------------------------------- #if !defined(STEAM) && defined(NO_MALLOC_OVERRIDE) -#include - #define MEM_ALLOC_CREDIT_(tag) ((void)0) #define MEM_ALLOC_CREDIT() MEM_ALLOC_CREDIT_(__FILE__) +#define MEM_ALLOC_CREDIT_FUNCTION() #define MEM_ALLOC_CREDIT_CLASS() #define MEM_ALLOC_CLASSNAME(type) NULL @@ -507,28 +555,6 @@ struct MemAllocFileLine_t #define MemAlloc_RegisterExternalAllocation( tag, p, size ) ((void)0) #define MemAlloc_RegisterExternalDeallocation( tag, p, size ) ((void)0) -inline void *MemAlloc_AllocAligned( size_t size, size_t align ) -{ - return (void *)_aligned_malloc( size, align ); -} -inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile, int nLine ) -{ - pszFile = pszFile; - nLine = nLine; - return (void *)_aligned_malloc( size, align ); -} - -inline void MemAlloc_FreeAligned( void *pMemBlock ) -{ - _aligned_free( pMemBlock ); -} -inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile, int nLine ) -{ - pszFile = pszFile; - nLine = nLine; - _aligned_free( pMemBlock ); -} - #endif // !STEAM && NO_MALLOC_OVERRIDE //----------------------------------------------------------------------------- diff --git a/public/tier1/fmtstr.h b/public/tier1/fmtstr.h index 39df48ed..4ec3526d 100644 --- a/public/tier1/fmtstr.h +++ b/public/tier1/fmtstr.h @@ -21,13 +21,13 @@ //============================================================================= // using macro to be compatable with GCC -#define FmtStrVSNPrintf( szBuf, nBufSize, ppszFormat ) \ +#define FmtStrVSNPrintf( szBuf, nBufSize, ppszFormat, lastArg ) \ do \ { \ int result; \ va_list arg_ptr; \ \ - va_start(arg_ptr, (*(ppszFormat))); \ + va_start(arg_ptr, lastArg); \ result = Q_vsnprintf((szBuf), (nBufSize)-1, (*(ppszFormat)), arg_ptr); \ va_end(arg_ptr); \ \ @@ -50,26 +50,26 @@ public: // Standard C formatting CFmtStrN(const char *pszFormat, ...) FMTFUNCTION( 2, 3 ) { - FmtStrVSNPrintf(m_szBuf, SIZE_BUF, &pszFormat); + FmtStrVSNPrintf(m_szBuf, SIZE_BUF, &pszFormat, pszFormat); } // Use this for pass-through formatting CFmtStrN(const char ** ppszFormat, ...) { - FmtStrVSNPrintf(m_szBuf, SIZE_BUF, ppszFormat); + FmtStrVSNPrintf(m_szBuf, SIZE_BUF, ppszFormat, ppszFormat); } // Explicit reformat const char *sprintf(const char *pszFormat, ...) FMTFUNCTION( 2, 3 ) { - FmtStrVSNPrintf(m_szBuf, SIZE_BUF, &pszFormat); + FmtStrVSNPrintf(m_szBuf, SIZE_BUF, &pszFormat, pszFormat); return m_szBuf; } // Use this for pass-through formatting void VSprintf(const char **ppszFormat, ...) { - FmtStrVSNPrintf(m_szBuf, SIZE_BUF, ppszFormat); + FmtStrVSNPrintf(m_szBuf, SIZE_BUF, ppszFormat, ppszFormat); } // Use for access @@ -81,7 +81,7 @@ public: void Clear() { m_szBuf[0] = 0; } - void AppendFormat( const char *pchFormat, ... ) { int nLength = Length(); char *pchEnd = m_szBuf + nLength; FmtStrVSNPrintf( pchEnd, SIZE_BUF - nLength, &pchFormat ); } + void AppendFormat( const char *pchFormat, ... ) { int nLength = Length(); char *pchEnd = m_szBuf + nLength; FmtStrVSNPrintf( pchEnd, SIZE_BUF - nLength, &pchFormat, pchFormat ); } void AppendFormatV( const char *pchFormat, va_list args ); void Append( const char *pchValue ) { AppendFormat( pchValue ); } diff --git a/public/tier1/smartptr.h b/public/tier1/smartptr.h index c8d6ffb2..95d0bef3 100644 --- a/public/tier1/smartptr.h +++ b/public/tier1/smartptr.h @@ -107,7 +107,7 @@ template < typename T > class CArrayAutoPtr : public CPlainAutoPtr < T > // Warning: no polymorphic destructor (delete on base class will be a mistake) { public: - explicit CArrayAutoPtr( T *p = NULL ) { Attach( p ); } + explicit CArrayAutoPtr( T *p = NULL ) { this->Attach( p ); } ~CArrayAutoPtr( void ) { Delete(); } public: diff --git a/public/tier1/utlmemory.h b/public/tier1/utlmemory.h index 601e722d..72264a02 100644 --- a/public/tier1/utlmemory.h +++ b/public/tier1/utlmemory.h @@ -272,7 +272,7 @@ private: char m_Memory[ SIZE*sizeof(T) + nAlignment ]; }; -#ifdef _LINUX +#if defined(POSIX) #define REMEMBER_ALLOC_SIZE_FOR_VALGRIND 1 #endif