#!/bin/bash

# /*
# The OGEL Programming Language Compiler
# Copyright (c) 2003 {cwo4,gf141,mmc91,mpk43}@columbia.edu
#                                                                                
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#                                                                                
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#                                                                                
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
# */

######################################################################
# This script issues all the commands necessary to completely compile an OGEL
# source file...
#
# Author: Charles O'Donnell <cwo4@columbia.edu>
#
# This assumes that the scripts:
#     libpacker.pl, rcx10trans_opt.pl
# are already in the PATH and the ogelgen classes are 
# in the CLASSPATH
#




file_name=$1
file_stem=`echo $1 | sed 's/.ogel//'`
file_master="$file_stem.master"
file_uniogel="$file_stem.uniogel"

# for some sanity, remove old vers of overwritten files
if [ -f $file_master ]; then
   rm $file_master
fi
if [ -f $file_uniogel ]; then
   rm $file_uniogel
fi

echo "Finding Library Dependencies"
perl `which libpacker.pl` $file_name 

# after pack, should be a file $input_file_stem.master
echo "Generating UNI-OGEL source"
java ogelgen $file_master $file_uniogel

# now run final stage on the output uni-ogel.uniogel file
echo "Generating final RCX 1.0 NQC source (optimizing)"
perl `which rcx10trans_opt.pl` $file_uniogel 


