-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
164 lines (141 loc) · 5.34 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: awoimbee <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/11/26 22:06:19 by marvin #+# #+# #
# Updated: 2019/08/24 00:43:53 by awoimbee ### ########.fr #
# #
# **************************************************************************** #
NAME = rtv1
CFLAGS = -Wall -Wextra -Ofast -march=native -ftree-vectorize -fstrict-aliasing #-fopt-info-vec-optimized -Werror
SRC_NAME = main.c \
init_argv.c \
loop.c \
t_obj/dist.c \
t_obj/norm.c \
\
renderer/calc_light.c \
renderer/render_master.c \
renderer/launch_ray.c \
renderer/supersample.c \
\
operators/camera.c \
\
parser/env_disp_cam.c \
parser/lights.c \
parser/obj_array.c \
parser/obj_individual.c \
parser/scene.c \
parser/support_funs.c \
parser/load_obj.c
SRC_FOLDERS = operators t_obj parser renderer
DEPS_FOLDER = dependencies
BUILD_FOLDER = build
################################################################################
############### CONSTANTS ###############
################################################################################
CC = gcc
LDLIBS = -lft -lm -lSDL2 -lpthread
LDFLAGS = -L./libs/libft -L$(DEPS_FOLDER)/lib #-Wl,-rpath=`pwd`/sdl2/lib
CFLAGS += -MMD -I./ -I./src/operators -I./src -isystem$(BUILD_FOLDER)/include/ -I./libs/libft
SDL_OPTIONS = -q \
--prefix=$(DEPS_PATH) \
--exec-prefix=$(DEPS_PATH) \
--bindir=$(BUILD_PATH)/bin \
--includedir=$(BUILD_PATH)/include \
--datarootdir=$(BUILD_PATH)/share
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
NUMPROC := $(shell grep -c ^processor /proc/cpuinfo)
ifeq ($(PROFILE),gen)
CFLAGS += -fprofile-generate #using perf is heaps better (fautoprofile something something)
else ifeq ($(PROFILE),use)
CFLAGS += -fprofile-use
endif
else ifeq ($(UNAME_S),Darwin)
NUMPROC := $(shell sysctl hw.ncpu | awk '{print $$2}')
PROCESS_PROFDATA := xcrun llvm-profdata merge -sparse default.profraw -o default.profdata
RM_PROFDATA := rm ./default.profraw ./default.profdata
ifeq ($(PROFILE),gen)
CFLAGS += -fprofile-instr-generate
else ifeq ($(PROFILE),use)
CFLAGS += -fprofile-instr-use
endif
endif
REPO_PATH = $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
DEPS_PATH = $(REPO_PATH)/$(DEPS_FOLDER)
BUILD_PATH = $(REPO_PATH)/$(BUILD_FOLDER)
SRC_FOLDER = src
OBJ_FOLDER = $(BUILD_FOLDER)/obj
DIRS = $(BUILD_FOLDER) $(DEPS_PATH) $(OBJ_FOLDER) $(addprefix $(OBJ_FOLDER)/,$(SRC_FOLDERS))
LSDL2 = $(DEPS_PATH)/lib/libSDL2.a
LFT = libs/libft/libft.a
SRC = $(addprefix $(SRC_FOLDER)/,$(SRC_NAME))
OBJ = $(addprefix $(OBJ_FOLDER)/,$(SRC_NAME:.c=.o))
################################################################################
################# RULES #################
################################################################################
all : $(NAME)
############## LIBS ############
$(BUILD_FOLDER)/include/SDL2 : $(LSDL2)
$(LSDL2) : | $(BUILD_FOLDER)
@printf "$(YLW)Making SDL2...$(EOC)\n"
@mkdir -p $(BUILD_PATH)/sdl2
@printf "$(INV)Creating build env...$(EOC)\n" &&\
cd $(BUILD_PATH)/sdl2 &&\
$(REPO_PATH)/libs/sdl2/configure $(SDL_OPTIONS) &&\
printf "$(INV)Building...$(EOC)\n" &&\
make -sj 10 &&\
printf "$(INV)Installing in $(DEPS_FOLDER)...$(EOC)\n" &&\
make -s install
@printf "$(EOC)\n"
$(LFT) :
@printf "$(YLW)Making libft...$(EOC)\n"
@make -s -j$(NUMPROC) -C libs/libft/
################################
$(NAME) : $(LFT) $(LSDL2) $(OBJ)
@printf "$(GRN)Linking $(NAME)...$(EOC)\n"
$(CC) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS) $(LDLIBS)
opti : obj_clean
@printf "Compiling instrumented version...\n"
@make $(NAME) PROFILE=gen > /dev/null
@printf "Profiling...\n"
@./rtv1 ./scenes/scene.rt
@$(PROCESS_PROFDATA)
@printf "Cleaning...\n"
@make obj_clean
make $(NAME) PROFILE=use
$(RM_PROFDATA)
$(OBJ_FOLDER)/%.o : $(SRC_FOLDER)/%.c | $(DIRS)
@printf "\t$(CC) (...) $@\n"
@$(CC) $(CFLAGS) -o $@ -c $<
$(DIRS) :
@mkdir -p $@
# Add rules written in .d files (by gcc -MMD)
# The '-' makes it doesn't care if the file exists or not
-include $(OBJ:.o=.d)
obj_clean :
@printf "$(RED)Cleaning $(OBJ_FOLDER)$(EOC)\n"
@rm -rf $(OBJ_FOLDER)
clean :
@printf "$(RED)Cleaning $(BUILD_FOLDER)$(EOC)\n"
@rm -rf $(BUILD_FOLDER)
@printf "$(YLW)Cleaning libft...$(EOC)\n"
@make -s fclean -C libs/libft
fclean : clean
@printf "$(YLW)Cleaning libs dependencies...$(EOC)\n"
@rm -rf $(DEPS_FOLDER)/lib
@printf "$(RED)Cleaning $(NAME)$(EOC)\n"
@rm -f $(NAME)
sclean : obj_clean
re : fclean all
sre : obj_clean all
.PHONY: all obj_clean clean fclean re sre
RED = \033[1;31m
GRN = \033[1;32m
YLW = \033[1;33m
INV = \033[7m
EOC = \033[0m