#!/bin/sh
# compile script for the C programs used by FeynArts
# last modified 8 Feb 00 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 have Mathematica (legally), 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
#
# c) For compiling TopEdit, you need some X11 developer's tools,
#    specifically xmkmf, imake, X11.h, Xlib.h, Xutil.h, and the
#    libX11 library. Although these files are usually part of the OS,
#    they may not have been installed in a default installation. In
#    that case ask your sysadmin to add the appropriate packages.
#
# d) There is a known problem with Linux when using glibc 2.1 or higher.
#    Some internal details have changed which make the MathLink library
#    as shipped with Mathematica incompatible. Solution: get the latest
#    version of that library at
#    http://support.wolfram.com/MathLink/Linux/RedHat6.html.


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

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

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


cat << _EOF_ > Imakefile
.SUFFIXES:

TopEdit_$HOSTTYPE: TopEdit.tm
	CC=mathcc ; export CC ; \
	sed "s/ cc / mathcc /g" $MCC | \
	sh -s TopEdit.tm \$(TOP_INCLUDES) -O6 $* -o TopEdit_$HOSTTYPE -L\$(USRLIBDIR) \$(XLIB) $SUNLIBS
	strip TopEdit_$HOSTTYPE

mpslatex_$HOSTTYPE: mpslatex.c
	gcc -O6 $* -o mpslatex_$HOSTTYPE mpslatex.c
	strip mpslatex_$HOSTTYPE

mathdict.pro:
	psfix -epsf << _EOF_ > mathdict.pro
_EOF_

xmkmf
make TopEdit_$HOSTTYPE mpslatex_$HOSTTYPE mathdict.pro
rm -f Makefile Makefile.bak Imakefile

