forked from nathanchance/env
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolchain
More file actions
executable file
·306 lines (230 loc) · 7.53 KB
/
toolchain
File metadata and controls
executable file
·306 lines (230 loc) · 7.53 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
306
#!/usr/bin/env bash
#
# GCC toolchain compilation script
#
# Copyright (C) 2017 Nathan Chancellor
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
################
# #
# PARAMETERS #
# #
################
# SOURCE OUR UNIVERSAL FUNCTIONS SCRIPT AND MAC CHECK
source common
# GATHER PARAMETERS
while [[ $# -ge 1 ]]; do
case "${1}" in
# ARCHITECTURE TO BUILD TOOLCHAIN FOR
"-a"|"--arch")
shift && enforce_value $@
ARCH=${1} ;;
# IS THIS A LOCAL TOOLCHAIN?
"-l"|"--local")
LOCAL=true ;;
# GCC NUMBER
"-n"|"--number")
shift && enforce_value $@
GCC_NUMBER=${1} ;;
# IS THIS A PERSONAL TOOLCHAIN?
"-p"|"--personal")
PERSONAL=true ;;
# BUILD ALL FOUR VARIANTS FOR THE PUBLIC
"-r"|"--release")
RELEASE=true ;;
# USE GNU OR LINARO SOURCE
"-s"|"--source")
shift && enforce_value $@
SOURCE=${1} ;;
# TARGET A SPECIFIC CPU (A73 or A57.A53)
"-t"|"--target")
shift && enforce_value $@
TARGET=-${1} ;;
*)
report_error "Invalid parameter specified!" ;;
esac
shift
done
###############
# #
# VARIABLES #
# #
###############
BUILD_FOLDER=${TC_FOLDER}/build
SOURCE_FOLDER=${BUILD_FOLDER}/source
PREBUILT_FOLDER=${TC_FOLDER}/prebuilts
###############
# #
# FUNCTIONS #
# #
###############
function set_variables() {
[[ -z ${GCC_NUMBER} ]] && GCC_NUMBER=7
[[ -n ${TARGET} ]] && PERSONAL=true && ARCH=arm64
[[ -n ${PERSONAL} && -z ${SOURCE} ]] && SOURCE=linaro
case ${SOURCE} in
"gnu")
export GCC_BRANCH=gcc-${GCC_NUMBER}-branch
export POS=3
export PERSONAL_PFX=g ;;
"linaro")
export GCC_BRANCH=linaro-local/gcc-${GCC_NUMBER}-integration-branch
export POS=5
export PERSONAL_PFX=l ;;
*)
report_error "Invalid GCC type!"
esac
case ${ARCH} in
"arm")
TUPLE_PFX=arm
TUPLE_SFX=androideabi ;;
"arm64")
TUPLE_PFX=aarch64
TUPLE_SFX=android ;;
*)
report_error "Invalid architecture!"
esac
export TUPLE=${TUPLE_PFX}-${SOURCE}-linux-${TUPLE_SFX}
if [[ -z ${PERSONAL} ]]; then
export PREFIX_FOLDER=${BUILD_FOLDER}/out/${TUPLE}
export PREBUILT_BRANCH=${TUPLE_PFX}-${SOURCE}-${GCC_NUMBER}.x
else
export PERSONAL_FOLDER=${PERSONAL_PFX}-${GCC_NUMBER}.x${TARGET}
export PREFIX_FOLDER=/opt/${PERSONAL_FOLDER}
export PREBUILT_BRANCH=tarballs-personal
[[ -n ${TARGET} ]] && TARGET_SUMMARY="This toolchain targets a specific CPU, notated in the file name. Beware if this is not your CPU!"
fi
}
function clone_repo() {
[[ ! -d ${SOURCE_FOLDER} ]] && mkdir -p ${SOURCE_FOLDER}
cd ${SOURCE_FOLDER}
case "${1}" in
"binutils")
git clone -b ${2} http://sourceware.org/git/binutils-gdb.git ${1} ;;
"gcc")
git clone -b ${2} https://git.linaro.org/toolchain/gcc.git ${1} ;;
"linux")
git clone -b ${2} https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ${1} ;;
esac
}
function update_repo() {
[[ -d ${SOURCE_FOLDER}/${1} ]] && cd ${SOURCE_FOLDER}/${1} \
|| clone_repo ${1} ${2}
git checkout ${2}
git fetch origin
git rebase origin/${2}
[[ $? -ne 0 ]] && report_error "There was a problem updating ${1}!"
}
function build() {
[[ ! -d ${PREBUILT_FOLDER} ]] && cd ${TOOLCHAIN_FOLDER} \
&& git clone git@github.com:nathanchance/gcc-prebuilts prebuilts
cd ${BUILD_FOLDER}
git -C ${PREBUILT_FOLDER} checkout ${PREBUILT_BRANCH}
ct-ng clean
if [[ -n ${PERSONAL} ]]; then
if [[ ! -d ${PREFIX_FOLDER} ]]; then
cd ${TOOLCHAIN_FOLDER}
tar xf ${PERSONAL_FOLDER}*.tar.xx
cd ${BUILD_FOLDER}
fi
CONFIG_FILE=${PREFIX_FOLDER}/bin/${TUPLE}-ct-ng.config
else
CONFIG_FILE=${PREBUILT_FOLDER}/bin/${TUPLE}-ct-ng.config
fi
if [[ ! -f ${CONFIG_FILE} ]]; then
ct-ng nconfig
else
${CONFIG_FILE} > .config
ct-ng savedefconfig
mv defconfig .config
echo "\a"
ct-ng nconfig
fi
ct-ng build.${THREADS}
[[ ! -f ${PREFIX_FOLDER}/bin/${TUPLE}-gcc ]] && report_error "Problem with compilation!"
}
function commit() {
cd ${PREBUILT_FOLDER}
UTC_DATE=$(TZ=UTC date +%Y%m%d)
if [[ -z ${PERSONAL} ]]; then
rm -rf *
cp -r ${PREFIX_FOLDER}/* .
else
rm -rf ${PERSONAL_FOLDER}*
cp -r ${PREFIX_FOLDER} .
XZ_OPT=-9 tar -Jcf ${PERSONAL_FOLDER}-${UTC_DATE}.tar.xz ${PERSONAL_FOLDER}
rm -rf ${PERSONAL_FOLDER}
fi
git add .
GCC_VERSION=$(${PREFIX_FOLDER}/bin/${TUPLE}-gcc --version | ag gcc | cut -d ' ' -f ${POS})
git commit --signoff -m "${TUPLE} ${GCC_VERSION}: ${UTC_DATE}
Compiled on $(source /etc/os-release; echo ${PRETTY_NAME}) $(uname -m)
Kernel version: $(uname -rv)
Host GCC version: $(gcc --version | awk '/gcc/ {print $3}')
Make version: $(make --version | awk '/Make/ {print $3}')
$([[ -n ${TARGET_SUMMARY} ]] && echo && echo -e "${TARGET_SUMMARY}" && echo)
Compiled with crosstool-NG: http://crosstool-ng.github.io/
GCC source: https://git.linaro.org/toolchain/gcc.git/log/?h=${GCC_BRANCH}"
git push
}
function tarballs() {
OUT_FOLDER=$(dirname ${PREFIX_FOLDER})
cd ${OUT_FOLDER}
rm -rf *.tar.xz
for FOLDER in $(ls); do
XZ_OPT=-9 tar -Jcf ${FOLDER}.tar.xz ${FOLDER}
done
cd ${PREBUILT_FOLDER}
git checkout tarballs-7.x
rm -rf *
mv -v ${OUT_FOLDER}/*.tar.xz .
git add .
git commit --signoff -m "Tarballs: $(TZ=UTC date +%Y%m%d)
Compiled on $(source /etc/os-release; echo ${PRETTY_NAME}) $(uname -m)
Kernel version: $(uname -rv)
Host GCC version: $(gcc --version | awk '/gcc/ {print $3}')
Make version: $(make --version | awk '/Make/ {print $3}')
Compiled with crosstool-NG: http://crosstool-ng.github.io/
GCC source: https://git.linaro.org/toolchain/gcc.git/log/?h=gcc-7-branch
https://git.linaro.org/toolchain/gcc.git/log/?h=linaro-local/gcc-7-integration-branch"
git push
exit
}
function release() {
update_repo binutils binutils-2_29-branch
update_repo linux master
for SOURCE in gnu linaro; do
for ARCH in arm arm64; do
export SOURCE ARCH
set_variables
update_repo gcc ${GCC_BRANCH}
build
commit
done
done
tarballs
return 0
}
################
# #
# SCRIPT START #
# #
################
[[ -n ${RELEASE} ]] && release && exit
set_variables
update_repo binutils binutils-2_29-branch
update_repo linux master
update_repo gcc ${GCC_BRANCH}
build
[[ -z ${LOCAL} ]] && commit