#!/bin/sh

n=run
S=`dirname $0`/../main
D=$HOME/.cache/easylang

mkdir -p $D

test ! -e $D/$n && compile=1
h="$S/kfunc.h $S/klib.h $S/klex.h $S/kparse.h $S/../native/kbgr.c $S/kwasm.h $0"
f="$S/kbas.c"
for i in $f $h; do
  test $i -nt $D/$n && compile=1
done

if test $compile; then
  rm -f $D/$n
  cc=clang
  which $cc >/dev/null || cc=gcc
  HB=/opt/homebrew
  echo "Compiling easylang (with $cc) ..." >&2
  $cc -Wall -O2 -D__SDL__ -I$S -I$HB/include -L$HB/lib -O $f -lSDL2 -lSDL2_ttf -lm -o $D/$n
  echo "done" >&2
fi

if test -x $D/$n; then
#	t0=$(date +%s.%2N)
	$D/$n $*
#	echo "$(date +%s.%2N) - $t0" | bc -l
fi

