-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (108 loc) · 4.04 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: pibouill <[email protected] +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/05/02 13:22:42 by pibouill #+# #+# #
# Updated: 2024/07/10 14:00:09 by pibouill ### ########.fr #
# #
# **************************************************************************** #
NAME := so_long
CC := cc
RM := rm -rf
CFLAGS := -Wall -Werror -Wextra -g
MLX_FLAGS :=
LINUX_FLAGS := -ldl -lglfw -pthread -lm
MACOS_FLAGS := -lglfw -framework Cocoa -framework OpenGL -framework IOKit
SRC_DIR := src
INC_DIR := -I ./inc/
MLX_DIR := lib/MLX42/
MLX_INC := -I ./lib/MLX42/include/MLX42
MLX_A := ./lib/MLX42/build/libmlx42.a
LIB_DIR := lib
LIBFT_DIR := libft
LIBFT_INC := -I ./libft/inc/
BIN_DIR := bin
LIBFT_CUT := $(shell echo $(LIBFT_DIR) | cut -c 4-)
UNAME := $(shell uname -s)
ifeq ($(UNAME), Linux)
MLX_FLAGS += $(LINUX_FLAGS)
endif
ifeq ($(UNAME), Darwin)
MLX_FLAGS += $(MACOS_FLAGS)
endif
################################################################################
## COLORS
ifeq ($(UNAME), Linux)
RED := \e[38;5;196m
ORANGE := \e[38;5;208m
GREEN := \033[0;92m
YELLOW := \033[0;93m
BLUE := \033[0;94m
END_COLOR := \033[0;39m
endif
ifeq ($(UNAME), Darwin)
GREEN := \033[0;92m
YELLOW := \033[0;93m
BLUE := \033[0;94m
RED := \033[0;91m
END_COLOR := \033[0m
endif
################################################################################
## SOURCES
SRC_FILES := main\
args_check\
free_utils\
map_check\
utils\
get_map_info\
build_map_array\
error_utils\
map_path_check\
img_to_map\
moves\
hooks\
update_player
SRC := $(addprefix $(SRC_DIR)/, $(addsuffix .c, $(SRC_FILES)))
OBJ := $(addprefix $(BIN_DIR)/, $(addsuffix .o, $(SRC_FILES)))
################################################################################
## RULES
all: $(NAME)
$(NAME): mlx $(OBJ)
+@make -C libft --no-print-directory
+@$(CC) -o $(NAME) $(OBJ) -L $(LIBFT_DIR) -l $(LIBFT_CUT) $(MLX_A) $(MLX_INC) $(MLX_FLAGS)
+@echo "$(GREEN)[ $(NAME) compiled. ]$(END_COLOR)"
mlx:
+@if [ ! -d $(MLX_DIR) ]; then \
git clone https://github.com/codam-coding-college/MLX42.git $(MLX_DIR); \
cmake $(MLX_DIR) -B $(MLX_DIR)/build && make -C $(MLX_DIR)/build -j4; \
printf "$(GREEN)\n------------------------\n\n$(END_COLOR)"; \
printf "$(GREEN)MLX42 built.\n$(END_COLOR)"; \
printf "$(GREEN)\n------------------------\n$(END_COLOR)"; \
else \
printf "$(GREEN)\n------------------------\n\n$(END_COLOR)"; \
printf "$(GREEN)MLX42 already built.\n$(END_COLOR)"; \
printf "$(GREEN)\n------------------------\n$(END_COLOR)"; \
fi
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c Makefile libft/src/*.c | $(BIN_DIR)
+@$(CC) -c $(CFLAGS) $(INC_DIR) $(LIBFT_INC) $(MLX_INC) $< -o $@
+@echo "$(BLUE)Compiling... $(notdir $<)$(END_COLOR)"
$(BIN_DIR):
+@mkdir $(BIN_DIR)
+@echo "$(YELLOW)Created $(BIN_DIR)/ directory at $(NAME)/$(END_COLOR)"
clean:
+@rm -rf $(BIN_DIR)
+@echo "$(GREEN)$(NAME) object files cleaned.$(END_COLOR)"
+@make clean -C libft --no-print-directory
fclean: clean
+@$(RM) bin $(NAME) libft/libft.a lib/MLX42
+@echo "$(YELLOW)$(NAME) executable file cleaned.$(END_COLOR)"
+@echo "$(YELLOW)lib/MLX42 cleaned.$(END_COLOR)"
+@printf "$(ORANGE)$(NAME) bin/ cleaned\n$(END_COLOR)"
re: fclean all
+@echo "$(RED)Cleaned all and rebuilt $(NAME) and $(LIBFT_DIR)$(END_COLOR)"
################################################################################
## PHONY
.PHONY: all clean fclean re mlx