forked from ygor-sena/42cursus-miniRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
107 lines (82 loc) · 3.25 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
################################################################################
## MINIRT ##
################################################################################
NAME := miniRT
RESET := \033[0m
CYAN := \033[1;36m
CHECK := \342\234\224
LOG := printf "[$(CYAN)$(CHECK)$(RESET)] %s\n"
################################################################################
## DIRECTORIES ##
################################################################################
OBJ_DIR := obj
LIB_DIR := lib
LIBFT_DIR := $(LIB_DIR)/libft
MLX_DIR := $(LIB_DIR)/mlx_linux
INC_DIRS := include $(LIBFT_DIR) $(MLX_DIR)
SRC_DIRS := tuples canvas matrices rays shapes lights materials helpers world
SRC_DIRS += camera parser patterns
SRC_DIRS := $(addprefix src/, $(SRC_DIRS))
SRC_DIRS += src
vpath %.h $(INC_DIRS)
vpath %.c $(SRC_DIRS)
LIBFT := $(LIBFT_DIR)/libft.a
MLX := $(MLX_DIR)/libmlx_Linux.a
HEADERS := tuples.h canvas.h matrices.h rays.h shapes.h lights.h materials.h
HEADERS += world.h helpers.h camera.h mlx.h parser.h patterns.h
SOURCES := main.c models.c basic_math.c vector_math.c colors.c canvas.c
SOURCES += mx_attributes.c mx_operations.c mx_rotations.c mx_transformations.c
SOURCES += mx_utils.c rays.c intersections.c spheres.c
SOURCES += lights.c materials.c world.c view_transform.c camera.c
SOURCES += render.c controls.c shapes.c shadows.c planes.c
SOURCES += scanner.c scanner_utils.c parse_types.c ft_atof.c swap.c
SOURCES += parse.c parse_basic.c parse_grouped.c parse_utils.c
SOURCES += parse_shapes_1.c parse_shapes_2.c bumpmap.c parse_textures.c
SOURCES += parse_ambient.c parse_element.c cylinders.c patterns.c
SOURCES += discriminants.c cones.c parse_pattern.c checkers.c mappings.c
OBJS := $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o))
################################################################################
## COMPILATION ##
################################################################################
CFLAGS := -Wall -Werror -Wextra $(addprefix -I,$(INC_DIRS))
LDFLAGS := -L $(LIBFT_DIR) -L $(MLX_DIR)
LDLIBS := -lft -lmlx -lXext -lX11 -lm
ifdef DEBUG
CFLAGS += -g
else
CFLAGS += -Ofast
endif
all: $(NAME)
r: $(NAME)
@make $(TEST) -C tests --no-print-directory
test: $(NAME)
@make -C tests --no-print-directory
$(NAME): $(OBJS) | $(LIBFT) $(MLX)
@$(LOG) "Building $@"
@$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
$(OBJ_DIR)/%.o: %.c $(HEADERS) | $(OBJ_DIR)
@$(LOG) "Compiling $(notdir $<)"
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR):
@$(LOG) "Creating objects directory"
@mkdir $@
$(LIBFT):
@make bonus -C $(LIBFT_DIR) --no-print-directory
$(MLX):
@make -C $(MLX_DIR) --no-print-directory
checks: $(NAME)
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
clean:
@$(RM) -r $(OBJS)
@$(LOG) "Removing objects"
@$(RM) -r $(OBJ_DIR)
@$(LOG) "Removing objects directory"
fclean: clean
@$(RM) -r $(NAME)
@$(LOG) "Removing $(NAME)"
@$(LOG) "Removing libft"
@make fclean -C $(LIBFT_DIR) --no-print-directory --silent
@$(LOG) "Removing mlx"
@make clean -C $(MLX_DIR) --no-print-directory --silent
re: clean all
.PHONY: all clean fclean re