2017-04-10 11:41:01 +00:00
#!/usr/bin/env bash
usage( )
{
2018-01-29 19:03:06 +00:00
echo " Usage: $0 [BuildArch] [LinuxCodeName] [cross] "
echo "BuildArch can be: arm(default), armel, arm64, x86"
echo "LinuxCodeName - optional, Code name for Linux, can be: trusty(default), vivid, wily, jessie, xenial. If BuildArch is armel, LinuxCodeName is jessie(default) or tizen."
echo "cross - optional, it initializes rootfs for cross building, works only for armel tizen now"
2017-04-10 11:41:01 +00:00
exit 1
}
2018-01-29 19:03:06 +00:00
__LinuxCodeName = trusty
2017-04-10 11:41:01 +00:00
__CrossDir = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
__InitialDir = $PWD
__BuildArch = arm
__UbuntuArch = armhf
__UbuntuRepo = "http://ports.ubuntu.com/"
__UbuntuPackages = "build-essential lldb-3.6-dev libunwind8-dev gettext symlinks liblttng-ust-dev libicu-dev"
2017-06-07 13:16:24 +00:00
__LLDB_Package = "lldb-3.6-dev"
2017-04-10 11:41:01 +00:00
__MachineTriple = arm-linux-gnueabihf
__UnprocessedBuildArgs =
2017-06-07 13:16:24 +00:00
__SkipUnmount = 0
2017-04-10 11:41:01 +00:00
for i in " $@ "
do
lowerI = " $( echo $i | awk '{print tolower($0)}' ) "
case $lowerI in
-?| -h| --help)
usage
exit 1
; ;
arm)
__BuildArch = arm
__UbuntuArch = armhf
; ;
arm64)
__BuildArch = arm64
__UbuntuArch = arm64
__UbuntuPackages = "build-essential libunwind8-dev gettext symlinks liblttng-ust-dev libicu-dev"
__MachineTriple = aarch64-linux-gnu
; ;
2017-06-07 13:16:24 +00:00
armel)
__BuildArch = armel
__UbuntuArch = armel
__UbuntuRepo = "http://ftp.debian.org/debian/"
__LinuxCodeName = jessie
; ;
2018-01-29 19:03:06 +00:00
x86)
__BuildArch = x86
__UbuntuArch = i386
__UbuntuRepo = "http://archive.ubuntu.com/ubuntu/"
; ;
2017-06-07 13:16:24 +00:00
lldb3.6)
__LLDB_Package = "lldb-3.6-dev"
; ;
lldb3.8)
__LLDB_Package = "lldb-3.8-dev"
; ;
vivid)
if [ " $__LinuxCodeName " != "jessie" ] ; then
__LinuxCodeName = vivid
fi
; ;
wily)
if [ " $__LinuxCodeName " != "jessie" ] ; then
__LinuxCodeName = wily
fi
; ;
xenial)
if [ " $__LinuxCodeName " != "jessie" ] ; then
__LinuxCodeName = xenial
fi
; ;
jessie)
__LinuxCodeName = jessie
__UbuntuRepo = "http://ftp.debian.org/debian/"
; ;
tizen)
if [ " $__BuildArch " != "armel" ] ; then
echo "Tizen is available only for armel."
usage;
exit 1;
fi
__LinuxCodeName =
__UbuntuRepo =
__Tizen = tizen
; ;
2018-01-29 19:03:06 +00:00
cross)
if [ " $__Tizen " != "tizen" ] ; then
echo "Cross building rootfs is available only for armel tizen."
usage;
exit 1;
fi
# Cross building is available for armel tizen only with x86 rootfs
echo Building x86 xenial rootfs for armel tizen cross build...
$0 x86 xenial
echo Building armel rootfs...
; ;
2017-06-07 13:16:24 +00:00
--skipunmount)
__SkipUnmount = 1
; ;
2017-04-10 11:41:01 +00:00
*)
__UnprocessedBuildArgs = " $__UnprocessedBuildArgs $i "
esac
done
2017-06-07 13:16:24 +00:00
if [ " $__BuildArch " = = "armel" ] ; then
__LLDB_Package = "lldb-3.5-dev"
fi
2017-04-10 11:41:01 +00:00
__RootfsDir = " $__CrossDir /rootfs/ $__BuildArch "
2018-01-29 19:03:06 +00:00
__UbuntuPackages += " ${ __LLDB_Package :- } "
2017-06-07 13:16:24 +00:00
2017-04-10 11:41:01 +00:00
if [ [ -n " $ROOTFS_DIR " ] ] ; then
__RootfsDir = $ROOTFS_DIR
fi
2017-06-07 13:16:24 +00:00
if [ -d " $__RootfsDir " ] ; then
if [ $__SkipUnmount = = 0 ] ; then
umount $__RootfsDir /*
fi
rm -rf $__RootfsDir
fi
2018-01-29 19:03:06 +00:00
if [ [ -n $__LinuxCodeName ] ] ; then
qemu-debootstrap --arch $__UbuntuArch $__LinuxCodeName $__RootfsDir $__UbuntuRepo
cp $__CrossDir /$__BuildArch /sources.list.$__LinuxCodeName $__RootfsDir /etc/apt/sources.list
2017-06-07 13:16:24 +00:00
chroot $__RootfsDir apt-get update
2018-01-29 19:03:06 +00:00
chroot $__RootfsDir apt-get -f -y install
2017-06-07 13:16:24 +00:00
chroot $__RootfsDir apt-get -y install $__UbuntuPackages
chroot $__RootfsDir symlinks -cr /usr
if [ $__SkipUnmount = = 0 ] ; then
umount $__RootfsDir /*
fi
2018-01-29 19:03:06 +00:00
elif [ " $__Tizen " = = "tizen" ] ; then
ROOTFS_DIR = $__RootfsDir $__CrossDir /$__BuildArch /tizen-build-rootfs.sh
else
echo "Unsupported target platform."
usage;
exit 1
2017-06-07 13:16:24 +00:00
fi