-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
236 lines (199 loc) · 5.85 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
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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: flfische <[email protected]. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/06/06 18:35:04 by flfische #+# #+# #
# Updated: 2024/07/10 10:46:31 by flfische ### ########.fr #
# #
# **************************************************************************** #
CC = cc
CFLAGS = -Wall -Wextra -Werror -O3 -g
MAKEFLAGS += --no-print-directory
NAME := miniRT
# DIRECTORIES
SRC_DIRS := src \
src/mlx \
src/errors \
src/maths \
src/objects \
src/raytracer \
src/colors \
src/parsing \
src/light \
src/textures \
src/debug \
OBJ_DIR := obj
INC_DIR := includes
TMP_DIR := tmp
# FILES
vpath %.c $(SRC_DIRS)
vpath %.h $(INC_DIR)
CFILES := miniRT.c \
init_rt.c \
join_threads.c \
mlx_init.c \
mlx_hooks.c \
print_error.c \
debug_messages.c \
CFILES += parsing.c \
parsing_handlers.c \
parsing_utils.c \
parsing_utils2.c \
parsing_utils3.c \
parse_camera.c \
parse_material.c \
parse_triangle.c \
parse_cone.c \
parse_cylinder.c \
custom_split.c \
# OBJECTS
CFILES += get_first_obj.c \
obj_func_getters.c \
hit.c \
camera.c \
sphere.c \
plane.c \
cylinder.c \
cylinder_utils.c \
cylinder_normal.c \
obj_utils.c \
cone.c \
cone_normal.c \
triangle.c \
# RT
CFILES += send_rays.c \
loop_pixels.c \
# COLORS
CFILES += avg_color.c \
color_conversions.c \
color_add.c \
color_mult.c \
# LIGHT
CFILES += compute_ambient.c \
compute_phong.c \
compute_diffuse.c \
compute_specular.c \
# MATHS
CFILES += random.c \
v3_add.c \
v3_copy.c \
v3_crossprod.c \
v3_div.c \
v3_dotprod.c \
v3_init.c \
v3_len.c \
v3_new.c \
v3_normalize.c \
v3_random.c \
v3_scalar.c \
v3_sub.c \
# MATERIALS
CFILES += check_materials.c \
assign_mat_tex.c \
# TEXTURES
CFILES += checkerboard.c \
parse_texture.c \
file_textures.c \
parse_bump.c \
OFILES := $(addprefix $(OBJ_DIR)/, $(CFILES:.c=.o))
HEADER_FILES := miniRT.h \
config.h \
objects.h \
INCLUDES := -I$(INC_DIR)
# LIBFT
LIBFT_DIR := libs/libft
LIBFT := $(LIBFT_DIR)/libft.a
LIBFT_FLAGS := -L$(LIBFT_DIR) -lft
INCLUDES += -I$(LIBFT_DIR)
# MLX42
MLX42_DIR := libs/MLX42
MLX42 = $(MLX42_DIR)/build/libmlx42.a
MLX42_FLAGS =
ifeq ($(shell uname),Darwin)
MLX42_FLAGS = -L$(MLX42_DIR)/build -lmlx42 -framework Cocoa -framework OpenGL -framework IOKit -lglfw
else ifeq ($(shell uname),Linux)
MLX42_FLAGS = -L$(MLX42_DIR)/build -lmlx42 -Iinclude -ldl -lglfw -pthread -lm
endif
INCLUDES += -I$(MLX42_DIR)/include/MLX42
# RULES
all: ascii $(NAME)
$(NAME): $(LIBFT) $(MLX42) $(OFILES)
@printf "\n$(YELLOW)Compiling $(NAME)...$(NC)\n"
@$(CC) $(CFLAGS) -o $@ $(OFILES) $(LIBFT_FLAGS) $(MLX42_FLAGS)
@if [ -f $(NAME) ]; then \
echo "$(GREEN)$(NAME) compiled successfully!$(NC)"; \
echo "$(CYAN)Run with ./$(NAME)$(NC)"; \
echo "------------------------------------------------"; \
else \
echo "$(RED)$(NAME) failed to compile$(NC)"; \
fi
$(OBJ_DIR)/%.o: %.c $(HEADER_FILES) | $(OBJ_DIR)
@$(eval CURRENT := $(shell echo $$(($(CURRENT) + 1))))
@$(eval PERCENT := $(shell echo $$(($(CURRENT) * 100 / $(TOTAL_SRCS)))))
@printf "$(CLEAR_LINE)$(YELLOW)Compiling $(PERCENT)%% [$(CURRENT)/$(TOTAL_SRCS)] $(ITALIC_LIGHT_YELLOW)$<$(NC) "
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(OBJ_DIR):
@echo "$(YELLOW)Creating obj directory...$(NC)"
@mkdir -p $(OBJ_DIR)
$(LIBFT):
@echo "$(YELLOW)Compiling libft...$(NC)"
@if [ ! -d $(LIBFT_DIR) ]; then mkdir -p $(LIBFT_DIR); fi
@git submodule update --remote --init -q
@$(MAKE) -C $(LIBFT_DIR)
$(MLX42):
@echo "$(YELLOW)Compiling mlx42...$(NC)"
@if [ ! -d $(MLX42_DIR)/build ]; then mkdir -p $(MLX42_DIR)/build; fi
@git submodule update --remote --init -q
@cd $(MLX42_DIR)/build && cmake .. && make -j4
clean:
@echo "$(RED)Cleaning $(NAME)...\n$(NC)"
@echo "$(RED)Removing object files...$(NC)"
@rm -rf $(OBJ_DIR)
@echo "$(RED)Cleaning libft...$(NC)"
@$(MAKE) -C $(LIBFT_DIR) clean
@echo "$(RED)Cleaning mlx42...$(NC)"
@$(MAKE) -C $(MLX42_DIR)/build clean
fclean: clean
@echo "$(RED)Removing binary files...$(NC)"
@rm -f $(NAME)
@$(MAKE) -C $(LIBFT_DIR) fclean
re: fclean all
norm:
@norminette $(SRC_DIRS) $(INC_DIR) $(LIBFT_DIR) | grep "Error" || echo "$(GREEN)Norme OK$(NC)"
debug: CFLAGS += -g
debug: CFLAGS += -DDEBUG=1
debug: clean all
sanitize: CFLAGS += -g -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment
sanitize: clean all
debug_thread: CFLAGS += -g
debug_thread: CFLAGS += -fsanitize=thread
debug_thread: clean all
hd: CFLAGS += -DWIN_WIDTH=1920 -DWIN_HEIGHT=1080
hd: clean all
.PHONY: all clean fclean re norm ascii debug debug_thread hd sanitize
# colors:
GREEN = \033[0;32m
LIGHT_GREEN = \033[0;92m
RED = \033[0;31m
YELLOW = \033[0;33m
LIGHT_YELLOW = \033[0;93m
ITALIC_LIGHT_YELLOW = \033[3;93m
CYAN = \033[0;36m
NC = \033[0m
CLEAR_LINE = \033[2K\r
ASCII_ART = $(CYAN)
# decoration:
ascii:
@echo "------------------------------------------------"
@echo "$(CYAN)"
@echo " __ ___ "
@echo " |\/| | |\ | | |__) | "
@echo " | | | | \| | | \ | "
@echo " "
@echo "$(NC)"
@echo "------------------------------------------------"
BAR_WIDTH = 50
TOTAL_SRCS = $(words $(CFILES))