-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
237 lines (195 loc) · 10.6 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# ---------------------------------------------------------------------------- #
# The purpose of the Makefile is to provide a tool which optimizes the build #
# of a project, The common problems are bad management of dependencies, relink #
# build, uncompiled modified sources... #
# #
# ---------------------------------------------------------------------------- #
# #
# USAGE #
# #
# ---------------------------------------------------------------------------- #
# First, the user must configure its environment settings. #
# - see 'PROJECT CONFIGURATION' to configure project directories #
# - see 'EXTERNAL TOOLS SETTINGS' to setup default programs to use #
# #
# Second, configure the sources. #
# - see 'TARGET SETUP' to set the name of the target and the sources #
# #
# Third, configure the build options. #
# - see 'PROJECT COMPILATION' to setup prepocessor, flags and libraries #
# #
# Fourth, setup the linking rule. #
# - see 'PUBLIC RULES' to modify the $(NAME) rule #
# #
# ---------------------------------------------------------------------------- #
# The project must compile at this step. #
# ---------------------------------------------------------------------------- #
# #
# To add custom rules, the concerned section is 'PUBLIC RULES'. Be sure to #
# keep at least the rules all, $(NAME), libs, clean, fclean and re. #
# #
# ---------------------------------------------------------------------------- #
# #
# /!\ WARNING /!\ #
# #
# The sections commented with '/!\' are critical, and must not be modified. #
# #
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# #
# TARGET SETUP #
# #
# ---------------------------------------------------------------------------- #
# - The 'NAME' variable must contain the expected name of the output target. #
# - The 'SRCS' variable must contain the list of the source files without the #
# base prefix of the directory. #
# ---------------------------------------------------------------------------- #
NAME = libcaps.a
# ---------------------------------------------------------------------------- #
SRCS = \
caps__context.c \
caps__initialize.c \
caps__finalize.c \
caps__init_func.c \
caps__init_func_by_keycode.c \
caps__exec_func.c \
caps__keycode_dump.c \
caps__keycode_cmp.c \
caps__keycode_find.c \
caps__win.c \
caps__print.c \
caps__print_cap.c \
caps__delete_line.c \
caps__cursor_to_offset.c \
caps__cursor_getxy.c \
caps__cursor_setxy.c \
node__key.c \
# ---------------------------------------------------------------------------- #
# PROJECT CONFIGURATION #
# ---------------------------------------------------------------------------- #
# - The 'DIR*' variables describe all directories of the project. #
# ---------------------------------------------------------------------------- #
DIRSRC = srcs
DIRINC = incs
DIRLIB = libs
DIRTST = test
DIROBJ = .objs
DIRDEP = .deps
# ---------------------------------------------------------------------------- #
# EXTERNAL TOOLS SETTINGS #
# ---------------------------------------------------------------------------- #
# - Set the default external programs. #
# ---------------------------------------------------------------------------- #
CC = clang
AR = ar
ARFLAGS = rc
RM = rm -f
# ---------------------------------------------------------------------------- #
# PROJECT COMPILATION #
# ---------------------------------------------------------------------------- #
# - The 'LDFLAGS' tells the linker where to find external libraries (-L flag). #
# - The 'LDLIBS' tells the linker the prefix of external libraries (-l flag). #
# - The 'CPPFLAGS' tells the compiler where to find preprocessors (-I flag). #
# - The 'CFLAGS' configures the compiler options. #
# ---------------------------------------------------------------------------- #
LIBS = \
LDFLAGS = \
-L $(DIRLIB)/libft \
-L $(DIRLIB)/ft_printf \
LDLIBS = \
-ltermcap \
-lft \
-lprintf \
CPPFLAGS = \
-I $(DIRINC) \
-I $(DIRLIB)/libft/ \
-I $(DIRLIB)/ft_printf/ \
CFLAGS = \
-g \
-Wall -Wextra -Werror \
# ---------------------------------------------------------------------------- #
# /!\ COMPILATION RULES /!\ #
# ---------------------------------------------------------------------------- #
DEPFLAGS = \
-MT $@ -MMD -MP -MF $(DIRDEP)/$*.Td \
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c
POSTCOMPILE = mv -f $(DIRDEP)/$*.Td $(DIRDEP)/$*.d
# ---------------------------------------------------------------------------- #
# /!\ SOURCES NORMALIZATION /!\ #
# ---------------------------------------------------------------------------- #
SRC = $(addprefix $(DIRSRC)/, $(SRCS))
OBJ = $(addprefix $(DIROBJ)/, $(SRCS:.c=.o))
$(DIROBJ) :
@mkdir -p $(DIROBJ)
$(DIRDEP) :
@mkdir -p $(DIRDEP)
# ---------------------------------------------------------------------------- #
# PUBLIC RULES #
# ---------------------------------------------------------------------------- #
# The rules must contain at least : #
# - all make libs and target #
# - $(NAME) make binaries and target #
# - libs build static libraries #
# - clean remove binaries #
# - fclean remove binaries and target #
# - fcleanlibs apply fclean rule on libraries #
# - re remove binaries, target and libraries and build the target #
# #
# To compile a static library, the $(NAME) rule should be : #
# '$(AR) $(ARFLAGS) $(NAME) $(OBJ)' #
# 'ranlib $(NAME)' #
# #
# To compile a C binary, the $(NAME) rule should be : #
# '$(CC) $(OBJ) -o $(NAME) $(LDFLAGS) $(LDLIBS)' #
# ---------------------------------------------------------------------------- #
all : libs $(NAME)
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "finish to build $(NAME)"
$(NAME) : $(DIROBJ) $(DIRDEP) $(OBJ) $(LIBS)
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "link objects..."
@$(AR) $(ARFLAGS) $(NAME) $(OBJ)
@ranlib $(NAME)
libs :
@make -C $(DIRLIB)/libft
@make -C $(DIRLIB)/ft_printf
fcleanlibs :
@make -C $(DIRLIB)/libft fclean
@make -C $(DIRLIB)/ft_printf fclean
clean :
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "remove objects..."
@$(RM) -r $(DIROBJ)
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "remove dependencies..."
@$(RM) -r $(DIRDEP)
fclean : clean
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "remove target..."
@$(RM) $(NAME)
re : fcleanlibs fclean all
# ---------------------------------------------------------------------------- #
# CUSTOM RULES #
# ---------------------------------------------------------------------------- #
test : re
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "run tests..."
submodule :
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "retrieve submodules..."
norme :
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "run norminette..."
@printf "\033[33m[ %s ]\033[0m %s\n" "$(NAME)" "missing headers not check"
@/usr/bin/norminette -R CheckTopCommentHeader \
$$(find * -name "*.[ch]")
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "run norminette..."
@printf "\033[33m[ %s ]\033[0m %s\n" "$(NAME)" "missing headers not check"
# ---------------------------------------------------------------------------- #
# /!\ PRIVATE RULES /!\ #
# ---------------------------------------------------------------------------- #
$(DIROBJ)/%.o : $($(DIRSRC)/%.c
$(DIROBJ)/%.o : $(DIRSRC)/%.c $(DIRDEP)/%.d
@mkdir -p $(dir $@)
@mkdir -p $(dir $(word 2,$^))
@printf "\033[32m[ %s ]\033[0m %s\n" "$(NAME)" "compiling $<..."
@$(COMPILE.c) $(OUTPUT_OPTION) $<
@$(POSTCOMPILE)
$(DIRDEP)/%.d : ;
.PRECIOUS : $(DIRDEP)/%.d
-include $(patsubst %,$(DIRDEP)/%.d,$(basename $(SRCS)))
# ---------------------------------------------------------------------------- #
.PHONY : all clean fclean re $(DIROBJ)/%.o $(DIRDEP)/%.d libs
# ---------------------------------------------------------------------------- #