-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
112 lines (94 loc) · 3.74 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: sebasnadu <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/09/13 18:41:02 by sebasnadu #+# #+# #
# Updated: 2023/11/01 18:23:58 by johnavar ### ########.fr #
# #
# **************************************************************************** #
# COLORS
DEFAULT = \033[0;39m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
UNAME = $(shell uname)
NAME = so_long
# LIBFT
LIBFT_DIR = ./libft
LIBFT_PATH = $(LIBFT_DIR)/libft.a
LIBFT_FLAGS = -L $(LIBFT_DIR) -lft
CC = cc
RM = rm -rf
PRINTF = printf
ifeq ($(DEBUG), 1)
CFLAGS = -g -Wall -Wextra -Werror -fsanitize=address
else
CFLAGS = -Wall -Wextra -Werror
endif
INC_DIR = ./includes
SRC_DIR = ./srcs
OBJ_DIR = ./obj
SRC_SUB_DIRS = $(shell find $(SRC_DIR) -type d -not -path '$(SRC_DIR)')
SRC = $(foreach dir, $(SRC_SUB_DIRS), $(wildcard $(dir)/*.c))
OBJ_SUB_DIRS = $(subst $(SRC_DIR), $(OBJ_DIR), $(SRC_SUB_DIRS))
# OBJ = $(subst $(SRC_SUB_DIR), $(OBJ_SUB_DIR), $(SRC:.c=.o))
OBJ = $(subst $(SRC_DIR), $(OBJ_DIR), $(SRC:.c=.o))
ifeq ($(UNAME), Darwin)
GFLAGS = -L$(GPATH) -lmlx -framework OpenGL -framework AppKit -lz
GPATH = ./minilibx_opengl
MLX_PATH = $(GPATH)/libmlx.a
INCLUDES = -I./includes -I$(LIBFT_DIR)/includes -I$(GPATH)
LIBS = -L$(LIBFT_DIR) -lft
else
# GFLAGS = -I$(GPATH) -L$(GPATH) -lmlx -lXext -lX11 -lm -lbsd
GFLAGS = -L$(GPATH) -lmlx -lXext -lX11 -lXrender -lm
GPATH = minilibx-linux
MLX_PATH = $(GPATH)/libmlx.a
INCLUDES = -I./includes -I$(LIBFT_DIR)/includes -I$(GPATH)
LIBS = -L$(LIBFT_DIR) -lft
endif
# progress bar
SRC_COUNT_TOT := $(shell expr $(shell echo -n $(SRC) | wc -w) - $(shell ls -l $(OBJ_DIR) 2>&1 | grep ".o" | wc -l) + 1)
ifeq ($(shell test $(SRC_COUNT_TOT) -le 0; echo $$?),0)
SRC_COUNT_TOT := $(shell echo -n $(SRC) | wc -w)
endif
SRC_COUNT := 0
SRC_PCT = $(shell expr 100 \* $(SRC_COUNT) / $(SRC_COUNT_TOT))
all : $(NAME)
$(NAME) : $(OBJ) _libft _mlx
@$(CC) $(CFLAGS) $(OBJ) $(LIBS) $(GFLAGS) -o $@
@$(PRINTF) "\r%100s\r$(GREEN)$(NAME): Compilation success 🎉!$(DEFAULT)\n"
$(OBJ): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
@mkdir -p $(OBJ_SUB_DIRS)
@$(eval SRC_COUNT = $(shell expr $(SRC_COUNT) + 1))
@$(PRINTF) "\r%100s\r[ %d/%d (%d%%) ] Compiling $(BLUE)$<$(DEFAULT)..." "" $(SRC_COUNT) $(SRC_COUNT_TOT) $(SRC_PCT)
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean :
@make clean -C $(LIBFT_DIR)
@make clean -C $(GPATH)
@$(PRINTF) "$(CYAN)Cleaning up object files in $(OBJ_DIR)...$(DEFAULT)\n"
@$(RM) $(OBJ_DIR)
fclean : clean
@$(PRINTF) "$(CYAN)Cleaning up $(NAME)...$(DEFAULT)\n"
@$(RM) $(NAME)
@$(PRINTF) "$(CYAN)Cleaning up $(LIBFT_PATH)...$(DEFAULT)\n"
@$(RM) $(LIBFT_PATH)
@$(PRINTF) "$(CYAN)Cleaning up $(MLX_PATH)...$(DEFAULT)\n"
@$(RM) $(MLX_PATH)
re : fclean all
_libft :
@make -C $(LIBFT_DIR)
_mlx :
@make -C $(GPATH)
norminette: | $(LIBFT_DIR)
@$(PRINTF) "$(CYAN)\nChecking norm for $(NAME)...$(DEFAULT)\n"
@norminette -R CheckForbiddenSourceHeader $(SRC_DIR) $(LIBFT_DIR) includes
.PHONY : all clean fclean re _libft _mlx norminette