-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (85 loc) · 2.27 KB
/
Makefile
File metadata and controls
105 lines (85 loc) · 2.27 KB
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
COM_COLOR = \033[0;34m
OBJ_COLOR = \033[0m
OK_COLOR = \033[0;32m
ERROR_COLOR = \033[0;31m
WARN_COLOR = \033[0;33m
NO_COLOR = \033[m
OK_STRING = "[OK]"
ERROR_STRING = "[ERROR]"
WARN_STRING = "[WARNING]"
COM_STRING = "Compiling"
define run_and_test
printf "%b" "$(COM_COLOR) $(COM_STRING) $(OBJ_COLOR) $(@F) $(NO_COLOR)\r"; \
$(1) 2> [email protected]; \
RESULT=$$?; \
if [ $$RESULT -ne 0 ]; then \
printf "%-60b%b" "$(COM_COLOR) $(COM_STRING) $(OBJ_COLOR) $@" "$(ERROR_COLOR) $(ERROR_STRING) $(NO_COLOR)\n" ; \
elif [ -s [email protected] ]; then \
printf "%-60b%b" "$(COM_COLOR) $(COM_STRING) $(OBJ_COLOR) $@" "$(WARN_COLOR) $(WARN_STRING) $(NO_COLOR)\n" ; \
else \
printf "%-60b%b" "$(COM_COLOR) $(COM_STRING) $(OBJ_COLOR) $(@F)" "$(OK_COLOR) $(OK_STRING) $(NO_COLOR)\n" ; \
fi; \
cat [email protected]; \
rm -f [email protected]; \
exit $$RESULT
endef
app = GPX2
srcExt = cpp
srcDir = src
objDir = obj
binDir = bin
inc = $(shell find -type f -iname "*.hpp" -printf "%h\n" | sort -u)
debug = 0
CFlags = -Wall -std=gnu++17 -O3
LDFlags =
libs =
libDir =
#************************ DO NOT EDIT BELOW THIS LINE! ****************
ifeq ($(debug),1)
debug=-g
else
debug=
endif
inc := $(addprefix -I,$(inc))
libs := $(addprefix -l,$(libs))
libDir := $(addprefix -L,$(libDir))
CFlags += -c $(debug) $(inc) $(libDir) $(libs)
sources := $(shell find $(srcDir) -name '*.$(srcExt)')
srcDirs := $(shell find . -name '*.$(srcExt)' -exec dirname {} \; | uniq)
objects := $(patsubst %.$(srcExt),$(objDir)/%.o,$(sources))
ifeq ($(srcExt),cpp)
CC = $(CXX)
else
CFlags += -std=gnu99
endif
.phony: all clean cleanbin
all: $(binDir)/$(app)
$(binDir)/$(app): COM_STRING = "Linking"
$(binDir)/$(app): buildrepo $(objects)
@mkdir -p `dirname $@`
@$(call run_and_test, $(CC) $(objects) $(LDFlags) -o $@)
$(objDir)/%.o: COM_STRING = "Compiling"
$(objDir)/%.o: %.$(srcExt)
@$(call make-depend,$<,$@,$(subst .o,.d,$@))
@$(call run_and_test, $(CC) $(CFlags) $< -o $@)
clean:
$(RM) -r $(objDir)
cleanbin: clean
$(RM) -r $(binDir)/$(app)
buildrepo:
@$(call make-repo)
define make-repo
for dir in $(srcDirs); \
do \
mkdir -p $(objDir)/$$dir; \
done
endef
# usage: $(call make-depend,source-file,object-file,depend-file)
define make-depend
$(CC) -MM \
-MF $3 \
-MP \
-MT $2 \
$(CFlags) \
$1
endef