-
Notifications
You must be signed in to change notification settings - Fork 116
/
Makefile.lib
100 lines (76 loc) · 2.74 KB
/
Makefile.lib
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
# 'There's more than one passage here,' he whispered with an effort: it seemed
# hard to make his breath give any sound. `It's as orc-like a place as ever
# there could be! '
### The build commands and verbosity
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
# @ in the non-verbose mode), and we will show the "real" cmds instead of
# their quiet versions (which are used in the non-verbose mode).
# Inspired by the Linux kernel build system.
ifdef V
Q =
quiet =
mquiet = masq_
else
Q = @
quiet = quiet_
mquiet = quiet_
endif
# Show the command (quiet or non-quiet version based on the assignment
# just above) and then execute it.
ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
quiet_cmd_compile = '[CC] $<'
masq_cmd_compile = $(COMPILE) -c $<
cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
quiet_cmd_compilexx = '[CXX] $<'
masq_cmd_compilexx = $(COMPILEXX) -c $<
cmd_compilexx = $(COMPILEXX) -Wp,-MD,.deps/$(*F).pp -c $<
quiet_cmd_archive =
cmd_archive = $(AR) r $@ $^ >/dev/null 2>&1
quiet_cmd_link = '[LINK] $@'
cmd_link = $(LINK) -o $@ $^ $(LIBS)
# Recursive make
quiet_cmd_recmake = "[make] $$subdir"
cmd_recmake = $(MAKE) -s -C $$subdir $$target
### Internal build rules
CFLAGS := $(COMMON_FLAGS) $(CFLAGS) $(XCFLAGS)
CXXFLAGS := $(COMMON_FLAGS) $(CXXFLAGS) $(XCFLAGS)
LDFLAGS := $(LDFLAGS) $(XLDFLAGS)
COMPILE = $(CC) $(CFLAGS) $(INCLUDES)
COMPILEXX = $(CXX) $(CXXFLAGS) $(INCLUDES)
LINK = $(CC) $(LDFLAGS)
DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
DEP_FILES = $(DEP_FILES_1:%.o=%.P)
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
ifdef DEP_FILES
-include $(DEP_FILES)
endif
%.o: %.c
$(call mcmd,compile)
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.o: %.cpp
$(call mcmd,compilexx)
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.a:
$(call cmd,archive)
# Recursion:
.PHONY: all-recursive clean-recursive clean-profiles-recursive
all-recursive clean-recursive clean-profiled-recursive:
+@target=`echo $@ | sed s/-recursive//`; \
for subdir in $(SUBDIRS); do \
$(call ncmd,recmake) || exit 1; \
done
# Main makefile may add extra commands by creating another clean:: rule
clean::
-@rm -f *.[oa] *~ >/dev/null 2>&1
clean-profiled:: clean-profiled-recursive
-@rm -f *.gcda *.gcno >/dev/null 2>&1