-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
300 lines (260 loc) · 9.74 KB
/
Copy pathMakefile
File metadata and controls
300 lines (260 loc) · 9.74 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
298
299
300
# Program name
NAME = cub3D
# Compiler and flags
CC = cc
CFLAGS = -Wall -Wextra -Werror -O3
# Directories
SRC_MANDATORY = src_mandatory
SRC_BONUS = src_bonus
OBJ_MANDATORY = obj_mandatory
OBJ_BONUS = obj_bonus
INCLUDES_MANDATORY = includes_mandatory/cub3d.h
INCLUDES_BONUS = includes_bonus/cub3d.h
LIBFT_DIR = Libft
# Platform detection
OS = $(shell uname)
MAKE = make -C
MKDIR = mkdir -p
RM = rm -rf
# Source files for mandatory version
MANDATORY_MAIN_FILES = main.c \
memory_management.c \
initialize_game_struct.c \
validations.c \
destroy_mlx_memory.c \
free_memory.c
MANDATORY_PARSING_FILES = parsing/parse_main.c \
parsing/parse_utils.c \
parsing/parse_rgb_texture.c \
parsing/parse_rgb_helper.c \
parsing/extract_map_statistics.c \
parsing/map_statistics.c \
parsing/wall_validation.c \
parsing/flood_fill.c
MANDATORY_GAME_FILES = game/game_init.c \
game/input_handling.c \
game/handle_keyboard_input.c \
game/player_movement.c \
game/player_movement_utils.c
MANDATORY_RAYCAST_FILES = raycasting/raycasting.c \
raycasting/raycasting_utils.c \
raycasting/rendering.c \
raycasting/drawing.c \
raycasting/drawing_utils.c \
raycasting/texture_coordinate.c
# Source files for bonus version
BONUS_MAIN_FILES = main.c \
memory_management.c \
initialize_game_struct.c \
validations.c \
destroy_mlx_memory.c \
free_memory.c
BONUS_PARSING_FILES = parsing/parse_main.c \
parsing/parse_utils.c \
parsing/parse_rgb_texture.c \
parsing/parse_rgb_helper.c \
parsing/extract_map_statistics.c \
parsing/map_statistics.c \
parsing/wall_validation.c \
parsing/flood_fill.c
BONUS_GAME_FILES = game/game_init.c \
game/input_handling.c \
game/handle_keyboard_input.c \
game/player_movement.c \
game/player_movement_utils.c \
game/game_init_bonus.c
BONUS_RAYCAST_FILES = raycasting/raycasting.c \
raycasting/raycasting_utils.c \
raycasting/rendering.c \
raycasting/drawing.c \
raycasting/drawing_utils.c \
raycasting/minimap.c \
raycasting/minimap_utils.c \
raycasting/rays_on_minimap.c \
raycasting/texture_coordinate.c
# All source files
MANDATORY_SRCS = $(addprefix $(SRC_MANDATORY)/, $(MANDATORY_MAIN_FILES) $(MANDATORY_PARSING_FILES) $(MANDATORY_GAME_FILES) $(MANDATORY_RAYCAST_FILES))
BONUS_SRCS = $(addprefix $(SRC_BONUS)/, $(BONUS_MAIN_FILES) $(BONUS_PARSING_FILES) $(BONUS_GAME_FILES) $(BONUS_RAYCAST_FILES))
# Object files
MANDATORY_OBJS = $(MANDATORY_SRCS:$(SRC_MANDATORY)/%.c=$(OBJ_MANDATORY)/%.o)
BONUS_OBJS = $(BONUS_SRCS:$(SRC_BONUS)/%.c=$(OBJ_BONUS)/%.o)
# Library files
LIBFT = $(LIBFT_DIR)/libft.a
# Math library
MATH_LIB = -lm
# Platform-specific MLX configuration
ifeq ($(OS), Linux)
# Check if system MLX is available by looking for libmlx files
# Try multiple common locations for system-installed MLX
ifneq ($(shell find /usr/lib* /usr/local/lib* -name "libmlx*" 2>/dev/null | head -1), )
# System MLX found
MLX_LIB = # No local MLX library needed
INCLUDES_MLX = -I/usr/include -I/usr/local/include
MLX_FLAGS = -lmlx -lXext -lX11
else ifneq ($(shell ldconfig -p 2>/dev/null | grep libmlx), )
# System MLX found via ldconfig
MLX_LIB = # No local MLX library needed
INCLUDES_MLX = -I/usr/include -I/usr/local/include
MLX_FLAGS = -lmlx -lXext -lX11
else ifeq ($(shell test -d mlx_linux && echo "yes"), yes)
# No system MLX, but mlx_linux folder exists
MLX_DIR = mlx_linux
MLX_LIB = $(MLX_DIR)/libmlx.a
INCLUDES_MLX = -I$(MLX_DIR)
MLX_FLAGS = -L$(MLX_DIR) -lmlx -lXext -lX11
else
# No MLX found anywhere - will try system MLX and let linker handle it
MLX_LIB = # No local MLX library needed
INCLUDES_MLX = -I/usr/include -I/usr/local/include
MLX_FLAGS = -lmlx -lXext -lX11
endif
else ifeq ($(OS), Darwin)
# macOS - use local mlx_macos
MLX_DIR = mlx_macos
MLX_LIB = $(MLX_DIR)/libmlx.a
INCLUDES_MLX = -I$(MLX_DIR)
MLX_FLAGS = -L$(MLX_DIR) -lmlx -framework OpenGL -framework AppKit
endif
# Include flags
MANDATORY_INCLUDES = -Iincludes_mandatory -I$(LIBFT_DIR) $(INCLUDES_MLX)
BONUS_INCLUDES = -Iincludes_bonus -I$(LIBFT_DIR) $(INCLUDES_MLX)
# Colors for pretty output
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[0;33m
BLUE = \033[0;34m
MAGENTA = \033[0;35m
CYAN = \033[0;36m
WHITE = \033[0;37m
RESET = \033[0m
# Emojis
SUCCESS = ✅
BUILD = 🔨
CLEAN = 🧹
# ================================== RULES =================================== #
# Default target (mandatory version)
all: $(LIBFT) $(MLX_LIB) $(OBJ_MANDATORY) mandatory
# Mandatory version
mandatory: $(MANDATORY_OBJS) $(INCLUDES_MANDATORY) Makefile
@echo "$(BUILD) $(GREEN)Compiling mandatory $(NAME)...$(RESET)"
@$(CC) $(CFLAGS) $(MANDATORY_OBJS) -L$(LIBFT_DIR) -lft $(MLX_FLAGS) $(MATH_LIB) -o $(NAME)
@echo "$(SUCCESS) $(YELLOW)Mandatory $(NAME) FINISHED$(RESET)"
# Bonus version
bonus: $(LIBFT) $(MLX_LIB) $(OBJ_BONUS) $(INCLUDES_BONUS) bonus_build
bonus_build: $(BONUS_OBJS) Makefile
@echo "$(BUILD) $(MAGENTA)Compiling bonus $(NAME)...$(RESET)"
@$(CC) $(CFLAGS) $(BONUS_OBJS) -L$(LIBFT_DIR) -lft $(MLX_FLAGS) $(MATH_LIB) -o $(NAME)
@echo "$(MAGENTA)$(SUCCESS) Bonus $(NAME) FINISHED with all features enabled!$(RESET)"
# Create object directories
$(OBJ_MANDATORY):
@$(MKDIR) $(OBJ_MANDATORY)
$(OBJ_BONUS):
@$(MKDIR) $(OBJ_BONUS)
# Build libft
$(LIBFT):
@echo "$(BUILD) $(CYAN)Making libft...$(RESET)"
@$(MAKE) $(LIBFT_DIR) --no-print-directory
@echo "$(SUCCESS) $(YELLOW)Made libft!$(RESET)"
# Build MinilibX (only if MLX_DIR is defined - local MLX)
ifdef MLX_DIR
$(MLX_LIB):
@echo "$(BUILD) $(CYAN)Making MinilibX ($(MLX_DIR))...$(RESET)"
@$(MAKE) $(MLX_DIR) --no-print-directory
@echo "$(SUCCESS) $(YELLOW)Made MinilibX!$(RESET)"
endif
# Compile mandatory object files
$(OBJ_MANDATORY)/%.o: $(SRC_MANDATORY)/%.c $(INCLUDES_MANDATORY)
@$(MKDIR) $(dir $@)
@echo "$(YELLOW)Compiling mandatory $<...$(RESET)"
@$(CC) $(CFLAGS) $(MANDATORY_INCLUDES) -c $< -o $@
# Compile bonus object files
$(OBJ_BONUS)/%.o: $(SRC_BONUS)/%.c $(INCLUDES_BONUS)
@$(MKDIR) $(dir $@)
@echo "$(YELLOW)Compiling bonus $<...$(RESET)"
@$(CC) $(CFLAGS) $(BONUS_INCLUDES) -c $< -o $@
# Clean object files
clean:
@$(RM) $(OBJ_MANDATORY) $(OBJ_BONUS)
@$(MAKE) $(LIBFT_DIR) clean --no-print-directory
ifdef MLX_DIR
@if [ -d "$(MLX_DIR)" ]; then $(MAKE) $(MLX_DIR) clean --no-print-directory; fi
endif
@echo "$(CLEAN) $(RED)Cleaned!$(RESET)"
# Clean everything
fclean: clean
@$(RM) $(NAME)
@$(MAKE) $(LIBFT_DIR) fclean --no-print-directory
ifdef MLX_DIR
@if [ -d "$(MLX_DIR)" ]; then $(MAKE) $(MLX_DIR) fclean --no-print-directory 2>/dev/null || true; fi
endif
@echo "$(CLEAN) $(RED)Full Cleaned!$(RESET)"
# Rebuild everything
re: fclean all
# Re-bonus
re_bonus: fclean bonus
# Help target
help:
@echo "$(CYAN)Available targets:$(RESET)"
@echo " $(GREEN)all$(RESET) - Build the mandatory version (default)"
@echo " $(GREEN)mandatory$(RESET) - Build the mandatory version explicitly"
@echo " $(GREEN)bonus$(RESET) - Build the bonus version with all features"
@echo " $(GREEN)clean$(RESET) - Remove object files"
@echo " $(GREEN)fclean$(RESET) - Remove object files and executable"
@echo " $(GREEN)re$(RESET) - Rebuild the mandatory version"
@echo " $(GREEN)re_bonus$(RESET) - Rebuild the bonus version"
@echo " $(GREEN)help$(RESET) - Show this help message"
@echo " $(GREEN)info$(RESET) - Show project information"
# Check for coding style (if norminette is available)
norm:
@if command -v norminette >/dev/null 2>&1; then \
echo "$(BLUE)Checking coding style for mandatory...$(RESET)"; \
norminette $(SRC_MANDATORY) $(INCLUDES_MANDATORY); \
echo "$(BLUE)Checking coding style for bonus...$(RESET)"; \
norminette $(SRC_BONUS) $(INCLUDES_BONUS); \
else \
echo "$(YELLOW)⚠️ norminette not found, skipping style check$(RESET)"; \
fi
# Test the program with a sample map
test: $(NAME)
@echo "$(CYAN)Testing with sample map...$(RESET)"
@if [ -f maps/simple.cub ]; then \
./$(NAME) maps/simple.cub; \
else \
echo "$(RED)❌ No test map found at maps/simple.cub$(RESET)"; \
fi
# Install dependencies
install-deps:
@echo "$(BLUE)Installing dependencies...$(RESET)"
ifeq ($(OS), Linux)
@if command -v apt >/dev/null 2>&1; then \
sudo apt update && sudo apt install -y build-essential libx11-dev libxext-dev; \
echo "$(GREEN)✅ Dependencies installed for Ubuntu/Debian$(RESET)"; \
elif command -v yum >/dev/null 2>&1; then \
sudo yum groupinstall -y "Development Tools" && sudo yum install -y libX11-devel libXext-devel; \
echo "$(GREEN)✅ Dependencies installed for RHEL/CentOS$(RESET)"; \
elif command -v pacman >/dev/null 2>&1; then \
sudo pacman -S base-devel libx11 libxext; \
echo "$(GREEN)✅ Dependencies installed for Arch Linux$(RESET)"; \
else \
echo "$(YELLOW)⚠️ Package manager not detected. Please install X11 and Xext development libraries manually.$(RESET)"; \
fi
else ifeq ($(OS), Darwin)
@echo "$(GREEN)On macOS, using local MinilibX from $(MLX_DIR)$(RESET)"
endif
# Show project info
info:
@echo "$(CYAN)Project Information:$(RESET)"
@echo " Name: $(GREEN)$(NAME)$(RESET)"
@echo " Compiler: $(GREEN)$(CC)$(RESET)"
@echo " Flags: $(GREEN)$(CFLAGS)$(RESET)"
@echo " Platform: $(GREEN)$(OS)$(RESET)"
@echo " Mandatory source files: $(GREEN)$(words $(MANDATORY_SRCS))$(RESET)"
@echo " Bonus source files: $(GREEN)$(words $(BONUS_SRCS))$(RESET)"
ifdef MLX_DIR
@echo " MLX: $(GREEN)Local ($(MLX_DIR))$(RESET)"
else
@echo " MLX: $(GREEN)System-installed$(RESET)"
endif
@echo " MLX Flags: $(GREEN)$(MLX_FLAGS)$(RESET)"
# Declare phony targets
.PHONY: all mandatory bonus bonus_build clean fclean re re_bonus help norm test install-deps info