# Makefile for "expecTerm" by Mark Weissman & Chris Matheus 1992
# Heavily based on Don Libes' Makefile for expect.
# Most of the comments are Don's.

VERSION = \"1.0beta\"

# Requires following version of Tcl (or later)
TCL = 6.2

# Tcl include files.  
# (If you haven't installed Tcl yet, read the README.expect file).
TCLHDIR = /usr/local/include
# Tcl library
TCLLIB = /usr/local/lib/libtcl.a

# Where to put man pages (for commands)
MAN1DIR = /usr/local/man/manl
# Extension to put on man pages (for commands)
MAN1EXT = l
# Where to put man pages (for libraries)
MAN3DIR = /usr/local/man/manl
# Extension to put on man pages (for libraries)
MAN3EXT = l

# Where to put final expecTerm binary
BINDIR = /usr/local/bin

# Where to put expecTerm library archive (can use expect's liib dir)
LIBDIR = /usr/local/lib/expect

# If want to set to ownership, modes, etc, to someone else upon installation,
# set the defn of CP to install or something similar.
CP = cp
# As above, but for ownership, modes, etc. of new directories.
MKDIR = mkdir
#
# Which C compiler to use.  
# Note: we use the System V compiler /usr/5bin/cc on Sun Sparcs.
#CC = gcc
CC = cc
#
# flags to pass to both cc and ld
# -O for production version
# -g for debuggable version
#
# 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.
# -DSVSV4 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.
# -DMIPS_BSD if you are on a Mips machine using the BSD universe.
# -DSIG_FN_RETURN=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.

CFLAGS = -g

#
# choose one of:
#	bsd - BSD
#	usg - USG (i.e., SIII through SVR3), SCO
#	unicos - Cray Unicos
#	sgi3 - Silicon Graphics, 3 or earlier
#	sgi - Silicon Graphics (using _getpty)
#	svr4 - SVR4
#	aix3 - recent versions of AIX (3.1.5 and later)

PTY_TYPE = bsd

#
# if you don't have ranlib, comment out the "RANLIB = ranlib" line and use
# the "RANLIB = echo" below.  If you don't know if you have ranlib, type
# "ranlib" at the shell and see if it finds the program or not.

RANLIB = ranlib

# RANLIB = echo
#
# If you are on a cray, comment out the "SETUID = echo" line and use the
# "SETUID = chmod s+o" below.  expecTerm 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 = echo

# SETUID = chmod u+s
#
# choose one of the following: select, poll, posix, or simple
INTERACT_TYPE = select
# If your system 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.
# See the beginning of that file (inter_poll.c) for more info.
# If that doesn't work, use simple.  This does not support
# multiple processes, but you will still find the result useful.
# posix is just a placeholder for future work.  Eventually, POSIX
# is supposed to provide a select/poll replacement, but they have not yet
# done so.  In the meantime, if you wish to cobble up something using
# the same idea as simple but supporting multiple processes AND
# 1003.1 compliant, send it to me.

# 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\"

# Flags to pass to ld (i.e., add to the end of the LIBS line below).
# On Sparcs use the system V libraries in /usr/5lib.
# -lcurses 	For Sun OS and AIX
# -lcursesX	For DEC Ultrix
# -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

LIBS = -L/usr/lib -lcurses $(TCLLIB) -lm

#####################################################
# Customizations and overrides for specific platforms
#####################################################
# For SUN OS 4.1
MACHINE_FLAGS = -D_SUN
INCLUDES = -I. -I$(TCLHDIR) -I/usr/5include
LIBS = -L/usr/5lib -lcurses $(TCLLIB) -lm
CC=/usr/5bin/cc
PTY_TYPE = bsd

# for IBM AIX 3.2
#MACHINE_FLAGS = -D_AIX -DNLS 
#INCLUDES = -I. -I$(TCLHDIR)  -I/usr/include
#LIBS = -L/usr/lib -lcurses $(TCLLIB) -lm
#PTY_TYPE = aix3

# for DEC ULTRIX
#MACHINE_FLAGS = -D_DEC
#INCLUDES = -I. -I$(TCLHDIR) -I/usr/include 
#LIBS = -L/usr/lib -lcursesX $(TCLLIB) -lm
#PTY_TYPE = bsd

#####################################################
#
# END OF THINGS YOU PROBABLY WANT TO CHANGE
#
#####################################################

CPPFLAGS = -DVERSION=$(VERSION) \
	-DPROGDIR=\"$(LIBDIR)\" \
	-DDFLT_STTY=$(STTY) \
	-DSCRIPTDIR=\"$(SCRIPTDIR)/\"
.c.o:
	$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $(MACHINE_FLAGS) -c $<



INTERACT = inter_$(INTERACT_TYPE)
PTY = pty_$(PTY_TYPE)
CFILES = main.c command.c expect.c $(PTY).c $(INTERACT).c unit_random.c \
	alarm.c termfuncs.c expTerm.c tinfo.c scrinfo.c switch.c
OFILES = main.o command.o expect.o $(PTY).o $(INTERACT).o unit_random.o \
	alarm.o termfuncs.o expTerm.o tinfo.o scrinfo.o switch.o
LIBCFILES = lib_exp.c lib_string.c $(PTY).c lib_debug.c
LIBOFILES = lib_exp.o lib_string.o $(PTY).o lib_debug.o

all: expecTerm

expecTerm: $(OFILES) 
	$(CC) $(CFLAGS) -o expecTerm $(OFILES) $(LIBS)
	$(SETUID) expecTerm
	# load -C $(CFLAGS) $(OFILES) $(LIBS)
	# link

saber:
	# setopt ccargs  $(CPPFLAGS)
	# setopt load_flags  $(CPPFLAGS)
	# unsetopt win_fork

install: expecTerm  
	$(CP) expecTerm $(BINDIR)
	$(CP) ExpectCap* $(LIBDIR)
	strip $(BINDIR)/expecTerm
	$(SETUID) $(BINDIR)/expecTerm
	$(CP) expect.man $(MAN1DIR)/expect.$(MAN1EXT)
	$(CP) expecTerm.man $(MAN1DIR)/expecTerm.$(MAN1EXT)

clean:
	-rm -f *.o core expecTerm *.lint *.glint dumb exho devtty *.a  *~ \#*

alarm.o: 	compat.h translate.h global.h 
command.o: 	translate.h global.h command.h expterm.h
expTerm.o: 	win.h compat.h translate.h global.h
expect.o: 	translate.h global.h command.h scrinfo.h
inter_poll.o: 	translate.h global.h command.h
inter_select.o: translate.h global.h command.h expterm.h
main.o: 	translate.h global.h command.h expterm.h
pty_aix3.o: 	global.h
pty_bsd.o: 	translate.h
pty_unicos.o: 	translate.h
pty_usg.o: 	translate.h
scrinfo.o: 	scrinfo.h command.h translate.h
termfuncs.o: 	win.h 
termfuncs.o: 	termfuncs.h
tinfo.o: 	compat.h win.h 
toc.o: 		win.h 
