# $Id$

# Master makefile for Mathematica part of Heisenberg

####################################################################
# Configuration section

# PWD = complete pathname of the dir containing this makefile.  If you
# are using csh this should be set automatically by the shell.
# Otherwise, remove the comment char from the next line and append the
# pathname of this dir.
# PWD = 

# BINDIR = dir in which to install executable files.  This is used by
# 'make install'.  By default (as this Makefile is distributed),
# executables are placed in a subdir of this dir called 'bin'.  If you
# want to put them somewhere else, change the def here, preferably to
# a dir which is on your search path.
BINDIR = $(PWD)/bin

# OPTIONS = compiler options
OPTIONS=-O

# BSDPREFIX = prefix for "BSD style" header files sys/types.h,
# sys/socket.h, netinet/in.h, netdb.h, and strings.h.  On Suns and other
# Berkeley Unix systems, leave the def of BSDPREFIX commented out.  On
# IRISes it should be
#   BSDPREFIX = bsd/
# (the last thing on the line should be the '/' --- no trailing blanks!)
# BSDPREFIX = 

# BSDLIBS = any library flags which are necessary to load the BSD
# libraries.  On Suns and other Berkeley Unix systems, leave the def
# of BSDPREFIX commented out.  On IRISes it should be
#   BSDLIBS = -lbsd
# BSDLIBS = 

# CP = copying command for use in installation. Should be 'ln' or 'cp'.
CP=ln

# HEISENBERGPATH = pathname, on graphics host, of executable file
# 'heisenberg'.  This is used only by the Heisenberg shell script.
HEISENBERGPATH = $(PWD)/../graphics/bin/heisenberg

# ELBOWDPATH = pathname, on graphics host, of executable file
# 'elbowd'.  This is used only by the Heisenberg shell script.
ELBOWDPATH = $(PWD)/../graphics/bin/elbowd

# MATHDIR = pathname on your Mathematica host of the Mathematica root dir.
# This is the dir containing the subdirs Bin.*, Init, Packages, etc.
MATHDIR = /Lakisis/usr/local/lib/math2

# MACHDIR = name of the subdirectory of the Mathematica root dir
# containing the Mathematica executable file 'mathexe'.  Use
# 	MACHDIR = Bin.sun3 	(for Sun 3's)
#   or	MACHDIR = Bin.sun4	(for Sun 4's)
#   or	MACHDIR = Bin.Iris 	(for IRISes)
# etc.
MACHDIR = Bin.sun3

# End configuration section --- don't change anything below here
####################################################################

INSTALL_BIN = $(PWD)/instl

HEISMATHPATH = $(BINDIR)/HeisMath

HEISPACKAGEPATH = $(PWD)/Packages

INSTALL = $(INSTALL_BIN) -cp "$(CP)"

SHELL = /bin/sh

MATHPIPE_MAKE_OPTIONS =  \
  PWD="$(PWD)/mathpipe"  \
  OPTIONS="$(OPTIONS)"  \
  BINDIR="$(BINDIR)"  \
  CP="$(CP)"  \
  INSTALL_BIN="$(INSTALL_BIN)" \
  BOTHPIPEDIR="$(PWD)/bothpipe" \
  SYS_TYPES_H="<$(BSDPREFIX)sys/types.h>" \
  SYS_SOCKET_H="<$(BSDPREFIX)sys/socket.h>" \
  NETINET_IN_H="<$(BSDPREFIX)netinet/in.h>" \
  NETDB_H="<$(BSDPREFIX)netdb.h>" \
  STRINGS_H="<$(BSDPREFIX)strings.h>" \
  LIBS="$(BSDLIBS)"

PACKAGES_MAKE_OPTIONS = \
  MATHPIPEPATH="$(BINDIR)/mathpipe"

SED_ARGS = \
  -e 's|HEISPACKAGEPATH|$(HEISPACKAGEPATH)|' \
  -e 's|MATHDIR|$(MATHDIR)|' \
  -e 's|MACHDIR|$(MACHDIR)|' \
  -e 's|HEISENBERGPATH|$(HEISENBERGPATH)|' \
  -e 's|ELBOWDPATH|$(ELBOWDPATH)|' \
  -e 's|HEISMATHPATH|$(HEISMATHPATH)|'

OBJS = Heisenberg HeisMath

####################################################################

all:	compile_mathpipe compile_packages scripts

$(BINDIR):
	mkdir $(BINDIR)

scripts:	Heisenberg HeisMath

compile_mathpipe:
	cd mathpipe ;				\
	$(MAKE)					\
	  $(MATHPIPE_MAKE_OPTIONS)

compile_packages:
	cd Packages ;			\
	$(MAKE)				\
	  $(PACKAGES_MAKE_OPTIONS)

install:	install_quietly
	@echo ''
	@echo 'Installation of the Mathematica part of Heisenberg is now'
	@echo 'complete. The executable files for the Mathematica host'
	@echo 'are in the directory'
	@echo '     $(BINDIR)'
	@echo ''

install_quietly:	$(BINDIR) install_mathpipe install_packages \
			install_scripts

install_mathpipe:
	cd mathpipe ;				\
	$(MAKE)					\
	  $(MATHPIPE_MAKE_OPTIONS)		\
	  install

install_packages:
	cd Packages ;				\
	$(MAKE)					\
	  $(PACKAGES_MAKE_OPTIONS)		\
	  install

HeisMath:	rm-HeisMath HeisMath.tpl
	sed \
	  $(SED_ARGS) \
	  -e 's|#TPLWARNING|# DO NOT EDIT THIS FILE DIRECTLY!  EDIT ONLY THE CORRESPONDING .tpl FILE.|' \
	  -e '/#TPL.*$$/d' \
	  < HeisMath.tpl > HeisMath
	chmod -w,+x HeisMath

rm-HeisMath:
	/bin/rm -f HeisMath ;

Heisenberg:	rm-Heisenberg Heisenberg.tpl
	sed \
	  $(SED_ARGS) \
	  -e 's|#TPLWARNING|# DO NOT EDIT THIS FILE DIRECTLY!  EDIT ONLY THE CORRESPONDING .tpl FILE.|' \
	  -e '/#TPL.*$$/d' \
	  < Heisenberg.tpl > Heisenberg
	chmod -w,+x Heisenberg

rm-Heisenberg:
	/bin/rm -f Heisenberg ;

install_scripts:	HeisMath Heisenberg
	$(INSTALL) '$(BINDIR)' HeisMath Heisenberg

heismath.tar.Z:	heismath.tar
	compress heismath.tar

heismath.tar:	rm-heismath.tar
	tar chbf 512 /tmp/heismath.tar *
	/bin/mv /tmp/heismath.tar .

rm-heismath.tar:
	/bin/rm -f heismath.tar ;

localclean:
	/bin/rm -f *~ ;

clean:	localclean
	cd mathpipe ; $(MAKE) clean
	cd Packages ; $(MAKE) clean

veryclean:	localclean
	cd mathpipe ; $(MAKE) veryclean
	cd Packages ; $(MAKE) veryclean

distclean:	localclean
	/bin/rm -r -f ./bin
	cd mathpipe ; $(MAKE) distclean
	cd Packages ; $(MAKE) distclean
