-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (49 loc) · 1.07 KB
/
Makefile
File metadata and controls
64 lines (49 loc) · 1.07 KB
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
NAME = ft_ping
SRCDIR = src
OBJDIR = obj
INCDIR = includes
# find all .c in src/
SRC := $(wildcard $(SRCDIR)/*.c)
# generate obj paths
OBJ := $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
CC = cc
CFLAGS = -Wall -Wextra -Werror -g3 -I$(INCDIR)
# Colors
RED := "\033[1;31m"
GREEN := "\033[1;32m"
RESET := "\033[0m"
# Verbose Mode
VERBOSE ?= 0
ifeq ($(VERBOSE),1)
V :=
else
V := @
endif
# Default Rule
all: $(OBJDIR) $(NAME)
# Create obj directory
$(OBJDIR):
$(V)mkdir -p $(OBJDIR)
# Build .o from .c with dependencies
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(V)mkdir -p $(dir $@)
$(V)$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
# Include .d files
DEP = $(OBJ:.o=.d)
-include $(DEP)
# Linking
$(NAME): $(OBJ)
$(V)$(CC) $(CFLAGS) $(OBJ) -o $(NAME) -lm
$(V)echo $(GREEN)"[$(NAME)] binary created ✔"$(RESET)
# Clean object files
clean:
$(V)echo $(RED)"Cleaning object files..."$(RESET)
$(V)rm -rf $(OBJDIR)
# Clean everything
fclean: clean
$(V)echo $(RED)"Removing binary..."$(RESET)
$(V)rm -f $(NAME)
# Rebuild
re: fclean all
.PHONY: all clean fclean re
.DEFAULT_GOAL := all