This repository was archived by the owner on Jul 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild
More file actions
executable file
·305 lines (245 loc) · 5.83 KB
/
build
File metadata and controls
executable file
·305 lines (245 loc) · 5.83 KB
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
#!/bin/sh
#
# The Main Script for Building GNU Toolchain
#
# Conke Hu <conke.hu@gmail.com>
# Rouchel Yan <rouchel.yan@maxwit.com>
#
# http://www.maxwit.com
#
MWT_TOP=`dirname $0`
cd ${MWT_TOP}
MWT_TOP=${PWD}
[ -e .config ] || \
{
echo ".config does NOT exist! using default configuration:"
cp defconfig .config || exit 1
cat .config
echo
}
# fixme
sed -i 's/ //g' .config
. ./.config || exit 1
if [ -z "${CONFIG_BINUTILS}" -o \
-z "${CONFIG_GCC}" -o \
-z "${CONFIG_LIBC}" -o \
-z "${CONFIG_LINUX}" -o \
-z "${CONFIG_CPU}" ]; then
echo "missing configuration, pls check the .config file!"
exit 1
fi
case "${CONFIG_CPU}" in
armv4t)
TARGET_ARCH="arm"
TARGET_PLAT="arm-maxwit-linux-gnueabi"
BU_CPU_OPT="--with-float=soft"
GCC_CPU_OPT="--with-float=soft --with-arch=armv4t"
;;
armv6zk)
TARGET_ARCH="arm"
TARGET_PLAT="arm-maxwit-linux-gnueabi"
GCC_CPU_OPT="--with-arch=armv6zk"
;;
armv5te)
TARGET_ARCH="arm"
TARGET_PLAT="arm-maxwit-linux-gnueabi"
BU_CPU_OPT="--with-float=soft"
GCC_CPU_OPT="--with-float=soft --with-arch=armv5te"
;;
# fixme
xscale)
TARGET_ARCH="arm"
TARGET_PLAT="arm-maxwit-linux-gnueabi"
BU_CPU_OPT="--with-float=soft"
GCC_CPU_OPT="--with-float=soft --with-arch=armv5te"
;;
armv7-a)
TARGET_ARCH="arm"
TARGET_PLAT="arm-maxwit-linux-gnueabi"
BU_CPU_OPT="--with-float=hard"
GCC_CPU_OPT="--with-fpu=vfp --with-float=hard --with-arch=armv7-a"
;;
# fixme
mips32)
TARGET_ARCH="mips"
QEMU_ARCH="mipsel"
TARGET_PLAT="mipsel-maxwit-linux-gnu"
GCC_CPU_OPT="--with-abi=32 --with-tune=mips32r2"
;;
loongson2f)
TARGET_ARCH="mips"
QEMU_ARCH="mips64el"
TARGET_PLAT="mips64el-maxwit-linux-gnu"
GCC_CPU_OPT="--with-abi=64 --with-tune=loongson2f"
BU_CPU_OPT="--enable-64-bit-bfd"
;;
*)
echo "No Target CPU Specified!"
exit 1
;;
esac
# fixme: be configurable
MAXWIT_TOP=/maxwit
SRC_PATH=${MAXWIT_TOP}/source
BUILD_PATH=${MAXWIT_TOP}/build/toolchain
TARGET_TOP=/maxwit/toolchain/${CONFIG_CPU}
ROOTFS_PATH=${MAXWIT_TOP}/image/rootfs
#TOOLCHAIN_PATH=${TARGET_TOP}/toolchain
#ROOTFS_PATH=${TARGET_TOP}
TOOLCHAIN_PATH=${TARGET_TOP}
BUILD_PLAT=`gcc -dumpmachine`
for path in ${TOOLCHAIN_PATH} ${ROOTFS_PATH} ${SRC_PATH} ${BUILD_PATH}
do
mkdir -vp ${path} || \
{
echo "Fail to create directory \"${path}\"!"
exit 1
}
done
export ROOTFS_PATH TOOLCHAIN_PATH BU_CPU_OPT GCC_CPU_OPT
# fixme
[ -z "${QEMU_ARCH}" ] && QEMU_ARCH=${TARGET_ARCH}
# $1 = package name
# $2 = /directory/of/the/url/file/
download()
{
local pkg=${1}
local dir=${2}
for ext in tar.xz tar.bz2 tar.gz tgz
do
if [ -f ${SRC_PATH}/${pkg}.${ext} ]; then
return 0
fi
done
if [ -x ${dir}/fetch.sh ]; then
${dir}/fetch.sh ${pkg} ${SRC_PATH} || exit 1
elif [ -e ${dir}/url ]; then
url=`grep "^\s*url\s*=" ${dir}/url | sed 's/^\s*url\s*=\s*//'`
ext=`grep "^\s*ext\s*=" ${dir}/url | sed 's/^\s*ext\s*=\s*//'`
wget ${url}/${pkg}.${ext} -P ${SRC_PATH} || exit 1
else
echo "\"${pkg} cannot be downloaded!"
exit 1
fi
return 0
}
# $1: package name
extract()
{
local opkg="${1}"
local upkg="${opkg}"
local pkg_ver=${opkg##*-}
cd ${BUILD_PATH}
case ${opkg} in
binutils-* | gcc-* | glibc-* | eglibc-*)
upkg=${opkg}-build${2}
# rm -rf ${upkg}
mkdir -p ${upkg}
;;
esac
# fixme
if [ -e ${opkg}/.__maxwit_extract ]; then
echo "package \"${opkg}\" exists, skipped"
cd ${upkg}
return 0
fi
echo -n "Extracting \"${opkg}\" "
if [ -z "${opkg}" ]; then
echo "target dir NOT specified!"
exit 1
fi
echo -n "."
pkg_exist=0
for ext in tar.xz tar.bz2 tar.gz tgz
do
if [ -f ${SRC_PATH}/${opkg}.${ext} ]; then
pkg_exist=1
break
fi
done
if [ pkg_exist = 0 ]; then
echo "\"${SRC_PATH}/${opkg}\" does NOT exist!"
exit 1
fi
tar xf ${SRC_PATH}/${opkg}.${ext} || exit 1
echo -n "."
case "${opkg}" in
glibc-* | eglibc-*)
glibc_ports=`echo $CONFIG_LIBC | sed 's/glibc-/glibc-ports-/'`
rm -rf ${glibc_ports}
tar xf ${SRC_PATH}/${glibc_ports}.tar.* || exit 1
mv ${glibc_ports} ${CONFIG_LIBC}/ports
;;
esac
echo " OK."
cd ${opkg} || exit 1
# make sure ``patch'' is installed
# before applying all available patches
for fpatch in `ls ${MWT_TOP}/${opkg%-*}/${pkg_ver}/*.patch 2>/dev/null`
do
patch -p1 < ${fpatch} || exit 1
done
touch .__maxwit_extract
if [ "${opkg}" != "${upkg}" ]; then
cd ../${upkg}
fi
}
# $1 = package
# $2 for gcc only
build_package()
{
local pkg=${1}
local pkg_dir=${pkg%%-[\.0-9]*}
local version=${pkg##${pkg_dir}-}
local build="build${2}.sh"
pkg_dir="${MWT_TOP}/${pkg_dir}"
if [ -f "${BUILD_PATH}/${pkg}/.__maxwit_built${2}" ]; then
echo "\"${1}\" has been built."
echo
return 0
fi
download ${pkg} ${pkg_dir}
echo
extract ${pkg} $2
echo
echo "Building \"${pkg}\" ..."
# fixme
if test -x ${pkg_dir}/${version}/${build}; then
build=${pkg_dir}/${version}/${build}
elif test -x ${pkg_dir}/${build}; then
build=${pkg_dir}/${build}
else
echo "No ${build} found in ${pkg_dir}!"
exit 1
fi
${build} ${pkg} ${BUILD_PLAT} ${TARGET_PLAT} || exit 1
touch ${BUILD_PATH}/${pkg}/.__maxwit_built${2}
echo
return 0
}
# export PATH
grep "${TOOLCHAIN_PATH}" ~/.bashrc > /dev/null \
|| echo "export PATH=\${PATH}:${TOOLCHAIN_PATH}/usr/bin" >> ~/.bashrc
echo ${PATH} | grep "${TOOLCHAIN_PATH}" > /dev/null \
|| export PATH=${PATH}:${TOOLCHAIN_PATH}/usr/bin
build_package ${CONFIG_LINUX}
build_package ${CONFIG_BINUTILS}
build_package ${CONFIG_GCC} 1
build_package ${CONFIG_LIBC}
build_package ${CONFIG_GCC} 2
# create symbolic links
[ -L ${TOOLCHAIN_PATH}/usr/bin/${TARGET_ARCH}-linux-gcc ] || \
{
cd ${TOOLCHAIN_PATH}/usr/bin
for file in `ls ${TARGET_PLAT}-*`
do
ln -vs ${file} ${TARGET_ARCH}-linux${file##${TARGET_PLAT}}
done
#ln -vs ${TARGET_PLAT}-gcc ${TARGET_PLAT}-cc
}
# backup
echo -n "Archive GNU Toolchain ..." # rootfs
cd ${TOOLCHAIN_PATH}/../
TC_BIN=`basename ${TOOLCHAIN_PATH}`
tar cJvf toolchain-${CONFIG_CPU}.tar.xz ${TC_BIN}
echo