-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (80 loc) · 3.52 KB
/
Copy pathMakefile
File metadata and controls
111 lines (80 loc) · 3.52 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
MAKE_FLAGS += -j
BIN_NAME := arcade
SRC := $(wildcard src/*.cpp)
SRC += $(wildcard src/*/*.cpp)
SRC_SFML := $(wildcard src/Graphic/SFML/*.cpp)
SRC_NCURSES := $(wildcard src/Graphic/Ncurses/*.cpp)
SRC_SDL2 := $(wildcard src/Graphic/SDL2/*.cpp)
SRC_PACMAN := $(wildcard src/Game/Pacman/*.cpp)
SRC_PACMAN += src/Game/Entity.cpp
SRC_PACMAN += src/Game/Text.cpp
SRC_SNAKE := $(wildcard src/Game/Snake/*.cpp)
SRC_SNAKE += src/Game/Entity.cpp
SRC_SNAKE += src/Game/Text.cpp
SRC_MENU := $(wildcard src/Game/Menu/*.cpp)
SRC_MENU += src/Game/Entity.cpp
SRC_MENU += src/Game/Text.cpp
BUILD_DIR := .build
CXXFLAGS += -Wall -Wextra -Werror=write-strings -g
CXXFLAGS += -Wno-unused-parameter -Wunused-result
CXXFLAGS += -Wp,-U_FORTIFY_SOURCE -Wcast-qual
CXXFLAGS += -Wformat=2 -Wshadow -fno-builtin -Wno-unused-command-line-argument
CXXFLAGS += -Wstrict-aliasing=0 -Wunreachable-code
CXXFLAGS += -Wwrite-strings -Werror=format-nonliteral -Werror=return-type
CXXFLAGS += -std=c++20 -iquote src
SFML_LDFLAGS += $(shell pkg-config --cflags --libs sfml-graphics sfml-window sfml-system)
NCURSES_LDFLAGS += $(shell pkg-config --cflags --libs ncurses)
SDL2_LDFLAGS += $(shell pkg-config --cflags --libs sdl2 SDL2_image SDL2_ttf)
include utils.mk
.PHONY: _start all
_start: all
CXX = clang++
# call mk-profile release, SRC, additional CFLAGS
define mk-profile
NAME_$(strip $1) := $4
OBJ_$(strip $1) := $$($(strip $2):%.cpp=$$(BUILD_DIR)/$(strip $1)/%.o)
$$(BUILD_DIR)/$(strip $1)/%.o: %.cpp
@ mkdir -p $$(dir $$@)
@ mkdir -p lib
@ $$(COMPILE.cpp) $$(CXXFLAGS) $(strip $3) $$< -o $$@
@ $$(LOG_TIME) "$$(C_GREEN) CC $$(C_PURPLE) $$(notdir $$@) $$(C_RESET)"
$$(NAME_$(strip $1)): $$(OBJ_$(strip $1))
@ $$(LINK.cpp) $$(OBJ_$(strip $1)) $$(LDFLAGS) $$(LDLIBS) $(strip $3) -o $$@
@ $$(LOG_TIME) "$$(C_BLUE) LD $$(C_PURPLE) $$(notdir $$@) $$(C_RESET)"
@ $$(LOG_TIME) "$$(C_GREEN) OK Compilation finished $$(C_RESET)"
endef
$(eval $(call mk-profile, core, SRC, , $(BIN_NAME)))
$(eval $(call mk-profile, sfml, SRC_SFML, $(SFML_LDFLAGS) -shared -fPIC, lib/arcade_sfml.so))
$(eval $(call mk-profile, ncurses, SRC_NCURSES, $(NCURSES_LDFLAGS) -shared -fPIC, lib/arcade_ncurses.so))
$(eval $(call mk-profile, sdl2, SRC_SDL2, $(SDL2_LDFLAGS) -shared -fPIC, lib/arcade_sdl2.so))
$(eval $(call mk-profile, pacman, SRC_PACMAN, -shared -fPIC, lib/arcade_pacman.so))
$(eval $(call mk-profile, snake, SRC_SNAKE, -shared -fPIC, lib/arcade_snake.so))
$(eval $(call mk-profile, menu, SRC_MENU, -shared -fPIC, lib/arcade_menu.so))
core: $(NAME_core)
games: $(NAME_pacman) $(NAME_snake) $(NAME_menu)
graphicals: $(NAME_sfml) $(NAME_ncurses) $(NAME_sdl2)
all: core graphicals games
debug: CXXFLAGS += -D DEBUG_MODE
debug: all
tests: $(NAME_test)
@ bash tests/run_all.sh
format:
@ find ./ -name "*.cpp" -type f -exec clang-format -i {} ";"
@ find ./ -name "*.hpp" -type f -exec clang-format -i {} ";"
@ $(LOG_TIME) "$(C_BLUE) CF $(C_GREEN) Code formated $(C_RESET)"
check_format:
@ find ./ -name "*.cpp" -type f -exec clang-format --dry-run --Werror {} ";" 2>&1 | wc -m | grep 0 > /dev/null
@ find ./ -name "*.hpp" -type f -exec clang-format --dry-run --Werror {} ";" 2>&1 | wc -m | grep 0 > /dev/null
@ $(LOG_TIME) "$(C_BLUE) CF $(C_GREEN) Code formated $(C_RESET)"
clean:
@ $(RM) -r $(BUILD_DIR)
@ $(LOG_TIME) "$(C_YELLOW) RM $(C_PURPLE) $(BUILD_DIR) $(C_RESET)"
fclean:
@ $(RM) -r $(NAME_core) $(BUILD_DIR) ./lib/
@ $(LOG_TIME) "$(C_YELLOW) RM $(C_PURPLE) $(NAME_core) $(BUILD_DIR) ./lib/ \
$(C_RESET)"
.NOTPARALLEL: re
re: fclean all
.PHONY: all clean fclean re
PREFIX ?=
BINDIR ?= $(PREFIX)/bin