#!/bin/csh
# makeBallista: makes the Ballista test for a specified function
# Copyright (C) 1998-2001  Carnegie Mellon University
#
# 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.

if ( ! -e MakefileHost || ! -e MakefileTarget ) then
    /bin/echo Missing either MakefileHost or MakefileTarget.
    /bin/echo Please run configure.
    exit 1
endif

if ( "$1" == '-c' ) then
    shift
    /bin/echo Cleaning up
#    make -f MakefileHost clean >& /dev/null
    make -f MakefileTarget clean >& /dev/null
endif

setenv FUNCTION $1
setenv PERL5LIB `pwd`/perllib

# print usage information when bad args are given
if ( $#argv == 0 ) then
    /bin/echo ""
    /bin/echo usage: makeBallista \[-c\] callName
    /bin/echo ""
    /bin/echo Where callName is the name of the function to be tested 
    /bin/echo The -c argument cleans up all old files before building
    /bin/echo ""
    exit 1
endif

# store mut name in file mut so we can determine what the last build built
if ( $1 != `cat mut` ) then
    echo $1 > mut
endif

/bin/echo Function: $FUNCTION

# create dataTypes file
./dataClimber $FUNCTION

setenv OBLIST

foreach A(`grep -v '#' dataTypes | awk '{print$1}'`)
    setenv OBLIST "$OBLIST templates/$A.o"
end

/bin/echo Datatype list: $OBLIST

setenv LLIST

if (!(-e userLibs)) then
    /bin/echo Warning: userLibs not found.  No user compiler flags used.
else
    foreach A(`grep -v "#" userLibs`)
	setenv LLIST "$LLIST $A"
    end
endif

#add the system OS libraries
if (!(-e osLibs)) then
    /bin/echo Warning: osLibs not found.  Link errors will most likely result.
else
    foreach A(`grep -v "#" osLibs`)
	setenv LLIST "$LLIST $A"
    end
endif

/bin/echo Compiler options: $LLIST

/bin/echo
/bin/echo

# should bail if any of these fail...
# make -f MakefileHost
make -rf MakefileTarget


