# This Makefile will make a program file in the current directory
# and will call it 3270.

# When you are happy with any local tests of the program then
# remember to do a "make install" to get 3270 put into the correct
# place with the correct program name.


# Site-dependent information:

# installation information:
#       OWNER           - name (or uid) for the installed executable's owner
#       GROUP           - group name (or gid) for the installed executable's group
#       BINMODE         - mode for the installed executable
#       LDMODE          - mode for the libraries directory LIBDIR: files therein
#                         must be readable by users.
#       LFMODE          - mode for files in the libraries directory LIBDIR: these
#                         must be readable by users.
#       OPTMODE         - mode for the options directory OPTDIR: files therein
#                         must be writeable by users.
#       PRINTMODE       - mode for the printing directory PRINTDIR: files therein
#                         must be writeable by users.
#       BINDIR          - directory where the executable should live
#       MANDIR          - directory where the manual page should live
#       MANEXT          - extension character(s) for the man pages

OWNER           = root
GROUP           = bin
BINMODE         = 5755
LDMODE          = 0755
LFMODE          = 0644
PRINTMODE       = 0755
OPTMODE         = 0755
BINDIR          = /usr/local/bin
MANDIR          = /usr/local/man/manl
MANEXT          = l


# Place where libraries (news, help, mhelp etc.) go

LIBDIR = /usr/local/lib/3270
DLIB = -DLIBDIR=\"$(LIBDIR)/\"

# Place where the map3270 (keyboard mapping) file goes

PROFILE = /usr/local/lib/3270/map3270
DPRO = -DPROFILE=\"$(PROFILE)\"


# The next two are optional: the compiled code includes the necessary
# #ifdef checks on the symbols OPTDIR / LOGFILE
# If you do NOT want either option then comment out the setting of
# DOPT/DLOG and uncomment the dummy setting which follows it.

# The DIRECTORY in which to put files of different user's saved options.
# Note that the program must be able to write into this directory. This
# may require having it as world or group writeable or by making the
# program set user or group ID on execution.

OPTDIR = /usr/local/lib/3270/options
DOPT = -DOPTDIR=\"$(OPTDIR)/\"
#DOPT=

# The FILE in which to write a log file.

LOGFILE = /tmp/3270log
DLOG = -DLOGFILE=\"$(LOGFILE)\"
#DLOG=

# The DIRECTORY in which to put files of screen prints.
# Note that the program must be able to write into this directory. This
# may require having it as world or group writeable or by making the
# program set user or group ID on execution.
# If undefined then the current directory will be used.

#PRINTDIR = /usr/local/lib/3270/prints
#DPRINT = -DPRINTDIR=\"$(PRINTDIR)/\"
DPRINT=


# The program has a generic name (3270)
# and a version number (do not change these unless you are a guru!).
# In the "make install" the actual program will be saved in $(BINDIR)
# under the name $(PROG)v$(VERSION)
# and also, via a symbolic link, to the name $(PROG).
# whilst the man page will be saved according to the specs given above.

# Installed program name

PROG = 3270

# Program version number
VERSION = 3.6

# Choice of compiler (e.g. normal: cc , gnu: gcc , DEC C: c89 )
# plus basic options.

# apollo        The ansi version ( -A ansi ) seems to fail because of
#               the socket.h and associated header files, which don't
#               see the defined types for some reason!
#               The default seems to be bsd4.3, which requires a different
#               form of signal() call!

CC = gcc 

# Ultrix new DEC compiler
#CC = /usr/bin/c89 -O

# gcc
#CC = /usr/local/bin/gcc

# Generic workstation type
# (3b2, alpha, apollo, hpux, rs6000, sgi, solaris, sun, ultrix)

# Choose just one of these!

#SYSTEM_TYPE = 3b2
#SYSTEM_TYPE = alpha
#SYSTEM_TYPE = apollo
#SYSTEM_TYPE = hpux
#SYSTEM_TYPE = rs6000
SYSTEM_TYPE = sgi
#SYSTEM_TYPE = solaris
#SYSTEM_TYPE = sun
#SYSTEM_TYPE = ultrix

# Choice of special purpose or general purpose
# Special purpose means that you expect to run it on just the type of
# workstation mentioned above.
# General purpose means that users might be actually coming from different
# types of system: these might be other types of workstation with xterm,
# workstations or terminals with some terminal emulator or asynchronous
# terminals on terminal servers.
# I call this tagibm (terminal access gateway to IBM).

# The point of this choice is to select which 3270 file and which help
# files (specifically the xterm help file). If you select special purpose,
# which normally means setting the USER_TYPE the same as the SYSTEM_TYPE,
# then these files can be tailored to your workstation.
# If, on the other hand, you select general purpose then these files will
# be an attempt to be all things to all (wo)men. In other words, the
# keyboard help will NOT be able to show you a picture of your keyboard,
# whilst the map3270 keyboard mapping file might miss some "exotic" keys
# because of possible clashes with similar keys on different systems.

# Normally you want one of the following two lines: the xterm help file
# will then be xterm.USER_TYPE and the map3270 file map3270.USER_TYPE.
# You are, of course, free to alter these or even create new ones with
# a different USER_TYPE name.

USER_TYPE = $(SYSTEM_TYPE)
#USER_TYPE = tagibm


# Top level choice : For particular workstation type.

#       This will imply a default option for the Middle and Bottom level
#       choices unless overridden by those choices.
#       It is simply the inclusion of SYSTEM_TYPE as defined above.
#       I don't see why you would need to change it!


# Middle level choice : For different operating systems: (put in SFLAGS)

#       These will imply a default option for the Bottom level choices
#       unless overridden by those choices.


# -DBSD                 - Set if compiling for BSD (default)
# -DBSD43               - Set if compiling for BSD4.3 or beyond
# -DAIX                 - Set if compiling for AIX
# -DSYSV                - Set if compiling for Unix System V
# -DSVR4                - Set if compiling for Unix System V Release 4

# Choose at most one of these, and only if it is not the standard for!
# the specified SYSTEM_TYPE!

#SFLAGS = -DBSD
#SFLAGS = -DBSD43
#SFLAGS = -DAIX
SFLAGS = -DSYSV
#SFLAGS = -DSVR4


# Bottom level choice : options within a system: (put in OFLAGS)

# Terminal Interface (choose at most one: default is set according to
# operating system / system type as set above)

# -DUSE_NEWTTY          - Set if using the new BDS tty terminal interface (default)
# -DUSE_SYSV_TERMIO     - Set if using the SystemV termio terminal interface
# -DUSE_TERMIOS         - Set if using the POSIX termios terminal interface

# Miscellaneous.
# (I try to follow the X11 standard methods)

# -DNOT_POSIX           - Does not have the unistd.h include file
#                         with the proper prototypes for standard
#                         routines such as ttyname().
#                         (applies to the ultrix systems before 4.?)

# -DNOT_STDC_ENV        - Does not have the stdlib.h include file
#                         (applies to the ultrix systems before 4.?)

# -DANSI_ALL            - Force in some basic standard ANSI sequences
#                         regardless of the terminal type.

# -DANSI_VT             - Force in some basic standard ANSI sequences
#                         for any terminal whose name starts with "vt"
#                         (assuming that it is a DEC VTx00 terminal)

# -DANSI_XTERM          - Force in some basic standard ANSI sequences
#                         for any terminal whose name starts with "xterm"
#                         (assuming that it is an xterm of some kind)

# -DSIGNALRETURNSINT    - The signal() routine is the bsd4.3 style: it
#                         expects to call an integer function routine.

OFLAGS = -D_POSIX_SOURCE -DANSI_ALL


# Mode of operation/compilation flags: (put in MFLAGS)

# -DTTY         - Set if the program is serving several users on tty connections.
#                 This is especially important if the ttys are LAT devices.
#                 The code will include checking as to whether the tty is
#                 still ready for output (a LAT user might have switched to
#                 another session). There is also a check for idle users, who
#                 will be thrown off after a number of warnings.
#                 This flag also includes Kermit file transfer code.
#                 Clearly, a workstation user does not want this code.

# -DGRAPHICS    - Set this if you are going to connect to an IBM having
#                 special graphics drivers (not gddm) which allow programs
#                 to do graphics I/O on terminals which support Tektronix
#                 style graphics.

# -DIPAD_ONLY   - Set this if the program is only to be called with direct
#                 IP addresses. It does not then use gethostbyname which
#                 saves a LOT of space.

# -DNOSIZER     - Set this to suppress automatic screen sizing, i.e. if
#                 the termcap entry for the number of lines and columns
#                 is guaranteed always to be correct.

# -DUSE_STDIO   - Set this to use stdio, rather than opening new I/O files.
#                 We normally open these new files to avoid any problems
#                 with redirection.

# -DNO_SL_CLEAR - Set only if all ts (host-writeable status line) sequences
#                 refrain from blanking out the status line. This is highly
#                 recommended when using ASCII terminals on LAT lines.

# -DXTERM_SL    - Set only if the xterm to be used can have a host-writeable
#                 status line, to be manipulated as described in the termcap
#                 entry for xterm (the ds/es/fs/hs/ts entries). Beware: the
#                 fact that these are defined in termcap does NOT imply
#                 that the xterm handles them!

# -DDENSE       - Set only if you have the special IBM code that implements
#                 the possibility of a 132-column screen for the alternate
#                 display of an IBM Model 3278-2 (which is normally just a
#                 24*80 screen). This is implemented in CERN and is found
#                 very useful. However, it is possible to find VM application
#                 programs which choose to use the alternate screen, thinking
#                 that it is also 24*80, and which therefore go wrong on
#                 a 24*132 alternate screen.
#                 If in doubt leave this out!

# -DEXTENDED    - Set for use with extended data stream, which allows
#                 for extended highlighting and colours.
#                 The colours can be set by termcap sequences
#                 c0, c1, ... , c7 for the 8 IBM extended colours
#                 r0, r1, ... , r7 for the corresponding reverse video.
#                 These can be in the termcap if you want, but if you
#                 want them to be included anyway then just use the
#                 ANSI_VT, ANSI_XTERM or ANSI_ALL symbols mentioned above.
#                 They should work for a real VT340, a DECterm on a colour
#                 display or the colour version of xterm.
#                 Of course, I disclaim responsibility for what might
#                 happen on any other type of terminal or emulation.
#                 The extended highlighting (blinking, reverse video and
#                 underscoring) require the standard termcap entries
#                 for mb, mr (and me) and us (and ue).

# Only use extended if you know your host can handle it. Our OCS box apparently
# can't.
MFLAGS = -DTTY -DUSE_STDIO # -DEXTENDED


# Debugging options: (put in DFLAGS)
# -DDEBUG       - simple debugging (onto file /tmp/outf) showing 3270 dialogue
# -DLDEBUG      - logging of exact terminal I/O:
#                 This only takes place if the call has the -d option.
#                 If DEBUG is also set then it goes onto /tmp/outf
#                 If DEBUG is not set then it goes ontl /tmp/log
# -DFROMNET     - save all characters received from the network connection
# -DTONET       - save all characters sent to the network connection
# -DDUMPSCREEN  - Include code to dump IBM screen image
# -DSHOWFIELDS  - Include code to show field markers of IBM screen

# production version (for Ultrix workstation)

DFLAGS=


# Where to find any extra library.
# We often need the library for the old termcap routines (tgetent etc),
# which is normally termlib (but not on the RS6000!)
# This may change if we go to standard terminfo!

EXTRALIB = -lposix -lcurses

#Now put the whole lot together for the compilation flags.

CFLAGS=   -Dsys_$(SYSTEM_TYPE) $(SFLAGS) $(OFLAGS) $(MFLAGS) $(DFLAGS) $(DLOG) $(DLIB) $(DOPT) $(DPRO)

LINT = lint $(CFLAGS)

P3270 = telnet.o 3270.o curscr.o globals.o iomodule.o sizer.o statusline.o parse.o finddef.o initscr.o cr_tty.o

all: 3270 mset

3270: $(P3270)
	 $(CC) $(CFLAGS) -o 3270 $(P3270) $(EXTRALIB)

mset: mset.o finddef.o
	 $(CC) $(CFLAGS) -o mset mset.o finddef.o

install: $(BINDIR)/$(PROG) $(BINDIR)/mset \
	    $(LIBDIR)/helpfiles $(LIBDIR)/maphelp \
	    $(OPTDIR)/options \
	    $(PRINTDIR)/printer \
	    $(MANDIR)/manpage \
	    $(PROFILE)/map3270

$(BINDIR)/$(PROG): 3270
	   -chown $(OWNER) 3270
	   -chgrp $(GROUP) 3270
	   -chmod $(BINMODE) 3270
	   -mv $(BINDIR)/$(PROG)v$(VERSION) $(BINDIR)/$(PROG)v$(VERSION).old
	   mv 3270 $(BINDIR)/$(PROG)v$(VERSION)
	   -mv $(BINDIR)/$(PROG) $(BINDIR)/$(PROG).old
	   ln $(BINDIR)/$(PROG)v$(VERSION) $(BINDIR)/$(PROG)

$(BINDIR)/mset: mset
	   -chown $(OWNER) mset
	   -chgrp $(GROUP) mset
	   -chmod $(BINMODE) mset
	   -mv $(BINDIR)/mset $(BINDIR)/mset.old
	   mv mset $(BINDIR)

$(LIBDIR)/helpfiles:
	   -mkdir $(LIBDIR)
	   cp 3270_* $(LIBDIR)
	   -chown $(OWNER) $(LIBDIR)/3270_*
	   -chgrp $(GROUP) $(LIBDIR)/3270_*
	   -chmod $(LDMODE) $(LIBDIR)
	   -chmod $(LFMODE) $(LIBDIR)/3270_*

$(LIBDIR)/maphelp:
	   -mkdir $(LIBDIR)
	   cp keyboards/* $(LIBDIR)
	   -chown $(OWNER) $(LIBDIR)/*
	   -chgrp $(GROUP) $(LIBDIR)/*
	   -chmod $(LDMODE) $(LIBDIR)
	   -chmod $(LFMODE) $(LIBDIR)/*
	   -mv $(LIBDIR)/xterm $(LIBDIR)/xterm.old
	   -ln -s $(LIBDIR)/xterm-$(USER_TYPE) $(LIBDIR)/xterm

$(OPTDIR)/options:
	   -mkdir $(OPTDIR)
	   -chown $(OWNER) $(OPTDIR)
	   -chgrp $(GROUP) $(OPTDIR)
	   -chmod $(OPTMODE) $(OPTDIR)

$(PRINTDIR)/printer:
	   -mkdir $(PRINTDIR)
	   -chown $(OWNER) $(PRINTDIR)
	   -chgrp $(GROUP) $(PRINTDIR)
	   -chmod $(OPTMODE) $(PRINTDIR)

$(MANDIR)/manpage:
	   cp 3270.1 $(MANDIR)/$(PROG).$(MANEXT)
	   -chown $(OWNER) $(MANDIR)/$(PROG).$(MANEXT)
	   -chgrp $(GROUP) $(MANDIR)/$(PROG).$(MANEXT)
	   -chmod 0644 $(MANDIR)/$(PROG).$(MANEXT)

$(PROFILE)/map3270:
	   -mv $(PROFILE) $(PROFILE).old
	   cp map3270.$(USER_TYPE) $(PROFILE)
	   -chown $(OWNER) $(PROFILE)
	   -chgrp $(GROUP) $(PROFILE)
	   -chmod 0644 $(PROFILE)

lint: telnet.c 3270.c curscr.c globals.c iomodule.c sizer.c statusline.c parse.c finddef.c initscr.c cr_tty.c
	  $(LINT) telnet.c 3270.c curscr.c globals.c iomodule.c sizer.c statusline.c parse.c finddef.c initscr.c cr_tty.c $(EXTRALIB)

clean:
	    -/bin/rm -f *.o a.out core mset 3270

telnet.o: telnet.h globals.h 3270.h
3270.o: telnet.h globals.h 3270.h
curscr.o: telnet.h globals.h 3270.h
globals.o: globals.h
iomodule.o: telnet.h globals.h 3270.h
statusline.o: telnet.h globals.h 3270.h
sizer.o: globals.h
parse.o: globals.h 3270.h
initscr.o:
cr_tty.o:
