#!/bin/sh

############################################################################
#cr                                                                       
#cr            (C) Copyright 1995 The Board of Trustees of the            
#cr                        University of Illinois                         
#cr                         All Rights Reserved                           
#cr                                                                       
############################################################################

############################################################################
# RCS INFORMATION:
#
# 	$RCSfile: configure,v $
# 	$Author: billh $	$Locker:  $		$State: Exp $
#	$Revision: 1.50 $	$Date: 1995/03/28 03:50:17 $
#
############################################################################
# DESCRIPTION:
#
# Main configuration script for vmd.
#
# Usage:
#	configure [ [arch] [optionlist] ]
#    where
#	arch = IRIX4 | IRIX5 | HPUX9 | HELP (if HELP is given, this
#		info is presented)
#	optionlist = one or more of the following options, separated by
#			spaces:
#		FORMS		- use GL and FORMS library for graphics and GUI
#		TEXT		- do not use any GUI library at all .. only text
#		REMOTE		- include remote simulation connection option
#		NOREMOTE	- do not include remote simulation option
#		CAVE | CAVESIM	- include cave display option
#		UNC		- use UNC tracker library for spatial tracker
#		EXTERNAL        - allow external input via PVM (experimental)
#		DEBUG		- including debugging statements
#		OPTIMIZE	- compile with standard optimization (ie -O)
#		ALL		- FORMS, REMOTE, CAVE, UNC, OPTIMIZE
#		NONE		- no options at all
#		NOMAKE		- does not do the co & make after configuring
#		MAKE		- does co & make after configuring
#
# If no arguments are given, the file 'configure.options' is checked; if it
# exists, the contents of the file are used for the current options.  Upon
# completion of a successful configure, configure.options is rewritten with
# a copy of the most recently used options.
#
# Configuration parameters are read from the file 'configure.parameters' if it
# exists; this file can contain values for configuration params in the format
#				<keyword>=<value>
# with no spaces between <keyword> and <value>.  The keywords are all described
# in the installation guide and at the beginning of this script; default values
# for all parameters are first declared at the start of this script, after
# which the file configure.parameters is read which can contain new values for
# selected parameters.
#
# This script may be run from the main vmd directory, or any of the
# subdirectories within it.
############################################################################
# REVISION HISTORY:
#
# $Log: configure,v $
# Revision 1.50  1995/03/28  03:50:17  billh
# Added CommandQueue.C
#
# Revision 1.49  1995/03/25  02:45:56  billh
# distrib target now strips executable.
# +e1 option added for SGI's; linker output directed to dev/null
#
# Revision 1.48  1995/03/24  18:54:28  billh
# Added many new files (source code moved from .h to .C files)
#
# Revision 1.47  95/03/21  00:40:39  billh
# Puts copyright notice at top of generated Makefile as well.
# 
# Revision 1.46  1995/03/21  00:34:01  billh
# Added copyright notice.
#
# Revision 1.45  1995/03/17  22:30:11  billh
# Updated located of ftp directory.
#
# Revision 1.44  1995/03/04  06:04:07  billh
# Added more files, used for labelling items via the mouse
#
# Revision 1.43  95/02/27  17:54:59  dalke
# Added TrackerForms.
# 
# Revision 1.42  1995/02/27  02:29:30  dalke
# Added the "External" interface
#
# Revision 1.41  1995/02/22  05:13:43  billh
# Added first set of files used for picking objects.
#
# Revision 1.40  1995/02/12  07:12:15  dalke
# Added changes for new input types
#
# Revision 1.39  1995/01/31  21:46:04  billh
# distribution now has the ptrepository directory removed to save space.
#
# Revision 1.38  1995/01/30  21:04:02  billh
# Added template source files, small syntax changes.
#
# Revision 1.37  1995/01/18  23:37:08  billh
# Fixed errors in distribution target.
#
# Revision 1.36  95/01/18  23:02:41  billh
# Added NOUNC option.
# Now produces gzipped version of distribution as well.
# Fixed problem with creating distribution configure.parameters
# 
# Revision 1.35  95/01/13  16:28:54  billh
# Now makes link to latest version in FTP directory for 'make ftp' command.
# 
# Revision 1.34  95/01/12  17:52:35  billh
# Fixed distribution  commands so the configure.parameters file is properly
# placed in the distribution.
# 
# Revision 1.33  95/01/09  20:09:52  billh
# Make depend no longer does a 'make savedepend' at the end for SGI's.
# Make distrib removes .o files and pictures link without complaining.
# Make ftp also copies over the latest copy of the README file.
# 
# Revision 1.32  95/01/09  10:04:42  billh
# Added 'make ftp' option.
# 
# Revision 1.31  1995/01/09  09:40:14  billh
# BIG changes ... added many more co and doc targets, changed to read
# file configure.parameters, added new documentation files, changed
# how 'make version' works.
#
# Revision 1.30  1994/12/06  08:35:03  billh
# Added color object files: CmdColor, ColorFormsObj, ColorUser
#
# Revision 1.29  94/11/30  01:50:19  billh
# Added 'make install' option.
# 
# Revision 1.28  1994/11/27  23:21:12  billh
# Finished distrib target; added many files needed for distribution, such
# as data files, run script, and README.
#
# Revision 1.27  1994/11/27  03:06:46  billh
# Started to add distrib target commands.
#
# Revision 1.26  1994/11/26  07:44:23  dalke
# Fragment, Residue, quickstart
#
# Revision 1.25  1994/11/24  07:28:30  dalke
# Added some render stuff, and split up UIText into two parts
#
# Revision 1.24  1994/11/22  08:27:59  billh
# Added EditFormsObj and CoorFileData files.
#
# Revision 1.23  94/11/12  10:27:30  dalke
# added Tokenize and Tree
# 
# Revision 1.22  1994/11/09  05:09:17  billh
# Added VRegionList files.
#
# Revision 1.21  1994/11/08  21:44:17  billh
# Added DrawPatch routines.
#
# Revision 1.20  1994/11/08  09:11:14  dalke
# Added CaveTracker
#
# Revision 1.19  1994/11/07  07:23:01  dalke
# Added GrabTool
#
# Revision 1.18  1994/11/02  16:39:20  billh
# Took out .vmd_init from VMD_EXTRA
#
# Revision 1.17  1994/11/02  05:18:10  dalke
# added ConfigList
#
# Revision 1.16  1994/11/01  11:23:26  dalke
# Added new CAVE files
#
# Revision 1.15  1994/10/29  02:25:43  billh
# added GraphicsFormsObj files.
#
# Revision 1.14  1994/10/28  18:37:01  billh
# Added GLMouse files; updated compiling rule to send unwanted info messages
# to /dev/null; fixed depend target for SGI's to also get optional defines.
#
# Revision 1.13  1994/10/26  23:23:29  billh
# Added DrawMolecule.C file.
#
# Revision 1.12  1994/10/24  08:08:40  dalke
# Added the start of documentation
#
# Revision 1.11  1994/10/21  03:54:17  billh
# Added RemoteList and SimFormsObj files.
#
# Revision 1.10  1994/10/20  01:32:59  billh
# Added files MolAction.h and CmdAnimate.C and .h .
# Added files AnimateFormsObj.C and .h
#
# Revision 1.9  1994/10/12  08:41:21  dalke
# added Timer class
#
# Revision 1.8  1994/10/07  08:39:03  dalke
# Added VMDTitle.[Ch]
#
# Revision 1.7  1994/10/05  07:47:39  billh
# Fixed to allow compilation on HP
#
# Revision 1.6  1994/10/04  22:24:09  billh
# Added HELP, NONE, NOMAKE options.
#
# Revision 1.5  94/10/04  21:42:13  dalke
# Added VButton.C
# 
# Revision 1.4  1994/10/04  20:30:37  billh
# Changed cc and CC options for HP's.
#
# Revision 1.3  1994/10/04  19:16:45  billh
# Changed from cp -f to cp, mv -f for both HP asnd SGI to use.
#
# Revision 1.2  1994/10/04  08:00:01  billh
# Made sure copies of configur escript to src and doc are done.
#
# Revision 1.1  1994/10/04  07:31:40  billh
# Initial revision
#
############################################################################

############################################################################
# default values for program configurable parameters ***STARTPARAMS***
############################################################################

###########################
# installation parameters
###########################
# name of shell script used to start program; this is the name used by users
INSTALLNAME=vmd

# directory where program data files and OS-specific executables are installed
INSTALLLIBDIR=/usr/local/lib/$INSTALLNAME

# directory where startup scripts and utility programs are installed.
# this should be a directory in the path of users who will run the program
INSTALLBINDIR=/usr/local/bin

# where to put files when making available for anon ftp
INSTALLFTPDIR=/Net/lisboa/usr/ftp/pub/mdscope/vmd

###########################
# compilation parameters
###########################

# default type of display to use upon startup of program: WIN, CAVE, or TEXT
DEFDISPLAY=WIN

# default screen height, a floating-point value.  This distance is in 'world'
# coordinate system
DEFHEIGHT="6.0"

# distance from the 'world' coordinates origin to the screen, in the same
# units as the DEFHEIGHT value.  If > 0, the screen is between the viewer
# and the origin; if < 0, the origin is in FRONT of the screen.
DEFDIST="-2.0"

# whether or not to display the program title on startup: ON or OFF
DEFTITLE=ON

# name of program initialization file, with default setting variables
INITFILENAME=.vmd_init

# max number of characters used for string comparisons
MAXSTRINGLEN=6

# program version number
PROGVERSION=0.96

# text prompt string
PROMPTSTRING="vmd > "

# startup command script file.  Read after program initialization.
STARTUPFILENAME=.vmdrc

###########################
# configure scrip parameters ***ENDPARAMS***
###########################
AUTHORS="William Humphrey and Andrew Dalke"


############################################################################
# main script begins
############################################################################

# make sure we're in the proper directory first
if [ ! -d src ]; then
  cd ..
  if [ ! -d src ]; then
    echo "This is not the proper directory.  Exiting ..."
    exit 1
  else
    echo "Configuring from directory `pwd` ..."
  fi
fi

# read user settings for parameters, if available 
if [ -f configure.parameters ]; then
  echo "Reading user configuration parameters ..."
  . configure.parameters
fi

###########################
# global variable declarations
###########################
archlist="IRIX4 IRIX5 HPUX9 HELP"
optlist=" HELP FORMS TEXT REMOTE NOREMOTE CAVE CAVESIM UNC NOUNC EXTERNAL DEBUG OPTIMIZE NONE ALL NOMAKE"

###########################
# useful functions
###########################

# print usage
myusage() {
  echo "Usage: $0 [ arch [ optionlist ] ], where"
  echo "         arch = one of $archlist"
  echo "   optionlist = zero or more of the following list:"
  echo "	$optlist, with"
  echo "              HELP: print out this information"
  echo "              FORMS: use GL and FORMS graphics/GUI libraries."
  echo "              TEXT: use no graphics/GUI libraries; text interface only."
  echo "              REMOTE: include remote connection cababilities."
  echo "              NOREMOTE: do not include remote connection cababilities."
  echo "              CAVE or CAVESIM: include support for CAVE display."
  echo "              UNC: include support for using the UNC TRACKER library."
  echo "              NOUNC: not not include support for the TRACKER library."
  echo "              EXTERNAL: get external commands via PVM (experimental)"
  echo "              DEBUG: include debugging statements."
  echo "              OPTIMIZE: compile with the -O flag (instead of -g)."
  echo "              NONE: do not include any optional components."
  echo "	      ALL: same as FORMS REMOTE CAVE UNC."
  echo "              NOMAKE: skips final steps to co and remake the code."
  exit 1
}

###########################
# initialization
###########################
# check the arguments, parse them, and set flags to get ready to run
###########################

myargs=$*
myarch=
myoptions=
myoptimizeflag="-g"
opt_forms=false
opt_remote=false
opt_cave=false
opt_cavesim=false
opt_unc=false
opt_external=false
opt_debug=false
opt_optim=false
opt_remake=false

# check for previous options file
if [ $# = 0 ]; then
  if [ -f configure.options ]; then
    myargs=`cat configure.options`
  else
    echo "No arguments given, and no file configure.options"
    myusage
  fi
fi

# make sure we have an arch and possible options
if [ "$myargs" = "" ]; then
  echo "Error: No architecture specified."
  myusage
fi

# parse arguments
firstarg=true
doallopt=true
for a in $myargs ; do
  if [ "$a" = "HELP" -o "$a" = "help" ]; then
    myusage
  fi
  if [ $firstarg = true ]; then
    for b in $archlist; do
      if [ "$a" = "$b" ]; then myarch=$a; fi
    done
    if [ "$myarch" = "" ]; then
	echo "Unknown architecture $a"
	myusage
    fi
    firstarg=false
  else
    if [ "$a" = "FORMS" ]; then
	opt_forms=true
    elif [ "$a" = "TEXT" ]; then
    	opt_forms=false
    	opt_cave=false
	opt_cavesim=false
    elif [ "$a" = "REMOTE" ]; then
    	opt_remote=true
    elif [ "$a" = "NOREMOTE" ]; then
    	opt_remote=false
    elif [ "$a" = "CAVE" ]; then
	opt_forms=true
    	opt_cave=true
	opt_cavesim=false
    elif [ "$a" = "CAVESIM" ]; then
	opt_forms=true
    	opt_cave=false
	opt_cavesim=true
    elif [ "$a" = "UNC" ]; then
    	opt_unc=true
    elif [ "$a" = "NOUNC" ]; then
    	opt_unc=false
    elif [ "$a" = "EXTERNAL" ]; then
        opt_external=true;
    elif [ "$a" = "DEBUG" ]; then
	opt_debug=true
    elif [ "$a" = "OPTIMIZE" -o "$a" = "OPT" -o "$a" = "OPTIM" ]; then
	opt_optim=true
    elif [ "$a" = "ALL" ]; then
        opt_forms=true
	opt_remote=true
	opt_cave=true
	opt_cavesim=false
	opt_unc=true
	opt_optim=true
    elif [ "$a" = "NONE" ]; then
        opt_forms=false
	opt_remote=false
	opt_cave=false
	opt_cavesim=false
	opt_unc=false
	opt_external=false;
	opt_optim=false
    elif [ "$a" = "MAKE" ]; then
    	opt_remake=true
    elif [ "$a" = "NOMAKE" ]; then
    	opt_remake=false
    else
       	echo "Unknown option $a"
	myusage
    fi
    doallopt=false
  fi
done

if [ $doallopt = true ]; then
  myoptions="FORMS REMOTE CAVE UNC OPTIMIZE"
  opt_optim=true
else
  if [ $opt_forms = true ]; then myoptions="$myoptions FORMS"; fi
  if [ $opt_remote = true ]; then myoptions="$myoptions REMOTE"; fi
  if [ $opt_cave = true ]; then myoptions="$myoptions CAVE"; fi
  if [ $opt_cavesim = true ]; then myoptions="$myoptions CAVESIM"; fi
  if [ $opt_unc = true ]; then myoptions="$myoptions UNC"; fi
  if [ $opt_external = true ]; then myoptions="$myoptions EXTERNAL"; fi
  if [ $opt_debug = true ]; then myoptions="$myoptions DEBUG"; fi
  if [ $opt_optim = true ]; then myoptions="$myoptions OPTIMIZE"; fi
  if [ $opt_remake = true ]; then myoptions="$myoptions MAKE"; fi
fi

echo "Configuring for architecture $myarch, with the following options:"
echo "   $myoptions"

# as a final preparation, note that optimization is handled differently
# than the other options
if [ $opt_optim = true ]; then
  myoptimizeflag="-O"
fi

###########################
# create new makefile
###########################
# write data to temporary file, then copy the file to the proper places
###########################
mkfile="temporary_Makefile"
rm -rf $mkfile

# first write header to makefile
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEHEADERTXT >> $mkfile
############################################################################
#cr                                                                       
#cr            (C) Copyright 1995 The Board of Trustees of the            
#cr                        University of Illinois                         
#cr                         All Rights Reserved                           
#cr                                                                       
############################################################################

############################################################################
# DESCRIPTION:
#
# 			main Makefile, generated by configure
#		
############################################################################

# machine to compile for, program name, and version
MAKEHEADERTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

# program configurable parameters
echo "ARCH			= $myarch" >> $mkfile
echo "OPTIMIZEFLAG		= $myoptimizeflag" >> $mkfile

echo "INSTALLNAME		= $INSTALLNAME" >> $mkfile
echo "INSTALLLIBDIR		= $INSTALLLIBDIR" >> $mkfile
echo "INSTALLBINDIR		= $INSTALLBINDIR" >> $mkfile
echo "INSTALLFTPDIR		= $INSTALLFTPDIR" >> $mkfile
echo "DEFDISPLAY		= $DEFDISPLAY" >> $mkfile
echo "DEFTITLE		= $DEFTITLE" >> $mkfile
echo "DEFHEIGHT		= $DEFHEIGHT" >> $mkfile
echo "DEFDIST			= $DEFDIST" >> $mkfile
echo "INITFILENAME		= $INITFILENAME" >> $mkfile
echo "MAXSTRINGLEN		= $MAXSTRINGLEN" >> $mkfile
echo "PROGNAME		= $INSTALLNAME"_"$myarch" >> $mkfile
echo "PROGVERSION		= $PROGVERSION" >> $mkfile
echo "PROMPTSTRING		= \"$PROMPTSTRING\"" >> $mkfile
echo "STARTUPFILENAME		= $STARTUPFILENAME" >> $mkfile

echo "AUTHORS			= \"$AUTHORS\"" >> $mkfile

# next section: non-configurable declarations
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEDECLTXT >> $mkfile

############################################################################
##################  no more configuration beyond this point  ###############
############################################################################

# makefile configuration
SHELL 			= /bin/sh
.SILENT:

#################################################################
# file which contains makefile dependencies (generated by make depend)
DEPENDFILE 		= Makedata.depend

# where to put the object files
OBJDIR			= objfiles/$(ARCH)

# directories for object files, scripts, and different parts of code.
# these are all relative to being in any of the subdirs of the main directory
# such as the src, lib, or bin dirs
MAINDIR			= ../.
SRCDIR 			= ../src
VMDLIBDIR		= ../lib
DATADIR			= ../data
BINDIR			= ../bin
DOCDIR			= ../doc
PROTEINSDIR		= ../proteins
BASEDISTRIBDIR		= ../distrib
BASEDISTRIBFILE		= $(INSTALLNAME)-$(PROGVERSION)
DISTRIBDIR		= $(BASEDISTRIBDIR)/$(BASEDISTRIBFILE)

# directory where to put the ftp files
FTPDIR                  = $(INSTALLFTPDIR)

# dirs for extra includes (except for OPTIONS, must have -I appended in front)
INCDIRS	= -I. $(OPTIONSINCDIRS) 

# dir for extra libs (except for OPTIONS, must have -l & -L appended in front)
LIBDIRS	= -L. $(OPTIONSLIBDIRS)
LIBS	= -lm $(OPTIONSLIBS)

# compiler and linker options
CFLAGS		= $(ARCH_COPTS)	$(OPTIMIZEFLAG) $(INCDIRS) \
			-DARCH_$(ARCH)	$(OPTIONSDEFS)
CPPFLAGS	= $(ARCH_CPPOPTS)	$(OPTIMIZEFLAG) $(INCDIRS) \
			-DARCH_$(ARCH)	$(OPTIONSDEFS)
LFLAGS		= $(LIBDIRS) 	$(LIBS)	$(ARCH_LOPTS)

#################################################################
# architecture-specific declarations:
#################################################################
MAKEDECLTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

###########################
# write architecture-specific options
###########################

if [ "$myarch" = "IRIX4" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEIRIX4TXT >> $mkfile
# definitions for IRIX4 architecture
#####
# specific names of programs used in make commands
#####
CCPP		= CC
CC		= cc
CD		= cd
COPY		= cp
COPYDIR		= cp -r
MAKEDIR		= mkdir
MOVE		= mv -f
DELETE		= rm -f
DELETEDIR	= rm -rf
ECHO		= echo
TAR		= tar
COMPRESS	= compress
GNUCOMPRESS	= /usr/local/bin/gzip
AR		= ar rsc
RANLIB		= /bin/true
COCMD		= co -q
COLOCKCMD	= co -l
CICMD		= ci -m"No message"
LATEX		= latex

#####
# extra compiler and linker options
#####
ARCH_COPTS	=
ARCH_CPPOPTS	= +e1
ARCH_LOPTS      = -lsun -lc_s -lsphere -lfm_s -lgl_s -lm -lmalloc

MAKEIRIX4TXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

elif [ "$myarch" = "IRIX5" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEIRIX5TXT >> $mkfile
# definitions for IRIX5 architecture
#####
# specific names of programs used in make commands
#####
CCPP		= CC
CC		= cc
CD		= cd
COPY		= cp
COPYDIR		= cp -r
MAKEDIR		= mkdir
MOVE		= mv -f
DELETE		= rm -f
DELETEDIR	= rm -rf
ECHO		= echo
TAR		= tar
COMPRESS	= compress
GNUCOMPRESS	= /usr/local/bin/gzip
AR		= ar rsc
RANLIB		= /bin/true
COCMD		= co -q
COLOCKCMD	= co -l
CICMD		= ci -m"No message"
LATEX		= latex

#####
# extra compiler and linker options
#####
ARCH_COPTS	=
ARCH_CPPOPTS	= +e1
ARCH_LOPTS      = -lc_s -lsphere -lfm_s -lgl_s -lm -lmalloc

MAKEIRIX5TXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

elif [ "$myarch" = "HPUX9" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEHPUX9TXT >> $mkfile
# definitions for HPUX9 architecture
#####
# specific names of programs used in make commands
#####
CCPP		= CC
CC		= cc
CD		= cd
COPY		= cp
COPYDIR		= cp -r
MAKEDIR		= mkdir
MOVE		= mv -f
DELETE		= rm -f
DELETEDIR	= rm -rf
ECHO		= echo
TAR		= tar
COMPRESS	= compress
GNUCOMPRESS	= /usr/local/bin/gzip
AR		= ar rsc
RANLIB		= /bin/true
COCMD		= co -q
COLOCKCMD	= co -l
CICMD		= ci -m"No message"
LATEX		= latex

#####
# extra compiler and linker options
# This is for compiling and linking with the NPGL library on HPUX 9.x
#####
ARCH_COPTS	= -Ae -I$(NPGLHOME)/include
ARCH_CPPOPTS	= +a1 -I$(NPGLHOME)/include
ARCH_LOPTS      = -L/usr/lib/X11R5 -L$(NPGLHOME)/lib \
		-Wl,-a,archive -lnpgl_ansi \
		-Wl,-a,shared -lXwindow -lsb -lXhp11 -lX11 -lm -ldld

MAKEHPUX9TXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fi

###########################
# write definitions for different configurable options
###########################
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEOPTIONSHEADTXT >> $mkfile
#################################################################
# optional components
#################################################################
MAKEOPTIONSHEADTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
echo "# options included: $myoptions" >> $mkfile

for opt in $myoptions; do
  if [ "$opt" = "OPTIMIZE" ]; then
echo "doing optimization" > /dev/null
  elif [ "$opt" = "NOMAKE" ]; then
echo "not doing remake" > /dev/null
  elif [ "$opt" = "FORMS" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKEFORMSTXT >> $mkfile

#######################
# OPTIONAL COMPONENT: GUI library to use.
#	Exactly one version of the following sets of items must be uncommented.
#	This specifies the libraries used for the on-screen GUI with buttons,
#	menus, etc.
#######################

# FORMS version
GUIDEF			= -DVMDFORMS
GUIDIR			= $(VMDLIBDIR)/forms
GUIINCDIR		= -I$(GUIDIR)/include
GUILIBDIR		= -L$(GUIDIR)/lib_$(ARCH)
GUILIB			= -lforms
GUI_CCPP		= \
				CmdMenu.C \
				AnimateFormsObj.C \
				ColorFormsObj.C \
				DisplayFormsObj.C \
				EditFormsObj.C \
				FilesFormsObj.C \
				FormsObj.C \
				GeometryFormsObj.C \
				GLDisplayDevice.C \
				GLMouse.C \
				GLRenderer.C \
				GraphicsFormsObj.C \
				MainFormsObj.C \
				MolFormsObj.C \
				RemoteFormsObj.C \
				SimFormsObj.C \
				TrackerFormsObj.C
GUI_CC			= forms_ui.c
GUI_H			= forms_ui.h \
				CmdMenu.h \
				AnimateFormsObj.h \
				ColorFormsObj.h \
				DisplayFormsObj.h \
				EditFormsObj.h \
				FilesFormsObj.h \
				FormsObj.h \
				GeometryFormsObj.h \
				GLDisplayDevice.h \
				GLMouse.h \
				GLRenderer.h \
				GraphicsFormsObj.h \
				MainFormsObj.h \
				MolFormsObj.h \
				RemoteFormsObj.h \
				SimFormsObj.h \
				TrackerFormsObj.h
GUI_EXTRA		= forms_ui.fd
GUI_OBJS		= $(GUI_CCPP:.C=.o)	$(GUI_CC:.c=.o)

MAKEFORMSTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "REMOTE" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKEREMOTETXT >> $mkfile

#######################
# OPTIONAL COMPONENT: Remote simulation connection support
#	This may be commented out if not required.
#	This allows the program to connect to or launch an MD simulation
#	on a remote computer, and to control and view the simulation results
#	on-line.  It requires an MD application modified to communicate with
#	this program (a primary example of this is namd).
#######################

REMOTEDEF		= -DVMDREMOTE
REMOTEDIR		= $(VMDLIBDIR)/mdcomm
REMOTEINCDIR		= -I$(REMOTEDIR)/include
REMOTELIBDIR		= -L$(REMOTEDIR)/lib_$(ARCH)
REMOTELIB		= -lmdcomm
REMOTE_CCPP		= \
				CmdRemote.C \
				MoleculeRemote.C \
				Remote.C \
				RemoteList.C
REMOTE_CC		=
REMOTE_H		= \
				CmdRemote.h \
				MoleculeRemote.h \
				Remote.h \
				RemoteList.h
REMOTE_EXTRA		=
REMOTE_OBJS		= $(REMOTE_CCPP:.C=.o)	$(REMOTE_CC:.c=.o)

MAKEREMOTETXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "UNC" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKEUNCTXT >> $mkfile

#######################
# OPTIONAL COMPONENT: UNC Tracker library support
#	This may be commented out if not required.
#	This allows the use of many different spatial trackers with the
#	library developed at U. of North Carolina.  Without it, non-CAVE
#	tracking is not allowed.
#######################

UNCDEF			= -DVMDUNC
UNCDIR			= $(VMDLIBDIR)/unc
UNCINCDIR		= -I$(UNCDIR)/include
UNCLIBDIR		= -L$(UNCDIR)/lib_$(ARCH)
UNCLIB			= -ltracker -lquat
UNC_CCPP		= UNCTracker.C
UNC_CC			=
UNC_H			= UNCTracker.h
UNC_EXTRA		=
UNC_OBJS		= $(UNC_CCPP:.C=.o)	$(UNC_CC:.c=.o)

MAKEUNCTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "EXTERNAL" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKEEXTERNALTXT >> $mkfile

#######################
# OPTIONAL COMPONENT: External interface
#	This may be commented out if not required.
#	This allows other programs to communicate with vmd via a PVM
#	message.  Currently this is experimental and is not included
#	by default
#######################

EXTERNALDEF		= -DVMDEXTERNAL
EXTERNALDIR		= $(HOME)/pvm3/
EXTERNALINCDIR		= -I$(EXTERNALDIR)/include
EXTERNALARCH            = `$(HOME)/pvm3/lib/pvmgetarch`
EXTERNALLIBDIR		= -L$(EXTERNALDIR)/lib/$(EXTERNALARCH)
EXTERNALLIB		= -lpvm3 -lgpvm3
EXTERNAL_CCPP		= \
				CmdExternal.C \
				UIExternal.C
EXTERNAL_CC		=
EXTERNAL_H		= \
				CmdExternal.h \
				UIExternal.h

EXTERNAL_EXTRA		=
EXTERNAL_OBJS		= $(EXTERNAL_CCPP:.C=.o)	$(EXTERNAL_CC:.c=.o)

MAKEEXTERNALTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "CAVE" -o "$opt" = "CAVESIM" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKECAVETXT >> $mkfile

#######################
# OPTIONAL COMPONENT: EVL/NCSA CAVE support
#	This may be commented out if not required.
#	This will require access to the cave library and headers, and will
#	result in unique CAVE objects being used in the program.
#######################

CAVEDEF			= -DVMDCAVE
CAVEDIR			= $(VMDLIBDIR)/cave
CAVEINCDIR		= -I$(CAVEDIR)/include
CAVELIBDIR		= -L$(CAVEDIR)/lib_$(ARCH)
CAVE_CCPP		= \
				CaveDisplayDevice.C \
				CaveScene.C \
				CaveRoutines.C \
				CaveTracker.C
CAVE_CC			=
CAVE_H			= \
				CaveDisplayDevice.h \
				CaveResizeArray.h 	CaveResizeArray.c \
				CaveRoutines.h \
				CaveScene.h \
				CaveTracker.h
CAVE_EXTRA		=
CAVE_OBJS		= $(CAVE_CCPP:.C=.o)	$(CAVE_CC:.c=.o)

# cave library to use
MAKECAVETXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    if [ "$opt" = "CAVE" ]; then
      echo "CAVELIB			= -lcave" >> $mkfile
    else
      echo "CAVELIB			= -lcavesim" >> $mkfile
    fi
  elif [ "$opt" = "DEBUG" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKEDEBUGTXT >> $mkfile

#######################
# OPTIONAL COMPONENT: Debugging code
#	This will include many statements that print debugging info.
# Note that including this will make the program VERY VERY SLOW.
#######################
DEBUGDEF		= -DVMDDEBUG

MAKEDEBUGTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  fi
done

###### final optional components Makefile statements
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEOPTIONSENDTXT >> $mkfile

OPTIONSDEFS	= $(GUIDEF)	$(REMOTEDEF)	$(UNCDEF)	$(CAVEDEF) \
			$(EXTERNALDEF)	$(DEBUGDEF)
OPTIONSINCDIRS	= $(GUIINCDIR)	$(REMOTEINCDIR)	$(UNCINCDIR)	$(CAVEINCDIR)\
			$(EXTERNALINCDIR)
OPTIONSLIBDIRS	= $(GUILIBDIR)	$(REMOTELIBDIR)	$(UNCLIBDIR)	$(CAVELIBDIR)\
			$(EXTERNALLIBDIR)
OPTIONSLIBS	= $(GUILIB)	$(REMOTELIB)	$(UNCLIB)	$(CAVELIB)\
			$(EXTERNALLIB)
OPTIONS_CCPP	= $(GUI_CCPP)	$(REMOTE_CCPP)	$(UNC_CCPP)	$(CAVE_CCPP)\
			$(EXTERNAL_CCPP)
OPTIONS_CC	= $(GUI_CC)	$(REMOTE_CC)	$(UNC_CC)	$(CAVE_CC)\
			$(EXTERNAL_CC)
OPTIONS_H	= $(GUI_H)	$(REMOTE_H)	$(UNC_H)	$(CAVE_H)\
			$(EXTERNAL_H)
OPTIONS_EXTRA	= $(GUI_EXTRA)	$(REMOTE_EXTRA)	$(UNC_EXTRA)	$(CAVE_EXTRA)\
			$(EXTERNAL_EXTRA)
OPTIONS_OBJS	= $(GUI_OBJS)	$(REMOTE_OBJS)	$(UNC_OBJS)	$(CAVE_OBJS)\
			$(EXTERNAL_OBJS)

#######################
# end of optional component selection
#######################

MAKEOPTIONSENDTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#######################
# write lists of all common files in program
#######################
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEFILELISTTXT >> $mkfile

# VMD source files
VMD_CCPP	= \
		Animation.C \
		AtomColor.C \
		AtomRep.C \
		AtomSel.C \
		Axes.C \
		BaseMolecule.C \
		Buttons.C \
		CmdAnimate.C \
		CmdColor.C \
		CmdDisplay.C \
		CmdLabel.C \
		CmdMol.C \
		CmdPick.C \
		CmdRender.C \
		CmdTool.C \
		CmdTracker.C \
		CmdTrans.C \
		CmdUtil.C \
		ColorList.C \
		ColorUser.C \
		Command.C \
		CommandQueue.C \
		ConfigList.C \
		CoorDCD.C \
		CoorFile.C \
		CoorFileData.C \
		CoorPDB.C \
		DisplayDevice.C \
		Displayable.C \
		DispCmds.C \
		DrawMolecule.C \
		DrawMolItem.C \
		DrawPatch.C \
		Enterprise.C \
		Geometry.C \
		GeometryAngle.C \
		GeometryAtom.C \
		GeometryBond.C \
		GeometryDihedral.C \
		GeometryList.C \
		GeometryMol.C \
		Global.C \
		GrabTool.C \
		Inform.C \
		Light.C \
		LightList.C \
		Matrix4.C \
		MolAction.C \
		Molecule.C \
		MoleculeList.C \
		MoleculeFile.C \
		MoleculeFileEDM.C \
		MoleculeFileGraph.C \
		MoleculeFilePDB.C \
		MoleculeFilePSF.C \
		MoleculeFileRaster3D.C \
		Mouse.C \
		NormalScene.C \
		PickList.C \
		PickMode.C \
		PickModeMolLabel.C \
		PickModeQuery.C \
		Pickable.C \
		PointerTool.C \
		ReadDCD.C \
		ReadEDM.C \
		ReadPDB.C \
		ReadPSF.C \
		Scene.C \
		Stage.C \
		Timer.C \
		Timestep.C \
		Tokenize.C \
		Tool.C \
		ToolControl.C \
		Tracker.C \
		TrackerList.C \
		UIList.C \
		UIObject.C \
		UIText.C \
		UIText2.C \
		UIVR.C \
		VButton.C \
		VMDTitle.C \
		VRegion.C \
		VRegionList.C \
		startup.C \
		utilities.C \
		vmd.C

VMD_CC	=

# VMD header files ... NOTE: for templates, both the .h AND the .c file
#	should be specified on the same line, in this header section.
#	The filename extension for a template source file should be .c,
#	not .C (the case of the extension must match the case of the header
#	file defining the template).  This all is done because template
#	source code files are NOT to be compiled as normal, and should NOT
#	have dependencies generated for them.
VMD_H		= \
		Animation.h \
		Atom.h \
		AtomColor.h \
		AtomRep.h \
		AtomSel.h \
		Axes.h \
		BaseMolecule.h \
		Buttons.h \
		CmdAnimate.h \
		CmdColor.h \
		CmdDisplay.h \
		CmdLabel.h \
		CmdMol.h \
		CmdPick.h \
		CmdRender.h \
		CmdTool.h \
		CmdTracker.h \
		CmdTrans.h \
		CmdUtil.h \
		ColorList.h \
		ColorUser.h \
		Command.h \
		CommandQueue.h \
		ConfigList.h \
		CoorDCD.h \
		CoorFile.h \
		CoorFileData.h \
		CoorPDB.h \
		DLinkList.h 		DLinkList.c \
		DispCmds.h \
		DisplayDevice.h \
		Displayable.h \
		DrawMolecule.h \
		DrawMolItem.h \
		DrawPatch.h \
		Enterprise.h \
		Fragment.h \
		GeometryAngle.h \
		GeometryAtom.h \
		GeometryBond.h \
		GeometryDihedral.h \
		GeometryList.h \
		GeometryMol.h \
		Global.h \
		GrabTool.h \
		Grid.h			Grid.c \
		Inform.h \
		Light.h \
		LightList.h \
		Matrix4.h \
		MolAction.h \
		Molecule.h \
		MoleculeFile.h \
		MoleculeFileEDM.h \
		MoleculeFileGraph.h \
		MoleculeFilePDB.h \
		MoleculeFilePSF.h \
		MoleculeFileRaster3D.h \
		MoleculeList.h \
		Mouse.h \
		NameList.h		NameList.c \
		NormalScene.h \
		PickList.h \
		PickMode.h \
		PickModeQuery.h \
		Pickable.h \
		PointerTool.h \
		ResizeArray.h		ResizeArray.c \
		ReadDCD.h \
		ReadEDM.h \
		ReadPDB.h \
		ReadPSF.h \
		Residue.h \
		Scene.h \
		Stack.h 		Stack.c \
		Stage.h \
		Timer.h \
		Timestep.h \
		Tokenize.h \
		Tool.h \
		ToolControl.h \
		Tracker.h \
		TrackerList.h \
		Tree.h \
		UIList.h \
		UIObject.h \
		UIText.h \
		UIVR.h \
		VButton.h \
		VMDTitle.h \
		VRegion.h \
		VRegionList.h \
		startup.h \
		utilities.h

# summary of the above files
VMD_SRCS	= $(VMD_CCPP)		$(VMD_CC)
VMD_OBJS	= $(VMD_CCPP:.C=.o)	$(VMD_CC:.c=.o)

# data files, such as the .vmdrc and other files
VMD_DATA	= \
		.tracker \
		.vmdrc \
		.vmd_init

# utility scripts, i.e. the script to start up vmd
VMD_BIN		= vmd

# VMD 'extra' files
VMD_EXTRA	=

###############################
# all components ... includes optional files, defined in Makedata.options
###############################
ALL_CCPP_SRCS	= $(VMD_CCPP)		$(OPTIONS_CCPP)
ALL_CC_SRCS	= $(VMD_CC)		$(OPTIONS_CC)
ALL_SRCS	= $(ALL_CCPP_SRCS)	$(ALL_CC_SRCS)
ALL_H		= $(VMD_H)		$(OPTIONS_H)
ALL_OBJS	= $(VMD_OBJS)		$(OPTIONS_OBJS)
EXTRA_FILES	= $(VMD_EXTRA)		$(OPTIONS_EXTRA)
DATA_FILES	= $(VMD_DATA)
BIN_FILES	=
SCRIPT_FILES	= $(INSTALLNAME)

# main directory utility files, such as this configure script and README
MAIN_DIR_FILES	= \
		README \
		configure

###############################
# Documentation files ... all in directory DOCDIR
###############################
DOC_STYLE_FILES	= \
		graphic.sty \
		picinpar.sty

# files needed for the installation guide
MAIN_INST_DOC	= ig.tex
DOC_INST_FILES	= \
		ig_chapters.tex \
		ig_custom.tex \
		ig_install.tex \
		ig_intro.tex \
		ig_macros.tex \
		ig_make.tex \
		ig_unpack.tex
ALL_INST_FILES	= $(MAIN_INST_DOC) $(DOC_INST_FILES)

# files needed for the user's guide
MAIN_USER_DOC	= ug.tex
DOC_USER_FILES	= \
		ug_chapters.tex \
		ug_intro.tex \
		ug_macros.tex \
		quickstart.tex

ALL_USER_FILES	= $(MAIN_USER_DOC) $(DOC_USER_FILES)

# files needed for the programmer's guide
MAIN_PROG_DOC	= pg.tex
DOC_PROG_FILES	= \
		pg_chapters.tex \
		pg_codestyle.tex \
		pg_filestruct.tex \
		pg_intro.tex \
		pg_macros.tex \
		pg_make.tex \
		pg_objects.tex \
		pg_structure.tex \
		Timer.tex

ALL_PROG_FILES	= $(MAIN_PROG_DOC) $(DOC_PROG_FILES)

# files needs by all the different guides, and for the book format
MAIN_ALL_DOC	= vmd.tex
DOC_ALL_FILES	= \
		vmd_authors.tex \
		vmd_begindoc.tex \
		vmd_configure.tex \
		vmd_macros.tex \
		vmd_moreinfo.tex \
		vmd_paramcomp.tex \
		vmd_paraminst.tex \
		vmd_ref.tex \
		vmd_style.tex \
		vmd_title.tex
ALL_MAIN_FILES	= $(MAIN_ALL_DOC) $(DOC_ALL_FILES)

DOC_FILES = \
		$(ALL_INST_FILES) \
		$(ALL_PROG_FILES) \
		$(ALL_USER_FILES) \
		$(ALL_MAIN_FILES) \
		$(DOC_STYLE_FILES)

DOC_DRIVER_FILES	= $(MAIN_INST_DOC) $(MAIN_PROG_DOC) $(MAIN_USER_DOC) \
				$(MAIN_ALL_DOC)
DOC_DVI_FILES		= $(DOC_DRIVER_FILES:.tex=.dvi)
DOC_PS_FILES		= $(DOC_DRIVER_FILES:.tex=.ps)

MAKEFILELISTTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

###############################
# Rest of makefile
###############################
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKERULESTXT >> $mkfile
############################### 
# default rules 
###############################

.C.o:
	$(ECHO) "Compiling " $< " --> " $*.o " ..."; \
	$(CCPP) $(CPPFLAGS) -c $(SRCDIR)/$< > /dev/null

.c.o:
	$(ECHO) "Compiling " $< " --> " $*.o " ..."; \
	$(CC) $(CFLAGS) -c $(SRCDIR)/$<

###############################
# main target rule
###############################

all default:	$(PROGNAME)

#### executables

$(PROGNAME): $(ALL_OBJS)
	$(ECHO) "Linking " $@ " ..."; \
	$(CCPP) $(CPPFLAGS) -o $@ $(ALL_OBJS) $(LFLAGS) > /dev/null

#### configure include files for src and documentation

version: srcversion docversion

srcversion:
	$(ECHO) "Updating src/config.h ..."; \
	$(CD) $(SRCDIR); \
	if [ -f config.h ]; then $(DELETE) config.h; fi; \
	$(ECHO) \#ifndef CONFIG_OPTIONS_H >> config.h ; \
	$(ECHO) \#define CONFIG_OPTIONS_H >> config.h ; \
	$(ECHO) \#define VERSION_MSG \"$(INSTALLNAME) for $(ARCH), version $(PROGVERSION) \(`date`\)\" >> config.h ; \
	$(ECHO) \#define CMDLEN $(MAXSTRINGLEN) >> config.h ; \
	$(ECHO) \#define VMDENVVAR \"VMDDIR\" >> config.h ; \
	$(ECHO) \#define DEF_VMDENVVAR \"$(INSTALLLIBDIR)\" >> config.h ; \
	$(ECHO) \#define VMD_INITFILE  \"$(INITFILENAME)\" >> config.h ; \
	$(ECHO) \#define VMD_STARTUP   \"$(STARTUPFILENAME)\" >> config.h ; \
	$(ECHO) \#define VMD_CMD_PROMPT \"$(PROMPTSTRING)\" >> config.h ; \
	$(ECHO) \#define INIT_DEFDISPLAY DISPLAY_$(DEFDISPLAY) >> config.h ; \
	$(ECHO) \#define INIT_DEFTITLE   TITLE_$(DEFTITLE) >> config.h ; \
	$(ECHO) \#define INIT_DEFHEIGHT  $(DEFHEIGHT) >> config.h ; \
	$(ECHO) \#define INIT_DEFDIST    $(DEFDIST) >> config.h ; \
	$(ECHO) \#endif >> config.h

docversion:
	$(ECHO) "Updating doc/vmd_version.tex ..."; \
	$(CD) $(DOCDIR); \
	if [ -f vmd_version.tex ]; then $(DELETE) vmd_version.tex; fi; \
	$(ECHO) '\\'newcommand\{\\VMDNAME\} \{$(INSTALLNAME)\}>>vmd_version.tex ;\
	$(ECHO) '\\'newcommand\{\\VMDDATE\} \{`date`\} >> vmd_version.tex ;\
	$(ECHO) '\\'newcommand\{\\VMDVER\} \{$(PROGVERSION)\}>>vmd_version.tex;\
	$(ECHO) '\\'newcommand\{\\VMDAUTHORS\} \{$(AUTHORS)\}>>vmd_version.tex

###############################
### latex the documentation
###############################
doc doc.all:	doc.ig doc.pg doc.ug

doc.ig:
	$(ECHO) "Creating the installation guide ..." ; \
	$(CD) $(DOCDIR); \
	$(LATEX) $(MAIN_INST_DOC) && \
		dvips -o -Z $(MAIN_INST_DOC:.tex=.dvi)

doc.pg:
	$(ECHO) "Creating the programmers guide ..." ; \
	$(CD) $(DOCDIR); \
	$(LATEX) $(MAIN_PROG_DOC) && \
		dvips -o -Z $(MAIN_PROG_DOC:.tex=.dvi)

doc.ug:
	$(ECHO) "Creating the users guide ..." ; \
	$(CD) $(DOCDIR); \
	$(LATEX) $(MAIN_USER_DOC) && \
		dvips -o -Z $(MAIN_USER_DOC:.tex=.dvi)

doc.book:
	$(ECHO) "Creating the complete documentation book ..." ;\
	$(CD) $(DOCDIR); \
	$(LATEX) $(MAIN_ALL_DOC) && \
		dvips -o -Z $(MAIN_ALL_DOC:.tex=.dvi)

###############################
### installation targets
###############################

# install everything
install.all: install.exe install.doc

# install program and data files in proper directory
install install.exe:
	$(ECHO) "Installing executables and data files in $(INSTALLLIBDIR)"; \
	if [ ! -d $(INSTALLLIBDIR) ]; then mkdir $(INSTALLLIBDIR); fi; \
	$(CD) $(SRCDIR); \
	  $(COPY) $(PROGNAME)   $(INSTALLLIBDIR) ; \
	  chmod u+w $(INSTALLLIBDIR)/$(PROGNAME)  ; \
	$(CD) $(DATADIR); \
	  $(COPY) .tracker $(INSTALLLIBDIR) ; \
	  chmod u+w $(INSTALLLIBDIR)/.tracker  ; \
	  $(COPY) .vmd_init $(INSTALLLIBDIR)/$(INITFILENAME) ; \
	  chmod u+w $(INSTALLLIBDIR)/$(INITFILENAME)  ; \
	  $(COPY) .vmdrc $(INSTALLLIBDIR)/$(STARTUPFILENAME) ; \
	  chmod u+w $(INSTALLLIBDIR)/$(STARTUPFILENAME)  ; \
	$(ECHO) "Installing scripts and utilities in $(INSTALLBINDIR)"; \
	$(CD) $(BINDIR); \
	if [ "$(BIN_FILES)" != "" ]; then \
	  $(COPY) $(BIN_FILES) $(INSTALLBINDIR) ; \
	fi ; \
	if [ -f run_vmd_tmp ]; then $(DELETE) run_vmd_tmp; fi ;\
	$(ECHO) '#!/bin/csh' >> run_vmd_tmp ; \
	$(ECHO) 'set defaultvmddir='$(INSTALLLIBDIR) >> run_vmd_tmp ; \
	$(ECHO) 'set vmdbasename='$(INSTALLNAME) >> run_vmd_tmp ; \
	cat $(VMD_BIN) >> run_vmd_tmp ; \
	chmod +x run_vmd_tmp ; \
	$(COPY) run_vmd_tmp $(INSTALLBINDIR)/$(INSTALLNAME) ; \
	$(DELETE) run_vmd_tmp ; \
	if [ "$(REMOTEDEF)" != "" ]; then \
	  $(ECHO) "Installing mdcomm files"; \
	  if [ ! -d $(INSTALLLIBDIR)/mdcomm ]; then \
	    mkdir $(INSTALLLIBDIR)/mdcomm ; \
	  fi ; \
	  $(COPY) $(VMDLIBDIR)/mdcomm/lib_$(ARCH)/md_consumer \
	  	$(INSTALLLIBDIR)/mdcomm/md_consumer_$(ARCH) ; \
	  $(COPY) $(VMDLIBDIR)/mdcomm/lib_$(ARCH)/chemd \
	  	$(INSTALLLIBDIR)/mdcomm/chemd_$(ARCH) ; \
	fi

### install documentation in proper directory
install.doc:
	$(ECHO) "Installing documentation in $(INSTALLLIBDIR)/doc"; \
	if [ ! -d $(INSTALLLIBDIR) ]; then mkdir $(INSTALLLIBDIR); fi; \
	if [ ! -d $(INSTALLLIBDIR)/doc ]; then mkdir $(INSTALLLIBDIR)/doc; fi; \
	$(CD) $(DOCDIR); \
	if [ "$(DOC_DVI_FILES)" != "" ]; then \
	  $(COPY) $(DOC_DVI_FILES) $(INSTALLLIBDIR)/doc; \
	fi ; \
	if [ "$(DOC_PS_FILES)" != "" ]; then \
	  $(COPY) $(DOC_PS_FILES) $(INSTALLLIBDIR)/doc ; \
	fi

###############################
### create distribution files
###############################

#### create the distribution directory
distrib.dir:
	if [ ! -d $(DISTRIBDIR) ]; then \
	  $(ECHO) "Creating source distribution directory $(DISTRIBDIR) ..."; \
	  mkdir $(DISTRIBDIR); \
	fi

#### copy the files necessary for the distribution into a temporary dir
distrib.copy:	distrib.dir
	$(ECHO) "Copying files ..." ; \
	$(CD) .. ; \
	$(TAR) cf - RCS/. READ* config* bin/. data/. doc/. lib/. \
		proteins/. src/. | (cd distrib/$(DISTRIBDIR); $(TAR) xvf -); \
	$(DELETE) distrib/$(DISTRIBDIR)/src/*.o ; \
	strip distrib/$(DISTRIBDIR)/src/$(PROGNAME) ; \
	if [ -d distrib/$(DISTRIBDIR)/src/ptrepository ]; then \
	  $(DELETEDIR) distrib/$(DISTRIBDIR)/src/ptrepository; \
	fi ; \
	$(DELETE) distrib/$(DISTRIBDIR)/doc/pictures ; \
	$(MAKEDIR) distrib/$(DISTRIBDIR)/doc/pictures ; \
	$(COPY) doc/pictures/*.eps doc/pictures/*.ps \
		distrib/$(DISTRIBDIR)/doc/pictures

#### create the configure.parameters file for distribution
distrib.conf.par:	distrib.dir
	$(ECHO) "Creating distribution configure.parameters ..." ; \
	cat ../configure | awk '{ if($$NF == "***STARTPARAMS***") { \
		  		 getline ; while($$NF != "***ENDPARAMS***") { \
					print ; getline \
		  		 } \
				} \
			}' > $(DISTRIBDIR)/configure.parameters

#### compress the distribution once is has been produced
distrib.compress:	distrib.dir
	$(ECHO) "  Creating and compressing $(BASEDISTRIBFILE).tar ..."; \
	$(CD) ../distrib ; \
	$(TAR) cf - $(BASEDISTRIBFILE) | \
		$(GNUCOMPRESS) > $(BASEDISTRIBFILE).tar.gz ; \
	$(TAR) cf - $(BASEDISTRIBFILE) | \
		$(COMPRESS) > $(BASEDISTRIBFILE).tar.Z

#### create the distribution .tar.Z file completely
distrib:
	make distrib.copy ; \
	make distrib.conf.par ; \
	make distrib.compress ; \
	$(DELETEDIR) $(DISTRIBDIR)

#### put distrib file out for anon ftp
ftp:
	$(ECHO) "Copying distribution to the FTP directory ..."; \
	$(CD) .. ; \
	$(COPY) README $(FTPDIR) ; \
	$(COPY) distrib/$(BASEDISTRIBFILE).tar.* $(FTPDIR) ; \
	$(CD) $(FTPDIR) ; \
	if [ -h $(INSTALLNAME).tar.Z ]; then \
	  $(DELETE) $(INSTALLNAME).tar.Z; \
	fi; \
	ln -s $(BASEDISTRIBFILE).tar.Z $(INSTALLNAME).tar.Z ; \
	if [ -h $(INSTALLNAME).tar.gz ]; then \
	  $(DELETE) $(INSTALLNAME).tar.gz; \
	fi; \
	ln -s $(BASEDISTRIBFILE).tar.gz $(INSTALLNAME).tar.gz

###############################
### RCS checkout targets:
###############################

co.main:
	$(ECHO) "Checking out main directory files ..." ; \
	$(CD) $(MAINDIR); \
	$(COCMD) $(MAIN_DIR_FILES)

co.data:
	$(ECHO) "Checking out data files ..." ; \
	$(CD) $(DATADIR); \
	$(COCMD) $(DATA_FILES)

co.bin:
	$(ECHO) "Checking out scripts and utility files ..." ; \
	$(CD) $(BINDIR); \
	$(COCMD) $(BIN_FILES) $(SCRIPT_FILES)

co.doc:
	$(ECHO) "Checking out all documentation files ..." ; \
	$(CD) $(DOCDIR); \
	$(COCMD) $(DOC_FILES)

co.doc.ig:
	$(ECHO) "Checking out installation guide documentation files ..." ; \
	$(CD) $(DOCDIR); \
	$(COCMD) $(ALL_INST_FILES) $(ALL_MAIN_FILES) $(DOC_STYLE_FILES)

co.doc.pg:
	$(ECHO) "Checking out programmers guide documentation files ..." ; \
	$(CD) $(DOCDIR); \
	$(COCMD) $(ALL_PROG_FILES) $(ALL_MAIN_FILES) $(DOC_STYLE_FILES)

co.doc.ug:
	$(ECHO) "Checking out users guide documentation files ..." ; \
	$(CD) $(DOCDIR); \
	$(COCMD) $(ALL_USER_FILES) $(ALL_MAIN_FILES) $(DOC_STYLE_FILES)

co.src:
	$(ECHO) "Checking out source files ..."; \
	$(CD) $(SRCDIR); \
	$(COCMD) $(ALL_SRCS)

co.h co.include co.header:
	$(ECHO) "Checking out include files ..."; \
	$(CD) $(SRCDIR); \
	$(COCMD) $(ALL_H)

co.extra:
	$(ECHO) "Checking out all other needed files ..." ; \
	if [ "$(EXTRA_FILES)" != "" ]; then \
	  $(CD) $(SRCDIR); \
	  $(COCMD) $(EXTRA_FILES); \
	fi

co:	co.src co.h co.doc co.data co.bin co.extra co.main
	make depend

locks:
	$(ECHO) "Currently locked RCS files: " ; \
	$(CD) RCS; \
	if [ "`rlog -L -R *,v`" != "" ]; then \
	  ls -alF `rlog -L -R *,v`; \
	fi

###############################
# other useful make commands
###############################

### reconfigure, based on latest options
configure:
	$(ECHO) "Reconfiguring, using last configuration options ..." ;\
	$(CD) .. ;\
	$(COCMD) configure ;\
	configure

### cleanup target

clean:
	$(DELETE) *.o *.a *.bak *.depend.old *~ core

### dependencies files targets

# save the current dependencies list to rcs
savedepend:
	if [ -f $(DEPENDFILE) ]; then \
	  $(ECHO) "Saving current dependencies file ..."; \
	  $(COLOCKCMD) $(DEPENDFILE).rcs; \
	  $(COPY) $(DEPENDFILE) $(DEPENDFILE).rcs; \
	  $(CICMD) $(DEPENDFILE).rcs; \
	else \
	  $(ECHO) "No current dependencies file $(DEPENDFILE) found.";\
	fi

MAKERULESTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

###########################
# write out rule to create dependencies
###########################
if [ "$myarch" = "IRIX4" -o "$myarch" = "IRIX5" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEDEPENDTXT >> $mkfile
# create dependencies file ... does not work on all architectures
depend: version
	echo "Creating " $(DEPENDFILE) " ..."; \
	if [ -f $(DEPENDFILE) ]; \
	  then $(MOVE) -f $(DEPENDFILE) $(DEPENDFILE).old; \
	fi; \
	touch $(DEPENDFILE); \
	if [ "$(ALL_CCPP_SRCS) " != " " ]; \
	  then $(CCPP) -M $(INCDIRS) -DARCH_$(ARCH) $(OPTIONSDEFS) \
	  	$(ALL_CCPP_SRCS) $(ALL_CC_SRCS) \
	    		| grep -v "/usr/include" >> $(DEPENDFILE); \
	fi

#################################################################
# includes dependencies
include $(SRCDIR)/$(DEPENDFILE)

MAKEDEPENDTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
else
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEDEPEND2TXT >> $mkfile
depend: version
	echo "Checking out " $(DEPENDFILE) " ..."; \
	if [ -f $(DEPENDFILE) ]; \
	  then $(MOVE) -f $(DEPENDFILE) $(DEPENDFILE).old; \
	fi; \
	$(COCMD) $(DEPENDFILE).rcs; \
	$(MOVE) $(DEPENDFILE).rcs $(DEPENDFILE)

#################################################################
# includes dependencies
include $(SRCDIR)/$(DEPENDFILE)

MAKEDEPEND2TXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fi

###########################
# finish up
###########################
# since we're here, the configuration was successful
###########################

# put new makefile in src and doc dir
echo "Copying new makefile to src and doc dir ..."
cp $mkfile src/Makefile
cp $mkfile doc/Makefile
rm -f $mkfile

# put a copy of the configure script in these dirs for convenience
echo "Saving configuration options ..."
echo $myarch $myoptions > configure.options
cp configure configure.src.tmp
mv -f configure.src.tmp src/configure
cp configure configure.doc.tmp
mv -f configure.doc.tmp doc/configure

# now go to the src dir and make afresh
if [ $opt_remake = true ]; then
  echo "Remaking $programname ..."
  cd src
  make clean
  if [ -d RCS/. ]; then make co; fi
  make
else
  echo "A new Makefile has been generated; you may need to cd to the src"
  echo "and doc directores and do a make to get everything up to date."
fi

exit 0
