#!/bin/bash

set -eu
set -o pipefail

sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install python2.7
sudo apt-get install node # They said nodejs, but that wasn't found by apt-get
sudo apt-get install default-jre

# Your system may provide Node.js as node instead of nodejs. In that case, you may need to also update the NODE_JS
# attribute of your ~/.emscripten file.

sudo apt-get install git-core

cd ~/emsdk

if [ -d src ]
then
    # Don't rebuild if we already have it
    exit 0
fi

cobble || true

cd src

# Fetch the latest registry of available tools.
./emsdk update

# Download and install the latest SDK tools.
./emsdk install latest

# Set up the compiler configuration to point to the "latest" SDK.
./emsdk activate latest

# Linux/Mac OS X only: Set the current Emscripten path
source ./emsdk_env.sh