#!/bin/bash

set -eu -o pipefail

help() {
  echo "$0 [options] <command>"
}

#help ; exit 0

# configuration
CC="gcc"
LLC="llc"
WGET="wget -q --show-progress --progress=bar:force"
URL="https://prcsoft.net/pl3/rel/"
# end configuration

pkgs=(
  "1.0.0dev0"
  "1.0.0dev1"
  "1.0.0dev2"
)

comp="none"

bld() {
  echo "# $1"

  bin="pl3-$1"
  src="pl3-$1-src.tar.xz"
  dir="pl3-$1-src"

  $WGET "$URL/$src" -O "$src"
  rm -rf "$bin" "$dir"
  tar -Jxf "$src"
  cd "$dir"

  make all check PL3=$comp

  cd ..
  rm -f "$bin"
  ln -s "$dir/$bin"
  comp="../$dir/$bin"
}

for pkg in ${pkgs[@]} ; do
  bld $pkg
done

exit 0
