-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
128 lines (109 loc) · 4.14 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: cwenz <cwenz@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/07/10 13:02:34 by cwenz #+# #+# #
# Updated: 2023/08/08 14:49:43 by cwenz ### ########.fr #
# #
# **************************************************************************** #
# Name of the binary executable
NAME := so_long
# Username and brew location
BREW := .brew
# Compiler and flags
# -fsanitize=address -g
CC := cc
CFLAGS := -Wall -Werror -Wextra
INCLUDES := -I./includes
# Submodules:
## Libft
LIBFT_PATH := libraries/42c-library
LIBFT := libraries/42c-library/libft.a
C_LIBRARY_MAKE := make -C libraries/42c-library
C_LIBRARY_FCLEAN := make fclean -C libraries/42c-library
## MLX
MLX_PATH := libraries/MLX42
MLX := $(MLX_PATH)/build/libmlx42.a
MLX_FLAGS := ./$(MLX) -Iinclude -lglfw -L"/Users/$(USER)/$(BREW)/opt/glfw/lib/" -framework Cocoa -framework OpenGL -framework IOKit
# Command to remove files
RM := rm -f
# Source file directories
SRC_DIR := ./src/
ANIMATION_DIR := ./src/animation/
COLLECTABLE_DIR := ./src/collectable/
ERROR_DIR := ./src/error/
EXIT_DIR := ./src/exit/
FREE_DIR := ./src/free/
HUD_DIR := ./src/hud/
INIT_DIR := ./src/initialize/
INPUT_DIR := ./src/input/
MAP_DIR := ./src/map/
MOB_DIR := ./src/mob/
TRAP_DIR := ./src/trap/
UTILS_DIR := ./src/utils/
# Source files
SRC_FILES := main.c
ANIMATION_FILES := animation.c animation_utils.c trap_animation_utils.c
COLLECTABLE_FILES := collectables.c collectables_utils.c
ERROR_FILES := error.c
EXIT_FILES := exit.c
FREE_FILES := free.c free_utils.c free_enemy.c
HUD_FILES := hud.c hud_utils.c player_dialogue.c
INIT_FILES := initialize.c
INPUT_FILES := handle_input.c input_utils.c
MAP_FILES := map.c map_utils.c check_map.c check_map_utils.c check_map_utils2.c is_map_solvable.c
MOB_FILES := player.c player_death.c mimic.c enemy.c
TRAP_FILES := trap.c trap_utils.c
UTIL_FILES := utils.c utils2.c
SRC += $(addprefix $(SRC_DIR), $(SRC_FILES))
SRC += $(addprefix $(ANIMATION_DIR), $(ANIMATION_FILES))
SRC += $(addprefix $(COLLECTABLE_DIR), $(COLLECTABLE_FILES))
SRC += $(addprefix $(ERROR_DIR), $(ERROR_FILES))
SRC += $(addprefix $(EXIT_DIR), $(EXIT_FILES))
SRC += $(addprefix $(FREE_DIR), $(FREE_FILES))
SRC += $(addprefix $(HUD_DIR), $(HUD_FILES))
SRC += $(addprefix $(INIT_DIR), $(INIT_FILES))
SRC += $(addprefix $(INPUT_DIR), $(INPUT_FILES))
SRC += $(addprefix $(MAP_DIR), $(MAP_FILES))
SRC += $(addprefix $(MOB_DIR), $(MOB_FILES))
SRC += $(addprefix $(TRAP_DIR), $(TRAP_FILES))
SRC += $(addprefix $(UTILS_DIR), $(UTIL_FILES))
# Object files
OBJ := $(SRC:.c=.o)
# Default target
all: init-submodules $(NAME)
$(NAME): $(OBJ) $(MLX)
@$(C_LIBRARY_MAKE)
@$(CC) $(CFLAGS) $(INCLUDES) $(OBJ) $(LIBFT) $(MLX) $(MLX_FLAGS) -o $(NAME)
@echo $(GREEN)"Linking $(NAME)"$(DEFAULT);
%.o: %.c
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
# Build MLX library
$(MLX):
@cd $(MLX_PATH) && cmake -B build && cmake --build build -j4
# Init submodules
init-submodules:
@if [ -z "$(shell ls -A $(MLX_PATH))" ]; then \
git submodule init $(MLX_PATH); \
git submodule update $(MLX_PATH); \
fi
@if [ -z "$(shell ls -A $(LIBFT_PATH))" ]; then \
git submodule init $(LIBFT_PATH); \
git submodule update $(LIBFT_PATH); \
fi
# Remove all object files
clean:
@$(RM) $(OBJ)
# Remove all generated files
fclean: clean
@$(C_LIBRARY_FCLEAN)
@$(RM) $(NAME)
# Rebuild everything
re: fclean all
.PHONY: all clone clean fclean re
# Colours to make it look nice :)
DEFAULT = "\033[39m"
GREEN = "\033[32m"