-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxsetup
executable file
·693 lines (601 loc) · 26.8 KB
/
xsetup
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
#!/bin/bash
# ................................................
# setup util 1.0 2021-diasgc
# ................................................
clear
# Target Triple
# <arch><sub-arch>-<vendor>-<os>-<environ>
# <arch> aarch64, arm, i686, x86_64
# <sub-arch> v7a,v7m
# <vendor> apple, pc, ibm, unknown
# <os> darwin, linux, openbsd
# <environ> android, elf, gnu, gnueabihf
#
#
: "${dir_root:=$(dirname $0)}"
: "${verbose}:=false}"
# cat $ANDROID_NDK_HOME/build/cmake/platforms.cmake | grep -oP 'NDK_MAX_PLATFORM_LEVEL "[0-9]+"'
# NDK_MAX_API=$(grep 'NDK_MAX_PLATFORM_LEVEL' $ANDROID_NDK_HOME/build/cmake/platforms.cmake | grep -oP '[0-9]+')
: "${NDK_API_DEFAULT:=34}"
#export LLVM_MINGW_JSON=$(curl -sL "https://api.github.com/repos/mstorsjo/llvm-mingw/releases/latest")
#llvm_mingw_targz=$(curl -sL "https://api.github.com/repos/mstorsjo/llvm-mingw/releases/latest" | jq -r -M '.assets[] | .browser_download_url' | grep '.*ucrt.*ubuntu.*'$(uname -p))
check_install(){
local v0
local v1
for p in $@; do
v0=$(dpkg-query -W $p 2>/dev/null | cut -f 2)
v1=$(dpkg-query --showformat='${Version}' --show ${p})
if [ -z "${v0}" ];then
printf "${CH}%-20s: ${C0}%s\n" " $p" "installing..."
printf "$(${cmd_install} $p -y 2>/dev/null | grep $p | sed "s/^$p//" | head -n1)\n"
elif [ "${v1}" == "${v0}" ]; then
printf "${CH}%-20s: ${C0}%s\n" " $p" "${v0}"
else
printf "${CH}%-20s: ${C0}%s" " $p" "${v0} upgrading to..."
printf "$(${cmd_install} $p -y 2>/dev/null | grep $p | sed "s/^$p//" | head -n1)\n"
fi
done
}
update(){
while [ -n "${1}" ]; do
case "${1}" in
ndk|NDK) install_ndk;;
llvm-mingw) install_llvm_mingw;;
llvm-gnu) install_llvm_gnu;;
esac
shift
done
}
function cmake_latest {
logsc 'Cleaning old cmake...' sudo apt purge --auto-remove cmake -y
logsc 'Checking for updates...' sudo apt update
logsc 'Installing tools...' sudo apt install -y software-properties-common lsb-release
logsc 'Cleaning...' sudo apt clean all
logsc 'Add gpg kitware...' wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
logsc 'Add kitware repository' sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ focal main"
logsc 'Updating...' sudo apt update
logsc 'Installing keyring...' sudo apt install kitware-archive-keyring
logsc 'Remove gpg kitware...'sudo rm /etc/apt/trusted.gpg.d/kitware.gpg
logsc 'Updating...' sudo apt update
logsc 'Installing latest cmake...' sudo apt install cmake
}
function libcheck {
local v
local g
for fscript in *.sh; do
case $fscript in _*|*build*|*setup*|*unpack*) continue;; esac
v="$(./${fscript} --get var dev_vrs)"
printf "${C0}%-20s:${CC0}%-10s" ${fscript} ${v}
#if [ -n "${v}" ]; then
g="$(./${fscript} --get vrs_remote 2>/dev/null)"
printf "${CY0}%-10s\n" ${g}
#fi
#printf "\n"
done
}
function select_ndk {
echo -e "${CH}Android NDK Support:${C0}"
PS3="Please select NDK version: "
links=($(get_ndk_links))
options=("None" $(echo "${links[@]}" | sed 's/https:\/\/dl\.google\.com\/android\/repository\/android-ndk-//g;s/-linux.zip//g'))
select opt in "${options[@]}"
do
idx=$(($REPLY-2))
if test $idx -ge 0; then
p_install_ndk=true
XB_HAS_NDK_CLANG=true
export XB_NDK_URL="${links[$idx]}"
echo -e "\e[1A${CH}Selected $(basename ${CC1}${XB_NDK_URL})\n${C0}"
break;
else
p_install_ndk=false
XB_HAS_NDK_CLANG=false
echo -e "\e[1A${CH}None selected: do not install NDK${C0}\n"
break;
fi
done
}
function pcount {
printf "%-14s"
local ln=0
while read -r sln; do
if [ -n "$sln" ]; then
((ln=ln+1))
printf "\e[13D%-13s" "[${ln}/${XB_COUNT_MAX}]"
fi
done
printf "\e[14D"
}
function get_ndk_links {
echo "$(wget -qO- https://developer.android.com/ndk/downloads | grep -Po "https://dl.google.com/android/repository/android-ndk-r..*-linux.zip" | sed "/\"/d")"
}
function install_ndk {
# No url, return
test -z "${XB_NDK_URL}" && return 1
local od=$(pwd)
cd ${HOME}
# install android-ndk
test -z "$(command -v unzip)" && check_install unzip
# Lets download
if [ ! -f "tmp.zip" ]; then
echo -ne "${CH}Downloading... ${C0} "
tput sc #&& echo -ne "\e[$(tput lines);0H${CY1}"
tput civis
wget --progress=dot ${XB_NDK_URL} -O tmp.zip 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\r%4s %s eta:%s ",$2,$1,$4)}'
tput rc
fi
XB_COUNT_MAX=$(zipinfo -h tmp | tr '\n' ':' | awk -F':' '{print $5}' | xargs)
echo -ne "${CH} decompressing... ${C0}"
local fname=$(basename ${XB_NDK_URL})
unzip tmp 2>&1 | pcount
tput cnorm
rm -f $fname tmp
mv android-ndk-r* android-ndk
export ANDROID_NDK_HOME="${HOME}/android-ndk"
cd $od
}
function install_llvm_gnu {
$cmd_install llvm clang libc6-dev-arm64-cross libc6-dev-armhf-cross
}
function llvm_mingw_get_latest_version {
echo $(curl --silent "https://api.github.com/repos/mstorsjo/llvm-mingw/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
}
function install_llvm_mingw {
# install llvm-mingw
local od=$(pwd)
if [ -z "${LLVM_MINGW_HOME}" ]; then
export LLVM_MINGW_HOME="$HOME/llvm-mingw"
fi
cd $(dirname ${LLVM_MINGW_HOME})
[ -d "llvm-mingw" ] && rm -rf "llvm-mingw"
export llvm_mingw_rel=$(llvm_mingw_get_latest_version)
wget_untar "https://github.com/mstorsjo/llvm-mingw/releases/download/${llvm_mingw_rel}/llvm-mingw-${llvm_mingw_rel}-ucrt-ubuntu-20.04-x86_64.tar.xz" "llvm-mingw"
echo $llvm_mingw_rel >"${LLVM_MINGW_HOME}/version"
export xv_llvm_mingw=$(./llvm-mingw/bin/aarch64-w64-mingw32-clang --version | grep -oP '\d*\.\d*.\d* (?=\()')
cd $od
}
function build_utils {
cd utils
[ -n "$(command -v clang++)" ] && cc=clang++ || cc=g++
printf "${CH}%-20s: ${C0}%s" " lz-string" "compiling..."
$cc -mtune=native -std=c++14 -O3 -Wall -stdlib=libstdc++ -c lz-string.cpp && clang++ -o lz-string lz-string.o && rm *.o && echo " done" || echo " fail"
cd ..
}
check_slink() {
local status
if [ ! -f "${1}" ]; then
sudo ln -s "${2}" "${1}" 2>&1 >/dev/null && status="created" || status="failed"
test $verbose && printf "${CH}%-50s-> ${C1}%s\n" " $1" "${2} ${status}"
elif [ "$(readlink ${1})" == "${2}" ]; then
test $verbose && printf "${CH}%-50s-> ${C0}%s\n" " $1" "${2} ok"
else
sudo ln -s "${2}" "${1}" 2>&1 >/dev/null && status="updated" || status="failed"
test $verbose && printf "${CH}%-50s-> ${C1}%s\n" " $1" "${2} ${status}"
fi
return 0
}
check_wrapper_gnu() {
if [ ! -f "/usr/${1}/bin/${2}" ]; then
cat <<-eof | sudo tee /usr/${1}/bin/${2} >/dev/null
#!/bin/bash
${2} --target=${1} --sysroot=/usr/${1} ${3} "\$@"
eof
sudo chmod +x "/usr/${1}/bin/${2}"
fi
}
check_wrapper_ndk() {
cat <<-eof | sudo tee ${3} >/dev/null
#!/bin/bash
\${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${2}\${API:=${NDK_API_DEFAULT}}-${1} "\$@"
eof
sudo chmod +x ${3}
}
XB_HAS_NDK_CLANG=true
XB_HAS_GNU_CLANG=true
XB_HAS_MINGW_CLANG=true
XB_HAS_MINGW_GCC=false
# first-time load common functions
test -z ${vsh+x} && source .common
# set cyan theme color
CH=${CC0}
force=false
init=false
ts=false
p_install_ndk=false
p_install_ndk_symlinks=false
p_install_llvm_gnu=false
p_install_llvm_sysroot=false
# load config
#[ -f ".config" ] && . .config || init=true
[ -n "$(command -v sudo)" ] && sudo echo -ne "Password: " && echo
#export cmd_install="sudo apt install"
if [ -z "${cmd_install}" ];then
[ -n "$(command -v sudo)" ] && cmd_install="sudo "
case $OSTYPE in
linux-gnu) cmd_install+="apt install"
;;
linux-android) cmd_install="pkg install"
;;
darwin) cmd_install="brew install"
;;
esac
#[ -n "$(which apt)" ] && cmd_install+="apt install " || cmd_install="exit 1;"
printf "\n${CH}%-20s: ${C0}%s\n" 'cmd install' "${cmd_install}"
fi
case "${1}" in
-f|--force) force=true
;;
--git-cleanup) echo -e "size before cleanup: $(du -s .git)\n"
git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.tar.gz' -- --all
rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc --aggressive --prune=now
echo -e "\nDone\n\n"
echo -e "size after cleanup: $(du -s .git)\n"
exit 0
;;
--install) shift; check_install $@; exit 0
;;
--latest-cmake) cmake_latest; exit 0
;;
--latest-llvm) sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"; exit 0
;;
--update) shift
while [ -n "${1}" ]; do
case "${1}" in
ndk|NDK) install_ndk;;
llvm-mingw) install_llvm_mingw;;
llvm-gnu) install_llvm_gnu;;
esac
shift
done
#exec ./x-setup
exit 0
;;
--libcheck) libcheck; exit 0
;;
--list) shift
v=$1
d=$2
[ -n "$d" ] && d="'$d'"
for f in *.sh; do
v=$(grep "$1=$d" $f)
[ -n "${v}" ] && echo "${f}: ${v}"
done
exit 0
;;
--build_utils) build_utils; exit 0
;;
--init) init=true
;;
--test) ts=true
;;
esac
if $ts; then
select_ndk
if [ -n "${XB_NDK_URL}" ]; then
install_ndk
fi
exit 0
fi
if $init; then
splash
if [ -z "${ANDROID_NDK_HOME}" ] || [ ! -d "${ANDROID_NDK_HOME}" ]; then
ndk_clang_bin_dir=$(find ~ -name "aarch64-linux-android??-clang" | tail -n1)
if [ -f "${ndk_clang_bin_dir}" ]; then
export ANDROID_NDK_HOME=$(echo ${ndk_clang_bin_dir} | sed 's|/toolchains/llvm/prebuilt.*||')
else
select_ndk
[ -n "${XB_NDK_URL}" ] && install_ndk
fi
if [ -d "${ANDROID_NDK_HOME}" ]; then
printf "\nexport ANDROID_NDK_HOME=${ANDROID_NDK_HOME}\n" >> ~/.bashrc && source ~/.bashrc
fi
fi
if [ -z "$(command -v clang)" ]; then
read -p "Linux LLVM/Clang Support: Install LLVM/Clang Toolchain? [Y|n]: " p_install_llvm_gnu
test "${p_install_llvm_gnu,,}" == "y" && p_install_llvm_gnu=true || p_install_llvm_gnu=false
XB_HAS_GNU_CLANG=${p_install_llvm_gnu}
fi
fi
echo -e "\n${CC1}This Machine:"
[ -z "${build_arch}" ] && build_arch="$(uname -m)-${OSTYPE,,}"
[ -z "${build_os}" ] && build_os=$(uname -s)
[ -z "${build_cpu}" ] && build_cpu=$(uname -m)
printf "${CH}%-20s: ${C0}%s\n" ' build arch' ${build_arch}
printf "${CH}%-20s: ${C0}%s\n" ' build os' ${build_os}
printf "${CH}%-20s: ${C0}%s\n" ' build cpu' ${build_cpu}
check_install gcc g++
gcc_version=$(gcc -dumpversion)
printf "${CH}%-20s: ${C0}%s\n" ' gcc version' ${gcc_version}
safe_mkdir ${dir_root}/builds/toolchain
export dir_toolchain="$(pwd)/builds/toolchain"
echo -e "\n${CC1}GNU-GCC:"
check_install 'gcc-aarch64-linux-gnu' 'g++-aarch64-linux-gnu' "libstdc++-${gcc_version}-dev-arm64-cross"
check_install 'gcc-arm-linux-gnueabihf' 'g++-arm-linux-gnueabihf' 'libstdc++6-armhf-cross'
check_install 'gcc-i686-linux-gnu' 'g++-i686-linux-gnu'
echo -e "\n${CC1}LLVM-Clang:"
$XB_HAS_GNU_CLANG && check_install clang-format clang-tidy clang-tools clang clangd \
libc++-dev libstdc++-12-dev libc++1 libc++abi-dev libc++abi1 libclang-dev \
libclang-common-dev libclang1 liblldb-dev libllvm-ocaml-dev libomp-dev libomp5 \
lld lldb llvm-dev llvm-runtime llvm python3-clang
echo
cclang=$(command -v clang)
if [ -n "${cclang}" ]; then
printf "${CH}%-20s: ${C0}%s\n" " found at" ${cclang}
CLANG_GNU_VERSION_FULL=$(clang -dumpversion)
CLANG_GNU_VERSION=${CLANG_GNU_VERSION_FULL%%\.*}
printf "${CH}%-20s: ${C0}%s\n" ' clang' "${CLANG_GNU_VERSION_FULL}"
# install symlinks
check_install libllvmlibc-${CLANG_GNU_VERSION}-dev
cl=(aarch64 arm i686 x86_64)
ab=(arm64 armhf i386 x86_64)
abi=(gnu gnueabihf gnu gnu)
cclang_args=''
for a in 0 1 2 3; do
t="${cl[$a]}-linux-${abi[$a]}"
if [ "${t}" != "${build_arch}" ]; then
check_install libc6-dev-${ab[$a]}-cross libstdc++6-${ab[$a]}-cross
[ -d "/usr/${t}/bin" ] || sudo mkdir -p "/usr/${t}/bin"
for e in ar as nm addr2line objcopy objdump ranlib readelf size strings strip windres; do
check_slink "/usr/${t}/bin/llvm-${e}" "/usr/bin/llvm-${e}"
done
llvm_vrs=$(ls -lh ${cclang} | grep -oP 'llvm-\d+')
if [ -n "${llvm_vrs}" ]; then
#check_slink "/usr/bin/llvm-addr2line" "/usr/lib/${llvm_vrs}/bin/llvm-addr2line"
check_slink "/usr/bin/llvm-windres" "/usr/lib/${llvm_vrs}/bin/llvm-windres"
fi
check_slink "/usr/${t}/bin/ld.lld" "/usr/bin/ld.lld"
test "${ab[${a}]}" = "armhf" && cclang_args='-mfloat-abi=hard -mfpu=neon' || cclang_args=''
check_wrapper_gnu "${t}" 'clang' "${cclang_args}"
check_wrapper_gnu "${t}" 'clang++' "${cclang_args}"
fi
done
fi
check_ndk_symlink(){
[[ -z "$(readlink "$1" | grep ${ANDROID_NDK_HOME})" ]]
}
update_ndkhome(){
sed -i 's@^export ANDROID_NDK_HOME=.*$@export ANDROID_NDK_HOME='"${ANDROID_NDK_HOME}"'@' ~/.bashrc
source ~/.bashrc
}
if [ "${OSTYPE}" != "linux-android" ] && $XB_HAS_NDK_CLANG; then
echo -e "\n${CC1}Android NDK:"
if [ -z "${ANDROID_NDK_HOME}" ]; then
ndk_clang_bin_dir=$(find ~ -name "aarch64-linux-android??-clang" | tail -n1)
if [ -z "${ndk_clang_bin_dir}" ]; then
install_ndk
else
export ANDROID_NDK_HOME=$(echo ${ndk_clang_bin_dir} | sed 's|/toolchains/llvm/prebuilt.*||')
fi
if [ -n "${ANDROID_NDK_HOME}" ]; then
printf "\nexport ANDROID_NDK_HOME=${ANDROID_NDK_HOME}\n" >> ~/.bashrc && source ~/.bashrc
fi
fi
if [ -n "${ANDROID_NDK_HOME}" ]; then
r="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android"
ANDROID_NDK_API="$(find ${r} -maxdepth 1 -type d | sed 's,'${r}',,' | sort | tail -n1 | sed 's,/,,')"
printf "${CH}%-20s: ${C0}%s\n" " found at" ${ANDROID_NDK_HOME}
printf "${CH}%-20s: ${C0}%s\n" " API level" ${ANDROID_NDK_API}
ndk_release=$(cat ${ANDROID_NDK_HOME}/source.properties | grep -Po '\.Revision.=.\K([0-9\.\-a-zA-Z]+)')
NDK_RELEASE=$(cat ${ANDROID_NDK_HOME}/source.properties | grep -Po 'BaseRevision.=.\K([0-9\.]+)')
printf "${CH}%-20s: ${C0}%s " ' version' ${ndk_release}
ndk_release_list=($(wget -qO- https://developer.android.com/ndk/downloads | grep -oP '(?<=ndkVersion..)\d+\.\d+\.\d+.*(?=")'))
ndk_release_latest="${ndk_release_list[-1]}"
if [ "${ndk_release}" = "${ndk_release_latest}" ]; then
echo -e "(updated)"
else
echo -e "${CY1} latest is ${ndk_release_latest}${C0}"
ndk_parent="$(dirname ${ANDROID_NDK_HOME})"
if [ -d "${ndk_parent}/${ndk_release_latest}" ]; then
read -p " Switch from ${ndk_version} to ${ndk_release_latest}? [Y|n]" yn;
case $yn in
y*|Y*)
export ANDROID_NDK_HOME="${ndk_parent}/${ndk_release_latest}"
vrs_ndk=${ndk_release_latest}
sed -i 's@^export ANDROID_NDK_HOME=.*$@export ANDROID_NDK_HOME='"${ANDROID_NDK_HOME}"'@' ~/.bashrc
source ~/.bashrc
;;
esac
fi
fi
ndk_build="linux-$(uname -m)"
TOOLCHAIN_NDK="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${ndk_build}"
SYSROOT_NDK="${TOOLCHAIN_NDK}/sysroot"
CLANG_NDK_VERSION_FULL="$(${TOOLCHAIN_NDK}/bin/clang -dumpversion)"
CLANG_NDK_VERSION="${CLANG_NDK_VERSION_FULL%%\.*}"
#TOOLCHAIN_NDK="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${ndk_build}"
#ndk_sysroot="${TOOLCHAIN_NDK}/sysroot"
#ndk_clang_version=$(${TOOLCHAIN_NDK}/bin/clang -dumpversion)
printf "${CH}%-20s: ${C0}%s\n" ' clang' "${CLANG_NDK_VERSION_FULL}"
# check and create symlinks in toolchains dir if needed
c_arch=('aarch64' 'arm' 'i686' 'x86_64')
c_abi=('arm64-v8a' 'armeabi-v7a' 'x86' 'x86_64')
c_clang=('aarch64-linux-android' 'armv7a-linux-androideabi' 'i686-linux-android' 'x86_64-linux-android')
c_lib=('aarch64-linux-android' 'arm-linux-androideabi' 'i686-linux-android' 'x86_64-linux-android')
for i in 0 1 2 3; do
#cl="${c_arch[${i}]}"
printf " ${CH}Checking symlinks for ${CW}${c_arch[${i}]}"
dir_toolchain="/usr/${c_lib[${i}]}"
#
[ -d "${dir_toolchain}/bin" ] || sudo mkdir -p "${dir_toolchain}/bin"
test $verbose && printf "\n clang"
if $force || [ ! -f "${dir_toolchain}/bin/clang" ]; then
check_wrapper_ndk "clang" "${c_clang[${i}]}" "${dir_toolchain}/bin/clang"
fi
test $verbose && printf " clang++"
if $force || [ ! -f "${dir_toolchain}/bin/clang++" ]; then
check_wrapper_ndk "clang++" "${c_clang[${i}]}" "${dir_toolchain}/bin/clang++"
fi
#[ -f "${dir_toolchain}/bin/as" ] || sudo ln -s "${TOOLCHAIN_NDK}/bin/${c_lib[${i}]}-as" "${dir_toolchain}/bin/as"
#[ -f "${dir_toolchain}/bin/ld" ] || sudo ln -s -f "${TOOLCHAIN_NDK}/bin/lld" "${dir_toolchain}/bin/ld"
check_ndk_symlink "${dir_toolchain}/bin/ld" && sudo ln -sfn "${TOOLCHAIN_NDK}/bin/ld" "${dir_toolchain}/bin/ld"
test $verbose && printf " ld"
check_ndk_symlink "${dir_toolchain}/bin/yasm" && sudo ln -sfn "${TOOLCHAIN_NDK}/bin/yasm" "${dir_toolchain}/bin/yasm"
test $verbose && printf " yasm"
for j in as ar nm addr2line objcopy objdump ranlib readelf readobj size strings strip; do
test $verbose && printf " $j"
check_ndk_symlink "${dir_toolchain}/bin/${j}" && sudo ln -sfn "${TOOLCHAIN_NDK}/bin/llvm-${j}" "${dir_toolchain}/bin/${j}"
#[ -f "${dir_toolchain}/bin/${j}" ] || sudo ln -s -f "${TOOLCHAIN_NDK}/bin/llvm-${j}" "${dir_toolchain}/bin/${j}"
done
check_ndk_symlink "${dir_toolchain}/lib" && sudo ln -sfn "${TOOLCHAIN_NDK}/sysroot/usr/lib/${c_lib[${i}]}" "${dir_toolchain}/lib"
[ -f "${dir_toolchain}/lib/libpthread.a" ] || sudo ${dir_toolchain}/bin/ar cr "${dir_toolchain}/lib/libpthread.a"
[ -f "${dir_toolchain}/lib/librt.a" ] || sudo ${dir_toolchain}/bin/ar cr "${dir_toolchain}/lib/librt.a"
check_ndk_symlink "${dir_toolchain}/sysroot" && sudo ln -sfn "${ndk_sysroot}" "${dir_toolchain}/sysroot"
check_ndk_symlink "${dir_toolchain}/include" && sudo ln -sfn "${ndk_sysroot}/usr/include" "${dir_toolchain}/include"
[ -d "${dir_root}/builds/android/${c_abi[${i}]}" ] || mkdir -p "${dir_root}/builds/android/${c_abi[${i}]}"
[ -d "${dir_toolchain}/local" ] && sudo unlink ${dir_toolchain}/local
sudo ln -sf "${dir_root}/builds/android/${c_abi[${i}]}" "${dir_toolchain}/local"
echo -e "${CH} ok${C0}"
done
printf "${CH}%-20s: ${C0}%s\n" ' toolchain slinks' ok
[ -f "${dir_toolchain}/include/sys/soundcard.h" ] || printf "#include <linux/soundcard.h>" >"${dir_toolchain}/include/sys/soundcard.h"
else
echo -e " not installed"
fi
fi
# usage create_symlink <src> <dst> will test if src and dst exists first
function create_symlink {
if [ ! -f "${2}" ] || [ ! "$(readlink ${2})" == "${1}" ]; then
sudo ln -s "${1}" "${2}"
test $verbose && printf "${CC1}%-10s ${C0}%-60s-> ${CW}%s\n" " created" "${1}" "${2}"
else
test $verbose && printf "${CH}%-10s ${C0}%-60s-> ${C0}%s\n" " ok" "${1}" "${2}"
fi
#test ! -f "${2}" && test -f "${1}" && sudo ln -s "${1}" "${2}"
}
function llvm_mingw_check_symlinks {
local cl_abi
if [ -z "$(ls -A ${LLVM_MINGW_HOME}/include)" ]; then
rm -r "${LLVM_MINGW_HOME}/include"
ln -s ${LLVM_MINGW_HOME}/generic-w64-mingw32/include ${LLVM_MINGW_HOME}/include
fi
for cl in aarch64 arm i686 x86_64; do
target_dir="/usr/${cl}-w64-mingw32"
cl_abi=${cl/arm/armv7}
source_dir="${LLVM_MINGW_HOME}/${cl_abi}-w64-mingw32"
test -d "${target_dir}" || sudo mkdir -p "${target_dir}/bin"
test -d "${target_dir}/dll" || sudo ln -s "${source_dir}/bin" "${target_dir}/dll"
test -d "${target_dir}/include" || sudo ln -s "${source_dir}/include" "${target_dir}/include"
test -d "${target_dir}/lib" || sudo ln -s "${source_dir}/lib" "${target_dir}/lib"
test -d "${target_dir}/share" || sudo ln -s "${source_dir}/share" "${target_dir}/share"
printf " ${CH}Checking symlinks for ${CW}${cl_abi}\n"
for e in addr2line ar as c++ clang clang++ dlltool g++ gcc ld llvm-ar llvm-ranlib nm objcopy objdump ranlib readelf size strings strip widl windres; do
create_symlink "${LLVM_MINGW_HOME}/bin/${cl_abi}-w64-mingw32-${e}" "${target_dir}/bin/${e}"
create_symlink "${LLVM_MINGW_HOME}/bin/${cl_abi}-w64-mingw32uwp-${e}" "${target_dir}/bin/uwp-${e}"
done
done
printf "${CH}%-20s: ${C0}%s\n" ' toolchain slinks' ok
}
echo -e "\n${CC1}LLVM MINGW:"
if [ -z "${LLVM_MINGW_HOME}" ]; then
llvm_mingw_bin_dir=$(find ~ -name "aarch64-w64-mingw32uwp-dlltool" | head -n1)
if [ -z "${llvm_mingw_bin_dir}" ]; then
echo -ne " not found. Install? "; read -p "[Y|n]" pndk
case $pndk in y|Y) install_llvm_mingw;; esac
else
export LLVM_MINGW_HOME=$(dirname $(dirname $llvm_mingw_bin_dir))
fi
fi
if [ -n "${LLVM_MINGW_HOME}" ]; then
printf "${CH}%-20s: ${C0}%s\n" " found at" ${LLVM_MINGW_HOME}
llvm_mingw_latest_release=$(llvm_mingw_get_latest_version)
[ -f "${LLVM_MINGW_HOME}/version" ] || echo "$llvm_mingw_latest_release" >>"${LLVM_MINGW_HOME}/version"
LLVM_MINGW_REL=$(cat ${LLVM_MINGW_HOME}/version)
printf "${CH}%-20s: ${C0}%s " ' release' ${LLVM_MINGW_REL}
if [ "${LLVM_MINGW_REL}" == "${llvm_mingw_latest_release}" ]; then
echo -e "(updated)"
else
echo -e "${CY1} latest is ${llvm_mingw_latest_release}${C0}"
fi
CLANG_MINGW_VERSION_FULL=$(${LLVM_MINGW_HOME}/bin/clang -dumpversion)
CLANG_MINGW_VERSION=${llvm_mingw_clang_version%%\.*}
printf "${CH}%-20s: ${C0}%s\n" ' clang' "${CLANG_MINGW_VERSION_FULL}"
# check and create symlinks in toolchains dir if needed
llvm_mingw_check_symlinks
fi
echo -e "\n${CC1}${b} Build tools${C0}"
check_install make cmake cmake-curses-gui meson build-essential automake autoconf autogen autopoint libtool-bin m4 nasm yasm pkg-config
case "$(meson --version)" in 0.5*) sudo add-apt-repository ppa:ubuntu-support-team/meson -y 2>&1 >/dev/null
sudo apt update 2>&1 >/dev/null
sudo apt install meson -y 2>&1 >/dev/null
;;
esac
echo -e "\n${CC1}${b} Repository tools${C0}"
check_install git subversion lzip unzip
echo -e "\n${CC1}${b} Other tools${C0}"
check_install curl gperf bison texinfo patch jq gettext
echo -e "\n${CC1}${b} Utilities${C0}"
if [ ! -f "${dir_root}/utils/lz-string" ]; then
build_utils
fi
echo -ne "\n${CC1}${b} Writing config${C0}"
[ -z "${llvm_mingw}" ] && [ -n "${LLVM_MINGW_HOME}" ] && llvm_mingw=${LLVM_MINGW_HOME}
case "$(uname -s)" in
Linux) build_arch=$(echo $(uname -m)-linux-gnu)
[ -n "$(grep -q BCM2708 /proc/cpuinfo)" ] && build_arch="${build_arch}eabihf"
if [ -n "$(command -v getprop)" ];then
build_arch=$(echo $(uname -m)-linux-android)
export API=$(getprop ro.build.version.sdk)
fi
;;
Darwin) build_arch=$(echo $(uname -m)-darwin-gnu);;
CYGWIN*|MINGW32*|MSYS*|MINGW*) build_arch=$(echo $(uname -m)-w64-mingw32);;
esac
#xv_x64_mingw=$(ls -t /usr/lib/gcc/x86_64-w64-mingw32 | grep -E "*-win32" | head -n1 2>/dev/null )
#xv_x86_mingw=$(ls -t /usr/lib/gcc/i686-w64-mingw32 | grep -E "*-win32" | head -n1 2>/dev/null)
: "${API:=34}"
cat <<-EOF >${dir_root}/.config
#!/bin/bash
export config_lastupdate=$(date +%s) \\
dir_root="$(pwd)" \\
sudo=$(command -v sudo) \\
cmd_install="${cmd_install}" \\
build_arch="${build_arch}" \\
XB_HAS_GNU_CLANG=${XB_HAS_GNU_CLANG} \\
XB_HAS_MINGW_CLANG=${XB_HAS_MINGW_CLANG} \\
XB_HAS_MINGW_GCC=${XB_HAS_MINGW_GCC} \\
XB_HAS_NDK_CLANG=${XB_HAS_NDK_CLANG} \\
CLANG_NDK_VERSION=${CLANG_NDK_VERSION} \\
CLANG_GNU_VERSION=${CLANG_GNU_VERSION} \\
CLANG_MINGW_VERSION=${CLANG_MINGW_VERSION} \\
LLVM_MINGW_HOME="${llvm_mingw}" \\
ANDROID_NDK_HOME="${ANDROID_NDK_HOME}" \\
ANDROID_NDK_API="${ANDROID_NDK_API}" \\
NDK_RELEASE="${NDK_RELEASE}" \\
TOOLCHAIN_NDK="${TOOLCHAIN_NDK}" \\
SYSROOT_NDK="${SYSROOT_NDK}" \\
LLVM_MINGW_REL="${LLVM_MINGW_REL}" \\
MAKE_EXECUTABLE="$(command -v make)" \\
CMAKE_EXECUTABLE="$(command -v cmake)" \\
NASM_EXECUTABLE="$(command -v nasm)" \\
PKG_CONFIG="$(command -v pkg-config)" \\
HOST_NPROC="$(nproc)" \\
xv_llvm_mingw="${xv_llvm_mingw}" \\
llvm_mingw_rel="${llvm_mingw_rel}" \\
GCC_AARCH64_REL="$(/usr/bin/aarch64-linux-gnu-gcc -dumpversion)" \\
GCC_ARMHF_REL="$(/usr/bin/arm-linux-gnueabihf-gcc -dumpversion)" \\
GCC_I686_REL="$(/usr/bin/i686-linux-gnu-gcc -dumpversion)" \\
GCC_X86_64_REL="$(/usr/bin/x86_64-linux-gnu-gcc -dumpversion)" \\
xv_x64_mingw="${xv_llvm_mingw}" \\
xv_x86_mingw="${xv_llvm_mingw}"
EOF
echo -ne "... ${CC1}Done!${C0}\n\n"
# unused
function llvm_mingw_check_symlinks_old {
# check and create symlinks in toolchains dir if needed
for cl in aarch64 arm i686 x86_64; do
for e in ar nm addr2line dlltool objcopy ranlib readelf strings strip windres; do
v="${dir_toolchain}/${cl}-w64-mingw32-${e}"
[ ! -f "${v}" ] && ln -s "${LLVM_MINGW_HOME}/bin/llvm-${e}" "${v}" 2>/dev/null
done
for e in as c++ c11 c99 cc clang clang++ g++ gcc; do
v="${dir_toolchain}/${cl}-w64-mingw32-${e}"
[ ! -f "${v}" ] && ln -s "${LLVM_MINGW_HOME}/bin/clang-target-wrapper.sh" "${v}" 2>/dev/null
done
[ ! -f "${dir_toolchain}/${cl}-w64-mingw32-objdump" ] && ln -s "${LLVM_MINGW_HOME}/bin/objdump-wrapper.sh" "${dir_toolchain}/${cl}-w64-mingw32-objdump" 2>/dev/null
[ ! -f "${dir_toolchain}/${cl}-w64-mingw32-ld" ] && ln -s "${LLVM_MINGW_HOME}/bin/ld-wrapper.sh" "${dir_toolchain}/${cl}-w64-mingw32-ld" 2>/dev/null
[ ! -f "${dir_toolchain}/${cl}-w64-mingw32-widl" ] && ln -s "${LLVM_MINGW_HOME}/bin/i686-w64-mingw32-widl" "${dir_toolchain}/${cl}-w64-mingw32-ld" 2>/dev/null
done
printf "${CH}%-20s: ${C0}%s\n" ' toolchain slinks' ok
}