-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.common
74 lines (53 loc) · 1.64 KB
/
Makefile.common
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
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)\
$(filter $(subst *,%,$2),$d))
INCLUDE_DIRS = .. ../vendors/signals $(BOOST_PATH)/include
LIB_DIRS =
LIB_NAMES = dl jpeg
COMPILER = g++
CFLAGS = -Wall -Wextra -Werror -std=c++1z -O3 \
$(foreach dir, $(INCLUDE_DIRS), -I $(dir))
LFLAGS = $(foreach dir, $(LIB_DIRS), -L $(dir)) \
$(foreach name, $(LIB_NAMES), -l$(name))
OBJ_DIR = objs
SRCS = $(call rwildcard, ./, *.cpp)
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
OBJ_SUB_DIRS = $(dir $(OBJS))
all: show_fancy_name
@$(MAKE) $(NAME)
$(NAME): $(OBJS)
@echo "$(bold)$(blue)linking $(green)$@$(reset)"
@$(COMPILER) $^ $(LFLAGS) -o $@
$(OBJS): | $(OBJ_DIR)
$(OBJ_DIR):
@$(foreach dir, $(OBJ_SUB_DIRS), mkdir -p $(dir);)
$(OBJ_DIR)/%.o: %.cpp
@echo "$(bold)$(cyan)compiling $(white)$<$(reset)"
@$(COMPILER) $(CFLAGS) -c $< -o $@
depend: .depend
.depend: $(SRCS)
@rm -f ./.depend
@$(foreach src, $^, $(COMPILER) $(CFLAGS) -MM -MT $(OBJ_DIR)/./$(src:.cpp=.o) $(src) >> ./.depend 2> /dev/null;)
-include .depend
clean: show_fancy_name
@echo "$(bold)$(red)cleaning $(white)$(OBJ_DIR)$(reset)"
@rm -rf $(OBJ_DIR)
@rm -f ./.depend
fclean: clean
@echo "$(bold)$(red)removing $(green)$(NAME)$(reset)"
@rm -f $(NAME)
re:
@$(MAKE) fclean
@$(MAKE) all
show_fancy_name:
@echo "\n$(bold)$(yellow)==> $(NAME)$(reset)"
# ANSI helpers
ansi = \033[$1m
bold = $(call ansi,1)
fg_color = $(call ansi,38;5;$1)
reset = $(call ansi,0)
red = $(call fg_color,1)
green = $(call fg_color,10)
blue = $(call fg_color,27)
cyan = $(call fg_color,6)
yellow = $(call fg_color,11)
white = $(call fg_color,255)