-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
149 lines (121 loc) · 5.18 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: suchua <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/10/05 12:01:03 by suchua #+# #+# #
# Updated: 2023/05/27 20:29:47 by suchua ### ########.fr #
# #
# **************************************************************************** #
# LIB NAME
NAME = libft.a
SONAME = libft.so
INCLUDES = include/
OBJS_DIR = objs/
SRCS_DIR = srcs/
CC = gcc
CFLAGS = -Wall -Werror -Wextra
ARCR = ar -crs
RM = rm -rf
# FILES
ATOITOA_FILES = ft_atoi ft_itoa
IS_FILES = ft_isalnum ft_isalpha ft_isascii ft_isdigit ft_isprint ft_isspace
LST_FILES = ft_lstadd_back ft_lstadd_front ft_lstclear ft_lstdelone \
ft_lstiter ft_lstlast ft_lstmap ft_lstnew ft_lstsize
MEM_FILES = ft_calloc ft_memchr ft_memcmp ft_memcpy ft_memmove ft_memset
PRINTF_FILES = ft_flags ft_print_nb ft_print_nb_utils ft_print_ch \
ft_printf ft_print_p ft_print_p_utils ft_print_usnb \
ft_print_usnb_utils ft_print_x ft_print_x_utils
PUT_FILES = ft_putchar_fd ft_putendl_fd ft_putnbr_fd ft_putstr_fd
STR_FILES = ft_bzero ft_split ft_strchr ft_strdup ft_striteri ft_strjoin \
ft_strlcat ft_strlcpy ft_strlen ft_strmapi ft_strncmp \
ft_strnstr ft_strrchr ft_strtrim ft_substr
TO_FILES = ft_tolower ft_toupper
GNL_FILES = get_next_line_bonus get_next_line_utils_bonus
MATH_FILES = ft_pow ft_sqrt
# addprefix suffix .c
ATOITOA_SRCS = $(addprefix $(SRCS_DIR)ft_atoitoa/, $(addsuffix .c, $(ATOITOA_FILES)))
IS_SRCS = $(addprefix $(SRCS_DIR)ft_is/, $(addsuffix .c, $(IS_FILES)))
LST_SRCS = $(addprefix $(SRCS_DIR)ft_lst/, $(addsuffix .c, $(LST_FILES)))
MEM_SRCS = $(addprefix $(SRCS_DIR)ft_mem/, $(addsuffix .c, $(MEM_FILES)))
PRINTF_SRCS = $(addprefix $(SRCS_DIR)ft_printf/, $(addsuffix .c, $(PRINTF_FILES)))
PUT_SRCS = $(addprefix $(SRCS_DIR)ft_put/, $(addsuffix .c, $(PUT_FILES)))
STR_SRCS = $(addprefix $(SRCS_DIR)ft_str/, $(addsuffix .c, $(STR_FILES)))
TO_SRCS = $(addprefix $(SRCS_DIR)ft_to/, $(addsuffix .c, $(TO_FILES)))
GNL_SRCS = $(addprefix $(SRCS_DIR)gnl/, $(addsuffix .c, $(GNL_FILES)))
MATH_SRCS = $(addprefix $(SRCS_DIR)gnl/, $(addsuffix .c, $(MATH_FILES)))
# addprefix suffix .o
ATOITOA_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(ATOITOA_FILES)))
IS_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(IS_FILES)))
LST_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(LST_FILES)))
MEM_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(MEM_FILES)))
PRINTF_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(PRINTF_FILES)))
PUT_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(PUT_FILES)))
STR_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(STR_FILES)))
TO_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(TO_FILES)))
GNL_OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(GNL_FILES)))
MATH_SRCS = $(addprefix $(SRCS_DIR)gnl/, $(addsuffix .o, $(MATH_FILES)))
#concat all .c files
SRCS = $(ATOITOA_SRCS)
SRCS += $(IS_SRCS)
SRCS += $(LST_SRCS)
SRCS += $(MEM_SRCS)
SRCS += $(PRINTF_SRCS)
SRCS += $(PUT_SRCS)
SRCS += $(STR_SRCS)
SRCS += $(TO_SRCS)
SRCS += $(GNL_SRCS)
#concat all .O files
OBJS = $(ATOITOA_OBJS) \
$(IS_OBJS) \
$(LST_OBJS) \
$(MEM_OBJS) \
$(PRINTF_OBJS) \
$(PUT_OBJS) \
$(STR_OBJS) \
$(TO_OBJS) \
$(GNL_OBJS) \
# vpath %.c $(SRCS_DIR)ft_atoitoa:$(SRCS_DIR)ft_is:$(SRCS_DIR)ft_lst:\
# $(SRCS_DIR)ft_mem:$(SRCS_DIR)ft_printf:$(SRCS_DIR)ft_put:\
# $(SRCS_DIR)ft_str:$(SRCS_DIR)ft_to:$(SRCS_DIR)gnl
# $(OBJS_DIR)%.o:%.c
# @$(CC) $(CFLAGS) -I $(INCLUDES) -c $< -o $@
all:
mkdir -p $(OBJS_DIR)
make $(NAME)
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_atoitoa/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_is/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_lst/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_mem/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_printf/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_put/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_str/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_to/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)gnl/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(OBJS_DIR)%.o:$(SRCS_DIR)ft_math/%.c
@$(CC) $(CFLAGS) -I $(INCLUDES) -c $^ -o $@
$(NAME): $(OBJS)
@$(ARCR) $(NAME) $(OBJS)
so: $(OBJS)
clang -shared -I$(INCLUDES) -o $(SONAME) $(OBJS)
bonus: $(NAME)
clean:
$(RM) $(OBJS_DIR)
fclean:
make clean
$(RM) $(NAME)
$(RM) $(SONAME)
re: fclean all
norm:
@norminette -R CheckForbiddenSourceHeader $(INCLUDES) $(SRCS_DIR)