-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (74 loc) · 2.45 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
CC = gcc
BUILD_DIR ?= ./build
NAME = mental_mahjong
RAYLIB_DIR ?= ./raylib/src/
# This allows the preprocessor to also generate the dependencies in the *.d files
CPPFLAGS += -MP -MD
CFLAGS = -Wall -Wextra -I$(RAYLIB_DIR)
LDFLAGS += -lm
DEBUGFLAGS = -g3 -fsanitize=address
# RELEASEFLAGS = -flto -O3 -DNDEBUG
RELEASEFLAGS = -O3 -DNDEBUG -fshort-enums
MODE ?= RELEASE# Default is Release
# Raylib has some warnings that we don’t want to see when compiling in debug
CUSTOM_CFLAGS = -Wno-unused-result -Wno-unused-but-set-variable
# Allow usage of mold linker for faster build time, default to false
USE_MOLD_LINKER ?= FALSE
ifeq ($(USE_MOLD_LINKER), TRUE)
LDFLAGS += -fuse-ld=mold
endif
ifeq ($(MODE),DEBUG)
CFLAGS += $(DEBUGFLAGS)
CUSTOM_CFLAGS += $(DEBUGFLAGS)
else
CFLAGS += $(RELEASEFLAGS)
CUSTOM_CFLAGS += $(RELEASEFLAGS)
endif
default: $(NAME)
# for raylib
RAYLIB_RELEASE_PATH = $(CURDIR)/$(BUILD_DIR)
LIBRAYLIB = $(BUILD_DIR)/libraylib.a
export CUSTOM_CFLAGS
export RAYLIB_RELEASE_PATH
SOURCES = $(shell find . -name '*.c' -not -path './test/*' -not -path './raylib/*')
OBJECTS = $(addprefix $(BUILD_DIR)/, $(SOURCES:%.c=%.o))
MAKEFILES = $(OBJECTS:%.o=%.d)
# We include the autogenerated dependencies
-include $(MAKEFILES)
$(NAME): $(OBJECTS) $(LIBRAYLIB)
@echo "Compiling Mahjong $(SOURCES) $(OBJECTS) $(LIBRAYLIB)"
$(CC) $(OBJECTS) $(LIBRAYLIB) $(LDFLAGS) -o $@
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(BUILD_DIR)/$(dir $<)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
raylib: $(LIBRAYLIB)
$(LIBRAYLIB):
@mkdir -p $(BUILD_DIR)
$(MAKE) -C $(RAYLIB_DIR)
TEST_SOURCE = $(wildcard test/*.c) $(wildcard test/*/*.c)
TEST_EXECUTABLE = $(TEST_SOURCE:test/%.c=build/%.x)
all: $(NAME) test
test: $(TEST_EXECUTABLE)
@start_time=$$(date +%s); \
number_test=0; \
for binary in $(wildcard build/*.x) $(wildcard build/*/*.x); do \
./$$binary 2>&1 ; \
number_test=$$((number_test + 1)); \
done; \
end_time=$$(date +%s); \
elapsed_time=$$((end_time - start_time)); \
echo "$$number_test test took $$elapsed_time s"
build/%.x: test/%.c $(OBJECTS) $(LIBRAYLIB)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< $(filter-out $(BUILD_DIR)/./controller/controller.o, $(OBJECTS)) $(LIBRAYLIB) $(LDFLAGS)
cleanall : clean clean_raylib
clean:
$(RM) $(OBJECTS)
$(RM) $(MAKEFILES)
$(RM) $(LIBRAYLIB)
$(RM) $(TEST_EXECUTABLE)
$(RM) --dir $(shell find $(BUILD_DIR) -type d | sort --reverse)
$(RM) $(NAME)
clean_raylib:
$(MAKE) clean -C $(RAYLIB_DIR)
.PHONY: clean cleanall clean_raylib test