aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/binutils/APKBUILD1
-rw-r--r--main/gcc/APKBUILD59
-rw-r--r--main/musl/APKBUILD59
-rwxr-xr-xscripts/bootstrap.sh164
4 files changed, 128 insertions, 155 deletions
diff --git a/main/binutils/APKBUILD b/main/binutils/APKBUILD
index 8bacc931c2..09ea0962d6 100644
--- a/main/binutils/APKBUILD
+++ b/main/binutils/APKBUILD
@@ -5,6 +5,7 @@ pkgrel=1
pkgdesc="Tools necessary to build programs"
url="http://www.gnu.org/software/binutils/"
depends=""
+options="toolchain"
makedepends_build="bison flex texinfo"
makedepends_host="zlib-dev"
makedepends="$makedepends_build $makedepends_host"
diff --git a/main/gcc/APKBUILD b/main/gcc/APKBUILD
index 32b7fd2c9b..70610f0f47 100644
--- a/main/gcc/APKBUILD
+++ b/main/gcc/APKBUILD
@@ -2,24 +2,23 @@
pkgname=gcc
pkgver=6.3.0
_pkgbase=6.3.0
-_cross=""
-[ "$BOOTSTRAP" = "noheaders" ] && pkgname="gcc-pass1"
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
-[ "$CHOST" != "$CTARGET" ] && _cross="-$CTARGET_ARCH"
+[ "$CBUILD" != "$CHOST" ] && _cross="-$CARCH" || _cross=""
+[ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target=""
-pkgname="$pkgname$_cross"
+pkgname="$pkgname$_target"
pkgrel=1
pkgdesc="The GNU Compiler Collection"
url="http://gcc.gnu.org"
arch="all"
license="GPL LGPL"
_gccrel=$pkgver-r$pkgrel
-depends="binutils$_cross isl"
-makedepends_build="paxmark bison flex texinfo gawk zip gmp-dev mpfr-dev mpc1-dev zlib-dev"
+options="toolchain"
+depends="binutils$_target isl"
+makedepends_build="gcc$_cross g++$_cross paxmark bison flex texinfo gawk zip gmp-dev mpfr-dev mpc1-dev zlib-dev"
makedepends_host="linux-headers gmp-dev mpfr-dev mpc1-dev isl-dev zlib-dev !gettext-dev"
-makedepends="$makedepends_build $makedepends_host"
subpackages=" "
-[ "$CHOST" = "$CTARGET" ] && subpackages="gcc-doc$_cross"
+[ "$CHOST" = "$CTARGET" ] && subpackages="gcc-doc$_target"
replaces="libstdc++ binutils"
: ${LANG_CXX:=true}
@@ -127,30 +126,31 @@ fi
_languages=c
if $LANG_CXX; then
- subpackages="$subpackages libstdc++:libcxx:$CTARGET_ARCH g++$_cross:gpp"
+ subpackages="$subpackages libstdc++:libcxx:$CTARGET_ARCH g++$_target:gpp"
_languages="$_languages,c++"
fi
if $LANG_OBJC; then
- subpackages="$subpackages libobjc::$CTARGET_ARCH gcc-objc$_cross:objc"
+ subpackages="$subpackages libobjc::$CTARGET_ARCH gcc-objc$_target:objc"
_languages="$_languages,objc"
fi
if $LANG_JAVA; then
- subpackages="$subpackages libgcj::$CTARGET_ARCH gcc-java$_cross:java"
+ subpackages="$subpackages libgcj::$CTARGET_ARCH gcc-java$_target:java"
_languages="$_languages,java"
fi
if $LANG_GO; then
- subpackages="$subpackages libgo::$CTARGET_ARCH gcc-go$_cross:go"
+ subpackages="$subpackages libgo::$CTARGET_ARCH gcc-go$_target:go"
_languages="$_languages,go"
fi
if $LANG_FORTRAN; then
- subpackages="$subpackages libgfortran::$CTARGET_ARCH gfortran$_cross:gfortran"
+ subpackages="$subpackages libgfortran::$CTARGET_ARCH gfortran$_target:gfortran"
_languages="$_languages,fortran"
fi
if $LANG_ADA; then
- subpackages="$subpackages libgnat::$CTARGET_ARCH gcc-gnat$_cross:gnat"
+ subpackages="$subpackages libgnat::$CTARGET_ARCH gcc-gnat$_target:gnat"
_languages="$_languages,ada"
- makedepends="$makedepends gcc-gnat"
+ makedepends_build="$makedepends_build gcc-gnat$_cross"
fi
+makedepends="$makedepends_build $makedepends_host"
source="ftp://gcc.gnu.org/pub/gcc/releases/gcc-${_pkgbase:-$pkgver}/gcc-${_pkgbase:-$pkgver}.tar.bz2
ftp://sourceware.org/pub/java/ecj-4.9.jar
@@ -266,15 +266,8 @@ build() {
[ "$CHOST" != "$CTARGET" ] && _cross_configure="--disable-bootstrap --with-sysroot=$CBUILDROOT"
case "$BOOTSTRAP" in
- noheaders)
- _bootstrap_configure="--with-newlib --without-headers --disable-shared --enable-threads=no"
- ;;
- nolibc)
- _bootstrap_configure="--with-newlib --disable-shared --enable-threads=no"
- ;;
- *)
- _bootstrap_configure="--enable-shared --enable-threads --enable-tls"
- ;;
+ nolibc) _bootstrap_configure="--with-newlib --disable-shared --enable-threads=no" ;;
+ *) _bootstrap_configure="--enable-shared --enable-threads --enable-tls" ;;
esac
$LIBGOMP || _bootstrap_configure="$_bootstrap_configure --disable-libgomp"
@@ -405,7 +398,7 @@ libatomic() {
replaces="gcc"
mkdir -p "$subpkgdir"/usr/lib
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}lib/libatomic.so.* "$subpkgdir"/usr/lib/ || \
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libatomic.so.* "$subpkgdir"/usr/lib/ || \
return 1
}
@@ -414,7 +407,7 @@ libcxx() {
depends=
mkdir -p "$subpkgdir"/usr/lib
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}lib/libstdc++.so.* "$subpkgdir"/usr/lib/ || \
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libstdc++.so.* "$subpkgdir"/usr/lib/ || \
return 1
}
@@ -423,14 +416,14 @@ gpp() {
depends="libstdc++=$_gccrel gcc=$_gccrel libc-dev"
mkdir -p "$subpkgdir/$_gcclibexec" \
"$subpkgdir"/usr/bin \
- "$subpkgdir"/usr/${_cross:+$CTARGET/}include \
- "$subpkgdir"/usr/${_cross:+$CTARGET/}lib \
+ "$subpkgdir"/usr/${_target:+$CTARGET/}include \
+ "$subpkgdir"/usr/${_target:+$CTARGET/}lib \
mv "$pkgdir/$_gcclibexec/cc1plus" "$subpkgdir/$_gcclibexec/"
paxmark -pmrs "$subpkgdir/$_gcclibexec/cc1plus" || return 1
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}lib/*++* "$subpkgdir"/usr/${_cross:+$CTARGET/}lib/ || return 1
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}include/c++ "$subpkgdir"/usr/${_cross:+$CTARGET/}include/ || return 1
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/*++* "$subpkgdir"/usr/${_target:+$CTARGET/}lib/ || return 1
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}include/c++ "$subpkgdir"/usr/${_target:+$CTARGET/}include/ || return 1
mv "$pkgdir"/usr/bin/*++ "$subpkgdir"/usr/bin/ || return 1
}
@@ -439,7 +432,7 @@ libobjc() {
replaces="objc"
depends=
mkdir -p "$subpkgdir"/usr/lib
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}lib/libobjc.so.* "$subpkgdir"/usr/lib/
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libobjc.so.* "$subpkgdir"/usr/lib/
}
objc() {
@@ -461,7 +454,7 @@ libgcc() {
depends=
mkdir -p "$subpkgdir"/usr/lib
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}lib/libgcc_s.so.* "$subpkgdir"/usr/lib/ || \
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libgcc_s.so.* "$subpkgdir"/usr/lib/ || \
return 1
}
@@ -471,7 +464,7 @@ libgomp() {
replaces="gcc"
mkdir -p "$subpkgdir"/usr/lib
- mv "$pkgdir"/usr/${_cross:+$CTARGET/}lib/libgomp.so.* "$subpkgdir"/usr/lib/
+ mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libgomp.so.* "$subpkgdir"/usr/lib/
}
java() {
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
index d44e05ef2c..81d951ba12 100644
--- a/main/musl/APKBUILD
+++ b/main/musl/APKBUILD
@@ -9,9 +9,14 @@ arch="all"
license="MIT"
depends=""
depends_dev="!uclibc-dev"
+options="toolchain"
makedepends="$depends_dev"
subpackages="$pkgname-dev $pkgname-dbg libc6-compat:compat:noarch"
-[ "$BOOTSTRAP" != "nolibc" ] && subpackages="$subpackages $pkgname-utils"
+case "$BOOTSTRAP" in
+nocc) pkgname="musl-dev"; subpackages="";;
+nolibc) ;;
+*) subpackages="$subpackages $pkgname-utils";;
+esac
source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
0001-fix-strftime-y-for-negative-years.patch
0002-make-globfree-safe-after-failed-glob-from-over-lengt.patch
@@ -33,24 +38,11 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
builddir="$srcdir"/musl-$pkgver
-install_sysroot_headers() {
- cd "$builddir"
- [ -z "${CBUILDROOT}" ] && die "CBUILDROOT not set"
- case "$CARCH" in
- aarch64*) ARCH="aarch64" ;;
- arm*) ARCH="arm" ;;
- x86) ARCH="i386" ;;
- x86_64) ARCH="x86_64" ;;
- ppc) ARCH="powerpc" ;;
- ppc64*) ARCH="powerpc64" ;;
- mips*) ARCH="mips" ;;
- esac
- make ARCH="$ARCH" prefix=/usr DESTDIR="${CBUILDROOT}" install-headers || return 1
-}
-
build() {
cd "$builddir"
+ [ "$BOOTSTRAP" == "nocc" ] && return 0
+
# provide minimal libssp_nonshared.a so we don't need libssp from gcc
${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS -c "$srcdir"/__stack_chk_fail_local.c -o __stack_chk_fail_local.o || return 1
${CROSS_COMPILE}ar r libssp_nonshared.a __stack_chk_fail_local.o || return 1
@@ -79,17 +71,32 @@ build() {
package() {
cd "$builddir"
- make DESTDIR="$pkgdir" install || return 1
- cp libssp_nonshared.a "$pkgdir"/usr/lib || return 1
-
- # make LDSO the be the real file, and libc the symlink
- local LDSO=$(make -f Makefile --eval "$(echo -e 'print-ldso:\n\t@echo $$(basename $(LDSO_PATHNAME))')" print-ldso)
- mv -f "$pkgdir"/usr/lib/libc.so "$pkgdir"/lib/"$LDSO" || return 1
- ln -sf "$LDSO" "$pkgdir"/lib/libc.musl-${CARCH}.so.1 || return 1
- ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/lib/libc.so || return 1
- mkdir -p "$pkgdir"/usr/bin || return 1
- ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/bin/ldd || return 1
+ if [ "$BOOTSTRAP" == "nocc" ]; then
+ case "$CARCH" in
+ aarch64*) ARCH="aarch64" ;;
+ arm*) ARCH="arm" ;;
+ x86) ARCH="i386" ;;
+ x86_64) ARCH="x86_64" ;;
+ ppc) ARCH="powerpc" ;;
+ ppc64*) ARCH="powerpc64" ;;
+ mips*) ARCH="mips" ;;
+ esac
+
+ make ARCH="$ARCH" prefix=/usr DESTDIR="$pkgdir" install-headers || return 1
+ else
+ make DESTDIR="$pkgdir" install || return 1
+
+ cp libssp_nonshared.a "$pkgdir"/usr/lib || return 1
+
+ # make LDSO the be the real file, and libc the symlink
+ local LDSO=$(make -f Makefile --eval "$(echo -e 'print-ldso:\n\t@echo $$(basename $(LDSO_PATHNAME))')" print-ldso)
+ mv -f "$pkgdir"/usr/lib/libc.so "$pkgdir"/lib/"$LDSO" || return 1
+ ln -sf "$LDSO" "$pkgdir"/lib/libc.musl-${CARCH}.so.1 || return 1
+ ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/lib/libc.so || return 1
+ mkdir -p "$pkgdir"/usr/bin || return 1
+ ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/bin/ldd || return 1
+ fi
# remove libintl.h, currently we don't want by default any NLS
# and use GNU gettext where needed. the plan is to migrate to
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