#!/usr/bin/env perl
# (C) Copyright 1995-2003 The Board of Trustees of the University of Illinois
#     All Rights Reserved
#
# Usage: configure [ optionlist ]   (See full option description down below)
# Perl 5.x must be in your path, and /usr/bin/env must exist in order
# for this to work correctly.

##############################################################################
# User modifiable installation parameters, can be overridden by env variables
##############################################################################
# Name of shell script used to start program; this is the name used by users
$install_name = "vmd";

# Directory where VMD startup script is installed, should be in users' paths.
$install_bin_dir="/usr/local/bin";

# Directory where VMD files and executables are installed
$install_library_dir="/usr/local/lib/$install_name";


# optionally override hard-coded defaults above with environment variables
if ($ENV{VMDINSTALLNAME}) {
  $install_name = $ENV{VMDINSTALLNAME}
}
if ($ENV{VMDINSTALLBINDIR}) {
  $install_bin_dir = $ENV{VMDINSTALLBINDIR}
}
if ($ENV{VMDINSTALLLIBRARYDIR}) {
  $install_library_dir = $ENV{VMDINSTALLLIBRARYDIR}
}

##############################################################################
# You shouldn't normally need to modify anything below this point, though some
# people will have to change include/library paths if compiling from source.
##############################################################################
# Usage: configure [ optionlist ]
# where [ optionlist ] is one or more of the following, separated by spaces:
# If conflicting options are given, the last one in the command is used.
# 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.
#
# Architectures:
# ---------------------------------------------------------------
# AIX4        - compile on an RS/6000 machine (gcc/g++/xlc/xlC)
# FREEBSD     - compile on a FreeBSD machine (gcc/g++)
# HPUX11      - compile on an HP-UX 11.0 machine (cc/CC/cc/aCC)
# IRIX6       - compile on an SGI, IRIX 6.X or later, 32-bit ABI
# IRIX6_64    - compile on an SGI, IRIX 6.X or later, 64-bit ABI
# LINUX       - compile on a Linux machine
# LINUXALPHA  - compile on a Linux machine
# LINUXPPC    - compile on a Linux machine
# MACOSX      - compile on a MacOS-X machine
# TRU64       - compile on a DEC Alpha/Digital Unix 4.0 machine
# SOLARIS2    - compile on a Solaris machine, 32-bit ABI
# SOLARIS2_64 - compile on a Solaris machine, 64-bit ABI
# SOLARISX86  - compile on a Solaris x86 machine
# WIN32       - compile on a Win32 machine (NT, 95, 98, etc)
#
# Hardware Accelerated (hopefully) Graphics Libraries:
# ---------------------------------------------------------------
# OPENGL     - use OpenGL for graphics
# SDL        - use SDL and OpenGL for graphics
# FLTKOPENGL - use FLTK to create an OpenGL window for graphics
# MESA       - use Mesa libraries for OpenGL API emulation (enables OPENGL)
# CAVE       - compile with the GL or OpenGL CAVE libraries
# FREEVR     - compile with the OpenGL FreeVR libraries
# ACTC       - triangle mesh stripification library for higher speed surfaces
# 
# Graphical user interface libraries:
# ---------------------------------------------------------------
# FLTK     - Fast Light Tool Kit (FORMS/XFORMS workalike) 
# TK       - enable use of TK library                     
#
# Optional components:
# ---------------------------------------------------------------
# IMD        - include option for connecting to remote MD simulations
# VRPN       - include VRPN tracker lib for spatial trackers
# SPACEBALL  - spaceball 6DOF input device
# LIBTACHYON - built-in raytracing via Tachyon library
# CONTRIB    - user contributed code for VMD which has restrictions
# TCL        - The Tcl scripting language
# PYTHON     - The Python scripting language
# PTHREADS   - POSIX Threads Support
# SWIG       - A Swig-generated interface
# NUMPY    - Numeric Python extensions
#
# Compiler options:
# ---------------------------------------------------------------
# STATIC     - link to static libraries only
# LP64       - compile for a 64-bit ABI instead of 32-bit if possible
# ACC        - compile with HP aCC (instead of CC)
# GCC        - compile with gcc (instead of the vendor supplied one)
# KCC        - compile with Kuck and Associates KCC compiler 
# PURIFY     - compile with purify instrumentation
# SILENT     - suppress the make command echo
# SHARED     - compile a shared library instead of a standalone executable
# CCACHE     - compile with ccache (requires local configuration)
#

############################################################################
# Configure script code begins here
############################################################################

#################### Parse command line options   ###########
# list of allowed architectures
@archlist=('IRIX6', 'IRIX6_64', 'FREEBSD', 'HPUX11', 'AIX4', 'LINUX', 'LINUXALPHA', 'LINUXPPC', 'MACOSX', 'TRU64', 'SOLARIS2', 'SOLARIS2_64', 'SOLARISX86', 'WIN32');

if ($#ARGV == -1) {
    $text = `cat configure.options`;
    chop($text);
    print "using configure.options: $text\n";
    $text =~ s/^\s*//g;
    $text =~ s/\s*$//g;
    $text =~ s/\s+/ /g;
    @ARGV = split(/\s/, $text);
}

$config_arch = shift @ARGV;
if ( ! grep( $_ eq $config_arch , @archlist)) {
    die "Architecture $config_arch not supported (@archlist)\n";
}

$config_opengl      = 0;  # OpenGL
$config_mesa        = 0;  # Mesa (OpenGL workalike)
$config_cave        = 0;  # CAVE (SGI-only)
$config_freevr      = 0;  # FreeVR
$config_actc        = 0;  # ACTC
 
$config_fltk        = 0;  # FLTK user interface
$config_fltkopengl  = 0;  # FLTK-based OpenGL display window
$config_sdl         = 0;  # SDL-based OpenGL display window
$config_tk          = 0;  # Tk interface extensions
 
$config_imd         = 0;  # interactive MD sockets code etc.
$config_spaceball   = 0;  # spaceball 6dof input support 
$config_libtachyon  = 0;  # Built-in Tachyon ray tracing support 
$config_vrpn        = 0;  # VRPN tracker/wand/haptic support
$config_sigma       = 0;  # Sigma support
$config_contrib     = 0;  # VMD Contributed code, off by default

$config_silent      = 0;  # noisy makefiles (can't turn this off, only on...)
$config_system      = 1;  # this is always on 
$config_vmd         = 1;  # this is always on 
$config_plugin      = 1;  # this is always on 

$config_swig        = 0;  # off by default
$config_numeric     = 0;  # off by default

foreach $term (@ARGV) {
    # graphics/windowing library
    if ($term eq "OPENGL")     { $config_opengl     = 1; next; }
    if ($term eq "SDL")        { $config_sdl        = 1; next; }
    if ($term eq "FLTKOPENGL") { $config_fltkopengl = 1; next; }
    if ($term eq "MESA")       { $config_mesa       = 1; next; }
    if ($term eq "CAVE")       { $config_cave       = 1; next; }
    if ($term eq "FREEVR")     { $config_freevr     = 1; next; }
    if ($term eq "ACTC")       { $config_actc       = 1; next; }

    # GUI options
    if ($term eq "FLTK" )      { $config_fltk       = 1; next; }
    if ($term eq "TK")         { $config_tk         = 1; next; }
    
    # Optional components
    if ($term eq "IMD")        { $config_imd        = 1; next; }
    if ($term eq "SPACEBALL")  { $config_spaceball  = 1; next; }
    if ($term eq "LIBTACHYON") { $config_libtachyon = 1; next; }
    if ($term eq "VRPN")       { $config_vrpn       = 1; next; }
    if ($term eq "CONTRIB")    { $config_contrib    = 1; next; }
    if ($term eq "TCL")        { $config_tcl        = 1; next; }
    if ($term eq "PYTHON")     { $config_python     = 1; next; }
    if ($term eq "PTHREADS")   { $config_pthreads   = 1; next; }
    if ($term eq "SWIG")       { $config_swig       = 1; next; }
    if ($term eq "NUMPY")      { $config_numeric    = 1; next; }

    # once optional, these are now required.  They exist for backwards
    # compatibility; some may be expanded again in the future
    if ($term eq "SURF")       { next; }
    if ($term eq "MSMS")       { next; }

    # compiler and make options 
    if ($term eq "SILENT")     { $config_silent = 1; next; }
    if ($term eq "NOSILENT")   { $config_silent = 0; next; }
    if ($term eq "STATIC")     { $config_static = 1; next; }
    if ($term eq "LP64")       { $config_lp64 = 1;   next; }
    if ($term eq "ACC")        { $config_acc = 1;    next; }
    if ($term eq "GCC")        { $config_gcc = 1;    next; }
    if ($term eq "KCC")        { $config_kcc = 1;    next; }
    if ($term eq "PURIFY")     { $config_purify = 1; next; }
    if ($term eq "SHARED")     { $config_shared = 1; next; }
    if ($term eq "CCACHE")     { $config_ccache = 1; next; }


    # error conditions
    die "Unknown option '$term'\n";
}

# convert back to a string and save
$config_string = "$config_arch";
if ($config_opengl)     { $config_string .= " OPENGL"      }
if ($config_sdl)        { $config_string .= " SDL"         }
if ($config_fltkopengl) { $config_string .= " FLTKOPENGL"  }
if ($config_mesa)       { $config_string .= " MESA"        }
if ($config_cave)       { $config_string .= " CAVE"        }
if ($config_freevr)     { $config_string .= " FREEVR"      }
if ($config_actc)       { $config_string .= " ACTC"        }

if ($config_fltk)       { $config_string .= " FLTK"        }
if ($config_tk)         { $config_string .= " TK"          }

if ($config_imd)        { $config_string .= " IMD"         }
if ($config_spaceball)  { $config_string .= " SPACEBALL"   }
if ($config_libtachyon) { $config_string .= " LIBTACHYON"  }
if ($config_vrpn)       { $config_string .= " VRPN"        }
if ($config_contrib)    { $config_string .= " CONTRIB"     }
if ($config_tcl)        { $config_string .= " TCL"         }
if ($config_python)     { $config_string .= " PYTHON"      }
if ($config_pthreads)   { $config_string .= " PTHREADS"    }
if ($config_swig)       { $config_string .= " SWIG"        }
if ($config_numeric)    { $config_string .= " NUMPY"       }

if ($config_silent)     { $config_string .= " SILENT"      }
if ($config_static)     { $config_string .= " STATIC"      }
if ($config_lp64)       { $config_string .= " LP64"        }

if ($config_acc)        { $config_string .= " ACC"         }
if ($config_gcc)        { $config_string .= " GCC"         }
if ($config_kcc)        { $config_string .= " KCC"         }
if ($config_purify)     { $config_string .= " PURIFY"      }
if ($config_shared)     { $config_string .= " SHARED"      }
if ($config_ccache)     { $config_string .= " CCACHE"      }

if (!open(OUTFILE, ">configure.options")) {
    print STDERR "** Cannot save parameters to configure.options: $!\n";
} else {
    print OUTFILE "$config_string\n";
    close(OUTFILE);
}

# This is where 'vmd_IRIX6' or 'vmd_SOLARIS2' gets created
$config_progname = "vmd_${config_arch}";

# Tcl and Python expects shared libraries to be named like this.
if ($config_shared) {
  $config_progname = "vmd.so";
}


#########################     GLOBAL DEFINES    #######################

# default screen height, a floating-point value.  This distance is in 'world'
# coordinate system
$def_height="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.
$def_dist="-2.0";

# whether or not to display the program title on startup: ON or OFF
$def_title="ON";

# default temporary file storage directory
$def_tmpdir="/tmp";

# name of the external image viewer program for this machine
$def_imageviewer="display %s";

# program version number
$progversion="1.8.1";

# text prompt string
$promptstring="vmd > ";

# startup command script file.  Read after program initialization.
$startupfilename=".vmdrc";

# main VMD url
$vmd_homepage="http://www.ks.uiuc.edu/Research/vmd/";

# VMD help url
$vmd_helppage="http://www.ks.uiuc.edu/Research/vmd/";

# who is to blame for this version of VMD.
$versionauthors="E. Caddigan, J. Cohen, J. Gullingsrud, J. Stone";

# who is actually to blame for this whole mess
$authorsline1="E. Caddigan, A. Dalke, P. Grayson, J. Gullingsrud, W. Humphrey, ";
$authorsline2="B. Isralewitz, S. Izrailev, D. Norris, J. Stone, J. Ulrich";
$authorsline3="";
$authors= $authorsline1 . $authorsline2 . $authorsline3;

#################### GENERIC OPTIONS FOR EACH MODULE ##################

# name of the script used for creating $install_name
$vmd_name    = "vmd";

################     VMD directory defines

# 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
$vmd_main_dir       = "../.";
$vmd_src_dir        = "../src";
$vmd_library_dir    = "../lib";
$vmd_data_dir       = "../data";
$vmd_doc_dir        = "../doc";
$vmd_bin_dir        = "../bin";
$vmd_proteins_dir   = "../proteins";
$vmd_distrib_dir    = "../distrib";
$vmd_arch_dir       = "../$config_arch";

################  General generic architecture settings
$arch_cd          = "cd";
$arch_copy        = "cp";
$arch_copydir     = "cp -r";
$arch_makedir     = "mkdir -p";
$arch_move        = "mv -f";
$arch_delete      = "rm -f";
$arch_deletedir   = "rm -rf";
$arch_echo        = "echo";
$arch_tar         = "tar";
$arch_compress    = "compress";
$arch_gnucompress = "/usr/local/bin/gzip";
$arch_latex       = "latex";
$arch_compilerc   = $arch_echo;
$arch_rcflags     = "No resource compiler required on this platform.";

$arch_cc          = "cc";
$arch_ccpp        = "CC";
$arch_gcc         = "gcc";
$arch_gccpp       = "g++";
$arch_accpp       = "aCC"; # for HPs
$arch_lex         = "lex";
$arch_yacc        = "yacc";
$arch_yflags      = "-d";

$arch_copts       = "";  # used to make CFLAGS   (for C)
$arch_cppopts     = "";  # used to make CPPFLAGS (for C++)
$arch_lopts       = "";  # used to make LOADLIBES   (for the linker)

$arch_opt_flag    = "-O";
$arch_debug_flag  = "-g";
$arch_depend_flag = "";   # used for "make depend" DO NOT SET IT HERE!

#
# use this if you have problems finding sqrtf and the other float math functions
#
# NOTE: The AIX make tool needs a space after the last -D"acosf...." 
#       if its missing, it breaks..
#
$arch_no_math_float = <<'EOM';
	-D"sqrtf=sqrt" -D"cosf=cos" -D"sinf=sin" -D"fabsf=fabs" -D"acosf=acos" 
EOM
    ;

# get rid of the trailing newline
chop($arch_no_math_float);

################ Plugin options
#
$plugin_dir	= "../plugins";
$molfile_dir = "$plugin_dir/$config_arch/molfile";
$plugin_include = "-I$plugin_dir/include -I$molfile_dir";
$plugin_library = "-L$plugin_dir -L$molfile_dir";
$plugin_libs    = "-lmolfile_plugin";
$plugin_defines = "-DVMDSTATICPLUGINS";
@plugin_cc      = ();
@plugin_ccpp    = ();
@plugin_h       = ('plugin.h',
                   'molfile_plugin.h',
                   'libmolfile_plugin.h');
@plugin_extra   = ();


################ OpenGL location
# location of OpenGL library and include files; if OPENGL is not being used,
# the next two options will be ignored.  If left blank, standard system
# directories will be searched.  This also specifies the names of the
# OpenGL libraries. Note that these options require -I and -L in front of
# the include and library directory names
#
# Note: The old OpenGL builds needed -DMATRIX_POST_MULTIPLY, this code was
#       seriously buggy.  The new code will build correctly without that 
#       form of matrix operation now, so we can build it identically to the
#       GL version.  The OpenGL code will compile either way, but until the
#       post multiply code is completely fixed in the core of VMD, don't.
#
$opengl_dir         = "";
$opengl_include     = "";
$opengl_library     = "";
$opengl_libs        = "-lGL -lGLU";
$opengl_defines     = "-DVMDOPENGL -DVMDGRAPHICS";
@opengl_cc          = ();
@opengl_ccpp        = ('OpenGLDisplayDevice.C',
		       'OpenGLRenderer.C',
                       'Hershey.C');
@opengl_h           = ('OpenGLDisplayDevice.h',
		       'OpenGLRenderer.h',
                       'Hershey.h');
@opengl_extra       = ();



################ Mesa location
# location of Mesa library and include files; basically does the same
# as OpenGL.  This is based on the default instructions from the Mesa
# README; the include files should by default be in /usr/local/include/GL.
$mesa_dir         = "$vmd_library_dir/Mesa";
$mesa_include     = "-I$mesa_dir/include";
$mesa_library     = "-L$mesa_dir/lib_$config_arch";
$mesa_libs        = "-lMesaGL -lMesaGLU"; 
$mesa_defines     = "-DUSELINEAXES -DVMDMESA -DVMDOPENGL -DVMDGRAPHICS";
@mesa_cc          = @opengl_cc;
@mesa_ccpp        = @opengl_ccpp;
@mesa_h           = @opengl_h;
@mesa_extra       = @opengl_extra;

#
# SDL Direct Media Interface 
#
$sdl_dir         = "$vmd_library_dir/sdl";
$sdl_include     = "-I$sdl_dir/include";
$sdl_library     = "-L$sdl_dir/lib_$config_arch";
$sdl_libs        = "-lGL -lGLU -lSDL"; 
$sdl_defines     = "-DVMDOPENGL -DVMDSDL -DVMDGRAPHICS";
@sdl_cc          = @opengl_cc;
@sdl_ccpp        = ('SDLOpenGLDisplayDevice.C',
                    'OpenGLRenderer.C',
                    'Hershey.C');
@sdl_h           = @opengl_h;
@sdl_extra       = @opengl_extra;

#
# FLTK-based OpenGL graphics windows 
#
$fltkopengl_dir         = "";
$fltkopengl_include     = "";
$fltkopengl_library     = "";
$fltkopengl_libs        = @opengl_libs; 
$fltkopengl_defines     = "-DVMDOPENGL -DVMDFLTKOPENGL -DVMDGRAPHICS";
@fltkopengl_cc          = @opengl_cc;
@fltkopengl_ccpp        = ('FltkOpenGLDisplayDevice.C',
                           'OpenGLRenderer.C',
                           'Hershey.C');
@fltkopengl_h           = @opengl_h;
@fltkopengl_extra       = @opengl_extra;


################ FLTK GUI
$fltk_defines     = "-DVMDGUI -DVMDFLTK";
$fltk_dir         = "$vmd_library_dir/fltk";
# Note: /usr/include has to be searched before $fltk_dir/include because 
# they have interposed their own math.h file, which breaks otherwise.
$fltk_include     = "-I/usr/include -I$fltk_dir/include";
$fltk_library     = "-L$fltk_dir/$config_arch";
$fltk_libs        = "-lfltk -lX11";
#@fltk_cc          = ('forms_ui.c');
@fltk_ccpp        = ( 'ColorFltkMenu.C',
                      'DisplayFltkMenu.C',
                      'FileChooserFltkMenu.C',
                      'GraphicsFltkMenu.C',
                      'SelectionBuilder.C',
                      'GeometryFltkMenu.C',
                      'MaterialFltkMenu.C',
                      'MolBrowser.C',
                      'RenderFltkMenu.C',
                      'SaveTrajectoryFltkMenu.C',
                      'VMDFltkMenu.C',
                      'MainFltkMenu.C',
                      'ToolFltkMenu.C',
                      'frame_selector.C');
@fltk_h           = ('ColorFltkMenu.h',
                     'DisplayFltkMenu.h',
                     'FileChooserFltkMenu.h',
                     'GeometryFltkMenu.h',
                     'GraphicsFltkMenu.h',
                     'GraphicsFltkReps.h',
                     'SelectionBuilder.h',
                     'MaterialFltkMenu.h',
                     'MolBrowser.h',
                     'RenderFltkMenu.h',
                     'SaveTrajectoryFltkMenu.h',
                     'VMDFltkMenu.h',
                     'MainFltkMenu.h',
                     'ToolFltkMenu.h',
                     'frame_selector.h');
@fltk_extra       = ('forms_ui.fd');

################ Tcl / Tk 
# location of TCL library and include file.
# If left blank, standard system  directories will be searched.
#$stock_tcl_include_dir=$ENV{"TCL_INCLUDE_DIR"} || "/usr/local/include";
#$stock_tcl_library_dir=$ENV{"TCL_LIBRARY_DIR"} || "/usr/local/lib";
$stock_tcl_include_dir=$ENV{"TCL_INCLUDE_DIR"} || "$vmd_library_dir/tcl/include";
$stock_tcl_library_dir=$ENV{"TCL_LIBRARY_DIR"} || "$vmd_library_dir/tcl/lib_$config_arch";


# location of Tk (for TK option)
#$stock_tk_include_dir=$ENV{"TK_INCLUDE_DIR"} || "/usr/local/include";
#$stock_tk_library_dir=$ENV{"TK_LIBRARY_DIR"} || "/usr/local/lib";
$stock_tk_include_dir=$ENV{"TK_INCLUDE_DIR"} || "$vmd_library_dir/tk/include";
$stock_tk_library_dir=$ENV{"TK_LIBRARY_DIR"} || "$vmd_library_dir/tk/lib_$config_arch";

if ($config_tk && !$config_tcl) {
  die "Error, Tk option requires Tcl\n";
}

if ($config_tcl) {
$tcl_defines      = "-DVMDTCL";
if ($config_tk) { $tcl_defines .= " -DVMDTK"; }
$tcl_include      = "-I$stock_tcl_include_dir";
if ($config_tk) { $tcl_include .= " -I$stock_tk_include_dir"; }
$tcl_library      = "-L$stock_tcl_library_dir";
if ($config_tk) { $tcl_library .= " -L$stock_tk_library_dir"; }
$tcl_libs         = "-ltcl8.4";  
if ($config_tk) { $tcl_libs = "-ltk8.4 -lX11 " . $tcl_libs; }

@tcl_cc           = ();
@tcl_ccpp         = ('ColorInfo.C',
		     'TclCommands.C',
		     'TclMeasure.C',
		     'TclMolInfo.C',
		     'TclTextInterp.C',
                     'TclVec.C',
		     'TclGraphics.C', 
		     'cmd_animate.C',
		     'cmd_color.C',
		     'cmd_display.C',
		     'cmd_imd.C',
		     'cmd_label.C',
		     'cmd_material.C',
		     'cmd_menu.C',
		     'cmd_mol.C',
		     'cmd_mouse.C',
		     'cmd_plugin.C',
		     'cmd_render.C',
		     'cmd_tool.C',
		     'cmd_trans.C',
		     'cmd_user.C',
		     'cmd_util.C',
		     'tcl_commands.C');
@tcl_h            = ('TclCommands.h',
		     'TclTextInterp.h',
		     'tcl_commands.h');
@tcl_extra        = ();
}

if ($config_tcl) {
@tk_cc		= ();
@tk_ccpp	= ('VMDTkMenu.C');
@tk_h		= ('VMDTkMenu.h');
}

################ IMD
# OPTIONAL COMPONENT: Interactive Molecular Dynamics support
# This may be commented out if not required.
# This allows VMD to connect directly to a running MD simulation
# and exchange forces, coordinates, and other messages.
$imd_defines        = "-DVMDIMD";
@imd_cc             = ();
if ($config_pthreads) {
@imd_ccpp           = ('IMDMgr.C',
                       'IMDSim.C',
		       'IMDSimThread.C',
		       'CmdIMD.C',
                       'imd.C' 
                      );
@imd_h              = ('imd.h',
                       'IMDMgr.h',
                       'IMDSim.h',
		       'IMDSimThread.h',
	               'CmdIMD.h'
                      ); 
} else {
@imd_ccpp           = ('IMDMgr.C',
                       'IMDSim.C',
		       'IMDSimBlocking.C',
		       'CmdIMD.C',
                       'imd.C' 
                      );
@imd_h              = ('imd.h',
                       'IMDMgr.h',
                       'IMDSim.h',
		       'IMDSimBlocking.h',
	               'CmdIMD.h'
                      ); 
}

################ SPACEBALL
# OPTIONAL COMPONENT: Spaceball 6DOF input support
# This may be commented out if not required.
$spaceball_defines        = "-DVMDSPACEBALL";
$spaceball_dir         = "$vmd_library_dir/libsball";
$spaceball_include     = "-I$spaceball_dir/include";
$spaceball_library     = "-L$spaceball_dir/lib_$config_arch";
$spaceball_libs        = "-lsball";
@spaceball_cc             = ();
@spaceball_ccpp           = ('Spaceball.C',
                             'SpaceballTracker.C'
                      );
@spaceball_h              = ('Spaceball.h',
                             'SpaceballTracker.h'
                      );

################ LIBTACHYON
# OPTIONAL COMPONENT: Built-in Tachyon ray tracing support 
# This may be commented out if not required.
$libtachyon_defines        = "-DVMDLIBTACHYON";
$libtachyon_dir         = "$vmd_library_dir/tachyon";
$libtachyon_include     = "-I$libtachyon_dir/include";
$libtachyon_library     = "-L$libtachyon_dir/lib_$config_arch";
$libtachyon_libs        = "-ltachyon";
@libtachyon_cc             = ();
@libtachyon_ccpp           = ('LibTachyonDisplayDevice.C'
                      );
@libtachyon_h              = ('LibTachyonDisplayDevice.h',
                      );

#######################
# OPTIONAL COMPONENT: VRPN 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.
#######################

$vrpn_defines        = "-DVMDVRPN";
$vrpn_dir            = "$vmd_library_dir/vrpn";
$vrpn_include        = "-I$vrpn_dir/vrpn -I$vrpn_dir/quat";
$vrpn_library        = "-L$vrpn_dir/lib_$config_arch";
$vrpn_libs           = "-lvrpn -lquat";
@vrpn_cc             = ();
@vrpn_ccpp           = ('P_VRPNTracker.C',
                        'P_VRPNButtons.C',
                        'P_VRPNFeedback.C',
                        'P_RotateTool.C');
@vrpn_h              = ('P_VRPNTracker.h',
                        'P_VRPNButtons.h',
                        'P_VRPNFeedback.h',
                        'P_RotateTool.h'); 
@vrpn_extra          = ();

#######################
# 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.
#######################
if ( $config_cave && !$config_opengl) {
  die "CAVE option requires OPENGL!";
}
$cave_defines       = "-DVMDCAVE";
$cave_dir           = "$vmd_library_dir/cave";
$cave_include       = "-I$cave_dir/include";
$cave_library       = "-L$cave_dir/lib_$config_arch";

# choose which library to link against
# someday we might need to add -lsnd back in, but not presently
if ( $config_opengl ) {
  if ($config_arch eq "IRIX6_64") {
    $cave_libs          = "-lcave_ogl_64 -lXi -lGL";
  } elsif ($config_arch eq "IRIX6") {
    $cave_libs          = "-lcave_ogl_n32 -lXi -lGL";
  } else {
    $cave_libs          = "-lcave_ogl -lXi";
  }
} else {
  $cave_libs          = "-lcave";
}
@cave_cc            = ();
@cave_ccpp          = ('CaveDisplayDevice.C',
		       'CaveScene.C',
		       'CaveRoutines.C',
		       'P_CaveTracker.C',
		       'P_CaveButtons.C'
		       );
@cave_h             = ('CaveDisplayDevice.h',
		       'CaveRoutines.h',
		       'CaveScene.h',
		       'P_CaveTracker.h',
		       'P_CaveButtons.h'
		       );
@cave_extra        = ();


#######################
# OPTIONAL COMPONENT: FreeVR support
#	This may be commented out if not required.
#	This will require access to the FreeVR library and headers, and will
#	result in unique FreeVR objects being used in the program.
#######################
if ( $config_freevr && !$config_opengl) {
  die "FREEVR option requires OPENGL!";
}
$freevr_defines     = "-DVMDFREEVR";
$freevr_dir         = "$vmd_library_dir/freevr";
$freevr_include     = "-I$freevr_dir/include";
$freevr_library     = "-L$freevr_dir/lib_$config_arch";

# choose which library to link against
$freevr_libs        = "-lfreevr -lXi";
@freevr_cc          = ();
@freevr_ccpp        = ('FreeVRDisplayDevice.C',
		       'FreeVRScene.C',
		       'FreeVRRoutines.C',
		       'P_FreeVRTracker.C',
		       'P_FreeVRButtons.C'
		       );
@freevr_h           = ('FreeVRDisplayDevice.h',
		       'FreeVRRoutines.h',
		       'FreeVRScene.h',
		       'P_FreeVRTracker.h',
		       'P_FreeVRButtons.h'
		       );
@freevr_extra      = ();


#######################
# OPTIONAL COMPONENT: ACTC Triangle Stripification Library
#   This option enables the use of ACTC for acceleration of surface
#   primitives.
#######################
$actc_defines     = "-DVMDACTC";
$actc_dir         = "$vmd_library_dir/actc";
$actc_include     = "-I$actc_dir/include";
$actc_library     = "-L$actc_dir/lib_$config_arch";
$actc_libs        = "-lactc";
@actc_cc          = ();
@actc_ccpp        = ();
@actc_h           = ();
@actc_extra       = ();


#######################
# OPTIONAL COMPONENT: Contributed VMD code
#   This option enables contributed code from the VMD user community.
#   Not all contributed code can be included in all VMD distributions due
#   to restrictions placed on the code by its author(s).  This config option
#   enables/disables these contributed codes in a semi-nice way.
#######################
$contrib_defines     = "-DVMDCONTRIB";
$contrib_dir         = "";    # "$vmd_library_dir/contrib";
$contrib_include     = "";    # "-I$contrib_dir/include";
$contrib_library     = "";    # "-L$contrib/lib_$config_arch";
$contrib_libs	     = "";
@contrib_cc	     = ();
@contrib_ccpp        = ('ReadMDLMol.C');         # MDL reader, A. Dalke
@contrib_h           = ('ReadMDLMol.h');         # MDL reader, A. Dalke
@contrib_extra	     = ();

################### system supplied sources and libraries
# these are the last libraries listed on the link line, and should
# satisfy any needs of the other libraries.
$system_defines       = "";
$system_dir           = "";
$system_include       = "-I.";
$system_library       = "-L.";
if ( $config_gcc ) {
  $system_libs        = "-ll -lm";
} else {
  $system_libs        = "-lm";
}
@system_cc             = ();
@system_ccpp           = ();
@system_h              = ();
@system_extra          = ();


###################
# OPTIONAL COMPONENT: POSIX Threads support
###################
$pthreads_defines  = "-DVMDTHREADS -DUSEPOSIXTHREADS -D_REENTRANT";
$pthreads_dir      = "";
$pthreads_include  = "";
$pthreads_library  = "";
$pthreads_libs     = "-lpthread";
@pthreads_h        = ('VMDThreads.h');
@pthreads_ccpp     = ('VMDThreads.C');


###################
# OPTIONAL COMPONENT: Python support
###################
$python_defines     = "-DVMDPYTHON";
$python_dir         = "$vmd_library_dir/python";
$python_include     = "-I$python_dir/lib_$config_arch/include/python2.2";
$python_library     = "-L$python_dir/lib_$config_arch/lib/python2.2/config";
$python_libs        = "-lpython2.2 -lpthread";
@python_h           = ('PythonTextInterp.h',
		       'py_commands.h',
		       'py_molecule.h');
@python_ccpp        = ('PythonTextInterp.C',
		       'py_animate.C',
		       'py_atomselection.C',
		       'py_axes.C',
		       'py_color.C',
		       'py_commands.C',
		       'py_display.C',
		       'py_graphics.C',
		       'py_imd.C',
		       'py_label.C',
		       'py_material.C',
		       'py_molecule.C',
		       'py_molrep.C',
		       'py_render.C',
		       'py_trans.C');

###################
# OPTIONAL COMPONENT: Swig interface
###################
$swig_defines      = "-DVMDSWIG";
$swig_include      = "";
$swig_library      = ""; 
$swig_libs         = ""; 
@swig_h            = ();
@swig_ccpp         = ();
# Interfaces for each language are enabled separately.
if ( $config_python ) {
  push(@swig_ccpp, 'vmd_python.C');
}

###################
# OPTIONAL COMPONENT: Numeric Python extension
# #################

# Numeric requires Python
if ( $config_numeric && !$config_python) {
  die "NUMPY option requires PYTHON!";
}
$numeric_defines   = "-DVMDNUMPY";
$numeric_include   = "";
$numeric_library   = "";
$numeric_libs      = "";
@numeric_h         = "";
@numeric_ccpp      = ('py_numeric.C');

################### standard sources
$vmd_defines       = "-DVMDSURF -DVMDMSMS -DVMDISOSURFACE $tcl_defines";
$vmd_include       = "$tcl_include";
$vmd_library       = "$tcl_library";
$vmd_libs          = "$tcl_libs";

@vmd_cc         = ('hash.c',
                   'vmdsock.c',
		               'vmddlopen.c',
		               'pcre.c',
		               @tcl_cc,
		               @tk_cc);

@vmd_ccpp	= (
		   'Animation.C', 
		   'ArtDisplayDevice.C', 
		   'AtomColor.C', 
		   'AtomRep.C', 
		   'AtomSel.C', 
		   'Axes.C', 
		   'BaseMolecule.C', 
		   'BondSearch.C', 
		   'CmdAnimate.C', 
		   'CmdColor.C', 
		   'CmdDisplay.C', 
		   'CmdLabel.C', 
                   'CmdMaterial.C',
		   'CmdMenu.C', 
		   'CmdMol.C', 
		   'CmdRender.C', 
		   'CmdTrans.C', 
		   'CommandQueue.C', 
		   'CoorPluginData.C',
		   'DisplayDevice.C', 
		   'Displayable.C', 
		   'DispCmds.C', 
		   'DrawMolecule.C', 
		   'DrawMolItem.C', 
		   'DrawMolItem2.C', 
		   'DrawMolItemRibbons.C', 
		   'DrawMolItemMSMS.C', 
		   'DrawMolItemSurface.C', 
		   'DrawMolItemVolume.C', 
		   'DrawForce.C', 
		   'FileRenderList.C', 
		   'FileRenderer.C', 
		   'FPS.C',
		   'GeometryAngle.C', 
		   'GeometryAtom.C', 
		   'GeometryBond.C', 
		   'GeometryDihedral.C', 
		   'GeometryList.C', 
		   'GeometryMol.C', 
		   'GeometrySpring.C', 
		   'Inform.C', 
		   'Isosurface.C', 
		   'JRegex.C', 
		   'JString.C', 
                   'MaterialList.C',
		   'Matrix4.C', 
		   'Measure.C',
		   'Molecule.C', 
		   'MoleculeList.C', 
		   'MoleculeGraphics.C', 
		   'MolFilePlugin.C',
		   'MolInfo.C',
		   'Mouse.C', 
		   'MSMSInterface.C', 
		   'P_JoystickTool.C',
		   'P_TugTool.C',
		   'P_GrabTool.C',
		   'P_PrintTool.C',
		   'P_PinchTool.C',
		   'P_UIVR.C',
		   'P_Buttons.C',
		   'P_Tracker.C',
		   'P_Tool.C',
		   'P_CmdTool.C',
		   'P_SensorConfig.C',
		   'ParseTree.C', 
		   'PickList.C', 
		   'PickModeAddBond.C',
		   'PickModeCenter.C', 
		   'PickModeForce.C',
		   'PickModeList.C',
		   'PickModeMolLabel.C', 
		   'PickModeMove.C', 
		   'PlainTextInterp.C',
		   'PluginMgr.C',
		   'POV3DisplayDevice.C', 
		   'PSDisplayDevice.C', 
	  	   'VMDQuat.C',
		   'RadianceDisplayDevice.C', 
		   'RayShadeDisplayDevice.C', 
		   'R3dDisplayDevice.C', 
		   'RenderManDisplayDevice.C',
		   'Scene.C', 
		   'SnapshotDisplayDevice.C', 
		   'SpringTool.C',
		   'Stage.C', 
		   'STLDisplayDevice.C', 
		   'Stride.C', 
		   'Surf.C', 
		   'SymbolTable.C', 
		   'TachyonDisplayDevice.C', 
		   'Timestep.C', 
		   'UIObject.C', 
		   'UIText.C', 
                   'VMDApp.C',
		   'VMDDir.C', 
		   'VMDDisplayList.C',
		   'VMDMenu.C',
		   'VMDTitle.C', 
		   'VrmlDisplayDevice.C', 
		   'Vrml2DisplayDevice.C', 
		   'utilities.C', 
		   'vmd.C',
		   @tcl_ccpp,
		   @tk_ccpp
		   );

################### standard headers

# VMD header files 
@vmd_h	   = (
	      'Animation.h', 
	      'ArtDisplayDevice.h', 
	      'Atom.h', 
	      'AtomColor.h', 
	      'AtomParser.h', 
	      'AtomRep.h', 
	      'AtomSel.h', 
	      'Axes.h', 
	      'BaseMolecule.h', 
	      'BondSearch.h', 
	      'CmdAnimate.h', 
	      'CmdColor.h', 
	      'CmdDisplay.h', 
	      'CmdLabel.h', 
              'CmdMaterial.h',
	      'CmdMenu.h', 
	      'CmdMol.h', 
	      'CmdRender.h', 
	      'CmdTrans.h', 
	      'Command.h', 
	      'CommandQueue.h', 
	      'CoorData.h',
	      'CoorPluginData.h',
              'DepthSortObj.h',
	      'DispCmds.h', 
	      'DisplayDevice.h', 
	      'Displayable.h', 
	      'DrawMolecule.h', 
	      'DrawMolItem.h', 
	      'DrawMolItemSolventPoints.data', 
	      'DrawForce.h', 
	      'FPS.h',
	      'FileRenderList.h', 
	      'FileRenderer.h', 
	      'Fragment.h', 
	      'GeometryAngle.h', 
	      'GeometryAtom.h', 
	      'GeometryBond.h', 
	      'GeometryDihedral.h', 
	      'GeometryList.h', 
	      'GeometryMol.h', 
	      'GeometrySpring.h', 
	      'Inform.h', 
	      'Isosurface.h', 
	      'JRegex.h', 
	      'JString.h', 
              'MaterialList.h',
	      'Matrix4.h', 
	      'Measure.h',
	      'Molecule.h', 
	      'MoleculeGraphics.h', 
	      'MoleculeList.h', 
	      'MolFilePlugin.h',
	      'MolInfo.h',
	      'Mouse.h', 
	      'MSMSInterface.h', 
	      'NameList.h',
	      'P_JoystickTool.h',
	      'P_TugTool.h',
	      'P_PinchToo.h',
	      'P_GrabTool.h',
	      'P_PrintTool.h',
	      'P_Feedback.h',
	      'P_UIVR.h',
	      'P_Buttons.h',
	      'P_Tracker.h',
	      'P_CmdTool.h',
	      'P_SensorConfig.h',
	      'P_Tool.h',
	      'ParseTree.h', 
	      'PickList.h', 
	      'PickMode.h', 
	      'PickModeAddBond.h',
	      'PickModeCenter.h', 
	      'PickModeForce.h',
	      'PickModeList.h',
	      'PickModeMolLabel.h', 
	      'PickModeMove.h', 
	      'Pickable.h', 
	      'PlainTextInterp.h',
	      'PluginMgr.h',
	      'PointerTool.h', 
	      'POV3DisplayDevice.h', 
	      'PSDisplayDevice.h', 
	      'VMDQuat.h',
	      'RadianceDisplayDevice.h', 
	      'RayShadeDisplayDevice.h', 
	      'R3dDisplayDevice.h', 
	      'ResizeArray.h',
	      'RenderManDisplayDevice.h',
	      'Residue.h', 
	      'Scene.h', 
	      'SnapshotDisplayDevice.h', 
	      'SortableArray.h',
	      'SpringTool.h',
	      'Stack.h',
	      'Stage.h', 
	      'STLDisplayDevice.h', 
	      'Stride.h', 
	      'Surf.h', 
	      'SymbolTable.h', 
	      'TachyonDisplayDevice.h', 
	      'TextEvent.h',
	      'TextInterp.h',
	      'Timestep.h', 
	      'UIObject.h', 
	      'UIText.h', 
              'VMDApp.h',
	      'VMDDir.h', 
	      'VMDDisplayList.h',
	      'VMDMenu.h',
	      'VMDTitle.h', 
	      'VrmlDisplayDevice.h', 
	      'Vrml2DisplayDevice.h', 
	      'utilities.h',
	      'pcre.h',
	      'pcreinternal.h',
	      'pcretables.h',
              'vmdsock.h',
	      @tcl_h,
	      @tk_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');


# VMD data files, default templates that users can copy
# to their home directory for things like .vmdrc and
# .vmdsensors.  These also provide the default behavior
# in the case that a user has no such files in their home
# directory.
@vmd_data    = ('.vmdsensors',
		'.vmdrc');
	       
$vmd_bin     = "vmd";

@vmd_extra   = (@tcl_extra);

@vmd_other_exe  = (
		   "$vmd_library_dir/stride/stride_$config_arch",
		   "$vmd_library_dir/surf/surf_$config_arch",
		   "$vmd_library_dir/tachyon/tachyon_$config_arch"
		   );
		   
@vmd_other_names = ("stride_$config_arch");

@vmd_main_dir_files = ('Announcement', 'FEEDBACK', 'LICENSE', 
			'README', 'configure');


################## ARCHITECTURE-SPECIFIC VERSIONS   ###############
if ($config_arch eq "AIX4") {
  if ($config_lp64) {
    print "No LP64 support for this platform currently.\n";
  }

  # AIX does NOT work if you list /usr/include at all, so we have
  # to un-hack this FLTK thing...
  $fltk_include     = "-I$fltk_dir/include";

  if ($config_gcc) {
    $arch_cc       = "gcc";
    $arch_ccpp     = "g++";
    $arch_cppopts  = $arch_no_math_float;
    $arch_lex      = "flex";
    # $arch_yacc     = "bison -b y";  # If standard yacc doesn't work
  } else {
    $arch_cc          = "xlc";
    $arch_ccpp        = "xlC";
#    $arch_opt_flag    = "-O -qmaxmem=16384";
    $arch_opt_flag    = "";
    $arch_cppopts     = "-D_H_ACCESS=1" . $arch_no_math_float; 
    $arch_lex         = "flex";  # has problems with the vendor lex... 
  }

  $opengl_libs      = "-lGL -lGLU -lX11 -lXext";
  $mesa_libs        = "-lMesaGL -lMesaGLU -lXext";
  $arch_lopts       = "-ldl";
}



if ($config_arch eq "FREEBSD") {
    $def_imageviewer="display %s";

    # XFree 4.0 Direct Rendering Interface and GLX 
    $opengl_dir         = "/usr/X11R6";
    $opengl_include     = "-I$opengl_dir/include";
    $opengl_library     = "-L$opengl_dir/lib";
    $opengl_libs        = "-lGL -lGLU"; 

    $arch_lex      = "flex";
    $arch_yacc     = "bison -b y -d ";  # If standard yacc doesn't work

    $arch_cc          = "gcc";
    $arch_ccpp        = "g++";
    $arch_depend_flag = "-MM";
    $arch_shld        = "ld -shared";
    $arch_shlibname   = "so";
    $arch_shcppopts   = "-fPIC";
    $arch_shldopts    = "-L/usr/local/lib -L/usr/X11R6/lib";

    $arch_opt_flag    = "-fno-for-scope -Wall -Wno-deprecated -O3 -march=i586 -fomit-frame-pointer";
    $arch_copts       = "-Wall -Wno-deprecated -O3 -march=i586 -fomit-frame-pointer";

    if ($config_static) {
      $arch_lopts       = "-static";
      $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/X11R6/lib -lXext -lX11";
    } else {
      $arch_lopts       = "";
      $mesa_libs        = "-lGL -lGLU -L/usr/X11R6/lib -lXext -lX11";
    }

    if ($config_shared) {
      $arch_lopts       = "-shared";
    }

    # a hack - to be removed, just keeps make happy
    $arch_template_repository = "foobar";

    # this is to make tcl happy
    $system_libs .= " -ldl";
 
    # this is to make python happy
    $system_libs .= " -lutil";

    # this is necessary for the embedded Python interpreter to dynamically
    # load shared libraries.  It increases the size of the binary by 200k.
    $arch_lopts .= " -Xlinker -export-dynamic";
}




if ($config_arch eq "HPUX11") {
    # HPUX11 aCC does NOT work if you list /usr/include at all, so we have
    # to un-hack this FLTK thing...
    $fltk_include     = "-I$fltk_dir/include";

    if ($config_lp64) {
      print "No LP64 support for this platform currently.\n";
    }

    $opengl_dir         = "/opt/graphics/OpenGL";
    $opengl_include     = "-I$opengl_dir/include";
    $opengl_library     = "-L$opengl_dir/lib";
    $opengl_libs        = "-lGL -lGLU -lX11 -lXext";
    $mesa_libs        = "-lMesaGL -lMesaGLU -lXext";

    $arch_opt_flag = "+O2";
    $arch_copts    = "+O2 +DAportable -Ae";
    $arch_cppopts  = "+DAportable +a1";

    # in tcl8.0 we can load shared libraries at run time, so we need -Wl,-E
    $arch_lopts    = "-Wl,-E -lmalloc";
    $arch_template_repository = "ptrepository";

    # for compiling with HP aCC compiler:
    if ($config_acc) {
      $arch_ccpp      = "aCC";
      $arch_cppopts  = "";
    }

    # for compiling with g++:
    if ($config_gcc) {
      $arch_cc       = "gcc";
      $arch_ccpp     = "g++";
      $arch_copts    = "";
      $arch_cppopts  = "";
      $arch_lopts = "-L/lib/pa1.1 -lmalloc -ldld";
    }
}



if ($config_arch eq "IRIX6" || $config_arch eq "IRIX6_64") {
  $def_imageviewer = "ipaste %s";
  $arch_debug_flag  = "-g";
  $arch_depend_flag = " -M -c";
  $arch_template_repository = "ii_files";
  $arch_shld      = "ld -shared";
  $arch_shlibname = "so";
  $arch_shcppopts = "-KPIC";

  if ($config_lp64) {
    # -64 64-bit mode 
    print "Configured for -64 64-bit build.\n";
    $arch_opt_flag    = "-64 -mips4 -O3 -woff 1110,1167,3255,3262 -G 0 -OPT:Olimit=8192";
    $arch_copts       = "-64 -mips4 -O3 -G 0";
    $arch_cppopts     = "-I/usr/include/CC";
    $arch_shldopts    = "-64 -mips4";

    # SGI linker doesn't figure things out for itself
    # requires us to list -lGL multiple times... argh!
    if ($config_opengl) {
      $arch_lopts    = "-lGL -64 -mips4 -O3 -L/usr/lib64";
    } else {
      $arch_lopts    = "-64 -mips4 -O3 -L/usr/lib64";
    }
  } else {
    # -n32 32-bit mode 
    print "Configured for -n32 32-bit build.\n";
    $arch_opt_flag = "-n32 -mips3 -O3 -woff 1110,1167,3255,3262 -OPT:Olimit=8192";
    $arch_copts    = "-n32 -mips3 -O3 ";
    $arch_cppopts  = "-I/usr/include/CC";
    $arch_shldopts  = "-n32 -mips3";

    # SGI linker doesn't figure things out for itself
    # requires us to list -lGL multiple times... argh!
    if ($config_opengl) {
      $arch_lopts    = "-lGL -n32 -mips3 -O3 ";
    } else {
      $arch_lopts    = "-n32 -mips3 -O3 ";
    }
  }
}



if ($config_arch eq "LINUX") {
    $def_imageviewer="display %s";
    if ($config_lp64) {
      print "No LP64 ABI on this platform currently.\n";
    }

    # XFree 4.0 Direct Rendering Interface and GLX 
    $opengl_dir         = "/usr/X11R6";
    $opengl_include     = "-I$opengl_dir/include";
    $opengl_library     = "-L$opengl_dir/lib";
    $opengl_libs        = "-lGL -lGLU"; 
    # $opengl_libs      = "-L/usr/X11R6/lib -lGL -lGLU -lXext -lX11";

    $arch_cc          = "gcc";
    $arch_ccpp        = "g++";
    # test hack to statically link libstd++
    # $arch_ccpp        = "gcc";
    $arch_depend_flag = "-MM";
    $arch_shld        = "ld -shared";
    $arch_shlibname   = "so";
    $arch_shcppopts   = "-fPIC";
    $arch_shldopts    = "";

    $arch_opt_flag    = "-fno-for-scope -Wall -Wno-deprecated -O3 -march=i586 -fomit-frame-pointer";
    $arch_copts       = "-Wall -Wno-deprecated -O3 -march=i586 -fomit-frame-pointer";

    if ($config_static) {
      $arch_lopts       = "-static";
      $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/X11R6/lib -lXext -lX11";
    } else {
      $arch_lopts       = "";
      # test hack to statically link libstd++
      # $arch_lopts     = "-lstdc++";
# -rpath causes problems for people running Chromium..
#      $arch_lopts       = "-Wl,-rpath,/usr/X11R6/lib -Wl,-rpath,/usr/local/lib";
      $mesa_libs        = "-lGL -lGLU -L/usr/X11R6/lib -lXext -lX11";
    }
    if ($config_shared) {
      $arch_lopts       = "-shared";
    }

    # UIText #include's <sys/select.h> but it doesn't exist for Linux
    $arch_cppopts     = "";

    # a hack - to be removed, just keeps make happy
    $arch_template_repository = "foobar";

    # this is to make tcl happy
    $system_libs .= " -ldl";
 
    # this is to make python happy
    $system_libs .= " -lutil";

    # this is necessary for the embedded Python interpreter to dynamically
    # load shared libraries.  It increases the size of the binary by 200k.
    $arch_lopts .= " -Xlinker -export-dynamic";
}



if ($config_arch eq "LINUXALPHA") {
    $def_imageviewer="display %s";
    if ($config_lp64) {
      print "LP64 ABI is already the default on this platform.\n";
    }

    # for compiling with g++:
    if ($config_gcc) {
      $arch_cc		= "gcc";
      $arch_ccpp  	= "g++";
      $arch_opt_flag	= "-Wall -O9 -fomit-frame-pointer -finline-functions -fexpensive-optimizations -fcaller-saves -fthread-jumps -fstrength-reduce -ffast-math";
      $arch_depend_flags= "-MM";
      $arch_copts	= "-Wall -O9 -fomit-frame-pointer -finline-functions -fexpensive-optimizations -fcaller-saves -fthread-jumps -fstrength-reduce -ffast-math";
      $arch_template_repository = "foobar";

      # so far only STATIC version tested
      if ($config_static) {
        $arch_lopts	= "-static"; 
      } else {
        $arch_lopts	= "-Wl,-rpath,/usr/X11R6/lib -Wl,-rpath,/usr/local/lib";
      }
    } else {
      # for compiling with Compaq ccc and cxx compilers:
      $arch_cc		= "ccc";
      $arch_ccpp        = "cxx";
      $arch_opt_flag    = "-w0 -O4 -fp_reorder -nocleanup -tune host";
      $arch_copts       = "-fast -O4 -tune host";
      $arch_depend_flag = "-M";
      $arch_cppopts	= "-msg_quiet ";
      $arch_template_repository = "cxx_repository";

      if ($config_static) {
        $arch_lopts	= "-non_shared"; 
      }
    }

    $arch_lex		= "flex"; # has problems with vendor lex
    $opengl_libs	= "-L/usr/shlib -lGL -lGLU -lXext -lX11";
    $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/X11R6/lib -lXext -lX11";

    # this is to make tcl happy
    $system_libs .= " -ldl";
}



if ($config_arch eq "LINUXPPC") {
    $def_imageviewer="display %s";
    if ($config_lp64) {
      print "No LP64 ABI on this platform currently.\n";
    }

    $arch_cc          = "gcc";
    $arch_ccpp        = "g++";
    $arch_depend_flag = "-MM";
    $arch_opt_flag    = "-Wall -O9 -fomit-frame-pointer -finline-functions -fexpensive-optimizations -fcaller-saves -fthread-jumps -fstrength-reduce -ffast-math";
    $arch_copts       = "-Wall -O9 -fomit-frame-pointer -finline-functions -fexpensive-optimizations -fcaller-saves -fthread-jumps -fstrength-reduce -ffast-math";

    if ($config_static) {
      $arch_lopts       = "-static"
    } else {
      $arch_lopts       = "-Wl,-rpath,/usr/X11R6/lib -Wl,-rpath,/usr/local/lib";
    }

    $opengl_libs      = "-L/usr/X11R6/lib -lGL -lGLU -lXext -lX11";
    $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/X11R6/lib -lXext -lX11";
    $arch_cppopts     = "";

    # a hack - to be removed, just keeps make happy
    $arch_template_repository = "foobar";

    # this is to make tcl happy
    $system_libs .= " -ldl";
}



if ($config_arch eq "MACOSX") {
    $def_imageviewer="/usr/bin/open %s";

    if ($config_lp64) {
      print "No LP64 ABI on this platform currently.\n";
    }

    $arch_cc          = "cc";
    $arch_ccpp        = "c++";
    $arch_depend_flag = "-MM";
    $arch_opt_flag    = "-Os -ffast-math";
    $arch_copts       = "-Os -ffast-math";

    $macosx102_no_math_float = <<'EOM';
	-D"sqrtf=sqrt" -D"cosf=cos" -D"sinf=sin" -D"acosf=acos" 
EOM
    ;
    # get rid of the trailing newline
    chop($macosx102_no_math_float);
    $arch_cppopts     = $macosx102_no_math_float;

    if ($config_static) {
      $arch_lopts       = "-static"
    } else {
      $arch_lopts       = "";
    }

    # Mesa version uses X11 just like other Unix versions,
    # but the OpenGL version uses native MacOS X, no X11.
    if ($config_mesa) {
      $fltk_libs        = "-lfltk-x11 -lX11";
      $opengl_include   = $opengl_include . " -I/usr/X11R6/include";
      $opengl_libs      = "-L/usr/X11R6/lib -framework OpenGL -framework AGL -framework Carbon -lXext -lX11";
    } else {
      ##
      ## MacOS X native builds using Tcl/Tck frameworks
      ## 
      $tcl_include      = "-I$stock_tcl_include_dir";
      if ($config_tk) { $tcl_include .= " -I$stock_tk_library_dir/Tk.framework/Versions/8.4/Headers"; }
      $tcl_library      = "-F$stock_tcl_library_dir";
      if ($config_tk) { $tcl_library .= " -F$stock_tk_library_dir"; }
      $tcl_libs         = "-framework Tcl";
      if ($config_tk) { $tcl_libs = "-framework Tk " . $tcl_libs; }

      $vmd_include       = "$tcl_include";
      $vmd_library       = "$tcl_library";
      $vmd_libs          = "$tcl_libs";

      $fltk_include     = "-I$fltk_dir/fltk-cvs";
      $fltk_libs        = "-lfltk_gl -lfltk";
      $opengl_include   = $opengl_include;
      $opengl_libs      = "-framework OpenGL -framework AGL -framework Carbon";
      $arch_compilerc   = "/Developer/Tools/Rez";
      $arch_rcflags     = "-t APPL -o ../MACOSX/vmd_MACOSX vmdmac.r";
    }

    $sdl_libs         = "-lSDL -framework OpenGL -framework AGL";
    $fltkopengl_libs  = "-framework OpenGL -framework AGL";
    $mesa_include     = $mesa_include . " -I/usr/X11R6/include";
    $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/X11R6/lib -lXext -lX11";

    # a hack - to be removed, just keeps make happy
    $arch_template_repository = "foobar";

    # no libm.a on MacOS-X
    $system_include   = $system_include . " -F/System/Library/Frameworks";
    $system_libs      = " -framework Carbon ";
}



if ($config_arch eq "TRU64") {
    if ($config_lp64) {
      print "LP64 ABI is already the default on this platform.\n";
    }

    # for compiling with g++:
    if ($config_gcc) {
      # GCC does NOT work if you list /usr/include at all, so we have
      # to un-hack this FLTK thing...
      $fltk_include     = "-I$fltk_dir/include";
      $arch_cc		= "gcc";
      $arch_ccpp  	= "g++";
      $arch_opt_flag	= "-O3";
      $arch_depend_flags= "-MM";
      $arch_copts	= "";
      $arch_cppopts	= "";
      $arch_template_repository = "foobar";

      # so far only STATIC version tested
      if ($config_static) {
        $arch_lopts	= "-static"; 
      } else {
        $arch_lopts	= "-Wl,-rpath,/usr/X11R6/lib -Wl,-rpath,/usr/local/lib";
      }
    } else {
      # for compiling with Compaq/DEC cc and cxx compilers:
      $arch_cc		= "cc";
      $arch_ccpp        = "cxx";
      $arch_opt_flag    = "-w0 -O4 -fp_reorder -nocleanup -tune host";
      $arch_copts       = "-fast -O4 -tune host";
      $arch_depend_flag = "-M";
      $arch_cppopts	= "-msg_quiet ";
      $arch_template_repository = "cxx_repository";

      if ($config_static) {
        $arch_lopts	= "-non_shared"; 
      }
    }

    $arch_lex		= "flex"; # has problems with vendor lex
    $opengl_libs	= "-L/usr/shlib -lGL -lGLU -lXext -lX11";
    $mesa_libs		= "-lMesaGL -lMesaGLU -L/usr/shlib -lXext -lX11";

    # this is to make tcl happy
    $system_libs .= " -ldnet_stub";
}



if ($config_arch eq "SOLARIS2" || $config_arch eq "SOLARIS2_64") {
    $freevr_libs .= " -lrt";

    if ($config_gcc) {
      if ($config_lp64) {
        print "GCC doesn't support LP64 ABI on this platform currently.\n";
      }
      $arch_ccpp        = "g++";
      $arch_cc	        = "gcc";
      $arch_opt_flag    = "-O";
      $arch_copts       = "-O";
      $arch_debug_flag  = "-g";
      $arch_depend_flag = "-M";
    } elsif ($config_kcc) {
      if ($config_lp64) {
        print "KCC doesn't support LP64 ABI on this platform currently.\n";
      }
      $arch_ccpp        = "KCC -D__EXTENSIONS__";
      $arch_cc          = "cc -D__EXTENSIONS__";
      $arch_opt_flag    = "-fast --backend -xO4 --backend -native";
      $arch_copts       = "-fast -xO4 -native";
      $arch_debug_flag  = "-g";
      $arch_depend_flag = "-xM";
      $arch_template_repository = "SunWS_cache";
    } else {
      # Using Sun's compilers.
      if ($config_lp64) {
        print "Configured for a 64-bit build.\n";
        $arch_ccpp        = "CC -D__EXTENSIONS__";
        $arch_cc          = "cc -D__EXTENSIONS__";
        if ($config_pthreads) {
          $arch_opt_flag    = "-mt -fast -xO3 -native -xarch=v9a";
          $arch_copts       = "-mt -fast -xO3 -native -xarch=v9a";
        } else { 
          $arch_opt_flag    = "-fast -xO3 -native -xarch=v9a";
          $arch_copts       = "-fast -xO3 -native -xarch=v9a";
        }
        $arch_debug_flag  = "-g";
        $arch_depend_flag = "-xM";
        $arch_template_repository = "SunWS_cache";
      } else {
        print "Configured for a 32-bit build.\n";
        $arch_ccpp        = "CC -D__EXTENSIONS__";
        $arch_cc          = "cc -D__EXTENSIONS__";
        if ($config_pthreads) {
          $arch_opt_flag    = "-mt -fast -xO3 -native -xarch=v8plusa";
          $arch_copts       = "-mt -fast -xO3 -native -xarch=v8plusa";
        } else { 
          $arch_opt_flag    = "-fast -xO3 -native -xarch=v8plusa";
          $arch_copts       = "-fast -xO3 -native -xarch=v8plusa";
        }
        $arch_debug_flag  = "-g";
        $arch_depend_flag = "-xM";
        $arch_template_repository = "SunWS_cache";
      }
    }

    $arch_cppopts     = $arch_no_math_float;


    if ($config_static) {
      $arch_lopts       = "-Bstatic -lsocket -lnsl";
    } else {
      $arch_lopts       = "-lsocket -lnsl -ldl";
    }

    $opengl_dir         = "/usr/openwin";
    $opengl_include     = "-I$opengl_dir/include";
    if ($config_lp64) {
      $opengl_library     = "-L$opengl_dir/lib/sparcv9";
    } else {
      $opengl_library     = "-L$opengl_dir/lib";
    }
    $opengl_libs        = "-lGL -lGLU -lX11 -lXext";

    $mesa_include     = $mesa_include . " -I/usr/openwin/include";
    if ($config_lp64) {
      $mesa_library     = $mesa_library . " -L/usr/openwin/lib/sparcv9";
      $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/openwin/lib/sparcv9 -lXext -lX11";
    } else {
      $mesa_library     = $mesa_library . " -L/usr/openwin/lib";
      $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/openwin/lib -lXext -lX11";
    }
}



if ($config_arch eq "SOLARISX86") {
    if ($config_lp64) {
      print "No LP64 ABI on this platform currently.\n";
    }

    if ($config_gcc) {
      $arch_ccpp        = "g++";
      $arch_cc	        = "gcc";
# XXX gcc/g++ 2.95 and newer need -fpermissive since the X11 headers 
# on Solaris (and other systems) are broken and still assume that missing
# types will default to int....  When they fix this in future revs of Solaris,
# we can remove this flag.  See: http://gcc.gnu.org/fom_serv/cache/25.html
      $arch_opt_flag    = "-Wall -O -fpermissive";
      $arch_copts       = "-Wall -O";
      $arch_debug_flag  = "-g";
      $arch_depend_flag = "-M";
      $arch_template_repository = "foobar";
    } else {
      # Using Sun's compilers
      $arch_ccpp        = "CC -D__EXTENSIONS__ -compat=4";
      $arch_cc          = "cc -D__EXTENSIONS__";
      if ($config_pthreads) {
        $arch_copts       = "-mt -fast -xO3 -native";
        $arch_opt_flag    = "-mt -fast -xO3 -native";
      } else {
        $arch_copts       = "-fast -xO3 -native";
        $arch_opt_flag    = "-fast -xO3 -native";
      }
      $arch_debug_flag  = "-g";
      $arch_depend_flag = "-xM";
      $arch_template_repository = "Templates.DB";
    }

    $arch_cppopts     = $arch_no_math_float;

    if ($config_static) {
      $arch_lopts       = "-Bstatic -lsocket -lnsl";
    } else {
      $arch_lopts       = "-lsocket -lnsl -ldl";
    }

    $mesa_include     = $mesa_include . " -I/usr/openwin/include";
    $mesa_library     = $mesa_library . " -L/usr/openwin/lib";
    $mesa_libs        = "-lMesaGL -lMesaGLU -L/usr/openwin/lib -lXext -lX11";
}



if ($config_arch eq "WIN32") {
    $arch_ccpp	      = "g++";
    $arch_cc	      = "gcc";
    $arch_opt_flag    = "-O";
    $arch_debug_flag  = "-g";
    $arch_depend_flag = "-M";

    $arch_copts       = "";
    $arch_cppopts     = $arch_no_math_float;
    $def_tmpdir="c:\\\\";
    $def_imageviewer="explorer %s";
    # startup command script file.  Read after program initialization.
    $startupfilename="vmd.rc";
}

#
# If ccache is enabled, add it before the normal command lines (but after
# purify.
#
if ($config_ccache) {
  $arch_ccpp = "ccache " . $arch_ccpp;
  $arch_cc   = "ccache " . $arch_cc;
}

#
# if purify is enabled, add it before the normal command lines.    
#
if ($config_purify) {
  if ($config_lp64) {
    $arch_ccpp = "purify -ptr64 " . $arch_ccpp;  
    $arch_cc =   "purify -ptr64 " . $arch_cc;  
  } else {
    $arch_ccpp = "purify " . $arch_ccpp;  
    $arch_cc =   "purify " . $arch_cc;  
  }
}


########################### Make config.h ####################
# get a pretty date
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$year += 1900;
$config_date = ("January", "February", "March", "April", "May",  "June", "July", "August", "September", "October", "November", "December")[$mon] .  
                " $mday, $year";

$config_version_msg = 
    "VMD for $config_arch, version $progversion ($config_date)";

## Bypass making config.h if VMD_NO_CONFIG is set
# This is helpful if you are debugging the configure script since
# a lot of files depend on config.h, so even minimal changes
# (like the date change for the version) causes a major recompile.
if (!defined $ENV{'VMD_NO_CONFIG'}) {
    open(OUTFILE, ">src/config.h") ||
	die "Cannot open config.h: $!\n";

    print OUTFILE <<EOM;
#ifndef CONFIG_OPTIONS_H
#define CONFIG_OPTIONS_H
#define VMDVERSION "$progversion"
#define VERSION_MSG "$config_version_msg"
/* You should not change this value */
#define CMDLEN 15
#define DEF_VMDIMAGEVIEWER "$def_imageviewer"
#define DEF_VMDENVVAR "$install_library_dir"
#define DEF_VMDTMPDIR "$def_tmpdir"
#define INIT_DEFDISPLAY DISPLAY_WIN
#define INIT_DEFTITLE TITLE_$def_title
#define INIT_DEFHEIGHT $def_height
#define INIT_DEFDIST $def_dist
#define VMD_AUTHORS "$authors"
#define VMD_AUTHORS_LINE1 "$authorsline1"
#define VMD_AUTHORS_LINE2 "$authorsline2"
#define VMD_AUTHORS_LINE3 "$authorsline3"
#define VMD_STARTUP "$startupfilename"
#define VMD_ARCH "$config_arch"
#define VMD_OPTIONS "$config_string"
#define VMD_HOMEPAGE "$vmd_homepage"
#define VMD_HELPPAGE "$vmd_helppage"
#define VMD_CMD_PROMPT "$promptstring"
#endif
EOM
    ;

    close(OUTFILE);
} else {
    print "Not making config.h because VMD_NO_CONFIG is set.\n";
}
########################### Make vmd_version.tex ####################
open(OUTFILE, ">doc/vmd_version.tex") ||
    die "Cannot open vmd_version.tex: $!\n";

 print OUTFILE ('\newcommand{\VMDNAME} {'        . "vmd"   . "}\n");
 print OUTFILE ('\newcommand{\VMDDATE} {'        . $config_date    . "}\n");
 print OUTFILE ('\newcommand{\VMDVER} {'         . $progversion    . "}\n");
 print OUTFILE ('\newcommand{\VMDAUTHORS} {'     . $authors        . "}\n");
 print OUTFILE ('\newcommand{\VMDVERSAUTHORS} {' . $versionauthors . "}\n");

close(OUTFILE);

############ main targets  (Washington DC, Moscow, Beijing, ....) ##

# '' makes the binary
# tclindex
# clean
# install
# build

####################### Target requirements #################
# This is tricky.  I'm creating functions on the fly for
# appending each of the available options to the vmd_
# parameters.  Then I will eval the concatenated string.
# Since VMD itself uses the same setup everyone else does,
# I could use this for everything.  However, it is a lot
# easier to see how the initial setup works.

@DEFINES  = ();
@INCDIRS  = ();
@LIBDIRS  = ();
@LIBS     = ();
@VMD_CCPP = ();
@VMD_CC   = ();
@VMD_H    = ();

sub create_config_option {
    local($param) = $_[0];
    local($if_statement) = '';
    $if_statement =<<END_OF_IF;
if (\$config_${param}) {
    push(\@DEFINES , \$${param}_defines);
    push(\@INCDIRS , \$${param}_include);
    push(\@LIBDIRS , \$${param}_library);
    push(\@LIBS    , \$${param}_libs);
    push(\@VMD_CC  , \@${param}_cc);
    push(\@VMD_CCPP, \@${param}_ccpp);
    push(\@VMD_H   , \@${param}_h);
}
END_OF_IF
    ;
    return $if_statement;
}

$if_statements = '';

$if_statements .= &create_config_option('gl');
$if_statements .= &create_config_option('opengl');
$if_statements .= &create_config_option('sdl');
$if_statements .= &create_config_option('fltkopengl');
$if_statements .= &create_config_option('mesa');
$if_statements .= &create_config_option('cave');
$if_statements .= &create_config_option('freevr');
$if_statements .= &create_config_option('actc');

$if_statements .= &create_config_option('imd');
$if_statements .= &create_config_option('spaceball');
$if_statements .= &create_config_option('libtachyon');
$if_statements .= &create_config_option('vrpn');
$if_statements .= &create_config_option('sigma');
$if_statements .= &create_config_option('contrib');
$if_statements .= &create_config_option('python');
$if_statements .= &create_config_option('pthreads');
$if_statements .= &create_config_option('swig');
$if_statements .= &create_config_option('numeric');

# all of the default stuff, tcl, etc..
$if_statements .= &create_config_option('vmd');

# plugin stuff
$if_statements .= &create_config_option('plugin');

# fltk has to come after 'vmd' due to some systems /usr/include contents..
$if_statements .= &create_config_option('fltk');

# system math and networking libraries (linked against last...) 
$if_statements .= &create_config_option('system');

# print "About to eval::\n$if_statements\n:::\n";
eval($if_statements);


######################### Make the Makefile ##########################

# convert a list into a set of lines for Makefile dependencies
sub makefile_lines_tabcr {
  # this one puts in carriage returns and tabs, which cause problems 
  # for some versions of Make, such as SGI
  join(" \\\n\t\t", @_);
}

sub makefile_lines {
  # this version just puts in spaces, which works much better, but is less 
  # readable in the resulting makefile.
  join(" ", @_);
}

$DEFINES    = &makefile_lines(@DEFINES);
$INCDIRS    = &makefile_lines(@INCDIRS);
$LIBDIRS    = &makefile_lines(@LIBDIRS);
$LIBS       = &makefile_lines(@LIBS);
$VMD_CCPP   = &makefile_lines_tabcr(@VMD_CCPP);
$VMD_CC     = &makefile_lines_tabcr(@VMD_CC);
$VMD_H      = &makefile_lines_tabcr(@VMD_H);
$VMD_YACC   = &makefile_lines(@vmd_yacc);
$VMD_LEX    = &makefile_lines(@vmd_lex);
$VMD_DATA   = &makefile_lines(@vmd_data);
$VMD_EXTRA  = &makefile_lines(@vmd_extra);
$VMD_OTHER_EXE       = &makefile_lines(@vmd_other_exe);
$VMD_OTHER_NAMES     = &makefile_lines(@vmd_other_names);
$VMD_MAIN_DIR_FILES  = &makefile_lines(@vmd_main_dir_files);

if ($config_silent) {
    $SILENT = ".SILENT:";
} else {
    $SILENT = "#.SILENT:";
}

open(OUTFILE, ">src/$vmd_src_dir/Makefile") ||
    die "Cannot open $vmd_src_dir/Makefile: $!\n";

print OUTFILE<<EOM;

# Makefile for $install_name
# $config_version_msg

$SILENT

CD          = $arch_cd
COPY        = $arch_copy
COPYDIR     = $arch_copydir
MAKEDIR     = $arch_makedir
MOVE        = $arch_move
DELETE      = $arch_delete
DELETEDIR   = $arch_deletedir
ECHO        = $arch_echo
TAR         = $arch_tar
COMPRESS    = $arch_compress
GNUCOMPRESS = $arch_gnucompress
LATEX       = $arch_latex

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


# C++ source files
VMD_CCPP    =	$VMD_CCPP

# C source files
VMD_CC      = 	$VMD_CC

# Header files
VMD_H       = 	$VMD_H

# yacc and lex files
VMD_YACC    = 	$VMD_YACC

VMD_LEX     = 	$VMD_LEX

# Misc. data file
VMD_DATA    = 	$VMD_DATA

VMD_EXTRA          = 	$VMD_EXTRA

VMD_OTHER_EXE      = 	$VMD_OTHER_EXE

VMD_OTHER_NAMES    = 	$VMD_OTHER_NAMES

VMD_MAIN_DIR_FILES = 	$VMD_MAIN_DIR_FILES

# Turn things into objects
VMD_OBJS    =   \$(VMD_CCPP:.C=.o)     \$(VMD_CC:.c=.o) \\
		\$(VMD_LEX:.l=.o)      \$(VMD_YACC:.y=.o)

INCDIRS     = $INCDIRS

LIBS        = $LIBS

LIBDIRS     = $LIBDIRS

DEFINES     = $DEFINES

# compiler and compiler directives 
CC          = $arch_cc
CFLAGS      = $arch_copts -DARCH_$config_arch \$(DEFINES) \$(INCDIRS)
COMPILERC   = $arch_compilerc
RCFLAGS     = $arch_rcflags
CCPP	    = $arch_ccpp
CPPFLAGS    = $arch_opt_flag $arch_cppopts -DARCH_$config_arch \$(DEFINES) \$(INCDIRS)

DEPEND      = $arch_depend_flag
DEPENDFILE  = Makedata.depend

LOADLIBES   = \$(LIBDIRS) \$(LIBS) $arch_lopts

LEX 	    = $arch_lex
YACC	    = $arch_yacc
YFLAGS      = $arch_yflags

############################### 
# default rules 
###############################

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

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

.y.o:
	\$(ECHO) "Converting " \$< " --> "\$\@ " ..."; \\
	\$(YACC) \$(YFLAGS) \$<
	\$(MOVE) y.tab.c y.tab.C
	\$(CCPP) \$(CPPFLAGS) -I$vmd_src_dir -c y.tab.C \\
		-o $vmd_arch_dir/\$\@
	\$(DELETE) y.tab.C

.l.o:
	\$(ECHO) "Converting " \$< " --> "\$\@ " ..."; \\
	\$(LEX) \$<
	\$(MOVE) lex.yy.c lex.yy.C
	\$(CCPP) \$(CPPFLAGS) -I$vmd_src_dir -c lex.yy.C \\
		-o $vmd_arch_dir/\$\@
	\$(DELETE) lex.yy.C

########## Targets

### Source targets
all default:   $config_progname

$config_progname: y.tab.h \$(VMD_OBJS)
	\$(ECHO) "Linking " \$\@ "..."; \\
	\$(CD) $vmd_arch_dir ; \\
	if [ ! -r ./$arch_template_repository ]; then \\
	  ln -s $vmd_src_dir/$arch_template_repository ./$arch_template_repository ; \\
	fi; \\
	\$(CCPP) \$(CPPFLAGS) -I$vmd_src_dir -o \$\@ \$(VMD_OBJS) \$(LOADLIBES) ; 
	\$(COMPILERC) \$(RCFLAGS)

# makes ONLY the yacc header file
# Alas, doing this means ParseTree.C is needlessly recompiled.  I'll
# let someone else figure out how to do this right -- APD
y.tab.h: AtomParser.y AtomParser.h
	\$(ECHO) "Creating " \$\@ " ..."; \\
	\$(YACC) \$(YFLAGS) $vmd_src_dir/AtomParser.y; \\
	\$(DELETE) y.tab.c

install:
	if [ ! -d $install_library_dir ]; then \\
		\$(MAKEDIR) $install_library_dir ; \\
	fi ; \\
	if [ ! -d $install_bin_dir ]; then \\
		\$(MAKEDIR) $install_bin_dir ; \\
	fi ; \\
	if [ ! -d $install_library_dir/doc ]; then \\
		\$(MAKEDIR) $install_library_dir/doc; \\
	fi
	-\$(COPY) ../Announcement  $install_library_dir
	-\$(COPY) ../README        $install_library_dir
	-\$(COPY) ../LICENSE       $install_library_dir
	-\$(COPY) $vmd_doc_dir/ug.pdf        $install_library_dir/doc
	-\$(COPY) ../$config_arch/vmd_$config_arch $install_library_dir
	-\$(COPY) @vmd_other_exe $install_library_dir
	-\$(CD) ..; \$(TAR) -cf - scripts | \\
	(cd $install_library_dir ; \$(TAR) -xf -)
	-\$(CD) $vmd_library_dir; \$(TAR) -cf - scripts | \\
	(cd $install_library_dir ; \$(TAR) -xf -)
	-\$(CD) ..; \$(TAR) -cf - python | \\
	(cd $install_library_dir/scripts ; \$(TAR) -xf -)
	-\$(CD) ..; \$(TAR) -cf - plugins | \\
	(cd $install_library_dir ; \$(TAR) -xf -)
	-\$(COPY) ../.vmdrc ../.vmdsensors $install_library_dir
	\$(CD) $vmd_bin_dir ; \\
	if [ -f run_vmd_tmp ]; then \$(DELETE) run_vmd_tmp; fi ; \\
	\$(ECHO) '#!/bin/csh' >> run_vmd_tmp ; \\
	\$(ECHO) 'set defaultvmddir=$install_library_dir' >> run_vmd_tmp ; \\
	\$(ECHO) 'set vmdbasename=vmd' >> run_vmd_tmp ; \\
	cat $vmd_bin >> run_vmd_tmp ; \\
	chmod +x run_vmd_tmp ; \\
	\$(COPY) run_vmd_tmp $install_bin_dir/$install_name ; \\
	\$(DELETE) run_vmd_tmp
	\$(ECHO) Make sure $install_bin_dir/$install_name is in your path.
	\$(ECHO) "VMD installation complete.  Enjoy!"

##### remove most of the cruft
clean:
	\$(CD) $vmd_arch_dir ; \\
		\$(DELETE) *.o *.depend.old core

veryclean: clean swigclean
	\$(CD) $vmd_arch_dir ; \\
	  \$(DELETEDIR) $arch_template_repository; \\
	  \$(DELETE) $config_progname
	\$(CD) $vmd_src_dir ; \\
	  \$(DELETE) *.o *.a *~ core y.tab.h; \\
	  \$(DELETEDIR) $arch_template_repository; \\
	  \$(DELETE) $config_progname
	\$(CD) $vmd_doc_dir ; \\
	  \$(DELETE) *~ core

# The '/usr/include' is to keep reduce checking /usr/include dates
# However, some compilers generate multi-column depend output
# (like  'AtomSel.o: /usr/include/stdio.h AtomSel.h')
# which can cause this to fail.  If that is the case, remove the
# grep parts.
depend: y.tab.h
	if [ "\$(DEPEND)" != "" ]; then \\
	echo "Building Makefile dependencies"; \\
	  \$(ECHO) "Creating " \$(DEPENDFILE) " ..."; \\
	  if [ -f \$(DEPENDFILE) ]; then \\
	    \$(MOVE) -f \$(DEPENDFILE) \$(DEPENDFILE).old; \\
	fi; \\
	  touch \$(DEPENDFILE); \\
	for i in ZZZ \$(VMD_CCPP) ; do \\
	  if [ "\$\$i" != "ZZZ" ]; then \\
	        \$(ECHO) checking dependencies for \$\$i ...; \\
	        \$(CCPP) \$(DEPEND) \$(CPPFLAGS) \$\$i |  \\
	                grep -v "/usr/include" >> \$(DEPENDFILE) ; \\
	  fi; \\
	done; \\
	for i in ZZZ \$(VMD_CC) ; do \\
	  if [ "\$\$i" != "ZZZ" ]; then \\
	        \$(ECHO) checking dependencies for \$\$i ...; \\
	        \$(CC) \$(DEPEND) \$(CFLAGS) \$\$i |  \\
	                grep -v "/usr/include" >> \$(DEPENDFILE) ; \\
	  fi; \\
	done; \\
	\$(ECHO) ParseTree.o AtomLexer.o AtomParser.o: y.tab.h \\
                >> \$(DEPENDFILE); \\
	\$(COPY) \$(DEPENDFILE) \$(DEPENDFILE).$config_arch ; \\
	else \\
	  \$(ECHO) "Cannot find dependencies; your compiler does not support dependency checking."; \\
        fi



# to bootstrap without a Makedata.depend file, either
#   touch Makedata.depend
# or change the following line to 'sinclude'
include Makedata.depend

# Rules for SWIG-generated interface.  Ignored unless SWIG option is present
include Makefile.swig

EOM
    ;
close(OUTFILE);

if (! -d  $config_arch) {
  `mkdir $config_arch`;
}

