Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
95 lines (69 loc) · 2.04 KB
/
Copy pathMakefile
File metadata and controls
95 lines (69 loc) · 2.04 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
# project folders
BIN := bin
BUILD:= build
SRC := src
LIBS := libs
ASSETS := assets
# variables
SRCS := $(wildcard $(SRC)/*.c)
OBJS := $(SRCS:$(SRC)/%.c=$(BUILD)/%.o)
DEPS := $(OBJS:.o=.d)
WEB_OBJS := $(SRCS:$(SRC)/%.c=$(BUILD)/web/%.o)
WEB_DEPS := $(WEB_OBJS:.o=.d)
# libs
LIB_RAYLIB := $(LIBS)/raylib/libraylib.a
LIB_RAYLIB_WEB := $(LIBS)/raylib/libraylib.web.a
WEB_SHELL := $(LIBS)/raylib/minshell.html
RAYLIB := -I$(LIBS)/raylib
LIB_LUA := $(LIBS)/lua/liblua.a
LIB_LUA_WEB := $(LIBS)/lua/liblua.web.a
LUA := -I$(LIBS)/lua
# preprocessor flags
CPPFLAGS := $(RAYLIB) $(LUA) -MMD -MP
CPPFLAGS += -DLUA_DIR=\"$(CURDIR)/$(SRC)\"
# compiler flags
CFLAGS := -std=c23 -Wall -pedantic
CFLAGS += -g -fsanitize=undefined -fsanitize-trap
# linker flags
LDFLAGS :=
LDLIBS := $(LIB_LUA) $(LIB_RAYLIB) -lopengl32 -lgdi32 -lwinmm
# web flags
WEB_CPPFLAGS := $(RAYLIB) $(LUA) -MMD -MP -DLUA_DIR=\"\"
WEB_CFLAGS := -std=c2x -Wall -pedantic
WEB_LDFLAGS := -sUSE_GLFW=3 -sASYNCIFY --shell-file $(WEB_SHELL)
WEB_LDFLAGS += --preload-file $(SRC)/init.lua@/init.lua
# tools
CLANG_FORMAT ?= clang-format
# targets
all: $(BIN)/main.exe
run: all
./$(BIN)/main.exe
$(BIN)/main.exe: $(OBJS) $(LIB_RAYLIB) $(LIB_LUA)
mkdir -p $(BIN)
gcc $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
$(BUILD)/%.o: $(SRC)/%.c | $(LIB_RAYLIB) $(LIB_LUA)
mkdir -p $(BUILD)
gcc $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
web: $(BIN)/index.html
run-web: web
python -m http.server 8000 -d $(BIN)
$(BIN)/index.html: $(WEB_OBJS) $(LIB_RAYLIB_WEB) $(LIB_LUA_WEB)
mkdir -p $(BIN)
emcc -o $@ $(WEB_OBJS) $(LIB_LUA_WEB) $(LIB_RAYLIB_WEB) $(WEB_LDFLAGS)
$(BUILD)/web/%.o: $(SRC)/%.c | $(LIB_RAYLIB_WEB) $(LIB_LUA_WEB)
mkdir -p $(BUILD)/web
emcc $(WEB_CPPFLAGS) $(WEB_CFLAGS) -c -o $@ $<
-include $(DEPS) $(WEB_DEPS)
$(LIB_RAYLIB):
$(MAKE) -C $(LIBS) raylib-desktop
$(LIB_RAYLIB_WEB):
$(MAKE) -C $(LIBS) raylib-web
$(LIB_LUA):
$(MAKE) -C $(LIBS) lua-mingw
$(LIB_LUA_WEB):
$(MAKE) -C $(LIBS) lua-web
clean:
rm -rf $(BIN) $(BUILD)
format:
$(CLANG_FORMAT) -i $(SRCS) $(wildcard $(SRC)/*.h)
.PHONY: all run web run-web clean format