#!/usr/bin/env bash

cd cpp
g++ wordcount_baseline.cpp -std=c++11 -o wordcount_baseline -O3
g++ wordcount.cpp -std=c++11 -o wordcount -O3
clang++-3.6 wordcount.cpp -std=c++11 -o wordcount_clang -O3

cd ../c
gcc wordcount.c -o wordcount -O3 -Wall

cd ../clojure
if [ ! -f ../clojure.jar ]; then
    wget https://oss.sonatype.org/content/repositories/snapshots/org/clojure/clojure/1.9.0-master-SNAPSHOT/clojure-1.9.0-master-20160119.195127-1.jar \
    -O ../clojure.jar
    chmod a+rx ../clojure.jar
fi

cd ../d
dmd -O -release -inline -boundscheck=off wordcount.d

cd ../elixir
MIX_ENV=prod mix escript.build > /dev/null

cd ../java
javac WordCountBaseline.java
javac -cp .:zah-0.6.jar WordCountOptimized.java

cd ../javascript
npm install

cd ../typescript
npm install --unsafe-perm

cd ../go
export GOPATH=$(pwd)
go install wordcount

cd ../guile
guild compile wordcount.scm
guild compile wordcount_reference.scm

cd ../csharp
mcs WordCount.cs

cd ../haskell
cabal install --verbose=0 --dry-run
RETURNCODE=$?
# Update if we have not already
if [ "$RETURNCODE" -ne "0" ]; then 
    cabal update 
fi
cabal install --verbose=0
cp dist/build/WordCount/WordCount .

cd ../rust/wordcount
cargo build --release
cp target/release/wordcount .
cd ..

cd ../scala
scalac Wordcount.scala