Skip to content

Instantly share code, notes, and snippets.

@lool
Last active September 16, 2017 23:12
Show Gist options
  • Save lool/342a90368ef636bb923aa084a9cdf6d3 to your computer and use it in GitHub Desktop.
Save lool/342a90368ef636bb923aa084a9cdf6d3 to your computer and use it in GitHub Desktop.
Cross-toolchain build scripts (from hudson.d.o)
#!/bin/sh
set -e
set -x
self="$(basename "$0")"
architecture="$1"
if [ -z "$architecture" ]; then
echo "Usage: $self <architecture>" >&2
exit 1
fi
sudo apt-get -y build-dep gdb
GDB_TARGET="$architecture" apt-get source -b gdb
#!/bin/sh
set -e
set -x
self="$(basename "$0")"
config_url="$1"
if [ -z "$config_url" ]; then
echo "Usage: $self <config-url>" >&2
exit 1
fi
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- mrproper
wget -O .config "$config_url"
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- oldconfig zImage uImage
#!/bin/sh
set -e
set -x
make distclean
./configure --target-list=arm-softmmu --static
make
#!/bin/sh
set -e
set -x
self="$(basename "$0")"
board="$1"
if [ -z "$board" ]; then
echo "Usage: $self <board-name>" >&2
exit 1
fi
make CROSS_COMPILE=arm-linux-gnueabi- mrproper "${board}_config"
make CROSS_COMPILE=arm-linux-gnueabi- all
#!/bin/sh
set -e
self="$(basename "$0")"
die() {
local format="$1"
shift
printf -- "$format\n" "$@" >&2
exit 1
}
dist="$1"
project="$2"
if [ -z "$dist" ] || [ -z "$project" ] || [ $# -gt 2 ]; then
die "Usage: $self <dist> <project>"
fi
dist_re='^[.0-9a-z-]+$'
if ! egrep -q "$dist_re"; then
die "Dist name should match '%s'" "$dist_re"
fi <<EOF
$dist
EOF
project_re='^[a-z-]+$'
if ! egrep -q "$project_re"; then
die "Project name should match '%s'" "$project_re"
fi <<EOF
$project
EOF
url="http://snapshots.linaro.org/$dist/$project"
date=$(lftp -c "open $url/; cd /; cd $url/; cls" |
grep '^[0-9]\+/$' |
sort |
sed -n '$ s#/$##p')
if [ -z "$date" ]; then
die "No snapshot found at %s" "$url"
fi
url_date="$url/$date"
build=$(lftp -c "open $url_date/; cd /; cd $url_date/; cls" |
grep '^[0-9]\+/$' |
sort |
sed -n '$ s#/$##p')
if [ -z "$build" ]; then
die "No build found at %s" "$url_date"
fi
image_url="$url_date/$build/images/tar"
tarball=$(lftp -c "open $image_url/; cd /; cd $image_url/; cls *.tar.gz" |
grep '^[0-9a-z-]\+\.tar\.gz$' |
sort |
tail -1)
if [ -z "$tarball" ]; then
die "No tarball found at %s" "$image_url"
fi
cat <<EOF
$image_url/$tarball
EOF
#!/bin/sh
set -e
self="$(basename "$0")"
current_user="$(id -un)"
host_arch="$(dpkg --print-architecture)"
# dist to use, this is used with arch to find a suitable chroot; defaults to
# development version of Ubuntu
dist="natty"
# packages to purge from the chroot
purge_pkgs=""
# packages to install in the chroot
install_pkgs=""
# whether to start from a fresh chroot every time or to reuse the same one;
# needs session_name to name the chroot
reuse="no"
# preferred name of the session in the chroot; there can only be one session
# with this name at the same time
session_name=""
# actual name of the session in the chroot
name=""
# whether to setup password-less sudo
sudo="no"
# architecture of the chroot
arch="$host_arch"
usage() {
echo "Usage: $self [--dist <dist>] [--purge-pkg <package>] [--install-pkg <package>] [--reuse] [--session-name <session name>] [--sudo] [--arch <arch>] <command> <arg...>"
}
while [ $# -gt 0 ]; do
case "$1" in
--help)
usage
exit 0
;;
--dist)
if [ -z "$2" ]; then
echo "Need distribution argument after --dist" >&2
usage >&2
exit 1
fi
dist="$2"
shift 2
;;
--purge-pkg)
if [ -z "$2" ]; then
echo "Need package argument after --purge-pkg" >&2
usage >&2
exit 1
fi
purge_pkgs="${purge_pkgs:+$purge_pkgs }$2"
shift 2
;;
--install-pkg)
if [ -z "$2" ]; then
echo "Need package argument after --install-pkg" >&2
usage >&2
exit 1
fi
install_pkgs="${install_pkgs:+$install_pkgs }$2"
shift 2
;;
--reuse)
reuse="yes"
shift
;;
--session-name)
if [ -z "$2" ]; then
echo "Need session name argument after --session-name" >&2
usage >&2
exit 1
fi
session_name="$2"
shift 2
;;
--sudo)
sudo="yes"
shift
;;
--arch)
if [ -z "$2" ]; then
echo "Need architecture argument after --arch" >&2
usage >&2
exit 1
fi
arch="$2"
shift 2
;;
--*)
echo "Unknown flag $1" >&2
usage >&2
exit 1
;;
*)
break
;;
esac
done
if [ "$reuse" = "yes" ] && [ -z "$session_name" ]; then
echo "A session name (--session-name) is required in reuse mode (--reuse)." >&2
exit 1
fi
# needed as long as schroot is configured with preserve-environment=true
export LC_ALL=C
cleanup() {
if [ "$reuse" = "yes" ]; then
return 0
fi
if [ -n "$name" ]; then
schroot -c "$name" -e
fi
}
trap "cleanup" EXIT HUP INT QUIT KILL PIPE TERM
chroot="$dist"
if [ "$arch" != "$host_arch" ]; then
chroot="$dist-$arch"
fi
if [ "$reuse" = "yes" ]; then
name="$session_name"
if schroot -l --all-sessions | grep -Fxq -- "session:$name"; then
schroot -c "$session_name" --recover-session
else
schroot -c "$chroot" --session-name "$name" -b
fi
else
name="$(schroot -c "$chroot" ${session_name:+--session-name "$session_name"} -b)"
fi
do_schroot() {
schroot -c "$name" -r -- "$@"
}
do_schroot_root() {
schroot -c "$name" -r -u root -- "$@"
}
do_schroot_apt_get() {
DEBIAN_FRONTEND=noninteractive do_schroot_root apt-get -y -o Dpkg::Options::=--force-confold "$@"
}
# XXX should this be part of the schroot setup?
# add deb-src stanzas to sources.list
if ! do_schroot grep -q '^deb-src[[:space:]]' /etc/apt/sources.list; then
do_schroot_root sed -i '/^deb[[:space:]]/ { p; s/deb/deb-src/ }' /etc/apt/sources.list
fi
# TODO
# - add support for setting components
do_schroot_apt_get update
if [ -n "$purge_pkgs" ]; then
do_schroot_apt_get purge $purge_pkgs
fi
if [ -n "$install_pkgs" ]; then
# XXX --no-install-recommends?
do_schroot_apt_get install $install_pkgs
fi
if [ "$sudo" = yes ]; then
do_schroot_apt_get install sudo
sudoers_line="$current_user ALL=(ALL) NOPASSWD: ALL"
if ! do_schroot_root grep -Fxq -- "$sudoers_line" /etc/sudoers 2>/dev/null; then
do_schroot_root tee -a /etc/sudoers >/dev/null <<EOF
$sudoers_line
EOF
fi
fi
do_schroot_apt_get dist-upgrade
do_schroot_apt_get autoremove
do_schroot_apt_get clean
do_schroot "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment