-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
141 lines (112 loc) · 3.36 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
# @author clemedon (Clément Vidon)
####################################### BEG_3 ####
NAME := philo
#------------------------------------------------#
# INGREDIENTS #
#------------------------------------------------#
# SRC_DIR source directory
# DST_DIR build directory
# SRCS source files
# OBJS object files
# DEPS dependency files
#
# CC compiler
# CFLAGS compiler flags
# CPPFLAGS preprocessor flags
SRC_DIR := src
DST_DIR := .build
SRCS := \
main.c \
checkargs.c \
init.c \
simulator.c \
simulation.c \
time_utils.c \
sim_utils.c \
utils.c
SRCS := $(SRCS:%=$(SRC_DIR)/%)
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(DST_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
CC := clang
CFLAGS := -Wall -Wextra -Werror
CPPFLAGS := -MMD -MP -I include
LDLIBS := -lpthread
#------------------------------------------------#
# UTENSILS #
#------------------------------------------------#
# RM force remove
# MAKE quietly make
# DIR_DUP duplicate directory tree
# VALGRIND valgrind command
# HELGRIND helgrind command
RM := rm -f
MAKEFLAGS += --no-print-directory
DIR_DUP = mkdir -p $(@D)
VALGRIND := valgrind -q --leak-check=yes --show-leak-kinds=all
HELGRIND := valgrind -q --tool=helgrind
CLS := \r\033[K
#------------------------------------------------#
# RECIPES #
#------------------------------------------------#
# all default goal
# $(NAME) linking .o -> binary
# %.o compilation .c -> .o
# clean remove .o
# fclean remove .o + binary
# re remake default goal
all: $(NAME)
$(NAME): $(OBJS)
$(CC) $(OBJS) $(LDLIBS) -o $(NAME)
$(info CREATED $@)
$(DST_DIR)/%.o: $(SRC_DIR)/%.c
$(DIR_DUP)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(info CREATED $@)
-include $(DEPS)
clean:
$(RM) $(OBJS) $(DEPS)
fclean: clean
$(RM) $(NAME)
re:
$(MAKE) fclean
$(MAKE) all
norm:
norminette | grep -v "OK" || true
update:
git stash
git pull
git submodule update --init
git stash pop
asan: CFLAGS += -O0 -g3 -fsanitize=address,undefined,integer -fno-optimize-sibling-calls
asan: LDFLAGS += -g3 -fsanitize=address,undefined,integer
asan: all
tsan: CFLAGS += -O0 -g3 -fsanitize=thread,undefined,integer -fno-optimize-sibling-calls
tsan: LDFLAGS += -g3 -fsanitize=thread,undefined,integer
tsan: all
ansi: CFLAGS += -W -pedantic -std=c89
ansi: all
every: CFLAGS += -Weverything
every: all
vrun: $(NAME)
$(if $(p), -$(VALGRIND) ./$(NAME) $(p), \
echo "$(CLS)Usage: make runv p=\"<params>\"")
hrun: $(NAME)
$(if $(p), -$(HELGRIND) ./$(NAME) $(p), \
echo "$(CLS)Usage: make runh p=\"<params>\"")
run: $(NAME)
$(if $(p), -./$(NAME) $(p), \
echo "$(CLS)Usage: make run p=\"<params>\"")
test_eval: $(NAME)
-bash test/eval.sh
test_custom: $(NAME)
$(if $(p), -bash test/custom.sh $(p), \
echo "$(CLS)Usage: make runh p=\"<params>\"")
malloc_test: $(OBJS)
clang -Wall -Wextra -Werror -g -fsanitize=undefined -rdynamic -o $@ $(OBJS) \
-Ltest/ft_mallocator -lmallocator
#------------------------------------------------#
# SPEC #
#------------------------------------------------#
.PHONY: runv runh run test_eval test_custom malloc_test
.SILENT:
####################################### END_3 ####