forked from ClassiCube/ClassiCube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
242 lines (208 loc) · 5.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
SOURCE_DIR := src
BUILD_DIR := build
C_SOURCES := $(wildcard $(SOURCE_DIR)/*.c)
C_OBJECTS := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES))
OBJECTS := $(C_OBJECTS)
ENAME = ClassiCube
CFLAGS = -g -pipe -fno-math-errno -Werror -Wno-error=missing-braces -Wno-error=strict-aliasing -Wno-error=maybe-uninitialized
LDFLAGS = -g -rdynamic
ifndef RM
# No prefined RM variable, try to guess OS default
ifeq ($(OS),Windows_NT)
RM = del
else
RM = rm -f
endif
endif
# Enables dependency tracking (https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/)
# This ensures that changing a .h file automatically results in the .c files using it being auto recompiled when next running make
# On older systems the required GCC options may not be supported - in which case just change TRACK_DEPENDENCIES to 0
TRACK_DEPENDENCIES=1
ifndef $(PLAT)
ifeq ($(OS),Windows_NT)
PLAT = mingw
else
PLAT = $(shell uname -s | tr '[:upper:]' '[:lower:]')
endif
endif
ifeq ($(PLAT),web)
CC = emcc
OEXT = .html
CFLAGS = -g
LDFLAGS = -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=1Mb --js-library $(SOURCE_DIR)/interop_web.js
endif
ifeq ($(PLAT),mingw)
CC = gcc
OEXT = .exe
CFLAGS += -DUNICODE
LDFLAGS = -g
LIBS = -mwindows -lwinmm -limagehlp
endif
ifeq ($(PLAT),linux)
CFLAGS += -DCC_BUILD_ICON
LIBS = -lX11 -lXi -lpthread -lGL -ldl
endif
ifeq ($(PLAT),sunos)
CFLAGS += -DCC_BUILD_ICON
LIBS = -lsocket -lX11 -lXi -lGL
endif
ifeq ($(PLAT),darwin)
OBJECTS += $(BUILD_DIR)/Window_cocoa.o
CFLAGS += -DCC_BUILD_ICON
LIBS =
LDFLAGS = -rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc
endif
ifeq ($(PLAT),freebsd)
CFLAGS += -I /usr/local/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),openbsd)
CFLAGS += -I /usr/X11R6/include -I /usr/local/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R6/lib -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),netbsd)
CFLAGS += -I /usr/X11R7/include -I /usr/pkg/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R7/lib -L /usr/pkg/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),dragonfly)
CFLAGS += -I /usr/local/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),haiku)
OBJECTS += $(BUILD_DIR)/Platform_BeOS.o $(BUILD_DIR)/Window_BeOS.o
CFLAGS = -g -pipe -fno-math-errno
LDFLAGS = -g
LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
endif
ifeq ($(PLAT),beos)
OBJECTS += $(BUILD_DIR)/Platform_BeOS.o $(BUILD_DIR)/Window_BeOS.o
CFLAGS = -g -pipe
LDFLAGS = -g
LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
TRACK_DEPENDENCIES=0
endif
ifeq ($(PLAT),serenityos)
LIBS = -lgl -lSDL2
endif
ifeq ($(PLAT),irix)
CC = gcc
LIBS = -lGL -lX11 -lXi -lpthread -ldl
endif
ifdef SDL2
CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_SDL2
LIBS += -lSDL2
endif
ifdef SDL3
CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_SDL3
LIBS += -lSDL3
endif
ifdef TERMINAL
CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_TERMINAL -DCC_GFX_BACKEND=CC_GFX_BACKEND_SOFTGPU
LIBS := $(subst mwindows,mconsole,$(LIBS))
endif
default: $(PLAT)
web:
$(MAKE) $(ENAME) PLAT=web
linux:
$(MAKE) $(ENAME) PLAT=linux
mingw:
$(MAKE) $(ENAME) PLAT=mingw
sunos:
$(MAKE) $(ENAME) PLAT=sunos
darwin:
$(MAKE) $(ENAME) PLAT=darwin
freebsd:
$(MAKE) $(ENAME) PLAT=freebsd
openbsd:
$(MAKE) $(ENAME) PLAT=openbsd
netbsd:
$(MAKE) $(ENAME) PLAT=netbsd
dragonfly:
$(MAKE) $(ENAME) PLAT=dragonfly
haiku:
$(MAKE) $(ENAME) PLAT=haiku
beos:
$(MAKE) $(ENAME) PLAT=beos
serenityos:
$(MAKE) $(ENAME) PLAT=serenityos
irix:
$(MAKE) $(ENAME) PLAT=irix
# Default overrides
sdl2:
$(MAKE) $(ENAME) SDL2=1
sdl3:
$(MAKE) $(ENAME) SDL3=1
terminal:
$(MAKE) $(ENAME) TERMINAL=1
# Some builds require more complex handling, so are moved to
# separate makefiles to avoid having one giant messy makefile
dreamcast:
$(MAKE) -f misc/dreamcast/Makefile
saturn:
$(MAKE) -f misc/saturn/Makefile
psp:
$(MAKE) -f misc/psp/Makefile
vita:
$(MAKE) -f misc/vita/Makefile
ps1:
cmake --preset default misc/ps1
cmake --build misc/ps1/build
ps2:
$(MAKE) -f misc/ps2/Makefile
ps3:
$(MAKE) -f misc/ps3/Makefile
xbox:
$(MAKE) -f misc/xbox/Makefile
xbox360:
$(MAKE) -f misc/xbox360/Makefile
n64:
$(MAKE) -f misc/n64/Makefile
ds:
$(MAKE) -f misc/ds/Makefile
3ds:
$(MAKE) -f misc/3ds/Makefile
gamecube:
$(MAKE) -f misc/gc/Makefile
wii:
$(MAKE) -f misc/wii/Makefile
wiiu:
$(MAKE) -f misc/wiiu/Makefile
switch:
$(MAKE) -f misc/switch/Makefile
os/2:
$(MAKE) -f misc/os2/Makefile
macclassic_68k:
$(MAKE) -f misc/macclassic/Makefile_68k
macclassic_ppc:
$(MAKE) -f misc/macclassic/Makefile_ppc
clean:
$(RM) $(OBJECTS)
$(ENAME): $(BUILD_DIR) $(OBJECTS)
$(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(EXTRA_LIBS) $(LIBS)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# === Compiling with dependency tracking ===
# NOTE: Tracking dependencies might not work on older systems - disable this if so
ifeq ($(TRACK_DEPENDENCIES), 1)
DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.d
DEPFILES := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.d, $(C_SOURCES))
$(DEPFILES):
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c $(BUILD_DIR)/%.d
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -c $< -o $@
include $(wildcard $(DEPFILES))
# === Compiling WITHOUT dependency tracking ===
else
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
endif
# === Platform specific file compiling ===
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.m
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
# EXTRA_CFLAGS and EXTRA_LIBS are not defined in the makefile intentionally -
# define them on the command line as a simple way of adding CFLAGS/LIBS