-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
141 lines (112 loc) · 3.72 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lpaulo-m <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/03/26 16:25:08 by lpaulo-m #+# #+# #
# Updated: 2021/04/04 21:51:17 by lpaulo-m ### ########.fr #
# #
# **************************************************************************** #
NAME = weekendrt.a
CC = gcc
CC_FLAGS = -Wall -Wextra -Werror
# CC_FLAGS = -g
CC_DEBUG_FLAGS = -g
EXTERNAL_LIBS = -lm
MAKE_EXTERNAL = make -C
SAFE_MAKEDIR = mkdir -p
ARCHIVE_AND_INDEX = ar -rcs
COPY = cp
REMOVE = /bin/rm -f
REMOVE_RECURSIVE = /bin/rm -rf
OBJECTS_PATH = ./objects
SOURCES_PATH = ./sources
INCLUDES_PATH = ./includes
LIBS_PATH = ./libs
ARCHIVES_PATH = ./archives
EXAMPLES_PATH = ./examples
HEADER_FILE = weekendrt.h
HEADER = $(addprefix $(INCLUDES_PATH)/,$(HEADER_FILE))
SOURCE_FILES = algebra.c \
\
vector.c vector_meta.c vector_scalar.c \
vector_operations.c vector_geometry.c \
point.c \
\
random.c random_utils.c random_geometry.c \
\
color.c pixel.c \
\
ray.c ray_caster.c ray_effects.c hittable.c \
\
sphere.c hittable_sphere.c \
\
material.c matte.c metallic.c dielectric.c \
\
world.c camera.c ray_tracer.c errors.c
SOURCES = $(addprefix $(SOURCES_PATH)/,$(SOURCE_FILES))
OBJECTS = $(addprefix $(OBJECTS_PATH)/,$(subst .c,.o,$(SOURCE_FILES)))
LIBFT = libft.a
LIBFT_PATH = $(LIBS_PATH)/libft
LIBFT_ARCHIVE = $(ARCHIVES_PATH)/$(LIBFT)
FT_LIBBMP = ft_libbmp.a
FT_LIBBMP_PATH = $(LIBS_PATH)/ft_libbmp
FT_LIBBMP_ARCHIVE = $(ARCHIVES_PATH)/$(FT_LIBBMP)
EXAMPLE_MAIN = $(EXAMPLES_PATH)/example.c
BLUE_GRADIENT_MAIN = $(EXAMPLES_PATH)/blue_gradient.c
IMAGE_NAME = hello.bmp
EXECUTE_EXAMPLE = ./a.out $(IMAGE_NAME)
OPEN_IMAGE = ffplay
EXAMPLE_GARBAGE = a.out a.out.dSYM $(IMAGE_NAME)
all: $(NAME)
$(NAME): build_libft build_ft_libbmp $(OBJECTS) $(HEADER)
$(ARCHIVE_AND_INDEX) $(NAME) $(OBJECTS)
$(OBJECTS_PATH)/%.o: $(SOURCES_PATH)/%.c $(HEADER)
$(SAFE_MAKEDIR) $(OBJECTS_PATH)
$(CC) $(CC_FLAGS) -I $(INCLUDES_PATH) -o $@ -c $< $(EXTERNAL_LIBS)
build_example: $(NAME)
$(CC) $(CC_DEBUG_FLAGS) -I $(INCLUDES_PATH) \
$(EXAMPLE_MAIN) $(NAME) $(FT_LIBBMP_ARCHIVE) $(LIBFT_ARCHIVE) $(EXTERNAL_LIBS)
example: build_example
$(EXECUTE_EXAMPLE)
$(OPEN_IMAGE) $(IMAGE_NAME)
build_libft:
$(MAKE_EXTERNAL) $(LIBFT_PATH)
$(SAFE_MAKEDIR) $(ARCHIVES_PATH)
$(COPY) $(LIBFT_PATH)/$(LIBFT) $(LIBFT_ARCHIVE)
build_ft_libbmp:
$(MAKE_EXTERNAL) $(FT_LIBBMP_PATH)
$(SAFE_MAKEDIR) $(ARCHIVES_PATH)
$(COPY) $(FT_LIBBMP_PATH)/$(FT_LIBBMP) $(FT_LIBBMP_ARCHIVE)
clean:
$(REMOVE) $(OBJECTS)
fclean: clean libft_clean ft_libbmp_clean
$(REMOVE) $(NAME)
example_clean: fclean
$(REMOVE_RECURSIVE) $(EXAMPLE_GARBAGE)
libft_clean:
$(MAKE_EXTERNAL) $(LIBFT_PATH) fclean
$(REMOVE) $(LIBFT_ARCHIVE)
ft_libbmp_clean:
$(MAKE_EXTERNAL) $(FT_LIBBMP_PATH) fclean
$(REMOVE) $(FT_LIBBMP_ARCHIVE)
re: fclean all
norm:
norminette $(LIBS_PATH)
@echo ----------------------
norminette $(INCLUDES_PATH)
@echo ----------------------
norminette $(SOURCES_PATH)
git:
git add -A
git commit -m "update"
git push
gitm:
git add -A
git commit -m $m
git push
.PHONY: all build_example example build_libft build_ft_libbmp \
clean fclean example_clean ft_libbmp_clean \
re norm git gitm