-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
194 lines (152 loc) · 4.95 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
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
# **************************************************************************** #
# VARS #
# **************************************************************************** #
# COLORS
NOCOL = \033[0m
RED = \033[31m
GRN = \033[32m
YEL = \033[33m
BLU = \033[34m
MAG = \033[35m
CYN = \033[36m
LBLU = \033[36m
LGRN = \033[0;90m
# OS
UNAME_S := $(shell uname -s)
# **************************************************************************** #
# PROGRAM #
# **************************************************************************** #
BIN_NAME = emu
INSTALL_PATH ?= /usr/local/bin
# **************************************************************************** #
# COMPILER #
# **************************************************************************** #
MAKE = make
CXX = g++
#CXX = clang++
CXXFLAGS += -std=c++17 -Wall -Wextra -Werror -MD
CXXFLAGS += -m64
# **************************************************************************** #
# PATHS #
# **************************************************************************** #
SRC_PATH = src
INC_PATH = inc
OBJ_PATH = obj
LIB_PATH = lib
BIN_PATH = bin
# **************************************************************************** #
# FLAGS #
# **************************************************************************** #
CXXFLAGS += -I ./$(INC_PATH)
CXXFLAGS += -I ./$(SRC_PATH)
# **************************************************************************** #
# SOURCES #
# **************************************************************************** #
SRC_FILES = main.cc \
chip8.cc \
engine.cc \
window.cc \
OBJ_FILES = $(SRC_FILES:%.cc=%.o)
DEP_FILES = $(SRC_FILES:%.cc=%.d)
SRC = $(addprefix $(SRC_PATH)/, $(SRC_FILES))
OBJ = $(addprefix $(OBJ_PATH)/, $(OBJ_FILES))
DEP = $(addprefix $(OBJ_PATH)/, $(DEP_FILES))
# **************************************************************************** #
# LIBS #
# **************************************************************************** #
# SDL2
#SDL2_NAME = libSDL2.a
#SDL2MAIN_NAME = libSDL2main.a
#SDL2_PATH = $(LIB_PATH)/SDL2
#CXXFLAGS += -I ./$(SDL2_PATH)/include
#LDFLAGS += -L ./$(SDL2_PATH)
LDLIBS += -lSDL2 -lSDL2main
# SYSTEM LIBS
LDLIBS += -ldl -lpthread
# **************************************************************************** #
# OS #
# **************************************************************************** #
CXXFLAGS += -I $(LIB_PATH)/include/
RM = rm -rf
CP = cp
PRINTF = printf
UNAME_S := $(shell uname -s)
MKDIR = mkdir -p
SLASH = /
ifeq ($(UNAME_S),Linux)
CXXFLAGS += -D LINUX
endif
NAME := $(BIN_PATH)/$(BIN_NAME)
# **************************************************************************** #
# RULES #
# **************************************************************************** #
# ALL
PHONY := all
all: $(NAME)
# NAME
$(NAME): $(OBJ) | $(BIN_PATH)
@$(PRINTF) "\n${YEL}LINKING:${NOCOL}\n"
@$(PRINTF) "${BLU}"
$(CXX) $(CXXFLAGS) $(DEBUG) $(OBJ) -o $@ $(LDFLAGS) $(LDLIBS)
#$(CXX) $(DEBUG) $(OBJ) -o $@ $(LDFLAGS) $(LDLIBS)
@$(PRINTF) "${NOCOL}"
@$(PRINTF) "\n${GRN}SUCCESS!${NOCOL}\n"
@$(PRINTF) "${CYN}type \"./${NAME}\" or \"make run\" to start!${NOCOL}\n"
# RELEASE
PHONY += release
release: DEBUG := -O3 -D NDEBUG
release: $(NAME)
# SANITIZE ADDRESS
PHONY += sanitize
ifeq ($(UNAME_S),Linux)
sanitize: DEBUG := -pedantic -g3 -fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=bounds -fsanitize=null
endif
ifeq ($(UNAME_S),Darwin)
sanitize: DEBUG := -pedantic -g3 -fsanitize=address
endif
sanitize: $(NAME)
# SANITIZE THREAD
PHONY += thread
thread: DEBUG := -g3 -fsanitize=thread
thread: $(NAME)
# VALGRIND
valgrind: DEBUG := -ggdb3
valgrind: $(NAME)
# OBJ
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.cc | $(OBJ_PATH)
@$(PRINTF) "${BLU}"
$(CXX) $(CXXFLAGS) $(DEBUG) -c $< -o $@
@$(PRINTF) "${NOCOL}"
# OBJ PATH
$(OBJ_PATH):
@$(PRINTF) "${MAG}"
$(MKDIR) $@
@$(PRINTF) "${NOCOL}"
# BIN_PATH
$(BIN_PATH):
@$(PRINTF) "${MAG}"
$(MKDIR) $@
@$(PRINTF) "${NOCOL}"
# CLEAN
PHONY += clean
clean:
@$(PRINTF) "${RED}"
$(RM) $(OBJ_PATH)
@$(PRINTF) "${NOCOL}"
# FULL CLEAN
PHONY += fclean
fclean: clean
@$(PRINTF) "${RED}"
$(RM) $(firstword $(subst $(SLASH), , $(BIN_PATH)))
@$(PRINTF) "${NOCOL}"
# RE
PHONY += re
re: fclean all
# RUN
PHONY += run
run: $(NAME)
@$(PRINTF) "\n${YEL}RUNNING...${NOCOL}\n"
$(NAME) 10 ./roms/test_opcode.ch8
@$(PRINTF) "\n${GRN}SUCCESS!${NOCOL}\n"
-include $(DEP)
.PHONY: $(PHONY)