-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
212 lines (159 loc) · 5.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
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
210
211
212
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: younhwan <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/02/25 14:57:24 by younhwan #+# #+# #
# Updated: 2023/02/25 14:57:25 by younhwan ### ########.fr #
# #
# **************************************************************************** #
SHELL = /bin/bash
IDX = 0
NAME = miniRT
LIBS_DIR = libs
LIBFT_DIR := ${LIBS_DIR}/libft
LIBFT_INCS_DIR := ${LIBFT_DIR}/incs
LIBFT := ${LIBFT_DIR}/libft.a
LIBGNL_DIR := ${LIBS_DIR}/libgnl
LIBGNL_INCS_DIR := ${LIBGNL_DIR}/incs
LIBGNL := ${LIBGNL_DIR}/libgnl.a
LIBVEC_DIR := ${LIBS_DIR}/libvec
LIBVEC_INCS_DIR := ${LIBVEC_DIR}/incs
LIBVEC := ${LIBVEC_DIR}/libvec.a
LIBRAY_DIR := ${LIBS_DIR}/libray
LIBRAY_INCS_DIR := ${LIBRAY_DIR}/incs
LIBRAY := ${LIBRAY_DIR}/libray.a
LIBMLX_DIR := ${LIBS_DIR}/libmlx
LIBMLX_INCS_DIR := ${LIBMLX_DIR}/incs
LIBMLX := ${LIBMLX_DIR}/libmlx.a
INCS_DIR = incs
SRCS_DIR = srcs
OBJS_DIR = objs
CC = cc
CFLAGS = -Wall -Wextra -Werror -I${INCS_DIR} -I${LIBFT_INCS_DIR} -I${LIBGNL_INCS_DIR} -I${LIBVEC_INCS_DIR} -I${LIBMLX_INCS_DIR} -MD -O3
LDFLAGS = -L${LIBFT_DIR} -lft -L${LIBGNL_DIR} -lgnl -L${LIBVEC_DIR} -lvec -L${LIBRAY_DIR} -lray -L${LIBMLX_DIR} -lmlx -framework OpenGL -framework AppKit
AR = ar rcs
RM = rm -f
SRCS = miniRT.c \
err/exit_with_err.c \
err/set_err.c \
event/key_event.c \
raytracing/raytracing.c \
raytracing/ambient.c \
raytracing/cone.c \
raytracing/cylinder.c \
raytracing/diffuse.c \
raytracing/hit_object.c \
raytracing/mirror_reflection.c \
raytracing/phong_reflection.c \
raytracing/plane.c \
raytracing/ray.c \
raytracing/specular.c \
raytracing/sphere.c \
raytracing/vec3_utils_in_raytracing.c \
render/render.c \
OBJS_DIRS = ${OBJS_DIR}/err \
${OBJS_DIR}/event \
${OBJS_DIR}/raytracing \
${OBJS_DIR}/render
ifdef BONUS
SRCS += parse_bonus/parse_bonus.c \
parse_bonus/parse_ambient_lightning_bonus.c \
parse_bonus/parse_camera_bonus.c \
parse_bonus/parse_cone_bonus.c \
parse_bonus/parse_cylinder_bonus.c \
parse_bonus/parse_light_bonus.c \
parse_bonus/parse_plane_bonus.c \
parse_bonus/parse_sphere_bonus.c \
parse_bonus/parse_utils_bonus.c
OBJS_DIRS += ${OBJS_DIR}/parse_bonus
else
SRCS += parse/parse.c \
parse/parse_ambient_lightning.c \
parse/parse_camera.c \
parse/parse_cylinder.c \
parse/parse_light.c \
parse/parse_plane.c \
parse/parse_sphere.c \
parse/parse_utils.c
OBJS_DIRS += ${OBJS_DIR}/parse
endif
ifdef SANITIZE
LDFLAGS += -fsanitize=address
endif
SRCS := ${addprefix ${SRCS_DIR}/, ${SRCS}}
OBJS := ${SRCS:${SRCS_DIR}/%.c=${OBJS_DIR}/%.o}
DEPS := ${OBJS:.o=.d}
SRCS_LEN = ${shell echo ${SRCS} | wc -w}
IS_MANDATORY = ${OBJS_DIR}/is_mandatory
IS_BONUS = ${OBJS_DIR}/is_bonus
all:
@${MAKE} ${IS_MANDATORY}
bonus:
@${MAKE} BONUS=1 ${IS_BONUS}
${IS_MANDATORY}: ${OBJS}
@${RM} ${IS_BONUS}
@if [ ${IDX} -gt 0 ]; then\
printf "\b"; echo "done ";\
fi
@${CC} ${LDFLAGS} -g -o ${NAME} ${OBJS}
@echo "Build ${NAME}: done"
@touch ${IS_MANDATORY}
${IS_BONUS}: ${OBJS}
@${RM} ${IS_MANDATORY}
@if [ ${IDX} -gt 0 ]; then\
printf "\b"; echo "done ";\
fi
@${CC} ${LDFLAGS} -g -o ${NAME} ${OBJS}
@echo "Build ${NAME}: done"
@touch ${IS_BONUS}
${OBJS}: ${LIBMLX}
${OBJS_DIR}/%.o: ${SRCS_DIR}/%.c | ${OBJS_DIRS}
${eval IDX = ${shell expr ${IDX} + 1}}
@if [ ${IDX} = 1 ]; then\
echo -n "Build dependencies in ${NAME} ... ";\
fi
@printf "%3d%%\b\b\b\b" ${shell expr ${IDX} \* 100 / ${SRCS_LEN}}
@${CC} ${CFLAGS} -g -c $< -o $@
${OBJS_DIR}:
@echo "Build ${NAME}"
@mkdir -p ${OBJS_DIR}
${OBJS_DIRS}: ${OBJS_DIR}
@mkdir -p ${OBJS_DIRS}
${LIBFT}:
@${MAKE} -C ${LIBFT_DIR}
${LIBGNL}: ${LIBFT}
@${MAKE} -C ${LIBGNL_DIR}
${LIBVEC}: ${LIBGNL}
@${MAKE} -C ${LIBVEC_DIR}
${LIBRAY}: ${LIBVEC}
@${MAKE} -C ${LIBRAY_DIR}
${LIBMLX}: ${LIBRAY}
@${MAKE} -C ${LIBMLX_DIR}
clean:
@${MAKE} -C ${LIBFT_DIR} clean
@${MAKE} -C ${LIBGNL_DIR} clean
@${MAKE} -C ${LIBVEC_DIR} clean
@${MAKE} -C ${LIBRAY_DIR} clean
@${MAKE} -C ${LIBMLX_DIR} clean
@echo "Remove dependencies in ${NAME}"
@${RM} -r ${OBJS_DIR}
fclean:
@${MAKE} -C ${LIBFT_DIR} fclean
@${MAKE} -C ${LIBGNL_DIR} fclean
@${MAKE} -C ${LIBVEC_DIR} fclean
@${MAKE} -C ${LIBRAY_DIR} fclean
@${MAKE} -C ${LIBMLX_DIR} fclean
@echo "Remove dependencies in ${NAME}"
@${RM} -r ${OBJS_DIR}
@echo "Remove ${NAME}"
@${RM} ${NAME}
re:
@echo "Rebuild ${NAME}"
@${MAKE} fclean
@${MAKE} all
.PHONY: all clean fclean re bonus
.NOTPARALLEL: all clean fclean re bonus
-include ${DEPS}