-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
126 lines (91 loc) · 3.02 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
# ==================================[ COLOR ]================================= #
RESET = \033[0m
BOLD = \033[1m
DIM = \033[2m
ITALIC = \033[3m
UNDERLINE = \033[4m
BLINK = \033[5m
REVERSE = \033[7m
HIDDEN = \033[8m
BLACK = \033[30m
RED = \033[31m
GREEN = \033[32m
YELLOW = \033[33m
BLUE = \033[34m
MAGENTA = \033[35m
CYAN = \033[36m
WHITE = \033[37m
BLACK_BG = \033[40m
RED_BG = \033[41m
GREEN_BG = \033[42m
YELLOW_BG = \033[43m
BLUE_BG = \033[44m
MAGENTA_BG = \033[45m
CYAN_BG = \033[46m
WHITE_BG = \033[47m
# ==================================[ SETUP ]================================= #
DIR_BUILD = .
DIR_OBJS = $(DIR_BUILD)/objs
DIR_DEPS = $(DIR_BUILD)/deps
DIR_SRCS = ./src
DIR_INCL = ./include
DIR_BIN = ./bin
FILES_SRCS = $(shell find . -wholename "$(DIR_SRCS)/*.cpp")
FILES_OBJS = $(patsubst $(DIR_SRCS)/%.cpp,$(DIR_OBJS)/%.o,$(FILES_SRCS))
FILES_DEPS = $(patsubst $(DIR_SRCS)/%.cpp,$(DIR_DEPS)/%.d,$(FILES_SRCS))
OPT =
DEBUG =
LIBS =
C_COMPILER = g++
I_FLAGS = $(foreach dir,$(DIR_INCL),-I$(dir) )
SILENCED =
C_FLAGS = -Wall -Wextra -Werror $(SILENCED) $(OPT) $(DEBUG) $(I_FLAGS)
C_DEPS = -MM -MP $(I_FLAGS)
BIN = libmini.so
# =================================[ BINARY ]================================= #
all:
@printf "$(BLUE_BG)$(WHITE)$(BOLD)[ Building ]$(RESET)$(WHITE) $(BIN)\n"
@make --silent $(BIN)
$(BIN): $(FILES_OBJS) $(FILES_DEPS)
# displays build command
@printf "$(BOLD)$(BLUE)building $(WHITE)%-30s$(RESET) $(CYAN)$(C_COMPILER) \
$(C_FLAGS) $(FILES_OBJS) -o $(BIN) $(LIBS)$(RESET)\n" "$@"
# builds binary
@mkdir -p $(@D)
@$(C_COMPILER) -shared $(C_FLAGS) -o $(BIN) $(FILES_OBJS)
# =================================[ OBJECTS ]================================ #
$(DIR_OBJS)/%.o: $(DIR_SRCS)/%.cpp
# displays build command
@printf "$(GREEN)building $(WHITE)%-30s$(RESET) $(CYAN)$(C_COMPILER) \
$(C_FLAGS)\n$(RESET)" "$(notdir $@)"
# builds object file
@mkdir -p $(@D)
@$(C_COMPILER) $(C_FLAGS) -fPIC -c $< -o $@
# ==============================[ DEPENDENCIES ]============================== #
$(DIR_DEPS)/%.d: $(DIR_SRCS)/%.cpp
@mkdir -p $(@D)
@$(C_COMPILER) $(C_FLAGS) $(C_DEPS) -MT $(DIR_OBJS)/$*.o -MF $@ $<
# =================================[ CLEANUP ]================================ #
clean:
@printf "$(RED_BG)$(WHITE)$(BOLD)[ Cleaning ]$(RESET)$(WHITE) $(BIN)\n"
@echo "$(RED)removing $(WHITE)*.o$(RESET)"
@rm -f $(FILES_OBJS)
@echo "$(RED)removing $(WHITE)*.d$(RESET)"
@rm -f $(FILES_DEPS)
fclean: clean
@echo "$(BOLD)$(RED)removing $(WHITE)$(BIN)$(RESET)"
@rm -f $(BIN)
re: fclean
@echo ""
@make -s all
# ================================[ UTILITIES ]=============================== #
run: all
@printf "\n$(GREEN_BG)$(WHITE)$(BOLD)[ Running ]$(RESET)$(WHITE) $(BIN)\n"
@./$(BIN)
debug:
@echo $(FILES_SRCS)
@echo $(FILES_OBJS)
@echo $(FILES_DEPS)
@echo $(C_FLAGS)
-include $(FILES_DEPS)
.PHONY: all submodules clean fclean re debug