Skip to content

Commit

Permalink
Fix macOS build (nillerusr#146)
Browse files Browse the repository at this point in the history
* Fix macOS build
* Fix *BSD build
* Add missing *BSD include
  • Loading branch information
exstrim401 authored Nov 27, 2022
1 parent 53bd92f commit 2fb712a
Show file tree
Hide file tree
Showing 45 changed files with 107 additions and 98 deletions.
4 changes: 2 additions & 2 deletions appframework/sdlmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CSDLMgr : public ILauncherMgr

// Get the next N events. The function returns the number of events that were filled into your array.
virtual int GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debugEvents = false );
#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)
virtual int PeekAndRemoveKeyboardEvents( bool *pbEsc, bool *pbReturn, bool *pbSpace, bool debugEvent = false );
#endif

Expand Down Expand Up @@ -1004,7 +1004,7 @@ int CSDLMgr::GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debug
return nToWrite;
}

#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)

int CSDLMgr::PeekAndRemoveKeyboardEvents( bool *pbEsc, bool *pbReturn, bool *pbSpace, bool debugEvent )
{
Expand Down
3 changes: 3 additions & 0 deletions appframework/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def build(bld):

libs = []

if bld.env.DEST_OS == 'darwin':
libs += ['FOUNDATION', 'APPKIT', 'IOKIT']

bld.stlib(
source = source,
target = PROJECT_NAME,
Expand Down
2 changes: 1 addition & 1 deletion common/freetype/config/ftconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifdef ANDROID
#include <sys/cdefs.h>
#elif defined(OSX) || defined(BSD)
#elif defined(OSX) || defined(PLATFORM_BSD)
#include <stdint.h>
#else
#include <bits/wordsize.h>
Expand Down
4 changes: 4 additions & 0 deletions dedicated/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
#include <stdlib.h>
#include "interface.h"
#include <string.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include "tier1/strtools.h"
#include "tier0/icommandline.h"
#include "tier0/dbg.h"
Expand Down
4 changes: 4 additions & 0 deletions dedicated/sys_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <stdarg.h>
#include <sys/types.h>
#include <sys/time.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
Expand Down
4 changes: 2 additions & 2 deletions dedicated_main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ int main( int argc, char *argv[] )
void *tier0 = dlopen( "libtier0" DLL_EXT_STRING, RTLD_NOW );
void *vstdlib = dlopen( "libvstdlib" DLL_EXT_STRING, RTLD_NOW );

const char *pBinaryName = "dedicated" DLL_EXT_STRING;
const char *pBinaryName = "bin/dedicated" DLL_EXT_STRING;

void *dedicated = dlopen( pBinaryName, RTLD_NOW );
if ( !dedicated )
dedicated = dlopen( "libdedicated" DLL_EXT_STRING, RTLD_NOW );
dedicated = dlopen( "bin/libdedicated" DLL_EXT_STRING, RTLD_NOW );

if ( !dedicated )
{
Expand Down
10 changes: 5 additions & 5 deletions engine/bugreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <copyfile.h>
#import <mach/mach_host.h>
#import <sys/sysctl.h>
#elif defined(BSD)
#elif defined(PLATFORM_BSD)
# include <sys/sysctl.h>
# include <sys/types.h>
# include <fcntl.h>
Expand Down Expand Up @@ -110,7 +110,7 @@
#define BUG_REPOSITORY_URL "\\\\fileserver\\bugs"
#elif defined(OSX)
#define BUG_REPOSITORY_URL "/Volumes/bugs"
#elif defined(LINUX) || defined(BSD)
#elif defined(LINUX) || defined(PLATFORM_BSD)
#define BUG_REPOSITORY_URL "\\\\fileserver\\bugs"
#else
//#error
Expand Down Expand Up @@ -144,7 +144,7 @@ unsigned long GetRam()
MEMORYSTATUS stat;
GlobalMemoryStatus( &stat );
return (stat.dwTotalPhys / (1024 * 1024));
#elif defined(OSX) || defined(BSD)
#elif defined(OSX) || defined(PLATFORM_BSD)
int mib[2] = { CTL_HW, HW_MEMSIZE };
u_int namelen = sizeof(mib) / sizeof(mib[0]);
uint64_t memsize;
Expand Down Expand Up @@ -345,7 +345,7 @@ void DisplaySystemVersion( char *osversion, int maxlen )

fclose( fpKernelVer );
}
#elif BSD
#elif PLATFORM_BSD
#ifdef __FreeBSD__
osversion = (char *)"FreeBSD";
#else
Expand Down Expand Up @@ -2257,7 +2257,7 @@ void NonFileSystem_CreatePath (const char *path)
}
}

#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)
#define COPYFILE_ALL 0
#define BSIZE 65535
int copyfile( const char *local, const char *remote, void *ignored, int ignoredFlags )
Expand Down
2 changes: 1 addition & 1 deletion engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ bool CGameServer::SpawnServer( const char *szMapName, const char *szMapFile, con
event->SetString( "os", "LINUX" );
#elif defined ( OSX )
event->SetString( "os", "OSX" );
#elif defined(BSD)
#elif defined(PLATFORM_BSD)
event->SetString("os",
# ifdef __FreeBSD__
"FreeBSD"
Expand Down
4 changes: 2 additions & 2 deletions engine/sv_uploadgamestats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//$ #include <uuid/uuid.h>
#ifdef OSX
#include <uuid/uuid.h>
#elif defined(BSD)
#elif defined(PLATFORM_BSD)
#include <uuid.h>
#else
typedef unsigned char uuid_t[16];
Expand Down Expand Up @@ -398,7 +398,7 @@ class CUploadGameStats : public IUploadGameStats
uuid_t newId;
#ifdef OSX
uuid_generate( newId );
#elif defined(BSD)
#elif defined(PLATFORM_BSD)
uint32_t status;
uuid_create( &newId, &status );
#endif
Expand Down
6 changes: 3 additions & 3 deletions engine/sys_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#elif defined(OSX)
#include <Carbon/Carbon.h>
#include <sys/sysctl.h>
#elif defined(BSD)
#elif defined(PLATFORM_BSD)
#include <sys/types.h>
#include <sys/sysctl.h>
#define HW_MEMSIZE HW_PHYSMEM
Expand Down Expand Up @@ -668,7 +668,7 @@ void Sys_InitMemory( void )
#elif defined(POSIX)
uint64_t memsize = ONE_HUNDRED_TWENTY_EIGHT_MB;

#if defined(OSX) || defined(BSD)
#if defined(OSX) || defined(PLATFORM_BSD)
int mib[2] = { CTL_HW, HW_MEMSIZE };
u_int namelen = sizeof(mib) / sizeof(mib[0]);
size_t len = sizeof(memsize);
Expand Down Expand Up @@ -1586,7 +1586,7 @@ CON_COMMAND( star_memory, "Dump memory stats" )
struct mstats memstats = mstats( );
Msg( "Available %.2f MB, Used: %.2f MB, #mallocs = %lu\n",
memstats.bytes_free / ( 1024.0 * 1024.0), memstats.bytes_used / ( 1024.0 * 1024.0 ), memstats.chunks_used );
#elif BSD
#elif PLATFORM_BSD
# warning TODO: Implement memory stats (peace of sheet of course)
#else // Win32
MEMORYSTATUS stat;
Expand Down
11 changes: 6 additions & 5 deletions engine/sys_dll2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include <Psapi.h>
#endif

#if defined( OSX ) || defined(BSD)
#if defined( OSX ) || defined(PLATFORM_BSD)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

Expand Down Expand Up @@ -278,7 +279,7 @@ static void posix_signal_handler( int i )
#define DO_TRY if ( sigsetjmp( g_mark, 1 ) == 0 )
#define DO_CATCH else

#if defined( OSX ) || defined(BSD)
#if defined( OSX ) || defined(PLATFORM_BSD)
#define __sighandler_t sig_t
#endif

Expand Down Expand Up @@ -537,7 +538,7 @@ class CErrorText
FreeLibrary( hInst );
}

#elif defined( OSX ) || defined(BSD)
#elif defined( OSX ) || defined(PLATFORM_BSD)

static const struct
{
Expand All @@ -548,7 +549,7 @@ class CErrorText
#define _XTAG( _x ) { _x, #_x }
_XTAG( HW_PHYSMEM ),
_XTAG( HW_USERMEM ),
#ifdef BSD
#ifdef PLATFORM_BSD
_XTAG( HW_PHYSMEM ),
_XTAG( HW_NCPU ),
#else
Expand All @@ -566,7 +567,7 @@ class CErrorText

if ( sysctl( mib, Q_ARRAYSIZE( mib ), &val, &len, NULL, 0 ) == 0 )
{
CommentPrintf( " %s: %" PRIu64 "\n", s_ctl_names[ i ].name, val );
CommentPrintf( " %s: %d\n", s_ctl_names[ i ].name, val );
}
}

Expand Down
4 changes: 2 additions & 2 deletions engine/sys_mainwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#elif defined(_X360)
// nothing to include for 360
#elif defined(OSX)
#elif defined(LINUX) || defined(BSD)
#elif defined(LINUX) || defined(PLATFORM_BSD)
#include "tier0/dynfunction.h"
#elif defined(_WIN32)
#include "tier0/dynfunction.h"
Expand Down Expand Up @@ -833,7 +833,7 @@ LRESULT CGame::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// return 0 if handled message, 1 if not
return lRet;
}
#elif defined(OSX) || defined(LINUX) || defined(_WIN32) || defined(BSD)
#elif defined(OSX) || defined(LINUX) || defined(_WIN32) || defined(PLATFORM_BSD)

#else
#error
Expand Down
14 changes: 7 additions & 7 deletions engine/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ def build(bld):
if bld.env.DEST_OS != "darwin":
source += ['audio/snd_dev_sdl.cpp']

if bld.env.DEST_OS == 'darwin':
source += [
'audio/snd_dev_openal.cpp', # [$OSXALL]
'audio/snd_dev_mac_audioqueue.cpp',# [$OSXALL]
'audio/voice_record_mac_audioqueue.cpp', #[$OSXALL]
]

if bld.env.DEST_OS == 'win32':
source += [
Expand Down Expand Up @@ -343,6 +337,12 @@ def build(bld):
'audio/voice_mixer_controls_openal.cpp', #[$OSXALL||$LINUXALL]
'audio/voice_record_openal.cpp' #[$OSXALL||$LINUXALL]
]
if bld.env.DEST_OS == 'darwin':
source += [
'audio/snd_dev_openal.cpp', # [$OSXALL]
'audio/snd_dev_mac_audioqueue.cpp',# [$OSXALL]
'audio/voice_record_mac_audioqueue.cpp', #[$OSXALL]
]

includes = [
'.',
Expand All @@ -363,7 +363,7 @@ def build(bld):
libs += ['SSL', 'CRYPTO'] # android curl was built with openssl
elif bld.env.DEST_OS == 'win32':
libs += ['USER32', 'WINMM', 'WININET', 'DSOUND', 'DXGUID', 'GDI32', 'bzip2']
elif bld.env.DEST_OS == 'darwin':
elif bld.env.DEST_OS == 'darwin' and not bld.env.DEDICATED:
libs += ['APPKIT', 'COREAUDIO', 'AUDIOTOOLBOX', 'SYSTEMCONFIGURATION']

install_path = bld.env.LIBDIR
Expand Down
2 changes: 1 addition & 1 deletion filesystem/basefilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ time_t CBaseFileSystem::FastFileTime( const CSearchPath *path, const char *pFile
{
return buf.st_mtime;
}
#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)
char caseFixedName[ MAX_PATH ];
bool found = findFileInDirCaseInsensitive_safe( pTmpFileName, caseFixedName );
if ( found && FS_stat( caseFixedName, &buf ) != -1 )
Expand Down
2 changes: 1 addition & 1 deletion filesystem/filesystem_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ void CBaseFileSystem::DoAsyncCallback( const FileAsyncRequest_t &request, void *
if ( pDataToFree )
{
Assert( !request.pfnAlloc );
#if defined( OSX ) || defined( LINUX ) || defined(BSD)
#if defined( OSX ) || defined( LINUX ) || defined(PLATFORM_BSD)
// The ugly delete[] (void*) method generates a compile warning on osx, as it should.
free( pDataToFree );
#else
Expand Down
6 changes: 3 additions & 3 deletions filesystem/filesystem_stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ int CFileSystem_Stdio::FS_chmod( const char *pathT, int pmode )
CBaseFileSystem::FixUpPath ( pathT, path, sizeof( path ) );

int rt = _chmod( path, pmode );
#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)
if (rt==-1)
{
char caseFixedName[ MAX_PATH ];
Expand Down Expand Up @@ -707,7 +707,7 @@ int CFileSystem_Stdio::FS_stat( const char *pathT, struct _stat *buf, bool *pbLo
}
#endif // defined(_WIN32) && defined(FILESYSTEM_MSVC2015_STAT_BUG_WORKAROUND)

#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)
if ( rt == -1 )
{
char caseFixedName[ MAX_PATH ];
Expand Down Expand Up @@ -866,7 +866,7 @@ CStdioFile *CStdioFile::FS_fopen( const char *filenameT, const char *options, in
}
}

#if defined(LINUX) || defined(BSD)
#if defined(LINUX) || defined(PLATFORM_BSD)
if(!pFile && !strchr(options,'w') && !strchr(options,'+') ) // try opening the lower cased version
{
char caseFixedName[ MAX_PATH ];
Expand Down
2 changes: 1 addition & 1 deletion gameui/BasePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ void CBasePanel::RunMenuCommand(const char *command)

RegCloseKey(hKey);
}
#elif defined( OSX ) || defined( LINUX ) || defined(BSD)
#elif defined( OSX ) || defined( LINUX ) || defined(PLATFORM_BSD)
FILE *fp = fopen( "/tmp/hl2_relaunch", "w+" );
if ( fp )
{
Expand Down
2 changes: 1 addition & 1 deletion ivp
12 changes: 6 additions & 6 deletions launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class CVCRHelpers : public IVCRHelpers
public:
virtual void ErrorMessage( const char *pMsg )
{
#if defined( WIN32 ) || defined( LINUX ) || defined(BSD)
#if defined( WIN32 ) || defined( LINUX ) || defined(PLATFORM_BSD)
NOVCR( ::MessageBox( NULL, pMsg, "VCR Error", MB_OK ) );
#endif
}
Expand Down Expand Up @@ -950,7 +950,7 @@ bool GrabSourceMutex()

#ifdef ANDROID
return true;
#elif defined (LINUX) || defined(BSD)
#elif defined (LINUX) || defined(PLATFORM_BSD)
/*
* Linux
*/
Expand Down Expand Up @@ -1198,7 +1198,7 @@ DLL_EXPORT int LauncherMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
DLL_EXPORT int LauncherMain( int argc, char **argv )
#endif
{
#if (defined(LINUX) || defined(BSD)) && !defined ANDROID
#if (defined(LINUX) || defined(PLATFORM_BSD)) && !defined ANDROID
// Temporary fix to stop us from crashing in printf/sscanf functions that don't expect
// localization to mess with your "." and "," float seperators. Mac OSX also sets LANG
// to en_US.UTF-8 before starting up (in info.plist I believe).
Expand All @@ -1225,7 +1225,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv )
Msg("SDL version: %d.%d.%d rev: %s\n", (int)ver.major, (int)ver.minor, (int)ver.patch, SDL_GetRevision());
#endif

#if (defined LINUX || defined BSD) && defined USE_SDL && defined TOGLES && !defined ANDROID
#if (defined LINUX || defined PLATFORM_BSD) && defined USE_SDL && defined TOGLES && !defined ANDROID
SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1");
#endif

Expand Down Expand Up @@ -1553,7 +1553,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv )
RegCloseKey(hKey);
}

#elif defined( OSX ) || defined( LINUX ) || defined(BSD)
#elif defined( OSX ) || defined( LINUX ) || defined(PLATFORM_BSD)
struct stat st;
if ( stat( RELAUNCH_FILE, &st ) == 0 )
{
Expand All @@ -1570,7 +1570,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv )
}
szCmd[nChars] = 0;
char szOpenLine[ MAX_PATH ];
#if defined( LINUX ) || defined(BSD)
#if defined( LINUX ) || defined(PLATFORM_BSD)
Q_snprintf( szOpenLine, sizeof(szOpenLine), "xdg-open \"%s\"", szCmd );
#else
Q_snprintf( szOpenLine, sizeof(szOpenLine), "open \"%s\"", szCmd );
Expand Down
2 changes: 0 additions & 2 deletions launcher/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def build(bld):

if bld.env.DEST_OS == 'win32':
libs += ['USER32', 'OLE32', 'SHELL32']
elif bld.env.DEST_OS == 'darwin':
libs += ['FOUNDATION', 'APPKIT', 'IOKIT']

install_path = bld.env.LIBDIR

Expand Down
Loading

0 comments on commit 2fb712a

Please sign in to comment.