forked from c4ev3/C4EV3.Toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixup_ptxconfigs.sh
executable file
·476 lines (416 loc) · 12.9 KB
/
fixup_ptxconfigs.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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/bin/bash
ARGS_FULL=("${@}")
get_replace()
{
local var="${1}"
if [ "${!var}" = "y" ]; then
echo "-e \"s~\# \(${var}\) is not set.*~\1=${!var}~\""
#FIXME turn it off again
else
echo "-e \"s~\(${var}\)=.*~\1=\\\"${!var}\\\"~\""
fi
}
fixup()
{
local config="${1}"
# version
PTXCONF_CONFIGFILE_VERSION="2018.12.0"
PTXCONF_PROJECT="OSELAS.Toolchain-2018.12.0"
PTXCONF_PROJECT="${PTXCONF_PROJECT##*/}"
# defaults
PTXCONF_PREFIX="/opt"
PTXCONF_GLIBC_CONFIG_EXTRA=""
PTXCONF_GLIBC_TIMESTAMP=""
PTXCONF_CROSS_GCC_LANG_JAVA=n
PTXCONF_KERNEL_HEADERS_SANITIZED=n
# FIXME: nptl vs. linuxthreads
touple="${config##*/}"
touple="${touple%.ptxconfig}"
local ifs_old="${IFS}"
IFS="_"
set -- ${touple}
IFS="${ifs_orig}"
while [ ${#} -ne 0 ]; do
part="${1}"
shift
case "${part}" in
gcc*)
PTXCONF_CROSS_GCC_VERSION="${part##gcc-}"
;;
glibc*)
PTXCONF_GLIBC_VERSION="${part##glibc-}"
;;
uclibc*)
PTXCONF_UCLIBC_VERSION="${part##uclibc-}"
;;
libc*)
PTXCONF_AVRLIB_VERSION="${part##libc-}"
;;
newlib*)
PTXCONF_NEWLIB_VERSION="${part##newlib-}"
;;
binutils*)
PTXCONF_CROSS_BINUTILS_VERSION="${part##binutils-}"
;;
kernel*)
PTXCONF_KERNEL_HEADERS_VERSION="${part##kernel-}"
PTXCONF_KERNEL_HEADERS_VERSION="${PTXCONF_KERNEL_HEADERS_VERSION%-sanitized}"
case "${part}" in
*-sanitized)
PTXCONF_KERNEL_HEADERS_SANITIZED=y
;;
esac
;;
linux*)
echo "please use kernel instead of linux"
exit 1
;;
java)
PTXCONF_CROSS_GCC_LANG_JAVA=y
;;
*)
PTXCONF_GNU_TARGET="${PTXCONF_GNU_TARGET}${PTXCONF_GNU_TARGET:+_}${part}"
;;
esac
done
#
# PTXCONF_GLIBC_HEADERS_FAKE_CROSS
# - ARM eabi hack
# - mips hack
#
case "${PTXCONF_GNU_TARGET}" in
arm*gnueabi)
PTXCONF_GLIBC_HEADERS_FAKE_CROSS="-D__ARM_EABI__"
;;
mips*)
PTXCONF_GLIBC_HEADERS_FAKE_CROSS="-DBOOTSTRAP_GCC -D_MIPS_SIM=_ABIO32"
;;
riscv64*)
PTXCONF_GLIBC_HEADERS_FAKE_CROSS="-D__riscv_atomic -D__riscv_xlen=64 -D__riscv_flen=64 -D__riscv_float_abi_double"
;;
*)
;;
esac
case "${PTXCONF_GNU_TARGET}" in
arm*)
PTXCONF_ARCH_ARM=y
;;
aarch64*)
PTXCONF_ARCH_ARM64=y
;;
i?86*)
PTXCONF_ARCH_I386=y
;;
mips*)
PTXCONF_ARCH_MIPS=y
;;
powerpc*)
PTXCONF_ARCH_POWERPC=y
;;
avr)
PTXCONF_ARCH_AVR=y
;;
x86_64*)
PTXCONF_ARCH_X86_64=y
;;
riscv64*)
PTXCONF_ARCH_RISCV64=y
;;
*)
echo "unsupported GNU_TARGET: ${PTXCONF_GNU_TARGET}"
exit 1
;;
esac
#
# PTXCONF_CROSS_GCC_CONFIG_EXTRA
# PTXCONF_GLIBC_CONFIG_EXTRA
#
case "${PTXCONF_GNU_TARGET}" in
# softfp, vfp
arm-1136jfs-linux-gnueabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=softfp --with-fpu=vfp --with-cpu=arm1136jf-s"
;;
# hard, vfp
arm-1136jfs-linux-gnueabihf)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=hard --with-fpu=vfp --with-cpu=arm1136jf-s"
;;
# softfp, neon
arm-v7a-linux-gnueabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=softfp --with-fpu=vfpv3-d16 --with-arch=armv7-a --with-mode=thumb --with-tune=cortex-a9"
;;
# hard, neon
arm-v7a-linux-gnueabihf)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=hard --with-fpu=vfpv3-d16 --with-arch=armv7-a --with-mode=thumb --with-tune=cortex-a9"
;;
# softfp, neon
arm-cortexa8-linux-gnueabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=softfp --with-fpu=neon --with-cpu=cortex-a8 --with-mode=thumb"
PTXCONF_GLIBC_CONFIG_EXTRA="--disable-multi-arch"
;;
# hard, neon
arm-cortexa8-linux-gnueabihf)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=hard --with-fpu=neon --with-cpu=cortex-a8 --with-mode=thumb"
PTXCONF_GLIBC_CONFIG_EXTRA="--disable-multi-arch"
;;
# soft, vfp
arm-v4t-linux-gnueabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=soft --with-fpu=vfp --with-arch=armv4t"
;;
arm-v5te-linux-gnueabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=soft --with-fpu=vfp --with-cpu=arm926ej-s"
;;
arm-v7m-uclinuxeabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=soft --with-fpu=vfp --with-arch=armv7-m --with-mode=thumb"
;;
arm-v7m-eabi)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=soft --with-fpu=vfp --with-arch=armv7-m --with-mode=thumb"
;;
# hard, vfp
arm-v7em-*eabihf)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=hard --with-fpu=fpv4-sp-d16 --with-arch=armv7e-m --with-mode=thumb"
;;
aarch64-v8a-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-abi=lp64 --with-arch=armv8-a"
;;
i486-unknown-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-arch=i486"
;;
i586-unknown-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-arch=i586"
;;
i686-unknown-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-arch=i686"
;;
i686-atom-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-arch=atom --with-fpmath=sse --with-specs='%{!mmovbe:%{!mno-movbe:-mno-movbe}}'"
;;
x86_64-unknown-linux-gnu)
;;
mipsel-softfloat-linux-gnu|mips-softfloat-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-float=soft"
PTXCONF_GLIBC_CONFIG_EXTRA="libc_mips_float=soft"
;;
powerpc-603e-linux-gnu)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="--with-cpu=603e --disable-altivec"
;;
avr)
#FIXME
;;
arm-elf)
#FIXME
;;
riscv64-linux-gnu)
#FIXME
;;
*)
echo "unknown GNU_TARGET: ${PTXCONF_GNU_TARGET}"
exit 1
;;
esac
case "${PTXCONF_GNU_TARGET}" in
*linux-gnu*)
PTXCONF_CROSS_GCC_CONFIG_EXTRA="$PTXCONF_CROSS_GCC_CONFIG_EXTRA --enable-linker-build-id"
;;
esac
#
# PTXCONF_GLIBC_CONFIG_EXTRA_CROSS
#
PTXCONF_GLIBC_CONFIG_EXTRA_CROSS="--enable-obsolete-rpc --enable-obsolete-nsl --enable-stackguard-randomization --enable-stack-protector=strong"
case "${PTXCONF_GNU_TARGET}" in
x86_64-unknown-linux-gnu)
PTXCONF_GLIBC_CONFIG_EXTRA_CROSS="${PTXCONF_GLIBC_CONFIG_EXTRA_CROSS} --enable-mathvec"
;;
esac
#
# PTXCONF_GLIBC_ENABLE_KERNEL
#
case "${PTXCONF_KERNEL_HEADERS_VERSION}" in
2.6.18)
PTXCONF_GLIBC_ENABLE_KERNEL="2.6.16"
;;
2.6.2[6789])
PTXCONF_GLIBC_ENABLE_KERNEL="2.6.23"
;;
2.6.3[56789])
PTXCONF_GLIBC_ENABLE_KERNEL="2.6.23"
;;
3.[123456789])
PTXCONF_GLIBC_ENABLE_KERNEL="2.6.32"
;;
3.1[0123456789])
PTXCONF_GLIBC_ENABLE_KERNEL="3.0"
;;
4.[0123456789]*)
PTXCONF_GLIBC_ENABLE_KERNEL="3.10"
;;
"")
;;
*)
echo "unknown KERNEL_HEADERS_VERSION: ${PTXCONF_KERNEL_HEADERS_VERSION}"
exit 1
esac
#
# PTXCONF_CROSS_GDB_VERSION
#
PTXCONF_CROSS_GDB_VERSION="8.2"
case "${PTXCONF_CROSS_GCC_VERSION}" in
3.*|4.[012].*)
PTXCONF_CROSS_GCC_43=n
;;
4.[34].*)
PTXCONF_CROSS_GCC_43=y
;;
linaro-4.[34][-.]*)
PTXCONF_CROSS_GCC_43=y
;;
4.[567].*)
PTXCONF_CROSS_GCC_45=y
;;
linaro-4.[567][-.]*)
PTXCONF_CROSS_GCC_45=y
;;
4.[89].*)
PTXCONF_CROSS_GCC_48=y
;;
linaro-4.[89][-.]*)
PTXCONF_CROSS_GCC_48=y
;;
5.*|7.*|8.*)
PTXCONF_CROSS_GCC_50=y
;;
*)
echo "unknown CROSS_GCC_VERSION: ${PTXCONF_CROSS_GCC_VERSION}"
exit 1
esac
case "${PTXCONF_GLIBC_VERSION}" in
2.22)
PTXCONF_GLIBC_LICENSE="GPL-2.0+ AND LGPL-2.1+"
PTXCONF_GLIBC_LICENSE_FILES="file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 file://COPYING.LIB;md5=4fbd65380cdd255951079008b364516c file://LICENSES;md5=e9a558e243b36d3209f380deb394b213"
;;
2.28)
PTXCONF_GLIBC_LICENSE="GPL-2.0-or-later AND LGPL-2.1-or-later"
PTXCONF_GLIBC_LICENSE_FILES="file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 file://COPYING.LIB;md5=4fbd65380cdd255951079008b364516c file://LICENSES;md5=cfc0ed77a9f62fa62eded042ebe31d72"
;;
esac
case "${PTXCONF_UCLIBC_VERSION}" in
0.9.33.2)
PTXCONF_UCLIBC_LICENSE="LGPL-2.1+"
PTXCONF_UCLIBC_LICENSE_FILES="file://COPYING.LIB;md5=a6f89e2100d9b6cdffcea4f398e37343"
;;
ng-1.0.31)
PTXCONF_UCLIBC_LICENSE="LGPL-2.1-or-later"
PTXCONF_UCLIBC_LICENSE_FILES="file://COPYING.LIB;md5=a6f89e2100d9b6cdffcea4f398e37343"
;;
esac
case "${PTXCONF_CROSS_GCC_VERSION}" in
5.2.0)
PTXCONF_CROSS_GCC_LICENSE="GPL-2.0+ WITH Classpath-exception-2.0 AND LGPL-2.1+ AND GPL-3.0+ AND GPL-3.0+ WITH GCC-exception-3.1 AND LGPL-3.0+"
PTXCONF_CROSS_GCC_LICENSE_FILES="file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552 file://COPYING.LIB;md5=2d5025d4aa3495befef8f17206a5b0a1 file://COPYING.RUNTIME;md5=fe60d87048567d4fe8c8a0ed2448bcc8 file://COPYING3;md5=d32239bcb673463ab874e80d47fae504 file://COPYING3.LIB;md5=6a6a8e020838b23406c81b19c1d46df6"
PTXCONF_CROSS_GCC_GCCLIBS_LICENSE="GPL-3.0 WITH GCC-exception-3.1"
PTXCONF_CROSS_GCC_GCCLIBS_LICENSES="COPYING3 COPYING.RUNTIME"
;;
8.2.1)
PTXCONF_CROSS_GCC_LICENSE="GPL-2.0-or-later WITH Classpath-exception-2.0 AND LGPL-2.1-or-later AND GPL-3.0-or-later AND GPL-3.0-or-later WITH GCC-exception-3.1 AND LGPL-3.0-or-later"
PTXCONF_CROSS_GCC_LICENSE_FILES="file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552 file://COPYING.LIB;md5=2d5025d4aa3495befef8f17206a5b0a1 file://COPYING.RUNTIME;md5=fe60d87048567d4fe8c8a0ed2448bcc8 file://COPYING3;md5=d32239bcb673463ab874e80d47fae504 file://COPYING3.LIB;md5=6a6a8e020838b23406c81b19c1d46df6"
PTXCONF_CROSS_GCC_GCCLIBS_LICENSE="GPL-3.0-only WITH GCC-exception-3.1"
PTXCONF_CROSS_GCC_GCCLIBS_LICENSES="COPYING3 COPYING.RUNTIME"
;;
esac
case "${PTXCONF_CROSS_BINUTILS_VERSION}" in
2.25.1)
PTXCONF_CROSS_BINUTILS_LICENSE="GPL-2.0+ AND LGPL-2.0+ GPL-3.0+ AND LGPL-3.0+"
PTXCONF_CROSS_BINUTILS_LICENSE_FILES="file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552 file://COPYING.LIB;md5=9f604d8a4f8e74f4f5140845a21b6674 file://COPYING3;md5=d32239bcb673463ab874e80d47fae504 file://COPYING3.LIB;md5=6a6a8e020838b23406c81b19c1d46df6"
;;
2.31.1)
PTXCONF_CROSS_BINUTILS_LICENSE="GPL-2.0-or-later AND LGPL-2.0-or-later GPL-3.0-or-later AND LGPL-3.0-or-later"
PTXCONF_CROSS_BINUTILS_LICENSE_FILES="file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552 file://COPYING.LIB;md5=9f604d8a4f8e74f4f5140845a21b6674 file://COPYING3;md5=d32239bcb673463ab874e80d47fae504 file://COPYING3.LIB;md5=6a6a8e020838b23406c81b19c1d46df6"
;;
esac
case "${PTXCONF_CROSS_GDB_VERSION}" in
7.10)
PTXCONF_CROSS_GDB_LICENSE="GPL-2.0+ AND LGPL-2.0+ GPL-3.0+ AND LGPL-3.0+"
PTXCONF_CROSS_GDB_LICENSE_FILES="file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552 file://COPYING.LIB;md5=9f604d8a4f8e74f4f5140845a21b6674 file://COPYING3;md5=d32239bcb673463ab874e80d47fae504 file://COPYING3.LIB;md5=6a6a8e020838b23406c81b19c1d46df6"
;;
8.2)
PTXCONF_CROSS_GDB_LICENSE="GPL-2.0-or-later AND LGPL-2.0-or-later GPL-3.0-or-later AND LGPL-3.0-or-later"
PTXCONF_CROSS_GDB_LICENSE_FILES="file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552 file://COPYING.LIB;md5=9f604d8a4f8e74f4f5140845a21b6674 file://COPYING3;md5=d32239bcb673463ab874e80d47fae504 file://COPYING3.LIB;md5=6a6a8e020838b23406c81b19c1d46df6"
;;
esac
clear
# add any new variables so they can be replaced
./p --force --ptxconfig="${config}" oldconfig < /dev/null || exit 1
local sed_magic=""
for var in ${!PTXCONF_@}; do
# remove tabs :)
eval "${var}"=\"$(echo "${!var}" | sed -e "s/[\t]\+/ /g")\"
echo "${var}"="${!var}"
sed_magic="${sed_magic} $(get_replace "${var}")"
if [ "${var}" != "PTXCONF_CONFIGFILE_VERSION" ]; then
unset "${var}"
fi
done
eval sed -i "${sed_magic}" "${config}"
echo
echo
echo
# change the configfile to force update
sed -i 's/PTXCONF__ptxconfig_MAGIC__=y//' "${config}"
./p --force --ptxconfig="${config}" oldconfig || exit 1
# fix PTXdist version
eval sed -i "$(get_replace PTXCONF_CONFIGFILE_VERSION)" \
-e "\"s~^\(\# PTXdist \).*~\1${PTXCONF_CONFIGFILE_VERSION}~\"" \
"${config}"
}
update()
{
local config="${1}"
local cmd="${2}"
local ifs_old="${IFS}"
IFS=":"
set -- ${cmd}
IFS="${ifs_orig}"
if [ -z "${1}" -o -z "${2}" -o -z "${3}" ]; then
echo "use --update <component>:<from>:<to>"
exit 1
fi
local component="${1}"
local from="${2}"
local to="${3}"
local config_new="${config/${component}-${from}/${component}-${to}}"
if [ "${config}" != "${config_new}" ]; then
git mv "${config}" "${config_new}" || return $?
fixup "${config_new}"
fi
}
#
# main()
#
action=fixup
action_args=""
set -- "${ARGS_FULL[@]}"
while [ ${#} -ne 0 ]; do
arg="${1}"
shift
case "${arg}" in
--update)
action=update
action_args="${1}"
shift
;;
*)
ARGS_SECOND[${#ARGS_SECOND[@]}]="${arg}"
;;
esac
done
set -- "${ARGS_SECOND[@]}"
if test -n "${1}"; then
if [ \! -e "${1}" ]; then
echo "error: '${1}' does not exist"
exit 1
fi
${action} ${1} "${action_args[@]}"
else
for config in `find ptxconfigs -name "*.ptxconfig"`; do
${action} ${config} "${action_args[@]}"
done
fi