-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
117 lines (86 loc) · 3.08 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/09/25 12:48:32 by ldulling #+# #+# #
# Updated: 2025/01/31 14:05:14 by ldulling ### ########.fr #
# #
# **************************************************************************** #
# ***************************** CONFIGURATION ******************************** #
NAME := libft.a
# Header files directory:
I := inc/
# Build directories:
B := build/
D := $B_dep/
O := $B_obj/
# Source files directory:
S := src/
# Makefiles in build/ directory with source file listings to be included
# (files that are dependent on others need to be below their dependency):
SOURCELISTS := libft.mk
# Flags:
CC ?= cc
CFLAGS ?= -Wall -Wextra -Werror -pedantic
INCFLAGS := $(addprefix -I,$I)
DEBUGFLAGS := -g
ARFLAGS := rcs
# ***************************** BUILD PROCESS ******************************** #
.DEFAULT_GOAL := all
include $(addprefix $B,$(SOURCELISTS))
OBJ := $(SRC:%.c=$O%.o)
DEP := $(SRC:%.c=$D%.d)
OBJ_SUBDIRS := $(sort $(dir $(OBJ)))
DEP_SUBDIRS := $(sort $(dir $(DEP)))
.PHONY : all cleandep cleanobj clean fclean re debug docs norm
all : $(NAME)
$(NAME) : $(OBJ)
ar $(ARFLAGS) $(NAME) $(OBJ)
$(OBJ): $O%.o : $S%.c | $(OBJ_SUBDIRS)
$(CC) $(CFLAGS) $(INCFLAGS) -c $< -o $@
$(DEP): $D%.d : $S%.c | $(DEP_SUBDIRS)
@ $(CC) $(CFLAGS) $(INCFLAGS) -M -MP -MF $@ -MT "$O$*.o $@" $<
$(OBJ_SUBDIRS) \
$(DEP_SUBDIRS) :
@ mkdir -p $@
cleandep :
ifneq (,$(wildcard $(DEP)))
rm -f $(DEP)
endif
ifneq (,$(wildcard $D))
-find $(D) -type d -empty -delete
endif
cleanobj :
ifneq (,$(wildcard $(OBJ)))
rm -f $(OBJ)
endif
ifneq (,$(wildcard $O))
-find $(O) -type d -empty -delete
endif
clean : cleandep cleanobj
fclean : clean
ifneq (,$(wildcard $(NAME)))
rm -f $(NAME)
endif
re : fclean all
debug : CFLAGS += $(DEBUGFLAGS)
debug : re
# Checks for documentation errors in the source code, like outdated names.
# Only supported by clang.
docs : CFLAGS += -Wdocumentation
docs : re
norm :
@ -norminette -R CheckForbiddenSourceHeader -R CheckDefine \
$(addprefix $S,$(SRC)) $(foreach dir,$I,$(dir)*.h)
ifeq (,$(filter cleandep cleanobj clean fclean re debug norm,$(MAKECMDGOALS)))
ifneq (,$(wildcard $O))
-include $(DEP)
endif
endif
# *************************** MAKEFILE DEBUGGING ***************************** #
# Prints the values of the variable given after the minus.
print-% :
@ echo $* = $($*)