-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
131 lines (93 loc) · 3.37 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gphilipp <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/10/18 14:24:46 by gphilipp #+# #+# #
# Updated: 2022/01/15 08:53:40 by gphilipp ### ########.fr #
# #
# **************************************************************************** #
# <!-- pre='srcs/' path='./' match='*.c' exclude='main.c' pos='1' template=' {0} \' -->
SRC = main.c \
is_alphabet.c \
# <!-- pre='srcs/' path='./' match='*_bonus.c' exclude='main_bonus.c' pos='1' template=' {0} \' -->
SRC_BONUS = main_bonus.c \
is_alphabet_bonus.c \
ifdef BONUS
SRC += $(SRC_BONUS)
_tmpsrc := $(SRC)
SRC = $(filter-out main.c, $(_tmpsrc))
endif
# <!-- pre='includes/' path='./' match='*.h' exclude='rendu.h' pos='1' template=' {0} \' -->
HDEP = rendu.h \
HDEPS = $(addprefix $(HEAD), $(HDEP))
SRCS = $(addprefix $(PRE), $(SRC))
OBJS = $(SRCS:.c=.o)
PRE = ./srcs/
HEAD = ./includes/
NAME = rendu
ifdef BONUS
NAME = rendu_bonus
endif
CC = gcc
CFLAGS = -Wall -Wextra -Werror
COMPILEFLAGS =
#COMPILEFLAGS = -L$(LIBLIST) -llist
all: libs $(NAME)
%.o: %.c $(HDEPS)
$(CC) $(CFLAGS) -I $(HEAD) -c $< -o $@
#LIBLIST = vendor/liblist/
LIBS = #$(LIBLIST)liblist.a
#list: $(LIBLIST)liblist.a
#$(LIBLIST)liblist.a:
# make -C $(LIBLIST)
libs_clean:
# make -C $(LIBLIST) clean
libs_fclean: libs_clean
# make -C $(LIBLIST) fclean
bonus: $(NAME)
@make BONUS=1
$(NAME): $(LIBS) $(OBJS) $(HDEPS)
$(CC) $(CFLAGS) -o $(NAME) $(COMPILEFLAGS) $(OBJS)
# Usage: make debug && lldb rendu_debug -o run
$(NAME)_debug: $(LIBS) $(SRCS) $(HDEPS)
$(CC) $(CFLAGS) -g -o $(NAME)_debug -I $(HEAD) $(COMPILEFLAGS) $(SRCS)
$(NAME)_sanitize: $(LIBS) $(SRCS) $(HDEPS)
$(CC) $(CFLAGS) -fsanitize=address -g -o $(NAME)_sanitize -I $(HEAD) $(COMPILEFLAGS) $(SRCS)
# Usage: make leaks && ./rendu_leaks
MAIN_PATH=srcs/main.c
$(NAME)_leaks: $(OBJS) $(HDEPS)
$(eval main_proto=$(shell grep 'int\tmain' $(MAIN_PATH)))
$(eval leaks_proto=$(shell echo '$(main_proto)' | sed 's/main/leaks_tester/'))
$(eval call_main=$(shell echo '$(main_proto)' | sed -E "s/(int| |\*|char|const|void|\[|\])//g"))
@echo '#include "stdlib.h"\n\n\
$(main_proto);\n\n\
$(leaks_proto) {\n\
\tint exitcode = $(call_main);\n\
\tsystem("leaks $(NAME)_leaks");\n\
\treturn (exitcode);\n\
}' > .tmp_leaks.c
$(CC) $(CFLAGS) -o $(NAME)_leaks $(COMPILEFLAGS) .tmp_leaks.c $(OBJS) -e_leaks_tester
@rm .tmp_leaks.c
debug: $(NAME)_debug
sanitize: $(NAME)_sanitize
leaks: $(NAME)_leaks
dclean: fclean
rm -f *.out
rm -rf *.dSYM
rm -f $(NAME)_debug
rm -f $(NAME)_sanitize
rm -f $(NAME)_leaks
find . -iname "*.o" -exec rm -i {} ";"
clean:
ifndef BONUS
make -s BONUS=1 clean;
endif
rm -f $(OBJS)
fclean: libs_fclean clean
rm -f $(NAME)
re: fclean
make all
.PHONY: all clean dclean fclean debug sanitize leaks list libs_clean libs_fclean re