-
-
Save lf-/3398b6a03f6088c80d3a3cc970575339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/bin/bash | |
| set -euo pipefail | |
| SYS161="sys161-2.0.3" | |
| BINUTILS161="binutils-2.24+os161-2.1" | |
| GCC161="gcc-4.8.3+os161-2.1" | |
| GDB161="gdb-7.8+os161-2.1" | |
| #MIRROR="http://www.eecs.harvard.edu/~dholland/os161/download" | |
| MIRROR="http://people.ece.ubc.ca/~os161/download" | |
| if [[ "$#" != 1 ]]; then | |
| echo "Usage: $0 your-base-directory" | |
| echo "Example: $0 ~/tools" | |
| exit 1 | |
| fi | |
| base="$(realpath "$1")" | |
| echo "Installing tools to $base" | |
| mkdir -p $base | |
| cd $base | |
| mkdir -p os161/bin | |
| mkdir -p sys161/bin | |
| grab() { | |
| if [[ -f $1 ]]; then | |
| echo "$1 exists, skipping" | |
| return 0 | |
| fi | |
| wget "$MIRROR/$1" | |
| } | |
| echo '*** Downloading OS/161 toolchain ***' | |
| grab $BINUTILS161.tar.gz | |
| grab $GCC161.tar.gz | |
| grab $GDB161.tar.gz | |
| grab $SYS161.tar.gz | |
| unpack() { | |
| if [[ -d $1 ]]; then | |
| echo "$1 exists, skipping extract" | |
| return 0 | |
| fi | |
| tar -xzf $1.tar.gz | |
| } | |
| echo '*** Unpacking OS/161 toolchain ***' | |
| unpack $BINUTILS161 | |
| unpack $GCC161 | |
| unpack $GDB161 | |
| unpack $SYS161 | |
| nproc=$(nproc) | |
| export CXXFLAGS=-std=gnu++11 | |
| export MAKEINFO=true | |
| buildBinutils() { | |
| echo '*** Building binutils ***' | |
| if [[ -f os161/bin/mips-harvard-os161-objdump ]]; then | |
| echo "binutils already built, skipping" | |
| return 0 | |
| fi | |
| cd $BINUTILS161 | |
| find . -name '*.info' -exec touch '{}' ';' | |
| touch intl/plural.c | |
| ./configure --nfp --disable-werror --target=mips-harvard-os161 --prefix=$base/os161 2>&1 | tee ../binutils.log | |
| make -j$nproc 2>&1 | tee -a ../binutils.log | |
| make install 2>&1 | tee -a ../binutils.log | |
| cd .. | |
| echo '*** Finished building binutils ***' | |
| rm -rf $BINUTILS161 | |
| } | |
| buildGcc() { | |
| echo '*** Building gcc ***' | |
| if [[ -f os161/bin/mips-harvard-os161-gcc ]]; then | |
| echo "gcc already built, skipping" | |
| return 0 | |
| fi | |
| cd $GCC161 | |
| touch intl/plural.c | |
| rm -rf ../gcc-build | |
| mkdir ../gcc-build | |
| cd ../gcc-build | |
| ../$GCC161/configure \ | |
| --enable-languages=c,lto \ | |
| -nfp \ | |
| --disable-shared \ | |
| --disable-threads \ | |
| --disable-libmudflap \ | |
| --disable-libssp \ | |
| --disable-libstdcxx \ | |
| --disable-nls \ | |
| --target=mips-harvard-os161 \ | |
| --prefix=$base/os161 2>&1 | tee ../gcc.log | |
| make -j$nproc 2>&1 | tee -a ../gcc.log | |
| make install 2>&1 | tee -a ../gcc.log | |
| cd .. | |
| echo '*** Finished building gcc ***' | |
| rm -rf $GCC161 | |
| rm -rf gcc-build | |
| } | |
| buildGdb() { | |
| echo '*** Building gdb ***' | |
| if [[ -f os161/bin/mips-harvard-os161-gdb ]]; then | |
| echo "gdb already built, skipping" | |
| return 0 | |
| fi | |
| cd $GDB161 | |
| find . -name '*.info' | xargs touch | |
| touch intl/plural.c | |
| ./configure \ | |
| --target=mips-harvard-os161 \ | |
| --prefix=$base/os161 \ | |
| --disable-werror \ | |
| --with-python=no \ | |
| --with-guile=no \ | |
| --disable-sim \ | |
| 2>&1 | tee ../gdb.log | |
| make -j$nproc 2>&1 | tee -a ../gdb.log | |
| make install 2>&1 | tee -a ../gdb.log | |
| cd .. | |
| echo '*** Finished building gdb ***' | |
| rm -rf $GDB161 | |
| } | |
| buildSys161() { | |
| echo '*** Building System/161 ***' | |
| if [[ -f sys161/bin/sys161 ]]; then | |
| echo "sys161 already built, skipping" | |
| return 0 | |
| fi | |
| cd $SYS161 | |
| # apparently they forgot to mark this extern symbol as such in the header and | |
| # got a multiple-defn error. a cool ODR violation caught by my modern linker | |
| sed -i 's/^uint64_t extra_selecttime;$/extern uint64_t extra_selecttime;/' include/onsel.h | |
| ./configure --prefix=$base/sys161 mipseb 2>&1 | tee ../sys161.log | |
| make -j$nproc 2>&1 | tee -a ../sys161.log | |
| make install 2>&1 | tee -a ../sys161.log | |
| cd .. | |
| mv $SYS161 sys161 | |
| echo '*** Finished building System/161 ***' | |
| } | |
| buildBinutils | |
| PATH=$base/sys161/bin:$base/os161/bin:$PATH | |
| export PATH | |
| buildGcc | |
| buildGdb | |
| buildSys161 | |
| rm -rf $BINUTILS161.tar.gz | |
| rm -rf $GCC161.tar.gz | |
| rm -rf $GDB161.tar.gz | |
| rm -rf $SYS161.tar.gz | |
| cd os161/bin | |
| for file in *; do | |
| ln -sf $file ${file:13} | |
| done | |
| cd ../.. | |
| cat > $base/activate <<EOF | |
| export PS1="(os161) \${PS1:-}" | |
| export PATH="$base/sys161/bin:$base/os161/bin:\$PATH" | |
| EOF | |
| activate_path=$base/activate | |
| printf 'Source %s (`. %s`) to use the toolchain\n' "$activate_path" "$activate_path" | |
| echo '*** Done ***' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment