# ---------------------------------------------------------------------------
#           [incr Tcl] - Object-oriented programming in Tcl
# ---------------------------------------------------------------------------
# This file is a Makefile for [incr 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.
# ---------------------------------------------------------------------------
ROOTNAME = @ROOTNAME@
VERSION  = @VERSION@
PACKAGE  = $(ROOTNAME)-$(VERSION)

# ---------------------------------------------------------------------------
# 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.)
# ---------------------------------------------------------------------------
# INSTALLATION DIRECTORIES
# ---------------------------------------------------------------------------

# Top-level directory in which to install architecture-specific files:
prefix = /usr/local
exec_prefix = $(prefix)

# Directory in which to install the archive libitcl.a:
LIB_DIR = $(exec_prefix)/lib

# Directory in which to install the include file itcl.h:
INCLUDE_DIR = $(exec_prefix)/include

# Directory in which to install the programs (itcl_wish and itcl_sh):
BIN_DIR = $(exec_prefix)/bin

# ---------------------------------------------------------------------------
# COMPILATION SOURCES/LIBRARIES
# ---------------------------------------------------------------------------

# Tcl source directory (must contain tclInt.h)
# (the configure script should find it; if not, edit below)
TCL_INC = -I@TCL_SRCDIR@

# Tk include directory
# (the configure script should find it; if not, edit below)
TK_INC = -I@TK_INCDIR@

# X11 include directory
# (the configure script should find it; if it is /usr/include,
# it will be commented out)
X11_INC =	@XINCLUDES@

# Tcl library
# (the configure script should find it; if not, edit below)
TCL_LIB = @TCL_LIBDIR@/libtcl.a

# Tk library
# (the configure script should find it; if not, edit below)
TK_LIB = @TK_LIBDIR@/libtk.a

# Linker switch(es) to use to link with the X11 library archive (the
# configure script will try to set this value automatically, but you
# can override it).
X11_LIB = @XLIBSW@

# Libraries to use when linking:  must include at least Tk, Tcl, Xlib,
# and the math library (in that order).  The "@LIBS@" part will be
# replaced (or has already been replaced) with relevant libraries as
# determined by the configure script.
LIBS = $(TK_LIB) $(TCL_LIB) $(X11_LIB) @LIBS@ -lm

# Composite list of include files
INCS = -I$(SRC_DIR) $(TCL_INC) $(TK_INC) $(X11_INC)

# To change the compiler switches, for example to change from -O
# to -g, change the following line:
CFLAGS = @CFLAGS@

# To turn off the security checks that disallow incoming sends when
# the X server appears to be insecure, reverse the comments on the
# following lines:
SECURITY_FLAGS =
#SECURITY_FLAGS = -DTK_NO_SECURITY

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

# 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.
# ---------------------------------------------------------------------------

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) $(INCS) $(AC_FLAGS) $(PROTO_FLAGS) \
	$(SECURITY_FLAGS) $(MEM_DEBUG_FLAGS)

SRCS = itcl_class.c itcl_core.c \
	itcl_methods.c itcl_objects.c itcl_vars.c \
	itcl_util.c

OBJS = itcl_class.o itcl_core.o \
	itcl_methods.o itcl_objects.o itcl_vars.o \
	itcl_util.o

SOBJS = itcl_class.so itcl_core.so \
	itcl_methods.so itcl_objects.so itcl_vars.so \
	itcl_util.so

all: @SHLIB@ libitcl.a itcl_wish itcl_sh

libitcl.a: $(OBJS)
	rm -f libitcl.a
	ar cr libitcl.a $(OBJS)
	$(RANLIB) libitcl.a

libitcl@SHLIB_SUFFIX@: $(SOBJS)
	rm -f libitcl@SHLIB_SUFFIX@
	@SHLIB_LOADER@ @SHLIB_LDFLAGS@ -o $@ $(SOBJS)

itcl_wish: tkAppInit.o libitcl.a
	$(CC) $(CC_SWITCHES) tkAppInit.o libitcl.a $(LIBS) -o itcl_wish

itcl_sh: tclAppInit.o libitcl.a
	$(CC) $(CC_SWITCHES) tclAppInit.o libitcl.a $(TCL_LIB) -lm -o itcl_sh

test: itcl_sh
	@( echo cd $(SRC_DIR)/../tests\; source all\; exit ) | ./itcl_sh

pure: tclAppInit.o tkAppInit.o libitcl.a
	purify $(CC) $(CC_SWITCHES) tclAppInit.o libitcl.a $(TCL_LIB) -lm \
		-o itcl_sh.pure
	purify $(CC) $(CC_SWITCHES) tkAppInit.o libitcl.a $(LIBS) \
		-o itcl_wish.pure

install: @SHLIB@ libitcl.a itcl_wish itcl_sh
	@for i in $(INCLUDE_DIR) $(LIB_DIR) $(BIN_DIR) ; do \
	    if [ ! -d $$i ] ; then \
			echo "Making directory $$i"; \
			mkdir $$i; \
			chmod 755 $$i; \
		else true; \
		fi; \
	done;
	@echo "Installing itcl.h"
	@$(INSTALL_DATA) itcl.h $(INCLUDE_DIR)
	@echo "Installing libitcl.a"
	@$(INSTALL_DATA) libitcl.a $(LIB_DIR)
	@$(RANLIB) $(LIB_DIR)/libitcl.a
	@if [ -n "@SHLIB@" ] ; then \
		echo "Installing @SHLIB@"; \
		$(INSTALL_DATA) @SHLIB@ $(LIB_DIR); \
	fi;
	@echo "Installing itcl_wish"
	@$(INSTALL_PROGRAM) itcl_wish $(BIN_DIR)
	@echo "Installing itcl_sh"
	@$(INSTALL_PROGRAM) itcl_sh $(BIN_DIR)

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

clean:
	rm -f *.o *.a *.so *.so.* core errs *~ \#* TAGS *.E a.out errors
	rm -f itcl_wish itcl_sh *pure*

distclean: clean
	rm -f Makefile config.status

lint:
	$(LINT) $(INCS) $(SRCS)

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

.SUFFIXES: .so $(SUFFIXES)
.c.so:
	$(CC) -c $(CC_SWITCHES) @SHLIB_CCFLAGS@ $<
	mv $*.o $@

$(OBJS): itcl_class.h itcl_core.h \
	itcl_methods.h itcl_objects.h itcl_vars.h \
	itcl_util.h
