Skip to content

Commit 1f98665

Browse files
committed
rationalise makefile-based compiling on macOS, outside of Xcode
The makefile will give you a Gtk-capable build, using Xcode will give the full macOS experience.
1 parent 90749d6 commit 1f98665

File tree

13 files changed

+57
-45
lines changed

13 files changed

+57
-45
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ ifeq ($(PLATFORM),WINDOWS)
140140
OURLDFLAGS+= -lm
141141
endif
142142
ifeq ($(PLATFORM),DARWIN)
143-
OURLDFLAGS+= -framework AppKit
144-
145143
ENGINEOBJS+= $(SRC)/osxbits.$o
146-
EDITOROBJS+= $(SRC)/EditorStartupWinController.$o
147144
endif
148145

149146
# Select the system layer
@@ -157,6 +154,8 @@ ifeq ($(RENDERTYPE),SDL)
157154
OURLDFLAGS+= $(GTKCONFIG_LIBS)
158155
ENGINEOBJS+= $(SRC)/gtkbits.$o
159156
EDITOROBJS+= $(SRC)/startgtk_editor.$o
157+
else
158+
ENGINEOBJS+= $(SRC)/startwin_stub.$o
160159
endif
161160
endif
162161
ifeq ($(RENDERTYPE),WIN)
@@ -253,7 +252,7 @@ kenbuild:
253252
RELEASE=$(RELEASE)
254253

255254
clean:
256-
-rm -f $(ENGINEOBJS) $(EDITOROBJS)
255+
-rm -f $(ENGINEOBJS) $(EDITOROBJS) $(TOOLS)/*.$o
257256
-$(MAKE) -C kenbuild -f Makefile clean
258257

259258
veryclean: clean

Makefile.deps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ $(LIBSQUISH)/squish.$o: $(LIBSQUISH)/squish.cpp $(LIBSQUISH)/squish.h $(LIBSQUIS
4646

4747
$(SRC)/startgtk_editor.$o: $(SRC)/startgtk_editor.c $(INC)/compat.h $(INC)/baselayer.h $(INC)/build.h $(INC)/compat.h $(INC)/editor.h
4848
$(SRC)/startwin_editor.$o: $(SRC)/startwin_editor.c $(INC)/build.h $(INC)/editor.h $(INC)/winlayer.h $(INC)/compat.h $(INC)/buildres.h
49+
$(SRC)/startwin_stub.$o: $(SRC)/startwin_stub.c
4950

5051
# Derived source files from shader files
5152
$(SRC)/glbuild_fs.c: $(SRC)/glbuild_fs.glsl

kenbuild/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ EDITOREXEOBJS=$(SRC)/bstub.$o
6666

6767
# Specialise for the platform
6868
ifeq ($(PLATFORM),DARWIN)
69-
GAMEEXEOBJS+= $(SRC)/StartupWinController.$o
70-
GAMELDFLAGS+= -framework AppKit
69+
GAMELDFLAGS+= -framework Foundation
7170
endif
7271

7372
# Select the system layer

kenbuild/src/game.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,11 @@ static int osdcmd_map(const osdfuncparm_t *parm) {
408408
return OSDCMD_OK;
409409
}
410410

411-
#if defined RENDERTYPEWIN || (defined RENDERTYPESDL && (defined __APPLE__ || defined HAVE_GTK))
411+
#if defined(RENDERTYPEWIN)
412+
# define HAVE_STARTWIN
413+
#elif defined(RENDERTYPESDL) && defined(__APPLE__) && defined(HAVE_OSX_FRAMEWORKS)
414+
# define HAVE_STARTWIN
415+
#elif defined(RENDERTYPESDL) && defined(HAVE_GTK)
412416
# define HAVE_STARTWIN
413417
#endif
414418

kenbuild/src/kdmsound_sdl2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This file has been modified from Ken Silverman's original release
55
// by Jonathon Fowler (jf@jonof.id.au)
66

7-
#if defined __APPLE__
7+
#if defined(__APPLE__) && defined(HAVE_OSX_FRAMEWORKS)
88
# include <SDL2/SDL.h>
99
#else
1010
# include "SDL.h"

src/build.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ static int osdcmd_showspriteextents(const osdfuncparm_t *parm)
232232
return OSDCMD_OK;
233233
}
234234

235-
#if defined RENDERTYPEWIN || (defined RENDERTYPESDL && (defined __APPLE__ || defined HAVE_GTK))
235+
#if defined(RENDERTYPEWIN)
236+
# define HAVE_STARTWIN
237+
#elif defined(RENDERTYPESDL) && defined(__APPLE__) && defined(HAVE_OSX_FRAMEWORKS)
238+
# define HAVE_STARTWIN
239+
#elif defined(RENDERTYPESDL) && defined(HAVE_GTK)
236240
# define HAVE_STARTWIN
237241
#endif
238242

src/compat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ char *Bgethomedir(void)
9494
dir = strdup(appdata);
9595
}
9696

97-
#elif defined __APPLE__
97+
#elif defined(__APPLE__)
9898
dir = osx_gethomedir();
9999

100100
#else
@@ -129,7 +129,7 @@ char *Bgetappdir(void)
129129
dir = strdup(appdir);
130130
}
131131

132-
#elif defined __APPLE__
132+
#elif defined(__APPLE__)
133133
dir = osx_getappdir();
134134

135135
#elif defined(__linux) || defined(__NetBSD__) || defined(__OpenBSD__)

src/osxbits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ char *osx_gethomedir(void);
55
char *osx_getappdir(void);
66
char *osx_getsupportdir(int global);
77

8+
#ifdef HAVE_OSX_FRAMEWORKS
89
int wmosx_filechooser(const char *initialdir, const char *initialfile, const char *type, int foropen, char **choice);
10+
#endif
911

1012
#endif

src/osxbits.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "osxbits.h"
2-
#import <AppKit/AppKit.h>
32
#import <Foundation/Foundation.h>
43

54
char *osx_gethomedir(void)
@@ -37,6 +36,9 @@
3736
return NULL;
3837
}
3938

39+
#ifdef HAVE_OSX_FRAMEWORKS
40+
#import <AppKit/AppKit.h>
41+
4042
int wmosx_filechooser(const char *initialdir, const char *initialfile, const char *type, int foropen, char **choice)
4143
{
4244
NSSavePanel *panel = nil;
@@ -71,3 +73,4 @@ int wmosx_filechooser(const char *initialdir, const char *initialfile, const cha
7173

7274
return resp == NSModalResponseOK ? 1 : 0;
7375
}
76+
#endif

src/sdlayer2.c

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "build.h"
88

9-
#if defined __APPLE__
9+
#if defined(__APPLE__) && defined(HAVE_OSX_FRAMEWORKS)
1010
# include <SDL2/SDL.h>
1111
#else
1212
# include "SDL.h"
@@ -29,14 +29,9 @@
2929

3030
#if defined(__APPLE__)
3131
# include "osxbits.h"
32-
#elif defined(HAVE_GTK)
32+
#endif
33+
#if defined(HAVE_GTK)
3334
# include "gtkbits.h"
34-
#else
35-
int startwin_open(void) { return 0; }
36-
int startwin_close(void) { return 0; }
37-
int startwin_puts(const char *s) { (void)s; return 0; }
38-
int startwin_idle(void *s) { (void)s; return 0; }
39-
int startwin_settitle(const char *s) { (void)s; return 0; }
4035
#endif
4136

4237
static int backgroundidle = 0;
@@ -48,6 +43,7 @@ static SDL_Window *sdl_window;
4843
static SDL_Renderer *sdl_renderer; // For non-GL 8-bit mode output.
4944
static SDL_Texture *sdl_texture; // For non-GL 8-bit mode output.
5045
static SDL_Surface *sdl_surface; // For non-GL 8-bit mode output.
46+
static SDL_Surface *sdl_appicon;
5147
static int usesdlrenderer = 0;
5248
static unsigned char *frame;
5349
static float curshadergamma = 1.f, cursysgamma = -1.f;
@@ -84,9 +80,7 @@ static int buildkeytranslationtable(void);
8480
static void enumdisplays(void);
8581
static void shutdownvideo(void);
8682

87-
#ifndef __APPLE__
88-
static SDL_Surface * loadappicon(void);
89-
#endif
83+
static void loadappicon(void);
9084

9185
int wm_msgbox(const char *name, const char *fmt, ...)
9286
{
@@ -107,7 +101,7 @@ int wm_msgbox(const char *name, const char *fmt, ...)
107101
do {
108102
rv = 0;
109103

110-
#if defined HAVE_GTK
104+
#if defined(HAVE_GTK)
111105
if (wmgtk_msgbox(name, buf) >= 0) {
112106
rv = 1;
113107
break;
@@ -159,7 +153,7 @@ int wm_ynbox(const char *name, const char *fmt, ...)
159153
do {
160154
rv = 0;
161155

162-
#if defined HAVE_GTK
156+
#if defined(HAVE_GTK)
163157
if ((rv = wmgtk_ynbox(name, buf)) >= 0) {
164158
break;
165159
}
@@ -181,14 +175,14 @@ int wm_ynbox(const char *name, const char *fmt, ...)
181175

182176
int wm_filechooser(const char *initialdir, const char *initialfile, const char *type, int foropen, char **choice)
183177
{
184-
#if defined __APPLE__ || defined HAVE_GTK
178+
#if (defined(__APPLE__) && defined(HAVE_OSX_FRAMEWORKS)) || defined(HAVE_GTK)
185179
int rv;
186180
if (mouseacquired && moustat) {
187181
SDL_SetRelativeMouseMode(SDL_FALSE);
188182
}
189-
#if defined __APPLE__
183+
#if defined(__APPLE__) && defined(HAVE_OSX_FRAMEWORKS)
190184
rv = wmosx_filechooser(initialdir, initialfile, type, foropen, choice);
191-
#elif defined HAVE_GTK
185+
#elif defined(HAVE_GTK)
192186
rv = wmgtk_filechooser(initialdir, initialfile, type, foropen, choice);
193187
#endif
194188
SDL_RaiseWindow(sdl_window);
@@ -204,7 +198,7 @@ int wm_filechooser(const char *initialdir, const char *initialfile, const char *
204198

205199
int wm_idle(void *ptr)
206200
{
207-
#if defined HAVE_GTK
201+
#if defined(HAVE_GTK)
208202
return wmgtk_idle(ptr);
209203
#else
210204
(void)ptr;
@@ -295,8 +289,12 @@ int main(int argc, char *argv[])
295289
// This avoids doubled character input in the (OSX) startup window's edit fields.
296290
SDL_EventState(SDL_TEXTINPUT, SDL_IGNORE);
297291

292+
loadappicon();
293+
298294
r = app_main(_buildargc, (char const * const*)_buildargv);
299295

296+
if (sdl_appicon) SDL_FreeSurface(sdl_appicon);
297+
300298
#ifdef __APPLE__
301299
free(_buildargv);
302300
#endif
@@ -903,13 +901,7 @@ int setvideomode(int xdim, int ydim, int bitspp, int fullsc)
903901
break;
904902
} while (1);
905903

906-
#ifndef __APPLE__
907-
{
908-
SDL_Surface *icon = loadappicon();
909-
SDL_SetWindowIcon(sdl_window, icon);
910-
SDL_FreeSurface(icon);
911-
}
912-
#endif
904+
if (sdl_appicon) SDL_SetWindowIcon(sdl_window, sdl_appicon);
913905

914906
if (bitspp == 8) {
915907
int i, j, pitch;
@@ -1229,19 +1221,19 @@ void *getglprocaddress(const char *name, int ext)
12291221
#endif
12301222

12311223

1232-
#ifndef __APPLE__
1233-
extern struct sdlappicon sdlappicon;
1234-
static SDL_Surface * loadappicon(void)
1224+
static void loadappicon(void)
12351225
{
1236-
SDL_Surface *surf;
1226+
#if !defined(__APPLE__) || (defined(__APPLE__) && !defined(HAVE_OSX_FRAMEWORKS))
1227+
extern struct sdlappicon sdlappicon;
12371228

1238-
surf = SDL_CreateRGBSurfaceFrom((void*)sdlappicon.pixels,
1229+
sdl_appicon = SDL_CreateRGBSurfaceFrom((void*)sdlappicon.pixels,
12391230
sdlappicon.width, sdlappicon.height, 32, sdlappicon.width*4,
12401231
0xffl,0xff00l,0xff0000l,0xff000000l);
1241-
1242-
return surf;
1243-
}
1232+
if (!sdl_appicon) {
1233+
debugprintf("loadappicon: error creating appicon surface: %s\n", SDL_GetError());
1234+
}
12441235
#endif
1236+
}
12451237

12461238
//
12471239
//

0 commit comments

Comments
 (0)