From c6c7cc7c1f6d6ab8fcf53edb167de00d496d5bdf Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Sun, 28 Oct 2012 18:18:04 +0100 Subject: [PATCH] Initial support for setting up cross-build chroots. --- mk-sbuild | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/mk-sbuild b/mk-sbuild index 82b5b85..ba87e6d 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -6,6 +6,7 @@ # Emmet Hikory # Scott Moser # Stefano Rivera +# Steve Langasek # # ################################################################## # @@ -57,6 +58,7 @@ function usage() echo " --distro=DISTRO Install specific distro:" echo " 'ubuntu' or 'debian' " echo " (defaults to determining from release name)" + echo " --target=ARCH Target architecture for cross-building" echo " --type=SCHROOT_TYPE Define the schroot type:" echo " 'directory'(default), 'file', or 'btrfs-snapshot'" echo " 'lvm-snapshot' is selected via --vg" @@ -86,7 +88,7 @@ function usage() if [ -z "$1" ]; then usage fi -OPTS=`getopt -o 'h' --long "help,debug,skip-updates,eatmydata,arch:,name:,source-template:,debootstrap-mirror:,debootstrap-include:,debootstrap-exclude:,debootstrap-proxy:,personality:,distro:,vg:,type:" -- "$@"` +OPTS=`getopt -o 'h' --long "help,debug,skip-updates,eatmydata,arch:,name:,source-template:,debootstrap-mirror:,debootstrap-include:,debootstrap-exclude:,debootstrap-proxy:,personality:,distro:,vg:,type:,target:" -- "$@"` eval set -- "$OPTS" VG="" @@ -161,6 +163,10 @@ while :; do SCHROOT_TYPE="$2" shift 2 ;; + --target) + TARGET_ARCH="$2" + shift 2 + ;; --) shift break @@ -440,6 +446,20 @@ ubuntu) ;; esac fi + if [ -n "$TARGET_ARCH" ]; then + # target chroots only supported in precise and later, so ignore + # the fact that powerpc was once not on ports. + case "$TARGET_ARCH" in + amd64 | i386) + TARGET_MIRROR="http://archive.ubuntu.com/ubuntu" + TARGET_SOURCES_SECURITY_URL="http://security.ubuntu.com/ubuntu" + ;; + armhf | armel | hppa | ia64 | lpia | powerpc | sparc) + TARGET_MIRROR="http://ports.ubuntu.com/ubuntu-ports" + TARGET_SOURCES_SECURITY_URL="http://ports.ubuntu.com/ubuntu-ports" + ;; + esac + fi # Add edgy+ buildd tools if [ "$RELEASE" != "breezy" ] && [ "$RELEASE" != "dapper" ]; then # Disable recommends for a smaller chroot (gutsy and later only) @@ -463,6 +483,10 @@ debian) if [ -z "$SOURCES_SECURITY_URL" ]; then SOURCES_SECURITY_URL="http://security.debian.org/" fi + if [ -n "$TARGET_ARCH" ]; then + TARGET_MIRROR="$DEBOOTSTRAP_MIRROR" + TARGET_SOURCES_SECURITY_URL="$SOURCES_SECURITY_URL" + fi # Unstable (aka "sid") does not have a security repository if [ "$RELEASE" = 'unstable' ] || [ "$RELEASE" = 'sid' ]; then SKIP_SECURITY=1 @@ -476,6 +500,18 @@ debian) ;; esac +if [ -n "$TARGET_ARCH" ]; then + # Ultimately we would like there to be a "cross-build-essential-$arch" + # package. In practice, the cross-g++ package is sufficient to pull in + # everything we need. + if ! target_tuple=$(dpkg-architecture -a"$TARGET_ARCH" -qDEB_HOST_GNU_TYPE) + then + echo "Unknown target architecture $TARGET_ARCH" >&2 + exit 1 + fi + BUILD_PKGS="$BUILD_PKGS g++-$target_tuple libc-dev:$TARGET_ARCH" +fi + debootstrap_opts="--components=$(echo $COMPONENTS | tr ' ' ,)" if [ -n "$DEBOOTSTRAP_INCLUDE" ] ; then debootstrap_opts="$debootstrap_opts --include=$DEBOOTSTRAP_INCLUDE" @@ -565,30 +601,53 @@ TEMP_SOURCES=`mktemp -t sources-XXXXXX` if [ -z "$TEMPLATE_SOURCES" ]; then TEMPLATE_SOURCES=~/.mk-sbuild.sources fi +if [ -n "$TARGET_ARCH" ]; then + MIRROR_ARCHS="[arch=$CHROOT_ARCH] " +fi if [ -r "$TEMPLATE_SOURCES" ]; then cat "$TEMPLATE_SOURCES" > "$TEMP_SOURCES" else cat > "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> "$TEMP_SOURCES" <> $MNT/finish.sh" <> $MNT/finish.sh" <