-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMakefile
131 lines (116 loc) · 3.29 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
CFLAGS=-std=c99
CFLAGS+=-Wall -Wextra -Wshadow -Wno-unused-function -Wno-missing-field-initializers
DEFS=
CC=gcc
INCS=-I. -Ithirdparty -Ishaders
OUTDIR=build
OUTEXT=
SHDC=sokol-shdc
SHDCFLAGS=--format sokol_impl --slang glsl410:glsl300es:hlsl4:metal_macos:metal_ios:wgsl
SHADERS=\
shaders/sample-effect.glsl.h \
shaders/sample-sdf.glsl.h \
shaders/sokol_gp.glsl.h
# platform
ifndef platform
platform=linux
endif
ifeq ($(platform), windows)
CC=x86_64-w64-mingw32-gcc
LIBS+=-lkernel32 -luser32 -lshell32 -lgdi32 -ld3d11 -ldxgi
OUTEXT=.exe
else ifeq ($(platform), linux)
DEFS+=-D_GNU_SOURCE
CFLAGS+=-pthread
LIBS+=-lX11 -lXi -lXcursor -lGL -ldl -lm
ifeq ($(backend), gles3)
LIBS+=-lEGL
endif
else ifeq ($(platform), macos)
LIBS+=-framework Cocoa -framework QuartzCore -framework Metal -framework MetalKit
CFLAGS+=-ObjC -x objective-c
else ifeq ($(platform), web)
LIBS+=-sFULL_ES3
CC=emcc
OUTEXT=.html
CFLAGS+=--shell-file=samples/sample-shell.html --embed-file images
endif
# build type
ifndef build
build=debug
endif
ifeq ($(platform), web)
ifeq ($(build), debug)
CFLAGS+=-Og -g
else
CFLAGS+=-O3 -g0 -s
endif
else ifeq ($(build), debug)
CFLAGS+=-Og -ffast-math -g
else ifeq ($(build), release)
CFLAGS+=-Ofast -fno-plt -g
DEFS+=-DNDEBUG
endif
ifeq ($(build), debug)
DEFS+=-DSOKOL_DEBUG
endif
# backend
ifndef backend
ifeq ($(platform), windows)
backend=d3d11
else ifeq ($(platform), macos)
backend=metal
else ifeq ($(platform), web)
backend=gles3
else
backend=glcore
endif
endif
ifeq ($(backend), glcore)
DEFS+=-DSOKOL_GLCORE
else ifeq ($(backend), gles3)
DEFS+=-DSOKOL_GLES3
else ifeq ($(backend), d3d11)
DEFS+=-DSOKOL_D3D11
else ifeq ($(backend), metal)
DEFS+=-DSOKOL_METAL
else ifeq ($(backend), dummy)
DEFS+=-DSOKOL_DUMMY_BACKEND
endif
SAMPLES=\
build/sample-rectangle$(OUTEXT) \
build/sample-primitives$(OUTEXT) \
build/sample-blend$(OUTEXT) \
build/sample-framebuffer$(OUTEXT) \
build/sample-bench$(OUTEXT) \
build/sample-sdf$(OUTEXT) \
build/sample-effect$(OUTEXT)
all: $(SAMPLES)
shaders: $(SHADERS)
clean:
rm -rf $(OUTDIR)
clean-shaders:
rm -f $(SHADERS)
$(OUTDIR)/%$(OUTEXT): samples/%.c shaders/*.h thirdparty/*.h sokol_gp.h
@mkdir -p $(OUTDIR)
$(CC) -o $@ $< $(INCS) $(DEFS) $(CFLAGS) $(LIBS)
shaders/%.glsl.h: shaders/%.glsl
$(SHDC) $(SHDCFLAGS) -i $^ -o $@
lint:
clang-tidy sokol_gp.h -- $(INCS) $(DEFS) $(CFLAGS) -DSOKOL_IMPL -include sokol_gfx.h
update-thirdparty:
wget -O thirdparty/sokol_app.h https://raw.githubusercontent.com/floooh/sokol/master/sokol_app.h
wget -O thirdparty/sokol_gfx.h https://raw.githubusercontent.com/floooh/sokol/master/sokol_gfx.h
wget -O thirdparty/sokol_glue.h https://raw.githubusercontent.com/floooh/sokol/master/sokol_glue.h
wget -O thirdparty/sokol_time.h https://raw.githubusercontent.com/floooh/sokol/master/sokol_time.h
wget -O thirdparty/sokol_log.h https://raw.githubusercontent.com/floooh/sokol/master/sokol_log.h
wget -O thirdparty/stb_image.h https://raw.githubusercontent.com/nothings/stb/master/stb_image.h
.PHONY: all shaders clean clean-shaders lint update-thirdparty
test: all
./build/sample-rectangle$(OUTEXT)
./build/sample-blend$(OUTEXT)
./build/sample-primitives$(OUTEXT)
./build/sample-effect$(OUTEXT)
./build/sample-framebuffer$(OUTEXT)
./build/sample-sdf$(OUTEXT)
./build/sample-bench$(OUTEXT)