#!/bin/sh
# compile script for the C programs used by FormCalc
# last modified 25 Jul 01 th

# If this compile script doesn't work on your system, check these things:
#
# a) You need gcc. If that's not installed on your system, change all
#    "gcc"s to "cc"s, but have your fingers crossed: not all ccs will
#    compile MathLink programs without errors. Sometimes you might need
#    to add switches to relax strict ANSI compliance.
#
# b) You need mcc. mcc is a script which compiles C programs that
#    contain MathLink code. Such programs have the extension .tm.
#    Presumably, if you legally own Mathematica, you should also have
#    mcc. However, some sysadmins seem to be stupid enough not to place
#    mcc in the path, so you might have to specify the full path in the
#    "MCC=" line below, typically something like
#    MCC=/usr/local/mathematica/AddOns/MathLink/DevelopersKits/Linux/CompilerAdditions/mcc


MCC=`csh -cf "which ${MCC:-mcc}"`

if [ ! -x "$MCC" ] ; then
  echo "You need mcc (the MathLink C compiler) to compile ReadForm"
  exit
fi

SUNLIBS=""
echo "$HOSTTYPE" | grep sun > /dev/null && SUNLIBS="-lnsl -lsocket"

make -f - << _EOF_
all: ReadForm_$HOSTTYPE ToForm_$HOSTTYPE ToFortran_$HOSTTYPE \
tools/ReadData_$HOSTTYPE

CFLAGS = -O6 $*

ReadForm_$HOSTTYPE: ReadForm.tm
	CC=gcc ; export CC ; \\
	  sed "s/ cc / gcc /g" $MCC | \\
	  sh -s ReadForm.tm \$(CFLAGS) -o ReadForm_$HOSTTYPE $SUNLIBS
	strip ReadForm_$HOSTTYPE

ToForm_$HOSTTYPE: ToForm.c
	gcc \$(CFLAGS) -o ToForm_$HOSTTYPE ToForm.c
	strip ToForm_$HOSTTYPE

ToFortran_$HOSTTYPE: ToFortran.c
	gcc \$(CFLAGS) -o ToFortran_$HOSTTYPE ToFortran.c
	strip ToFortran_$HOSTTYPE

tools/ReadData_$HOSTTYPE: tools/ReadData.tm
	cd tools ; CC=gcc ; export CC ; \\
	  sed "s/ cc / gcc /g" $MCC | \\
	  sh -s ReadData.tm \$(CFLAGS) -o ReadData_$HOSTTYPE $SUNLIBS
	strip tools/ReadData_$HOSTTYPE
	cd tools ; ln -sf ReadData_$HOSTTYPE ReadData

_EOF_

