-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.mk
164 lines (131 loc) · 4.26 KB
/
config.mk
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
all:
CC := $(CROSS_COMPILE)gcc
CXX := $(CROSS_COMPILE)g++
STRIP := $(CROSS_COMPILE)strip
AR ?= ar
HOSTCC ?= gcc
HOSTCXX ?= g++
HOSTSTRIP ?= strip
RM ?= rm -f
RMDIR ?= rmdir
T ?= release
ARFLAGS = rcs
ifeq ($(T), debug)
CFLAGS += -Wall -g -O2 -DDEBUG
CXXFLAGS += -Wall -g -O2 -DDEBUG
HOSTCFLAGS += -Wall -g -O2
HOSTCXXFLAGS += -Wall -g -O2
else
CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 \
-fno-common
CXXFLAGS += -Wall -fomit-frame-pointer -O2 -fno-common
LDFLAGS += -s
HOSTCFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 \
-fno-common
HOSTCXXFLAGS += -Wall -fomit-frame-pointer -O2 -fno-common
HOSTLDFLAGS += -s
endif
CFLAGS += -pipe
HOSTCFLAGS += -pipe
ifeq ($(Q),)
quiet := quiet_
else
quiet :=
endif
test.x86-objs = test.o
test3.x86-objs = test3.o
dot-target = $(dir $@).$(notdir $@)
depfile = $(dot-target).d
getm-objs = $(if $($(1)-objs),$($(1)-objs),$(1).o)
echo-cmd = @echo ' $($(quiet)cmd_$(1))';
cmd = @$(echo-cmd) $(cmd_$(1))
ifeq ($(findstring Win,$(OS)),Win)
gen-target = $(if 1,$(1).exe)
gen-targets = $(foreach m,$(1),$(addsuffix .exe,$(m)))
rm-suffix = $(patsubst %.exe,%,$(1))
else
gen-target = $(1)
gen-targets = $(1)
rm-suffix = $(1)
endif
define module_template
$(call gen-target,$(1)): $(addprefix $($(2)-dir)/,$(call getm-objs,$(1))) $($(1)-lds)
endef
define target_template
$(1)-dir ?= .$(1)
$(1)-objs := $(sort $(foreach m,$($(1)),$(call getm-objs,$(m))))
objs := $(obj) $$($(1)-objs)
$(1)-objs := $$(addprefix $$($(1)-dir)/,$$($(1)-objs))
endef
$(eval $(call target_template,host))
$(foreach m,$(host),$(eval $(call module_template,$(m),host)))
$(eval $(call target_template,progs))
$(foreach m,$(progs),$(eval $(call module_template,$(m),progs)))
deps-dir ?= .deps
deps := $(addprefix $(deps-dir)/,$(patsubst %.o,%.d,$(objs)))
quiet_cmd_host-objs = HOSTCC $(notdir $@)
cmd_host-objs = mkdir -p $(dir $@); $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
quiet_cmd_host = HOSTLD $@
cmd_host = mkdir -p $(dir $@); \
$(HOSTCC) $(HOSTLDFLAGS) -o $@ \
$(addprefix $(host-dir)/, \
$(call getm-objs,$(call rm-suffix,$(@F)))) \
$($(call rm-suffix,$(@F))-libs) $(HOSTLDLIBS) \
$($(call rm-suffix,$(@F))-lds)
quiet_cmd_progs-objs = CC $(notdir $@)
cmd_progs-objs = $(CC) $(CFLAGS) -c -o $@ $<
quiet_cmd_progs = LD $@
cmd_progs = mkdir -p $(dir $@); \
$(CC) $(LDFLAGS) -o $@ \
$(addprefix $(progs-dir)/, \
$(call getm-objs,$(call rm-suffix,$(@F)))) \
$($(call rm-suffix,$(@F))-lds) $(LDLIBS) \
$($(call rm-suffix,$(@F))-libs)
clean_dir = (cd $(1) && $(RM) $(2) -f) >/dev/null 2>&1; \
$(RMDIR) $(1) >/dev/null 2>&1; :
quiet_cmd_clean_host = CLEAN host
cmd_clean_host = $(call clean_dir,$(host-dir),*.o); \
$(RM) $(host-target) -f ; :
quiet_cmd_clean_progs = CLEAN progs
cmd_clean_progs = $(call clean_dir,$(progs-dir),*.o); \
$(RM) $(progs-target) -f ; :
quiet_cmd_clean_dep = CLEAN deps
cmd_clean_dep = $(call clean_dir,$(deps-dir),*.d)
host-target := $(call gen-targets,$(host))
progs-target := $(call gen-targets,$(progs))
ifeq ($(Q),)
QUIET_CC = @echo ' CC $@'; $(CC) $(CFLAGS) -c -o $@ $<
QUIET_AR = @echo ' AR $@'; $(AR) $(ARFLAGS) $@ $^
QUIET_LINK = @echo ' LINK $@'; $(CC)
QUIET_RM = @echo ' CLEAN $1'; $(RM) -f $1
else
QUIET_CC = $(CC) $(CFLAGS) -c -o $@ $<
QUIET_AR = $(AR) $(ARFLAGS) $@ $^
QUIET_LINK = $(CC)
QUIET_RM = $(RM) -f
endif
.PHONY: all
all: DEPS $(host-target) $(progs-target)
$(host):
$(call cmd,host)
$(host-objs) : $(host-dir)/%.o : %.c
@mkdir -p $(dir $@);
$(call cmd,host-objs)
$(progs-target):
$(call cmd,progs)
$(progs-objs) : $(progs-dir)/%.o : %.c
@mkdir -p $(dir $@);
$(call cmd,progs-objs)
DEPS: $(deps)
#$(deps)
$(deps-dir)/%.d:%.c
@mkdir -p $(deps-dir)
@$(CC) $(CFLAGS) -MM -MF $@.$$$$ $<; \
sed 's,\($*\)\.o[ :]*,$(progs-dir)/\1.o $(host-dir)/\1.o $@ : Makefile ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
clean::
$(call cmd,clean_host)
$(call cmd,clean_progs)
$(call cmd,clean_dep)
distclean: clean
-include $(deps)