-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (104 loc) · 3.29 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
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: mweverli <[email protected]> +#+ #
# +#+ #
# Created: 2022/10/01 17:54:19 by mweverli #+# #+# #
# Updated: 2023/06/12 18:27:03 by mweverli ######## odam.nl #
# #
# **************************************************************************** #
#========================================#
#========= GENERAL VARIABLES: =========#
#========================================#
NAME := philo
OBJ_DIR := OBJ
SRC_DIR := src
INC_DIR := include
LIB_DIR := lib
SRC := philo/philo.c \
philo/philo_actions.c \
philo/philo_error.c \
philo/philo_free.c \
philo/philo_init.c \
philo/philo_message.c \
philo/philo_routine.c \
philo/philo_run.c \
\
utils/philo_utils_convert.c \
utils/philo_utils_mem.c \
utils/philo_utils_str.c \
utils/philo_utils_time.c
OBJ := $(SRC:%.c=$(OBJ_DIR)/%.o)
SRC := $(SRC:%=$(SRC_DIR)/%)
DEP := $(OBJ:.o=.d)
DIR_LIST := $(sort $(dir $(OBJ)))
-include $(DEP)
#============= COMPILATION ==============#
INCLUDE := -I $(INC_DIR)
LIBRARY := -pthread
CC := gcc
CFL := -Wall -Werror -Wextra -Wpedantic
ifdef DEBUG
CFL += -g
endif
ifdef THRD
CFL += -fsanitize=thread
endif
ifdef FSAN
CFL += -fsanitize=address -fsanitize=undefined
endif
ifdef PRTY
CFL += -D PRETTY=1
endif
COMPILE := $(CC) $(CFL)
INFO_FL := \
$(if $(findstring -g,$(CFL)),-g) \
$(if $(findstring thread,$(CFL)),-fsan=thread) \
$(if $(findstring address,$(CFL)),-fsan=address) \
$(if $(findstring undefined,$(CFL)),-fsan=undef)
#========================================#
#============== RECIPIES ===============#
#========================================#
var:
@echo $(SRC)
@echo ""
@echo $(OBJ)
@echo ""
@echo $(DIR_LIST)
@echo ""
all: $(DIR_LIST) $(NAME)
$(DIR_LIST):
@mkdir -p $@
$(NAME): $(OBJ)
@echo ""
$(COMPILE) $(INCLUDE) $(LIBRARY) $(OBJ) -o $(NAME)
@echo ""
@echo "$(COMPILE) $(INCLUDE) $(LIBRARY) $(CYAN)$(notdir $(OBJ))$(RESET) -o $(NAME)"
$(OBJ_DIR)/%.o:$(SRC_DIR)/%.c
@$(COMPILE) $(INCLUDE) -MMD -o $@ -c $<
@echo "$(CYAN)COMPILE $(INFO_FL) $(notdir $(<:%.c=%))$(RESET)"
clean:
@rm -rf $(OBJ_DIR)
@echo "$(RED)$(BOLD)CLEANING $(NAME)$(RESET)"
fclean: clean
@rm -f $(NAME)
re: fclean all
debug:
@$(MAKE) DEBUG=1 all
rebug: fclean debug
#========================================#
#============== LIBRARIES ===============#
#========================================#
#========================================#
#============ MISCELLANEOUS =============#
#========================================#
.PHONY: all clean fclean re debug rebug
.DEFAULT_GOAL := all
#=============== COLOURS ================#
BOLD := \033[1m
RED := \033[31;1m
GREEN := \033[32;1m
CYAN := \033[36;1m
RESET := \033[0m