-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
213 lines (165 loc) · 4.28 KB
/
build.sh
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
#!/bin/bash
set -u
set -e
source ./config.sh
export FULL_REBUILD=${FULL_REBUILD:-}
if [ ! -z ${FULL_REBUILD} ]; then
echo "You are about to rebuild the entire toolchain from scratch"
echo "This will remove any changes you have made to the source files"
echo "and take substantially longer than a partial rebuild"
read -p "Are you sure this is what you want? (y/n) " confirm
case $confirm in
[Nn] ) exit;;
esac
fi
if [ ! -z ${FULL_REBUILD} ]; then
# Remove and then recreate prefix directory
if [ -d ${XC_PREFIX} ]; then
rm -rf ${XC_PREFIX}
fi
mkdir ${XC_PREFIX}
fi
# Create temp directory if it does not already exist
if [ ! -d ${XC_TMP_DIR} ]; then
mkdir -p ${XC_TMP_DIR}
fi
# Download all tarballs
if [ ! -x ${FULL_REBUILD} ]; then
# Binutils
if [ ! -f ${BINUTILS_TARBALL} ]; then
wget ${BINUTILS_URL} -O ${BINUTILS_TARBALL}
fi
# Linux
if [ ! -f ${KERNEL_TARBALL} ]; then
wget ${KERNEL_URL} -O ${KERNEL_TARBALL}
fi
# Glibc
if [ ! -f ${GLIBC_TARBALL} ]; then
wget ${GLIBC_URL} -O ${GLIBC_TARBALL}
fi
# GCC
if [ ! -f ${GCC_TARBALL} ]; then
wget ${GCC_URL} -O ${GCC_TARBALL}
fi
# MPFR
if [ ! -f ${MPFR_TARBALL} ]; then
wget ${MPFR_URL} -O ${MPFR_TARBALL}
fi
# MPC
if [ ! -f ${MPC_TARBALL} ]; then
wget ${MPC_URL} -O ${MPC_TARBALL}
fi
# GMP
if [ ! -f ${GMP_TARBALL} ]; then
wget ${GMP_URL} -O ${GMP_TARBALL}
fi
# ISL
if [ ! -f ${ISL_TARBALL} ]; then
wget ${ISL_URL} -O ${ISL_TARBALL}
fi
# Cloog
if [ ! -f ${CLOOG_TARBALL} ]; then
wget ${CLOOG_URL} -O ${CLOOG_TARBALL}
fi
fi
# Extract all tarballs
if [ ! -z ${FULL_REBUILD} ]; then
# Binutils
if [ -d ${BINUTILS_SRC_DIR} ]; then
rm -rf ${BINUTILS_SRC_DIR}
fi
tar -xf ${BINUTILS_TARBALL} -C ${XC_TMP_DIR}
# Linux
if [ -d ${KERNEL_SRC_DIR} ]; then
rm -rf ${KERNEL_SRC_DIR}
fi
tar -xf ${KERNEL_TARBALL} -C ${XC_TMP_DIR}
# glibc
if [ -d ${GLIBC_SRC_DIR} ]; then
rm -rf ${GLIBC_SRC_DIR}
fi
tar -xf ${GLIBC_TARBALL} -C ${XC_TMP_DIR}
# GCC
if [ -d ${GCC_SRC_DIR} ]; then
rm -rf ${GCC_SRC_DIR}
fi
tar -xf ${GCC_TARBALL} -C ${XC_TMP_DIR}
# MPFR
if [ -d ${MPFR_SRC_DIR} ]; then
rm -rf ${MPFR_SRC_DIR}
fi
tar -xf ${MPFR_TARBALL} -C ${XC_TMP_DIR}
ln -s ${MPFR_SRC_DIR} ${GCC_SRC_DIR}/mpfr
# MPC
if [ -d ${MPC_SRC_DIR} ]; then
rm -rf ${MPC_SRC_DIR}
fi
tar -xf ${MPC_TARBALL} -C ${XC_TMP_DIR}
ln -s ${MPC_SRC_DIR} ${GCC_SRC_DIR}/mpc
# GMP
if [ -d ${GMP_SRC_DIR} ]; then
rm -rf ${GMP_SRC_DIR}
fi
tar -xf ${GMP_TARBALL} -C ${XC_TMP_DIR}
ln -s ${GMP_SRC_DIR} ${GCC_SRC_DIR}/gmp
# ISL
if [ -d ${ISL_SRC_DIR} ]; then
rm -rf ${ISL_SRC_DIR}
fi
tar -xf ${ISL_TARBALL} -C ${XC_TMP_DIR}
ln -s ${ISL_SRC_DIR} ${GCC_SRC_DIR}/isl
# Cloog
if [ -d ${CLOOG_SRC_DIR} ]; then
rm -rf ${CLOOG_SRC_DIR}
fi
tar -xf ${CLOOG_TARBALL} -C ${XC_TMP_DIR}
ln -s ${CLOOG_SRC_DIR} ${GCC_SRC_DIR}/cloog
fi
# Build binutils
# Remove and recreate the build directory
if [ -d ${BINUTILS_BUILD_DIR} ]; then
rm -rf ${BINUTILS_BUILD_DIR}
fi
mkdir ${BINUTILS_BUILD_DIR}
cd ${BINUTILS_BUILD_DIR}
${BINUTILS_SRC_DIR}/configure ${BINUTILS_CONFIGURE_OPTIONS[*]}
make
make install
# Build kernel headers (no need for separate build directory)
cd ${KERNEL_SRC_DIR}
make ${KERNEL_MAKE_OPTIONS[*]}
# Build GCC (first pass)
# Remove and recreate the build directory
if [ -d ${GCC_BUILD_DIR} ]; then
rm -rf ${GCC_BUILD_DIR}
fi
mkdir ${GCC_BUILD_DIR}
cd ${GCC_BUILD_DIR}
${GCC_SRC_DIR}/configure ${GCC_CONFIGURE_OPTIONS[*]}
make all-gcc
make install-gcc
# Build glibc (first pass)
# Remove and recreate the build directory
if [ -d ${GLIBC_BUILD_DIR} ]; then
rm -rf ${GLIBC_BUILD_DIR}
fi
mkdir ${GLIBC_BUILD_DIR}
cd ${GLIBC_BUILD_DIR}
${GLIBC_SRC_DIR}/configure ${GLIBC_CONFIGURE_OPTIONS[*]}
make install-bootstrap-headers=yes install-headers
make csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o ${XC_HEADER_DIR}/lib
${XC_TARGET}-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o ${XC_HEADER_DIR}/lib/libc.so
touch ${XC_HEADER_DIR}/include/gnu/stubs.h
# Build GCC (second pass)
cd ${GCC_BUILD_DIR}
make all-target-libgcc
make install-target-libgcc
# Build glibc (second pass)
cd ${GLIBC_BUILD_DIR}
make
make install
# Build and install GCC (third pass)
cd ${GCC_BUILD_DIR}
make all
make install