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.
This commit is contained in:
Yamagi Burmeister 2012-09-14 11:21:02 +02:00
parent dd6ed24104
commit ba10009aa5
14 changed files with 160 additions and 23 deletions

110
Makefile
View file

@ -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
# ----------

View file

@ -31,8 +31,12 @@
#ifndef _QAL_API_H_
#define _QAL_API_H_
#if defined (__APPLE__)
#include <OpenAL/al.h>
#else
#include <AL/al.h>
#include <AL/efx.h>
#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

View file

@ -31,7 +31,11 @@
#include <windows.h>
#endif
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#ifndef APIENTRY
#define APIENTRY

View file

@ -32,9 +32,14 @@
#ifdef USE_OPENAL
#if defined (__APPLE__)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
#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:");

View file

@ -31,6 +31,8 @@
#ifdef _WIN32
#include "SDL/SDL.h"
#elif defined(__APPLE__)
#include <SDL/SDL.h>
#else
#include "SDL.h"
#endif

View file

@ -31,6 +31,8 @@
#ifdef _WIN32
#include <SDL/SDL.h>
#elif defined(__APPLE__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

View file

@ -27,10 +27,16 @@
#include "../../refresh/header/local.h"
#include "../generic/header/glwindow.h"
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#ifdef _WIN32
#include <SDL/SDL.h>
#elif defined(__APPLE__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

View file

@ -32,6 +32,8 @@
#ifdef _WIN32
#include <SDL/SDL.h>
#elif defined(__APPLE__)
#include <SDL/SDL.h>
#else
#include <SDL.h>
#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

View file

@ -41,6 +41,11 @@
#define MAP_ANONYMOUS MAP_ANON
#endif
#if defined(__APPLE__)
#include <sys/types.h>
#define MAP_ANONYMOUS MAP_ANON
#endif
byte *membase;
int maxhunksize;
int curhunksize;

View file

@ -34,6 +34,10 @@
#include "../../common/header/common.h"
#include "header/unix.h"
#if defined(__APPLE__) && !defined(DEDICATED_ONLY)
#include <SDL/SDL.h>
#endif
int
main(int argc, char **argv)
{

View file

@ -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
}
}

View file

@ -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

View file

@ -36,8 +36,15 @@
#include <stdlib.h>
#include <time.h>
typedef unsigned char byte;
#if defined(__APPLE__)
#include <stdbool.h>
typedef bool qboolean;
#else
typedef enum {false, true} qboolean;
#endif
typedef unsigned char byte;
#ifndef NULL
#define NULL ((void *)0)

View file

@ -30,7 +30,12 @@
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "../../client/header/ref.h"
#include "../../backends/generic/header/qgl.h"