-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-sysroot.sh
executable file
·68 lines (47 loc) · 1.55 KB
/
build-sysroot.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
#!/bin/bash
HOST_ARCH=amd64
TARGET_ARCH=armhf
DEB_RELEASE=bullseye
CHROOT_PATH="$(realpath $1)/${DEB_RELEASE}-${TARGET_ARCH}-chroot"
SYSROOT_PATH="$(realpath $1)/${DEB_RELEASE}-${TARGET_ARCH}-sysroot"
set -xe
install_packages(){
awk '/^[^#]/{ print;}' $2 > ${1}/etc/${2}
chroot ${1} /bin/bash -c "apt update && xargs apt install -y < /etc/${2} --"
}
chroot_init(){
local ARCH=$1
local DEST=$2
debootstrap --foreign --arch ${ARCH} --variant minbase ${DEB_RELEASE} ${DEST}
chroot ${DEST} /bin/bash -c "useradd -u 0 root"
}
target_sysroot_init(){
local sysroot=$1
local chroot=$2
mkdir $1/{usr,opt} -p
test -d ${sysroot}/usr/bin || mkdir ${sysroot}/usr/bin
cp -r ${chroot}/lib ${sysroot}
cp -r ${chroot}/usr/include ${sysroot}/usr
cp -r ${chroot}/usr/lib ${sysroot}/usr
cp ${chroot}/usr/bin/*qmake ${sysroot}/usr/bin
wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
sed -i '1c#!/usr/bin/env python3' sysroot-relativelinks.py
./sysroot-relativelinks.py ${sysroot}
rm sysroot-relativelinks.py
}
install_toolchain_file(){
local file=$1
local sysroot=$2
awk "{ gsub(/<<sysroot>>/,"\""${SYSROOT_PATH}"\""); print; }" ${file} > ${sysroot}/toolchain.cmake
}
main(){
if [ ! -f ${CHROOT_PATH}/etc/os-release ]; then
chroot_init ${TARGET_ARCH} ${CHROOT_PATH}
fi
install_packages ${CHROOT_PATH} target.packages
target_sysroot_init $SYSROOT_PATH $CHROOT_PATH
install_toolchain_file toolchain.cmake ${SYSROOT_PATH}
echo "Succesfully build chroot at ${CHROOT_PATH}"
}
main