Skip to content

Instantly share code, notes, and snippets.

@KatrinaHoffert
Last active August 29, 2015 14:10
Show Gist options
  • Save KatrinaHoffert/450156ce3d8a0c9cbf32 to your computer and use it in GitHub Desktop.
Save KatrinaHoffert/450156ce3d8a0c9cbf32 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# By Mike Hoffert. Based on build-kernel.sh in OS161.
#
# Alternative build script. Only errors are shown. Will automatically
# configure the script.
#
# Usage:
# ./build-kernel2 <kernel-name> [options]
#
# Parameters:
# -q: Quiet mode -- disables all unnecessary output. Only errors will be shown.
# -c: Clean first -- will clean before we build. Slower.
# -r: Run on successful build
#
# Example:
# ./build-kernel2.sh ASST2 -cr
PATH=/www/docs/classes/332/t1/os161/bin:$PATH
# Change this to redirect output into a file
OUTPUT=/dev/null
quietMode=0
cleanMode=0
runMode=0
# Skip first option
OPTIND=2
while getopts "qckur" opt; do
case "$opt" in
q)
quietMode=1
;;
c)
cleanMode=1
;;
r)
runMode=1
;;
esac
done
# Clean if we're supposed to
if [ $cleanMode -eq 1 ] ; then
if [ $quietMode -eq 0 ] ; then echo "Cleaning OS161"; fi
./clean-kernel2.sh > "$OUTPUT"
# Cleaning causes an issue that requires that we build twice. So we'll
# ignore any possible errors on this initial build.
if [ $quietMode -eq 0 ] ; then echo "Performing clean build (this can take a while)"; fi
./conf-kernel.sh $1 > "$OUTPUT" 2>&1
cd src
./configure --ostree=`pwd`/../root > "$OUTPUT" 2>&1
cd kern/compile/$1
bmake depend > "$OUTPUT" 2>&1
bmake > "$OUTPUT" 2>&1
bmake install > "$OUTPUT" 2>&1
cd ../../../
bmake depend > "$OUTPUT" 2>&1
bmake > "$OUTPUT" 2>&1
bmake install > "$OUTPUT" 2>&1
cd ..
fi
# Kind of a hacky way of writing a "try-catch" block. See:
# <http://stackoverflow.com/a/22010339/1968462>.
{
if [ $quietMode -eq 0 ] ; then echo "Building $1"; fi
./conf-kernel.sh $1 > "$OUTPUT" &&
cd src &&
./configure --ostree=`pwd`/../root > "$OUTPUT" &&
cd kern/compile/$1 &&
bmake depend > "$OUTPUT" &&
bmake > "$OUTPUT" &&
bmake install > "$OUTPUT" &&
if [ $quietMode -eq 0 ] ; then echo "Kernel build succeeded"; fi &&
cd ../../../ &&
bmake depend > "$OUTPUT" &&
bmake > "$OUTPUT" &&
bmake install > "$OUTPUT" &&
if [ $quietMode -eq 0 ] ; then echo "Userspace build succeeded"; fi &&
cd .. &&
# We succeeded. Run the kernel
if [ $runMode -eq 1 ] ; then ./boot-kernel.sh $1 ; fi
} || {
echo
echo "========================================="
echo "==== There were errors in the build. ===="
echo "========================================="
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment