#
# This file is a Makefile for Tcl.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
# the configuration script).
#----------------------------------------------------------------

# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

exec_prefix =	\tcl
prefix =	\tcl

# Directory in which to install the library of Tcl scripts (note:
# you can set the TCL_LIBRARY environment variable at run-time to
# override the compiled-in location):
#TCL_LIBRARY =	$(prefix)\lib\tcl
TCL_LIBRARY_PATH =	/tcl

# Directory in which to install the archive libtcl.lib:
LIB_DIR =	$(exec_prefix)\lib

# Directory in which to install the program tclsh:
BIN_DIR =	$(exec_prefix)\bin

# Directory in which to install the include file tcl.h:
INCLUDE_DIR =	$(prefix)\include

# Top-level directory for manual entries:
MAN_DIR =	$(prefix)\man

# Directory in which to install manual entry for tclsh:
MAN1_DIR =	$(MAN_DIR)\man1

# Directory in which to install manual entries for Tcl's C library
# procedures:
MAN3_DIR =	$(MAN_DIR)\man3

# Directory in which to install manual entries for the built-in
# Tcl commands:
MANN_DIR =	$(MAN_DIR)\mann

# To change the compiler switches, for example to change from -O
# to -g, change the following line:
CFLAGS = /Q /O /Sm /Gm /Xi

# To disable ANSI-C procedure prototypes reverse the comment characters
# on the following lines:
PROTO_FLAGS =
#PROTO_FLAGS = -DNO_PROTOTYPE

# Mathematical functions like sin and atan2 are enabled for expressions
# by default.  To disable them, reverse the comment characters on the
# following pairs of lines:
MATH_FLAGS =
#MATH_FLAGS = -DTCL_NO_MATH
#MATH_LIBS = -lm
MATH_LIBS =

# To compile for non-UNIX systems (so that only the non-UNIX-specific
# commands are available), reverse the comment characters on the
# following pairs of lines.  In addition, you'll have to provide your
# own replacement for the "panic" procedure (see panic.c for what
# the current one does).
GENERIC_FLAGS =
#GENERIC_FLAGS = -DTCL_GENERIC_ONLY
UNIX_OBJS = panic.obj tclEnv.obj tclGlob.obj tclMain.obj tclUnixAZ.obj \
	tclUnixStr.obj tclUnixUtil.obj
#UNIX_OBJS =

# To enable memory debugging reverse the comment characters on the following
# lines.  Warning:  if you enable memory debugging, you must do it
# *everywhere*, including all the code that calls Tcl, and you must use
# ckalloc and ckfree everywhere instead of malloc and free.
MEM_DEBUG_FLAGS =
#MEM_DEBUG_FLAGS = -DTCL_MEM_DEBUG

# Some versions of make, like SGI's, use the following variable to
# determine which shell to use for executing commands:
SHELL =		/bin/sh

#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

#COMPAT_OBJS =		@LIBOBJS@
COMPAT_OBJS =		opendir.obj
#AC_FLAGS =		@DEFS@
AC_FLAGS =		-DUSE_DIRENT2_H -DNO_SYS_TIME_H=1 -DNO_SYS_WAIT_H=1 -DNO_UNION_WAIT
INSTALL =		@INSTALL@
INSTALL_PROGRAM =	@INSTALL_PROGRAM@
INSTALL_DATA =		@INSTALL_DATA@
RANLIB =		@RANLIB@
#SRC_DIR =		@srcdir@
SRC_DIR =		.
VPATH =			@srcdir@

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------


CC =		icc
CC_SWITCHES =	$(CFLAGS) /I. /I$(SRC_DIR) /I\ibmcpp\include $(AC_FLAGS) $(MATH_FLAGS) \
$(GENERIC_FLAGS) $(PROTO_FLAGS) $(MEM_DEBUG_FLAGS) \
-DTCL_LIBRARY="\"$(TCL_LIBRARY_PATH)\""

GENERIC_OBJS =	regexp.obj tclAsync.obj tclBasic.obj tclCkalloc.obj \
	tclCmdAH.obj tclCmdIL.obj tclCmdMZ.obj tclExpr.obj tclGet.obj \
	tclHash.obj tclHistory.obj tclLink.obj tclParse.obj tclProc.obj \
	tclUtil.obj tclVar.obj

OBJS = $(GENERIC_OBJS) $(UNIX_OBJS) $(COMPAT_OBJS)

all: libtcl.lib tclsh.exe

libtcl.lib: $(OBJS)
	rm -f libtcl.lib
	lib libtcl $(OBJS);

tclsh.exe: tclAppInit.obj libtcl.lib
	$(CC) $(CC_SWITCHES) /Fetclsh tclAppInit.obj libtcl.lib $(MATH_LIBS)

tcltest: tclTest.obj libtcl.lib
	$(CC) $(CC_SWITCHES) /Fetcltest tclTest.obj libtcl.lib $(MATH_LIBS)

test: tcltest
	@cwd=`pwd`; \
	cd $(SRC_DIR); TCL_LIBRARY=`pwd`\library; export TCL_LIBRARY; \
	cd $$cwd; ( echo cd $(SRC_DIR)\tests\; source all ) | .\tcltest

install: install-binaries install-libraries install-man

install-binaries: libtcl.lib tclsh
	@for i in $(LIB_DIR) $(BIN_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@echo "Installing libtcl.lib"
	@$(INSTALL_DATA) libtcl.lib $(LIB_DIR)
	@$(RANLIB) $(LIB_DIR)\libtcl.lib
	@echo "Installing tclsh"
	@$(INSTALL_PROGRAM) tclsh $(BIN_DIR)

install-libraries:
	@for i in $(prefix)\lib $(INCLUDE_DIR) $(TCL_LIBRARY) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@echo "Installing tcl.h"
	@$(INSTALL_DATA) $(SRC_DIR)\tcl.h $(INCLUDE_DIR)
	@cd $(SRC_DIR)\library; for i in *.tcl tclIndex; \
	    do \
	    echo "Installing library\$$i"; \
	    $(INSTALL_DATA) $$i $(TCL_LIBRARY); \
	    done;

install-man:
	@for i in $(MAN_DIR) $(MAN1_DIR) $(MAN3_DIR) $(MANN_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@cd $(SRC_DIR)\doc; for i in *.1; \
	    do \
	    echo "Installing doc\$$i"; \
	    rm -f $(MAN1_DIR)\$$i; \
	    sed -e '\man\.macros/r man.macros' -e '\man\.macros/d' \
		    $$i > $(MAN1_DIR)\$$i; \
	    chmod 444 $(MAN1_DIR)\$$i; \
	    done;
	@cd $(SRC_DIR)\doc; for i in *.3; \
	    do \
	    echo "Installing doc\$$i"; \
	    rm -f $(MAN3_DIR)\$$i; \
	    sed -e '\man\.macros\r man.macros' -e '\man\.macros\d' \
		    $$i > $(MAN3_DIR)\$$i; \
	    chmod 444 $(MAN3_DIR)\$$i; \
	    done;
	@cd $(SRC_DIR)\doc; for i in *.n; \
	    do \
	    echo "Installing doc\$$i"; \
	    rm -f $(MANN_DIR)\$$i; \
	    sed -e '\man\.macros\r man.macros' -e '\man\.macros\d' \
		    $$i > $(MANN_DIR)\$$i; \
	    chmod 444 $(MANN_DIR)\$$i; \
	    done;

Makefile: $(SRC_DIR)\Makefile.in
	$(SHELL) config.status

clean:
	rm -f *.lib *.obj core errs *~ \#* TAGS *.E a.out errors tclsh.exe tcltest.exe

distclean: clean
	rm -f Makefile config.status

getcwd.obj: $(SRC_DIR)\compat\getcwd.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\getcwd.c

opendir.obj: $(SRC_DIR)\compat\opendir.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\opendir.c

strerror.obj: $(SRC_DIR)\compat\strerror.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\strerror.c

strstr.obj: $(SRC_DIR)\compat\strstr.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\strstr.c

strtod.obj: $(SRC_DIR)\compat\strtod.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\strtod.c

strtol.obj: $(SRC_DIR)\compat\strtol.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\strtol.c

strtoul.obj: $(SRC_DIR)\compat\strtoul.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\strtoul.c

tmpnam.obj: $(SRC_DIR)\compat\tmpnam.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\tmpnam.c

waitpid.obj: $(SRC_DIR)\compat\waitpid.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)\compat\waitpid.c

.c.obj:
	$(CC) -c $(CC_SWITCHES) $<

$(OBJS): $(SRC_DIR)\tcl.h $(SRC_DIR)\tclInt.h
$(UNIX_OBJS): $(SRC_DIR)\tclUnix.h
tclCmdIL.obj: $(SRC_DIR)\patchlevel.h
