Mac OS X build fixes (bug 4391, r=dvander).

This commit is contained in:
Scott Ehlert 2010-05-14 00:34:56 -05:00
parent 73e2daec56
commit 31c8cc9681
10 changed files with 52 additions and 26 deletions

View File

@ -314,6 +314,8 @@ LoadPluginsFromFile(const char *filepath, int &skipped)
{ {
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
ext = ".dll"; ext = ".dll";
#elif defined __APPLE__
ext = ".dylib";
#else #else
ext = "_i486.so"; ext = "_i486.so";
#endif #endif
@ -481,7 +483,7 @@ mm_StartupMetamod(bool is_vsp_load)
ConVarFlag_SpOnly); ConVarFlag_SpOnly);
mm_basedir = provider->CreateConVar("mm_basedir", mm_basedir = provider->CreateConVar("mm_basedir",
#if defined __linux__ #if defined __linux__ || defined __APPLE__
"addons/metamod", "addons/metamod",
#else #else
"addons\\metamod", "addons\\metamod",
@ -1123,6 +1125,8 @@ ProcessVDF(const char *path, bool &skipped)
file, file,
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
".dll" ".dll"
#elif defined __APPLE__
".dylib"
#else #else
"_i486.so" "_i486.so"
#endif #endif

View File

@ -39,7 +39,7 @@
#include <sourcehook/sourcehook.h> #include <sourcehook/sourcehook.h>
#include <ISmmPlugin.h> #include <ISmmPlugin.h>
#include "metamod_provider.h" #include "metamod_provider.h"
#include "version.h" #include <metamod_version.h>
using namespace SourceMM; using namespace SourceMM;

View File

@ -425,6 +425,8 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
const char *ext = UTIL_GetExtension(file); const char *ext = UTIL_GetExtension(file);
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
ext = ext ? "" : ".dll"; ext = ext ? "" : ".dll";
#elif defined __APPLE__
ext = ext ? "" : ".dylib";
#else #else
ext = ext ? "" : "_i486.so"; ext = ext ? "" : "_i486.so";
#endif #endif
@ -547,6 +549,8 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
const char *ext = UTIL_GetExtension(file); const char *ext = UTIL_GetExtension(file);
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
ext = ext ? "" : ".dll"; ext = ext ? "" : ".dll";
#elif defined __APPLE__
ext = ext ? "" : ".dylib";
#else #else
ext = ext ? "" : "_i486.so"; ext = ext ? "" : "_i486.so";
#endif #endif

View File

@ -27,9 +27,9 @@
#include <stdio.h> #include <stdio.h>
#include "metamod_oslink.h" #include "metamod_oslink.h"
#include <malloc.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef __linux #if defined __linux__ || defined __APPLE__
#include <errno.h> #include <errno.h>
#endif #endif
@ -57,7 +57,7 @@ const char *dlerror()
} }
#endif #endif
#if defined __linux__ #if defined __linux_ || defined __APPLE___
int GetLastError() int GetLastError()
{ {
return errno; return errno;
@ -82,7 +82,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
return false; return false;
HMODULE dll = (HMODULE)mem.AllocationBase; HMODULE dll = (HMODULE)mem.AllocationBase;
GetModuleFileName(dll, (LPTSTR)buffer, maxlength); GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
Dl_info info; Dl_info info;
if (!dladdr(pAddr, &info)) if (!dladdr(pAddr, &info))
return false; return false;

View File

@ -51,11 +51,15 @@
#define PATH_SEP_CHAR '\\' #define PATH_SEP_CHAR '\\'
#define ALT_SEP_CHAR '/' #define ALT_SEP_CHAR '/'
#define PATH_SIZE MAX_PATH #define PATH_SIZE MAX_PATH
#define SERVER_DLL "server.dll"
#define strcasecmp stricmp #define strcasecmp stricmp
inline bool _IsPathSepChar(char c) { return (c == '/' || c == '\\'); } inline bool _IsPathSepChar(char c) { return (c == '/' || c == '\\'); }
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
#define OS_LINUX #if defined __linux__
#define OS_LINUX
#elif defined __APPLE__
#define OS_DARWIN
#include <sys/syslimits.h>
#endif
#include <dlfcn.h> #include <dlfcn.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
@ -69,11 +73,10 @@
#define PATH_SIZE PATH_MAX #define PATH_SIZE PATH_MAX
#define stricmp strcasecmp #define stricmp strcasecmp
#define strnicmp strncasecmp #define strnicmp strncasecmp
#define SERVER_DLL "server_i486.so"
inline bool _IsPathSepChar(char c) { return (c == '/'); } inline bool _IsPathSepChar(char c) { return (c == '/'); }
#endif #endif
#if defined __linux__ #if defined __linux__ || defined __APPLE__
#include <errno.h> #include <errno.h>
int GetLastError(); int GetLastError();
#endif #endif
@ -103,7 +106,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength);
#endif #endif
#endif #endif
#ifndef __linux__ #if !defined __linux__ && !defined __APPLE__
#define snprintf _snprintf #define snprintf _snprintf
#if defined _MSC_VER && _MSC_VER < 1500 #if defined _MSC_VER && _MSC_VER < 1500
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf

View File

@ -197,7 +197,7 @@ inline bool pathchar_sep(char a)
{ {
#if defined WIN32 #if defined WIN32
return (a == '/' || a == '\\'); return (a == '/' || a == '\\');
#elif defined __linux__ #else
return (a == '/'); return (a == '/');
#endif #endif
} }
@ -208,7 +208,7 @@ inline bool pathstr_isabsolute(const char *str)
return (pathchar_isalpha(str[0]) return (pathchar_isalpha(str[0])
&& str[1] == ':' && str[1] == ':'
&& pathchar_sep(str[2])); && pathchar_sep(str[2]));
#elif defined __linux__ #else
return (str[0] == '/'); return (str[0] == '/');
#endif #endif
} }

View File

@ -54,6 +54,8 @@ static char mm_path[PLATFORM_MAX_PATH];
#if defined _WIN32 #if defined _WIN32
#define SERVER_NAME "server.dll" #define SERVER_NAME "server.dll"
#elif defined __APPLE__
#define SERVER_NAME "server.dylib"
#elif defined __linux__ #elif defined __linux__
#define SERVER_NAME "server" LIB_SUFFIX #define SERVER_NAME "server" LIB_SUFFIX
#endif #endif

View File

@ -81,6 +81,9 @@ static const char *backend_names[] =
#if defined _WIN32 #if defined _WIN32
#define LIBRARY_EXT ".dll" #define LIBRARY_EXT ".dll"
#define LIBRARY_MINEXT ".dll" #define LIBRARY_MINEXT ".dll"
#elif defined __APPLE__
#define LIBRARY_EXT ".dylib"
#define LIBRARY_MINEXT ".dylib"
#elif defined __linux__ #elif defined __linux__
#define LIBRARY_EXT LIB_SUFFIX #define LIBRARY_EXT LIB_SUFFIX
#define LIBRARY_MINEXT ".so" #define LIBRARY_MINEXT ".so"
@ -179,6 +182,9 @@ mm_GetProcAddress(const char *name)
#if defined _WIN32 #if defined _WIN32
#define TIER0_NAME "bin\\tier0.dll" #define TIER0_NAME "bin\\tier0.dll"
#define VSTDLIB_NAME "bin\\vstdlib.dll" #define VSTDLIB_NAME "bin\\vstdlib.dll"
#elif defined __APPLE__
#define TIER0_NAME "bin/libtier0.dylib"
#define VSTDLIB_NAME "bin/libvstdlib.dylib"
#elif defined __linux__ #elif defined __linux__
#define TIER0_NAME "bin/" LIB_PREFIX "tier0" LIB_SUFFIX #define TIER0_NAME "bin/" LIB_PREFIX "tier0" LIB_SUFFIX
#define VSTDLIB_NAME "bin/" LIB_PREFIX "vstdlib" LIB_SUFFIX #define VSTDLIB_NAME "bin/" LIB_PREFIX "vstdlib" LIB_SUFFIX

View File

@ -40,26 +40,33 @@
#define SH_COMP_MSVC 2 #define SH_COMP_MSVC 2
#if defined WIN32 #if defined WIN32
#define SH_SYS SH_SYS_WIN32
#define SH_XP SH_XP_WINAPI
#define SH_COMP SH_COMP_MSVC
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <direct.h> #include <direct.h>
#define PLATFORM_MAX_PATH MAX_PATH #define PLATFORM_MAX_PATH MAX_PATH
#define SH_SYS SH_SYS_WIN32
#define SH_XP SH_XP_WINAPI
#define SH_COMP SH_COMP_MSVC
#define PATH_SEP_STR "\\" #define PATH_SEP_STR "\\"
#define PATH_SEP_CHAR '\\' #define PATH_SEP_CHAR '\\'
#define ALT_SEP_CHAR '/' #define ALT_SEP_CHAR '/'
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
#if defined __linux__
#define SH_SYS SH_SYS_LINUX
#elif defined __APPLE__
#define SH_SYS SH_SYS_APPLE
#endif
#define SH_XP SH_XP_POSIX
#define SH_COMP SH_COMP_GCC
#include <dlfcn.h> #include <dlfcn.h>
#include <dirent.h> #include <dirent.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#if SH_SYS == SH_SYS_APPLE
#include <sys/syslimits.h>
#endif
typedef void * HMODULE; typedef void * HMODULE;
#define PLATFORM_MAX_PATH PATH_MAX #define PLATFORM_MAX_PATH PATH_MAX
#define SH_SYS SH_SYS_LINUX
#define SH_XP SH_XP_POSIX
#define SH_COMP SH_COMP_GCC
#define PATH_SEP_STR "/" #define PATH_SEP_STR "/"
#define PATH_SEP_CHAR '/' #define PATH_SEP_CHAR '/'
#define ALT_SEP_CHAR '\\' #define ALT_SEP_CHAR '\\'

View File

@ -270,7 +270,7 @@ mm_ResolvePath(const char *path, char *buffer, size_t maxlength)
{ {
#if defined _WIN32 #if defined _WIN32
return _fullpath(buffer, path, maxlength) != NULL; return _fullpath(buffer, path, maxlength) != NULL;
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
assert(maxlength >= PATH_MAX); assert(maxlength >= PATH_MAX);
return realpath(path, buffer) != NULL; return realpath(path, buffer) != NULL;
#endif #endif
@ -289,7 +289,7 @@ mm_LoadLibrary(const char *path, char *buffer, size_t maxlength)
mm_GetPlatformError(buffer, maxlength); mm_GetPlatformError(buffer, maxlength);
return NULL; return NULL;
} }
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
lib = dlopen(path, RTLD_NOW); lib = dlopen(path, RTLD_NOW);
if (lib == NULL) if (lib == NULL)
@ -307,7 +307,7 @@ mm_GetLibAddress(void *lib, const char *name)
{ {
#if defined _WIN32 #if defined _WIN32
return GetProcAddress((HMODULE)lib, name); return GetProcAddress((HMODULE)lib, name);
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
return dlsym(lib, name); return dlsym(lib, name);
#endif #endif
} }
@ -317,7 +317,7 @@ mm_UnloadLibrary(void *lib)
{ {
#if defined _WIN32 #if defined _WIN32
FreeLibrary((HMODULE)lib); FreeLibrary((HMODULE)lib);
#else #elif defined __linux__ || defined __APPLE__
dlclose(lib); dlclose(lib);
#endif #endif
} }
@ -333,7 +333,7 @@ mm_GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
return false; return false;
HMODULE dll = (HMODULE)mem.AllocationBase; HMODULE dll = (HMODULE)mem.AllocationBase;
GetModuleFileName(dll, (LPTSTR)buffer, maxlength); GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
#elif defined __linux__ #elif defined __linux__ || defined __APPLE__
Dl_info info; Dl_info info;
if (!dladdr(pAddr, &info)) if (!dladdr(pAddr, &info))
return false; return false;