-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
269 lines (206 loc) · 5.9 KB
/
Makefile
File metadata and controls
269 lines (206 loc) · 5.9 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
# define paths
# RAYLIB_PATH = ~/Projects/tests/raylib
RAYLIB_PATH = ./extern/raylib
# set web compilers
# (see: https://gist.github.com/rolandoam/5199237 for example)
EMSDK_PATH = ~/Projects/tests/emsdk
EMSCRIPTEN_VERSION = 1.37.39
EMSCRIPTEN_PATH = $(EMSDK_PATH)/emscripten/$(EMSCRIPTEN_VERSION)
# define compile target platform
# - PLATFORM_DESKTOP
# - PLATFORM_WEB
PLATFORM ?= PLATFORM_DESKTOP
# output binary
BIN := main
BIN_DIR := build
# for github pages
WEB_PUBLIC_DIR := docs
# source files
# SRCS := \
# src/main.cpp \
# src/gui.c
SRCS := $(wildcard src/*.cpp)
SRCS += $(wildcard src/*.c)
SRCS += $(wildcard src/util/*.cpp)
SRCS := $(filter-out src/tests.c, $(SRCS)) #ignore `tests.c`
# include header paths
# - -I.
# - -I./src
# - -I./extern
# - -L$(RAYLIB_PATH)/release/include
INCLUDES := -I.
INCLUDES += -I./src
INCLUDES += -I./extern
# INCLUDES += -I./extern/variant/include
INCLUDES += -I$(RAYLIB_PATH)/release/include
# include libraries
# - -L.
# - -L/usr/local/lib
# - -L$(RAYLIB_PATH)/release/libs/osx
LDLIBS := -L.
LDLIBS += -L/usr/local/lib
LDLIBS += -L$(RAYLIB_PATH)/release/libs/osx
LDLIBS += -lm
LDLIBS += -lraylib
# compiler warnings
WARNINGS := -Wall #-Wextra #-pedantic
# optimization level (if any)
OPTIMIATION := -O1
# ---------------------------------
# files included in the tarball generated by 'make dist' (e.g. add LICENSE file)
DISTFILES := $(BIN)
# filename of the tar archive generated by 'make dist'
DISTOUTPUT := $(BIN).tar.gz
TMP_DIR := .tmp
# intermediate directory for generated object files
OBJDIR := $(TMP_DIR)/.o
# intermediate directory for generated dependency files
DEPDIR := $(TMP_DIR)/.d
# EMSCRIPTEN / HTML5:
ifeq ($(PLATFORM),PLATFORM_WEB)
OBJDIR := $(TMP_DIR)/.o-web
DEPDIR := $(TMP_DIR)/.d-web
endif
# object files, auto generated from source files
OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS)))
# dependency files, auto generated from source files
DEPS := $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))
# Create required subdirectories
# (compilers (at least gcc and clang) don't create the subdirectories automatically)
$(shell mkdir -p $(dir $(TMP_DIR)) >/dev/null)
$(shell mkdir -p $(dir $(OBJS)) >/dev/null)
$(shell mkdir -p $(dir $(DEPS)) >/dev/null)
$(shell mkdir -p $(BIN_DIR) >/dev/null)
$(shell mkdir -p $(WEB_PUBLIC_DIR) >/dev/null)
# C compiler
CC := clang
# C++ compiler
CXX := clang++
# linker
LD := clang++
# tar
TAR := tar
# C flags
CFLAGS := -std=c11
# C++ flags
CXXFLAGS := -std=c++11
# C/C++ flags
CPPFLAGS := -g $(WARNINGS) $(OPTIMIATION) $(INCLUDES) -D$(PLATFORM)
# linker flags
LDFLAGS := -g -Wall
# EMSCRIPTEN / HTML5:
ifeq ($(PLATFORM),PLATFORM_WEB)
CC = $(EMSCRIPTEN_PATH)/emcc
CXX = $(EMSCRIPTEN_PATH)/em++
LD = $(EMSCRIPTEN_PATH)/em++
RAYLIB_RELEASE = $(RAYLIB_PATH)/release/libs/html5
LDLIBS = $(RAYLIB_RELEASE)/libraylib.bc
# Emscripten Flags (see INFOS.md)
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
# -O2 # if used, also set --memory-init-file 0
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
# -s USE_PTHREADS=1 # multithreading support
EMSC_FLAGS :=
EMSC_FLAGS += -D_DEFAULT_SOURCE
EMSC_FLAGS += -s USE_GLFW=3
EMSC_FLAGS += --preload-file resources/production
EMSC_FLAGS += --shell-file platform/web/shell.html
EMSC_FLAGS += --memory-init-file 0
EMSC_FLAGS += -s TOTAL_MEMORY=16777216
# Use WASM
EMSC_FLAGS += -s WASM=1
EMSC_FLAGS += -s BINARYEN=1
# # Debugging / Profiling
# EMSC_FLAGS += -s ASSERTIONS=1
# EMSC_FLATS += -s SAFE_HEAP=1
# EMSC_FLAGS += --emit-symbol-map
# EMSC_FLAGS += --profiling
# EMSC_FLAGS += --cpuprofiler # CPU visualizer
# EMSC_FLAGS += --memoryprofiler # memory visualizer
# # Optimizations
EMSC_FLAGS += -O3 # optimize
EMSC_FLAGS += -g0 # removes all debug info from JS code (function names, etc)
EMSC_FLAGS += -s ELIMINATE_DUPLICATE_FUNCTIONS=1 # slow to run!
EMSC_FLAGS += --closure 1 # run closure compiler (NOTE: '-g0' required for this)
CPPFLAGS += $(EMSC_FLAGS)
LDFLAGS += $(EMSC_FLAGS)
BIN = index
EXT = .html
endif
# flags required for dependency generation; passed to compilers
DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.Td
# compile C source files
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c -o $@
# compile C++ source files
COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -o $@
# link object files to binary
LINK.o = $(LD) $(LDFLAGS) $(LDLIBS) -o $(BIN_DIR)/$@$(EXT)
# precompile step
PRECOMPILE =
# postcompile step
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
all: $(BIN)
dist: $(DISTFILES)
$(TAR) -cvzf $(DISTOUTPUT) $^
.PHONY: clean
clean:
$(RM) -r $(TMP_DIR) $(BIN_DIR)
.PHONY: distclean
distclean: clean
$(RM) $(BIN) $(DISTOUTPUT)
.PHONY: install
install:
@echo no install tasks configured
.PHONY: uninstall
uninstall:
@echo no uninstall tasks configured
.PHONY: check
check:
@echo no tests configured
# BUILD AND RUN
.PHONY: run
run: all
@echo "\n\n\n"
@echo [ RUNNING \'$(BIN_DIR)/$(BIN)\' ]
./$(BIN_DIR)/$(BIN)
# WEB
.PHONY: web
web:
make PLATFORM=PLATFORM_WEB
# RUN WEB (start HTTP server)
.PHONY: run-web
run-web: web
http-server build
# WEB
.PHONY: deploy-web
deploy-web: clean
$(RM) $(WEB_PUBLIC_DIR)/*
make web
mv $(BIN_DIR)/* $(WEB_PUBLIC_DIR)
$(BIN): $(OBJS)
$(LINK.o) $^
$(OBJDIR)/%.o: %.c
$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
$(PRECOMPILE)
$(COMPILE.c) $<
$(POSTCOMPILE)
$(OBJDIR)/%.o: %.cpp
$(OBJDIR)/%.o: %.cpp $(DEPDIR)/%.d
$(PRECOMPILE)
$(COMPILE.cc) $<
$(POSTCOMPILE)
$(OBJDIR)/%.o: %.cc
$(OBJDIR)/%.o: %.cc $(DEPDIR)/%.d
$(PRECOMPILE)
$(COMPILE.cc) $<
$(POSTCOMPILE)
$(OBJDIR)/%.o: %.cxx
$(OBJDIR)/%.o: %.cxx $(DEPDIR)/%.d
$(PRECOMPILE)
$(COMPILE.cc) $<
$(POSTCOMPILE)
.PRECIOUS = $(DEPDIR)/%.d
$(DEPDIR)/%.d: ;
-include $(DEPS)