-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
297 lines (255 loc) · 9.36 KB
/
Makefile
File metadata and controls
297 lines (255 loc) · 9.36 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: zfarah <zfarah@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/15 20:55:03 by jpelline #+# #+# #
# Updated: 2025/11/11 14:09:12 by zfarah ### ########.fr #
# #
# **************************************************************************** #
# ████████████
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ SETTINGS ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Project configuration
NAME := miniRT
CC := cc
# Compiler flags
CFLAGS := -Wall -Wextra -Werror
DEBUG_FLAGS := -g3 -fsanitize=address -fsanitize=undefined
OPTFLAGS := -Ofast -ffast-math -march=native -flto -funroll-loops -fomit-frame-pointer
# Directory structure
SRC_DIR := src
OBJ_DIR := obj
LIB_DIR := lib
DEP_DIR := $(OBJ_DIR)/.deps
# Libraries
LIBFT_DIR := $(LIB_DIR)/libft
LIBFT := $(LIBFT_DIR)/libft.a
MLX_PATH := $(LIB_DIR)/MLX42/build/
MLX_NAME := libmlx42.a
MLX_BPATH := MLX42/
MLX := $(MLX_PATH)$(MLX_NAME)
# Include paths and libraries
INC := -I./include -I$(LIB_DIR)/MLX42/include/MLX42 -I$(LIBFT_DIR)/include
# Dependency generation flags
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d
# Additional flags
LDFLAGS = -L$(LIBFT_DIR) -lft -L$(MLX_PATH) -lmlx42
# Detect the operating system
UNAME_S := $(shell uname -s)
# Set OS-specific variables
ifeq ($(UNAME_S),Linux)
LDFLAGS += -lglfw -lXext -lX11 -lm -ldl -pthread
endif
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -ldl /opt/homebrew/opt/glfw/lib/libglfw.dylib -pthread -lm
endif
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ VISUAL STYLING ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Terminal colors for build output
BOLD := $(shell tput bold)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
BLUE := $(shell tput setaf 4)
MAGENTA := $(shell tput setaf 5)
CYAN := $(shell tput setaf 6)
WHITE := $(shell tput setaf 7)
RESET := $(shell tput sgr0)
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ SOURCE FILES ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Virtual path
VPATH := $(SRC_DIR): \
$(SRC_DIR)/parsing: \
$(SRC_DIR)/primitives: \
$(SRC_DIR)/geometry: \
$(SRC_DIR)/MLX: \
$(SRC_DIR)/raytracer \
$(SRC_DIR)/threads \
$(SRC_DIR)/textures:
# Parsing and syntax analysis
SRCS_MAIN := \
main.c \
utils.c \
parsing.c \
parse_ambient.c \
parse_camera.c \
parse_cylinder.c \
parse_light.c \
parse_paraboloid.c \
parse_plane.c \
parse_sphere.c \
parse_cube.c \
autosave.c \
autosave_utils.c \
autosave_utils2.c \
cube_utils.c \
cleanup.c \
shadow.c \
parse_textures.c \
parsing_utility.c \
parsing_utility2.c \
camera_utils.c \
parse_skybox.c \
skybox.c \
color.c \
color2.c \
viewport.c \
vectors.c \
vectors2.c \
vectors3.c \
vectors4.c \
maths.c \
raytracer.c \
intersection.c \
sphere.c \
fps.c \
init.c \
key_hooks.c \
resize_hook.c \
plane.c \
hit.c \
draw.c \
threads.c \
rotation.c \
move_camera.c \
move_objects.c \
scale_objects.c \
scale_objects_utils.c \
vector.c \
light.c \
cylinder.c \
circle.c \
orthonormal_basis.c \
phong.c \
phong_utils.c \
ray.c \
paraboloid.c \
paraboloid_utils.c \
plane_uv.c \
cube_uv.c \
texture.c \
sphere_uv.c \
refraction.c \
reflection.c \
cube.c
# Combine all source files
SRCS := \
$(SRCS_MAIN)
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ BUILD VARIABLES ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Object files and build tracking
OBJS := $(addprefix $(OBJ_DIR)/,$(SRCS:.c=.o))
TOTAL_SRCS := $(words $(SRCS))
# Build markers and progress tracking
MARKER_STANDARD := .standard_build
PROGRESS_FILE := $(OBJ_DIR)/.progress
# Utility variables for build optimization
LATEST_SRC := $(shell find src -name "*.c" | \
xargs ls -t 2>/dev/null | head -1)
OBJ_FILES_EXIST := $(shell [ -n "$(wildcard $(OBJ_DIR)/*.o)" ] && echo yes)
# Looking for updated header files
LATEST_HEADER := $(shell find include \
-name "*.h" 2>/dev/null | xargs ls -t \
2>/dev/null | head -1)
# Check if binary is up to date
is_up_to_date = \
[ -f $(NAME) ] && \
[ "$(NAME)" -nt $(LATEST_SRC) ] && \
[ "$(NAME)" -nt $(LATEST_HEADER) ] && \
[ "$(OBJ_FILES_EXIST)" = "yes" ]
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ BUILD TARGETS ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Default target with intelligent rebuild detection
all:
@if [ -f $(MARKER_STANDARD) ] && $(is_up_to_date) 2>/dev/null; then \
echo ">$(BOLD)$(YELLOW) $(NAME) is already up to date.$(RESET)"; \
else \
echo ">$(BOLD)$(WHITE) Starting to build $(NAME)...$(RESET)"; \
$(MAKE) $(NAME) --no-print-directory; \
touch $(MARKER_STANDARD); \
echo ">$(BOLD)$(GREEN) All components built successfully!$(RESET)"; \
fi
# Main executable linking with dependency checking
$(NAME): $(OBJS) $(LIBFT) $(MLX)
@echo ">$(BOLD)$(GREEN) Linking $(NAME)...$(RESET)"
@$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(OPTFLAGS) $(LDFLAGS)
@touch $(MARKER_STANDARD)
@rm -f $(PROGRESS_FILE)
@echo ">$(BOLD)$(GREEN) $(NAME) successfully compiled!$(RESET)"
# Individual object file compilation with progress tracking
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR) $(DEP_DIR)
@if [ -f $(PROGRESS_FILE) ]; then \
CURRENT=$$(cat $(PROGRESS_FILE)); \
NEXT=$$((CURRENT + 1)); \
echo "$$NEXT" > $(PROGRESS_FILE); \
printf "> [%3d%%] $(CYAN)(%d/%d files) Compiling $<... $(RESET)\n" \
$$((NEXT*100/$(TOTAL_SRCS))) $$((NEXT)) $(TOTAL_SRCS); \
fi
@$(CC) $(CFLAGS) $(OPTFLAGS) $(DEPFLAGS) -c $< -o $@ $(INC)
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ ADDITIONAL TARGETS ■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Directory creation and dependency management
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
@echo "0" > $(PROGRESS_FILE)
# Include auto-generated dependency files
-include $(wildcard $(DEP_DIR)/*.d)
$(DEP_DIR): | $(OBJ_DIR)
@mkdir -p $@
# build libft if needed
$(LIBFT):
@echo ">$(MAGENTA) Building libft library...$(RESET)"
@$(MAKE) -sC $(LIBFT_DIR) --no-print-directory
# Build MLX42 if needed
$(MLX):
@echo "$(CYAN) Building MLX42 library...$(RESET)"
@cd $(LIB_DIR) && \
git clone -q --depth 1 \
--branch v2.4.1 \
--single-branch \
git@github.com:codam-coding-college/MLX42.git> /dev/null 2>&1
@echo "$(BOLD)$(GREEN)✅ MLX42 successfully cloned!$(RESET)"
@cd $(LIB_DIR)/$(MLX_BPATH) && cmake -B build > /dev/null 2>&1
@echo "$(BOLD)$(GREEN)✅ MLX42 successfully built to ./lib/MLX42/build$(RESET)"
@$(MAKE) -sC $(MLX_PATH) --no-print-directory
@echo "$(BOLD)$(GREEN)✅ $(MLX) successfully compiled!$(RESET)"
# Development and debugging build configuration
debug: CFLAGS += $(DEBUG_FLAGS)
debug: OPTFLAGS := -O0
debug: fclean $(NAME)
@echo ">$(BOLD)$(CYAN) Debug build completed!$(RESET)"
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CLEAN TARGETS ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Remove object files and build artifacts
clean:
@if [ -d $(OBJ_DIR) ]; then \
echo "> [ $(NAME) ] $(YELLOW) Cleaning object files...$(RESET)"; \
rm -rf $(OBJ_DIR); \
printf "> [ %-5s ] %b %s Object files cleaned!%b\n" "$(NAME)" \
"$(YELLOW)" "$(NAME)" "$(RESET)"; \
else \
echo "> [ $(NAME) ] $(BOLD)$(YELLOW) Nothing to be done with \
$(RESET)$(WHITE)clean$(RESET)"; \
fi
# Complete cleanup including executables and external libraries
fclean: clean
@if [ -f $(NAME) ]; then \
echo "> [ $(NAME) ] $(YELLOW) Removing $(NAME)...$(RESET)"; \
rm -f $(NAME); \
rm -f $(MARKER_STANDARD); \
printf "> [ %-5s ] %b %s removed!%b\n" "$(NAME)" "$(YELLOW)" \
"$(NAME)" "$(RESET)"; \
else \
echo "> [ $(NAME) ] $(BOLD)$(YELLOW) Nothing to be done with \
$(RESET)$(BOLD)$(WHITE)fclean$(RESET)"; \
fi
@if [ -f $(LIBFT) ]; then \
$(MAKE) -C $(LIBFT_DIR) fclean --no-print-directory; \
else \
echo "> [ libft ] $(BOLD)$(YELLOW) Nothing to be done with \
$(RESET)$(BOLD)$(WHITE)fclean$(RESET)"; \
fi
# Full rebuild from clean slate
re:
@echo "> [ $(NAME) ] $(BOLD)$(WHITE) Rebuilding from scratch...$(RESET)"
@$(MAKE) fclean --no-print-directory
@$(MAKE) $(NAME) --no-print-directory
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ TARGET DECLARATIONS ■■■■■■■■■■■■■■■■■■■■■■■■■ #
# Preserve intermediate object files and declare phony targets
.SECONDARY: $(OBJS)
.PHONY: all debug clean fclean re