#!/bin/bash
HEPTC=../../heptc
HEPTC_OPTIONS="-memalloc"

GCC=gcc
GCC_OPTIONS="-g -O2 -std=c99 -I ../../../lib/c"

VERBOSE=1

interfaces=(mctypes.epi)
ext_libs=(mc_ext.epi mathext.epi)
sources=(mcinlined.ept)

for f in ${interfaces[@]}; do
    if [ $VERBOSE ] ; then
        echo "**** Compiling interface: $f *******"
    fi
    $HEPTC $HEPTC_OPTIONS -target c $f
done

for f in ${ext_libs[@]}; do
    if [ $VERBOSE ] ; then
        echo "**** Compiling external lib: $f *******"
    fi
    $HEPTC $HEPTC_OPTIONS $f
done

for f in ${sources[@]}; do
    if [ $VERBOSE ] ; then
        echo "**** Compiling source file: $f *******"
    fi
    $HEPTC $HEPTC_OPTIONS -target c $f
done

#$HEPTC $HEPTC_OPTIONS -target c -s dv_fighterdebug mcinlined.ept

source_dirs=(mctypes_c mcinlined_c)
other_files=(main.c mathext.c mathext.h mc_ext.c mc_ext.h)
if [ -d _build ]; then
   rm -r _build
fi
mkdir _build
cd _build

for f in ${source_dirs[@]}; do
    cp ../$f/* .
done
for f in ${other_files[@]}; do
    cp ../$f .
done

$GCC $GCC_OPTIONS *.c -o mission_control

cp mission_control ..

cd ..
