#!/bin/sh
# compile script for the C programs used by FormCalc
# last modified 11 Feb 03 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.  You may need to change
#    CFLAGS to e.g. relax strict ANSI compliance.
#
# b) You need mcc.  mcc is a script which compiles MathLink programs.
#    Such programs have the extension .tm.  If you have Mathematica,
#    you should also have mcc.  If mcc is not on the path, specify it
#    in the environment variable MCC, e.g.
#    setenv MCC /opt/mathematica/Executables/Linux/mcc

MCC=`which ${MCC:-mcc}`

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

eval `awk '/^sysid=/ { print $0; exit; }' $MCC`

[ -d $sysid ] || mkdir $sysid

make -f - << _EOF_
all: $sysid/ReadForm $sysid/ToForm $sysid/ToFortran $sysid/ReadData

CC = gcc
CFLAGS = -O3 -fomit-frame-pointer $*

$sysid/ReadForm: ReadForm.tm
	CC=\$(CC) $MCC ReadForm.tm \$(CFLAGS) -o $sysid/ReadForm
	strip $sysid/ReadForm

$sysid/ToForm: ToForm.c
	\$(CC) \$(CFLAGS) -o $sysid/ToForm ToForm.c
	strip $sysid/ToForm

$sysid/ToFortran: ToFortran.c
	\$(CC) \$(CFLAGS) -o $sysid/ToFortran ToFortran.c
	strip $sysid/ToFortran

$sysid/ReadData: tools/ReadData.tm
	CC=\$(CC) $MCC tools/ReadData.tm \$(CFLAGS) -o $sysid/ReadData
	strip $sysid/ReadData
_EOF_

