Added support for Mac OS X and building with clang (bug 5601, r=dvander).

This commit is contained in:
Scott Ehlert
2013-02-13 01:14:37 -06:00
parent b0fe6c83e2
commit 40c1fee55a
191 changed files with 3835 additions and 1946 deletions

View File

@ -1,92 +1,131 @@
#(C)2004-2005 AMX Mod X Development Team
# (C)2004-2013 AMX Mod X Development Team
# Makefile written by David "BAILOPAN" Anderson
HLSDK = ../../../hlsdk
###########################################
### EDIT THESE PATHS FOR YOUR OWN SETUP ###
###########################################
HLSDK = ../../../hlsdk/multiplayer
MM_ROOT = ../../../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O2 -funroll-loops -s -pipe -fomit-frame-pointer -fno-strict-aliasing
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-4.1
NAME = mysql
#MYSQL_DIR = ../../../mysql-5.0.22
MYSQL_DIR = ../../../mysql-5.0
BIN_SUFFIX_32 = amxx_i386.so
BIN_SUFFIX_64 = amxx_amd64.so
#####################################
### EDIT BELOW FOR OTHER PROJECTS ###
#####################################
OBJECTS = basic_sql.cpp handles.cpp module.cpp threading.cpp sdk/amxxmodule.cpp oldcompat_sql.cpp
OBJECTS += thread/BaseWorker.cpp thread/ThreadWorker.cpp thread/PosixThreads.cpp
OBJECTS += mysql/MysqlQuery.cpp mysql/MysqlResultSet.cpp mysql/MysqlDatabase.cpp mysql/MysqlDriver.cpp
PROJECT = mysql
LINK = -lgcc -static-libgcc $(MYSQL_DIR)/lib/libmysqlclient_r.a -lz -lpthread
OBJECTS = basic_sql.cpp handles.cpp module.cpp threading.cpp sdk/amxxmodule.cpp oldcompat_sql.cpp \
thread/BaseWorker.cpp thread/ThreadWorker.cpp thread/PosixThreads.cpp \
mysql/MysqlQuery.cpp mysql/MysqlResultSet.cpp mysql/MysqlDatabase.cpp mysql/MysqlDriver.cpp
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -I$(MYSQL_DIR)/include -L$(MYSQL_DIR)/lib -Ithread \
-Imysql -Isdk
##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
C_OPT_FLAGS = -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
C_GCC4_FLAGS = -fvisibility=hidden
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
CPP = gcc
CPP_OSX = clang
ifeq "$(GCC_VERSION)" "4"
OPT_FLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
LINK = $(MYSQL_DIR)/lib/libmysqlclient_r.a -lz -lpthread -L$(MYSQL_DIR)/lib
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(MYSQL_DIR)/include -Ithread -Imysql -Isdk
################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
OS := $(shell uname -s)
ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
LIB_SUFFIX = _amxx
CFLAGS += -DOSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
LIB_SUFFIX = _amxx_i386
CFLAGS += -DLINUX
LINK += -shared
endif
LINK += -m32 -lm -ldl
CFLAGS += -DSM_DEFAULT_THREADER -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H \
-Dstricmp=strcasecmp -fno-strict-aliasing -m32 -Wall -Werror
CPPFLAGS += -fno-exceptions -fno-rtti
BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT)
ifeq "$(DEBUG)" "true"
BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS)
CFLAGS += $(C_DEBUG_FLAGS)
else
BIN_DIR = Release
CFLAGS = $(OPT_FLAGS)
CFLAGS += $(C_OPT_FLAGS)
LINK += -s
endif
CFLAGS += -DNDEBUG -Wall -Wno-non-virtual-dtor -Werror -fno-exceptions -DHAVE_STDINT_H -Dstricmp=strcasecmp -fno-rtti -static-libgcc
CFLAGS += -DSM_DEFAULT_THREADER -m32
IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_$(BIN_SUFFIX_64)
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64
INCLUDE += -Lextra/lib_linux64
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
BINARY = $(NAME)_$(BIN_SUFFIX_32)
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32
OPT_FLAGS += -march=i686
INCLUDE += -Lextra/lib_linux
CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(C_GCC4_FLAGS)
CPPFLAGS += $(CPP_GCC4_FLAGS)
endif
# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif
# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
# This will break if we include other Makefiles, but is fine for now. It allows
# us to make a copy of this file that uses altered paths (ie. Makefile.mine)
# or other changes without mucking up the original.
MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
$(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all:
mkdir -p $(BIN_DIR)/thread
mkdir -p $(BIN_DIR)/mysql
mkdir -p $(BIN_DIR)/sdk
mkdir -p $(BIN_DIR)
$(MAKE) mysql
mkdir -p $(BIN_DIR)/mysql
mkdir -p $(BIN_DIR)/thread
mkdir -p $(BIN_DIR)/sdk
$(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
amd64:
$(MAKE) all AMD64=true
$(PROJECT): $(OBJ_BIN)
$(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY)
mysql: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug:
$(MAKE) all DEBUG=true
debug:
$(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true
default: all
clean:
rm -rf Release/thread/*.o
rm -rf Release/mysql/*.o
rm -rf Release/sdk/*.o
rm -rf Release/*.o
rm -rf Release/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Release/$(NAME)_$(BIN_SUFFIX_64)
rm -rf Debug/thread/*.o
rm -rf Debug/mysql/*.o
rm -rf Debug/sdk/*.o
rm -rf Debug/*.o
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_32)
rm -rf Debug/$(NAME)_$(BIN_SUFFIX_64)
rm -rf $(BIN_DIR)/*.o
rm -rf $(BIN_DIR)/mysql/*.o
rm -rf $(BIN_DIR)/thread/*.o
rm -rf $(BIN_DIR)/sdk/*.o
rm -f $(BIN_DIR)/$(BINARY)

View File

@ -42,7 +42,7 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
{
snprintf(error, maxlength, "Initialization failed");
}
return false;
return NULL;
}
if (do_timeout && info->max_timeout)
@ -67,7 +67,7 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
{
snprintf(error, maxlength, "%s", mysql_error(mysql));
}
return false;
return NULL;
}
MysqlDatabase *pMysql = new MysqlDatabase(mysql, this);

View File

@ -2240,7 +2240,7 @@ static META_FUNCTIONS g_MetaFunctions_Table =
GetEngineFunctions_Post
};
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{
if ((int) CVAR_GET_FLOAT("developer") != 0)
UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
@ -2334,7 +2334,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#ifdef __linux__
#if defined(__linux__) || defined(__APPLE__)
// linux prototype
C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) {
@ -3050,7 +3050,7 @@ char* UTIL_VarArgs( char *format, ... )
// UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message >
//=========================================================
void UTIL_LogPrintf( char *fmt, ... )
void UTIL_LogPrintf( const char *fmt, ... )
{
va_list argptr;
static char string[1024];

View File

@ -20,11 +20,16 @@
// DLL Export
#undef DLLEXPORT
#ifndef __linux__
#if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __attribute__((visibility("default")))
#endif
#if defined(__linux__) && !defined(LINUX)
#define LINUX
#elif defined(__APPLE__) && !defined(OSX)
#define OSX
#endif
#undef C_DLLEXPORT
@ -66,7 +71,7 @@ struct amxx_module_info_s
#if defined HAVE_STDINT_H
#include <stdint.h>
#else
#if defined __LCC__ || defined __DMC__ || defined LINUX
#if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
#if defined HAVE_INTTYPES_H
#include <inttypes.h>
#else
@ -308,7 +313,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif
#if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__
#if defined LINUX || defined __FreeBSD__ || defined __APPLE__
#pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k
@ -395,7 +400,7 @@ enum {
};
#if !defined AMX_NO_ALIGN
#if defined __linux__
#if defined(__linux__) || defined(__APPLE__)
#pragma pack() /* reset default packing */
#else
#pragma pack(pop) /* reset previous packing */
@ -406,7 +411,7 @@ enum {
// ***** declare functions *****
#ifdef USE_METAMOD
void UTIL_LogPrintf( char *fmt, ... );
void UTIL_LogPrintf( const char *fmt, ... );
void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage);
short FixedSigned16( float value, float scale );
unsigned short FixedUnsigned16( float value, float scale );
@ -833,11 +838,11 @@ int FN_AllowLagCompensation_Post(void);
#ifdef FN_PrecacheModel
int FN_PrecacheModel(char *s);
int FN_PrecacheModel(const char *s);
#endif // FN_PrecacheModel
#ifdef FN_PrecacheSound
int FN_PrecacheSound(char *s);
int FN_PrecacheSound(const char *s);
#endif // FN_PrecacheSound
#ifdef FN_SetModel
@ -857,7 +862,7 @@ void FN_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize
#ifdef FN_ChangeLevel
void FN_ChangeLevel(char *s1, char *s2);
void FN_ChangeLevel(const char *s1, const char *s2);
#endif // FN_ChangeLevel
#ifdef FN_GetSpawnParms
@ -1261,19 +1266,19 @@ char *FN_GetInfoKeyBuffer(edict_t *e);
#endif // FN_GetInfoKeyBuffer
#ifdef FN_InfoKeyValue
char *FN_InfoKeyValue(char *infobuffer, char *key);
char *FN_InfoKeyValue(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue
#ifdef FN_SetKeyValue
void FN_SetKeyValue(char *infobuffer, char *key, char *value);
void FN_SetKeyValue(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue
#ifdef FN_SetClientKeyValue
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, char *key, char *value);
void FN_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue
#ifdef FN_IsMapValid
int FN_IsMapValid(char *filename);
int FN_IsMapValid(const char *filename);
#endif // FN_IsMapValid
#ifdef FN_StaticDecal
@ -1281,7 +1286,7 @@ void FN_StaticDecal(const float *origin, int decalIndex, int entityIndex, int mo
#endif // FN_StaticDecal
#ifdef FN_PrecacheGeneric
int FN_PrecacheGeneric(char *s);
int FN_PrecacheGeneric(const char *s);
#endif // FN_PrecacheGeneric
#ifdef FN_GetPlayerUserId
@ -1414,11 +1419,11 @@ const char *FN_GetPlayerAuthId(edict_t *e);
#ifdef FN_PrecacheModel_Post
int FN_PrecacheModel_Post(char *s);
int FN_PrecacheModel_Post(const char *s);
#endif // FN_PrecacheModel_Post
#ifdef FN_PrecacheSound_Post
int FN_PrecacheSound_Post(char *s);
int FN_PrecacheSound_Post(const char *s);
#endif // FN_PrecacheSound_Post
#ifdef FN_SetModel_Post
@ -1438,7 +1443,7 @@ void FN_SetSize_Post(edict_t *e, const float *rgflMin, const float *rgflMax);
#endif // FN_SetSize_Post
#ifdef FN_ChangeLevel_Post
void FN_ChangeLevel_Post(char *s1, char *s2);
void FN_ChangeLevel_Post(const char *s1, const char *s2);
#endif // FN_ChangeLevel_Post
#ifdef FN_GetSpawnParms_Post
@ -1842,19 +1847,19 @@ char *FN_GetInfoKeyBuffer_Post(edict_t *e);
#endif // FN_GetInfoKeyBuffer_Post
#ifdef FN_InfoKeyValue_Post
char *FN_InfoKeyValue_Post(char *infobuffer, char *key);
char *FN_InfoKeyValue_Post(char *infobuffer, const char *key);
#endif // FN_InfoKeyValue_Post
#ifdef FN_SetKeyValue_Post
void FN_SetKeyValue_Post(char *infobuffer, char *key, char *value);
void FN_SetKeyValue_Post(char *infobuffer, const char *key, const char *value);
#endif // FN_SetKeyValue_Post
#ifdef FN_SetClientKeyValue_Post
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, char *key, char *value);
void FN_SetClientKeyValue_Post(int clientIndex, char *infobuffer, const char *key, const char *value);
#endif // FN_SetClientKeyValue_Post
#ifdef FN_IsMapValid_Post
int FN_IsMapValid_Post(char *filename);
int FN_IsMapValid_Post(const char *filename);
#endif // FN_IsMapValid_Post
#ifdef FN_StaticDecal_Post
@ -1862,7 +1867,7 @@ void FN_StaticDecal_Post(const float *origin, int decalIndex, int entityIndex, i
#endif // FN_StaticDecal_Post
#ifdef FN_PrecacheGeneric_Post
int FN_PrecacheGeneric_Post(char *s);
int FN_PrecacheGeneric_Post(const char *s);
#endif // FN_PrecacheGeneric_Post
#ifdef FN_GetPlayerUserId_Post
@ -2116,7 +2121,7 @@ typedef int (*PFN_ADD_NEW_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...);
typedef cell * (*PFN_GET_AMXADDR) (AMX * /*amx*/, cell /*offset*/);
typedef void (*PFN_PRINT_SRVCONSOLE) (char * /*format*/, ...);
typedef void (*PFN_PRINT_SRVCONSOLE) (const char * /*format*/, ...);
typedef const char * (*PFN_GET_MODNAME) (void);
typedef const char * (*PFN_GET_AMXSCRIPTNAME) (int /*id*/);
typedef AMX * (*PFN_GET_AMXSCRIPT) (int /*id*/);
@ -2175,8 +2180,8 @@ typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned i
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_AMX_FINDNATIVE) (AMX* /*amx*/, const char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/, int /* debug */);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);

View File

@ -19,7 +19,7 @@
#endif
#include <new>
#include <malloc.h>
#include <stdlib.h>
namespace SourceHook
{

View File

@ -196,7 +196,7 @@ public:
if (is_space(v[len-1]))
{
for (i=len-1; i>=0; i--)
for (i=len-1; i<len; i--)
{
if (!is_space(v[i])
|| (is_space(v[i]) && i==0))

View File

@ -1,7 +1,7 @@
#ifndef _INCLUDE_SOURCEMOD_THREAD_SUPPORT_H
#define _INCLUDE_SOURCEMOD_THREAD_SUPPORT_H
#if defined __linux__
#if defined __linux__ || defined __APPLE__
#include "PosixThreads.h"
#elif defined WIN32
#include "WinThreads.h"

View File

@ -134,7 +134,7 @@ void MysqlThread::SetInfo(const char *host, const char *user, const char *pass,
m_user.assign(user);
m_pass.assign(pass);
m_db.assign(db);
m_max_timeout = m_max_timeout;
m_max_timeout = max_timeout;
m_port = port;
m_qrInfo.queue_time = gpGlobals->time;
}