#!/usr/bin/env bash
#
# build.sh

if [ -f $1.c ]; then
   echo
   echo "--- Building $1 ---"

   if [ -f $1.s ]; then
      rm $1.s
   fi
   if [ -f $1.o ]; then
      rm $1.o
   fi
   if [ -f $1.bin ]; then
      rm $1.bin
   fi
   if [ -f $1.hex ]; then
      rm $1.hex
   fi

   cc65 -t sym1 -O $1.c
   ca65 $1.s
   ld65 -C sym1-32k.cfg -m $1.map -o $1.bin $1.o sym1.lib
   if [ -f $1.bin ]; then
      bin2hex $1.bin $1.hex > /dev/null 2>&1
   fi
   if [ -f $1.hex ]; then
      echo "--- $1.hex made ---"
   else
      echo "--- $1.hex FAIL ---"
   fi


fi

