#!/bin/bash
#
# Copyright © 2019 Keith Packard <keithp@keithp.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#

curdir=`pwd`
dir=`dirname $0`
cd "$dir/../.."

case $# in
    2)
    ;;
    *)
	echo "usage: $0 <build-dir> <target>" 1>&2
	exit 1
	;;
esac

build="$1"
builddir=`echo $build | sed 's/^[^:]*://'`
buildhost=`echo $build | sed 's/:.*$//'`
echo builddir "$builddir"

target="$2"

rsync -Ravz --delete `git ls-files` "$build"

ssh $buildhost "cd '$builddir'/ports/posix && make"

rsync -avz "$build"/ports/posix/snek "$curdir"/"$target"
