-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.build
156 lines (134 loc) · 4.77 KB
/
Makefile.build
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
# -*- makefile-gmake -*-
.PHONY : build-dir
build-dir : build-target
include Makefile.common
include $(CONFIG)
backtrace-0 = -fomit-frame-pointer
backtrace-1 = -fno-omit-frame-pointer
backtrace = $(backtrace-$(CONFIG_BACKTRACE))
bits-0 = 32
bits-1 = 64
CFLAGS = -m$(bits-$(CONFIG_64)) -mno-red-zone -mno-sse -nostdinc -g -O \
-ffreestanding -fno-builtin -fno-stack-protector $(backtrace) -fno-PIE \
-fno-strict-aliasing -Wall $(CONSTANTS-1) -I$(DIR) -Iinclude
ASFLAGS = -m$(bits-$(CONFIG_64)) -g -Wa,-I,$(DIR) -Wa,--divide
LDFLAGS = -m$(bits-$(CONFIG_64)) -g -nostdlib -Wl,--build-id=none -static
outo_p = $(outo)_p
outa_p = $(outa)_p
outp_p = $(outp)_p
target = $(outo)
defouto = $(dir)$(outo)
defouta = $(dir)$(outa)
defoutp = $(dir)$(outp)
include $(dir)Makefile
subouto := $(subdirs-1:%=$(dir)%/$(outo))
subouta := $(asubdirs-1:%=$(dir)%/$(outa))
suboutp := $(psubdirs-1:%=$(dir)%/$(outp))
subouto_p := $(subdirs-1:%=$(dir)%/$(outo_p))
subouta_p := $(asubdirs-1:%=$(dir)%/$(outa_p))
suboutp_p := $(psubdirs-1:%=$(dir)%/$(outp_p))
make-detect := b$(shell echo g)
m-b := b
m-bg := g
m := $(m-$(make-detect))
bins-1 ?=
bobjs-1-name := $(bins-1:%=%-objs)
bobjs-1-b := $(bobjs-1-name:%=$(%))
bobjs-1-g := $(foreach i,$(bobjs-1-name),$($(i)))
bobjs-1 := $(bobjs-1-$(m))
blibs-1-name := $(bins-1:%=%-libs)
blibs-1-b := $(blibs-1-name:%=$(%))
blibs-1-g := $(foreach i,$(blibs-1-name),$($(i)))
blibs-1 := $(blibs-1-$(m))
bstacksize-1-name := $(bins-1:%=%-stacksize)
bstacksize-1-b := $(bstacksize-1-name:%=$(%).)
bstacksize-1-g := $(foreach i,$(bstacksize-1-name),$($(i)).)
bstacksize-1 := $(bstacksize-1-$(m))
bobjs = $(bobjs-1:%=$(dir)%)
objs = $(objs-1:%=$(dir)%) $(subouto) $(subouta) $(suboutp)
deps = $(objs-1:%.o=$(dir)%.d) $(bobjs-1:%.o=$(dir)%.d)
bins = $(bins-1:%=$(dir)%.bin)
flags-data := CFLAGS=$(CFLAGS) ASFLAGS=$(ASFLAGS) LDFLAGS=$(LDFLAGS)
depends-data := include $(deps)
objects-data := $(objs) $(bobjs)
boptions-data := bobjs=$(bobjs) blibs=$(blibs-1) bstacksize=$(bstacksize-1)
$(defouto) : $(objs) $(dir)$(depends) $(dir)$(objects)
$(V-info) LD $(defouto)
$(CC) $(LDFLAGS) -Wl,-r -o $(defouto) $(objs)
$(defouta) : $(objs) $(dir)$(depends)
$(V-info) AR $(defouta)
$(RM) $(defouta)
$(AR) cr $(defouta) $(objs)
$(defoutp) : $(bins) $(dir)$(depends) $(dir)$(objects)
$(V-info) LD $(defoutp)
$(CC) $(ASFLAGS) $(LDFLAGS) -Wl,-r -o $(defoutp) $(bins:%=%.s)
$(bins) : $(bobjs) $(blibs-1) $(objs) $(dir)$(boptions)
$(V-info) LD $@
echo '.section .processes' > [email protected]
echo '.long prc_$(*F)_name, 0, prc_$(*F)_bin, 0' >> [email protected]
echo '.quad prc_$(*F)_bin_end - prc_$(*F)_bin' >> [email protected]
echo '.quad $($(*F)-stacksize)+0' >> [email protected]
echo '.data' >> [email protected]
echo 'prc_$(*F)_name: .string "$(*F)"' >> [email protected]
echo 'prc_$(*F)_bin: .incbin "$@"' >> [email protected]
echo 'prc_$(*F)_bin_end:' >> [email protected]
$(CC) $(LDFLAGS) -o $@ $($(*F)-objs:%=$(dir)%) \
$($(*F)-libs) $(objs)
$(objs) $(bobjs) : $(dir)$(flags)
$(dir)$(flags) : update-flags
@:
.PHONY : update-flags
update-flags :
@set -- $(flags-data); \
case "$$*" in "`$(SED) 1q $(dir)$(flags) 2>/dev/null`");; \
*)echo "$$*" > $(dir)$(flags);; esac
$(dir)$(depends) : update-depends
@:
.PHONY : update-depends
update-depends :
set -- $(depends-data); \
case $$# in 1)a='#empty';; *)a="$$*";; esac; \
case "$$a" in "`$(SED) 1q $(dir)$(depends) 2>/dev/null`");; \
*)while shift; case $$# in 0)false;; *):;; esac; do : >> "$$1"; done; \
echo "$$a" > $(dir)$(depends);; esac
$(dir)$(objects) : update-objects
@:
.PHONY : update-objects
update-objects :
@set -- $(objects-data); \
case "$$*" in "`$(SED) 1q $(dir)$(objects) 2>/dev/null`");; \
*)echo "$$*" > $(dir)$(objects);; esac
$(dir)$(boptions) : update-boptions
@:
.PHONY : update-boptions
update-boptions :
@set -- $(boptions-data); \
case "$$*" in "`$(SED) 1q $(dir)$(boptions) 2>/dev/null`");; \
*)echo "$$*" > $(dir)$(boptions);; esac
.PHONY : build-target
build-target : $(dir)$(target)
$(subouto) $(subouta) $(suboutp) : $(subouto_p) $(subouta_p) $(suboutp_p)
@:
.PHONY : $(subouto_p) $(subouta_p) $(suboutp_p)
$(subouto_p) $(subouta_p) $(suboutp_p) :
case "`$(SED) 1q $(@D)/$(depends) 2>/dev/null`" in \
''): >> $(@D)/$(depends);; esac
$(MAKE) $(V-makeopt) -f Makefile.build $(@:_p=) DIR=$(@D) V=$(V)
# Suffix rules
.SUFFIXES :
.SUFFIXES : .c .s .o .bin
.c.o :
$(V-info) CC $@
$(CC) $(CFLAGS) -MD -c -o $@ $< && \
$(SED) -n -e 's/.*: *//' -e '/^ *$$/d' -e :a -e '/\\$$/{N' -e ba -e '}' \
-e 's/$$/ :/' -e H -e '$${x' -e p -e q -e '}' < $(@:.o=).d >> $(@:.o=).d || \
{ $(RM) $@; false; }
.s.o :
$(V-info) CC $@
$(CC) $(ASFLAGS) -c -o $@ $< && \
$(SED) -n -e '1{x' -e 's=^=$@ :>=' -e x -e '}' -e 's/#.*//' \
-e '/\.include ".*"/{s=.*\.include "\([^"]*\)".*=<$(@D)/\1>=' -e H -e '}' \
-e '$${x' -e 's/>.</ /g' -e 's/>$$//p' -e 's/.*: *//' \
-e 's/$$/ :/p' -e '}' $< > $(@:.o=).d || { $(RM) $@; false; }
# include
include $(dir)$(depends)