-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
164 lines (121 loc) · 4.64 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
CC = cc
LD = cc
AR = ar
emscripten: CC = emcc
emscripten: LD = emcc
emscripten: AR = emar
DIR = build
EMS_OPTS = -s USE_GLFW=3 -s USE_WEBGL2=1 \
-s FULL_ES3=1 -s EMULATE_FUNCTION_POINTER_CASTS=1 \
-s WASM_MEM_MAX=2GB -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 \
-s SAFE_HEAP=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -g4
LIBS = -lm -lGL -pthread -ldl -lX11 -lrt
LDFLAGS_REL = $(LIBS) candle/$(DIR)/candle.a \
-Wl,--format=binary -Wl,candle/$(DIR)/data.zip -Wl,--format=default
LDFLAGS_DEB = $(LIBS) candle/$(DIR)/candle_debug.a \
-Wl,--format=binary -Wl,candle/$(DIR)/data.zip -Wl,--format=default
LDFLAGS_EMS = -lm -lGL -ldl -lrt candle/$(DIR)/candle_emscripten.a \
$(EMS_OPTS) --preload-file candle/$(DIR)/data.zip@/ --shell-file candle/index.html -g4
GLFW = third_party/glfw/src
TINYCTHREAD = third_party/tinycthread/source
PLUGINS = $(wildcard ../*.candle)
PLUGINS_DIR = $(patsubst %, %/$(DIR), $(PLUGINS))
PLUGINS_REL = $(patsubst %, %/libs, $(PLUGINS_DIR))
PLUGINS_DEB = $(patsubst %, %/libs_debug, $(PLUGINS_DIR))
PLUGINS_EMS = $(patsubst %, %/libs_emscripten, $(PLUGINS_DIR))
PLUGINS_CLEAN = $(patsubst %, %_clean, $(PLUGINS))
THIRD_PARTY_SRC = \
$(GLFW)/context.c \
$(GLFW)/init.c \
$(GLFW)/input.c \
$(GLFW)/monitor.c \
$(GLFW)/window.c \
$(GLFW)/vulkan.c \
$(GLFW)/egl_context.c \
$(GLFW)/glx_context.c \
$(GLFW)/linux_joystick.c \
$(GLFW)/osmesa_context.c \
$(GLFW)/posix_thread.c \
$(GLFW)/posix_time.c \
$(GLFW)/x11_init.c \
$(GLFW)/x11_monitor.c \
$(GLFW)/x11_window.c \
$(GLFW)/xkb_unicode.c \
$(TINYCTHREAD)/tinycthread.c
SRCS = $(wildcard *.c) $(wildcard components/*.c) $(wildcard systems/*.c) \
$(wildcard formats/*.c) $(wildcard utils/*.c) $(wildcard vil/*.c) \
$(wildcard ecs/*.c)
OBJS_REL = $(patsubst %.c, $(DIR)/%.o, $(SRCS) $(THIRD_PARTY_SRC))
OBJS_DEB = $(patsubst %.c, $(DIR)/%.debug.o, $(SRCS) $(THIRD_PARTY_SRC))
OBJS_EMS = $(patsubst %.c, $(DIR)/%.emscripten.o, $(SRCS))
CFLAGS = -std=c89 -pedantic -Wall -Wno-unused-function \
-DTHREADED $(PARENTCFLAGS)
CFLAGS_REL = $(CFLAGS) -O3
CFLAGS_DEB = $(CFLAGS) -g3 -DDEBUG
CFLAGS_EMS = -Wall -I. -Wno-unused-function \
$(EMS_OPTS)
##############################################################################
all: init $(PLUGINS_REL) $(DIR)/candle.a $(DIR)/data.zip
-cat "" $(PLUGINS_REL) | paste -sd " " > $(DIR)/libs
echo -n " $(LDFLAGS_REL)" >> $(DIR)/libs
$(DIR)/candle.a: $(OBJS_REL)
$(AR) rs $@ $(OBJS_REL)
$(DIR)/$(GLFW)/%.o: $(GLFW)/%.c
$(CC) -o $@ -c $< $(CFLAGS_REL) -D_GLFW_X11
$(DIR)/%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS_REL)
../%.candle/$(DIR)/libs: force
$(MAKE) -C ../$*.candle
# utils/gl.c:
# galogen gl.xml --api gl --ver 3.0 --profile core --exts $(EXTS)
# mv gl.c gl.h utils/
##############################################################################
debug: init $(PLUGINS_DEB) $(DIR)/candle_debug.a $(DIR)/data.zip
-cat "" $(PLUGINS_DEB) | paste -sd " " > $(DIR)/libs_debug
echo -n " $(LDFLAGS_DEB)" >> $(DIR)/libs_debug
$(DIR)/candle_debug.a: $(OBJS_DEB)
$(AR) rs $@ $(OBJS_DEB)
$(DIR)/$(GLFW)/%.debug.o: $(GLFW)/%.c
$(CC) -o $@ -c $< $(CFLAGS_DEB) -D_GLFW_X11
$(DIR)/%.debug.o: %.c
$(CC) -o $@ -c $< $(CFLAGS_DEB)
../%.candle/$(DIR)/libs_debug: force
$(MAKE) -C ../$*.candle debug
##############################################################################
emscripten: init $(PLUGINS_EMS) $(DIR)/candle_emscripten.a $(DIR)/data.zip
-cat "" $(PLUGINS_EMS) | paste -sd " " > $(DIR)/libs_emscripten
echo -n " $(LDFLAGS_EMS)" >> $(DIR)/libs_emscripten
$(DIR)/candle_emscripten.a: $(OBJS_EMS)
$(AR) rs $@ $(OBJS_EMS)
$(DIR)/%.emscripten.o: %.c
$(CC) -o $@ -c $< $(CFLAGS_EMS)
../%/$(DIR)/libs_emscripten: force
$(MAKE) -C ../$* emscripten
##############################################################################
$(DIR)/res:
echo $(foreach res,$(PLUGINS), $(patsubst %, $(res)/%, $(shell cat "" $(res)/$(DIR)/res))) > $(DIR)/res
$(DIR)/data.zip: $(DIR)/res $(DIR)/packager
@:$(if $(value SAUCES),, $(error Undefined SAUCES))
$(DIR)/packager ../$(SAUCES) $(shell cat $(DIR)/res)
$(DIR)/packager: buildtools/packager.c
cc buildtools/packager.c -O3 -o $(DIR)/packager
##############################################################################
force:
true
init:
mkdir -p $(DIR)
mkdir -p $(DIR)/components
mkdir -p $(DIR)/systems
mkdir -p $(DIR)/utils
mkdir -p $(DIR)/formats
mkdir -p $(DIR)/vil
mkdir -p $(DIR)/ecs
mkdir -p $(DIR)/$(GLFW)
mkdir -p $(DIR)/$(TINYCTHREAD)
rm -f $(DIR)/res
##############################################################################
%.candle_clean:
$(MAKE) -C $*.candle clean
clean: $(PLUGINS_CLEAN)
rm -fr $(DIR)
.PHONY: clean all init