-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
209 lines (176 loc) · 6.31 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
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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: humbi <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/06/02 16:33:15 by rbetz #+# #+# #
# Updated: 2023/08/31 12:49:12 by humbi ### ########.fr #
# #
# **************************************************************************** #
NAME := miniRT
### ### COMPABILITY ### ###
OS := $(shell uname)
### ### COMPILER ### ###
CC := cc
CFLAGS := -Wall -Wextra -Werror
CFLAGS += -O2 -MMD
#CFLAGS += -g #-fsanitize=address
### ### SOURCES ### ###
VPATH := src/ \
src/camera \
src/parsing \
src/color \
src/intersection \
src/memory \
src/mlx \
src/parsing \
src/ray \
src/rendering \
src/threads \
src/utils \
src/vector
SRC_F := miniRT.c
SRC_F += camera.c
SRC_F += color.c
SRC_F += hit_sphere.c hit_plane.c hit_cylinder.c hit_circle.c hit_square.c
SRC_F += ft_error.c cleanup.c
SRC_F += keyhooks.c setup.c
SRC_F += file_parsing.c print_map.c file_utils.c file_utils_2.c
SRC_F += line_parsing.c ft_split_p.c ft_atof.c
SRC_F += pre_field_check.c line_utils.c pars_error.c
SRC_F += get_resolution.c get_camera.c get_ambient.c get_light.c
SRC_F += get_sphere.c get_plane.c get_cylinder.c get_circle.c get_rect.c
SRC_F += get_square.c insert_vectors.c
SRC_F += ray.c ray_utils.c
SRC_F += hard_shadow.c soft_shadow.c render.c hit_object.c
SRC_F += threads.c
SRC_F += free.c random.c
### ### OBJECTS ### ###
OBJ_D := ./obj
OBJ_F := $(patsubst %.c,$(OBJ_D)/%.o,$(SRC_F))
DEP_F := $(patsubst %.c,$(OBJ_D)/%.d,$(SRC_F))
### ### COLORS ### ###
RED := \033[1;31m
GREEN := \033[1;32m
YELL := \033[1;33m
BLUE := \033[1;34m
WHITE := \033[0m
### ### LIBRARIES ### ###
LIBFT_D := ./lib/libft
LIBFT_F := $(LIBFT_D)/libft.a
LIBFT_U := https://www.github.com/Alphacharge/mylibft
LIBVEC_D := ./lib/libvec
LIBVEC_F := $(LIBVEC_D)/libvec.a
LIBVEC_U := https://www.github.com/Alphacharge/libvec
MLX42_D := ./lib/MLX42
ifeq ($(OS), Darwin)
MLX42_BD := $(MLX42_D)/build
else
MLX42_BD := $(MLX42_D)/build_l
endif
MLX42_F := $(MLX42_BD)/libmlx42.a
MLX42_U := https://www.github.com/codam-coding-college/MLX42
LSAN_D := ./lib/LeakSanitizer
LSAN_F := $(LSAN_D)/liblsan.a
LSAN_U := https://www.github.com/mhahnFr/LeakSanitizer
LIB := -L $(LIBFT_D) -l ft -L $(LIBVEC_D) -l vec -L $(MLX42_BD) -l mlx42
### ### HEADER ### ###
INC_D := ./inc
INC_F := -I $(INC_D) -I $(LIBFT_D) -I $(LIBVEC_D) -I $(MLX42_D)/include/MLX42
#Linux/Mac Compability for Leaksanitizer
ifeq ($(OS), Darwin)
ifeq ($(shell test -d $(LSAN_D) && test -f $(LSAN_F) && echo exists), exists)
INC_F += -Wno-gnu-include-next -I $(LSAN_D)/include
LIB += -L $(LSAN_D) -llsan -lc++
endif
else ifeq ($(OS), Linux)
ifeq ($(shell test -d $(LSAN_D) && test -f $(LSAN_F) && echo exists), exists)
INC_F += -Wno-gnu-include-next -I $(LSAN_D)/include
LIB += -rdynamic -L $(LSAN_D) -llsan -ldl -lstdc++
endif
endif
### ### COMPABILITY ### ###
#Mac Compability for our programm
ifeq ($(OS), Darwin)
LIB += -l glfw
endif
#Linux Compability for our programm
ifeq ($(OS), Linux)
LIB += -lm -ldl -l glfw -lpthread
ifeq ($(shell which cmake), )
@echo "$(BLUE)Install cmake and glfw...$(WHITE)"
@apt-get update
@apt-get install -qq -y libglfw3-dev cmake
endif
endif
### ### RULES ### ###
#make lsan is downloading lsan if its not.
#every make will be with lsan until a clean occurs.
all: message $(LIBFT_F) $(LIBVEC_F) $(MLX42_F)
@$(MAKE) -j $(NAME)
lsan: clean_lsan $(OBJ_D) $(LIBFT_F) $(LIBVEC_F) $(MLX42_F) $(LSAN_F)
@$(MAKE) -j $(NAME)
$(NAME): $(OBJ_D) $(OBJ_F)
$(CC) $(CFLAGS) $(INC_F) -o $(NAME) $(OBJ_F) $(LIB)
$(OBJ_D)/%.o: %.c
$(CC) $(CFLAGS) $(INC_F) -c $< -o $@
-include $(DEP_F)
$(OBJ_D):
@git config advice.detachedHead false
@mkdir -p $@
$(LIBFT_F):
ifneq ($(shell test -d $(LIBFT_D) && echo exists), exists)
@echo "$(GREEN)Clone libft ...$(WHITE)"
@git clone -q --branch v1.0.0 --recurse-submodules $(LIBFT_U) $(LIBFT_D)
endif
@$(MAKE) -j -C $(LIBFT_D)
$(LIBVEC_F):
ifneq ($(shell test -d $(LIBVEC_D) && echo exists), exists)
@echo "$(GREEN)Clone libvec ...$(WHITE)"
@git clone -q --recurse-submodules $(LIBVEC_U) $(LIBVEC_D)
endif
@$(MAKE) -j -C $(LIBVEC_D)
$(MLX42_F):
ifneq ($(shell test -d $(MLX42_D) && echo exists), exists)
@echo "$(GREEN)Clone MLX42 ...$(WHITE)"
@git clone -q --branch v2.3.0 --recurse-submodules $(MLX42_U) $(MLX42_D)
endif
ifneq ($(shell test -d $(MLX42_BD) && echo exists), exists)
@echo "$(GREEN)Cmake MLX42 ...$(WHITE)"
@cmake -S $(MLX42_D) -B $(MLX42_BD)
endif
@$(MAKE) -j -C $(MLX42_BD)
$(LSAN_F):
ifneq ($(shell test -d $(LSAN_D) && echo exists), exists)
@echo "$(GREEN)Clone LeakSanitizer ...$(WHITE)"
@git clone -q --branch v1.4 --recursive $(LSAN_U) $(LSAN_D)
endif
@echo "$(GREEN)Make LeakSanitizer ...$(WHITE)"
@$(MAKE) -s -C $(LSAN_D)
message:
@echo "$(BLUE)---------------------------------------------------------"
@echo "$(BLUE)|$(RED)\t\t\t\t\t _ _ _\t$(BLUE)|"
@echo "$(BLUE)|$(RED)\t\t\t\t\t /_/_/_/$(YELL)\\ \t$(BLUE)|"
@echo "$(BLUE)|$(RED)\t\t\t\t\t /_/_/_/$(YELL)\/\\ \t$(BLUE)|"
@echo "$(BLUE)|$(RED)\t\tmini$(YELL)R$(GREEN)T$(RED)\t\t\t/_/_/_/$(YELL)\/\/\\ \t$(BLUE)|"
@echo "$(BLUE)|$(GREEN)\tby $(RED)fkernbac $(GREEN)and $(YELL)rbetz$(GREEN)\t\t\_\_\_\$(YELL)/\/\/\t$(BLUE)|"
@echo "$(BLUE)|$(GREEN)\t\t\t\t\t \_\_\_\$(YELL)/\/\t$(BLUE)|"
@echo "$(BLUE)|$(GREEN)\t\t\t\t\t \_\_\_\$(YELL)/\t$(BLUE)|"
@echo "$(BLUE)---------------------------------------------------------$(WHITE)"
clean_lsan:
@rm -rf $(OBJ_D)
clean:
@rm -rf $(OBJ_D)
@rm -f $(LSAN_F)
@make fclean -C $(LIBFT_D)
@make fclean -C $(LIBVEC_D)
fclean: clean
# @rm -rf $(MLX42_BD)
@rm -f $(NAME)
@echo "$(BLUE)--->$(GREEN)Cleaning $(NAME) .....$(WHITE)"
@echo "$(RED)All is cleaned$(WHITE)"
re: fclean all
bonus: all
.PHONY: all fclean clean re lsan bonus clean_lsan