-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathMakefile
More file actions
419 lines (348 loc) · 12.7 KB
/
Makefile
File metadata and controls
419 lines (348 loc) · 12.7 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# CUSTOM ARGS :
# WAYLAND=1 -> use wayland
# WAYLAND_X11=1 -> use wayland AND X11
# NO_VULKAN=1 -> do not compile the vulkan example
# NO_GLES=1 -> do not compile the gles example (on by default for non-linux OSes)
# NO_OSMESA=1 -> do not compile the osmesa example (on by default for non-linux OSes)
CC ?= gcc
AR ?= ar
# used for compiling RGFW.o
CUSTOM_CFLAGS =
# used for the examples
CFLAGS =
CFLAGS += -g3
ifdef RGFW_C89
CUSTOM_CFLAGS += -std=c89 -Wno-declaration-after-statement -Wall -Wextra -Wpedantic
endif
DX11_LIBS = -static -lgdi32 -ldxgi -ld3d11 -luuid -ld3dcompiler
VULKAN_LIBS = -lgdi32 -I $(VULKAN_SDK)\Include -L $(VULKAN_SDK)\Lib -lvulkan-1
LIBS := -static -lgdi32
LINK_GL1 = -lopengl32
EXT = .exe
LIB_EXT = .dll
ifneq ($(CC),zig cc)
LIBS += -D _WIN32_WINNT=0x0501
endif
OS_DIR = \\
NO_OSMESA = 1
NO_GLES = 1
NO_EGL = 1
detected_OS = windows
OBJ_FILE = .o
ifeq ($(WAYLAND_ONLY), 1)
WAYLAND = 1
endif
ifeq ($(WAYLAND_X11), 1)
WAYLAND = 1
endif
# not using a cross compiler
ifeq (,$(filter $(CC),x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ /opt/msvc/bin/x64/cl.exe /opt/msvc/bin/x86/cl.exe))
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
ifeq ($(detected_OS),Darwin) # Mac OS X
DX11_LIBS =
LIBS := -framework CoreVideo -framework Cocoa -framework OpenGL -framework IOKit
LINK_GL1 = -framework OpenGL
VULKAN_LIBS = $(LIBS) -lvulkan
EXT =
LIB_EXT = .dylib
OS_DIR = /
NO_VULKAN ?= 1
endif
ifeq ($(detected_OS),Linux)
DX11_LIBS =
LINK_GL1 = -lGL
ifneq ($(WAYLAND_ONLY), 1)
LIBS = -lXrandr -lX11 -ldl -lpthread -lm
else
LIBS =
endif
VULKAN_LIBS = $(LIBS) -lvulkan
EXT =
LIB_EXT = .so
OS_DIR = /
NO_GLES = 0
NO_EGL = 0
endif
ifeq ($(detected_OS),NetBSD)
DX11_LIBS =
LINK_GL1 = -lGL
CUSTOM_CFLAGS += -I/usr/pkg/include -I/usr/X11R7/include -Wl,-R/usr/pkg/lib -Wl,-R/usr/X11R7/lib -L/usr/pkg/lib -L/usr/X11R7/lib
LIBS := $(CUSTOM_CFLAGS) -lXrandr -lX11 -lpthread -lm
VULKAN_LIBS = $(LIBS) -lvulkan
EXT =
LIB_EXT = .so
OS_DIR = /
NO_GLES = 0
NO_EGL = 0
NO_VULKAN = 1
endif
ifeq (,$(filter $(detected_OS),Linux Darwin NetBSD))
detected_OS := windows
endif
else
OS_DIR = /
endif
ifeq ($(WAYLAND),1)
WAYLAND_SOURCE = $(shell make -f wayland.mk sources -s)
NO_VULKAN = 1
NO_GLES = 0
NO_EGL = 0
LIBS += -D RGFW_WAYLAND $(WAYLAND_SOURCE) -lwayland-cursor -lwayland-client -lxkbcommon -lwayland-egl -lEGL -lm
LINK_GL1 = -lEGL -lGL
# LIBS += -ldecor-0
ifeq ($(WAYLAND_X11), 1)
LIBS += -D RGFW_X11
endif
endif
LINK_GL3 =
LINK_GL2 =
LINK_OSMESA =
ifneq (,$(filter $(CC),cl /opt/msvc/bin/x64/cl.exe /opt/msvc/bin/x86/cl.exe))
WARNINGS = -Wall -wd4668 -wd4820 -wd5045
LIBS =
DX11_LIBS =
VULKAN_LIBS =
OBJ_FILE = .obj
else ifneq (,$(filter $(CC),emcc em++))
DX11_LIBS =
LINK_GL1 = -s LEGACY_GL_EMULATION -D LEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0
LINK_GL3 = -s FULL_ES3 -s USE_WEBGL2
LINK_GL2 = -s FULL_ES2 -s USE_WEBGL2
LINK_OSMESA = -sALLOW_MEMORY_GROWTH
EXPORTED_JS = -s EXPORTED_RUNTIME_METHODS="['stringToNewUTF8']"
LIBS = -s WASM=1 -s ASYNCIFY -s GL_SUPPORT_EXPLICIT_SWAP_CONTROL=1 $(EXPORTED_JS)
EXT = .js
NO_GLES = 0
NO_EGL = 0
NO_VULKAN = 1
detected_OS = web
DX11_LIBS =
else ifeq (,$(filter $(CC),g++ clang++ em++))
CFLAGS += -std=c99
WARNINGS = -Wall -Werror -Wdouble-promotion -Wmissing-prototypes -Wextra -Wstrict-prototypes -Wold-style-definition -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wpointer-arith -Wvla -Wcast-align -Wstrict-overflow -Wnested-externs -Wstrict-aliasing -Wredundant-decls -Winit-self -Wmissing-noreturn
else
WARNINGS = -Wall -Werror -Wdouble-promotion -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wpointer-arith -Wvla -Wcast-align -Wstrict-overflow -Wstrict-aliasing -Wredundant-decls -Winit-self -Wmissing-noreturn
NO_VULKAN = 1
ifeq ($(detected_OS),Darwin)
WARNINGS += -Wno-deprecated -Wno-unknown-warning-option -Wno-pedantic
endif
endif
ifeq ($(WAYLAND_X11), 1)
# lazy fix (no -Wmissing-prototypes for wayland X11)
WARNINGS = -Wall -Werror -Wdouble-promotion -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wpointer-arith -Wvla -Wcast-align -Wstrict-overflow -Wstrict-aliasing -Wredundant-decls -Winit-self -Wmissing-noreturn
endif
EXAMPLE_OUTPUTS = \
examples/gl11/gl11 \
examples/surface/surface\
examples/event_queue/event_queue \
examples/callbacks/callbacks \
examples/state-checking/state-checking \
examples/flags/flags \
examples/monitor/monitor \
examples/gamma/gamma \
examples/gl33_ctx/gl33_ctx \
examples/smooth-resize/smooth-resize \
examples/multi-window/multi-window \
examples/standard-mouse-icons/icons \
examples/custom_alloc/custom_alloc \
examples/flash/flash \
EXAMPLE_OUTPUTS_CUSTOM = \
examples/window_icons/icons \
examples/mouse_icons/icons \
examples/gamepad/gamepad \
examples/first-person-camera/camera \
examples/microui_demo/microui_demo \
examples/gl33/gl33 \
examples/portableGL/pgl \
examples/gles2/gles2 \
examples/egl/egl \
examples/osmesa_demo/osmesa_demo \
examples/vk10/vk10 \
examples/dx11/dx11 \
examples/metal/metal \
examples/minimal_links/minimal_links \
examples/gears/gears \
examples/srgb/srgb
TEST_OUTPUTS = \
tests/loop \
all: $(WAYLAND_SOURCE) $(EXAMPLE_OUTPUTS) $(EXAMPLE_OUTPUTS_CUSTOM) libRGFW$(LIB_EXT) libRGFW.a
examples: $(WAYLAND_SOURCE) $(EXAMPLE_OUTPUTS) $(EXAMPLE_OUTPUTS_CUSTOM)
tests: $(WAYLAND_SOURCE) $(TEST_OUTPUTS)
examples/gears/gears: examples/gears/gears.c RGFW.h $(WAYLAND_SOURCE)
ifneq (,$(filter $(CC),emcc em++))
@echo gears is not supported on this platform
else
$(CC) $(CFLAGS) -I. $< $(LINK_GL1) $(LIBS) -lm $($) -o $@$(EXT)
endif
examples/srgb/srgb: examples/srgb/srgb.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) -I. $< $(LINK_GL1) $(LIBS) -lm $($) -o $@$(EXT)
examples/portableGL/pgl: examples/portableGL/pgl.c RGFW.h $(WAYLAND_SOURCE)
ifeq (,$(filter $(CC),emcc em++))
$(CC) -w $(CFLAGS) -I. $< -lm $(LIBS) -o $@
else
@echo "the portableGL example doesn't support html5"
endif
examples/gles2/gles2: examples/gles2/gles2.c RGFW.h $(WAYLAND_SOURCE)
ifneq ($(NO_GLES), 1)
$(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_GL2) -lGL -o $@$(EXT)
else
@echo gles has been disabled
endif
examples/egl/egl: examples/egl/egl.c RGFW.h $(WAYLAND_SOURCE)
ifneq ($(NO_EGL), 1)
$(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_GL1) -lGL -lEGL -o $@$(EXT)
else
@echo egl has been disabled
endif
examples/osmesa_demo/osmesa_demo: examples/osmesa_demo/osmesa_demo.c RGFW.h $(WAYLAND_SOURCE)
ifneq ($(NO_OSMESA), 1)
$(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_OSMESA) -lOSMesa -o $@$(EXT)
else
@echo osmesa has been disabled
endif
examples/vk10/vk10: examples/vk10/vk10.c examples/vk10/vkinit.h RGFW.h $(WAYLAND_SOURCE)
ifneq ($(NO_VULKAN), 1)
glslangValidator -V examples/vk10/shaders/vert.vert -o examples/vk10/shaders/vert.h --vn vert_code
glslangValidator -V examples/vk10/shaders/frag.frag -o examples/vk10/shaders/frag.h --vn frag_code
$(CC) $(CFLAGS) -I. $< $(VULKAN_LIBS) -o $@
else
@echo vulkan has been disabled
endif
examples/every_api/every:
ifneq ($(NO_VULKAN), 1)
$(CC) $(CFLAGS) -I. $< $(LINK_GL1) $(VULKAN_LIBS) $(DX11_LIBS) -o $@
else
$(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_GL1) $(DX11_LIBS) -D RGFW_NO_VULKAN -o $@
endif
examples/dx11/dx11: examples/dx11/dx11.c RGFW.h $(WAYLAND_SOURCE)
ifeq ($(CC), zig cc)
@echo directX is not supported with Zig
else ifneq (,$(filter $(CC),g++ clang++ "zig cc"))
@echo directX is not supported with C++
else ifneq (,$(filter $(detected_OS), windows Windows_NT))
$(CC) $(CFLAGS) -I. $< $(DX11_LIBS) -o $@
else
@echo directX is not supported on $(detected_OS)
endif
examples/metal/metal: examples/metal/metal.m RGFW.h $(WAYLAND_SOURCE)
ifeq ($(detected_OS),Darwin) # Mac OS X
$(CC) $(CFLAGS) examples/metal/metal.m -I. -framework CoreVideo -framework Metal -framework Cocoa -framework IOKit -framework QuartzCore -o $@
else
@echo metal is not supported on $(detected_OS)
endif
examples/minimal_links/minimal_links: examples/minimal_links/minimal_links.c RGFW.h $(WAYLAND_SOURCE)
ifeq ($(WAYLAND), 1)
@echo nostl is not supported on this platform
else ifneq (,$(filter $(CC),emcc em++))
@echo nostl is not supported on this platform
else ifeq ($(detected_OS),NetBSD)
$(CC) $(CFLAGS) $(CFLAGS) -pthread -I. $< -o $@$(EXT)
else ifeq ($(detected_OS),Linux)
$(CC) $(CFLAGS) -I. $< -lXrandr -lX11 -o $@$(EXT)
else ifeq ($(detected_OS),windows)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lgdi32 -o $@$(EXT)
else ifeq ($(detected_OS),Darwin)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -framework CoreVideo -framework Cocoa -o $@$(EXT)
else
@echo minimal_links is not supported on this platform
endif
examples/nostl/nostl: examples/nostl/nostl.c RGFW.h $(WAYLAND_SOURCE)
ifeq ($(WAYLAND), 1)
@echo nostl is not supported on this platform
else ifneq (,$(filter $(CC),emcc em++))
@echo nostl is not supported on this platform
else ifeq ($(detected_OS),Linux)
$(CC) $(CFLAGS) -fno-stack-protector -lX11 -lXcursor -lGL -lXi -lXrandr -I. $< -o $@$(EXT)
else ifeq ($(detected_OS),windows)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lkernel32 -lgdi32 -lshell32 -lUser32 -o $@$(EXT)
else ifeq ($(detected_OS),Darwin)
$(CC) $(CFLAGS) -fno-stack-protector $(WARNINGS) -I. $< -framework CoreVideo -framework Cocoa -o $@$(EXT)
else
@echo nostl is not supported on this platform
endif
examples/microui_demo/microui_demo: examples/microui_demo/microui_demo.c RGFW.h $(WAYLAND_SOURCE)
ifeq (,$(filter $(CC),emcc em++ g++ clang++))
$(CC) $(CFLAGS) -I. $< examples/microui_demo/microui.c $(LINK_GL1) $(LIBS) -o $@$(EXT)
else ifneq (,$(filter $(CC),em++ g++ clang++))
@echo microui demo not supported with C++
else
$(CC) $(CFLAGS) -I. $< examples/microui_demo/microui.c -s USE_WEBGL2 $(LIBS) $(LINK_GL1) -o $@$(EXT)
endif
examples/window_icons/icons: examples/window_icons/icons.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) -I. $< $(LIBS) -lm $(LINK_GL1) -o $@$(EXT)
examples/mouse_icons/icons: examples/mouse_icons/icons.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) -I. $< $(LIBS) -lm $(LINK_GL1) -o $@$(EXT)
examples/gamepad/gamepad: examples/gamepad/gamepad.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) -I. $< $(LIBS) -lm $(LINK_GL1) -o $@$(EXT)
examples/first-person-camera/camera: examples/first-person-camera/camera.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) -I. $< $(LIBS) -lm $(LINK_GL1) -o $@$(EXT)
examples/gl33/gl33: examples/gl33/gl33.c RGFW.h $(WAYLAND_SOURCE)
ifeq ($(WAYLAND), 1)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lm $(LIBS) $(LINK_GL1) -lEGL -lwayland-egl -o $@$(EXT)
else ifeq ($(detected_OS),NetBSD)
$(CC) $(CFLAGS) $(WARNINGS) $(CFLAGS) -I. $< -lm -o $@$(EXT)
else ifeq ($(detected_OS),Linux)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lm -o $@$(EXT)
else ifeq ($(detected_OS),windows)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lgdi32 -D UNICODE -o $@$(EXT)
else ifeq ($(detected_OS),Darwin)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -framework CoreVideo -framework IOKit -framework Cocoa -o $@$(EXT)
else
$(CC) $(CFLAGS) $(WARNINGS) -I. $< $(LIBS) $(LINK_GL3) -o $@$(EXT)
endif
$(EXAMPLE_OUTPUTS): %: %.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< $(LINK_GL1) $(LIBS) $($) -o $@$(EXT)
$(TEST_OUTPUTS): %: %.c RGFW.h $(WAYLAND_SOURCE)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< $(LINK_GL1) $(LIBS) $($) -o $@$(EXT)
@for exe in $(TEST_OUTPUTS); do \
echo "Running $$exe..."; \
./$$exe$(EXT); \
done
debug: all
@for exe in $(EXAMPLE_OUTPUTS); do \
echo "Running $$exe..."; \
./$$exe$(EXT); \
done
./examples/gamepad/gamepad
./examples/first-person-camera/camera
./examples/portableGL/pgl$(EXT)
./examples/microui_demo/microui_demo
./examples/gl33/gl33$(EXT)
ifneq ($(NO_GLES), 1)
./examples/gles2/gles2$(EXT)
endif
ifneq ($(NO_OSMESA), 1)
./examples/osmesa_demo/osmesa_demo$(EXT)
endif
ifneq ($(NO_VULKAN), 1)
./examples/vk10/vk10$(EXT)
endif
ifeq ($(detected_OS), windows)
./examples/dx11/dx11.exe
endif
$(MAKE) clean
RGFW$(OBJ_FILE): RGFW.h $(WAYLAND_SOURCE)
#$(CC) -x c $(CUSTOM_CFLAGS) -c RGFW.h -D RGFW_IMPLEMENTATION -fPIC -D RGFW_EXPORT
cp RGFW.h RGFW.c
$(CC) $(CUSTOM_CFLAGS) -c RGFW.c -D RGFW_IMPLEMENTATION -fPIC -D RGFW_EXPORT
rm RGFW.c
libRGFW$(LIB_EXT): RGFW.h RGFW$(OBJ_FILE)
$(MAKE) RGFW$(OBJ_FILE)
ifeq ($(CC), cl)
link /DLL /OUT:libRGFW.dll RGFW.obj
else
$(CC) $(CUSTOM_CFLAGS) -shared RGFW$(OBJ_FILE) $(LIBS) -o libRGFW$(LIB_EXT)
endif
libRGFW.a: RGFW.h RGFW$(OBJ_FILE)
$(MAKE) RGFW$(OBJ_FILE)
$(AR) rcs libRGFW.a RGFW$(OBJ_FILE)
ifeq ($(WAYLAND),1)
$(WAYLAND_SOURCE): %.c:
$(MAKE) -f wayland.mk
endif
clean:
rm -f *.o *.obj *.dll .dylib *.a *.so $(EXAMPLE_OUTPUTS) $(EXAMPLE_OUTPUTS_CUSTOM) $(TEST_OUTPUTS) .$(OS_DIR)examples$(OS_DIR)*$(OS_DIR)*.exe .$(OS_DIR)examples$(OS_DIR)*$(OS_DIR)*.js .$(OS_DIR)examples$(OS_DIR)*$(OS_DIR)*.wasm .$(OS_DIR)examples$(OS_DIR)vk10$(OS_DIR)shaders$(OS_DIR)*.h
ifeq ($(WAYLAND),1)
$(MAKE) -f wayland.mk clean
endif
.PHONY: all examples clean