Skip to content

Instantly share code, notes, and snippets.

@kousu
Last active May 13, 2016 10:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kousu/16c6af510db5d2aac220 to your computer and use it in GitHub Desktop.
Save kousu/16c6af510db5d2aac220 to your computer and use it in GitHub Desktop.
Cs350 OS161 Install scripts
If you're on Archlinux you shouuuuld just be able to drop these two files in a dir by themselves, chmod +x them, and run "install.sh".
If you're on a different Unix you can probably adapt this without too much effort to your system, especially the part about .
If you're not in Winter 2015 you probably need to tweak update.sh.
Sorry for the poor documentation and poor testing! And also the almost complete lack of error handling!
Hopefully this helps someone else in the future! this represents 13 hours of my life!
Tip: make your empty dir a git repo so that then you can just do
```
git clean -df && git clean -xfd
```
if this breaks on you and you need to restart.
#!/bin/bash
# install the os161 dev environment on ArchLinux
# current as of January 2015
# <nguenthe@uwaterloo.ca>
# in bash since I like 'pushd'
# depends:
# wget
# tar
# gcc
# NOT texinfo because Arch's texinfo is *too new* to be compatible with this toolchain, and anyway all it's used for is gnu info pages and who cares about those?
# ncurses
# TODO: write this as a makefile (how can I get a makefile to use "has bmake installed" as a dependency??)
# or at least implement error checking.
# this is based on the instructions at https://www.student.cs.uwaterloo.ca/~cs350/common/Install161NonCS.html
# this creates this layout:
# build/ - where
# src/ - the kernel source, from the os161.tar.gz file (and then for you to work on further)
# tools/ - the PREFIX (in the makefile sense) where the toolchain gets installed
# bin/ - programs in the toolchain
# man/ - manpages in the toolchain
# src/ - where source code for the toolchain is unpacked (you needn't keep this around once its built)
# etc.
# to reset to a pristine state:
# rm -r build src tools
# or: git clean -df && git clean -xfd
# to just clean
HERE=$(dirname $0)
export PREFIX=$(realpath tools/) #
ARCH=mips-harvard-os161 #
# Install dependencies that we can find in our package manager.
# note: if you are adapting this to Debian (/Mint/Ubuntu/etc)
# be aware that bmake is not in stable but it *is* currently
# in testing: https://packages.debian.org/sid/bmake
# but it might be simpler just to use the package from the CS350 site
for pkg in gettext texinfo ncurses bmake; do
if ! pacman -Q $pkg 2>/dev/null; then
echo "Please install $pkg:"
sudo pacman -S $pkg
fi
done
# Download the CS350 sys161/os161 distribution packages one at a time
# to avoid downloading too much--more than just what we need is on this site
# notice that we *skip* bmake (and mk which is a separate file yet built as a part of bmake) since bmake is in the Arch repos
#..hmmm. maybe this shouldn't redownload; that's a pretty heavy investment to require,
# esp if things break and you need to redo them
# maybe I should just say that you are obligated to use update.sh in order to use this
echo "Downloading cs350 MIPS cross compiler toolchain"
echo "Expect this to take 5 minutes"
${HERE}/update.sh
mkdir -p $PREFIX/src
for pkg in os161-binutils os161-gcc os161-gdb sys161; do
# even though these the -r makes wget place the files
tar -zxvf www.student.cs.uwaterloo.ca/~cs350/os161_repository/$pkg.tar.gz -C $PREFIX/src
done
echo "Building cs350 MIPS cross-compiler toolchain"
echo "Expect this to take 5 minutes"
pushd $PREFIX/src
# we do all these steps explicitly since
# a) it's important to build binutils first, because the gcc build breifly needs its version of ar(1).
# (we could parallelize the building of gdb, however (I.. think))
# b) each install has slightly different configure args; tho I haven't tested what happens if I don't play along with that.
#
pushd binutils*
./configure --nfp --disable-werror --target=$ARCH --prefix=$PREFIX &&
make &&
make install &&
popd
export PATH=$PREFIX/bin:$PATH #make this next build able to find $ARCH-ar
pushd gcc*
./configure -nfp --disable-shared --disable-threads --disable-libmudflap --disable-libssp --target=$ARCH --prefix=$PREFIX &&
make && make install &&
popd
pushd gdb*
./configure --disable-werror --target=$ARCH --prefix=$PREFIX &&
make MAKEINFO=true && #MAKEINFO=true is a dirty trick that convinces this build to ignore the fact that its infopage syntax is *too old*; in fact it just doesn't build the infopages at all
make install MAKEINFO=true
popd
pushd sys161*
./configure --prefix=$PREFIX mipseb &&
make &&
make install
popd
popd # $PREFIX/src/. back to the top level.
# by default, sys161 needs this file in its working directory to run named exactly so
cp tools/src/sys161-1.99.06/sys161.conf.sample sys161.conf
# set up the last parts of the build environment
mkdir build
# extract the 0s161 source to src/
echo "Extracint OS161 source code"
echo "Expect this to take 1 minutes"
OS161=www.student.cs.uwaterloo.ca/~cs350/os161_repository/os161.tar.gz
tar -zxvf $OS161
OS161=$(tar -ztf $OS161 | head -n 1) #get the name of the single top level folder in the archive. there's probbbbbably a better way to do this
mv $OS161 src/
unset OS161
pushd src/
./configure --ostree=$(realpath ../build) --toolprefix="$ARCH-"g #this writes ./defs.mk; the toolprefix defaults to cs350-, but since we just got rid of all prefixes this is wrong.
popd
echo "Build finished(probablylolnoerrorcheckinginherereally)"
echo
echo "Try building a kernel:"
echo "pushd src/"
echo "cd kern/config"
echo "./config ASST0"
echo "cd ../compile/ASST0"
echo "bmake depend"
echo "bmake"
echo "bmake install"
echo "popd"
echo
echo "And then running it:"
echo "sys161 build/kernel"
echo
echo "And try building userland"
echo "pushd src/"
echo "bmake"
echo "bmake install" #places
echo "popd"
echo
echo "You may want to 'rm -rf tools/src/' as well."
#!/bin/sh
echo "Updating local CS350 site copy"
# These options make wget behave somewhat like rsync; without -r
# If you remove -N then wget will redownload all the things despite their timestamps
#... ugh:
# "When running Wget with ‘-r’ or ‘-p’, but without ‘-N’, ‘-nd’, or ‘-nc’, re-downloading a file will result in the new copy simply overwriting the old."
# but this is *not true*; empirically, I'm seeing
# and --backups=0 doesn't work either
# fuckkkkkkk you wget
wget --progress=bar -r -p -N -np http://www.student.cs.uwaterloo.ca/~cs350/W15/
find -regextype posix-egrep -regex ".*\.[[:digit:]]$" | while read stupid_wget_backup; do
rm $stupid_wget_backup;
done
git add www.student.cs.uwaterloo.ca
if ! git diff --staged --quiet www.student.cs.uwaterloo.ca; then #-> no changes -> output 0 -> considered "true" by bash, so we need "!"
# tip from http://stackoverflow.com/questions/13715544/shell-script-to-check-git-for-changes-and-then-loop-through-changed-files
git status
echo -n "Do you want to commit the new copy? [Y/n] "; read ANS
if [ x$ANS = x"y" ]; then
git commit -v
fi
# whether or not the user followed through on the commit, undo the `git add` above.
git reset HEAD www.student.cs.uwaterloo.ca
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment