# Agent Tcl
# Bob Gray
# 29 June 1995
#
# This Makefile compiles the transportable agent system.
#
# Copyright 1995, Robert S. Gray, Department of Computer Science, Dartmouth College

  # Change everything to match your environment BEFORE COMPILING

  # TCP/IP port for the server
  # Unix domain socket for the server

PORT			= 8196
SOCKET_NAME		= agentsocket

  # default directory for PGP keys

PGP_KEY_DIRECTORY 	= ~/.agpgp

  # server log directory, data directory, username, groupname, server's home
  # directory, local machine name and administrator PGP keyname.  The Unix
  # domain socket that the server uses for communication on the local machine
  # is placed in the DATA_DIRECTORY so be sure that you get it right BEFORE
  # COMPILING (otherwise you will have to set the AGENT_UNIX_SOCKET
  # environment variable every time that you run an agent interpreter).  The
  # other items are used to provide a reasonable, default configuration
  # file for the agent server.
  #
  # NOTE: For both performance and security reasons, it is critical that 
  #       both the log and data directories are on the LOCAL DISK.  I can not
  #       emphasize this point strongly enough so I will say it again.  For
  #       both performance and security reasons, it is critical that both the
  #       log and data directories are on the LOCAL DISK.  If you need
  #       help identifying which portions of the machine's filesystem are on
  #       the local disk and which are on remote disks, you should contact
  #       your system administrator.
  #
  #       For best peformance, you should install the ENTIRE SYSTEM on the 
  #       local disk (i.e., all the executables, libraries and scripts).  
  #       Installation directories are set in the next section.

LOG_DIRECTORY		= /usr/agenttcl/logs
DATA_DIRECTORY		= /usr/agenttcl/access
USERNAME		= agenttcl
GROUPNAME		= users
SERVER_HOME		= /usr/agenttcl
LOCAL_MACHINE		= grumpy.dartmouth.edu
ADMIN_KEYNAME		= Agent Tcl administrator <cs.dartmouth.edu>
TEMP_DIRECTORY		= /usr/agenttcl/temp

  # source and build directories -- must be fully qualified

SOURCE_PREFIX		= /home/rgray/code/agent2.0
BUILD_PREFIX		= /home/rgray/code/agent2.0/build

  # install directories for Agent Tcl, Agent Tk and the server

PREFIX 			= /usr/agenttcl

BIN_PREFIX		= ${PREFIX}/bin
INC_PREFIX		= ${PREFIX}/include
LIB_PREFIX		= ${PREFIX}/lib

SERV_INSTALL		= ${PREFIX}/server
BIN_INSTALL		= ${BIN_PREFIX}
INC_INSTALL		= ${INC_PREFIX}
LIB_INSTALL		= ${LIB_PREFIX}
PGP_INSTALL		= ${BIN_PREFIX}

TCL_LIBRARY 		= ${LIB_INSTALL}/scripts
TK_LIBRARY		= ${LIB_INSTALL}/tkscripts
EXAMP_LIBRARY		= ${LIB_INSTALL}/examples

  # Optimization level

#OPTIMIZATION = -O2
#OPTIMIZATION = -O
OPTIMIZATION =
#OPTIMIZATION = -g
#OPTIMIZATION = -pg

  # Reverse the following lines if you want to generate static libraries
  # rather than shared libraries -- shared libraries are highly recommended
  # since they minimize memory usage when multiple agents are running at once.

CONFIG_FLAGS = --enable-shared
#CONFIG_FLAGS =

  # On a few systems the configure scripts will detect a "ranlib" that
  # actually should not be used.  If you run into problems, uncomment this
  # line.

#RANLIB=touch

  # Sun's C++ Workshop compiler requires libC.so (which on my Solaris machine
  # is in directory /opt/SUNWspro/lib).

#BUILTIN_LIBS	= -L/opt/SUNWspro/lib -lC

  # UNCOMMENT THE -lbsd LINE IF YOU ARE COMPILING UNDER AIX!!!!!!!
  # And, if you know of other platforms where -lbsd is required, please send
  # me mail (robert.s.gray@dartmouth.edu)

#BUILTIN_LIBS	= -lbsd

  # uncomment the appropriate set of three (and comment out the other set)
  #
  # CC     = your C++ compiler
  # TCL_CC = your C compiler
  # CFLAGS = additional flags for the compilers

CC		= gcc 
TCL_CC		= gcc
CFLAGS		= -DSERVER_TCP_PORT=${PORT} -Wall ${OPTIMIZATION}

#CC		= CC
#TCL_CC		= cc
#CFLAGS		= -DSERVER_TCP_PORT=${PORT} ${OPTIMIZATION} 

# ----------------------------------------------------------------------------------
# DO NOT CHANGE ANYTHING BELOW HERE!
# ----------------------------------------------------------------------------------

  # symbolic names for Tcl and Tk

TCL_LANGUAGE_NAME	= STATE-TCL
TK_LANGUAGE_NAME	= STATE-TK

  # name of the D'Agents interpreter (Tcl-based)
  # name of the D'Agents interpreter (Tk-based)
  # name of the D'Agents server
  # name of the PGP program

TCL_INTERP_NAME		= agent
TK_INTERP_NAME  	= agent-tk
SERVER_NAME		= agentd
PGP_NAME		= agpgp

  # default directory for PGP keys

  # test for symbolic link

TEST_COMMAND	= `${SOURCE_PREFIX}/test.sh 2> /dev/null`

  # architecture name

ARCH		= `arch`

  # install programs

INSTALL		= ${SOURCE_PREFIX}/install-sh -c
INSTALL_DATA_U	= ${INSTALL} -m 644
INSTALL_DATA_GU = ${INSTALL} -m 640
INSTALL_DATA_R  = ${INSTALL} -m 600
INSTALL_PROG_U  = ${INSTALL} -m 755
INSTALL_PROG_R  = ${INSTALL} -m 700
 
  # force the use of the Bourne shell on machines such as SGI's

SHELL		= /bin/sh

  # Reverse the following if you want to generate tcltest and tktest
  # There is no need to do this in normal installation.

GENERATE_TESTS = 0
#GENERATE_TESTS	= 1

  # Reverse the following if you want to generate the standard Tcl
  # interpreters "tclsh" and "wish".  There is no need to do this in a
  # normal installation.

GENERATE_SHELLS = 0
#GENERATE_SHELLS = 1

  # Reverse the following if you do *not* want to generate the Agent Tcl 
  # interpreters "agent" and "agent-tk".  Again there is no need to do this
  # in a normal installation.
  
GENERATE_INTERPS = 1
#GENERATE_INTERPS = 0

  # main targets 

all: serv tcl_agent tk_agent

# -----------------------------------------------------------------------------------
# BASE BUILD DIRECTORIES 
# -----------------------------------------------------------------------------------

${BUILD_PREFIX}/stamp:
${BUILD_PREFIX}/bin/stamp:
${BUILD_PREFIX}/lib/stamp:
${BUILD_PREFIX}/obj/stamp:

stamp: ${BUILD_PREFIX}/stamp \
	${BUILD_PREFIX}/bin/stamp \
	${BUILD_PREFIX}/lib/stamp \
	${BUILD_PREFIX}/obj/stamp 
	echo "if [ ! -d ${BUILD_PREFIX} ]; then \
		mkdir ${BUILD_PREFIX}; \
		chmod 755 ${BUILD_PREFIX}; \
		touch ${BUILD_PREFIX}/stamp; \
	      fi; \
	      if [ ! -f ${BUILD_PREFIX}/stamp ]; then \
		touch ${BUILD_PREFIX}/stamp; \
	      fi; \
	      for i in bin lib obj; \
 		do \
		  if [ ! -d ${BUILD_PREFIX}/\$$i ] ; then \
		    mkdir ${BUILD_PREFIX}/\$$i; \
		    chmod 755 ${BUILD_PREFIX}/\$$i; \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		  if [ ! -f ${BUILD_PREFIX}/\$$i/stamp ]; then \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		done; \
		touch stamp" \
	| sh

# -----------------------------------------------------------------------------------
# END OF BASE BUILD DIRECTORIES 
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# CORE 
# -----------------------------------------------------------------------------------

${BUILD_PREFIX}/obj/generic/stamp:
${BUILD_PREFIX}/obj/random/stamp:
${BUILD_PREFIX}/obj/platform/stamp:

core_stamp: stamp \
	${BUILD_PREFIX}/obj/generic/stamp \
	${BUILD_PREFIX}/obj/random/stamp \
	${BUILD_PREFIX}/obj/platform/stamp
	echo "for i in obj/generic obj/random obj/platform; \
		do \
		  if [ ! -d ${BUILD_PREFIX}/\$$i ] ; then \
		    mkdir ${BUILD_PREFIX}/\$$i; \
		    chmod 755 ${BUILD_PREFIX}/\$$i; \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		  if [ ! -f ${BUILD_PREFIX}/\$$i/stamp ]; then \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		done; \
		touch core_stamp" \
	| sh

unix_platform: ${BUILD_PREFIX}/obj/platform/Makefile force
	echo "cd ${BUILD_PREFIX}/obj/platform; \
	      make unix_platform \"CFLAGS=${CFLAGS}\"" \
	| sh

plat: unix_platform

${BUILD_PREFIX}/obj/platform/Makefile: core_stamp platform/Makefile.in configure Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      outputfile=platform/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

rand: ${BUILD_PREFIX}/obj/random/Makefile force
	echo "cd ${BUILD_PREFIX}/obj/random; \
	      make lib \"CFLAGS=${CFLAGS}\"" \
	| sh

${BUILD_PREFIX}/obj/random/Makefile: \
	core_stamp \
	${SOURCE_PREFIX}/random/Makefile.in \
	${SOURCE_PREFIX}/configure \
	Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CC=${TCL_CC}; \
	      export CC; \
	      CXX=""; \
	      export CXX; \
	      outputfile=random/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR} --cache-file=./config.c.cache; \
	      " \
	| sh

gen: ${BUILD_PREFIX}/obj/generic/Makefile force
	echo "cd ${BUILD_PREFIX}/obj/generic; \
	      make all \
		   \"CFLAGS=${CFLAGS}\" \
		   \"PGP_EXECUTABLE=${PGP_INSTALL}/${PGP_NAME}\" \
		   \"PGP_KEY_DIRECTORY=${PGP_KEY_DIRECTORY}\" \
		   \"UNIX_SOCKET=${DATA_DIRECTORY}/${SOCKET_NAME}\"" \
	| sh

${BUILD_PREFIX}/obj/generic/Makefile: core_stamp generic/Makefile.in configure Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      outputfile=generic/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

unix_core: plat rand gen

# -----------------------------------------------------------------------------------
# END OF CORE 
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# AGENT SERVER  
# -----------------------------------------------------------------------------------

${BUILD_PREFIX}/obj/server/stamp:

server_stamp: core_stamp \
	${BUILD_PREFIX}/obj/server/stamp
	echo "for i in obj/server; \
		do \
		  if [ ! -d ${BUILD_PREFIX}/\$$i ] ; then \
		    mkdir ${BUILD_PREFIX}/\$$i; \
		    chmod 755 ${BUILD_PREFIX}/\$$i; \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		  if [ ! -f ${BUILD_PREFIX}/\$$i/stamp ]; then \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		done; \
		touch server_stamp" \
	| sh

serv: ${BUILD_PREFIX}/obj/server/Makefile unix_core force
	echo "cd ${BUILD_PREFIX}/obj/server; \
	      make all \"SERVER_NAME=${SERVER_NAME}\" \
	               \"CFLAGS=${CFLAGS}\" \
		       \"BUILTIN_LIBS=${BUILTIN_LIBS}\" \
		       \"LIB_INSTALL_DIR=${LIB_INSTALL}\" \
		       \"UNIX_SOCKET=${DATA_DIRECTORY}/${SOCKET_NAME}\"" \
	| sh

${BUILD_PREFIX}/obj/server/Makefile: server_stamp server/Makefile.in configure Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
		  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      outputfile=server/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

# -----------------------------------------------------------------------------------
# END OF AGENT SERVER
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# AGENT TCL 
# -----------------------------------------------------------------------------------

${BUILD_PREFIX}/obj/tcl/stamp:
${BUILD_PREFIX}/obj/generic-tcl/stamp:
${BUILD_PREFIX}/obj/restrict-tcl/stamp:
${BUILD_PREFIX}/obj/agent-tcl/stamp:

tcl_stamp: stamp \
	${BUILD_PREFIX}/obj/tcl/stamp \
	${BUILD_PREFIX}/obj/generic-tcl/stamp \
	${BUILD_PREFIX}/obj/restrict-tcl/stamp \
	${BUILD_PREFIX}/obj/agent-tcl/stamp
	echo "for i in obj/tcl obj/generic-tcl obj/restrict-tcl \
			obj/agent-tcl; \
		do \
		  if [ ! -d ${BUILD_PREFIX}/\$$i ] ; then \
		    mkdir ${BUILD_PREFIX}/\$$i; \
		    chmod 755 ${BUILD_PREFIX}/\$$i; \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		  if [ ! -f ${BUILD_PREFIX}/\$$i/stamp ]; then \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		done; \
		touch tcl_stamp" \
	| sh

tcl_stack: ${BUILD_PREFIX}/obj/tcl/Makefile force
	echo "cd ${BUILD_PREFIX}/obj/tcl; \
	      make lib \"TCL_LIBRARY=${TCL_LIBRARY}\" \"OPTIMIZATION=${OPTIMIZATION}\"; \
	      if test \$$? -ne 0; then \
		  exit 1; \
	      fi; \
	      if test ${GENERATE_SHELLS} = 1; then \
		  make ../../bin/tclsh \"OPTIMIZATION=${OPTIMIZATION}\"; \
		  if test \$$? -ne 0; then \
		      exit 1; \
		  fi; \
	      fi; \
	      if test ${GENERATE_TESTS} = 1; then \
		  make ../../bin/tcltest \"OPTIMIZATION=${OPTIMIZATION}\"; \
		  if test \$$? -ne 0; then \
		      exit 1; \
		  fi; \
	      fi; " \
	| sh

${BUILD_PREFIX}/obj/tcl/Makefile: tcl_stamp tcl7.5/unix/Makefile.in tcl7.5/unix/configure Makefile
	echo "cp tcl7.5/unix/configure ${BUILD_PREFIX}/obj/tcl; \
	      chmod 755 ${BUILD_PREFIX}/obj/tcl/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}/tcl7.5/unix; \
	      cd ${BUILD_PREFIX}/obj/tcl; \
	      CC=${TCL_CC}; \
	      export CC; \
	      CXX=""; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
	  	  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$$SOURCE_DIR" \
	| sh

${BUILD_PREFIX}/obj/tcl/tclConfig.sh: tcl_stamp tcl7.5/unix/Makefile.in tcl7.5/unix/configure Makefile
	echo "cp tcl7.5/unix/configure ${BUILD_PREFIX}/obj/tcl; \
	      chmod 755 ${BUILD_PREFIX}/obj/tcl/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}/tcl7.5/unix; \
	      cd ${BUILD_PREFIX}/obj/tcl; \
	      CC=${TCL_CC}; \
	      export CC; \
	      CXX=""; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
		  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$$SOURCE_DIR" \
	| sh

tcl_generic: ${BUILD_PREFIX}/obj/generic-tcl/Makefile force
	echo "cd ${BUILD_PREFIX}/obj/generic-tcl; \
	      make all \"CFLAGS=${CFLAGS}\"" \
	| sh

${BUILD_PREFIX}/obj/generic-tcl/Makefile: tcl_stamp generic-tcl/Makefile.in configure Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      outputfile=generic-tcl/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

tcl_restrict: ${BUILD_PREFIX}/obj/restrict-tcl/Makefile force
	echo "cd ${BUILD_PREFIX}/obj/restrict-tcl; \
	      make all \"CFLAGS=${CFLAGS}\"" \
	| sh

${BUILD_PREFIX}/obj/restrict-tcl/Makefile: tcl_stamp restrict-tcl/Makefile.in configure Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      outputfile=restrict-tcl/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

core_tcl: tcl_generic tcl_restrict

tcl_agent: ${BUILD_PREFIX}/obj/agent-tcl/Makefile unix_core core_tcl tcl_stack force
	echo "cd ${BUILD_PREFIX}/obj/agent-tcl; \
	      make lib \
		   \"INTERP_NAME=${TCL_INTERP_NAME}\" \
		   \"LANGUAGE_NAME=${TCL_LANGUAGE_NAME}\" \
	           \"CFLAGS=${CFLAGS}\" \
		   \"LIB_INSTALL_DIR=${LIB_INSTALL}\" \
		   \"BUILTIN_LIBS=${BUILTIN_LIBS}\"; \
	      if test \$$? -ne 0; then \
		  exit 1; \
	      fi; \
	      if test ${GENERATE_INTERPS} = 1; then \
	          make ../../bin/${TCL_INTERP_NAME} \
		       \"INTERP_NAME=${TCL_INTERP_NAME}\" \
		       \"LANGUAGE_NAME=${TCL_LANGUAGE_NAME}\" \
	               \"CFLAGS=${CFLAGS}\" \
		       \"LIB_INSTALL_DIR=${LIB_INSTALL}\" \
		       \"BUILTIN_LIBS=${BUILTIN_LIBS}\"; \
		  if test \$$? -ne 0; then \
		      exit 1; \
		  fi; \
	      fi" \
	| sh

${BUILD_PREFIX}/obj/agent-tcl/Makefile: tcl_stamp agent-tcl/Makefile.in configure Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
		  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      outputfile=agent-tcl/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

# -----------------------------------------------------------------------------------
# END OF AGENT TCL 
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# AGENT TK
# -----------------------------------------------------------------------------------

${BUILD_PREFIX}/obj/tk/stamp:
${BUILD_PREFIX}/obj/agent-tk/stamp:

tk_stamp: \
	tcl_stamp \
	${BUILD_PREFIX}/obj/tk/stamp \
	${BUILD_PREFIX}/obj/agent-tk/stamp
	echo "for i in obj/tk obj/agent-tk; \
		do \
		  if [ ! -d ${BUILD_PREFIX}/\$$i ] ; then \
		    mkdir ${BUILD_PREFIX}/\$$i; \
		    chmod 755 ${BUILD_PREFIX}/\$$i; \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		  if [ ! -f ${BUILD_PREFIX}/\$$i/stamp ]; then \
		    touch ${BUILD_PREFIX}/\$$i/stamp; \
		  fi; \
		done; \
		touch tk_stamp" \
	| sh

${BUILD_PREFIX}/obj/tk/Makefile: \
	tk_stamp \
	${BUILD_PREFIX}/obj/tcl/tclConfig.sh \
	${SOURCE_PREFIX}/tk4.1/unix/Makefile.in \
	${SOURCE_PREFIX}/tk4.1/unix/configure \
	Makefile
	echo "cp tk4.1/unix/configure ${BUILD_PREFIX}/obj/tk; \
	      chmod 755 ${BUILD_PREFIX}/obj/tk/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}/tk4.1/unix; \
	      cd ${BUILD_PREFIX}/obj/tk; \
	      CC=${TCL_CC}; \
	      export CC; \
	      CXX=""; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
		  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$$SOURCE_DIR" \
	| sh

${BUILD_PREFIX}/obj/tk/tkConfig.sh: \
	tk_stamp \
	${BUILD_PREFIX}/obj/tcl/tclConfig.sh \
	${SOURCE_PREFIX}/tk4.1/unix/Makefile.in \
	${SOURCE_PREFIX}/tk4.1/unix/configure \
	Makefile
	echo "cp tk4.1/unix/configure ${BUILD_PREFIX}/obj/tk; \
	      chmod 755 ${BUILD_PREFIX}/obj/tk/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}/tk4.1/unix; \
	      cd ${BUILD_PREFIX}/obj/tk; \
	      CC=${TCL_CC}; \
	      export CC; \
	      CXX=""; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
		  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$$SOURCE_DIR" \
	| sh

tk_stack: \
	${BUILD_PREFIX}/obj/tk/Makefile \
	force
	echo "cd ${BUILD_PREFIX}/obj/tk; \
	      make lib \"TK_LIBRARY=${TK_LIBRARY}\" \"OPTIMIZATION=${OPTIMIZATION}\"; \
	      if test \$$? -ne 0; then \
		  exit 1; \
	      fi; \
	      if test ${GENERATE_SHELLS} = 1; then \
		  make ../../bin/wish \"OPTIMIZATION=${OPTIMIZATION}\"; \
		  if test \$$? -ne 0; then \
		      exit 1; \
		  fi; \
	      fi; \
	      if test ${GENERATE_TESTS} = 1; then \
		  make ../../bin/tktest \"OPTIMIZATION=${OPTIMIZATION}\"; \
		  if test \$$? -ne 0; then \
		      exit 1; \
		  fi; \
	      fi; " \
	| sh

tk_agent: \
	${BUILD_PREFIX}/obj/agent-tk/Makefile \
	tk_stack tcl_agent \
	force
	echo "cd ${BUILD_PREFIX}/obj/agent-tk; \
	      make lib \
		   \"INTERP_NAME=${TK_INTERP_NAME}\" \
		   \"LANGUAGE_NAME=${TK_LANGUAGE_NAME}\" \
	           \"CFLAGS=${CFLAGS}\" \
		   \"LIB_INSTALL_DIR=${LIB_INSTALL}\" \
	           \"TK_LIBRARY=${TK_LIBRARY}\" \
		   \"BUILTIN_LIBS=${BUILTIN_LIBS}\"; \
	      if test \$$? -ne 0; then \
		  exit 1; \
	      fi; \
	      if test ${GENERATE_INTERPS} = 1; then \
	          make ../../bin/${TK_INTERP_NAME} \
		       \"INTERP_NAME=${TK_INTERP_NAME}\" \
		       \"LANGUAGE_NAME=${TK_LANGUAGE_NAME}\" \
	               \"CFLAGS=${CFLAGS}\" \
		       \"LIB_INSTALL_DIR=${LIB_INSTALL}\" \
	               \"TK_LIBRARY=${TK_LIBRARY}\" \
		       \"BUILTIN_LIBS=${BUILTIN_LIBS}\"; \
	          if test \$$? -ne 0; then \
		      exit 1; \
	          fi; \
	      fi" \
	| sh

${BUILD_PREFIX}/obj/agent-tk/Makefile: \
	tk_stamp \
	${SOURCE_PREFIX}/agent-tk/Makefile.in \
	${SOURCE_PREFIX}/configure \
	Makefile
	echo "cp configure ${BUILD_PREFIX}/obj; \
	      chmod 755 ${BUILD_PREFIX}/obj/configure; \
	      SOURCE_DIR=${SOURCE_PREFIX}; \
	      cd ${BUILD_PREFIX}/obj; \
	      CXX=${CC}; \
	      export CXX; \
	      if test -n \"${RANLIB}\"; then \
		  RANLIB=\"${RANLIB}\"; \
		  export RANLIB; \
	      fi; \
	      outputfile=agent-tk/Makefile; \
	      export outputfile; \
	      ./configure --enable-gcc ${CONFIG_FLAGS} --srcdir=\$${SOURCE_DIR}" \
	| sh

# -----------------------------------------------------------------------------------
# END OF AGENT TK 
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# SCRIPT CUSTOMIZATION 
# -----------------------------------------------------------------------------------

tcl_script_directories: \
	core_stamp \
	force
	echo "for i in scripts \
		       scripts/start \
		       scripts/managers \
		       scripts/keys \
		       scripts/examples \
		       scripts/tk \
		       scripts/tk/demos; \
		do \
		  if [ ! -d ${BUILD_PREFIX}/\$$i ] ; then \
		    mkdir ${BUILD_PREFIX}/\$$i; \
		    chmod 755 ${BUILD_PREFIX}/\$$i; \
		  fi; \
		done" \
	| sh

tcl_scripts: \
	tcl_script_directories \
	force
	echo "TCL_LIBRARY=${SOURCE_PREFIX}/scripts/agent; \
	      export TCL_LIBRARY; \
	      LD_LIBRARY_PATH=${BUILD_PREFIX}/lib; \
	      export LD_LIBRARY_PATH; \
              if test "x${CONFIG_FLAGS}" != "x"; then \
                  _RLD_LIST=""; \
                  if test -f ${BUILD_PREFIX}/lib/libagtcl.so; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagtcl.so:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libagtcl.a; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagtcl.a:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libagrand.so; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagrand.so:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libagrand.a; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagrand.a:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libsttcl.so; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libsttcl.so:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libsttcl.a; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libsttcl.a:\"; \
                  fi; \
                  _RLD_LIST=\"\$${_RLD_LIST}DEFAULT\"; \
                  export _RLD_LIST; \
              fi; \
	      cd ${BUILD_PREFIX}/obj/agent-tcl; \
	      ${BUILD_PREFIX}/bin/${TCL_INTERP_NAME} \
		${SOURCE_PREFIX}/customize.tcl \
		\"${BUILD_PREFIX}\" \
		\"${SOURCE_PREFIX}\" \
		\"${BIN_INSTALL}/${TCL_INTERP_NAME}\" \
		\"${BIN_INSTALL}/${TK_INTERP_NAME}\" \
		\"${PGP_INSTALL}/${PGP_NAME}\" \
		\"${PGP_KEY_DIRECTORY}\" \
		\"${TCL_LIBRARY}\" \
		\"${TK_LIBRARY}\" \
		\"${LIB_INSTALL}\" \
		\"${SERV_INSTALL}/${SERVER_NAME}\" \
		\"${SERV_INSTALL}\" \
		\"${PORT}\" \
		\"${DATA_DIRECTORY}/${SOCKET_NAME}\" \
		\"${LOG_DIRECTORY}\" \
		\"${USERNAME}\" \
		\"${GROUPNAME}\" \
		\"${SERVER_HOME}\" \
		\"${LOCAL_MACHINE}\" \
		\"${DATA_DIRECTORY}\" \
		\"${ADMIN_KEYNAME}\" \
		\"${JAVA_BIN_INSTALL}/java\" \
		\"${JAVA_LIB_INSTALL}/classes.zip\" \
		\"${JAVA_CLASS_INSTALL}\" \
		\"${TEMP_DIRECTORY}\"; \
	      if test \$$? -ne 0; then \
		  echo \"**********************************************************\"; \
		  echo \"FATAL ERROR in customize.tcl\"; \
		  echo \"**********************************************************\"; \
		  exit 1; \
	      fi" \
	| sh

customize: tcl_scripts force

# -----------------------------------------------------------------------------------
# END OF SCRIPT CUSTOMIZATION
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# INSTALLATION
# -----------------------------------------------------------------------------------

directories:
	echo "for i in ${PREFIX} ${BIN_PREFIX} ${INC_PREFIX} ${LIB_PREFIX} \
			${BIN_INSTALL} ${SERV_INSTALL} \
			${INC_INSTALL} ${INC_INSTALL}/random \
			${LIB_INSTALL} \
			${TCL_LIBRARY} ${EXAMP_LIBRARY} ${TK_LIBRARY} \
			${SERVER_HOME} ${SERVER_HOME}/.agpgp \
			${DATA_DIRECTORY} ${LOG_DIRECTORY} \
			${TEMP_DIRECTORY} \
			${TK_LIBRARY}/demos ${TK_LIBRARY}/demos/images; \
		do \
		  if [ ! -d \$$i ] ; then \
		    mkdir \$$i; \
		    chmod 755 \$$i; \
		    else true; \
		  fi; \
		done; \
		chmod go-rwx ${TEMP_DIRECTORY};" \
	| sh

install: \
	directories \
	utilinstall \
	confinstall \
	install-tcl \
	install-tk \
	install-server

install-code: \
	directories \
	install-tcl \
	install-tk \
	install-server

utilinstall: directories
	${INSTALL_PROG_U} ${BUILD_PREFIX}/scripts/start/machine.tcl ${BIN_INSTALL}/machine.tcl
	${INSTALL_PROG_U} ${BUILD_PREFIX}/scripts/keys/keys.tcl ${BIN_INSTALL}/keys.tcl

confinstall: directories
	${INSTALL_DATA_R} ${BUILD_PREFIX}/scripts/start/agent.languages ${DATA_DIRECTORY}/agent.languages
	${INSTALL_DATA_R} ${BUILD_PREFIX}/scripts/managers/manager.conf ${DATA_DIRECTORY}/manager.conf
	${INSTALL_DATA_R} ${BUILD_PREFIX}/scripts/start/agentd.conf ${DATA_DIRECTORY}/agentd.conf
	${INSTALL_PROG_R} ${BUILD_PREFIX}/scripts/start/start_agentd ${SERV_INSTALL}/start_agentd
	${INSTALL_PROG_R} ${BUILD_PREFIX}/scripts/start/start_man ${SERV_INSTALL}/start_man

install-server-binaries: directories
	${INSTALL_PROG_R} ${BUILD_PREFIX}/bin/${SERVER_NAME} ${SERV_INSTALL}/${SERVER_NAME}
	${INSTALL_PROG_U} ${BUILD_PREFIX}/bin/genrand ${SERV_INSTALL}/genrand
	${INSTALL_PROG_U} ${BUILD_PREFIX}/bin/seerand ${SERV_INSTALL}/seerand
	${INSTALL_PROG_U} ${BUILD_PREFIX}/bin/stirrand ${SERV_INSTALL}/stirrand
	${INSTALL_PROG_R} ${BUILD_PREFIX}/scripts/start/kill.tcl ${SERV_INSTALL}/kill.tcl
	${INSTALL_PROG_R} ${BUILD_PREFIX}/scripts/managers/manager.tcl ${SERV_INSTALL}/manager.tcl

install-server-libraries: directories
	echo "cd ${BUILD_PREFIX}/lib; \
	      for i in libagrand libagserv libagtserv; \
	      do \
		link=\"\"; \
		file=\"\"; \
		for j in \$$i*.so; \
		  do \
		    if test -f \$$j; then \
		      if ${TEST_COMMAND} \$$j; then \
			link=\$$j; \
		      else \
			file=\$$j; \
		      fi; \
		    fi; \
		  done; \
		if test "x\$$file" != "x"; then \
		  ${INSTALL_PROG_U} \$$file ${LIB_INSTALL}/\$$file; \
		  rm -f ${LIB_INSTALL}/\$$link; \
		  ln -s \$$file ${LIB_INSTALL}/\$$link; \
		fi; \
		link=\"\"; \
		file=\"\"; \
		for j in \$$i*.a; \
		  do \
		    if test -f \$$j; then \
		      if ${TEST_COMMAND} \$$j; then \
			link=\$$j; \
		      else \
			file=\$$j; \
		      fi; \
		    fi; \
		  done; \
		if test "x\$$file" != "x"; then \
		  ${INSTALL_PROG_U} \$$file ${LIB_INSTALL}/\$$file; \
		  rm -f ${LIB_INSTALL}/\$$link; \
		  ln -s \$$file ${LIB_INSTALL}/\$$link; \
		fi; \
	      done;" \
	| sh

install-server: \
	directories \
	install-server-binaries \
	install-server-libraries

install-agenttcl-binaries: directories
	${INSTALL_PROG_U} ${BUILD_PREFIX}/bin/${TCL_INTERP_NAME} ${BIN_INSTALL}/${TCL_INTERP_NAME}
	${INSTALL_DATA_U} ${SOURCE_PREFIX}/scripts/agent/tclIndex ${TCL_LIBRARY}/tclIndex
	echo "cd ${SOURCE_PREFIX}/scripts/agent; for i in *.tcl; \
	  do \
	  ${INSTALL_PROG_U} \$$i ${TCL_LIBRARY}/\$$i; \
	  done;" \
	| sh

install-agenttcl-examples: directories
	echo "cd ${BUILD_PREFIX}/scripts/examples; for i in *.tcl; \
	  do \
	  ${INSTALL_PROG_U} \$$i ${EXAMP_LIBRARY}/\$$i; \
	  done;" \
	| sh

install-agenttcl-libraries: directories
	echo "cd ${BUILD_PREFIX}/lib; \
	      for i in libagtcl libagrand libsttcl; \
	      do \
		link=\"\"; \
		file=\"\"; \
		for j in \$$i*.so; \
		  do \
		    if test -f \$$j; then \
		      if ${TEST_COMMAND} \$$j; then \
			link=\$$j; \
		      else \
			file=\$$j; \
		      fi; \
		    fi; \
		  done; \
		if test "x\$$file" != "x"; then \
		  ${INSTALL_PROG_U} \$$file ${LIB_INSTALL}/\$$file; \
		  rm -f ${LIB_INSTALL}/\$$link; \
		  ln -s \$$file ${LIB_INSTALL}/\$$link; \
		fi; \
		link=\"\"; \
		file=\"\"; \
		for j in \$$i*.a; \
		  do \
		    if test -f \$$j; then \
		      if ${TEST_COMMAND} \$$j; then \
			link=\$$j; \
		      else \
			file=\$$j; \
		      fi; \
		    fi; \
		  done; \
		if test "x\$$file" != "x"; then \
		  ${INSTALL_PROG_U} \$$file ${LIB_INSTALL}/\$$file; \
		  rm -f ${LIB_INSTALL}/\$$link; \
		  ln -s \$$file ${LIB_INSTALL}/\$$link; \
		fi; \
	      done;" \
	| sh

install-tcl: \
	directories \
	install-agenttcl-binaries \
	install-agenttcl-examples \
	install-agenttcl-libraries

install-agenttk-binaries: directories
	${INSTALL_PROG_U} ${BUILD_PREFIX}/bin/${TK_INTERP_NAME} ${BIN_INSTALL}/${TK_INTERP_NAME}
	${INSTALL_DATA_U} ${SOURCE_PREFIX}/scripts/agent/tclIndex ${TCL_LIBRARY}/tclIndex
	echo "cd ${SOURCE_PREFIX}/scripts/agent; for i in *.tcl; \
	  do \
	  ${INSTALL_PROG_U} \$$i ${TCL_LIBRARY}/\$$i; \
	  done;" \
	| sh
	${INSTALL_DATA_U} ${SOURCE_PREFIX}/scripts/tk/tclIndex ${TK_LIBRARY}/tclIndex
	echo "cd ${SOURCE_PREFIX}/scripts/tk; for i in *.tcl; \
	  do \
	  ${INSTALL_PROG_U} \$$i ${TK_LIBRARY}/\$$i; \
	  done;" \
	| sh

install-agenttk-examples: directories
	echo "cd ${BUILD_PREFIX}/scripts/examples; for i in *.tk; \
	  do \
	  ${INSTALL_PROG_U} \$$i ${EXAMP_LIBRARY}/\$$i; \
	  done;" \
	| sh

install-agenttk-libraries: directories
	echo "cd ${BUILD_PREFIX}/lib; \
	      for i in libagtk libagrand libsttcl libsttk; \
	      do \
		link=\"\"; \
		file=\"\"; \
		for j in \$$i*.so; \
		  do \
		    if test -f \$$j; then \
		      if ${TEST_COMMAND} \$$j; then \
			link=\$$j; \
		      else \
			file=\$$j; \
		      fi; \
		    fi; \
		  done; \
		if test "x\$$file" != "x"; then \
		  ${INSTALL_PROG_U} \$$file ${LIB_INSTALL}/\$$file; \
		  rm -f ${LIB_INSTALL}/\$$link; \
		  ln -s \$$file ${LIB_INSTALL}/\$$link; \
		fi; \
		link=\"\"; \
		file=\"\"; \
		for j in \$$i*.a; \
		  do \
		    if test -f \$$j; then \
		      if ${TEST_COMMAND} \$$j; then \
			link=\$$j; \
		      else \
			file=\$$j; \
		      fi; \
		    fi; \
		  done; \
		if test "x\$$file" != "x"; then \
		  ${INSTALL_PROG_U} \$$file ${LIB_INSTALL}/\$$file; \
		  rm -f ${LIB_INSTALL}/\$$link; \
		  ln -s \$$file ${LIB_INSTALL}/\$$link; \
		fi; \
	      done;" \
	| sh

install-tk: \
	directories \
	install-agenttk-binaries \
	install-agenttk-examples \
	install-agenttk-libraries

# -----------------------------------------------------------------------------------
# END OF INSTALLATION
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# RANDOM BITS 
# -----------------------------------------------------------------------------------

ranbits: force
	echo "echo \"\"; \
	      echo \"Making random bits ...\"; \
	      LD_LIBRARY_PATH=${BUILD_PREFIX}/lib; \
	      export LD_LIBRARY_PATH; \
              if test "x${CONFIG_FLAGS}" != "x"; then \
                  _RLD_LIST=""; \
                  if test -f ${BUILD_PREFIX}/lib/libagtcl.so; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagtcl.so:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libagtcl.a; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagtcl.a:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libagrand.so; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagrand.so:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libagrand.a; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libagrand.a:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libsttcl.so; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libsttcl.so:\"; \
                  fi; \
                  if test -f ${BUILD_PREFIX}/lib/libsttcl.a; then \
                      _RLD_LIST=\"\$${_RLD_LIST}${BUILD_PREFIX}/lib/libsttcl.a:\"; \
                  fi; \
                  _RLD_LIST=\"\$${_RLD_LIST}DEFAULT\"; \
                  export _RLD_LIST; \
              fi; \
	      ${BUILD_PREFIX}/bin/genrand ${DATA_DIRECTORY}/random.bin 3072; \
	      if test \$$? -ne 0; then \
		  exit 1; \
	      fi; \
	      ${INSTALL_DATA_R} ${DATA_DIRECTORY}/random.bin ${SERVER_HOME}/.agpgp/randseed.bin" \
	| sh

# -----------------------------------------------------------------------------------
# END OF RANDOM BITS 
# -----------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------
# CLEANUP 
# -----------------------------------------------------------------------------------

clean:
	echo "rm -rf ${BUILD_PREFIX}/obj" | sh
 
superclean:
	echo "rm -rf ${BUILD_PREFIX}; \
	      rm -f stamp; \
	      rm -f core_stamp; \
	      rm -f tcl_stamp; \
	      rm -f tk_stamp; \
	      rm -f server_stamp" \
	| sh

# -----------------------------------------------------------------------------------
# END OF CLEANUP 
# -----------------------------------------------------------------------------------

force:
