forked from tbrebion/ft_irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
131 lines (101 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
# Generated with GenMake
# Arthur-TRT - https://github.com/arthur-trt/genMake
# genmake v1.1.6
#Compiler and Linker
CC := clang
CXX := c++
ifeq ($(shell uname -s),Darwin)
CC := gcc
CXX := g++
endif
#The Target Binary Program
TARGET := ircserv
TARGET_BONUS := ircserv-bonus
BUILD := release
include sources.mk
#The Directories, Source, Includes, Objects, Binary and Resources
SRCDIR := srcs
INCDIR := includes
BUILDDIR := obj
TARGETDIR := .
SRCEXT := cpp
DEPEXT := d
OBJEXT := o
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
OBJECTS_BONUS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_BONUS:.$(SRCEXT)=.$(OBJEXT)))
#Flags, Libraries and Includes
cflags.release := -Wall -Werror -Wextra -g3
cflags.valgrind := -Wall -Werror -Wextra -DDEBUG -ggdb
cflags.debug := -Wall -Werror -Wextra -DDEBUG -ggdb -fsanitize=address -fno-omit-frame-pointer
CFLAGS := $(cflags.$(BUILD))
CPPFLAGS := $(cflags.$(BUILD)) -std=c++98
lib.release :=
lib.valgrind := $(lib.release)
lib.debug := $(lib.release) -fsanitize=address -fno-omit-frame-pointer
LIB := $(lib.$(BUILD))
INC := -I$(INCDIR) -I/usr/local/include
INCDEP := -I$(INCDIR)
# Colors
C_RESET := \033[0m
C_PENDING := \033[0;36m
C_SUCCESS := \033[0;32m
# Multi platforms
ECHO := echo
# Escape sequences (ANSI/VT100)
ES_ERASE := "\033[1A\033[2K\033[1A"
ERASE := $(ECHO) $(ES_ERASE)
GREP := grep --color=auto --exclude-dir=.git
NORMINETTE := norminette `ls`
# Default Make
all: $(TARGETDIR)/$(TARGET)
@$(ERASE)
@$(ECHO) "$(TARGET)\t\t[$(C_SUCCESS)✅$(C_RESET)]"
@$(ECHO) "$(C_SUCCESS)All done, compilation successful! 👌 $(C_RESET)"
# Test rule
test: all
$(TARGETDIR)/$(TARGET) 2121 pass
debug: all
valgrind --log-file="valgrind.log" --leak-check=full --track-origins=yes --show-leak-kinds=all --track-fds=yes $(TARGETDIR)/$(TARGET) 2121 pass
# Bonus rule
bonus: CPPFLAGS += -DBONUS
bonus: $(TARGETDIR)/$(TARGET_BONUS)
@$(ERASE)
@$(ECHO) "$(TARGET)\t\t[$(C_SUCCESS)✅$(C_RESET)]"
@$(ECHO) "$(C_SUCCESS)All done, compilation successful with bonus! 👌 $(C_RESET)"
# Remake
re: fclean all
# Clean only Objects
clean:
@$(RM) -f *.d *.o
@$(RM) -rf $(BUILDDIR)
# Full Clean, Objects and Binaries
fclean: clean
@$(RM) -rf $(TARGET)
# Pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
# Link
$(TARGETDIR)/$(TARGET): $(OBJECTS)
@mkdir -p $(TARGETDIR)
$(CXX) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
# Link Bonus
$(TARGETDIR)/$(TARGET_BONUS): $(OBJECTS_BONUS)
@mkdir -p $(TARGETDIR)
$(CXX) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
$(BUILDIR):
@mkdir -p $@
# Compile
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
@$(ECHO) "$(TARGET)\t\t[$(C_PENDING)⏳$(C_RESET)]"
$(CXX) $(CPPFLAGS) $(INC) -c -o $@ $<
@$(CXX) $(CPPFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
@$(ERASE)
@$(ERASE)
@cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
@sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
@sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
@rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
norm:
@$(NORMINETTE) | $(GREP) -v "Not a valid file" | $(GREP) "Error\|Warning" -B 1 || true
# Non-File Targets
.PHONY: all re clean fclean norm bonus