#!/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.81 $	$Date: 1995/07/04 22:06:36 $
#
############################################################################
# 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:
# GL			- use GL for windows and graphics (default)
# STARBASE        	- use Starbase for graphics
# NOGRAPHICS		- do not include ANY graphics capability
# FORMS			- use FORMS library for GUI (default)
# TK             	- use TK library for GUI
# NOGUI			- do not use ANY GUI library
# TCL      | NOTCL	- use/do not use the Tcl scripting language parser
# REMOTE   | NOREMOTE	- include/exclude remote sim connection option
# CAVE     | NOCAVE	- include/exclude cave display option
# UNC      | NOUNC	- include/exclude UNC tracker lib for spatial tracker
# EXTERNAL | NOEXTERNAL	- allow/disallow external input via PVM (experimental)
# SIGMA    | NOSIGMA	- include/exclude SIgMA MD interface (experimental)
# ALPHA    | NOALPHA    - use external calls to the alpha shape programs
# DEBUG    | NODEBUG	- include/exclude debugging statement code
# OPTIMIZE | NOOPTIMIZE	- compile with/without standard optimization (ie -O)
# MAKE     | NOMAKE	- does/does not do the co & make after configuring
# SILENT   | NOSILENT	- suppress/do not suppress make command echo
# ALL			- GL FORMS TCL REMOTE CAVE UNC OPTIMIZE
# NONE			- no options at all
#
# 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 start 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.
############################################################################

############################################################################
# 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

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

# location of TCL library and include file; if TCL is not being used,
# the next two options will be ignored
TCL_INCLUDE_DIR=${TCL_INCLUDE_DIR-/usr/local/include}
TCL_LIBRARY_DIR=${TCL_LIBRARY_DIR-/usr/local/lib}

# name of 'Babel' conversion program executable, with the complete path
DEFBABELBIN=$INSTALLBINDIR/babel

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

# 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"

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

# name of default html viewer to use; this value may be overridden when the
# program is run with the environment variable VMDHTMLVIEWER
DEFHTMLVIEWER=Mosaic

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

# default temporary file storage directory
DEFTMPDIR="/tmp"

# 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=1.0

# text prompt string
PROMPTSTRING="vmd > "

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

###########################
# configure script parameters ***ENDPARAMS***
###########################

# who is actually to blame for this mess
AUTHORS="W. Humphrey, A. Dalke, K. Hamer, J. Leech, J. Phillips"

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


############################################################################
# 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 GL STARBASE NOGRAPHICS FORMS TK NOGUI TCL NOTCL REMOTE NOREMOTE SIGMA NOSIGMA CAVE NOCAVE UNC NOUNC EXTERNAL NOEXTERNAL DEBUG NODEBUG ALPHA NOALPHA OPTIMIZE NOOPTIMIZE MAKE NOMAKE SILENT NOSILENT NONE ALL"

###########################
# 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 "  GL: use the GL library for windows and graphics (def)."
  echo "  STARBASE: use the Starbase library for graphics."
  echo "  NOGRAPHICS: do not include any graphics capability."
  echo "  FORMS: use the FORMS GUI library (def)."
  echo "  TK: use the TK GUI library."
  echo "  NOGUI: do not include any GUI library."
  echo "  TCL or NOTCL: include/exclude the Tcl parser (requires libtcl)."
  echo "  REMOTE or NOREMOTE: include/exlude remote connection cababilities."
  echo "  CAVE or NOCAVE: include/exclude support for CAVE display (GL only)."
  echo "  ALPHA or NOALPHA: use external calls to the alpha shape programs."
  echo "  UNC or NOUNC: include/exclude support for using UNC TRACKER lib."
  echo "  DEBUG or NODEBUG: include/exclude debugging statements."
  echo "  OPTIMIZE or NOOPTIMIZE: compile (or do not compile) with -O flag."
  echo "  MAKE or NOMAKE: re-co and remake the code after config, or skip."
  echo "  SILENT or NOSILENT: suppress (do not suppress) make command echo."
  echo "  ALL: same as GL FORMS TCL REMOTE CAVE UNC OPTIMIZE."
  echo "  NONE: do not include any optional components."
  exit 1
}

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

myargs=$*
myarch=
myoptions=
myoptimizeflag="-g"
opt_graphics=gl
opt_gui=forms
opt_tcl=false
opt_remote=false
opt_cave=false
opt_alpha=false
opt_unc=false
opt_external=false
opt_sigma=false
opt_debug=false
opt_optim=false
opt_remake=false
opt_silent=true

# 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" = "GL" ]; then
	opt_graphics=gl
    elif [ "$a" = "STARBASE" ]; then
        opt_graphics=starbase
        opt_gui=tk
	opt_cave=false
    elif [ "$a" = "NOGRAPHICS" ]; then
	opt_graphics=false
    	opt_cave=false
    elif [ "$a" = "FORMS" ]; then
	opt_gui=forms
    elif [ "$a" = "TK" ]; then
        opt_gui=tk
    elif [ "$a" = "NOGUI" ]; then
	opt_gui=false
    elif [ "$a" = "TCL" ]; then
        opt_tcl=true
    elif [ "$a" = "NOTCL" ]; then
        opt_tcl=false
    elif [ "$a" = "REMOTE" ]; then
    	opt_remote=true
    elif [ "$a" = "NOREMOTE" ]; then
    	opt_remote=false
    elif [ "$a" = "CAVE" ]; then
    	opt_cave=true
	opt_graphics=gl
    elif [ "$a" = "NOCAVE" ]; then
    	opt_cave=false
    elif [ "$a" = "ALPHA" ]; then
        opt_alpha=true
    elif [ "$a" = "NOALPHA" ]; then
        opt_alpha=false    
    elif [ "$a" = "UNC" ]; then
    	opt_unc=true
    elif [ "$a" = "NOUNC" ]; then
    	opt_unc=false
    elif [ "$a" = "EXTERNAL" ]; then
        opt_external=true;
    elif [ "$a" = "NOEXTERNAL" ]; then
        opt_external=false;
    elif [ "$a" = "SIGMA" ]; then
    	opt_sigma=true
    elif [ "$a" = "NOSIGMA" ]; then
    	opt_sigma=false
    elif [ "$a" = "DEBUG" ]; then
	opt_debug=true
    elif [ "$a" = "NODEBUG" ]; then
	opt_debug=false
    elif [ "$a" = "OPTIMIZE" -o "$a" = "OPT" ]; then
	opt_optim=true
    elif [ "$a" = "NOOPTIMIZE" -o "$a" = "NOOPT" ]; then
	opt_optim=false
    elif [ "$a" = "MAKE" ]; then
    	opt_remake=true
    elif [ "$a" = "NOMAKE" ]; then
    	opt_remake=false
    elif [ "$a" = "SILENT" ]; then
        opt_silent=true
    elif [ "$a" = "NOSILENT" ]; then
        opt_silent=false
    elif [ "$a" = "ALL" ]; then
	opt_graphics=gl
	opt_gui=forms
	opt_tcl=true
	opt_remote=true
	opt_cave=true
	opt_unc=true
	opt_optim=true
    elif [ "$a" = "NONE" ]; then
	opt_graphics=false
	opt_gui=false
	opt_tcl=false
	opt_remote=false
	opt_cave=false
	opt_alpha=false
	opt_unc=false
	opt_external=false
	opt_sigma=false
	opt_optim=false
	opt_debug=false
    else
       	echo "Unknown option $a"
	myusage
    fi
    doallopt=false
  fi
done

if [ $doallopt = true ]; then
  myoptions="GL FORMS TCL REMOTE CAVE UNC OPTIMIZE"
  opt_optim=true
else
  if [ $opt_graphics = gl ]; then
    myoptions="$myoptions GL"
  elif [ $opt_graphics = starbase ]; then
    myoptions="$myoptions STARBASE"  
  else
    myoptions="$myoptions NOGRAPHICS"
  fi

  if [ $opt_gui = forms ]; then
    myoptions="$myoptions FORMS"
  elif [ $opt_gui = tk ]; then
    myoptions="$myoptions TK"
    opt_tcl=true
  else
    myoptions="$myoptions NOGUI"
  fi

  if [ $opt_tcl = true ]; then myoptions="$myoptions TCL"; fi
  if [ $opt_remote = true ]; then myoptions="$myoptions REMOTE"; fi
  if [ $opt_cave = true ]; then myoptions="$myoptions CAVE"; fi
  if [ $opt_alpha = true ]; then myoptions="$myoptions ALPHA"; fi
  if [ $opt_unc = true ]; then myoptions="$myoptions UNC"; fi
  if [ $opt_external = true ]; then myoptions="$myoptions EXTERNAL"; fi
  if [ $opt_sigma = true ]; then myoptions="$myoptions SIGMA"; 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
  if [ $opt_silent = false ]; then myoptions="$myoptions NOSILENT"; 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 "DEFHTMLVIEWER		= $DEFHTMLVIEWER" >> $mkfile
echo "DEFBABELBIN		= $DEFBABELBIN" >> $mkfile
echo "DEFDISPLAY		= $DEFDISPLAY" >> $mkfile
echo "DEFTITLE			= $DEFTITLE" >> $mkfile
echo "DEFHEIGHT			= $DEFHEIGHT" >> $mkfile
echo "DEFDIST			= $DEFDIST" >> $mkfile
echo "DEFTMPDIR			= $DEFTMPDIR" >> $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 "TCLINCLUDEDIR		= $TCL_INCLUDE_DIR" >> $mkfile
echo "TCLLIBRARYDIR		= $TCL_LIBRARY_DIR" >> $mkfile

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

# next section: non-configurable declarations (except for NOSILENT)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if [ $opt_silent = true ]; then
  echo ".SILENT:" >> $mkfile
fi

cat << \MAKEDECLTXT >> $mkfile

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

# makefile configuration
VPATH                   = .:../src
SHELL 			= /bin/sh
.SUFFIXES: .C .c ..c .i .o

#################################################################
# 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

# information on how to create the distribution
BASEDISTRIBFILE		= $(INSTALLNAME)-$(PROGVERSION)
BASEDISTRIBALLFILE	= $(BASEDISTRIBFILE).all.tar
BASEDISTRIBBINFILE	= $(BASEDISTRIBFILE).bin.tar
LINKDISTRIBALLFILE	= $(INSTALLNAME).all.tar
LINKDISTRIBBINFILE	= $(INSTALLNAME).bin.tar
DISTRIBDIR		= $(BASEDISTRIBDIR)/$(BASEDISTRIBFILE)
DISTRIBMAINDIRS		= bin data lib proteins src
DISTRIBDOCDIRS		= doc
DISTRIBLIBS		= cave forms libg++ mdcomm unc
DISTRIBLIBSEXTRA	= cave forms libg++ unc
DISTRIBPROTEINS		= \
			$(PROTEINSDIR)/alanin.pdb \
			$(PROTEINSDIR)/alanin.psf \
			$(PROTEINSDIR)/alanin.DCD \
			$(PROTEINSDIR)/deoxy.pdb \
			$(PROTEINSDIR)/mbco.pdb \
			$(PROTEINSDIR)/star.pdb

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

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

# dir for extra libs (except for OPTIONS, must have -l & -L appended in front)
LIBDIRS	= -L. -L$(VMDLIBDIR)/libg++/lib_$(ARCH) $(OPTIONSLIBDIRS)

# the -ll is for the lex library - you might not need it
LIBS	= -ll -lg++ $(OPTIONSLIBS) -lm -lmalloc

# compiler and linker options
CFLAGS		= $(ARCH_COPTS)	$(OPTIMIZEFLAG) $(INCDIRS) \
			-DARCH_$(ARCH)	$(OPTIONSDEFS)	$(USER_COPTS)
CPPFLAGS	= $(ARCH_CPPOPTS)	$(OPTIMIZEFLAG) $(INCDIRS) \
			-DARCH_$(ARCH)	$(OPTIONSDEFS)	$(USER_CPPOPTS)

LFLAGS		= $(LIBDIRS) 	$(LIBS)	$(ARCH_LOPTS)
YFLAGS		= -d

#################################################################
# 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
GLINCDIR	=
GLLIBDIR	=
GLLIBNAME	= -lsphere -lfm_s -lgl_s 
LEX		= lex
YACC		= yacc

#####
# extra compiler and linker options
#####
ARCH_COPTS	=
ARCH_CPPOPTS	= 
ARCH_LOPTS      = -lsun -lc_s

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
GLINCDIR	=
GLLIBDIR	=
GLLIBNAME	= -lsphere -lfm_s -lgl_s 
LEX		= lex
YACC		= yacc

#####
# extra compiler and linker options
#####
ARCH_COPTS	=
ARCH_CPPOPTS	= 
ARCH_LOPTS      = -lc_s

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
GLINCDIR	= -I$(NPGLHOME)/include
GLLIBDIR	= -L/usr/lib/X11R5 -L$(NPGLHOME)/lib
GLLIBNAME	= -Wl,-a,archive -lnpgl_ansi \
		-Wl,-a,shared -lXwindow -lsb -lXhp11 -lX11 -lm -ldld
LEX		= lex
YACC		= yacc

#####
# extra compiler and linker options
# This is for compiling and linking with the NPGL library on HPUX 9.x
#####
ARCH_COPTS	= -Ae
ARCH_CPPOPTS	= +a1
ARCH_LOPTS      =

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" = "GL" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKEGLTXT >> $mkfile

#######################
# OPTIONAL COMPONENT: use GL library for windows and graphics
#	This specifies the libraries used for the rendering library and
#	window manager.
#######################

GRAPHICSDEF		= -DVMDGRAPHICS -DVMDGL
GRAPHICSINCDIR		= $(GLINCDIR)
GRAPHICSLIBDIR		= $(GLLIBDIR)
GRAPHICSLIB		= $(GLLIBNAME)
GRAPHICS_CCPP		= \
				GLDisplayDevice.C \
				GLRenderer.C
GRAPHICS_CC		=
GRAPHICS_H		= \
				GLDisplayDevice.h \
				GLRenderer.h
GRAPHICS_EXTRA		=
GRAPHICS_OBJS		= $(GRAPHICS_CCPP:.C=.o)	$(GRAPHICS_CC:.c=.o)

MAKEGLTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "STARBASE" ]; then                               
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKESTARBASETXT >> $mkfile                             
                                 
#######################
# OPTIONAL COMPONENT: use HP Starbase library for graphics.
#       This specifies the libraries used for the rendering library and  
#       window manager. libtksb is the Tk Starbase widget and Tcl bindings;   
#       configuring STARBASE requires (and specifies) TK and TCL as well.
#######################                                                    
                                                                      
GRAPHICSDEF             = -DVMDGRAPHICS -DVMDSTARBASE
GRAPHICSINCDIR          = -I/usr/include/X11R5        
GRAPHICSLIBDIR          = -L/usr/lib/X11R5
GRAPHICSLIB             = -ltksb -lXwindow -lsb -lsbdl -lXhp11 -lX11 -lm -ldld
GRAPHICS_CCPP           = \       
                                SBDisplayDevice.C \
                                SBRenderer.C
GRAPHICS_CC             =      
GRAPHICS_H              = \
                                SBDisplayDevice.h \
                                SBRenderer.h
GRAPHICS_EXTRA          =
GRAPHICS_OBJS           = $(GRAPHICS_CCPP:.C=.o)        $(GRAPHICS_CC:.c=.o)

MAKESTARBASETXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "TCL" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cat << \MAKETCLTXT >> $mkfile

#######################
# OPTIONAL COMPONENT: use Tcl library for script parsing and interpreting
#	Tcl allows VMD to contain a general scripting language with variables,
# control loops, and other fun stuff.  If it is not included, VMD text
# commands will still work, but the general interpreted script capabilities
# will not be available.  The Tcl library must already be installed on
# the system to allow this option to work.
#	All Tcl-specific code is contained in UIText.C
#######################

TCLDEF			= -DVMDTCL
TCLINCDIR		= -I$(TCLINCLUDEDIR)
TCLLIBDIR		= -L$(TCLLIBRARYDIR)
TCLLIB			= -ltcl
TCL_CCPP		=
TCL_CC			=
TCL_H			=
TCL_EXTRA		=
TCL_OBJS		= $(TCL_CCPP:.C=.o)	$(TCL_CC:.c=.o)

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

#######################
# OPTIONAL COMPONENT: Use FORMS GUI library
#	This specifies the library used for the on-screen GUI with buttons,
#	menus, etc.
#######################

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

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

#######################
# OPTIONAL COMPONENT: Use TK GUI library
#       This specifies the library used for the on-screen GUI with buttons,
#       menus, etc. This requires (and explicitly adds) the TCL option. 
#       Because TCLDIR etc. specify the location of Tk code as well,
#       not all of the variables are specified here. This also pulls in     
#       Extended Tcl and Tk, because they are so useful in writing Tcl code.
#######################

# TK version                         
GUIDEF                  = -DVMDGUI -DVMDTK   
GUIDIR                  = $(VMDLIBDIR)/tcl      
GUIINCDIR               = -I$(GUIDIR)/include
GUILIBDIR               = -L$(GUIDIR)/lib_$(ARCH)
GUILIB                  = -ltkx -ltk -ltclx -ltcl -lX11 -lm
GUI_CCPP                = \
				TclCmd.C \
                                UITk.C
GUI_CC                  =
GUI_H                   = UITk.h
GUI_EXTRA               =
GUI_OBJS                = $(GUI_CCPP:.C=.o)     $(GUI_CC:.c=.o)

MAKETKTXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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)

# executable programs for mdcomm system (in lib/mdcomm/bin_ARCH dir)
REMOTE_CONFDIR		= rappd
REMOTE_CONSUMER		= namd_consumer
REMOTE_APPDAEMON	= namdd
REMOTE_DAEMON		= rappd
REMOTE_PROGRAMS		= \
				$(REMOTE_CONSUMER) \
				$(REMOTE_APPDAEMON) \
				$(REMOTE_DAEMON)

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

#######################
# OPTIONAL COMPONENT: Sigma connection support
#	This may be commented out if not required.
#	This allows the program to connect to the Sigma MD code over
#	Unix sockets to control and view simulations online.
#######################

SIGMADEF		= -DVMDSIGMA
SIGMADIR		= $(VMDLIBDIR)/sigma
SIGMAINCDIR		= -I$(SIGMADIR)/include
SIGMALIBDIR		= -L$(SIGMADIR)/lib_$(ARCH)
SIGMALIB		= -lgeneral
SIGMA_CCPP		= \
				CmdSigma.C \
				PickModeDrag.C \
				MoleculeSigma.C
SIGMA_CC		=
SIGMA_H			= \
				CmdSigma.h \
				PickModeDrag.h \
				MoleculeSigma.h
SIGMA_EXTRA		=
SIGMA_OBJS		= $(SIGMA_CCPP:.C=.o)  $(SIGMA_CC:.c=.o)

MAKESIGMATXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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" ]; 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)
CAVELIB			= -lcave -lsnd
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)

MAKECAVETXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  elif [ "$opt" = "ALPHA" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   cat << \MAKEALPHATXT >> $mkfile

#######################
# OPTIONAL COMPONENT: Alpha shape code
#	This is the interface between vmd and the alpha shape programs
# from Edelsbrunner's group.  Their code has not yet been released so 
# it is doubtful that you will be able to use this.
#######################
ALPHADEF		= -DVMDALPHA_SHAPE
ALPHADIR		= $(VMDLIBDIR)/alpha
ALPHAINCDIR		= -I$(ALPHADIR)/include
ALPHALIBDIR		= -L$(ALPHADIR)/lib_$(ARCH)
ALPHALIB		= -l_alf
ALPHA_CCPP		= AlphaShape.C
ALPHA_CC		=
ALPHA_H			= AlphaShape.h
ALPHA_EXTRA		=
ALPHA_OBJS		= $(ALPHA_CCPP:.C=.o)	$(ALPHA_CC:.c=.o)

MAKEALPHATXT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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	= $(GRAPHICSDEF)	$(GUIDEF)	$(REMOTEDEF) \
			$(UNCDEF)	$(CAVEDEF) 	$(TCLDEF) \
			$(SIGMADEF)	$(EXTERNALDEF)	$(DEBUGDEF) \
			$(ALPHADEF)
OPTIONSINCDIRS	= $(GRAPHICSINCDIR)	$(GUIINCDIR)	$(REMOTEINCDIR) \
			$(UNCINCDIR)	$(CAVEINCDIR) 	$(TCLINCDIR) \
			$(SIGMAINCDIR)	$(EXTERNALINCDIR) \
			$(ALPHAINCDIR)
OPTIONSLIBDIRS	= $(GRAPHICSLIBDIR)	$(GUILIBDIR)	$(REMOTELIBDIR) \
			$(UNCLIBDIR)	$(CAVELIBDIR) 	$(TCLLIBDIR)  \
			$(SIGMALIBDIR)	$(EXTERNALLIBDIR) \
			$(ALPHALIBDIR)
OPTIONSLIBS	= $(GRAPHICSLIB)	$(GUILIB)	$(REMOTELIB) \
			$(UNCLIB)	$(CAVELIB) 	$(TCLLIB) \
			$(SIGMALIB)	$(EXTERNALLIB)  $(ALPHALIB)
OPTIONS_CCPP	= $(GRAPHICS_CCPP)	$(GUI_CCPP)	$(REMOTE_CCPP) \
			$(UNC_CCPP)	$(CAVE_CCPP) 	$(TCL_CCPP) \
			$(SIGMA_CCPP)	$(EXTERNAL_CCPP) \
			$(ALPHA_CCPP)
OPTIONS_CC	= $(GRAPHICS_CC)	$(GUI_CC)	$(REMOTE_CC) \
			$(UNC_CC)	$(CAVE_CC) 	$(TCL_CC) \
			$(SIGMA_CC)	$(EXTERNAL_CC)	$(ALPHA_CC)
OPTIONS_H	= $(GRAPHICS_H)		$(GUI_H)	$(REMOTE_H) \
			$(UNC_H)	$(CAVE_H) 	$(TCL_H) \
			$(SIGMA_H)	$(EXTERNAL_H)	$(ALPHA_H)
OPTIONS_EXTRA	= $(GRAPHICS_EXTRA)	$(GUI_EXTRA)	$(REMOTE_EXTRA) \
			$(UNC_EXTRA)	$(CAVE_EXTRA) 	$(TCL_EXTRA) \
			$(SIGMA_EXTRA)	$(EXTERNAL_EXTRA) \
			$(ALPHA_EXTRA)
OPTIONS_OBJS	= $(GRAPHICS_OBJS)	$(GUI_OBJS)	$(REMOTE_OBJS) \
			$(UNC_OBJS)	$(CAVE_OBJS) 	$(TCL_OBJS) \
			$(SIGMA_OBJS)	$(EXTERNAL_OBJS) \
			$(ALPHA_OBJS)
OPTIONS_SRCS	= $(OPTIONS_CCPP)	$(OPTIONS_CC)

#######################
# 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 \
		BabelConvert.C \
		BaseMolecule.C \
		Buttons.C \
		CmdAnimate.C \
		CmdColor.C \
		CmdDisplay.C \
		CmdLabel.C \
		CmdMenu.C \
		CmdMol.C \
		CmdMouse.C \
		CmdPick.C \
		CmdRender.C \
		CmdTool.C \
		CmdTracker.C \
		CmdTrans.C \
		CmdUser.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 \
		FileRenderList.C \
		FileRenderer.C \
		Geometry.C \
		GeometryAngle.C \
		GeometryAtom.C \
		GeometryBond.C \
		GeometryDihedral.C \
		GeometryList.C \
		GeometryMol.C \
		GeometryTug.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 \
		ParseTree.C \
		PickList.C \
		PickMode.C \
		PickModeMolLabel.C \
		PickModeQuery.C \
		Pickable.C \
		PointerTool.C \
		PopupMenu.C \
		POVDisplayDevice.C \
		RayShadeDisplayDevice.C \
		R3dDisplayDevice.C \
		ReadDCD.C \
		ReadEDM.C \
		ReadPDB.C \
		ReadPSF.C \
		Scene.C \
		Stage.C \
		SymbolTable.C \
		TextTracker.C \
		Timer.C \
		Timestep.C \
		Tokenize.C \
		Tool.C \
		ToolControl.C \
		Tracker.C \
		TrackerList.C \
		UIList.C \
		UIObject.C \
		UIText.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 \
		BabelConvert.h \
		BaseMolecule.h \
		Buttons.h \
		CmdAnimate.h \
		CmdColor.h \
		CmdDisplay.h \
		CmdLabel.h \
		CmdMenu.h \
		CmdMol.h \
		CmdMouse.h \
		CmdPick.h \
		CmdRender.h \
		CmdTool.h \
		CmdTracker.h \
		CmdTrans.h \
		CmdUser.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 \
		FileRenderList.h \
		FileRenderer.h \
		Fragment.h \
		Geometry.h \
		GeometryAngle.h \
		GeometryAtom.h \
		GeometryBond.h \
		GeometryDihedral.h \
		GeometryList.h \
		GeometryMol.h \
		GeometryTug.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 \
		ParseTree.h \
		PickList.h \
		PickMode.h \
		PickModeMolLabel.h \
		PickModeQuery.h \
		Pickable.h \
		PointerTool.h \
		PopupMenu.h \
		POVDisplayDevice.h \
		RayShadeDisplayDevice.h \
		R3dDisplayDevice.h \
		ResizeArray.h		ResizeArray.c \
		ReadDCD.h \
		ReadEDM.h \
		ReadPDB.h \
		ReadPSF.h \
		Residue.h \
		Scene.h \
		Stack.h 		Stack.c \
		Stage.h \
		SymbolTable.h \
		TextTracker.h \
		Timer.h \
		Timestep.h \
		Tokenize.h \
		Tool.h \
		ToolControl.h \
		Tracker.h \
		TrackerList.h \
		UIList.h \
		UIObject.h \
		UIText.h \
		UIVR.h \
		VButton.h \
		VMDTitle.h \
		VRegion.h \
		VRegionList.h \
		startup.h \
		utilities.h

# VMD yacc and lex files.  There is only one of each,
#  and they are used for the atom selection parser
VMD_YACC	= AtomParser.y

VMD_LEX		= AtomLexer.l

# summary of the above files
VMD_SRCS	= $(VMD_CCPP)		$(VMD_CC) \
		  $(VMD_YACC)		$(VMD_LEX)
VMD_OBJS	= $(VMD_CCPP:.C=.o)	$(VMD_CC:.c=.o) \
		  $(VMD_LEX:.l=.o)	$(VMD_YACC:.y=.o)

# data files, such as the .vmdrc and other files
VMD_DATA	= \
		vmd_help.html \
		.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_YACC_SRCS	= $(VMD_YACC)		$(OPTIONS_YACC)
ALL_LEX_SRCS	= $(VMD_LEX)		$(OPTIONS_LEX)
ALL_SRCS	= $(VMD_SRCS)		$(OPTIONS_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	= \
		Announcement \
		ChangeLog \
		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.tex \
		ug_basics.tex \
		ug_chapters.tex \
		ug_exec_env.tex \
		ug_file_types.tex \
		ug_form_animate.tex \
		ug_form_color.tex \
		ug_form_display.tex \
		ug_form_edit.tex \
		ug_form_file.tex \
		ug_form_graphics.tex \
		ug_form_labels.tex \
		ug_form_main.tex \
		ug_form_mol.tex \
		ug_form_remote.tex \
		ug_form_render.tex \
		ug_form_tracker.tex \
		ug_forms.tex \
		ug_future.tex \
		ug_intro.tex \
		ug_mdcomm.tex \
		ug_misc.tex \
		ug_mol_colors.tex \
		ug_mol_reps.tex \
		ug_mol_selection.tex \
		ug_mouse_display.tex \
		ug_mouse_forms.tex \
		ug_other_ui.tex \
		ug_rendering.tex \
		ug_simulation.tex \
		ug_stereo.tex \
		ug_text_ui.tex \
		ug_topics.tex \
		ug_tutorial.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 \
		ColorList.tex \
		ColorUser.tex \
		Command.tex \
		CommandQueue.tex \
		Animation.tex \
		Atom.tex \
		BaseMolecule.tex \
		DLinkList.tex \
		DispCmd.tex \
		DisplayDevice.tex \
		Displayable.tex \
		DrawMolecule.tex \
		Inform.tex \
		Matrix4.tex \
		Molecule.tex \
		Mouse.tex \
		PopupMenu.tex \
		PopupMenuItem.tex \
		NameList.tex \
		ResizeArray.tex \
		Scene.tex \
		Stack.tex \
		Timer.tex \
		Timestep.tex \
		UIList.tex \
		UIObject.tex \
		UIText.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.i:
	$(ECHO) "Preprocessing " $< " --> " $*.i " ..."; \
	$(CCPP) $(CPPFLAGS) -E $(SRCDIR)/$< > $*.i

.C..c:
	$(ECHO) "Translating " $< " --> " $*..c " ..."; \
	$(CCPP) $(CPPFLAGS) -Fc $(SRCDIR)/$< > $*..c

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

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

.y.o:
	$(ECHO) "Converting " $< " --> "$@ " ..."; \
	$(YACC) $(YFLAGS) $<
	$(CCPP) $(CFLAGS) -c y.tab.c
	rm y.tab.c
	mv y.tab.o $@

.l.o:
	$(ECHO) "Converting " $< " --> "$@ " ..."; \
	$(LEX) $<
	$(CCPP) $(CFLAGS) -c lex.yy.c
	mv lex.yy.o $@


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

all default:	$(PROGNAME)

#### executables

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

#### 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 +'%B %e, %Y'`\)\" >> config.h ; \
	$(ECHO) \#define CMDLEN $(MAXSTRINGLEN) >> config.h ; \
	$(ECHO) \#define DEF_VMDHTMLVIEWER \"$(DEFHTMLVIEWER)\" >> config.h; \
	$(ECHO) \#define DEF_VMDBABELBIN \"$(DEFBABELBIN)\" >> config.h ; \
	$(ECHO) \#define DEF_VMDENVVAR \"$(INSTALLLIBDIR)\" >> config.h ; \
	$(ECHO) \#define DEF_VMDTMPDIR \"$(DEFTMPDIR)\" >> 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) \#define VMD_AUTHORS   \"$(AUTHORS)\" >> 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) \#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 +'%B %e, %Y'`\} >> 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 install.doc

### install program and data files in proper directory (i.e. everything except docs)
install: install.exe install.scripts install.data install.mdcomm

### create installation directories
install.dir:
	if [ ! -d $(INSTALLLIBDIR) ]; then \
		$(MAKEDIR) $(INSTALLLIBDIR); \
	fi ; \
	if [ ! -d $(INSTALLLIBDIR)/doc ]; then \
		$(MAKEDIR) $(INSTALLLIBDIR)/doc; \
	fi

### install executable
install.exe: install.dir
	$(ECHO) "Installing executable in $(INSTALLLIBDIR)"; \
	$(CD) $(SRCDIR); \
	if [ -f $(INSTALLLIBDIR)/$(PROGNAME) ]; then \
		$(COPY) $(INSTALLLIBDIR)/$(PROGNAME) \
			$(INSTALLLIBDIR)/$(PROGNAME)_old ; \
	fi; \
	$(COPY) $(PROGNAME)   $(INSTALLLIBDIR) ; \
	chmod u+w $(INSTALLLIBDIR)/$(PROGNAME)

### install executable and scripts and utilities
install.scripts: install.dir
	$(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 ; \
	$(ECHO) 'set consumer='$(REMOTE_CONSUMER) >> run_vmd_tmp ; \
	cat $(VMD_BIN) >> run_vmd_tmp ; \
	chmod +x run_vmd_tmp ; \
	$(COPY) run_vmd_tmp $(INSTALLBINDIR)/$(INSTALLNAME) ; \
	$(DELETE) run_vmd_tmp

### install data files in proper directory
install.data: install.dir
	$(ECHO) "Installing data files in $(INSTALLLIBDIR)"; \
	$(CD) $(DATADIR); \
	$(COPY) vmd_help.html .tracker $(INSTALLLIBDIR) ; \
	$(COPY) .vmd_init $(INSTALLLIBDIR)/$(INITFILENAME) ; \
	$(COPY) .vmdrc $(INSTALLLIBDIR)/$(STARTUPFILENAME) ; \
	$(CD) $(INSTALLLIBDIR) ; \
	chmod u+w .tracker vmd_help.html $(INITFILENAME) $(STARTUPFILENAME)

### install MDCOMM files (if necessary)
install.mdcomm: install.dir
	if [ "$(REMOTEDEF)" != "" ]; then \
	  $(ECHO) "Installing mdcomm files in $(INSTALLLIBDIR)/mdcomm"; \
	  if [ ! -d $(INSTALLLIBDIR)/mdcomm ]; then \
	    $(MAKEDIR) $(INSTALLLIBDIR)/mdcomm ; \
	  fi ; \
	  if [ ! -d $(INSTALLLIBDIR)/mdcomm/$(REMOTE_CONFDIR) ]; then \
	    $(MAKEDIR) $(INSTALLLIBDIR)/mdcomm/$(REMOTE_CONFDIR) ; \
	  fi ; \
	  if [ -f $(VMDLIBDIR)/mdcomm/bin_$(ARCH)/$(REMOTE_CONSUMER) ]; then \
	    $(COPY) $(VMDLIBDIR)/mdcomm/bin_$(ARCH)/$(REMOTE_CONSUMER)  \
		$(INSTALLLIBDIR)/mdcomm/$(REMOTE_CONSUMER)_$(ARCH) ; \
	  fi; \
	  if [ -f $(VMDLIBDIR)/mdcomm/bin_$(ARCH)/$(REMOTE_APPDAEMON) ];then \
	    $(COPY) $(VMDLIBDIR)/mdcomm/bin_$(ARCH)/$(REMOTE_APPDAEMON)  \
		$(INSTALLLIBDIR)/mdcomm/$(REMOTE_APPDAEMON)_$(ARCH) ; \
	  fi; \
	  if [ -f $(VMDLIBDIR)/mdcomm/bin_$(ARCH)/$(REMOTE_DAEMON) ];then \
	    $(COPY) $(VMDLIBDIR)/mdcomm/bin_$(ARCH)/$(REMOTE_DAEMON)  \
		$(INSTALLLIBDIR)/mdcomm/$(REMOTE_DAEMON)_$(ARCH) ; \
	  fi; \
	  $(COPY) $(VMDLIBDIR)/mdcomm/$(REMOTE_CONFDIR)/* \
		$(INSTALLLIBDIR)/mdcomm/$(REMOTE_CONFDIR); \
	fi

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

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

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

#### copy over the bin files
distrib.bin:	distrib.dir
	$(ECHO) "Copying distribution files from 'bin' ..." ; \
	$(CD) $(BINDIR) ; \
	$(COPY) $(VMD_BIN) $(BIN_FILES) $(DISTRIBDIR)/bin

#### copy over the data files
distrib.data:	distrib.dir
	$(ECHO) "Copying distribution files from 'data' ..." ; \
	$(CD) $(DATADIR) ; \
	$(COPY) $(DATA_FILES) $(DISTRIBDIR)/data

#### copy over the documentation files
distrib.doc:	distrib.dir
	$(ECHO) "Copying distribution files from 'doc' ..." ; \
	$(CD) $(DOCDIR) ; \
	$(COPY) ig.ps pg.ps ug.ps $(DISTRIBDIR)/doc ; \

#### copy over the protein files
distrib.proteins:	distrib.dir
	$(ECHO) "Copying distribution files from 'proteins' ..." ; \
	$(COPY) $(DISTRIBPROTEINS) $(DISTRIBDIR)/proteins

#### create a tar file in the lib directory
distrib.lib.tar:
	$(ECHO) "Creating lib tar file ..." ; \
	$(CD) $(VMDLIBDIR) ; \
	if [ -f libtar.tar ] ; then $(DELETE) libtar.tar; fi ; \
	$(TAR) cf libtar.tar $(DISTRIBLIBS)

#### copy the tar file over to the distrib lib file, and untar it
distrib.lib:	distrib.dir distrib.lib.tar
	$(ECHO) "Copying distribution files from 'lib' ..." ; \
	$(MOVE) $(VMDLIBDIR)/libtar.tar $(DISTRIBDIR)/lib ; \
	$(CD) $(DISTRIBDIR)/lib ; \
	$(TAR) xf libtar.tar ; \
	$(DELETE) libtar.tar

#### copy over the source files, removing the revision history text
distrib.src:	distrib.dir
	$(ECHO) "Copying distribution files from 'src' ..." ; \
	$(CD) $(SRCDIR) ; \
	$(COPY) Makefile Makedata.depend $(DISTRIBDIR)/src ; \
	for i in `ls -1 *.C *.c *.h *.y *.l *.fd` ; do \
	  cat $$i | awk '{ while(1>0) { \
				if($$1!="/*" || $$2!="REVISION") { \
					print \
				} else { \
					break \
				} \
				if(getline < 1) { \
					break \
				} \
			   } \
			   exit \
			 }' > $(DISTRIBDIR)/src/$$i ; \
	done

#### copy over the vmd executable
distrib.exe:		distrib.dir
	$(ECHO) "Copying executable to distribution directory ..." ; \
	$(CD) $(SRCDIR) ; \
	$(COPY) $(PROGNAME) $(DISTRIBDIR)/src

#### 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

#### copy over the main files
distrib.top:	distrib.conf.par
	$(ECHO) "Copying top-level distribution files ..." ; \
	$(CD) .. ; \
	$(COPY) $(MAIN_DIR_FILES) configure.options src/$(DISTRIBDIR)/.

#### the main copying driver
distrib.copy:	distrib.bin distrib.data distrib.proteins distrib.lib \
			distrib.src distrib.exe distrib.doc distrib.top
	chmod -R u+w $(DISTRIBDIR)/. ; \
	chmod -R go-w $(DISTRIBDIR)/.

#### compress the distribution once is has been produced
distrib.compress:	distrib.copy
	$(CD) ../distrib ; \
	$(ECHO) "Creating and compressing $(BASEDISTRIBALLFILE).gz ..."; \
	if [ -f $(BASEDISTRIBALLFILE).gz ]; then \
	  $(MOVE) $(BASEDISTRIBALLFILE).gz $(BASEDISTRIBALLFILE).gz.old; \
	fi ; \
	$(TAR) cf - $(BASEDISTRIBFILE) | \
	  $(GNUCOMPRESS) > $(BASEDISTRIBALLFILE).gz ; \
	$(ECHO) "Creating and compressing $(BASEDISTRIBALLFILE).Z ..."; \
	if [ -f $(BASEDISTRIBALLFILE).Z ]; then \
	  $(MOVE) $(BASEDISTRIBALLFILE).Z $(BASEDISTRIBALLFILE).Z.old; \
	fi ; \
	$(TAR) cf - $(BASEDISTRIBFILE) | \
	  $(COMPRESS) > $(BASEDISTRIBALLFILE).Z ; \
	$(ECHO) "Removing extra files to create $(BASEDISTRIBBINFILE) ..." ; \
	$(CD) $(BASEDISTRIBFILE)/src ; \
	$(DELETE) *.C *.c *.h *.y *.l *.fd ; \
	$(CD) ../lib ; \
	$(DELETEDIR) $(DISTRIBLIBSEXTRA) ; \
	$(CD) ../.. ; \
	$(ECHO) "Creating and compressing $(BASEDISTRIBBINFILE).gz ..."; \
	if [ -f $(BASEDISTRIBBINFILE).gz ]; then \
	  $(MOVE) $(BASEDISTRIBBINFILE).gz $(BASEDISTRIBBINFILE).gz.old; \
	fi ; \
	$(TAR) cf - $(BASEDISTRIBFILE) | \
	  $(GNUCOMPRESS) > $(BASEDISTRIBBINFILE).gz ; \
	$(ECHO) "Creating and compressing $(BASEDISTRIBBINFILE).Z ..."; \
	if [ -f $(BASEDISTRIBBINFILE).Z ]; then \
	  $(MOVE) $(BASEDISTRIBBINFILE).Z $(BASEDISTRIBBINFILE).Z.old; \
	fi ; \
	$(TAR) cf - $(BASEDISTRIBFILE) | \
	  $(COMPRESS) > $(BASEDISTRIBBINFILE).Z

#### the main distribution creation target ... starts the whole chain ...
dist distribution distrib:	distrib.compress
	$(ECHO) "Deleting temporary distribution directory ..."; \
	$(DELETEDIR) $(DISTRIBDIR)

#### put distrib file out for anon ftp
justftp ftp:
	$(ECHO) "Copying distribution to the FTP directory ..."; \
	$(CD) .. ; \
	$(COPY) README ChangeLog $(FTPDIR) ; \
	$(CD) distrib ; \
	$(COPY) $(BASEDISTRIBALLFILE).gz $(BASEDISTRIBBINFILE).gz $(FTPDIR); \
	$(COPY) $(BASEDISTRIBALLFILE).Z  $(BASEDISTRIBBINFILE).Z  $(FTPDIR); \
	$(CD) $(FTPDIR) ; \
	chmod u+w README ChangeLog ; \
	if [ -h $(LINKDISTRIBALLFILE).gz ]; then \
	  $(DELETE) $(LINKDISTRIBALLFILE).gz; \
	fi; \
	if [ -h $(LINKDISTRIBALLFILE).Z ]; then \
	  $(DELETE) $(LINKDISTRIBALLFILE).Z; \
	fi; \
	if [ -h $(LINKDISTRIBBINFILE).gz ]; then \
	  $(DELETE) $(LINKDISTRIBBINFILE).gz; \
	fi; \
	if [ -h $(LINKDISTRIBBINFILE).Z ]; then \
	  $(DELETE) $(LINKDISTRIBBINFILE).Z; \
	fi; \
	ln -s $(BASEDISTRIBALLFILE).gz $(LINKDISTRIBALLFILE).gz ; \
	ln -s $(BASEDISTRIBALLFILE).Z  $(LINKDISTRIBALLFILE).Z  ; \
	ln -s $(BASEDISTRIBBINFILE).gz $(LINKDISTRIBBINFILE).gz ; \
	ln -s $(BASEDISTRIBBINFILE).Z  $(LINKDISTRIBBINFILE).Z ; \
	chgrp -R vmd . ; \
	chmod -R g+w .

#### the whole show, do the distribution and put on ftp
ftpall: distrib justftp


###############################
### 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 config conf:
	$(ECHO) "Reconfiguring ..." ;\
	$(CD) .. ;\
	configure

### cleanup target

clean:
	$(DELETE) *.o *.i *.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 rules to create dependencies and to automatically check
# files out from the RCS
###########################
if [ "$myarch" = "IRIX4" -o "$myarch" = "IRIX5" ]; then
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cat << \MAKEDEPENDTXT >> $mkfile
# create dependencies file ... does not work on all architectures
# also, the yacc/lex dependencies must be done by hand
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
	echo "AtomParser.o: AtomParser.y" >> $(DEPENDFILE)
	echo "AtomParser.o: AtomParser.h" >> $(DEPENDFILE)
	echo "AtomLexer.o: AtomParser.o" >> $(DEPENDFILE)
	echo "ParseTree.o: AtomParser.o" >> $(DEPENDFILE)
	echo "y.tab.h: AtomParser.o" >>  $(DEPENDFILE)

$(ALL_SRCS) $(ALL_H) $(EXTRA_FILES) $(DATA_FILES) $(SCRIPT_FILES) $(DOC_FILES):
	@echo "  Retrieving $@ from RCS directory"
	$(COCMD) $@

config.h vmd_version.tex:
	true

#################################################################
# 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
