-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (102 loc) · 3.41 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
# Generated with GenMake
# Arthur-TRT - https://github.com/arthur-trt/genMake
# genmake v1.0
#Compiler and Linker
CC := clang
ifeq ($(shell uname -s),Darwin)
CC := gcc
endif
#The Target Binary Program
TARGET := minishell
TARGET_BONUS := minishell-bonus
BUILD := release
include sources.mk
#The Directories, Source, Includes, Objects, Binary and Resources
SRCDIR := srcs
INCDIR := inc
BUILDDIR := obj
TARGETDIR := .
SRCEXT := c
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
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))
lib.release := -Llibftprintf -lftprintf -lreadline
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)
# hide STD/ERR and prevent Make from returning non-zero code
HIDE_STD := > /dev/null
HIDE_ERR := 2> /dev/null || true
GREP := grep --color=auto --exclude-dir=.git
NORMINETTE := norminette `ls`
# Default Make
all: libft $(TARGETDIR)/$(TARGET)
@$(ERASE)
@$(ECHO) "$(TARGET)\t\t[$(C_SUCCESS)✅$(C_RESET)]"
@$(ECHO) "$(C_SUCCESS)All done, compilation successful! 👌 $(C_RESET)"
# Bonus rule
bonus: CFLAGS += -DBONUS
bonus: CPPFLAGS += -DBONUS
bonus: libft $(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)
@make $@ -C libftprintf
# Full Clean, Objects and Binaries
fclean: clean
@$(RM) -rf $(TARGET)
@make $@ -C libftprintf
# Pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
# Link
$(TARGETDIR)/$(TARGET): $(OBJECTS)
@mkdir -p $(TARGETDIR)
$(CC) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
# Link Bonus
$(TARGETDIR)/$(TARGET_BONUS): $(OBJECTS_BONUS)
@mkdir -p $(TARGETDIR)
$(CC) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
$(BUILDIR):
@mkdir -p $@
# Compile
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
@$(ECHO) "$(TARGET)\t\t[$(C_PENDING)⏳$(C_RESET)]"
$(CC) $(CFLAGS) $(CPPFLAGS) $(INC) -c -o $@ $<
@$(CC) $(CFLAGS) $(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
libft:
@make -C libftprintf
norm:
@$(NORMINETTE) | $(GREP) -v "Not a valid file" | $(GREP) "Error\|Warning" -B 1 || true
# Non-File Targets
.PHONY: all re clean fclean norm bonus libft