2018-11-08 01:51:56 +00:00
#!/usr/bin/env bash
usage( )
{
2020-03-31 13:04:58 +00:00
echo " Usage: $0 [BuildArch] [CodeName] [lldbx.y] [--skipunmount] --rootfsdir <directory>] "
2018-11-08 01:51:56 +00:00
echo "BuildArch can be: arm(default), armel, arm64, x86"
2020-03-31 13:04:58 +00:00
echo "CodeName - optional, Code name for Linux, can be: trusty, xenial(default), zesty, bionic, alpine. If BuildArch is armel, LinuxCodeName is jessie(default) or tizen."
echo " for FreeBSD can be: freebsd11 or freebsd12."
echo "lldbx.y - optional, LLDB version, can be: lldb3.9(default), lldb4.0, lldb5.0, lldb6.0 no-lldb. Ignored for alpine and FReeBSD"
2018-11-08 01:51:56 +00:00
echo "--skipunmount - optional, will skip the unmount of rootfs folder."
exit 1
}
2020-03-31 13:04:58 +00:00
__CodeName = xenial
2018-11-08 01:51:56 +00:00
__CrossDir = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
__InitialDir = $PWD
__BuildArch = arm
__UbuntuArch = armhf
__UbuntuRepo = "http://ports.ubuntu.com/"
2019-05-08 12:25:49 +00:00
__LLDB_Package = "liblldb-3.9-dev"
2018-11-08 01:51:56 +00:00
__SkipUnmount = 0
# base development support
__UbuntuPackages = "build-essential"
__AlpinePackages = "alpine-base"
__AlpinePackages += " build-base"
__AlpinePackages += " linux-headers"
2020-01-22 13:31:03 +00:00
__AlpinePackagesEdgeTesting = " lldb-dev"
__AlpinePackagesEdgeMain = " llvm9-libs"
__AlpinePackagesEdgeMain += " python3"
2018-11-08 01:51:56 +00:00
# symlinks fixer
__UbuntuPackages += " symlinks"
# CoreCLR and CoreFX dependencies
__UbuntuPackages += " libicu-dev"
__UbuntuPackages += " liblttng-ust-dev"
__UbuntuPackages += " libunwind8-dev"
__AlpinePackages += " gettext-dev"
__AlpinePackages += " icu-dev"
__AlpinePackages += " libunwind-dev"
__AlpinePackages += " lttng-ust-dev"
# CoreFX dependencies
__UbuntuPackages += " libcurl4-openssl-dev"
__UbuntuPackages += " libkrb5-dev"
__UbuntuPackages += " libssl-dev"
__UbuntuPackages += " zlib1g-dev"
__AlpinePackages += " curl-dev"
__AlpinePackages += " krb5-dev"
__AlpinePackages += " openssl-dev"
__AlpinePackages += " zlib-dev"
2020-03-31 13:04:58 +00:00
__FreeBSDBase = "12.1-RELEASE"
__FreeBSDPkg = "1.10.5"
__FreeBSDPackages = "libunwind"
__FreeBSDPackages += " icu"
__FreeBSDPackages += " libinotify"
__FreeBSDPackages += " lttng-ust"
__FreeBSDPackages += " llvm-90"
__FreeBSDPackages += " krb5"
2018-11-08 01:51:56 +00:00
__UnprocessedBuildArgs =
2019-05-08 12:25:49 +00:00
while :; do
if [ $# -le 0 ] ; then
break
fi
lowerI = " $( echo $1 | awk '{print tolower($0)}' ) "
2018-11-08 01:51:56 +00:00
case $lowerI in
-?| -h| --help)
usage
exit 1
; ;
arm)
__BuildArch = arm
__UbuntuArch = armhf
__AlpineArch = armhf
__QEMUArch = arm
; ;
arm64)
__BuildArch = arm64
__UbuntuArch = arm64
__AlpineArch = aarch64
__QEMUArch = aarch64
; ;
armel)
__BuildArch = armel
__UbuntuArch = armel
__UbuntuRepo = "http://ftp.debian.org/debian/"
2020-03-31 13:04:58 +00:00
__CodeName = jessie
2018-11-08 01:51:56 +00:00
; ;
x86)
__BuildArch = x86
__UbuntuArch = i386
__UbuntuRepo = "http://archive.ubuntu.com/ubuntu/"
; ;
lldb3.6)
__LLDB_Package = "lldb-3.6-dev"
; ;
lldb3.8)
__LLDB_Package = "lldb-3.8-dev"
; ;
lldb3.9)
__LLDB_Package = "liblldb-3.9-dev"
; ;
lldb4.0)
__LLDB_Package = "liblldb-4.0-dev"
; ;
2019-05-08 12:25:49 +00:00
lldb5.0)
__LLDB_Package = "liblldb-5.0-dev"
; ;
lldb6.0)
__LLDB_Package = "liblldb-6.0-dev"
; ;
2018-11-08 01:51:56 +00:00
no-lldb)
unset __LLDB_Package
; ;
2019-05-08 12:25:49 +00:00
trusty) # Ubuntu 14.04
2020-03-31 13:04:58 +00:00
if [ " $__CodeName " != "jessie" ] ; then
__CodeName = trusty
2018-11-08 01:51:56 +00:00
fi
; ;
2019-05-15 12:11:39 +00:00
xenial) # Ubuntu 16.04
2020-03-31 13:04:58 +00:00
if [ " $__CodeName " != "jessie" ] ; then
__CodeName = xenial
2018-11-08 01:51:56 +00:00
fi
; ;
2019-05-15 12:11:39 +00:00
zesty) # Ubuntu 17.04
2020-03-31 13:04:58 +00:00
if [ " $__CodeName " != "jessie" ] ; then
__CodeName = zesty
2018-11-08 01:51:56 +00:00
fi
; ;
2019-05-08 12:25:49 +00:00
bionic) # Ubuntu 18.04
2020-03-31 13:04:58 +00:00
if [ " $__CodeName " != "jessie" ] ; then
__CodeName = bionic
2018-11-08 01:51:56 +00:00
fi
; ;
2019-05-08 12:25:49 +00:00
jessie) # Debian 8
2020-03-31 13:04:58 +00:00
__CodeName = jessie
2018-11-08 01:51:56 +00:00
__UbuntuRepo = "http://ftp.debian.org/debian/"
; ;
2019-05-15 12:11:39 +00:00
stretch) # Debian 9
2020-03-31 13:04:58 +00:00
__CodeName = stretch
2019-05-15 12:11:39 +00:00
__UbuntuRepo = "http://ftp.debian.org/debian/"
__LLDB_Package = "liblldb-6.0-dev"
; ;
buster) # Debian 10
2020-03-31 13:04:58 +00:00
__CodeName = buster
2019-05-15 12:11:39 +00:00
__UbuntuRepo = "http://ftp.debian.org/debian/"
__LLDB_Package = "liblldb-6.0-dev"
; ;
2018-11-08 01:51:56 +00:00
tizen)
if [ " $__BuildArch " != "armel" ] ; then
echo "Tizen is available only for armel."
usage;
exit 1;
fi
2020-03-31 13:04:58 +00:00
__CodeName =
2018-11-08 01:51:56 +00:00
__UbuntuRepo =
__Tizen = tizen
; ;
alpine)
2020-03-31 13:04:58 +00:00
__CodeName = alpine
2018-11-08 01:51:56 +00:00
__UbuntuRepo =
; ;
2020-03-31 13:04:58 +00:00
freebsd11)
__FreeBSDBase = "11.3-RELEASE"
; &
freebsd12)
__CodeName = freebsd
__BuildArch = x64
__SkipUnmount = 1
; ;
2018-11-08 01:51:56 +00:00
--skipunmount)
__SkipUnmount = 1
; ;
2019-05-08 12:25:49 +00:00
--rootfsdir| -rootfsdir)
shift
__RootfsDir = $1
; ;
2018-11-08 01:51:56 +00:00
*)
2019-05-08 12:25:49 +00:00
__UnprocessedBuildArgs = " $__UnprocessedBuildArgs $1 "
2018-11-08 01:51:56 +00:00
; ;
esac
2019-05-08 12:25:49 +00:00
shift
2018-11-08 01:51:56 +00:00
done
if [ " $__BuildArch " = = "armel" ] ; then
__LLDB_Package = "lldb-3.5-dev"
fi
__UbuntuPackages += " ${ __LLDB_Package :- } "
2019-05-08 12:25:49 +00:00
if [ -z " $__RootfsDir " ] && [ ! -z " $ROOTFS_DIR " ] ; then
2018-11-08 01:51:56 +00:00
__RootfsDir = $ROOTFS_DIR
fi
2019-05-08 12:25:49 +00:00
if [ -z " $__RootfsDir " ] ; then
2019-06-05 12:10:31 +00:00
__RootfsDir = " $__CrossDir /../../../.tools/rootfs/ $__BuildArch "
2019-05-08 12:25:49 +00:00
fi
2018-11-08 01:51:56 +00:00
if [ -d " $__RootfsDir " ] ; then
if [ $__SkipUnmount = = 0 ] ; then
umount $__RootfsDir /*
fi
rm -rf $__RootfsDir
fi
2020-03-31 13:04:58 +00:00
if [ [ " $__CodeName " = = "alpine" ] ] ; then
2018-11-08 01:51:56 +00:00
__ApkToolsVersion = 2.9.1
2019-11-19 13:41:23 +00:00
__AlpineVersion = 3.9
2018-11-08 01:51:56 +00:00
__ApkToolsDir = $( mktemp -d)
wget https://github.com/alpinelinux/apk-tools/releases/download/v$__ApkToolsVersion /apk-tools-$__ApkToolsVersion -x86_64-linux.tar.gz -P $__ApkToolsDir
tar -xf $__ApkToolsDir /apk-tools-$__ApkToolsVersion -x86_64-linux.tar.gz -C $__ApkToolsDir
mkdir -p $__RootfsDir /usr/bin
cp -v /usr/bin/qemu-$__QEMUArch -static $__RootfsDir /usr/bin
2020-01-22 13:31:03 +00:00
2018-11-08 01:51:56 +00:00
$__ApkToolsDir /apk-tools-$__ApkToolsVersion /apk \
-X http://dl-cdn.alpinelinux.org/alpine/v$__AlpineVersion /main \
-X http://dl-cdn.alpinelinux.org/alpine/v$__AlpineVersion /community \
-U --allow-untrusted --root $__RootfsDir --arch $__AlpineArch --initdb \
add $__AlpinePackages
2020-01-22 13:31:03 +00:00
$__ApkToolsDir /apk-tools-$__ApkToolsVersion /apk \
-X http://dl-cdn.alpinelinux.org/alpine/edge/main \
-U --allow-untrusted --root $__RootfsDir --arch $__AlpineArch --initdb \
add $__AlpinePackagesEdgeMain
$__ApkToolsDir /apk-tools-$__ApkToolsVersion /apk \
-X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
-U --allow-untrusted --root $__RootfsDir --arch $__AlpineArch --initdb \
add $__AlpinePackagesEdgeTesting
2018-11-08 01:51:56 +00:00
rm -r $__ApkToolsDir
2020-03-31 13:04:58 +00:00
elif [ [ " $__CodeName " = = "freebsd" ] ] ; then
mkdir -p $__RootfsDir /usr/local/etc
wget -O - https://download.freebsd.org/ftp/releases/amd64/${ __FreeBSDBase } /base.txz | tar -C $__RootfsDir -Jxf - ./lib ./usr/lib ./usr/libdata ./usr/include ./usr/share/keys ./etc ./bin/freebsd-version
# For now, ask for 11 ABI even on 12. This can be revisited later.
echo " ABI = \"FreeBSD:11:amd64\"; FINGERPRINTS = \" ${ __RootfsDir } /usr/share/keys\"; REPOS_DIR = [\" ${ __RootfsDir } /etc/pkg\"]; REPO_AUTOUPDATE = NO; RUN_SCRIPTS = NO; " > ${ __RootfsDir } /usr/local/etc/pkg.conf
echo "FreeBSD: { url: " pkg+http://pkg.FreeBSD.org/\$ { ABI} /quarterly" , mirror_type: \"srv\", signature_type: \"fingerprints\", fingerprints: \" ${ __RootfsDir } /usr/share/keys/pkg\", enabled: yes } " > ${ __RootfsDir } /etc/pkg/FreeBSD.conf
mkdir -p $__RootfsDir /tmp
# get and build package manager
wget -O - https://github.com/freebsd/pkg/archive/${ __FreeBSDPkg } .tar.gz | tar -C $__RootfsDir /tmp -zxf -
cd $__RootfsDir /tmp/pkg-${ __FreeBSDPkg }
./autogen.sh && ./configure --prefix= $__RootfsDir /host && make install
rm -rf $__RootfsDir /tmp/pkg-${ __FreeBSDPkg }
# install packages we need.
$__RootfsDir /host/sbin/pkg -r $__RootfsDir -C $__RootfsDir /usr/local/etc/pkg.conf update
$__RootfsDir /host/sbin/pkg -r $__RootfsDir -C $__RootfsDir /usr/local/etc/pkg.conf install --yes $__FreeBSDPackages
elif [ [ -n $__CodeName ] ] ; then
qemu-debootstrap --arch $__UbuntuArch $__CodeName $__RootfsDir $__UbuntuRepo
cp $__CrossDir /$__BuildArch /sources.list.$__CodeName $__RootfsDir /etc/apt/sources.list
2018-11-08 01:51:56 +00:00
chroot $__RootfsDir apt-get update
chroot $__RootfsDir apt-get -f -y install
chroot $__RootfsDir apt-get -y install $__UbuntuPackages
chroot $__RootfsDir symlinks -cr /usr
if [ $__SkipUnmount = = 0 ] ; then
umount $__RootfsDir /*
fi
2020-03-31 13:04:58 +00:00
if [ [ " $__BuildArch " = = "arm" && " $__CodeName " = = "trusty" ] ] ; then
2018-11-08 01:51:56 +00:00
pushd $__RootfsDir
patch -p1 < $__CrossDir /$__BuildArch /trusty.patch
patch -p1 < $__CrossDir /$__BuildArch /trusty-lttng-2.4.patch
popd
fi
elif [ " $__Tizen " = = "tizen" ] ; then
ROOTFS_DIR = $__RootfsDir $__CrossDir /$__BuildArch /tizen-build-rootfs.sh
else
echo "Unsupported target platform."
usage;
exit 1
fi