aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2017-02-17 07:44:24 +0000
committerTimo Teräs <timo.teras@iki.fi>2017-02-17 08:22:03 +0000
commita95a079d7a562e73276448362141171bef668cab (patch)
tree810dd65e7772b76de91734556092be72843be003 /scripts
parent7b268e6114d17b132956ea45ae63976f184e5bc8 (diff)
downloadaports-a95a079d7a562e73276448362141171bef668cab.tar.bz2
aports-a95a079d7a562e73276448362141171bef668cab.tar.xz
scripts/bootstrap.sh, binutils, gcc, musl: improve bootstrap
- requires new abuild (from git until 2.30 is tagged) - properly build initial musl-dev before c-compiler is available - mark core aports with options=toolchain, and fix all makedepends - bootstrap.sh: reorganize and use set -e there - bootstrap.sh: use new EXTRADEPENDS_* to pull in implicit dependencies during bootstrap to simplify the script
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bootstrap.sh164
1 files changed, 68 insertions, 96 deletions
diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh
index b7e4f9cb7a..a9fd7547b9 100755
--- a/scripts/bootstrap.sh
+++ b/scripts/bootstrap.sh
@@ -1,5 +1,7 @@
#!/bin/sh
+set -e
+
TARGET_ARCH="$1"
SUDO_APK=abuild-apk
@@ -10,7 +12,8 @@ KERNEL_PKG="linux-firmware linux-vanilla"
[ -e /usr/share/abuild/functions.sh ] || (echo "abuild not found" ; exit 1)
CBUILDROOT="$(CTARGET=$TARGET_ARCH . /usr/share/abuild/functions.sh ; echo $CBUILDROOT)"
. /usr/share/abuild/functions.sh
-[ -z "$CBUILD_ARCH" ] && die "abuild is too old (use git snapshot from cross-build branch)"
+[ -z "$CBUILD_ARCH" ] && die "abuild is too old (use 2.29.0 or later)"
+[ -z "$CBUILDROOT" ] && die "CBUILDROOT not set for $TARGET_ARCH"
# deduce aports directory
[ -z "$APORTS" ] && APORTS=$(realpath $(dirname $0)/../)
@@ -27,100 +30,6 @@ msg() {
printf "${prompt} ${name}: %s\n" "$1" >&2
}
-setup_sysroot() {
- [ -e "$CBUILDROOT" ] && return 0
- msg "Creating sysroot in $CBUILDROOT"
- mkdir -p "$CBUILDROOT/etc/apk/keys"
- cp -a /etc/apk/keys/* "$CBUILDROOT/etc/apk/keys"
- ${SUDO_APK} add --quiet --initdb --arch $TARGET_ARCH --root $CBUILDROOT
-}
-
-create_cross_compiler() {
- msg "Building cross-compiler"
-
- # Prepare local build environment
- apk info --quiet --installed build-base gcc-gnat || ${SUDO_APK} add build-base gcc-gnat
-
- # Build and install cross binutils (--with-sysroot)
- CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname binutils) abuild up2date >& /dev/null
- if [ $? -ne 0 ]; then
- CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname binutils) abuild -r || return 1
- ${SUDO_APK} add --repository "$REPODEST/main" binutils-$TARGET_ARCH || return 1
- fi
-
- # Build and install cross GCC
- CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname gcc) abuild up2date >& /dev/null
- if [ $? -ne 0 ]; then
- # Build bootstrap C-library for target if needed
- CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild up2date >& /dev/null
- if [ $? -ne 0 ]; then
- # musl does not need GCC for headers installation, skipped step.
- # CTARGET=$TARGET_ARCH BOOTSTRAP=noheaders abuild
-
- # Hack: Install C-library headers for target sysroot
- CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild clean unpack prepare install_sysroot_headers || return 1
-
- # Build minimal cross GCC (--with-newlib --enable-threads=no --disable-bootstrap)
- CTARGET=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname gcc) abuild -r || return 1
-
- # Cross build bootstrap C-library for the target
- ${SUDO_APK} --quiet del gcc-$TARGET_ARCH g++-$TARGET_ARCH gcc-gnat-$TARGET_ARCH
- ${SUDO_APK} add --repository "$REPODEST/main" gcc-pass2-$TARGET_ARCH || return 1
- CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild -r || return 1
- ${SUDO_APK} --quiet del gcc-pass2-$TARGET_ARCH
- fi
-
- # Build cross GCC
- apk info --quiet --installed --root "$CBUILDROOT" musl-dev || \
- ${SUDO_APK} --root "$CBUILDROOT" add --repository "$REPODEST/main" musl-dev \
- || return 1
- CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname gcc) abuild -r || return 1
- ${SUDO_APK} add --repository "$REPODEST/main" gcc-gnat gcc-$TARGET_ARCH g++-$TARGET_ARCH gcc-gnat-$TARGET_ARCH \
- || return 1
- fi
-}
-
-cross_compile_base() {
- msg "Cross building base system"
-
- # remove possible old pass2 gcc, and add implicit host prerequisite packages
- apk info --quiet --installed gcc-pass2-$TARGET_ARCH && ${SUDO_APK} del gcc-pass2-$TARGET_ARCH
- apk info --quiet --installed gcc-gnat gcc-$TARGET_ARCH g++-$TARGET_ARCH gcc-gnat-$TARGET_ARCH || \
- ${SUDO_APK} add --repository "$REPODEST/main" gcc-gnat gcc-$TARGET_ARCH g++-$TARGET_ARCH gcc-gnat-$TARGET_ARCH \
- || return 1
- apk info --quiet --installed --root "$CBUILDROOT" libgcc libstdc++ musl-dev || \
- ${SUDO_APK} --root "$CBUILDROOT" add --repository "$REPODEST/main" libgcc libstdc++ musl-dev \
- || return 1
-
- # ordered cross-build
- for PKG in fortify-headers linux-headers musl libc-dev pkgconf zlib \
- busybox busybox-initscripts binutils make \
- libressl libfetch apk-tools \
- gmp mpfr3 mpc1 isl cloog gcc \
- openrc alpine-conf alpine-baselayout alpine-keys alpine-base build-base \
- attr libcap patch sudo acl fakeroot tar \
- pax-utils abuild openssh \
- ncurses util-linux lvm2 popt xz cryptsetup kmod lddtree mkinitfs \
- $KERNEL_PKG ; do
-
- CHOST=$TARGET_ARCH BOOTSTRAP=bootimage APKBUILD=$(apkbuildname $PKG) abuild -r || exit 1
-
- case "$PKG" in
- fortify-headers | libc-dev | build-base)
- # headers packages which are implicit but mandatory dependency
- apk info --quiet --installed --root "$CBUILDROOT" $PKG || \
- ${SUDO_APK} --update --root "$CBUILDROOT" --repository "$REPODEST/main" add $PKG \
- || return 1
- ;;
- musl | gcc)
- # target libraries rebuilt, force upgrade
- [ "$(apk upgrade --root "$CBUILDROOT" --repository "$REPODEST/main" --available --simulate | wc -l)" -gt 1 ] &&
- ${SUDO_APK} upgrade --root "$CBUILDROOT" --repository "$REPODEST/main" --available
- ;;
- esac
- done
-}
-
if [ -z "$TARGET_ARCH" ]; then
local program=$(basename $0)
cat <<EOF
@@ -144,4 +53,67 @@ EOF
return 1
fi
-setup_sysroot && create_cross_compiler && cross_compile_base
+if [ ! -d "$CBUILDROOT" ]; then
+ msg "Creating sysroot in $CBUILDROOT"
+ mkdir -p "$CBUILDROOT/etc/apk/keys"
+ cp -a /etc/apk/keys/* "$CBUILDROOT/etc/apk/keys"
+ ${SUDO_APK} add --quiet --initdb --arch $TARGET_ARCH --root $CBUILDROOT
+fi
+
+msg "Building cross-compiler"
+
+# Build and install cross binutils (--with-sysroot)
+CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname binutils) abuild -r
+
+if ! CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild up2date 2>/dev/null; then
+ # C-library headers for target
+ CHOST=$TARGET_ARCH BOOTSTRAP=nocc APKBUILD=$(apkbuildname musl) abuild -r
+
+ # Minimal cross GCC
+ EXTRADEPENDS_HOST="musl-dev" \
+ CTARGET=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname gcc) abuild -r
+
+ # Cross build bootstrap C-library for the target
+ EXTRADEPENDS_BUILD="gcc-pass2-$TARGET_ARCH" \
+ CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild -r
+fi
+
+# Full cross GCC
+EXTRADEPENDS_TARGET="musl musl-dev" \
+CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname gcc) abuild -r -k
+
+# Cross build-base
+CTARGET=$TARGET_ARCH APKBUILD=$(apkbuildname build-base) abuild -r
+
+msg "Cross building base system"
+
+# add implicit target prerequisite packages
+apk info --quiet --installed --root "$CBUILDROOT" libgcc libstdc++ musl-dev || \
+ ${SUDO_APK} --root "$CBUILDROOT" add --repository "$REPODEST/main" libgcc libstdc++ musl-dev
+
+# ordered cross-build
+for PKG in fortify-headers linux-headers musl libc-dev pkgconf zlib \
+ busybox busybox-initscripts binutils make \
+ libressl libfetch apk-tools \
+ gmp mpfr3 mpc1 isl cloog gcc \
+ openrc alpine-conf alpine-baselayout alpine-keys alpine-base build-base \
+ attr libcap patch sudo acl fakeroot tar \
+ pax-utils abuild openssh \
+ ncurses util-linux lvm2 popt xz cryptsetup kmod lddtree mkinitfs \
+ $KERNEL_PKG ; do
+
+ CHOST=$TARGET_ARCH BOOTSTRAP=bootimage APKBUILD=$(apkbuildname $PKG) abuild -r
+
+ case "$PKG" in
+ fortify-headers | libc-dev | build-base)
+ # headers packages which are implicit but mandatory dependency
+ apk info --quiet --installed --root "$CBUILDROOT" $PKG || \
+ ${SUDO_APK} --update --root "$CBUILDROOT" --repository "$REPODEST/main" add $PKG
+ ;;
+ musl | gcc)
+ # target libraries rebuilt, force upgrade
+ [ "$(apk upgrade --root "$CBUILDROOT" --repository "$REPODEST/main" --available --simulate | wc -l)" -gt 1 ] &&
+ ${SUDO_APK} upgrade --root "$CBUILDROOT" --repository "$REPODEST/main" --available
+ ;;
+ esac
+done