Skip to content

Instantly share code, notes, and snippets.

@geoff-nixon
Last active July 26, 2016 17:16
Show Gist options
  • Save geoff-nixon/dcd6379d3e5616efd8ee to your computer and use it in GitHub Desktop.
Save geoff-nixon/dcd6379d3e5616efd8ee to your computer and use it in GitHub Desktop.
#!/bin/sh -x # Bootstrap a toolchain from scratch on Chrome OS. WIP.
die(){ printf "%s\n" "$@" && exit 1 ;}
warn(){ printf "%s\n" "$@"; return 0 ;}
download(){ curl -L\# "$1" ;}
alias grep=\grep
# Some rather terse error messages.
nocrossystem(){ die "No crossystem. Are you sure you're running Chrome OS?" ;}
nox86_64arch(){ die "Sorry, x86_64 is the only supported arch at present." ;}
nodevchannel(){ die "Not on dev-channel. Open chrome://chrome to switch." ;}
notindevmode(){ die "Not in dev mode. Press ESC-⟳-⎋, then ctrl-D on boot." ;}
nodevpasswd(){ die "No dev password. Press ctl-alt-➔, follow instructions." ;}
notincrosh(){ die "Run in crosh. ctrl-alt-T / install 'crosh window' ext." ;}
notchronos(){ die "Do not run this script as root." ;}
sanity_check(){
# Make sure we're actually on a Chromium-like system.
crossystem >/dev/null 2>&1 || nocrossystem
# We only support x86_64 at present. If anyone wants to donate/lend some
# hardware for other architectures, I'd be happy to port. Ping me if you
# want to take swing at it yourself — setting up the bootstrap toolchain is
# a little tricky.
[ -$(uname -m)- = -x86_64- ] || nox86_64arch
# Make sure we're dev-channel.
grep TRACK < /etc/lsb-release | grep dev >/dev/null 2>&1 || nodevchannel
# Make sure we're in dev mode.
[ $(crossystem devsw_cur) = 1 ] || notindevmode
# Make sure chromeos-setdevpasswd has been run, i.e., make sure we can sudo.
[ -e /mnt/stateful_partition/etc/devmode.passwd ] || nodevpasswd
# Make sure this is a crosh window, not the console.
[ $SHLVL -gt 1 ] || notincrosh
# Make sure we're not running as root. We'll use sudo, only when we have to.
[ $(whoami) = chronos ] || notchronos
# Until I can figure out how to check for this.
echo
warn "The bootstrap process may take some time."
warn "We're temporarily disabling power management,"
warn "so make sure you're plugged in!"
echo
warn "You may be prompted to enter your developer password to authenticate."
echo
# sudo initctl stop powerd
}
setconstants(){
# Get and set some variables.
############### COMPILER FLAGS - EDIT AS YOU LIKE #########################
# Default to safe flags...
# OPT_FLAGS="-Os" # Or, see below.
# Targeting the host machine...
# MARCH_FLAGS="-march=native" # -mtune=native is redundant.
MARCH_FLAGS="-march=core2 -mtune=haswell" # Build for distribution (LCD).
# Without debug info, to conserve space...
DEBUG_FLAGS="-g0"
# DEBUG_FLAGS="-g" # Unless you need it, of course.
# With hardening flags (like Google how does it).
HARDENC_FLAGS="-fPIC -fstack-protector-strong" # -fPIE -pie
HARDENL_FLAGS="-Wl,-z,now,-z,relro,--hash-style=gnu"
# Or, instead of -Os, you could...
OPT_FLAGS="-Ofast" # -O3 + -ffast-math
# Enable LTO
OPT_FLAGS="$OPT_FLAGS -fuse-linker-plugin"
OPT_FLAGS="$OPT_FLAGS -fno-fat-lto-objects -flto-compression-level=9"
make -v >/dev/null 2>&1 && OPT_FLAGS="$OPT_FLAGS -flto=jobserver"
# Enable Graphite
# OPT_FLAGS="$OPT_FLAGS -ftree-vectorize -floop-block -floop-interchange"
# OPT_FLAGS="$OPT_FLAGS -ftree-loop-distribution -floop-strip-mine"
############### END COMPILER FLAGS - DON'T EDIT BELOW ######################
# System stuff.
ARCH=$(uname -m)
# Flesh this out with more architectures and variables eventually.
case $(uname -m) in
i386) LIBC_SO=/lib/libc.so.6 ;;
x86_64) LIBC_SO=/lib64/libc.so.6 ;;
''|*) die "Unknown architecture, or something is wrong." ;;
esac
}
pkgv(){
case "$1" in
apr) echo 1.5.2 ;;
apr-util) echo 1.5.4 ;;
autoconf) echo latest ;;
automake) echo 1.15 ;;
bc) echo 1.06 ;;
binutils) echo 2.25 ;;
bison) echo 3.0.4 ;;
bzip2) echo 1.0.6 ;;
cmake) echo 3.2.2 ;;
coreutils) echo 8.23 ;;
curl) echo 7.42.1 ;;
cvs) echo 1.12.13 ;;
diffutils) echo 3.3 ;;
doxygen) echo 1.8.9.1 ;;
expat) echo 2.1.0 ;;
file) echo 5.22 ;;
fish) echo 2.1.2 ;;
flex) echo 2.5.39 ;;
gawk) echo 4.1.3 ;;
gcc) echo 5.1.0 ;;
gdb) echo 7.9.1 ;;
gdbm) echo latest ;;
gettext) echo latest ;;
git) echo 2.4.2 ;;
glibc) echo 2.19 ;;
# glibc) $LIBC_SO | head -1 | sed 's|.*Gentoo \([0-9]\.[0-9]*\).*|\1|' ;;
gmp) echo 6.0.0a ;;
graphviz) echo 2.38.0 ;;
isl) echo 0.14.1 ;;
kernel) echo 3.8 ;;
# kernel) uname -r | sed 's|\(.*\..*\)\..*|\1|' ;;
less) echo 451 ;;
libarchive) echo 3.1.2 ;;
libssh2) echo 1.5.0 ;;
libtool) echo 2.4.6 ;;
libxml2) echo 2.9.2 ;;
libxslt) echo 1.1.28 ;;
libpng) echo 1.6.17 ;;
libidn) echo 1.30 ;;
llvm) echo 3.6.1 ;;
ltrace) echo 0.7.3 ;;
m4) echo latest ;;
make) echo 3.82 ;;
man) echo 1.6c ;;
mpc) echo 1.0.3 ;;
mpfr) echo 3.1.2 ;;
nano) echo 2.4.1 ;;
ncurses) echo 5.9 ;;
nettle) echo 3.1.1 ;;
ninja) echo v1.5.3 ;;
node) echo v0.12.4 ;;
openssl) echo 1.0.2a ;;
parallel) echo latest ;;
patch) echo 2.7.5 ;;
pcre) echo 8.37 ;;
perl) echo 5.20.2 ;;
pkg-config) echo 0.28 ;;
python) echo 2.7.10 ;;
rcs) echo 5.9.4 ;;
readline) echo 6.3 ;;
ruby) echo 2.2.2 ;;
serf) echo 1.3.8 ;;
sqlite) echo 3081002 ;;
strace) echo 4.10 ;;
subversion) echo 1.8.13 ;;
texinfo) echo 5.2 ;;
xz) echo 5.2.1 ;;
zlib) echo 1.2.8 ;;
esac
}
pkgurl(){
chrome3rdparty=http://chromium.googlesource.com/chromiumos/third_party
ftpgnu=http://ftp.gnu.org/gnu
gh=http://github.com
rel=releases/download
pkgdir=
pkgv=$(pkgv $1)
case "$1" in
autoconf | automake | bc | binutils | bison |\
coreutils | diffutils | gawk | gdb | gdbm |\
gettext | gmp | less | libidn | libtool |\
m4 | make | mpc | mpfr | nano |\
nettle | parallel | patch | rcs | readline |\
texinfo) pkgdir=$ftpgnu/$1 ;;
bzip2) echo http://www.bzip.org/$pkgv/$1-$pkgv.tar.gz ;;
file) echo ftp://ftp.astron.com/pub/$1/$1-$pkgv.tar.gz ;;
fish) echo http://$1shell.com/files/$pkgv/$1-$pkgv.tar.gz ;;
doxygen) echo http://downloads.sf.net/$1/$1-$pkgv.src.tar.gz ;;
expat) echo http://downloads.sf.net/$1/$1-$pkgv.tar.gz ;;
flex) echo http://downloads.sf.net/$1/$1-$pkgv.tar.gz ;;
gcc) echo $ftpgnu/$1/$1-$pkgv/$1-$pkgv.tar.bz2 ;;
glibc) echo $chrome3rdparty/$1/+archive/upstream/gentoo/$pkgv.tar.gz ;;
kernel) echo $chrome3rdparty/$1/+archive/chromeos-$pkgv.tar.gz ;;
man) echo http://opensource.apple.com/tarballs/man/man-16.tar.gz ;;
ninja) echo http://github.com/martine/$1/archive/$pkgv.tar.gz ;;
python) echo http://python.org/ftp/$1/$pkgv/Python-$pkgv.tar.xz ;;
sqlite) echo http://$1.org/2015/$1-autoconf-$pkgv.tar.gz ;;
strace) echo http://downloads.sf.net/$1/$1-$pkgv.tar.xz ;;
llvm) echo http://$1.org/releases/$pkgv/$1-$pkgv.src.tar.xz ;;
ltrace) echo http://$1.org/$1_$pkgv.orig.tar.bz2 ;;
libpng) echo http://downloads.sf.net/$1/$1-$pkgv.tar.gz ;;
pcre) echo http://downloads.sf.net/$1/$1-$pkgv.tar.gz ;;
perl) echo $gh/shoichikaji/relocatable-$1/$rel/0.10/$1-x86_64-linux.tar.gz ;;
cmake) pkgdir=http://www.cmake.org/files/v3.2 ;;
curl) pkgdir=http://curl.haxx.se/download ;;
cvs) pkgdir=http://ftp.gnu.org/non-gnu/$1/source/feature/$pkgv ;;
apr) pkgdir=http://apache.org/dist/apr ;;
apr-util) pkgdir=http://apache.org/dist/apr ;;
git) pkgdir=http://www.kernel.org/pub/software/scm/$1 ;;
graphviz) pkgdir=http://$1.org/pub/$1/stable/SOURCES ;;
isl) pkgdir=http://$1.gforge.inria.fr ;;
libarchive) pkgdir=http://www.$1.org/downloads ;;
libssh2) pkgdir=http://$1.org/download ;;
libxml2) pkgdir=http://xmlsoft.org/sources ;;
libxslt) pkgdir=http://xmlsoft.org/sources ;;
ncurses) pkgdir=http://ftp.gnu.org/gnu/$1 ;;
node) pkgdir=http://$1js.org/dist/$pkgv ;;
openssl) pkgdir=http://www.openssl.org/source ;;
pkg-config) pkgdir=http://pkgconfig.freedesktop.org/releases ;;
ruby) pkgdir=http://cache.$1-lang.org/pub/$1/2.2 ;;
serf) pkgdir=http://$1.googlecode.com/svn/src_releases ;;
subversion) pkgdir=http://apache.org/dist/$1 ;;
xz) pkgdir=http://tukaani.org/$1 ;;
zlib) pkgdir=http://$1.net ;;
''|*) Echo "Nope" && exit 1 ;;
esac
[ $pkgdir ] || return 0
if curl -Ls $pkgdir/$extradir | grep tar.xz >/dev/null 2>&1; then
echo $pkgdir/$extradir$1-$(pkgv $1).tar.xz
elif curl -Ls $pkgdir/$extradir | grep tar.gz >/dev/null 2>&1; then
echo $pkgdir/$extradir$1-$(pkgv $1).tar.gz
elif curl -Ls $pkgdir/$extradir | grep tar.bz2 >/dev/null 2>&1; then
echo $pkgdir/$extradir$1-$(pkgv $1).tar.bz2
else echo "Error: None found." && exit 1
fi
}
downloadpkg(){
pkgurl $1 | grep '.xz$' >/dev/null 2>&1 && TARSUFFIX=J
pkgurl $1 | grep '.gz$' >/dev/null 2>&1 && TARSUFFIX=x
pkgurl $1 | grep '.bz2$' >/dev/null 2>&1 && TARSUFFIX=j
echo "Downloading $1..."
[ $1 = kernel ] || [ $1 = glibc ] && mkdir -p $1 && cd $1
download "$(pkgurl $1)" | tar x$TARSUFFIX
[ $1 = kernel ] || [ $1 = glibc ] && cd .. && return 0
[ $1 = python ] && mv Python* python && return 0
mv $1* $1
}
makedotfiles(){
echo; echo "Configuring user dotfiles..."; echo
# We could append to existing dotfiles, but I prefer moving any existing
# ones out of harms way, and letting the user reintegrate them manually.
for df in rc profile bashrc bash_profile; do
cd; [ -e .$df ] && mv .$df $df && warn "Note: moving existing .$df to $df."
done
# In order to "play nice", a.k.a "don't hog /usr/local" like everything
# else (dev_install, crew, crouton, ...) we remount /tmp, $HOME, and
# $HOME/.. (/home/chronos, which is persistent between Chrome users),
# which by default are mounted noexec, like every other mountpoint except
# /usr/local. I think this works pretty well. One downside is the remount
# needs to be redone each time the system reboots, and this requires sudoer
# privileges. This is why this code needs to go in the startfiles.
# But, after that, everything is done as user, and that's a vast improvement
# to using root for just about everything...
# The idea is to use the $HOME or /home/chronos to store our goods, since
# this is the largest partition, but to symlink into /tmp for a short and
# memorable path/install prefix, so software that requires an absolute path
# get confused, and alternate packages can be linked-in or linked-out, sort
# of like how homebrew's Cellar/keg mechanism works.
torc(){ echo "$*" >> ~/.rc ;} # Yeah. I dislike heredocs.
torc 'mountx(){'
torc ' echo; echo "Enter password to remount with -x permissions:"; echo'
torc ''
torc ' for mountpoint in /tmp /home/chronos $HOME; do'
torc ' sudo mount -i -o remount,exec $mountpoint'
torc ' done'
torc '}'
torc ''
# You figure it out? :) Also, we *could* do this on each volume, but why?
torc 'echo :>~/.:&& chmod +x ~/.:&&~/.: 2>/dev/null || mountx; rm -rf ~/.:'
torc ''
torc "last4=$(ifconfig |grep eth| sed -e's|:||g' -e's|.*r ||' | cut -c9-12)"
torc 'mdnsname=chrome-$last4.local'
torc ''
torc 'enablemdnsandssh(){'
torc ' initctl status avahi 2>/dev/null | grep stop >/dev/null 2>&1 &&'
torc ' sudo initctl start avahi >/dev/null 2>&1 &&'
torc ' sudo avahi-set-host-name chromebook >/dev/null 2>&1 ||:'
torc ''
torc ' [ -e /mnt/stateful_partition/etc/ssh ] &&'
torc ' netstat -an 2>/dev/null | grep :22 >/dev/null ||'
torc ' sudo iptables -I INPUT -p tcp --dport 22 -j ACCEPT'
torc ' pidof sshd >/dev/null || sudo /usr/sbin/sshd -o "UseDns yes"'
torc '}'
torc ''
torc 'mkdir -p /home/chronos/usr/local/bin'
torc '[ ! -e "/tmp/usr" ] && cd /tmp && ln -s /home/chronos/usr . && cd'
torc '[ ! -e "$HOME/Downloads/Developer" ] &&'
torc ' cd ~/Downloads && ln -s /home/chronos/usr Developer && cd'
torc ''
# Build a robust PATH.
torc 'unset PATH'
torc "for dir in '' /usr/local /usr /tmp/usr /tmp/usr/local; do"
torc ' for bindir in libexec sbin bin; do'
torc ' [ -d $dir/$bindir ] && PATH=$dir/$bindir:$PATH'
torc ' done'
torc 'done'
torc 'export PATH="$(echo $PATH | sed "s|:$||")"'
torc 'export PATH=$PATH:/tmp/bootstrap/toolchain/bin'
torc ''
# Set some sensible defaults.
torc 'export MAKEFLAGS=-j$(grep proc < /proc/cpuinfo | wc -l)'
torc ''
torc "FLAGS=\"$OPT_FLAGS $MARCH_FLAGS $HARDENC_FLAGS $DEBUG_FLAGS\""
torc ''
torc 'export CPPFLAGS="-isystem /tmp/usr/include -I/tmp/usr/local/include"'
torc 'export CFLAGS="$CPPFLAGS $FLAGS" # -std=gnu11'
torc 'export CXXFLAGS="$CPPFLAGS $FLAGS"'
torc "export LDFLAGS=\"$HARDENL_FLAGS -L/tmp/usr/local/lib -Wl,-S,--relax\""
torc ''
# Try to un-fuck ourselves a little bit.
torc 'unset LD_LIBRARY_PATH'
torc 'unset MANPATH'
torc 'unset EDITOR'
torc 'unset PAGER'
torc ''
torc 'export CLICOLOR=1'
torc 'export TERM=xterm-color'
torc ''
torc "alias la='ls -lah'"
torc 'enablemdnsandssh'
torc ''
torc 'cd'
torc ''
# Daisy chain the rest of the startfiles. Edit as you like, of course.
echo '[ -e ~/.rc ] && . ~/.rc' >> ~/.profile
echo '[ -e ~/.rc ] && . ~/.rc' >> ~/.bashrc
echo '[ -e ~/.profile ] && . ~/.profile ||' >> ~/.bash_profile
echo '[ -e ~/.bashrc ] && . ~/.bashrc' >> ~/.bash_profile
# Gonna sneak this one in there for kicks 'til someone complains. bash == bs.
echo 'which fish >/dev/null 2>&1 && exec fish -il' >> ~/.bash_profile
# And finally...
. ~/.rc
cd
}
downloadpkg(){
pkgurl $1 | grep '.xz$' >/dev/null 2>&1 && TARSUFFIX=J
pkgurl $1 | grep '.gz$' >/dev/null 2>&1 && TARSUFFIX=z
pkgurl $1 | grep '.bz2$' >/dev/null 2>&1 && TARSUFFIX=j
echo; echo "Downloading $1..."
[ $1 = kernel ] || [ $1 = glibc ] && mkdir -p $1 && cd $1
download "$(pkgurl $1)" | tar x$TARSUFFIX
[ $1 = kernel ] || [ $1 = glibc ] && cd .. && return 0
[ $1 = Python ] && mv Python* python && return 0
mv $1* $1
}
stdconfigureflags='
--build=x86_64-cros-linux-gnu
--prefix=/tmp/usr/local
--disable-option-checking
--disable-all-warnings
--disable-assert
--disable-bootstrap
--disable-build-warnings
--disable-csharp
--disable-curldebug
--disable-debug
--disable-dependency-tracking
--disable-doc
--disable-documentation
--disable-examples-build
--disable-gcc-warnings
--disable-gcc-Werror
--disable-gmp-version-check
--disable-gtk-doc
--disable-gtk-doc-html
--disable-gtk-doc-pdf
--disable-isl-version-check
--disable-java
--disable-libjava
--disable-libstdcxx-pch
--disable-libtool-lock
--disable-lint
--disable-ltdl-install
--disable-lzma-links
--disable-lzmadec
--disable-lzmainfo
--disable-maintainer-mode
--disable-mpc-version-check
--disable-mpfr-version-check
--disable-multilib
--disable-native-java
--disable-nls
--disable-profile
--disable-rebuild-docs
--disable-rpath
--disable-scripts
--disable-shared
--disable-versioned-symbols
--disable-warnings
--disable-werror
--disable-werror-always
--disable-xz
--disable-xzdec
--enable-add-ons
--enable-as-accelerator-for=x86_64-cros-linux-gnu
--enable-bind-now
--enable-bsdcat=static
--enable-bsdcpio=static
--enable-bsdtar=static
--enable-c++
--enable-changeword
--enable-cookies
--enable-crypto-auth
--enable-cxx
--enable-disallowing-of-undefined-references
--enable-dynamic-extensions
--enable-fast-install
--enable-fsect-man5
--enable-gmp-internals
--enable-gold
--enable-host-shared
--enable-indirect-deps
--enable-install-libbfd
--enable-ipv6
--enable-jit
--enable-kernel=3.8
--enable-languages=c,c++,fortran,go,java,jit,objc,obj-c++
--enable-largefile
--enable-libcurl-option
--enable-libgdbm-compat
--enable-lock-elision
--enable-lto
--enable-merge
--enable-multibyte
--enable-nss-crypt
--enable-optimize
--enable-other-child
--enable-pcre16
--enable-pcre32
--enable-pcre8
--enable-pcregrep-jit
--enable-pie
--enable-plugin
--enable-plugins
--enable-portable-binary
--enable-posix-shm
--enable-pt_chown
--enable-readline
--enable-relocatable
--enable-runtime-module-search
--enable-silent-rules
--enable-single-binary=shebangs
--enable-stackguard-randomization
--enable-stage1-checking=release
--enable-static
--enable-systemtap
--enable-target-optspace
--enable-thread-safe
--enable-threaded-resolver
--enable-threads
--enable-threads=posix
--enable-threadsafe
--enable-unaligned-access
--enable-unicode-properties
--enable-unix-sockets
--enable-utf8
--enable-version-specific-runtime-libs
--enable-xattr
--with-apr-util=/tmp/usr/local/bin/apu-config
--with-apr=/tmp/usr/local/bin/apr-config
--with-arch-64=core2
--with-ca-bundle=
--with-ca-path=
--with-crypto
--with-curses=/tmp/usr/local
--with-dbm=gdbm
--with-demangler-in-ld
--with-devrandom=/dev/urandom
--with-diagnostics-color=always
--with-doxygen=/tmp/usr/local
--with-editor=vim
--with-ensurepip=install
--with-expat=/tmp/usr/local
--with-fpectl
--with-gdbm=/tmp/usr/local
--with-gmp-prefix=/tmp/usr/local
--with-gmp=/tmp/usr/local
--with-history
--with-included-gettext
--with-included-glib
--with-included-libcroco
--with-included-libunistring
--with-included-libxml
--with-int=gmp
--with-internal-glib
--with-isl=/tmp/usr/local
--with-libmagic=/tmp/usr/local
--with-libpng-prefix=/tmp/usr/local
--with-libssh2=/tmp/usr/local
--with-libz
--with-linker-hash-style=gnu
--with-local-prefix=/tmp/usr/local
--with-lzma=/tmp/usr/local
--with-mantype=man
--with-mpc=/tmp/usr/local
--with-mpfr=/tmp/usr/local
--with-native-system-header-dir=/tmp/usr/include
--with-openssl
--with-pager=less
--with-pic
--with-plugins
--with-readline=/tmp/usr/include
--with-secure
--with-serf=/tmp/usr/local
--with-shell=/bin/dash
--with-signal-module
--with-sqlite3=/tmp/usr/local
--with-sqlite=/tmp/usr/local
--with-ssl
--with-ssl=/tmp/usr/local
--with-static-linked-ext
--with-syscmd-shell=/bin/dash
--with-system-zlib
--with-threads
--with-tune-64=haswell
--with-wctype-functions
--with-zlib
--with-zlib-prefix=/tmp/usr/local
--with-zlib=/tmp/usr/local
--without-berkeley-db
--without-debug
--without-html
--without-libcc1
--without-ssl2
--without-ssl3
--without-whiny-user-strftime
' #--download=all --english-only --release --static --mandir=share/man
buildpkg(){
cd /tmp; rm -rf $1; downloadpkg $1; cd $1
# Pre-configure
case $1 in
gmp) echo 'ZGlmZiAtLWdpdCBhL2NvbmZpZ3VyZSBiL2NvbmZpZ3VyZQppbm
RleCA2MGM2YmQ1Li41MDE3NWE2IDEwMDc1NQotLS0gYS9jb25m
aWd1cmUKKysrIGIvY29uZmlndXJlCkBAIC0yMzUyOSArMjM1Mj
kgQEAgRU9GCi1nbXBfY29tcGlsZT0iJENDICRDRkxBR1MgJENQ
UEZMQUdTIC1jIGNvbmZ0ZXN0LmMgPiY1IDI+JjEiCitnbXBfY2
9tcGlsZT0iJENDIC1mbm8tbHRvIC1jIGNvbmZ0ZXN0LmMgPiY1
IDI+JjEiCg==' | tr -d '\n' | sed 's| *||g' |
base64 --decode | patch -Np1 2>/dev/null ||: ;;
make) echo 'ZGlmZiAtLWdpdCBhL21haW4uYyBiL21haW4uYwppbmRleCBjNj
k4OWUzLi45NWE2MTE4IDEwMDY0NAotLS0gYS9tYWluLmMKKysr
IGIvbWFpbi5jCkBAIC0xNzUyLDIgKzE3NTEsMCBAQCBtYWluIC
hpbnQgYXJnYywgY2hhciAqKmFyZ3YsIGNoYXIgKiplbnZwKQot
ICAgICAgICAgIGVycm9yIChOSUxGLAotICAgICAgICAgICAgIC
AgICBfKCJ3YXJuaW5nOiBqb2JzZXJ2ZXIgdW5hdmFpbGFibGU6
IHVzaW5nIC1qMS4gIEFkZCBgKycgdG8gcGFyZW50IG1ha2Ugcn
VsZS4iKSk7Cg==' | tr -d '\n' | sed 's| *||g' |
base64 --decode | patch -Np1 2>/dev/null ||: ;;
mpfr) curl -Ls http://mpfr.org/mpfr-current/allpatches | patch -Np1
export CPPFLAGS="$CPPFLAGS -O3"; export CFLAGS="$CFLAGS -O3" ;;
*) : ;;
esac
echo; echo "Configuring $1..."; echo
case $1 in
gmp) export MPN_PATH=" x86_64/fastsse x86_64/core2 x86_64 generic"
./configure $(echo $stdconfigureflags) \
--build=core2-cros-linux-gnu --without-readline --disable-cxx ;;
isl) ./configure $(echo $stdconfigureflags) --with-gmp=system ;;
perl) : ;;
zlib) ./configure --static --prefix=/tmp/usr/local ;;
*) ./configure $(echo $stdconfigureflags) ;;
esac
echo "Building $1..."
case $1 in
make) ./build.sh 2>/dev/null && ./make 2>/dev/null &&
./make -j1 install-strip 2>/dev/null &&
make clean 2>/dev/null && . ~/.rc && make 2>/dev/null &&
export PATH=$PATH:/tmp/bootstrap/toolchain/bin &&
export MAKEFLAGS="$MAKEFLAGS --no-print-directory" ;;
perl) cp -Rp * /tmp/usr/local/ ;;
*) make 2>/dev/null; make -j1 install-strip 2>/dev/null ||
make -j1 install 2>/dev/null ;;
esac
case $1 in
gmp | isl) make check; . ~/.rc ;;
mpfr) . ~/.rc ;;
*) : ;;
esac
find /tmp/usr/local -name \*.la -delete
rm -rf /tmp/usr/local/share/info
cd
}
bootstraptoolchain(){
echo; echo "Bootstrapping toolchain..."
cd /tmp; rm -rf bootstrap bootstrap.* /tmp/bootstrap
guc=https://gist.githubusercontent.com/anonymous/f6db6c61cd7117673b95/raw/
bs=bootstrap
curl -Ls $guc$bs.aa $guc$bs.ab $guc$bs.ac $guc$bs.ad $guc$bs.ae $guc$bs.af \
$guc$bs.ag $guc$bs.ah $guc$bs.ai $guc$bs.aj $guc$bs.ak $guc$bs.al \
$guc$bs.am $guc$bs.an $guc$bs.ao > bootstrap.b 2>/dev/null
curl -L\# file://$PWD/bootstrap.b | base64 --decode | xz -dc | tar x
rm -rf bootstrap.a* bootstrap.b
cd /tmp/bootstrap/toolchain/bin; ln -s ld.gold ld 2>/dev/null ||:
export PATH=$PATH:$PWD
echo "Done."; echo; echo "Now building tools..."; echo
buildpkg perl
buildpkg make
buildpkg zlib
buildpkg patch
buildpkg make
buildpkg diffutils
buildpkg m4
buildpkg gmp
buildpkg mpfr
buildpkg mpc
buildpkg isl
buildpkg bison
buildpkg flex
buildpkg gawk
buildpkg binutils
}
rm -rf /tmp/bootstrap
here=$(pwd -P)
sanity_check
setconstants
makedotfiles
gcc -v >/dev/null 2>&1 || bootstraptoolchain
cd "$here"
set +x
###### PAY NO ATTENTION TO THE CRAP BELOW ########
# cd /tmp; rm -rf glibc-src; mkdir -p glibc-src; cd glibc-src
# download $GLIBC_SRC | tar xz 2>/dev/null &
# cd /tmp; rm -rf kernel-src; mkdir -p kernel-src; cd kernel-src
# download $KERNEL_SRC | tar xz 2>/dev/null
# /tmp/gcc-5.1.0/configure --build=x86_64-cros-linux-gnu --disable-bootstrap --disable-checking --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-shared --disable-werror --enable-lto --enable-static --enable-host-shared --enable-target-optspace --enable-version-specific-runtime-libs --enable-languages=c,c++ --with-pic --with-system-zlib --with-arch-64=core2 --with-tune-64=haswell --with-diagnostics-color=always --with-fpmath=sse --with-native-system-header-dir=/tmp/bootstrap/usr/include --with-local-prefix=/tmp/bootstrap/usr/local --prefix=/tmp/bootstrap/toolchain
# ./chromeos/scripts/prepareconfig chromiumos-$ARCH
# make headers_install ARCH=$ARCH INSTALL_HDR_PATH=/tmp/headers
# http://ftp.gnu.org/gnu/make/make-3.82.tar.gz
# http://ftp.gnu.org/gnu/gawk/gawk-4.1.3.tar.xz
# curl -Ls http://www.mpfr.org/mpfr-current/allpatches | patch -N -Z -p1
#./configure --prefix=/tmp/gawk --disable-nls --disable-rpath --disable-extensions
#make -i; make -j1 install -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment