summaryrefslogtreecommitdiff
path: root/src/stage1
diff options
context:
space:
mode:
authorAndreas Grapentin <andreas@grapentin.org>2018-03-29 23:33:02 +0200
committerAndreas Grapentin <andreas@grapentin.org>2018-03-29 23:33:02 +0200
commitc1fced40c2f37f844eb810216eb0a1da1a436aa8 (patch)
tree205d4971dd3e2498d8c78b42ff1320f3603957e5 /src/stage1
parent0cdff36d43aea7dc5415e6a4d58d1e10c68e2965 (diff)
major restructure, builds ok up to end of stage2
Diffstat (limited to 'src/stage1')
-rw-r--r--src/stage1/makepkg.conf.in6
-rwxr-xr-xsrc/stage1/stage1.sh193
-rw-r--r--src/stage1/toolchain-pkgbuilds/gcc-bootstrap/0001-pthread-reentrant.patch.in11
-rw-r--r--src/stage1/toolchain-pkgbuilds/gcc-bootstrap/PKGBUILD.in38
-rw-r--r--src/stage1/toolchain-pkgbuilds/gcc/0001-pthread-reentrant.patch.in11
-rw-r--r--src/stage1/toolchain-pkgbuilds/gcc/PKGBUILD.in48
6 files changed, 159 insertions, 148 deletions
diff --git a/src/stage1/makepkg.conf.in b/src/stage1/makepkg.conf.in
index ca3a250..270774b 100644
--- a/src/stage1/makepkg.conf.in
+++ b/src/stage1/makepkg.conf.in
@@ -10,6 +10,12 @@ VCSCLIENTS=('bzr::bzr'
BUILDENV=(!distcc color !ccache check !sign)
OPTIONS=(strip docs !libtool !staticlibs emptydirs zipman purge !optipng !upx !debug)
INTEGRITY_CHECK=(md5)
+CARCH="x86_64"
+CHOST="x86_64-pc-linux-gnu"
+CPPFLAGS="-D_FORTIFY_SOURCE=2"
+CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"
+CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"
+LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
STRIP_BINARIES="--strip-all"
STRIP_SHARED="--strip-unneeded"
STRIP_STATIC="--strip-debug"
diff --git a/src/stage1/stage1.sh b/src/stage1/stage1.sh
index a1d2ee4..0715724 100755
--- a/src/stage1/stage1.sh
+++ b/src/stage1/stage1.sh
@@ -18,119 +18,106 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
##############################################################################
-set -euo pipefail
-
-msg "Entering Stage 1"
-notify "*Bootstrap Entering Stage 1*"
-
-# set a bunch of convenience variables
-_builddir="$topbuilddir"/stage1
-_srcdir="$topsrcdir"/stage1
-_pkgdest="$_builddir"/packages
-_logdest="$_builddir"/makepkglogs
-_makepkgdir="$_builddir"
-
-function check_toolchain() {
+check_cross_toolchain() {
echo -n "checking for $CHOST binutils ... "
- local _have_binutils
- type -p $CHOST-ar >/dev/null && _have_binutils=yes || _have_binutils=no
- echo $_have_binutils
- [ "x$_have_binutils" == "xyes" ] || return 1
+ local have_binutils=yes
+ type -p "$CHOST-ar" >/dev/null || have_binutils=no
+ echo $have_binutils
+ [ "x$have_binutils" == "xyes" ] || return 1
echo -n "checking for $CHOST gcc ... "
- local _have_gcc
- type -p $CHOST-g++ >/dev/null && _have_gcc=yes || _have_gcc=no
- echo $_have_gcc
- [ "x$_have_gcc" == "xyes" ] || return 1
+ local have_gcc=yes
+ type -p "$CHOST-g++" >/dev/null || have_gcc=no
+ echo $have_gcc
+ [ "x$have_gcc" == "xyes" ] || return 1
- local _sysroot=$($CHOST-gcc --print-sysroot)
+ local sysroot
+ sysroot=$("$CHOST-gcc" --print-sysroot) || die "failed to produce $CHOST-gcc sysroot"
echo -n "checking for $CHOST linux api headers ... "
- local _have_headers
- [ -e "$_sysroot"/include/linux/kernel.h ] && _have_headers=yes || _have_headers=no
- echo $_have_headers
- [ "x$_have_headers" == "xyes" ] || return 1
+ local have_headers=yes
+ [ -e "$sysroot"/include/linux/kernel.h ] || have_headers=no
+ echo $have_headers
+ [ "x$have_headers" == "xyes" ] || return 1
echo -n "checking for $CHOST glibc ... "
- local _have_glibc
- [ -e "$_sysroot"/usr/lib/libc.so.6 ] && _have_glibc=yes || _have_glibc=no
- echo $_have_glibc
- [ "x$_have_glibc" == "xyes" ] || return 1
+ local have_glibc=yes
+ [ -e "$sysroot"/usr/lib/libc.so.6 ] || have_glibc=no
+ echo $have_glibc
+ [ "x$have_glibc" == "xyes" ] || return 1
}
-# simply return if the toolchain is already there
-if check_toolchain; then return 0; fi
-
-# check for required programs in $PATH to build the toolchain
-check_exe makepkg
-check_exe pacman
-check_exe sed
-check_exe sudo
-
-# create required directories
-mkdir -p "$_logdest" "$_pkgdest"
-chown $SUDO_USER "$_logdest" "$_pkgdest"
-
-# create a sane makepkg.conf
-cat "$_srcdir"/makepkg.conf.in > "$_builddir"/makepkg.conf
-cat >> "$_builddir"/makepkg.conf << EOF
-CARCH="$(source /etc/makepkg.conf && echo $CARCH)"
-CHOST="$(source /etc/makepkg.conf && echo $CHOST)"
-CPPFLAGS="$(source /etc/makepkg.conf && echo $CPPFLAGS)"
-CFLAGS="$(source /etc/makepkg.conf && echo $CFLAGS)"
-CXXFLAGS="$(source /etc/makepkg.conf && echo $CXXFLAGS)"
-LDFLAGS="$(source /etc/makepkg.conf && echo $LDFLAGS)"
-LOGDEST="$_logdest"
-PKGDEST="$_pkgdest"
+stage1() {
+ msg -n "Entering Stage 1"
+
+ export BUILDDIR="$TOPBUILDDIR"/stage1
+ export SRCDIR="$TOPSRCDIR"/stage1
+ export PKGDEST="$BUILDDIR"/packages
+ export LOGDEST="$BUILDDIR"/makepkglogs
+ export MAKEPKGDIR="$BUILDDIR"
+
+ check_cross_toolchain && return
+
+ check_exe gpg makepkg pacman sed sudo || return
+
+ # create required directories
+ mkdir -p "$LOGDEST" "$PKGDEST" "$SRCDEST"
+ chown "$SUDO_USER" "$LOGDEST" "$PKGDEST" "$SRCDEST"
+
+ # create a sane makepkg.conf
+ cat "$SRCDIR"/makepkg.conf.in > "$BUILDDIR"/makepkg.conf
+ cat >> "$BUILDDIR"/makepkg.conf << EOF
+LOGDEST="$LOGDEST"
+PKGDEST="$PKGDEST"
+SRCDEST="$SRCDEST"
MAKEFLAGS="-j$(($(nproc) + 1))"
EOF
-_srcdest="$(source /etc/makepkg.conf && echo $SRCDEST || true)"
-[ -z "$_srcdest" ] || echo "SRCDEST=\"$_srcdest\"" >> "$_builddir"/makepkg.conf
-
-# build and install the toolchain packages
-for pkg in binutils linux-libre-api-headers gcc-bootstrap glibc gcc; do
- _pkgname=$CHOST-$pkg
- echo -n "checking for $_pkgname ... "
- _pkgfile=$(find $_pkgdest -regex "^.*/$_pkgname-[^-]*-[^-]*-[^-]*\.pkg\.tar\.xz\$")
- [ -n "$_pkgfile" ] && _have_pkg=yes || _have_pkg=no
- echo $_have_pkg
-
- if [ "x$_have_pkg" == "xno" ]; then
- msg "makepkg: $_pkgname"
- prepare_makepkgdir
-
- cp "$_srcdir"/toolchain-pkgbuilds/$pkg/PKGBUILD.in .
-
- import_keys
-
- # substitute architecture variables
- sed -i "s#@CHOST@#$CHOST#g; \
- s#@CARCH@#$CARCH#g; \
- s#@LINUX_ARCH@#$LINUX_ARCH#g; \
- s#@GCC_MARCH@#${GCC_MARCH:-}#g; \
- s#@GCC_MABI@#${GCC_MABI:-}#g; \
- s#@MULTILIB@#${MULTILIB:-disable}#g; \
- s#@GCC_32_MARCH@#${GCC_32_MARCH:-}#g; \
- s#@GCC_32_MABI@#${GCC_32_MABI:-}#g; \
- s#@CARCH32@#${CARCH32:-}#g; \
- s#@CHOST32@#${CHOST32:-}#g" \
- PKGBUILD
-
- # build the package
- chown -R $SUDO_USER .
- sudo -u $SUDO_USER makepkg -LC --config "$_builddir"/makepkg.conf || failed_build
-
- popd >/dev/null
- notify -c success -u low "$_pkgname"
- fi
-
- # install the package
- set +o pipefail
- _pkgfile=$(find $_pkgdest -regex "^.*/$_pkgname-[^-]*-[^-]*-[^-]*\.pkg\.tar\.xz\$" | head -n1)
- yes | pacman -U "$_pkgfile"
- set -o pipefail
-done
-
-# final sanity check
-check_toolchain || die "toolchain build incomplete"
+ # build and install the toolchain packages
+ for pkg in binutils linux-libre-api-headers gcc-bootstrap glibc gcc; do
+ msg "makepkg: $CHOST-$pkg"
+
+ if ! check_pkgfile "$PKGDEST" "$CHOST-$pkg"; then
+ prepare_makepkgdir "$MAKEPKGDIR/$CHOST-$pkg" || return
+
+ # produce pkgfiles
+ for f in "$SRCDIR"/toolchain-pkgbuilds/$pkg/*.in; do cp "$f" "$(basename "${f%.in}")"; done
+ sed -i "s#@CHOST@#$CHOST#g; \
+ s#@CARCH@#$CARCH#g; \
+ s#@LINUX_ARCH@#$LINUX_ARCH#g; \
+ s#@GCC_MARCH@#${GCC_MARCH:-}#g; \
+ s#@GCC_MABI@#${GCC_MABI:-}#g; \
+ s#@MULTILIB@#${MULTILIB:-disable}#g; \
+ s#@GCC_32_MARCH@#${GCC_32_MARCH:-}#g; \
+ s#@GCC_32_MABI@#${GCC_32_MABI:-}#g; \
+ s#@CARCH32@#${CARCH32:-}#g; \
+ s#@CHOST32@#${CHOST32:-}#g" \
+ PKGBUILD
+
+ import_keys || return
+
+ if ! sudo -u "$SUDO_USER" makepkg -LC --config "$BUILDDIR"/makepkg.conf; then
+ local log phase
+ log=$(find_lastlog "$LOGDEST" "$CHOST-$pkg")
+ if [ -z "$log" ]; then
+ error -n "$CHOST-$pkg: error in makepkg"
+ else
+ phase=$(sed 's/.*\(pkgver\|prepare\|build\|package\).*/\1/' <<< "$log")
+ error -n -d "$log" "$CHOST-$pkg: error in $phase"
+ fi
+ return "$ERROR_BUILDFAIL"
+ fi
+
+ popd >/dev/null || return
+ notify -c success -u low "$CHOST-$pkg"
+ fi
+
+ # install the package
+ # shellcheck disable=SC2010
+ pkgfile=$(ls -t "$PKGDEST" | grep -P "^$CHOST-$pkg(-[^-]*){3}\\.pkg" | head -n1)
+ yes | pacman -U "$PKGDEST/$pkgfile"
+ done
+
+ # final sanity check
+ check_cross_toolchain || die -e "$ERROR_MISSING" "toolchain build incomplete"
+}
diff --git a/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/0001-pthread-reentrant.patch.in b/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/0001-pthread-reentrant.patch.in
new file mode 100644
index 0000000..36342ef
--- /dev/null
+++ b/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/0001-pthread-reentrant.patch.in
@@ -0,0 +1,11 @@
+--- trunk/gcc/config/riscv/linux.h 2018/01/03 10:03:58 256169
++++ trunk/gcc/config/riscv/linux.h 2018/02/13 11:21:01 257621
+@@ -47,6 +47,8 @@
+
+ #define ICACHE_FLUSH_FUNC "__riscv_flush_icache"
+
++#define CPP_SPEC "%{pthread:-D_REENTRANT}"
++
+ #define LINK_SPEC "\
+ -melf" XLEN_SPEC "lriscv \
+ %{shared} \
diff --git a/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/PKGBUILD.in b/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/PKGBUILD.in
index 25dc331..02f51ee 100644
--- a/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/PKGBUILD.in
+++ b/src/stage1/toolchain-pkgbuilds/gcc-bootstrap/PKGBUILD.in
@@ -2,7 +2,7 @@
_target=@CHOST@
pkgname=$_target-gcc-bootstrap
-pkgver=7.3.1
+pkgver=7.3.1+20180312
_islver=0.18
pkgrel=1
pkgdesc='The GNU Compiler Collection - cross compiler for @CARCH@ target - bootstrap version. only used to build initial glibc and compiler'
@@ -14,35 +14,33 @@ makedepends=(gmp mpfr)
options=(!emptydirs !strip)
provides=(${pkgname%-bootstrap})
conflicts=(${pkgname%-bootstrap})
-_snapshot=7-20180215
-source=(#ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-$pkgver.tar.xz
- ftp://gcc.gnu.org/pub/gcc/snapshots/$_snapshot/gcc-$_snapshot.tar.xz
- http://isl.gforge.inria.fr/isl-$_islver.tar.bz2)
-sha256sums=('bb276f6fce4822fc0806d1e87d21245854d1e41f2a7027c7288375084176c679'
- '6b8b0fd7f81d0a957beb3679c81bbb34ccc7568d5682844d8924424a0dadcb1b')
-
-if [ -n "$_snapshot" ]; then
- _basedir=gcc-$_snapshot
-else
- _basedir=gcc-$pkgver
-fi
+source=(https://sources.archlinux.org/other/gcc/gcc-${pkgver/+/-}.tar.xz{,.sig}
+ http://isl.gforge.inria.fr/isl-$_islver.tar.bz2
+ 0001-pthread-reentrant.patch)
+validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux.org
+ 13975A70E63C361C73AE69EF6EEB81F8981C74C7) # richard.guenther@gmail.com
+sha256sums=('c52618f656f2102b3544419e7d0a8a4f4e6ff052783865202be73edf1a40e28b'
+ 'SKIP'
+ '6b8b0fd7f81d0a957beb3679c81bbb34ccc7568d5682844d8924424a0dadcb1b'
+ 'fc9c6f0edd615f2b39deff28b9626a08fd98ef8ce19f7e34281c0a5bd653ac3b')
prepare() {
- cd $_basedir
+ [[ ! -d gcc ]] && ln -s gcc-${pkgver/+/-} gcc
+ cd gcc
# link isl for in-tree builds
ln -sf ../isl-$_islver isl
- echo $pkgver > gcc/BASE-VER
-
# Do not run fixincludes
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
# hack! - some configure tests for header files using "$CPP $CPPFLAGS"
- sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" "$srcdir"/$_basedir/{libiberty,gcc}/configure
+ sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" "$srcdir"/gcc/{libiberty,gcc}/configure
+
+ # fix -pthreads behavior on risc-v
+ patch -Np1 -i "$srcdir/0001-pthread-reentrant.patch"
- rm -rf $srcdir/gcc-build
- mkdir $srcdir/gcc-build
+ mkdir -p "$srcdir/gcc-build"
}
build() {
@@ -53,7 +51,7 @@ build() {
CFLAGS=${CFLAGS/-pipe/}
CXXFLAGS=${CXXFLAGS/-pipe/}
- $srcdir/$_basedir/configure \
+ $srcdir/gcc/configure \
--target=$_target \
--prefix=/usr \
--libdir=/usr/lib \
diff --git a/src/stage1/toolchain-pkgbuilds/gcc/0001-pthread-reentrant.patch.in b/src/stage1/toolchain-pkgbuilds/gcc/0001-pthread-reentrant.patch.in
new file mode 100644
index 0000000..36342ef
--- /dev/null
+++ b/src/stage1/toolchain-pkgbuilds/gcc/0001-pthread-reentrant.patch.in
@@ -0,0 +1,11 @@
+--- trunk/gcc/config/riscv/linux.h 2018/01/03 10:03:58 256169
++++ trunk/gcc/config/riscv/linux.h 2018/02/13 11:21:01 257621
+@@ -47,6 +47,8 @@
+
+ #define ICACHE_FLUSH_FUNC "__riscv_flush_icache"
+
++#define CPP_SPEC "%{pthread:-D_REENTRANT}"
++
+ #define LINK_SPEC "\
+ -melf" XLEN_SPEC "lriscv \
+ %{shared} \
diff --git a/src/stage1/toolchain-pkgbuilds/gcc/PKGBUILD.in b/src/stage1/toolchain-pkgbuilds/gcc/PKGBUILD.in
index 4ba85e8..2863cad 100644
--- a/src/stage1/toolchain-pkgbuilds/gcc/PKGBUILD.in
+++ b/src/stage1/toolchain-pkgbuilds/gcc/PKGBUILD.in
@@ -2,7 +2,7 @@
_target=@CHOST@
pkgname=$_target-gcc
-pkgver=7.3.1
+pkgver=7.3.1+20180312
_islver=0.18
pkgrel=1
pkgdesc='The GNU Compiler Collection - cross compiler for @CARCH@ target'
@@ -14,35 +14,33 @@ makedepends=(gmp mpfr)
options=(!emptydirs !strip staticlibs)
conflicts=($pkgname-bootstrap)
replaces=($pkgname-bootstrap)
-_snapshot=7-20180215
-source=(#ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-$pkgver.tar.xz
- ftp://gcc.gnu.org/pub/gcc/snapshots/$_snapshot/gcc-$_snapshot.tar.xz
- http://isl.gforge.inria.fr/isl-$_islver.tar.bz2)
-sha256sums=('bb276f6fce4822fc0806d1e87d21245854d1e41f2a7027c7288375084176c679'
- '6b8b0fd7f81d0a957beb3679c81bbb34ccc7568d5682844d8924424a0dadcb1b')
-
-if [ -n "$_snapshot" ]; then
- _basedir=gcc-$_snapshot
-else
- _basedir=gcc-$pkgver
-fi
+source=(https://sources.archlinux.org/other/gcc/gcc-${pkgver/+/-}.tar.xz{,.sig}
+ http://isl.gforge.inria.fr/isl-$_islver.tar.bz2
+ 0001-pthread-reentrant.patch)
+validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux.org
+ 13975A70E63C361C73AE69EF6EEB81F8981C74C7) # richard.guenther@gmail.com
+sha256sums=('c52618f656f2102b3544419e7d0a8a4f4e6ff052783865202be73edf1a40e28b'
+ 'SKIP'
+ '6b8b0fd7f81d0a957beb3679c81bbb34ccc7568d5682844d8924424a0dadcb1b'
+ 'fc9c6f0edd615f2b39deff28b9626a08fd98ef8ce19f7e34281c0a5bd653ac3b')
prepare() {
- cd $_basedir
+ [[ ! -d gcc ]] && ln -s gcc-${pkgver/+/-} gcc
+ cd gcc
# link isl for in-tree builds
ln -sf ../isl-$_islver isl
- echo $pkgver > gcc/BASE-VER
-
# Do not run fixincludes
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
# hack! - some configure tests for header files using "$CPP $CPPFLAGS"
- sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" "$srcdir"/$_basedir/{libiberty,gcc}/configure
+ sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" "$srcdir"/gcc/{libiberty,gcc}/configure
+
+ # fix -pthreads behavior on risc-v
+ patch -Np1 -i "$srcdir/0001-pthread-reentrant.patch"
- rm -rf $srcdir/gcc-build
- mkdir $srcdir/gcc-build
+ mkdir -p "$srcdir/gcc-build"
}
build() {
@@ -53,7 +51,7 @@ build() {
CFLAGS=${CFLAGS/-pipe/}
CXXFLAGS=${CXXFLAGS/-pipe/}
- $srcdir/$_basedir/configure \
+ $srcdir/gcc/configure \
--target=$_target \
--prefix=/usr \
--libdir=/usr/lib \
@@ -62,19 +60,19 @@ build() {
--with-local-prefix=/usr/$_target \
--with-build-sysroot=/usr/$_target \
--with-sysroot=/usr/$_target \
- --with-system-zlib \
--enable-shared \
+ --with-system-zlib \
--enable-tls \
--enable-languages=c,c++,fortran \
--disable-libmudflap \
--disable-libssp \
--disable-libquadmath \
--disable-nls \
- --disable-bootstrap \
- --enable-checking=release \
--@MULTILIB@-multilib \
--with-abi=@GCC_MABI@ \
- --with-arch=@GCC_MARCH@
+ --with-arch=@GCC_MARCH@ \
+ --disable-bootstrap \
+ --enable-checking=release
make
}
@@ -94,5 +92,5 @@ package() {
rm -r "$pkgdir"/usr/lib/libcc1.so{,.0,.0.0.0}
rm -r "$pkgdir"/usr/share/man/man7
rm -r "$pkgdir"/usr/share/info
- rm -r "$pkgdir"/usr/share/gcc-$pkgver
+ rm -r "$pkgdir"/usr/share/gcc-*
}