-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (81 loc) · 1.97 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
#
# Executable name
NAME := libft.a
# Git submodule to init
SUBMODULES :=
# Base flags
BASE_FLAGS = -Wall -Wextra
INCLUDE_FLAGS =
# Compilation flags (per language)
C_FLAGS = $(INCLUDE_FLAGS) $(BASE_FLAGS)
CPP_FLAGS = $(INCLUDE_FLAGS) $(BASE_FLAGS) -std=c++14
LINK_FLAGS = $(BASE_FLAGS)
DEBUG_MODE ?= 0
ifeq ($(DEBUG_MODE),1)
# Extra flags used in debug mode
BASE_FLAGS += -g
else
# Extra flags used when not in debug mode
BASE_FLAGS += -O2
endif
export DEBUG_MODE
UNAME := $(shell uname | cut -c1-6)
ifeq ($(UNAME),CYGWIN)
CC_CPP = i686-w64-mingw32-g++
CC_AR = i686-w64-mingw32-ar
else
CC_CPP = clang++
CC_AR = ar
endif
# Objects directory
O_DIR := _objs
# Jobs
JOBS := 4
# Depend file name
DEPEND := depend.mk
# tmp
SUBMODULE_RULES := $(addsuffix /.git,$(SUBMODULES))
PRINT_OK = printf ' \033[32m$<\033[0m\n'
PRINT_LINK = printf '\033[32m$@\033[0m\n'
# Default rule (need to be before any include)
all: $(SUBMODULE_RULES) init
-make -j$(JOBS) $(NAME)
# Include $(O_FILES) and dependencies
include $(DEPEND)
init: $(LIBS_RULES) $(OBJ_DIR_TREE) $(PUBLIC_LINKS)
# Linking
$(NAME): $(OBJ_DIR_TREE) $(PUBLIC_LINKS) $(LINK_DEPENDS) $(O_FILES)
$(CC_AR) rcs $@ $(O_FILES) && $(PRINT_LINK)
# Compiling
$(O_DIR)/%.o: %.c
clang $(C_FLAGS) -c $< -o $@ && $(PRINT_OK)
$(O_DIR)/%.o: %.cpp
$(CC_CPP) $(CPP_FLAGS) -c $< -o $@ && $(PRINT_OK)
# Init submodules
$(SUBMODULE_RULES):
git submodule init $(@:.git=)
git submodule update $(@:.git=)
# Create include links
$(PUBLIC_LINKS):
ln -fs $(abspath $<) $@
# Create obj directories
$(OBJ_DIR_TREE):
mkdir -p $@
# Set debug mode and make
debug: _debug all
# Clean, set debug mode and make
rebug: fclean debug
# Clean obj files
clean:
-rm -f $(O_FILES) $(PUBLIC_LINKS) 2> /dev/null
-rm -df $(OBJ_DIR_TREE) 2> /dev/null
# Clean everything
fclean: clean
rm -f $(NAME)
# Clean and make
re: fclean all
# Set debug flags
_debug:
$(eval DEBUG_MODE = 1)
.SILENT:
.PHONY: all clean fclean re debug rebug _debug init