#!/bin/sh
# compile script for the C programs used by FormCalc
# last modified 23 Mar 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 tools/restack_$HOSTTYPE \
tools/ladj_$HOSTTYPE tools/plot_$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

tools/restack_$HOSTTYPE: tools/restack.c
	gcc \$(CFLAGS) -o tools/restack_$HOSTTYPE tools/restack.c
	strip tools/restack_$HOSTTYPE
	cd tools ; ln -sf restack_$HOSTTYPE restack

tools/ladj_$HOSTTYPE: tools/ladj.c
	gcc \$(CFLAGS) -o tools/ladj_$HOSTTYPE tools/ladj.c
	strip tools/ladj_$HOSTTYPE

tools/plot_$HOSTTYPE: tools/plot.c
	gcc \$(CFLAGS) -o tools/plot_$HOSTTYPE tools/plot.c -lm
	strip tools/plot_$HOSTTYPE
	cd tools ; ln -sf plot_$HOSTTYPE plot

_EOF_

