#!/usr/bin/env bash

set -e

[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en .stack-work.lock "$0" "$@" || :

move-back() {
    mv -v .stack-work .stack-work-doc
    [[ -d .stack-work-build ]] && mv -v .stack-work-build .stack-work
}

if [[ -d .stack-work-doc ]]; then
    [[ -d .stack-work ]] && mv -v .stack-work .stack-work-build
    mv -v .stack-work-doc .stack-work
    trap move-back EXIT
fi

stack build --fast --flag uniworx:library-only --flag uniworx:dev --haddock --haddock-hyperlink-source --haddock-deps --haddock-internal
