#!/bin/sh
set -ex

echo "Installing Wake"

wget https://github.com/sifive/wake/releases/download/v0.19.0/ubuntu-16-04-wake_0.19.0-1_amd64.deb
sudo dpkg -i ubuntu-16-04-wake_0.19.0-1_amd64.deb


echo "Installing Protobuf"

mkdir protoc
cd protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zip
unzip protoc-3.7.1-linux-x86_64.zip
export PATH=$PATH:$PWD/bin
cd ..


echo "Installing Wit"

git clone https://github.com/sifive/wit.git --branch v0.12.0
export PATH=$PATH:$PWD/wit


echo "Initialize Workspace"

git config --global url."https://github.com/".insteadOf 'git@github.com:'
wit --repo-path $PWD/.. init workspace -a rocket-chip
cd workspace/


echo "Compile Scala"

export WAKE_PATH=$PATH
wake --init .
wake -x 'compileScalaModule rocketchipScalaModule | getPathResult'
cd ..
