#==============================================================================
#
# Makefile for Extended Tcl.  This requires Tcl 6.2 from Berkeley, which
# should be compiled before running this makefile.  Its location is configured
# below.
#
#------------------------------------------------------------------------------
# Copyright 1991 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#==============================================================================
#
# Configuration section.  Modify this section to set some general options and
# selecting a section for a specific Unix implementation.
#
#==============================================================================

#------------------------------------------------------------------------------
#
# Location of the UCB Tcl distribution relative to this directory.
#
TCL_UCB_DIR=../tcl6.2

#------------------------------------------------------------------------------
# Compiler debug/optimization/profiling flag to use.  Not that if debugging or
# profiling is enabled, the DO_STRIPPING option below must be disabled.
#
OPTIMIZE_FLAG=-g

#------------------------------------------------------------------------------
# Stripping of the final tclshell binary.  Specify `true' if the binary is to
# be stripped (optimized case) or specify `false' if the binary is not to be
# stripped (debugging case).
#
DO_STRIPPING=false

#------------------------------------------------------------------------------
# Enable or disable Tcl history in the Tcl flag.  If this macro is set to
# '-DTCL_NOHISTORY', the `history' command will not be available in the Tcl
# shell.  Many people do not find the history command useful and its rather
# large, so this way it can be excluded from the standard shell.  It will
# still be in the library and will be available in other applications if they
# use `Tcl_RecordAndEval'.
#
HISTORY_FLAG=

#------------------------------------------------------------------------------
# Memory debugging defines.  These are only of interest if you are adding C
# code to Tcl or debugging Tcl C code.  They help find memory overwrites and
# leaks.  One or more of the following flags may be specified (in the form
# -DFLAGNAME).
#
#    o TCL_MEM_DEBUG - Turn on memory debugging. 
#    o TCL_SHELL_MEM_LEAK - Dump a list of active memory blocks when the
#      shell exits an eof (requires TCL_MEM_DEBUG).
#
# NOTE: If TCL_MEM_DEBUG is enabled, the Berkeley Tcl distribution must be 
# recompiled with this option as well, or it will not link.  In addition a flag
# MEM_VALIDATE may be specified in the Berkeley Tcl compilation to do
# validation of all memory blocks on each allocation or deallocation (very
# slow).
#
MEM_DEBUG_FLAGS=-DTCL_MEM_DEBUG

#==============================================================================
# Install options sections.  This sections describes the installation options.
# Some of the actual values are set under each system definition in the
# system dependent section.  Your might want to change some of these values
# before installing.
#..............................................................................
#
# o TCL_OWNER - The user that will own all Tcl files after installation.
#   (system dependent)
# o TCL_GROUP - The group that all Tcl files will belong to after installation.
#   (system dependent)
# o TCL_DEFAULT - Base name of Tcl default file.  This name will have a
#   version number appended.  (system dependent)
#

#
# The directory to install Tcl binary into.
#
TCL_BINDIR=/usr/local/bin

#
# The directory tcl.a library goes into.
#
TCL_LIBDIR=/usr/local/lib

#
# The directory the Tcl .h files go into.
#
TCL_INCLUDEDIR=/usr/local/include

#
# The directory .tcl files and the .tlib library goes into.
#
TCL_TCLDIR=/usr/local/tcl

#==============================================================================
# This section defines where and how the manual pages are to be installed.
# This is somewhat problematic, so a global option not to install manual pages
# is provided. Since there are so many manual pages provided, they are placed
# together in one Tcl manual page directory, rather than splitting into the
# standard manual pages directories.  The actual definitions of these variables
# are set for in the system dependent section.  You might want to modify these
# values.
#..............................................................................

#
# Set to 1 to install manual files, to 0 to not install manual files.
#

TCL_MAN_INSTALL=0

# o TCL_MAN_BASEDIR - Base manual directory where all of the man.* and cat.*
#   directories live.
# o TCL_MAN_SECTION - Section for Tcl manual pages. This is appended to the
#   directory name and all of the manual file names.
# o TCL_MAN_SEPARATOR - The separator character used in the directory name
#   of the cat* and man* manual directories.  This is usually empty  or 
#   a period.
# o TCL_MAN_STYLE - The style of manual management the system has.  It is
#   a string with one of the following values:
#      o SHORT - Short file name installation (an index can be generated).
#      o LONG - Long file name installation, a link will be made for each
#        name the manual page is to be available under.
# o TCL_MAN_INDEX - If 1, then a manual page index will be build in the manual
#   base directory named index.TCL.  Each line in the file has the form:
#       mansubject manfile section
# o TCL_MAN_INDEX_MERGE - If 1, then the manual index will be merged with the
#   an index file named `index' in the manual base directory.  The old index
#   will be backed up in a file named `index.bak'.

#==============================================================================
# System specific configuration.  Comment out the section of defines that are
# required for your version of Unix.  In addition to the options defined in the
# Berkeley source the following options can be defined here.  This information
# will help you build your own system configuration if one is not supplied
# here.
#
#    o SYS_DEP_FLAGS - The system dependency flags.  The following options are
#      available, these should be defined using -Dflag.
#
#      o TCL_NO_TOLOWER_MACRO - Define if the `_tolower' and `_toupper' macros
#        are not available.
#      o TCL_HAVE_SETLINEBUF - Define if the `setlinebuf' is available as part
#        of stdio.
#      o TCL_32_BIT_RANDOM - Define if the `rand' function returns a value in
#        the range 0..(2^31)-1, leave undefined if `rand' returns a value
#        in the range 0..(2^15)-1.
#      o TCL_NO_SELECT - The select call is not available.
#      o TCL_USE_BZERO_MACRO - Use a macro to define bzero for the select
#        FD_ZERO macro.
#      o TCL_SIG_PROC_INT - Set if the signal handling procs have a return type
#        of int instead of void.
#      o TCL_POSIX_SIG - Set if posix signals are available (sigaction, etc).
#
#    o LINK_OPTIONS - The flags to specify when linking the tclshell.
#
#    o RANLIB_CMD - Either `ranlib' if ranlib is required or `true' if ranlib
#      should not be used.
#
#    o MCS_CMD - Command to delete comments from the object file comment
#      section, if available.  The command `true' if it's not available.  This
#      makes the object file even smaller after its stipped.
#
#    o SUPPORT_FLAGS - The flags for SUPPORT_OBJS code.  The following options
#      are available, these should be defined using -Dflag.
#
#      o TCL_HAS_TM_ZONE - If if 'struct tm' has the 'tm_zone' field.   Used
#        by strftime.
#
#    o SUPPORT_OBJS - The object files to compile to implement library 
#      functions that are not available on this particular version of Unix.
#      The following are available:
#         o strftime

#------------------------------------------------------------------------------
# System V 3.2.0 (tested on Bell-Tech or Intel Unix for the Intel 386)
#
#SYS_DEP_FLAGS=-DTCL_NO_SELECT
#LINK_OPTIONS=-lc_s -lm
#RANLIB_CMD=true
#MCS_CMD=mcs -d
#SUPPORT_FLAGS=
#SUPPORT_OBJS=strftime.o
#
#TCL_OWNER=bin
#TCL_GROUP=bin
#TCL_DEFAULT=/etc/default/tcl
#
#TCL_MAN_BASEDIR=/usr/man
#TCL_MAN_SECTION=tcl
#TCL_MAN_SEPARATOR="."
#TCL_MAN_STYLE=short
#TCL_MAN_INDEX=1
#TCL_MAN_INDEX_MERGE=0

#------------------------------------------------------------------------------
#  SCO Unix - System V 3.2.2
#
#SYS_DEP_FLAGS=-DTCL_USE_BZERO_MACRO -DTCL_POSIX_SIG
SYS_DEP_FLAGS=-DTCL_USE_BZERO_MACRO
#LINK_OPTIONS=-lc_s -lm -ldbm
#RANLIB_CMD=true
#MCS_CMD=mcs -d
#SUPPORT_FLAGS=
#SUPPORT_OBJS=
#
#TCL_OWNER=bin
#TCL_GROUP=bin
#TCL_DEFAULT=/etc/default/tcl
#
#TCL_MAN_BASEDIR=/usr/man
#TCL_MAN_SECTION=tcl
#TCL_MAN_SEPARATOR="."
#TCL_MAN_STYLE=short
#TCL_MAN_INDEX=1
#TCL_MAN_INDEX_MERGE=1

#
# BSD386
#
MAKEFLAGS=fMakefile
#------------------------------------------------------------------------------
# BSD
#
SYS_DEP_FLAGS= -DTCL_NO_TOLOWER_MACRO -DTCL_HAVE_SETLINEBUF -DTCL_32_BIT_RANDOM
LINK_OPTIONS=-lm
RANLIB_CMD="ranlib"
MCS_CMD=true
SUPPORT_FLAGS=-DTCL_HAS_TM_ZONE
SUPPORT_OBJS=strftime.o
#
TCL_OWNER=root
TCL_GROUP=sys
TCL_DEFAULT=/usr/local/lib/tcldefault
#
TCL_MAN_BASEDIR=/usr/man
TCL_MAN_SECTION=3
TCL_MAN_SEPARATOR=""
TCL_MAN_STYLE=long
TCL_MAN_INDEX=0
TCL_MAN_INDEX_MERGE=0

#------------------------------------------------------------------------------
# SUN O/S
#
#SYS_DEP_FLAGS=-DTCL_NO_TOLOWER_MACRO -DTCL_HAVE_SETLINEBUF -DTCL_32_BIT_RANDOM -DTCL_POSIX_SIG
#LINK_OPTIONS=-lm
#RANLIB_CMD="ranlib"
#MCS_CMD=true
#SUPPORT_FLAGS=-DTCL_HAS_TM_ZONE
#SUPPORT_OBJS=
#
#TCL_OWNER=bin
#TCL_GROUP=bin
#TCL_DEFAULT=/usr/local/lib/tcldefault
#
#TCL_MAN_BASEDIR=/usr/man
#TCL_MAN_SECTION=3
#TCL_MAN_SEPARATOR=""
#TCL_MAN_STYLE=long
#TCL_MAN_INDEX=0
#TCL_MAN_INDEX_MERGE=0

#------------------------------------------------------------------------------
#    HPUX - Hewlett-Packard HP/UX
#
#SYS_DEP_FLAGS= -DTCL_32_BIT_RANDOM -DTCL_POSIX_SIG
#LINK_OPTIONS=-lBSD -lPW -lm
#RANLIB_CMD=true
#MCS_CMD=true
#SUPPORT_FLAGS=-DTCL_HAS_TM_ZONE
#SUPPORT_OBJS=
#
#TCL_OWNER=root
#TCL_GROUP=system
#TCL_DEFAULT=/usr/local/lib/tcldefault
#
#TCL_MAN_BASEDIR=/usr/man
#TCL_MAN_SECTION=3
#TCL_MAN_SEPARATOR=""
#TCL_MAN_STYLE=long
#TCL_MAN_INDEX=0
#TCL_MAN_INDEX_MERGE=0

#------------------------------------------------------------------------------
#    XENIX-386 - SCO Xenix 2.3.3 for the 80386
#
#SYS_DEP_FLAGS=-DTCL_NO_SELECT -DTCL_SIG_PROC_INT
#LINK_OPTIONS=-ldir -lm
#RANLIB_CMD=ranlib
#MCS_CMD=true
#SUPPORT_FLAGS=
#SUPPORT_OBJS=strftime.o
#
#TCL_OWNER=bin
#TCL_GROUP=bin
#TCL_DEFAULT=/etc/default/tcl
#
#TCL_MAN_BASEDIR=/usr/man
#TCL_MAN_SECTION=tcl
#TCL_MAN_SEPARATOR="."
#TCL_MAN_STYLE=short
#TCL_MAN_INDEX=1
#TCL_MAN_INDEX_MERGE=1

#------------------------------------------------------------------------------
#                        End of Configuration Section
#==============================================================================

SHELL=/bin/sh
TCLSHELL=../tcl

# List of files that are touched by second makefiles when something changes.

MADE.FILES=ucbsrc/made.tmp ossupport/made.tmp src/made.tmp

# Options to pass to the next lowest level for C compilations.

CFLAGS= $(OPTIMIZE_FLAG) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) $(SYS_DEP_FLAGS) -DTCL_386BSD

all: ExtendedObjs tcl TCLDEFAULT

#
# Generate the Tcl shell.
#
tcl: libtcl.a src/main.o $(MADE.FILES)
	$(RANLIB_CMD) libtcl.a
	cc $(CFLAGS) src/main.o libtcl.a $(LINK_OPTIONS) -o tcl
	if $(DO_STRIPPING) ; then \
	    strip tcl; \
	    $(MCS_CMD) tcl; fi
#
# Objects in the lower-level directorys
#
ExtendedObjs: libtcl.a
	cd ucbsrc;$(MAKE) -$(MAKEFLAGS) all 'CFLAGS=$(CFLAGS)'

	cd ossupport;$(MAKE) -$(MAKEFLAGS) all 'OBJS=$(SUPPORT_OBJS)' 'CFLAGS=$(CFLAGS) $(SUPPORT_FLAGS)'

	cd src;$(MAKE) -$(MAKEFLAGS) all 'CFLAGS=$(CFLAGS)' 'HISTORY_FLAG=$(HISTORY_FLAG)' 'TCL_DEFAULT=$(TCL_DEFAULT)' 'RANLIB_CMD=$(RANLIB_CMD)' 'LINK_OPTIONS=$(LINK_OPTIONS)' 'DO_STRIPPING=$(DO_STRIPPING)' 'MCS_CMD=$(MCS_CMD)'

	cd tclsrc;$(MAKE) -$(MAKEFLAGS) 'TCL_UCB_DIR=../$(TCL_UCB_DIR)' all

#
# Generate a temporary TCLDEFAULT file so Tcl can be run in this directory.
#
TCLDEFAULT:
	@echo "	- Generating temporary TCLDEFAULT file -"
	@echo '# Temporary TCLDEFAULT file for debugging'  >TCLDEFAULT
	@echo "set TCLPATH `pwd`/tcllib"                  >>TCLDEFAULT
	@echo "set TCLINIT `pwd`/tcllib/TclInit.tcl"      >>TCLDEFAULT


#
# Copy the baseline libtcl.a file.  Force the other Makefiles to add their
# .o files to the library by nuking their made.tmp file.
#
libtcl.a:	$(TCL_UCB_DIR)/libtcl.a
	true "karl ??? why does this always copy the library over ???"
	cp $(TCL_UCB_DIR)/libtcl.a .
	rm -f ossupport/made.tmp ucbsrc/made.tmp src/made.tmp

#
# This just test to see if the C++ include file compiles.
#
tcl++:
	cd src;$(MAKE) -$(MAKEFLAGS) tcl++ 'CFLAGS=$(CFLAGS)'

#
# Run the Basic and Extended Tcl tests.
#
test: all
	./tcl -c "cd $(TCL_UCB_DIR)/tests;source all"
	./tcl -c "cd tests;source all"	

#
# Install Tcl.
#
install: all install.conf
	./tcl tclsrc/installTcl.tcl install.conf

install.conf: Makefile
	@echo "Creating install.conf"
	@echo "set TCL_UCB_DIR         {$(TCL_UCB_DIR)}"          >install.conf
	@echo "set TCL_DEFAULT         {$(TCL_DEFAULT)}"         >>install.conf
	@echo "set TCL_OWNER           {$(TCL_OWNER)}"           >>install.conf
	@echo "set TCL_GROUP           {$(TCL_GROUP)}"           >>install.conf
	@echo "set TCL_BINDIR          {$(TCL_BINDIR)}"          >>install.conf
	@echo "set TCL_LIBDIR          {$(TCL_LIBDIR)}"          >>install.conf
	@echo "set TCL_INCLUDEDIR      {$(TCL_INCLUDEDIR)}"      >>install.conf
	@echo "set TCL_TCLDIR          {$(TCL_TCLDIR)}"          >>install.conf
	@echo "set TCL_MAN_INSTALL     {$(TCL_MAN_INSTALL)}"     >>install.conf
	@echo "set TCL_MAN_BASEDIR     {$(TCL_MAN_BASEDIR)}"     >>install.conf
	@echo "set TCL_MAN_SECTION     {$(TCL_MAN_SECTION)}"     >>install.conf
	@echo "set TCL_MAN_SEPARATOR   {$(TCL_MAN_SEPARATOR)}"   >>install.conf
	@echo "set TCL_MAN_STYLE       {$(TCL_MAN_STYLE)}"       >>install.conf
	@echo "set TCL_MAN_INDEX       {$(TCL_MAN_INDEX)}"       >>install.conf
	@echo "set TCL_MAN_INDEX_MERGE {$(TCL_MAN_INDEX_MERGE)}" >>install.conf
	

clean:
	cd ucbsrc;$(MAKE) -$(MAKEFLAGS) clean
	cd ossupport;$(MAKE) -$(MAKEFLAGS) clean
	cd src;$(MAKE) -$(MAKEFLAGS) clean
	cd tclsrc;$(MAKE) -$(MAKEFLAGS) clean
	-rm -f libtcl.a TCLDEFAULT tcl install.conf
