-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
70 lines (51 loc) · 1.48 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
SRC_DIR = src/
OBJ_DIR = bin/
INC_DIR = include/
NAME = ircserv
SRCS = $(wildcard $(SRC_DIR)*.cpp)
SRCS := $(SRCS:$(SRC_DIR)%=%)
OBJS = $(addprefix $(OBJ_DIR), $(SRCS:.cpp=.o))
DEPENDS = $(OBJS:.o=.d)
CXX = c++
CXXFLAGS = -Wall -Werror -Wextra --std=c++98 $(DEFINES)
INCLUDE = -I$(INC_DIR)
DEBUGFLAGS = -g
define generate_compile_commands
make --always-make --dry-run \
| grep -wE 'gcc|cc|clang|g\+\+|c\+\+' \
| grep -w '\-c' \
| jq -nR "[inputs|{directory:\""$(PWD)"\", command:., file: match(\"[^ ]*\\\.(cpp|c)\").string[0:]}]" \
> $(OBJ_DIR)/compile_commands.json
endef
all: $(NAME)
debug: CXXFLAGS += $(DEBUGFLAGS)
debug: $(NAME)
$(NAME): $(OBJ_DIR) $(OBJS)
@$(call generate_compile_commands)
@printf "\n$(BLUE)Linking... $(RESET)"
@$(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME) $(LFLAGS)
@printf "$(BLUE)Done\n$(RESET)"
-include $(DEPENDS)
$(OBJ_DIR)%.o: $(SRC_DIR)%.cpp
@printf "$(BLUE)→ $(GREEN)Compiling $(subst $(SRC_DIR),,$<)\n$(RESET)"
@$(CXX) $(CXXFLAGS) $(INCLUDE) -MMD -MP -c $< -o $@
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
clean:
@printf '$(BLUE)→ $(ORANGE)Removing object files$(RESET)\n'
@rm -rf $(OBJ_DIR)
fclean: clean
@printf '$(BLUE)→ $(ORANGE)Removing executable$(RESET)\n'
@rm -f $(NAME)
re: fclean print_newline all
print_newline:
@echo
compile_commands: $(OBJ_DIR)
@$(call generate_compile_commands)
@echo 'Done'
.PHONY: all clean fclean re print_newline compile_commands
# colors
ORANGE = \e[1;33m
BLUE = \e[1;34m
GREEN = \e[1;32m
RESET = \e[0m