-
Notifications
You must be signed in to change notification settings - Fork 266
/
Makefile
284 lines (223 loc) · 7.68 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
OUTPUT = $(CURDIR)/output
BINUTILS_SRCDIR = BINUTILS_SRCDIR_not_set
GCC_SRCDIR = GCC_SRCDIR_not_set
MUSL_SRCDIR = MUSL_SRCDIR_not_set
GCC_CONFIG_FOR_TARGET =
COMMON_CONFIG =
GCC_CONFIG =
TOOLCHAIN_CONFIG =
XGCC_DIR = ../obj_gcc/gcc
XGCC = $(XGCC_DIR)/xgcc -B $(XGCC_DIR)
-include config.mak
ifneq ($(findstring fdpic,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --enable-fdpic
endif
ifneq ($(filter x86_64%x32,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-abi=x32
endif
ifneq ($(findstring powerpc64,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-abi=elfv2
endif
ifneq ($(findstring mips64,$(TARGET))$(findstring mipsisa64,$(TARGET)),)
ifneq ($(findstring n32,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-abi=n32
else
GCC_CONFIG_FOR_TARGET += --with-abi=64
endif
endif
ifneq ($(findstring s390x,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-long-double-128
endif
ifneq ($(filter %sf,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-float=soft
endif
ifneq ($(filter %hf,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-float=hard
endif
ifneq ($(LIBTOOL),)
LIBTOOL_ARG = LIBTOOL=$(LIBTOOL)
endif
MAKE += MULTILIB_OSDIRNAMES=
MAKE += INFO_DEPS= infodir=
MAKE += ac_cv_prog_lex_root=lex.yy
MAKE += MAKEINFO=false
FULL_BINUTILS_CONFIG = \
--disable-separate-code \
$(COMMON_CONFIG) $(BINUTILS_CONFIG) $(TOOLCHAIN_CONFIG) \
--disable-werror \
--target=$(TARGET) --prefix= \
--libdir=/lib --disable-multilib \
--with-sysroot=$(SYSROOT) \
--enable-deterministic-archives
FULL_GCC_CONFIG = --enable-languages=c,c++ \
$(GCC_CONFIG_FOR_TARGET) \
$(COMMON_CONFIG) $(GCC_CONFIG) $(TOOLCHAIN_CONFIG) \
--disable-bootstrap \
--disable-assembly \
--disable-werror \
--target=$(TARGET) --prefix= \
--libdir=/lib --disable-multilib \
--with-sysroot=$(SYSROOT) \
--enable-tls \
--disable-libmudflap --disable-libsanitizer \
--disable-gnu-indirect-function \
--disable-libmpx \
--enable-initfini-array \
--enable-libstdcxx-time=rt
FULL_MUSL_CONFIG = $(MUSL_CONFIG) \
--prefix= --host=$(TARGET)
ifneq ($(NATIVE),)
HOST:=$(TARGET)
endif
ifeq ($(BUILD),)
GUESS = $(shell cd $(GCC_SRCDIR) && ./config.guess)
TARGET_CANON = $(shell cd $(GCC_SRCDIR) && ./config.sub $(TARGET))
BUILD = $(GUESS)$(if $(subst $(TARGET_CANON),,$(GUESS)),,xx)
endif
ifeq ($(HOST),)
SYSROOT = /$(TARGET)
FULL_BINUTILS_CONFIG += --build=$(BUILD) --host=$(BUILD)
FULL_GCC_CONFIG += --with-build-sysroot=$(CURDIR)/obj_sysroot \
AR_FOR_TARGET=$(PWD)/obj_binutils/binutils/ar \
AS_FOR_TARGET=$(PWD)/obj_binutils/gas/as-new \
LD_FOR_TARGET=$(PWD)/obj_binutils/ld/ld-new \
NM_FOR_TARGET=$(PWD)/obj_binutils/binutils/nm-new \
OBJCOPY_FOR_TARGET=$(PWD)/obj_binutils/binutils/objcopy \
OBJDUMP_FOR_TARGET=$(PWD)/obj_binutils/binutils/objdump \
RANLIB_FOR_TARGET=$(PWD)/obj_binutils/binutils/ranlib \
READELF_FOR_TARGET=$(PWD)/obj_binutils/binutils/readelf \
STRIP_FOR_TARGET=$(PWD)/obj_binutils/binutils/strip-new \
--build=$(BUILD) --host=$(BUILD) \
# end
FULL_MUSL_CONFIG += CC="$(XGCC)" LIBCC="../obj_gcc/$(TARGET)/libgcc/libgcc.a"
MUSL_VARS = AR=../obj_binutils/binutils/ar RANLIB=../obj_binutils/binutils/ranlib
obj_musl/.lc_configured: | obj_gcc/gcc/.lc_built
obj_musl/.lc_built: | obj_gcc/$(TARGET)/libgcc/libgcc.a
obj_gcc/gcc/.lc_built: | obj_sysroot/usr obj_sysroot/lib32 obj_sysroot/lib64 obj_sysroot/include
obj_gcc/.lc_built: | obj_sysroot/.lc_libs obj_sysroot/.lc_headers
obj_gcc/.lc_configured: obj_binutils/.lc_built
else
SYSROOT = /
FULL_BINUTILS_CONFIG += --build=$(BUILD) --host=$(HOST)
FULL_GCC_CONFIG += --build=$(BUILD) --host=$(HOST)
MUSL_VARS =
endif
ifeq ($(TARGET),)
all:
@echo TARGET must be set.
@exit 1
install: all
else
all: musl gcc binutils
install: install-musl install-gcc install-binutils
musl: obj_musl/.lc_built
toolchain: gcc binutils
install-toolchain: install-gcc install-binutils
gcc: obj_gcc/.lc_built
binutils: obj_binutils/.lc_built
.PHONY: all musl toolchain install-musl install-toolchain clean
src_binutils: | $(BINUTILS_SRCDIR)
ln -sf $(BINUTILS_SRCDIR) $@
src_gcc_base: | $(GCC_SRCDIR)
ln -sf $(GCC_SRCDIR) $@
src_musl: | $(MUSL_SRCDIR)
ln -sf $(MUSL_SRCDIR) $@
ifneq ($(GMP_SRCDIR),)
src_gcc: src_gmp
src_gmp: | $(GMP_SRCDIR)
ln -sf "$(GMP_SRCDIR)" $@
endif
ifneq ($(MPC_SRCDIR),)
src_gcc: src_mpc
src_mpc: | $(MPC_SRCDIR)
ln -sf "$(MPC_SRCDIR)" $@
endif
ifneq ($(MPFR_SRCDIR),)
src_gcc: src_mpfr
src_mpfr: | $(MPFR_SRCDIR)
ln -sf "$(MPFR_SRCDIR)" $@
endif
ifneq ($(ISL_SRCDIR),)
src_gcc: src_isl
src_isl: | $(ISL_SRCDIR)
ln -sf "$(ISL_SRCDIR)" $@
endif
src_gcc: src_gcc_base
rm -rf $@ $@.tmp
mkdir $@.tmp
cd $@.tmp && ln -sf ../src_gcc_base/* .
$(if $(GMP_SRCDIR),cd $@.tmp && ln -sf ../src_gmp gmp)
$(if $(MPC_SRCDIR),cd $@.tmp && ln -sf ../src_mpc mpc)
$(if $(MPFR_SRCDIR),cd $@.tmp && ln -sf ../src_mpfr mpfr)
$(if $(ISL_SRCDIR),cd $@.tmp && ln -sf ../src_isl isl)
mv $@.tmp $@
obj_%:
mkdir -p $@
obj_sysroot/include:
mkdir -p $@
obj_sysroot/usr: | obj_sysroot
ln -sf . $@
obj_sysroot/lib32: | obj_sysroot
ln -sf lib $@
obj_sysroot/lib64: | obj_sysroot
ln -sf lib $@
obj_binutils/.lc_configured: | obj_binutils src_binutils
cd obj_binutils && ../src_binutils/configure $(FULL_BINUTILS_CONFIG)
touch $@
obj_binutils/.lc_built: | obj_binutils/.lc_configured
cd obj_binutils && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" all
touch $@
obj_gcc/.lc_configured: | obj_gcc src_gcc
cd obj_gcc && ../src_gcc/configure $(FULL_GCC_CONFIG)
touch $@
obj_gcc/gcc/.lc_built: | obj_gcc/.lc_configured
cd obj_gcc && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" all-gcc
touch $@
obj_musl/.lc_configured: | obj_musl src_musl
cd obj_musl && ../src_musl/configure $(FULL_MUSL_CONFIG)
touch $@
obj_sysroot/.lc_headers: | obj_musl/.lc_configured obj_sysroot
cd obj_musl && $(MAKE) DESTDIR=$(CURDIR)/obj_sysroot install-headers
touch $@
obj_gcc/$(TARGET)/libgcc/libgcc.a: | obj_sysroot/.lc_headers
cd obj_gcc && $(MAKE) MAKE="$(MAKE) enable_shared=no $(LIBTOOL_ARG)" all-target-libgcc
obj_musl/.lc_built: | obj_musl/.lc_configured
cd obj_musl && $(MAKE) $(MUSL_VARS)
touch $@
obj_sysroot/.lc_libs: | obj_musl/.lc_built
cd obj_musl && $(MAKE) $(MUSL_VARS) DESTDIR=$(CURDIR)/obj_sysroot install
touch $@
obj_gcc/.lc_built: | obj_gcc/.lc_configured obj_gcc/gcc/.lc_built
cd obj_gcc && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)"
touch $@
install-musl: | obj_musl/.lc_built
cd obj_musl && $(MAKE) $(MUSL_VARS) DESTDIR=$(DESTDIR)$(OUTPUT)$(SYSROOT) install
install-binutils: | obj_binutils/.lc_built
cd obj_binutils && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" DESTDIR=$(DESTDIR)$(OUTPUT) install
install-gcc: | obj_gcc/.lc_built
cd obj_gcc && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" DESTDIR=$(DESTDIR)$(OUTPUT) install
ln -sf $(TARGET)-gcc $(DESTDIR)$(OUTPUT)/bin/$(TARGET)-cc
ifneq ($(LINUX_SRCDIR),)
TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(TARGET_ARCH)))
LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
ifneq ($(LINUX_ARCH),)
all: kernel-headers
install: install-kernel-headers
kernel-headers: | obj_kernel_headers/.lc_built
src_kernel_headers: | $(LINUX_SRCDIR)
ln -sf "$(LINUX_SRCDIR)" $@
obj_kernel_headers/.lc_built: | src_kernel_headers
mkdir -p $(CURDIR)/obj_kernel_headers/staged
cd src_kernel_headers && $(MAKE) ARCH=$(LINUX_ARCH) O=$(CURDIR)/obj_kernel_headers INSTALL_HDR_PATH=$(CURDIR)/obj_kernel_headers/staged headers_install
find obj_kernel_headers/staged/include '(' -name .install -o -name ..install.cmd ')' -exec rm {} +
touch $@
install-kernel-headers: | obj_kernel_headers/.lc_built
mkdir -p $(DESTDIR)$(OUTPUT)$(SYSROOT)/include
cp -R obj_kernel_headers/staged/include/* $(DESTDIR)$(OUTPUT)$(SYSROOT)/include
endif
endif
endif
clean:
rm -rf src_* obj_*