-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
341 lines (289 loc) · 13.5 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#######################################################
# #
# Makefile #
# #
# Sean<[email protected]> #
# #
# Usage: Script to build arm-linux-gnueabi(arm32) #
# #
#######################################################
# Platform: ubuntu16.04/Niaoyun VPS #
#######################################################
# setup-env - envirments setup #
#######################################################
#setup-env:
#customize here
#------------------------8<----------------------------
ALIAS := arm-linux
_BIN_VER_ := 2.30
_GCC_VER_ := 7.3.0
_LIB_VER_ := 2.27
_GDB_VER_ := 8.1
_KNL_VER_ := 4.10.8
#_PATH_ := ${HOME}/gnutools
_PATH_ :=
_OPTIONS_ := --disable-nls
#------------------------8<----------------------------
ARCH := arm
TARGET := arm-linux-gnueabi
BINUTILS_VERSION := binutils-${_BIN_VER_}
GCC_VERSION := gcc-${_GCC_VER_}
GLIBC_VERSION := glibc-${_LIB_VER_}
GDB_VERSION := gdb-${_GDB_VER_}
KERNEL_VERSION := linux-${_KNL_VER_}
_TOP_DIR_ := $$(pwd)
ifeq (${_PATH_}, )
PREFIX_PARENT := ${_TOP_DIR_}/gnutools
else
PREFIX_PARENT := ${_PATH_}
endif
PRJROOT := ${_TOP_DIR_}/build/${TARGET}-${_GCC_VER_}
PREFIX := ${PREFIX_PARENT}/${TARGET}-${_GCC_VER_}
TARGET_PREFIX := ${PREFIX}/${TARGET}
#SW_DL_URL := ftp://sources.redhat.com/pub
#SW_DL_URL := https://mirrors.ustc.edu.cn
SW_DL_URL := https://mirrors.tuna.tsinghua.edu.cn
DLFLAGS := -c --tries=0 --timeout=10
#function to check wheather file exsits in path
#return empty, if doesn't exist
#$(1) - name
#$(2) - path
#$(call FILE_DIR_EXIST,name,path)
FILE_DIR_EXIST=$(filter %$(1), $(shell echo $(2)/*))
.PHONY: all
@echo "build end!"
all: show-info setup-dir setup-dl setup-uzp build-bin build-cc1 build-hdr build-lib build-cc2 build-gdb build-lnk build-pac
# @echo "start all!"
# make setup-pkg
# make setup-env
# make show-info
# make setup-dir
# make setup-dl
# make setup-uzp
# make build-bin
# make build-cc1
# make build-hdr
# make build-lib
# make build-cc2
# make build-gdb
# make build-lnk
# make build-pac
@echo "end all!"
#######################################################
# show-info - show the directory infos #
#######################################################
show-info:
@echo "show info..."
@echo "-----------------8<---------------------"
@echo "ALIAS := "${ALIAS}
@echo "BINUTILS_VERSION := "${BINUTILS_VERSION}
@echo "GCC_VERSION := "${GCC_VERSION}
@echo "GDB_VERSION := "${GDB_VERSION}
@echo "KERNEL_VERSION := "${KERNEL_VERSION}
@echo "GLIBC_VERSION := "${GLIBC_VERSION}
@echo "PRJROOT := "${PRJROOT}
@echo "PREFIX := "${PREFIX}
@echo "_OPTIONS_ := "${_OPTIONS_}
@echo "-----------------8<---------------------"
@echo "show info end"
#######################################################
# setup-pkg - prerequisite #
#######################################################
#setup-pkg:
# sudo apt-get install libncurses5-dev gperf bison flex texinfo help2man gawk libtool libtool-bin automake
#######################################################
# setup-dir - directory structure construct #
#######################################################
setup-dir:
@echo "setup dir..."
mkdir -pv ${PRJROOT} ${PREFIX}
mkdir -pv ${_TOP_DIR_}/package
mkdir -pv ${_TOP_DIR_}/target
mkdir -pv ${PRJROOT}/src
mkdir -pv ${PRJROOT}/bld
cp -rf ${_TOP_DIR_}/test ${PRJROOT}
mkdir -pv ${PRJROOT}/bld/${BINUTILS_VERSION}
mkdir -pv ${PRJROOT}/bld/${GCC_VERSION}-pass1
mkdir -pv ${PRJROOT}/bld/${GCC_VERSION}-pass2
mkdir -pv ${PRJROOT}/bld/${GDB_VERSION}
mkdir -pv ${PRJROOT}/bld/${GLIBC_VERSION}
# tree -L 3
@echo "setup dir end"
#######################################################
# setup-dl - donload tarballs #
#######################################################
#an urgerly implimentation, should be optimized
ifneq ($(_KNL_VER_:2.%=Z.%), $(_KNL_VER_))
_MID_DIR_ := v2.6
endif
ifneq ($(_KNL_VER_:3.%=Z.%), $(_KNL_VER_))
_MID_DIR_ := v3.x
endif
ifneq ($(_KNL_VER_:4.%=Z.%), $(_KNL_VER_))
_MID_DIR_ := v4.x
endif
ifneq ($(_KNL_VER_:5.%=Z.%), $(_KNL_VER_))
_MID_DIR_ := v5.x
endif
ifndef _MID_DIR_
$(error "unsupport kernel version")
endif
setup-dl:
#download tarballs here
@echo "download src..."
wget ${DLFLAGS} -O ${_TOP_DIR_}/package/binutils-${_BIN_VER_}.tar.xz ${SW_DL_URL}/gnu/binutils/binutils-${_BIN_VER_}.tar.xz
wget ${DLFLAGS} -O ${_TOP_DIR_}/package/gcc-${_GCC_VER_}.tar.xz ${SW_DL_URL}/gnu/gcc/gcc-${_GCC_VER_}/gcc-${_GCC_VER_}.tar.xz
wget ${DLFLAGS} -O ${_TOP_DIR_}/package/gdb-${_GDB_VER_}.tar.xz ${SW_DL_URL}/gnu/gdb/gdb-${_GDB_VER_}.tar.xz
wget ${DLFLAGS} -O ${_TOP_DIR_}/package/glibc-${_LIB_VER_}.tar.xz ${SW_DL_URL}/gnu/glibc/glibc-${_LIB_VER_}.tar.xz
wget ${DLFLAGS} -O ${_TOP_DIR_}/package/linux-${_KNL_VER_}.tar.xz ${SW_DL_URL}/kernel/$(_MID_DIR_)/linux-${_KNL_VER_}.tar.xz
@echo "download src end"
#######################################################
# setup-uzp - unzip tarballs #
#######################################################
setup-uzp:
@echo "unzip src..."
ifeq ($(call FILE_DIR_EXIST,binutils-${_BIN_VER_},${PRJROOT}/src),)
tar -Jxvf ${_TOP_DIR_}/package/binutils-${_BIN_VER_}.tar.xz -C ${PRJROOT}/src
endif
ifeq ($(call FILE_DIR_EXIST,gcc-${_GCC_VER_},${PRJROOT}/src),)
tar -Jxvf ${_TOP_DIR_}/package/gcc-${_GCC_VER_}.tar.xz -C ${PRJROOT}/src
endif
ifeq ($(call FILE_DIR_EXIST,gdb-${_GDB_VER_},${PRJROOT}/src),)
tar -Jxvf ${_TOP_DIR_}/package/gdb-${_GDB_VER_}.tar.xz -C ${PRJROOT}/src
endif
ifeq ($(call FILE_DIR_EXIST,linux-${_KNL_VER_},${PRJROOT}/src),)
tar -Jxvf ${_TOP_DIR_}/package/linux-${_KNL_VER_}.tar.xz -C ${PRJROOT}/src
endif
ifeq ($(call FILE_DIR_EXIST,glibc-${_LIB_VER_},${PRJROOT}/src),)
tar -Jxvf ${_TOP_DIR_}/package/glibc-${_LIB_VER_}.tar.xz -C ${PRJROOT}/src
endif
@echo "unzip src end"
#######################################################
# build-hdr - build linux headers #
#######################################################
build-hdr:
@echo "build hdr..."
ifeq ($(call FILE_DIR_EXIST,version.h,${PREFIX}/${TARGET}/include/linux),)
make -C ${PRJROOT}/src/${KERNEL_VERSION} ARCH=${ARCH} CROSS_COMPILE=${PREFIX}/bin/${TARGET}- INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install
endif
@echo "build hdr end"
#######################################################
# build-bin - binutils #
#######################################################
build-bin:
@echo "build bin..."
cp -f ${_TOP_DIR_}/Makefile ${PRJROOT}/bld/${BINUTILS_VERSION}/Makefile.inn
make -C ${PRJROOT}/bld/${BINUTILS_VERSION} -f Makefile.inn build-bin-inner _PRJROOT_INN_=${PRJROOT} _PREFIX_INN_=${PREFIX}
@echo "build bin end"
build-bin-inner:
ifeq ($(call FILE_DIR_EXIST,Makefile,${_PRJROOT_INN_}/bld/${BINUTILS_VERSION}),)
${_PRJROOT_INN_}/src/${BINUTILS_VERSION}/configure --target=${TARGET} --prefix=${_PREFIX_INN_} --enable-shared ${_OPTIONS_} 2>&1 |tee configure.out
endif
make -w all install 2>&1 |tee make.out
#######################################################
# build-cc1 - gcc-pass1 #
#######################################################
build-cc1:
@echo "build cc1..."
cp -f ${_TOP_DIR_}/Makefile ${PRJROOT}/bld/${GCC_VERSION}-pass1/Makefile.inn
make -C ${PRJROOT}/bld/${GCC_VERSION}-pass1 -f Makefile.inn build-cc1-inner _PRJROOT_INN_=${PRJROOT} _PREFIX_INN_=${PREFIX}
@echo "build cc1 end"
build-cc1-inner:
ifeq ($(call FILE_DIR_EXIST,Makefile,${_PRJROOT_INN_}/bld/${GCC_VERSION}-pass1),)
${_PRJROOT_INN_}/src/${GCC_VERSION}/configure --target=${TARGET} --prefix=${_PREFIX_INN_} --enable-languages=c --disable-shared --disable-threads --without-headers --disable-libmudflap --disable-nls 2>&1 |tee configure.out
endif
make -w all-gcc install-gcc 2>&1 |tee make-gcc.out
make -w all-target-libgcc install-target-libgcc 2>&1 |tee make-target-libgcc.out
#######################################################
# build-lib build glibc #
#######################################################
build-lib:
@echo "build lib..."
cp -f ${_TOP_DIR_}/Makefile ${PRJROOT}/bld/${GLIBC_VERSION}/Makefile.inn
make -C ${PRJROOT}/bld/${GLIBC_VERSION} -f Makefile.inn build-lib-inner _PRJROOT_INN_=${PRJROOT} _PREFIX_INN_=${PREFIX}
@echo "build lib end"
_LIB_INNER_FLAGS_ := CC=${_PREFIX_INN_}/bin/${TARGET}-gcc CXX=${_PREFIX_INN_}/bin/${TARGET}-g++ AR=${_PREFIX_INN_}/bin/${TARGET}-ar AS=${_PREFIX_INN_}/bin/${TARGET}-as RANLIB=${_PREFIX_INN_}/bin/${TARGET}-ranlib READELF=${_PREFIX_INN_}/bin/${TARGET}-readelf NM=${_PREFIX_INN_}/bin/${TARGET}-nm
build-lib-inner:
ifeq ($(call FILE_DIR_EXIST,Makefile,${_PRJROOT_INN_}/bld/${GLIBC_VERSION}),)
${_PRJROOT_INN_}/src/${GLIBC_VERSION}/configure ${_LIB_INNER_FLAGS_} --host=${TARGET} --prefix=${_PREFIX_INN_}/${TARGET} --with-tls --disable-profile --enable-add-ons --with-headers=${_PREFIX_INN_}/${TARGET}/include libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_arm_tls=yes ${_OPTIONS_} 2>&1 |tee configure.out
endif
make ${_LIB_INNER_FLAGS} -w all install 2>&1 |tee make.out
#######################################################
# build-cc2 - gcc-pass2 #
#######################################################
build-cc2:
@echo "build cc2..."
cp -f ${_TOP_DIR_}/Makefile ${PRJROOT}/bld/${GCC_VERSION}-pass2/Makefile.inn
make -C ${PRJROOT}/bld/${GCC_VERSION}-pass2 -f Makefile.inn build-cc2-inner _PRJROOT_INN_=${PRJROOT} _PREFIX_INN_=${PREFIX}
@echo "build cc2 end"
build-cc2-inner:
ifeq ($(call FILE_DIR_EXIST,Makefile,${_PRJROOT_INN_}/bld/${GCC_VERSION}-pass2),)
${_PRJROOT_INN_}/src/${GCC_VERSION}/configure --target=${TARGET} --prefix=${_PREFIX_INN_} --enable-languages=c,c++ --enable-shared ${_OPTIONS_} 2>&1 |tee configure.out
endif
make -w all install 2>&1 |tee make.out
#######################################################
# build-gdb - build gdb #
#######################################################
build-gdb:
@echo "build gdb..."
cp -f ${_TOP_DIR_}/Makefile ${PRJROOT}/bld/${GDB_VERSION}/Makefile.inn
make -C ${PRJROOT}/bld/${GDB_VERSION} -f Makefile.inn build-gdb-inner _PRJROOT_INN_=${PRJROOT} _PREFIX_INN_=${PREFIX}
@echo "build gdb end"
build-gdb-inner:
ifeq ($(call FILE_DIR_EXIST,Makefile,${_PRJROOT_INN_}/bld/${GDB_VERSION}),)
${_PRJROOT_INN_}/src/${GDB_VERSION}/configure --target=${TARGET} --prefix=${_PREFIX_INN_} --enable-shared ${_OPTIONS_} 2>&1 |tee configure.out
endif
make -w all install 2>&1 |tee make.out
#######################################################
# build-lnk - build alias #
#######################################################
build-lnk:
@echo "build lnk..."
#ifeq ($(call FILE_DIR_EXIST,${ALIAS}-gcc,${PREFIX}/bin),)
ln -s -f ${PREFIX}/bin/${TARGET}-addr2line ${PREFIX}/bin/${ALIAS}-addr2line
ln -s -f ${PREFIX}/bin/${TARGET}-ar ${PREFIX}/bin/${ALIAS}-ar
ln -s -f ${PREFIX}/bin/${TARGET}-as ${PREFIX}/bin/${ALIAS}-as
ln -s -f ${PREFIX}/bin/${TARGET}-c++ ${PREFIX}/bin/${ALIAS}-c++
ln -s -f ${PREFIX}/bin/${TARGET}-c++filt ${PREFIX}/bin/${ALIAS}-c++filt
ln -s -f ${PREFIX}/bin/${TARGET}-cpp ${PREFIX}/bin/${ALIAS}-cpp
ln -s -f ${PREFIX}/bin/${TARGET}-elfedit ${PREFIX}/bin/${ALIAS}-elfedit
ln -s -f ${PREFIX}/bin/${TARGET}-g++ ${PREFIX}/bin/${ALIAS}-g++
ln -s -f ${PREFIX}/bin/${TARGET}-gcc ${PREFIX}/bin/${ALIAS}-gcc
ln -s -f ${PREFIX}/bin/${TARGET}-gcov ${PREFIX}/bin/${ALIAS}-gcov
ln -s -f ${PREFIX}/bin/${TARGET}-gdb ${PREFIX}/bin/${ALIAS}-gdb
ln -s -f ${PREFIX}/bin/${TARGET}-gprof ${PREFIX}/bin/${ALIAS}-gprof
ln -s -f ${PREFIX}/bin/${TARGET}-ld ${PREFIX}/bin/${ALIAS}-ld
ln -s -f ${PREFIX}/bin/${TARGET}-nm ${PREFIX}/bin/${ALIAS}-nm
ln -s -f ${PREFIX}/bin/${TARGET}-objcopy ${PREFIX}/bin/${ALIAS}-objcopy
ln -s -f ${PREFIX}/bin/${TARGET}-objdump ${PREFIX}/bin/${ALIAS}-objdump
ln -s -f ${PREFIX}/bin/${TARGET}-ranlib ${PREFIX}/bin/${ALIAS}-ranlib
ln -s -f ${PREFIX}/bin/${TARGET}-readelf ${PREFIX}/bin/${ALIAS}-readelf
ln -s -f ${PREFIX}/bin/${TARGET}-run ${PREFIX}/bin/${ALIAS}-run
ln -s -f ${PREFIX}/bin/${TARGET}-size ${PREFIX}/bin/${ALIAS}-size
ln -s -f ${PREFIX}/bin/${TARGET}-strings ${PREFIX}/bin/${ALIAS}-strings
ln -s -f ${PREFIX}/bin/${TARGET}-strip ${PREFIX}/bin/${ALIAS}-strip
#endif
@echo "build lnk end"
#######################################################
# build-pac - build tarball #
#######################################################
build-pac:
@echo "build tarball here"
@echo "save versions"
@echo ${BINUTILS_VERSION} > ${PREFIX}/versions.txt
@echo ${GCC_VERSION} >> ${PREFIX}/versions.txt
@echo ${GLIBC_VERSION} >> ${PREFIX}/versions.txt
@echo ${GDB_VERSION} >> ${PREFIX}/versions.txt
@echo ${KERNEL_VERSION} >> ${PREFIX}/versions.txt
@echo "platform: "$$(uname -msr) >> ${PREFIX}/versions.txt
tar -zcvf ${_TOP_DIR_}/target/${TARGET}-toolchain-${_GCC_VER_}-$$(uname -s)-$$(date +%Y%m%d%H%M%S).tar.gz -C ${PREFIX_PARENT} ${TARGET}-${_GCC_VER_}
@echo "build tarball end"
test-tool:
@echo "test here"
make -C ${PRJROOT}/test TEST_PREFIX=${PREFIX}/bin/${TARGET}-
@echo "test end"
clean:
@echo "clean here"
rm -rf *.out
rm -rf ${PRJROOT} ${PREFIX}
@echo "clean end"