#
# Makefile for Expect
#

VERSION = \"4.5.1\"
SHORT_VERSION = 4.5
# Requires following version of Tcl or later
TCL = 6.5
# Tk optional
TK = 3.0

srcdir 	= @srcdir@
VPATH = @srcdir@

######################################################################
# The following lines are things you are likely to want to change
######################################################################

# Tcl include files.  (If you haven't installed Tcl yet, read the README file).
# This must point to the directory that contains ALL of Tcl's include
# files, not just the public ones.
TCLHDIR = $(srcdir)/../tcl
# Tcl library
TCLLIB = ../tcl/libtcl.a

# The following three defs are only nec. if you want to use Tk with Expect.
# Tk include files
TKHDIR = $(srcdir)/../tk
# Tk library
TKLIB = ../tk/libtk.a
# X11 include files
X11HDIR = $(srcdir)/../X11

# flags to pass to both cc and ld
# -O for production version
# -g for debuggable version
CFLAGS = -g

# which C compiler to use
CC = cc

# By default, `make install' will install the appropriate files in
# /mit/sipb/bin, /mit/sipb/lib, /mit/sipb/man, etc.  You can specify
# an installation prefix other than /mit/sipb here:
prefix = /mit/sipb

# You can specify a separate installation prefix for architecture-specific
# files such as binaries and libraries.
exec_prefix = $(prefix)

# The following Expect scripts are not necessary to have installed as
# commands, but are very useful.  Edit out what you don't want installed.
# The INSTALL file describes these and others in more detail.
# Some Make's screw up if you delete all of them because SCRIPTS is a
# target.  If this is a problem, just comment out the SCRIPTS target itself.
SCRIPTS = timed-run timed-read ftp-rfc autopasswd robohunt lpunlock weather \
	passmass rftp kibitz rlogin-cwd xpstat
# A couple (well, one for now) of the scripts have man pages of their own.
# You can delete these too, if you don't want'em.
SCRIPTS_MANPAGES = kibitz

# Short directory path where expect binary can be found to support #! hack.
# This directory path can be the same as the directory in which the binary
# actually sits except when the path is so long that the #! mechanism breaks
# (usually at 32 characters).
# The solution is to create a directory with a very short name, which consists
# only of symbolic links back to the true binaries.  Subtracting two for "#!"
# and a couple more for arguments (typically " -f" or " --") gives you 27
# characters.  Pathnames over this length won't be able to use the #! magic.
# For more info on this, see the execve(2) man page.
SHORT_BINDIR = /mit/sipb/bin

# If you have select but it doesn't support ttys and your poll does,
# change this from select to poll.  Known systems with this problem: older
# SCO boxes.
PTY_TYPE = @PTY_TYPE@

# If you have ranlib but it should be avoided, change this from "ranlib" #
# to something innocuous like "echo".  Known systems with this problem:
# older SCO boxes.
RANLIB = @RANLIB@

######################################################################
# End of things you are likely to want to change
######################################################################

bindir 	= $(exec_prefix)/bin
bindir_arch_indep = $(prefix)/bin
libdir 	= $(exec_prefix)/lib/@sys
tooldir = $(libdir)
datadir = $(prefix)/lib

mandir 	= $(prefix)/man
man1dir = $(mandir)/man1
man3dir = $(mandir)/man3
infodir = $(prefix)/info
includedir = $(prefix)/include
oldincludedir =
docdir = $(datadir)/doc

SHELL = /bin/sh

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@

AR = ar
ARFLAGS = cr

# X library
X11_LIB_FLAGS=
X11_LIB = -lX11

# If you are on a cray, comment out the "SETUID = echo" line and use the
# "SETUID = chmod s+o" below.  expect must be setuid on crays in order to
# open ptys (and accordingly, you must run this Makefile as root).
# See the FAQ for more info on why this is necessary on Crays.
SETUID = @SETUID@
# SETUID = chmod u+s
#
# choose one of the following: select, poll, posix, or simple
EVENT_TYPE = @EVENT_TYPE@
# If your system (Sun, recent HP, Ultrix, etc) has select(2) use select
# Note that many SV machines support select.  Starting with SVR4, all will.
# If your machine supports poll(2) but not select, use poll.
# If that doesn't work, use simple.  This does not support
# multiple processes, but you will still find the result useful.
# Some machines (e.g., 3b2 running SVR3) have poll, but do not
# support it for ttys.  In this case, you must also use simple.
# Eventually, POSIX is supposed to provide a select/poll replacement,
# but they have not yet done so.
# Some machines (e.g., SCO) have select, but do not support it for ttys.
# In this case, use poll or simple.  Note that such machines will not
# be able to use Expect with Tk since Tk's event manager insists on
# reading all events through select.
SCRIPTDIR	= $(datadir)/expect

# Define default parameters for ptys.  This is used when 1) running in the
# background, 2) user has not defined the variable STTY_INIT to initialize
# ptys, and 3) the pty-driver's defaults suck.
# Use whatever format your local stty program likes.  
STTY=\"sane\"

CPPFLAGS =	-I. -I$(srcdir) -I$(TCLHDIR) -I$(TKHDIR) -I$(X11HDIR) \
		-DVERSION=$(VERSION) \
		-DDFLT_STTY=$(STTY) \
		-DSCRIPTDIR=\"$(SCRIPTDIR)/\"

#
# Flags to pass to cc (i.e. add to the end of the CFLAGS line below).
# Note that setting one will not set others automatically.  Set all that
# are relevant.
# 
# -DPOSIX if you are have POSIX tty support.  (Currently only tested on AIX
#	3.x).  
# -DNOWAITPID if your system doesn't have waitpid.  Only really old systems
#	lack this.
# -DNO_PID_T if your system doesn't have a typedef for pid_t.  If you don't
#	know, try without defining it.  If it compiles, you're ok.
# -DNO_MEMCPY if your system does not have memcpy.  If you don't know, try
#	without defining it.  If it compiles, you're ok.
# -DNO_STRING_H if your system does not have /usr/include/string.h.  If you
#	don't know, try without defining it.  If it compiles, you're ok.
# -DSYSV3 if you are running SVR3 or later.
# -DSYSV4 if you are running SVR4.  This option does not preclude -DSYSV3.
# -DHPUX if you are running HP-UX.
# -DCRAY=51 or 60, 70, etc, if you are running Cray Unicos 5.1, 6.0, 7.0, etc.
# -DAUX2 if you are running Mac A/UX 2.
# -DUTS if you are on an Amdahl.
# -DSCO if you are running SCO Unix.
# -DMIPS_BSD if you are on a Mips machine using the BSD universe.
# -DRETSIGTYPE=int if you are running SunOS-3.X or similar systems that
#	define the function argument to signal as int (*func)() rather than
#	void (*func)().
# -DREARM_SIG if you are running systems (such as V7, SV, Unicos) where signal
#	handlers need to be rearmed after use.
# -D_BSD_SIGNALS if you are on a Silicon Graphics AND want BSD semantics when
#	using the expect library.  Otherwise, you are better off just sticking
#	with defining REARM_SIG (above).
# -DEXTERN_ERRNO if your system needs "extern int errno" (e.g., MORE/bsd).
# -DTERM=whatever if your system is unhappy with the default terminal struct
#	name (termios for SV, and sgttyb for BSD).  Some SV systems (3b2 &
#	pre-8.0 HPUX) want "termio".
# -DNOSTDLIB if your system doesn't have /usr/include/stdlib.h.  If you don't
#	know, try without.  If you get bad declarations on malloc, then add.

# Flags to pass to ld (i.e., add to the end of the LIBS line below).
#
# -lc -lBSD     If you are using the BSD compatibility library on an HP/UX,
#		force libc.a to be loaded first.
# -lsocket	For SCO UNIX 3.2.2
#  /usr/ucblib/libucb.a is needed for solaris 2.0 after -lm
LIBS = -lm

######################################################################
# End of things you probably dont want to change
######################################################################

# If your "make" automatically includes CPPFLAGS in CC, use
#CFLAGS = $(CLFLAGS)
# else use following two lines 
# use these flags on an HP700 running hp-ux
#CFLAGS = $(CLFLAGS) $(CPPFLAGS) -DHPUX -DSYSV3 -DREARM_SIG
CFLAGS_INT = $(MH_CFLAGS) $(CPPFLAGS) $(CFLAGS)

.c.o:
	$(CC) -c $(CFLAGS_INT) $(HDEFS) $<

EVENT = exp_$(EVENT_TYPE)
PTY = pty_$(PTY_TYPE)
CFILES = $(srcdir)/exp_command.c $(srcdir)/expect.c $(srcdir)/$(PTY).c \
	$(srcdir)/exp_inter.c $(srcdir)/exp_regexp.c $(srcdir)/exp_tty.c \
	$(srcdir)/exp_log.c $(srcdir)/exp_main_sub.c $(srcdir)/exp_pty.c \
	$(srcdir)/vprintf.c
OFILES = exp_command.o expect.o $(PTY).o exp_inter.o exp_regexp.o exp_tty.o \
	exp_log.o exp_main_sub.o exp_pty.o vprintf.o
LIBCFILES = $(srcdir)/lib_exp.c $(srcdir)/lib_string.c $(srcdir)/$(PTY).c \
	$(srcdir)/lib_debug.c $(srcdir)/exp_pty.c $(srcdir)/vprintf.c
LIBOFILES = lib_exp.o lib_string.o $(PTY).o lib_debug.o exp_pty.o vprintf.o
LIBEXPECT = libexpect.a
LIBEXPTCL = libexptcl.a
LIBEXPTK  = libexptk.a

#all: expect expectk $(LIBEXPECT) $(LIBEXPTCL) $(LIBEXPTK)
all: expect $(LIBEXPECT) $(LIBEXPTCL)

info:
dvi:

expect:	$(OFILES) exp_main_exp.o $(EVENT).o
	$(CC) $(CFLAGS) -o expect $(OFILES) exp_main_exp.o $(EVENT).o $(LIBS) $(TCLLIB)
	$(SETUID) expect

expectk:        $(OFILES) exp_main_tk.o exp_tk.o
	$(CC) $(CLFLAGS) -o expectk $(OFILES) exp_main_tk.o exp_tk.o $(TKLIB) $(TCLLIB) $(X11_LIB_FLAGS) $(X11_LIB) $(LIBS) 
	$(SETUID) expectk

Makefile : $(srcdir)/Makefile.in $(host_makefile_frag)
	$(SHELL) config.status

$(LIBEXPECT): $(LIBOFILES)
	$(AR) $(ARFLAGS) $(LIBEXPECT) $(LIBOFILES)
	-$(RANLIB) $(LIBEXPECT)

$(LIBEXPTCL): $(OFILES) $(EVENT).o
	$(AR) $(ARFLAGS) $(LIBEXPTCL) $(OFILES) $(EVENT).o
	-$(RANLIB) $(LIBEXPTCL)

$(LIBEXPTK): $(OFILES) exp_tk.o
	$(AR) $(ARFLAGS) $(LIBEXPTK) $(OFILES) exp_tk.o
	-$(RANLIB) $(LIBEXPTK)

install-info:
install:	expect $(LIBEXPECT) $(SCRIPTS)
# install Expect
	-parent=`echo $(bindir)|sed -e 's@/[^/]*$$@@'`; \
	if [ -d $$parent ] ; then true ; else mkdir $$parent ; fi
	-if [ -d $(bindir) ] ; then true ; else mkdir $(bindir) ; fi
	$(INSTALL_PROGRAM) -s expect $(bindir)
# install Expect man page
	-parent=`echo $(man1dir)|sed -e 's@/[^/]*$$@@'`; \
	if [ -d $$parent ] ; then true ; else mkdir $$parent ; fi
	-if [ -d $(man1dir) ] ; then true ; else mkdir $(man1dir) ; fi
	$(INSTALL_DATA) $(srcdir)/expect.man $(man1dir)/expect.1
# install Expect library
	-parent=`echo $(libdir)|sed -e 's@/[^/]*$$@@'`; \
	if [ -d $$parent ] ; then true ; else mkdir $$parent ; fi
	-if [ -d $(libdir) ] ; then true ; else mkdir $(libdir) ; fi
	$(INSTALL_DATA) libexpect.a $(libdir)/libexpect.a.n
	-$(RANLIB) $(libdir)/libexpect.a.n
	mv -f $(libdir)/libexpect.a.n $(libdir)/libexpect.a
# install Expect library man page
	-parent=`echo $(man3dir)|sed -e 's@/[^/]*$$@@'`; \
	if [ -d $$parent ] ; then true ; else mkdir $$parent ; fi
	-if [ -d $(man3dir) ] ; then true ; else mkdir $(man3dir) ; fi
	$(INSTALL_DATA) $(srcdir)/libexpect.man $(man3dir)/libexpect.3
# install Expect library include file
	-parent=`echo $(includedir)|sed -e 's@/[^/]*$$@@'`; \
	if [ -d $$parent ] ; then true ; else mkdir $$parent ; fi
	-if [ -d $(includedir) ] ; then true ; else mkdir $(includedir) ; fi
	$(INSTALL_DATA) $(srcdir)/expect.h $(includedir)
# ditto but for Expect-Tcl library if present
	-if [ -s $(LIBEXPTCL) ] ; then \
		$(INSTALL_DATA) $(LIBEXPTCL) $(libdir)/$(LIBEXPTCL).n ; \
		$(RANLIB) $(libdir)/$(LIBEXPTCL).n 2>>/dev/null ; \
		mv -f $(libdir)/$(LIBEXPTCL).n $(libdir)/$(LIBEXPTCL) ; \
		$(INSTALL_DATA) $(srcdir)/libexptcl.man $(man3dir)/libexptcl.3 ; \
	fi
# ditto but for Expectk
	-if [ -x expectk ] ; then \
		$(INSTALL_PROGRAM) expectk $(bindir) ; \
	fi
# ditto but for Expect-Tk library if present
	-if [ -s $(LIBEXPTK) ] ; then \
		$(INSTALL_DATA) $(LIBEXPTK) $(libdir)/$(LIBEXPTK).n ; \
		$(RANLIB) $(libdir)/$(LIBEXPTK).n 2>>/dev/null ; \
		mv -f $(libdir)/$(LIBEXPTK).n $(libdir)/$(LIBEXPTK) ; \
		$(INSTALL_DATA) $(srcdir)/libexptk.man $(man3dir)/libexptk.3 ; \
	fi
# create utility-script directory
	-parent=`echo $(SCRIPTDIR)|sed -e 's@/[^/]*$$@@'`; \
	if [ -d $$parent ] ; then true ; else mkdir $$parent ; fi
	-if [ -d $(SCRIPTDIR) ] ; then true ; else mkdir $(SCRIPTDIR) ; fi
# install standalone scripts and their man pages, if requested
	-if [ -n "$(SCRIPTS)" ] ; then \
		for i in $(SCRIPTS) ; do \
		  $(INSTALL_PROGRAM) $$i $(bindir_arch_indep) ; \
		  chmod a+x $(bindir_arch_indep)/$$i ; \
		  rm $$i; \
		done ; \
	fi
	-if [ -n "$(SCRIPTS_MANPAGES)" ]; then \
		for file in "$(SCRIPTS_MANPAGES)" ; do \
			$(INSTALL_DATA) example/$$file.man $(man1dir)/$$file.1 ; \
		done \
	fi

$(SCRIPTS):
	./expect fixline1 $(SHORT_BINDIR) < example/$@ > $@

clean:
	-rm -f *~ *.o core expect expectk dumb exho devtty *.a

distclean: clean
	-rm -f Makefile config.status exp_conf.h

configure: configure.in
	autoconf configure.in > configure

LINTFLAGS = -h -q -x 

lint:
	lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) $(TCLLINTLIB) | tee expect.lint
	lint $(LINTFLAGS) $(CPPFLAGS) $(LIBCFILES) | tee libexpect.lint

# Following target builds expect under CodeCenter.
exp:	$(CFILES) exp_main_exp.c $(EVENT).c
	#load $(CPPFLAGS) $(CFILES) exp_main_exp.c $(EVENT).c $(TCLLIB) $(LIBS)

# Following target builds expectk under CodeCenter.  Notes:
# Because of explicit #includes of <X11/...> in tk.h, you need to create
# a symlink from your X11 include directory to this directory
tk:     $(CFILES) exp_main_tk.c exp_tk.c
	#load $(CPPFLAGS) $(CFILES) exp_main_tk.c exp_tk.c $(TKLIB) $(TCLLIB) $(X11_LIB) $(LIBS)

# Follow definitions are for building expect and expectk under ObjectCenter
oexp:   $(CFILES) exp_main_exp.c $(EVENT).c
	#load $(CPPFLAGS) -C $(CFILES) exp_main_exp.c $(EVENT).c $(TCLLIB)

otk:    $(CFILES) exp_main_tk.c exp_tk.c
	#load $(CPPFLAGS) -C $(CFILES) exp_main_tk.c exp_tk.c $(TKLIB)

FTPDIR = /proj/elib/online/pub/expect

ftp:	expect-$(SHORT_VERSION).tar.Z
	cp expect-$(SHORT_VERSION).tar.Z $(FTPDIR)/alpha.tar.Z
	cp HISTORY $(FTPDIR)
	rm expect-$(SHORT_VERSION).tar.Z
	ls -l $(FTPDIR)/alpha.tar.Z

expect-$(SHORT_VERSION).tar:
	rm -f ../expect-$(SHORT_VERSION)
	ln -s `pwd` ../expect-$(SHORT_VERSION)
	rm -f ../pubfile
	ln pubfile ..
	cd ..;tar cvf expect-$(SHORT_VERSION).tar `pubfile expect-$(SHORT_VERSION)`
	mv ../expect-$(SHORT_VERSION).tar .

expect-$(SHORT_VERSION).tar.Z:	expect-$(SHORT_VERSION).tar
	rm -f expect-$(SHORT_VERSION).tar.Z
	compress expect-$(SHORT_VERSION).tar

expect.o:	$(srcdir)/exp_global.h $(srcdir)/exp_command.h exp_conf.h
exp_main_exp.o:	$(srcdir)/exp_global.h exp_conf.h
exp_command.o:	$(srcdir)/exp_global.h $(srcdir)/exp_command.h exp_conf.h
$(EVENT).o:	$(srcdir)/exp_global.h $(srcdir)/exp_command.h exp_conf.h
$(PTY).o:	$(srcdir)/exp_tty.h $(srcdir)/exp_rename.h exp_conf.h
