#!/bin/bash

# Path to the LLVM interpreter
LLI="lli"
#LLI="/usr/local/opt/llvm/bin/lli"

# Path to the LLVM compiler
LLC="/usr/bin/llc"

# Path to the C compiler
CC="/usr/bin/cc"


if [[ $# -ne 1 ]]; then # check if num args != 1
    echo "usage: compiler <path/to/source/code>"
    exit 1
fi

basename=`echo $1 | sed 's/.*\\///
                             s/.gw//'`

#echo -n "$basename..."
./gwiz.native $1 > $basename.ll &&
$LLC -relocation-model=pic ${basename}.ll > ${basename}.s &&
$CC -o ${basename}.exe ${basename}.s struct.o list.o parse_gpx.o -L/usr/local/opt/libxml2/lib `xml2-config --libs` -lm &&
./${basename}.exe

