-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
135 lines (105 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
128
129
130
131
132
133
134
135
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mpeulet <mpeulet@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/04/11 11:29:48 by OrioPrisc #+# #+# #
# Updated: 2024/02/13 18:54:57 by mpeulet ### ########.fr #
# #
# **************************************************************************** #
CC = cc
SRC_COMMON = raycast.c \
math_utils.c \
vec2d.c \
vec2d_2.c \
env.c \
image.c \
image2.c \
draw.c \
deal_key.c \
hooks.c \
door.c \
collision.c \
sprites.c \
utils.c \
map.c \
vector_to_2dtab.c \
map_to_lines/map_to_lines.c \
map_to_lines/need_lines.c \
map_to_lines/map_to_lines_bonus.c \
mini_map/mini_map.c \
parsing/convert_cub_to_vector.c \
parsing/debug_print_cub.c \
parsing/error_management.c \
parsing/extract_colors.c \
parsing/flood_fill.c \
parsing/extract_textures.c \
parsing/find_player.c \
parsing/parse_utils.c \
ALL_SRC = $(SRC_COMMON) main.c
NAME = cub3D
NAME_BONUS = cub3D_bonus
OBJ_FOLDER = objs/
CFLAGS = -Wall -Wextra -Werror -g
SRC_FOLDER = srcs/
INC_FOLDER = includes/
HEADERS_FOLDER = includes/\
libft/includes/\
minilibx-linux/\
LIBS = libft/libft.a\
libft/libftprintf.a\
libft/libgetnextline.a\
minilibx-linux/libmlx.a\
#here to ensure things get pulled properly
SUBMODULES = libft/.git\
libft/ftprintf/.git\
libft/getnextline/.git\
minilibx-linux/.git\
LFLAGS = -Llibft -Lminilibx-linux -lftprintf -lvector -lgetnextline -lft -lmlx -lXext -lX11 -lm -lbsd
DEPENDS := $(patsubst %.c,$(OBJ_FOLDER)%.d,$(ALL_SRC))
OBJS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(SRC_COMMON) main.c)
OBJS_BONUS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(SRC_COMMON) main_bonus.c)
COMMANDS := $(patsubst %.c,$(OBJ_FOLDER)%.cc,$(ALL_SRC))
all: $(NAME) compile_commands.json
bonus: $(NAME_BONUS) compile_commands.json
-include $(DEPENDS)
$(SUBMODULES) :
git submodule update --init --recursive
%.a: | $(SUBMODULES)
make -C $(@D) MAKEFLAGS=
$(NAME_BONUS): $(LIBS) $(OBJS_BONUS) | $(SUBMODULES)
$(CC) $(CFLAGS) $(OBJS_BONUS) $(LFLAGS) -o $@
$(NAME): $(LIBS) $(OBJS) | $(SUBMODULES)
$(CC) $(CFLAGS) $(OBJS) $(LFLAGS) -o $@
COMP_COMMAND = $(CC) -c $(CFLAGS) $(addprefix -I,$(HEADERS_FOLDER)) -MMD -MP $< -o $@
CONCAT = awk 'FNR==1 && NR!=1 {print ","}{print}'
$(OBJ_FOLDER)main_bonus.o $(OBJ_FOLDER)main.cc: $(SRC_FOLDER)main.c Makefile | $(SUBMODULES)
@mkdir -p $(@D)
$(COMP_COMMAND) -DBONUS=1
@printf '{\n\t"directory" : "$(shell pwd)",\n\t"command" : "$(COMP_COMMAND)",\n\t"file" : "$<"\n}' > $(OBJ_FOLDER)main.cc
$(OBJ_FOLDER)%.o $(OBJ_FOLDER)%.cc: $(SRC_FOLDER)%.c Makefile | $(SUBMODULES)
@mkdir -p $(@D)
$(COMP_COMMAND)
@printf '{\n\t"directory" : "$(shell pwd)",\n\t"command" : "$(COMP_COMMAND)",\n\t"file" : "$<"\n}' > $(OBJ_FOLDER)$*.cc
compile_commands.json : $(COMMANDS) Makefile
@echo "Making compile_commands.json"
@echo "[" > compile_commands.json
@$(CONCAT) $(COMMANDS) >> compile_commands.json
@echo "]" >> compile_commands.json
clean: | $(SUBMODULES)
rm -f $(OBJS_BONUS) $(OBJS) $(DEPENDS) $(COMMANDS)
for lib in $(shell dirname $(LIBS)); do \
make -C $$lib clean; \
done
fclean: clean | $(SUBMODULES)
rm -f $(NAME) compile_commands.json
make -C libft fclean
re: fclean all
norm:
@norminette $(SRC_FOLDER) $(INC_FOLDER) | grep -A1 -B1 Error | grep -v 'OK!' || true
.PHONY: all clean fclean re norm bonus
.SUFFIXES:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules