From ba10009aa5e7aca01c4610f1291e166b70e26b9b Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Fri, 14 Sep 2012 11:21:02 +0200 Subject: [PATCH] Add support for Mac OS X These are the code changes and Makefile changes necessary to build and run Yamagi Quake II on Max OS X. OS X 10.6 or higher is required, older version may work but we cannot guarantee it. The documentation will be added in another commit. This patch was contributed by W. Beser, I made only some small cosmetical changes. --- Makefile | 110 ++++++++++++++++++++++++------ src/backends/generic/header/qal.h | 6 ++ src/backends/generic/header/qgl.h | 4 ++ src/backends/generic/qal.c | 11 +++ src/backends/sdl/cd.c | 2 + src/backends/sdl/input.c | 2 + src/backends/sdl/refresh.c | 6 ++ src/backends/sdl/sound.c | 4 ++ src/backends/unix/hunk.c | 5 ++ src/backends/unix/main.c | 4 ++ src/client/sound/snd_al.c | 11 ++- src/common/header/common.h | 4 ++ src/common/header/shared.h | 9 ++- src/refresh/header/local.h | 5 ++ 14 files changed, 160 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index bb0a2eac..fe92cec5 100644 --- a/Makefile +++ b/Makefile @@ -34,18 +34,18 @@ WITH_OGG:=yes # Enables the optional OpenAL sound system. # To use it your system needs libopenal.so.1 -# or openal32.dll (we recommend openal-soft) +# or openal32.dll (we recommend openal-soft) # installed WITH_OPENAL:=yes -# Enables retexturing support. Adds +# Enables retexturing support. Adds # a dependency to libjpeg WITH_RETEXTURING:=yes # Set the gamma via X11 and not via SDL. This works # around problems in some SDL version. Adds dependencies # to pkg-config, libX11 and libXxf86vm. Unsupported on -# Windows. +# Windows and OS X. WITH_X11GAMMA:=no # Enables opening of ZIP files (also known as .pk3 paks). @@ -55,11 +55,25 @@ WITH_ZIP:=yes # Enable systemwide installation of game assets WITH_SYSTEMWIDE:=no -# This will set the default SYSTEMDIR, a non-empty string +# This will set the default SYSTEMDIR, a non-empty string # would actually be used. On Windows normals slashes (/) # instead of backslashed (\) should be used! WITH_SYSTEMDIR:= +# This will set the architectures of the OSX-binaries. +# You have to make sure your libs/frameworks supports +# these architectures to build an universal ppc-compatible +# one would add -arch ppc for example, but I did not tested +# it! +OSX_ARCH := -arch i386 -arch x86_64 + +# This will set the build options to create an MacOS .app-bundle. +# The app-bundle itself will not be created, but the runtime paths +# will be set to expect the linked Frameworks in *.app/Contents/ +# Frameworks and the game-data will be expected in # *.app/ +# Contents/Resources +OSX_APP := no + # ====================================================== # # !!! DO NOT ALTER ANYTHING BELOW THIS LINE !!! # # ====================================================== # @@ -75,8 +89,8 @@ endif ifeq ($(OSTYPE), Windows) # At this time only i386 is supported on Windows # (amd64 works, but building an 64 bit executable -# is not that easy. Especially SDL and OpenAL are -# somewhat problematic) +# is not that easy. Especially SDL and OpenAL are +# somewhat problematic) ARCH := i386 else # Some platforms call it "amd64" and some "x86_64" @@ -106,9 +120,16 @@ endif # CHANGE THIS, since it's our only chance to debug this # crap when random crashes happen! # -# -MMD to generate header dependencies. +# -MMD to generate header dependencies. (They cannot be +# generated if building universal binaries on OSX) +ifeq ($(OSTYPE), Darwin) +CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ + -Wall -pipe -g +CFLAGS += $(OSX_ARCH) +else CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ -Wall -pipe -g -MMD +endif # ---------- @@ -124,18 +145,24 @@ endif # Extra CFLAGS for SDL ifneq ($(OSTYPE), Windows) -SDLCFLAGS := $(shell sdl-config --cflags) + ifeq ($(OSTYPE), Darwin) + SDLCFLAGS := + else + SDLCFLAGS := $(shell sdl-config --cflags) + endif endif # ---------- # Extra CFLAGS for X11 ifneq ($(OSTYPE), Windows) +ifneq ($(OSTYPE), Darwin) ifeq ($(WITH_X11GAMMA),yes) X11CFLAGS := $(shell pkg-config x11 --cflags) X11CFLAGS += $(shell pkg-config xxf86vm --cflags) endif endif +endif # ---------- @@ -146,6 +173,8 @@ else ifeq ($(OSTYPE),FreeBSD) INCLUDE := -I/usr/local/include else ifeq ($(OSTYPE),OpenBSD) INCLUDE := -I/usr/local/include +else ifeq ($(OSTYPE),Darwin) +INCLUDE := endif # ---------- @@ -159,6 +188,8 @@ else ifeq ($(OSTYPE),OpenBSD) LDFLAGS := -L/usr/local/lib -lm else ifeq ($(OSTYPE),Windows) LDFLAGS := -lws2_32 -lwinmm +else ifeq ($(OSTYPE), Darwin) +LDFLAGS := $(OSX_ARCH) -lm endif # ---------- @@ -166,6 +197,8 @@ endif # Extra LDFLAGS for SDL ifeq ($(OSTYPE), Windows) SDLLDFLAGS := -lSDL +else ifeq ($(OSTYPE), Darwin) +SDLLDFLAGS := -framework SDL -framework OpenGL -framework Cocoa else SDLLDFLAGS := $(shell sdl-config --libs) endif @@ -174,11 +207,13 @@ endif # Extra LDFLAGS for X11 ifneq ($(OSTYPE), Windows) +ifneq ($(OSTYPE), Darwin) ifeq ($(WITH_X11GAMMA),yes) X11LDFLAGS := $(shell pkg-config x11 --libs) X11LDFLAGS += $(shell pkg-config xxf86vm --libs) endif endif +endif # ---------- @@ -218,7 +253,7 @@ endif ifeq ($(OSTYPE), Windows) clean: @echo "===> CLEAN" - @-rmdir /S /Q release build + @-rmdir /S /Q release build else clean: @echo "===> CLEAN" @@ -269,18 +304,32 @@ build/client/%.o: %.c ${Q}mkdir -p $(@D) ${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(INCLUDE) -o $@ $< +ifeq ($(OSTYPE), Darwin) +build/client/%.o : %.m + @echo "===> CC $<" + ${Q}mkdir -p $(@D) + ${Q}$(CC) $(OSX_ARCH) $(USE_APP_RESOURCES) -x objective-c -c $< -o $@ +endif + ifeq ($(WITH_CDA),yes) release/quake2 : CFLAGS += -DCDA endif ifeq ($(WITH_OGG),yes) release/quake2 : CFLAGS += -DOGG +ifeq ($(OSTYPE), Darwin) +release/quake2 : LDFLAGS += -framework Vorbis -framework Ogg +else release/quake2 : LDFLAGS += -lvorbis -lvorbisfile -logg endif +endif ifeq ($(WITH_OPENAL),yes) ifeq ($(OSTYPE), OpenBSD) release/quake2 : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"libopenal.so"' +else ifeq ($(OSTYPE), Darwin) +release/quake2 : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"/System/Library/Frameworks/OpenAL.framework/OpenAL"' +release/quake2 : LDFLAGS += -framework OpenAL else release/quake2 : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"libopenal.so.1"' endif @@ -291,7 +340,14 @@ release/quake2 : CFLAGS += -DZIP -DNOUNCRYPT release/quake2 : LDFLAGS += -lz endif endif - + +ifeq ($(OSTYPE), Darwin) +ifeq ($(OSX_APP), yes) +release/quake2 : USE_APP_RESOURCES = -DUSE_APP_RESOURCES +release/quake2 : LDFLAGS += -Xlinker -rpath -Xlinker @loader_path/../Frameworks +endif +endif + # ---------- # The server @@ -310,7 +366,7 @@ release/q2ded.exe : CFLAGS += -DDEDICATED_ONLY release/q2ded.exe : LDFLAGS += -lz ifeq ($(WITH_ZIP),yes) -release/q2ded.exe : CFLAGS += -DZIP -DNOUNCRYPT +release/q2ded.exe : CFLAGS += -DZIP -DNOUNCRYPT release/q2ded.exe : LDFLAGS += -lz endif else @@ -322,10 +378,9 @@ server: build/server/%.o: %.c @echo "===> CC $<" ${Q}mkdir -p $(@D) - ${Q}$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< + ${Q}$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< release/q2ded : CFLAGS += -DDEDICATED_ONLY -release/q2ded : LDFLAGS += -lz ifeq ($(WITH_ZIP),yes) release/q2ded : CFLAGS += -DZIP -DNOUNCRYPT @@ -372,11 +427,16 @@ release/ref_gl.so : CFLAGS += -DX11GAMMA endif ifeq ($(WITH_RETEXTURING),yes) -release/ref_gl.so : CFLAGS += -DRETEXTURE -release/ref_gl.so : LDFLAGS += -ljpeg + release/ref_gl.so : CFLAGS += -DRETEXTURE + ifeq ($(OSTYPE), Darwin) + release/ref_gl.so : LDFLAGS += -framework libjpeg + else + release/ref_gl.so : LDFLAGS += -ljpeg + endif endif + endif - + # ---------- # The baseq2 game @@ -406,7 +466,7 @@ build/baseq2/%.o: %.c release/baseq2/game.so : CFLAGS += -fPIC release/baseq2/game.so : LDFLAGS += -shared endif - + # ---------- # Used by the game @@ -539,6 +599,10 @@ CLIENT_OBJS_ += \ src/backends/unix/system.o endif +ifeq ($(OSTYPE), Darwin) +CLIENT_OBJS_ += src/backends/sdl_osx/SDLMain.o +endif + # ---------- # Used by the server @@ -577,7 +641,7 @@ ifeq ($(OSTYPE), Windows) SERVER_OBJS_ += \ src/backends/windows/mem.o \ src/backends/windows/network.o \ - src/backends/windows/system.o + src/backends/windows/system.o else SERVER_OBJS_ += \ src/backends/unix/hunk.o \ @@ -658,7 +722,7 @@ release/quake2 : $(CLIENT_OBJS) @echo "===> LD $@" ${Q}$(CC) $(CLIENT_OBJS) $(LDFLAGS) $(SDLLDFLAGS) -o $@ endif - + # release/q2ded ifeq ($(OSTYPE), Windows) release/q2ded.exe : $(SERVER_OBJS) icon @@ -675,12 +739,16 @@ ifeq ($(OSTYPE), Windows) release/ref_gl.dll : $(OPENGL_OBJS) @echo "===> LD $@" ${Q}$(CC) $(OPENGL_OBJS) $(LDFLAGS) $(SDLLDFLAGS) -o $@ +else ifeq ($(OSTYPE), Darwin) +release/ref_gl.so : $(OPENGL_OBJS) + @echo "===> LD $@" + ${Q}$(CC) $(OPENGL_OBJS) $(LDFLAGS) $(SDLLDFLAGS) -o $@ else release/ref_gl.so : $(OPENGL_OBJS) @echo "===> LD $@" ${Q}$(CC) $(OPENGL_OBJS) $(LDFLAGS) $(X11LDFLAGS) -o $@ endif - + # release/baseq2/game.so ifeq ($(OSTYPE), Windows) release/baseq2/game.dll : $(GAME_OBJS) @@ -691,5 +759,5 @@ release/baseq2/game.so : $(GAME_OBJS) @echo "===> LD $@" ${Q}$(CC) $(GAME_OBJS) $(LDFLAGS) -o $@ endif - + # ---------- diff --git a/src/backends/generic/header/qal.h b/src/backends/generic/header/qal.h index 7c6616b1..de1a3437 100644 --- a/src/backends/generic/header/qal.h +++ b/src/backends/generic/header/qal.h @@ -31,8 +31,12 @@ #ifndef _QAL_API_H_ #define _QAL_API_H_ + #if defined (__APPLE__) + #include + #else #include #include + #endif /* Function pointers used to tie * the qal API to the OpenAL API */ @@ -109,10 +113,12 @@ extern LPALDOPPLERFACTOR qalDopplerFactor; extern LPALDOPPLERVELOCITY qalDopplerVelocity; extern LPALSPEEDOFSOUND qalSpeedOfSound; extern LPALDISTANCEMODEL qalDistanceModel; +#if !defined (__APPLE__) extern LPALGENFILTERS qalGenFilters; extern LPALFILTERI qalFilteri; extern LPALFILTERF qalFilterf; extern LPALDELETEFILTERS qalDeleteFilters; +#endif /* * Gives information over the OpenAL diff --git a/src/backends/generic/header/qgl.h b/src/backends/generic/header/qgl.h index 5b781b82..0ef3672a 100644 --- a/src/backends/generic/header/qgl.h +++ b/src/backends/generic/header/qgl.h @@ -31,7 +31,11 @@ #include #endif +#if defined(__APPLE__) +#include +#else #include +#endif #ifndef APIENTRY #define APIENTRY diff --git a/src/backends/generic/qal.c b/src/backends/generic/qal.c index b3b1e666..49f213d4 100644 --- a/src/backends/generic/qal.c +++ b/src/backends/generic/qal.c @@ -32,9 +32,14 @@ #ifdef USE_OPENAL +#if defined (__APPLE__) +#include +#include +#else #include #include #include +#endif #include "../../common/header/common.h" #include "header/qal.h" @@ -142,10 +147,12 @@ LPALDOPPLERFACTOR qalDopplerFactor; LPALDOPPLERVELOCITY qalDopplerVelocity; LPALSPEEDOFSOUND qalSpeedOfSound; LPALDISTANCEMODEL qalDistanceModel; +#if !defined (__APPLE__) LPALGENFILTERS qalGenFilters; LPALFILTERI qalFilteri; LPALFILTERF qalFilterf; LPALDELETEFILTERS qalDeleteFilters; +#endif /* * Gives information over the OpenAL @@ -316,10 +323,12 @@ QAL_Shutdown() qalDopplerVelocity = NULL; qalSpeedOfSound = NULL; qalDistanceModel = NULL; +#if !defined (__APPLE__) qalGenFilters = NULL; qalFilteri = NULL; qalFilterf = NULL; qalDeleteFilters = NULL; +#endif /* Unload the shared lib */ Sys_FreeLibrary(handle); @@ -445,10 +454,12 @@ QAL_Init() qalDopplerVelocity = Sys_GetProcAddress(handle, "alDopplerVelocity"); qalSpeedOfSound = Sys_GetProcAddress(handle, "alSpeedOfSound"); qalDistanceModel = Sys_GetProcAddress(handle, "alDistanceModel"); +#if !defined (__APPLE__) qalGenFilters = Sys_GetProcAddress(handle, "alGenFilters"); qalFilteri = Sys_GetProcAddress(handle, "alFilteri"); qalFilterf = Sys_GetProcAddress(handle, "alFilterf"); qalDeleteFilters = Sys_GetProcAddress(handle, "alDeleteFilters"); +#endif /* Open the OpenAL device */ Com_Printf("...opening OpenAL device:"); diff --git a/src/backends/sdl/cd.c b/src/backends/sdl/cd.c index b55c2361..094789e2 100644 --- a/src/backends/sdl/cd.c +++ b/src/backends/sdl/cd.c @@ -31,6 +31,8 @@ #ifdef _WIN32 #include "SDL/SDL.h" +#elif defined(__APPLE__) + #include #else #include "SDL.h" #endif diff --git a/src/backends/sdl/input.c b/src/backends/sdl/input.c index 1170480d..e63ea264 100644 --- a/src/backends/sdl/input.c +++ b/src/backends/sdl/input.c @@ -31,6 +31,8 @@ #ifdef _WIN32 #include +#elif defined(__APPLE__) +#include #else #include #endif diff --git a/src/backends/sdl/refresh.c b/src/backends/sdl/refresh.c index 828b39f8..58ddd3a1 100644 --- a/src/backends/sdl/refresh.c +++ b/src/backends/sdl/refresh.c @@ -27,10 +27,16 @@ #include "../../refresh/header/local.h" #include "../generic/header/glwindow.h" +#if defined(__APPLE__) +#include +#else #include +#endif #ifdef _WIN32 #include +#elif defined(__APPLE__) +#include #else #include #endif diff --git a/src/backends/sdl/sound.c b/src/backends/sdl/sound.c index defebf4b..04788ae6 100644 --- a/src/backends/sdl/sound.c +++ b/src/backends/sdl/sound.c @@ -32,6 +32,8 @@ #ifdef _WIN32 #include +#elif defined(__APPLE__) +#include #else #include #endif @@ -122,6 +124,8 @@ SNDDMA_Init(void) s_sdldriver = (Cvar_Get("s_sdldriver", "dsound", CVAR_ARCHIVE)); #elif __linux__ s_sdldriver = (Cvar_Get("s_sdldriver", "alsa", CVAR_ARCHIVE)); +#elif __APPLE__ + s_sdldriver = (Cvar_Get("s_sdldriver", "CoreAudio", CVAR_ARCHIVE)); #else s_sdldriver = (Cvar_Get("s_sdldriver", "dsp", CVAR_ARCHIVE)); #endif diff --git a/src/backends/unix/hunk.c b/src/backends/unix/hunk.c index cc623f16..6067b11a 100644 --- a/src/backends/unix/hunk.c +++ b/src/backends/unix/hunk.c @@ -41,6 +41,11 @@ #define MAP_ANONYMOUS MAP_ANON #endif +#if defined(__APPLE__) + #include + #define MAP_ANONYMOUS MAP_ANON +#endif + byte *membase; int maxhunksize; int curhunksize; diff --git a/src/backends/unix/main.c b/src/backends/unix/main.c index 4d9871fa..6da1a15f 100644 --- a/src/backends/unix/main.c +++ b/src/backends/unix/main.c @@ -34,6 +34,10 @@ #include "../../common/header/common.h" #include "header/unix.h" +#if defined(__APPLE__) && !defined(DEDICATED_ONLY) +#include +#endif + int main(int argc, char **argv) { diff --git a/src/client/sound/snd_al.c b/src/client/sound/snd_al.c index 71924223..b702c8ea 100644 --- a/src/client/sound/snd_al.c +++ b/src/client/sound/snd_al.c @@ -74,6 +74,9 @@ AL_InitStreamSource() static void AL_InitUnderwaterFilter() { +#if defined (__APPLE__) + return; +#else /* Generate a filter */ qalGenFilters(1, &underwaterFilter); @@ -95,6 +98,7 @@ AL_InitUnderwaterFilter() /* The effect */ qalFilterf(underwaterFilter, AL_LOWPASS_GAIN, 1.5); qalFilterf(underwaterFilter, AL_LOWPASS_GAINHF, 0.25); +#endif } qboolean @@ -166,8 +170,9 @@ AL_Shutdown(void) S_AL_StreamDie(); qalDeleteSources(1, &streamSource); +#if !defined (__APPLE__) qalDeleteFilters(1, &underwaterFilter); - +#endif if (s_numchannels) { /* delete source names */ @@ -537,7 +542,9 @@ AL_Underwater() /* Apply to all sources */ for (i = 0; i < s_numchannels; i++) { +#if !defined (__APPLE__) qalSourcei(s_srcnums[i], AL_DIRECT_FILTER, underwaterFilter); +#endif } } @@ -554,7 +561,9 @@ AL_Overwater() /* Apply to all sources */ for (i = 0; i < s_numchannels; i++) { +#if !defined (__APPLE__) qalSourcei(s_srcnums[i], AL_DIRECT_FILTER, 0); +#endif } } diff --git a/src/common/header/common.h b/src/common/header/common.h index e7d52f86..246abd2e 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -45,6 +45,8 @@ #define BUILDSTRING "OpenBSD" #elif defined _WIN32 #define BUILDSTRING "Windows" +#elif defined __APPLE__ + #define BUILDSTRING "MacOS X" #else #define BUILDSTRING "Unknown" #endif @@ -69,6 +71,8 @@ #define LIBGL "opengl32.dll" #elif defined __OpenBSD__ #define LIBGL "libGL.so" +#elif defined __APPLE__ + #define LIBGL "/System/Library/Frameworks/OpenGL.framework/OpenGL" #else #define LIBGL "libGL.so.1" #endif diff --git a/src/common/header/shared.h b/src/common/header/shared.h index 2e5da573..fe9aa06a 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -36,8 +36,15 @@ #include #include -typedef unsigned char byte; + +#if defined(__APPLE__) +#include +typedef bool qboolean; +#else typedef enum {false, true} qboolean; +#endif + +typedef unsigned char byte; #ifndef NULL #define NULL ((void *)0) diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index 2c31e92d..07a0828e 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -30,7 +30,12 @@ #include #include #include + +#if defined(__APPLE__) +#include +#else #include +#endif #include "../../client/header/ref.h" #include "../../backends/generic/header/qgl.h"