#!/bin/bash
# Compiles an art program to an executable

# Path to ART compiler
if [ -e "./art.native" ]
then
    ART="./art.native"
elif [ -e "./art" ]
then
    ART="./art"
else
    echo "No art compiler found. Attempting build..."
    echo ""
    make clean
    if make 
    then
        ART="./art.native"
    else
        echo -e "\nBuild Failed!!!" && exit 2
    fi
fi



base=`echo "$1" | sed 's/.*\\///
                             s/.art//'`

if [ -z "$2" ]
then 
    out=./$base
else
    out="$2"
fi

if [ -z "$3" ]
then 
    tmp="/tmp"
else
    tmp="$3"
fi

${ART} < $1 > ${tmp}/${base}.ll &&
llc ${tmp}/${base}.ll &&
gcc ${tmp}/${base}.s -g -lm -lglut -lGLU -lGL -o $out 

