#!/bin/sh

. ~/.bin/_config

set -xe

_install()
{
    _make
    export PKG_ADD="/usr/sbin/pkg_add -a"
    export FETCH_PACKAGES=No
    make install

}

_reinstall()
{
    _make
    export PKG_ADD="/usr/sbin/pkg_add -a"
    export FETCH_PACKAGES=No
    make reinstall
}

_fake()
{
    _make
    make fake
}

_refake()
{
    _make
    make clean=fake
    make fake
}

_clean()
{
    make clean="all"
}

_realclean()
{
    _clean
    make clean=dist
}

_makesum()
{
    make -j10 makesum
}

_fetch()
{
    make -j10 fetch
}

_refetch()
{
    make clean=dist
    make -j10 fetch
}

_make()
{
    export PKG_ADD="/usr/sbin/pkg_add -a"
    export FETCH_PACKAGES=-Dsnap
    make install-depends
    _fetch
    export FETCH_PACKAGES=No
    make
}

_update-go()
{
    needs go--
    make MODGO_VERSION=latest modgo-gen-modules > modules.inc.new
}

case $1 in
         fake)     _fake; ;;
       refake)     _refake; ;;
      install)     _install; ;;
    reinstall)     _reinstall; ;;
        clean)     _clean; ;;
    realclean)     _realclean; ;;
      makesum)     _makesum; ;;
    remakesum)     _remakesum; ;;
    update-go)     _update-go; ;;
    *)             [ -z "$1" ] && _make; ;;
esac
