#
# 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 =	/usr/local
prefix =	/usr/local

# 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

# Directory in which to install the archive libtcl.a:
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 = -O

# 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.o tclEnv.o tclGlob.o tclMain.o tclUnixAZ.o \
	tclUnixStr.o tclUnixUtil.o
#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@
AC_FLAGS =		@DEFS@
INSTALL =		@INSTALL@
INSTALL_PROGRAM =	@INSTALL_PROGRAM@
INSTALL_DATA =		@INSTALL_DATA@
RANLIB =		@RANLIB@
SRC_DIR =		@srcdir@
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 =		@CC@
CC_SWITCHES =	${CFLAGS} -I. -I${SRC_DIR} ${AC_FLAGS} ${MATH_FLAGS} \
${GENERIC_FLAGS} ${PROTO_FLAGS} ${MEM_DEBUG_FLAGS} \
-DTCL_LIBRARY=\"${TCL_LIBRARY}\"

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

OBJS = ${GENERIC_OBJS} ${UNIX_OBJS} ${COMPAT_OBJS}

all: libtcl.a tclsh

libtcl.a: ${OBJS}
	rm -f libtcl.a
	ar cr libtcl.a ${OBJS}
	$(RANLIB) libtcl.a

tclsh: tclAppInit.o libtcl.a
	${CC} ${CC_SWITCHES} tclAppInit.o libtcl.a ${MATH_LIBS} -o tclsh

tcltest: tclTest.o libtcl.a
	${CC} ${CC_SWITCHES} tclTest.o libtcl.a ${MATH_LIBS} -o tcltest

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.a 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.a"
	@$(INSTALL_DATA) libtcl.a $(LIB_DIR)
	@$(RANLIB) $(LIB_DIR)/libtcl.a
	@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 *.a *.o core errs *~ \#* TAGS *.E a.out errors tclsh tcltest

distclean: clean
	rm -f Makefile config.status

getcwd.o: $(SRC_DIR)/compat/getcwd.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/getcwd.c

opendir.o: $(SRC_DIR)/compat/opendir.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/opendir.c

strerror.o: $(SRC_DIR)/compat/strerror.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/strerror.c

strstr.o: $(SRC_DIR)/compat/strstr.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/strstr.c

strtod.o: $(SRC_DIR)/compat/strtod.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/strtod.c

strtol.o: $(SRC_DIR)/compat/strtol.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/strtol.c

strtoul.o: $(SRC_DIR)/compat/strtoul.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/strtoul.c

tmpnam.o: $(SRC_DIR)/compat/tmpnam.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/tmpnam.c

waitpid.o: $(SRC_DIR)/compat/waitpid.c
	$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/compat/waitpid.c

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

${OBJS}: $(SRC_DIR)/tcl.h $(SRC_DIR)/tclInt.h
${UNIX_OBJS}: $(SRC_DIR)/tclUnix.h
tclCmdIL.o: $(SRC_DIR)/patchlevel.h
