Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Last active April 15, 2023 15:37
Show Gist options
  • Save tvlooy/b7bccfa6b07bf6873bc47e2b778de3a0 to your computer and use it in GitHub Desktop.
Save tvlooy/b7bccfa6b07bf6873bc47e2b778de3a0 to your computer and use it in GitHub Desktop.
ckermit ubuntu 20.04

apt-get install libpam0g-dev

download http://www.columbia.edu/kermit/ck90.html

replace 2 changed files

make linux

makefile

# makefile / Makefile / ckuker.mak / CKUKER.MAK
#
# Sun Aug 21 10:33:08 2011
BUILDID=20110821
CKVER= "9.0.302"
#
# -- Makefile to build C-Kermit for UNIX and UNIX-like platforms --
#
# Copyright (C) 1985, 2011,
#   Trustees of Columbia University in the City of New York.
#   All rights reserved.  See the C-Kermit COPYING.TXT file or the
#   copyright text in the ckcmai.c module for disclaimer and permissions.
#   In case you can't find the COPYING.TXT file, it contains the 
#   Simplified 3-Clause BSD License, which is an Open Source license.
#
# Author: Frank da Cruz, Columbia University
# 612 West 115th Street, New York NY 10025-7799, USA
# Email: [email protected]
# Web:   http://kermit.columbia.edu/
# FTP:   ftp://kermit.columbia.edu/kermit/
#
# Note: Author is no longer at Columbia University or at the 115th Street
# address effective 1 July 2011.  The email address should still work,
# as well as the website and FTP addresses, for the foreseeable future.
# For new developments, also check:
#
#    http://www.columbia.edu/~fdc/kermit/
#
# Contributions from many others.  Special thanks to Jeff Altman for the
# secure-build targets, Peter Eichhorn, assyst GmbH, for the consolidated
# HP-UX targets and the "uninstall" target, to Robert Lipe for the updated
# and consolidated SCO UNIX / ODT / OSR5 targets, to Ric Anderson for the
# IRIX 6.x targets, to Seth Theriault for major improvements to the
# Mac OS X targets, and to Alexey Dokuchaev for FreeBSD 9.0.
#
# C-Kermit is written and produced by hand without any automated procedures
# such as autoconf / automake / configure, although some of the targets below
# (especially the linux target) inspect the environment and make some
# decisions in the most portable way possible. The automated tools are not
# used because (a) C-Kermit predates them, and (b) they are not portable to
# all the platforms where C-Kermit must be (or once was) built, and (c) to
# keep C-Kermit as independent as possible from external tools over which
# we have no control.
#
# Most entries use the "xermit" target, which uses the select()-based CONNECT
# module, ckucns.c.  The "wermit" target uses the original fork()-based CONNECT
# module, ckucon.c, which has some drawbacks but was portable to every Unix
# variant whether it had TCP/IP or not (select() is part of the TCP/IP
# library, which was not standard on older Unixes).  If your target still uses
# the "wermit" target, please try substituting the "xermit" one and if it
# works, let us know (mailto:[email protected]).  When changing a
# target over from wermit to xermit, also remove -DNOLOEARN.
#
# CAREFUL: Don't put the lowercase word "if", "define", or "end" as the first
# word after the "#" comment introducer in the makefile, even if it is
# separated by whitespace.  Some versions of "make" understand these as
# directives.  Uppercase letters remove the danger, e.g. "# If you have..."
# 
# WARNING: This is a huge makefile.  Although this is less likely since the
# turn of the century, some "make" programs might run out of memory.  If this
# happens to you, edit away the parts that do not apply to your platform and
# try again.
#
# WARNING 2: In many cases this file invokes itself recursively, sometimes
# several levels deep (as in the Linux targets); i.e. some targets are used
# as 'subroutines' of other targets, with parameters passed by setting
# environment variables.  For that reason, don't use 'make -e'.
#
# Certain UNIX variations have their own separate makefiles:
#  . For 2.10 or 2.11 BSD on the DEC PDP-11, use ckubs2.mak.
#  . For Plan 9, use ckpker.mk.
#
# Separate build procedures are provided non-UNIX platforms: VMS, VOS,
# AOS/VS, etc.  See the ckaaaa.txt file or the Kermit website for details.
#
#
# DIRECTIONS FOR UNIX
#
# Rename this file to "makefile" or "Makefile" if necessary.  Pick out the
# entry most appropriate for your UNIX version from the list below and then
# give the appropriate "make" command, for example "make aix", "make macosx",
# "make linux".  If you experience any difficulties with the build procedure,
# then please also read any comments that accompany the make entry itself
# (search for the make entry name on the left margin).
#
# Other targets:
#  'make install' is an installation script (read accompanying comments!).
#  'make uninstall' undoes 'make install' (read accompanying comments!).
#  'make clean' removes intermediate and object files.
#  'make show' tells the default include and lib paths for secure builds.
#
# IMPORTANT:
#   For more detailed installation instructions, read the files ckuins.txt
#   and ckccfg.txt, also available at the Kermit website in HTML form:
#   http://www.columbia.edu/kermit/ckuins.html
#   http://www.columbia.edu/kermit/ckccfg.html
#
#  For descriptions of known problems and limitations,
#   read the files ckcbwr.txt and ckubwr.txt (the "beware files") or:
#   http://www.columbia.edu/kermit/ckcbwr.html
#   http://www.columbia.edu/kermit/ckubwr.html
#
# Most targets build C-Kermit with its symbol table included.  To reduce the
# size of the executable program, add "LNKFLAGS=-s" to the end of your 'make'
# command or to the makefile entry, or 'strip' the executable after
# building.  To further reduce the size after building, use 'mcs -d' if your
# Unix version has such a command.  For further details on size reduction, read
# ckccfg.txt to find out how to remove features that you don't need.
#
# TCP/IP networking support: If your C-Kermit version does not include TCP/IP
# networking, but your UNIX system does, try adding -DTCPSOCKET to the CFLAGS
# of your makefile entry.  If that doesn't work, look at some of the other
# targets that include this flag for ideas about what libraries might need to
# be included (typically -lsocket and/or -lBSD and/or -lnsl and/or -linet).
# NOTE: In some cases (old versions of SCO or HP-UX), you might need not only
# a C compiler, but also a "TCP/IP developers kit" for the required object
# libraries and header files.
#
# Please report modifications, failures (preferably with fixes) or successes
# to the author, [email protected].
#
# TARGETS FOR DIFFERENT UNIX PLATFORMS AND VERSIONS:
#
# + Marks those that have been built successfully for C-Kermit 9.0 or later.
# - Those that once built OK but no longer do (e.g. too big).
# ? Those that worked in a previous version but have not been tested recently.
# --------------------------
# Some commonly used targets:
#
# + "make linux" should work for any version of Linux on any hardware.
# + "make linux+ssl" ditto, with OpenSSL security added.
# + "make linux+krb5" ditto, with Kerberos 5 security added.
# + "make linux+krb5+ssl" Linux with OpenSSL and Kerberos 5.
# + "make netbsd", NetBSD, any version.
# + "make netbsd+ssl", NetBSD with OpenSSL 0.9.7 or later.
# + "make netbsd+krb5", NetBSD with Kerberos 5.
# + "make netbsd+krb5+ssl", NetBSD with Kerberos 5 and OpenSSL 0.9.7 or later.
# ? "make freebsd1" for FreeBSD 1.x
# ? "make freebsd2" for FreeBSD 2.x
# + "make freebsd3" for FreeBSD 3.x
# ? "make freebsd4" for FreeBSD 4.0
# + "make freebsd", FreeBSD 4.1 or later.
# + "make freebsd+ssl", FreeBSD 5.0 or later with OpenSSL 0.9.7 or later.
# + "make openbsd", OpenBSD 2.3 or later.
# + "make openbsd+ssl", OpenBSD 2.3 or later with OpenSSL 0.9.7 or later.
# + "make mirbsd", MirBSD.
# + "make mirbsd+ssl", MirBSD with OpenSSL 0.9.7 or later.
# + "make macosx" should work for any Mac OS X version 10.3.9 or later.
# + "make macosx+krb5+openssl" Mac OS X 10.3.9 or later + Kerberos V + OpenSSL.
# + "make aix" should work for any version of AIX 4.2 or later.
# + "make aixg" should work for any version of AIX 4.2 or later, using gcc.
# + "make aix+ssl" ditto, with OpenSSL (specifying SSLLIB and SSLINC)
# + "make aix+ibmssl" ditto, with IBM OpenSSL
# + "make solaris9", "make solaris10" for Solaris 9 or 10 with Sun cc.
# + "make solaris9g", "make solaris10g" for Solaris 9 or 10 with gcc.
# + "make solaris11" for Solaris 11 with Sun CC
# + "make solaris11g" for Solaris 11 with gcc
# + "make sco_osr600" for SCO OpenServer 6.0.0.
#
# For other current OSs such as Solaris, HP-UX, and SCO there are separate
# targets for different combinations of OS version and compiler; see the
# complete list.  For older OS's see the complete list.  If an old target
# doesn't work in this release of C-Kermit you can get a previous release from
# the Kermit FTP site: ftp://kermit.columbia.edu/kermit/
#
# SECURE TARGETS (versions that support authentication and encryption)
#  are described after the following list.  Search for ******* below.
#
# --------------------------
# Complete list (alphabetical):
# ? for 386BSD (Jolix) 0.0, 0.1, "make 386bsd" (see comments in entry),
#     or (preferably, if it works) "make bsd44" or "make bsd44c".
# ? for Acorn RISCiX, "make riscix" or "make riscix-gcc"
# ? for Alliant FX/8 with Concentrix 4.1 or later, "make bsdlck"
# ? for Altos 486, 586, 986 with Xenix 3.0, "make altos"
# ? for Altos ACS68000, 8Mhz 68000, UNIX System 3 Rel 2, 512K, "make altos3"
# ? for Amdahl UTS 2.4 on IBM 370 series & compatible mainframes, "make uts24"
# ? for Amdahl UTSV IBM 370 series & compatible mainframes, "make utsv"
# ? for Amdahl UTSV IBM 370 series mainframes with TCP/IP, "make utsvtcp"
# ? for Amdahl mainframes with UNIX System V R 5.2.6b 580, "make sys3"
# ? for Apollo Aegis 9.x, DOMAIN/IX 9.x, "make aegis"
#    (Last tested in C-Kermit 5A(189))
# ? for Apollo DOMAIN/IX, if the above fails, try "make apollobsd"
# ? for Apollo with SR10.0 or later, BSD environment, "make sr10-bsd"
# ? for Apollo with SR10.0 or later, System V environment, "make sr10-s5r3"
# ? for Apple Macintosh II with A/UX pre-3.0, "make aux", "auxgcc" or "auxufs"
# ? for Apple Macintosh with A/UX 3.0 and gcc, "make aux3gcc" or aux3gccc
# ? for Apple PowerMac with MkLinux, "make mklinux" (read Linux entry first)
# ? for Apple PowerMac with LinuxPPC, "make linuxppc"
# ? for Apple Macintosh with Minix 1.5.10, "make minix68k" or "make minixc68"
# ? for Apple Macintosh with Mac OS X 1.0 (Rhapsody), "make macosx10"
#     (no curses), "make macosx10c" (curses), or "make macosx10nc" (ncurses).
#     Or "make macosx10ncx" (ncurses but "make macosx10nc" doesn't work).
# ? for Apple Macintosh with Mac OS X 10.2, "make macosx102nc" (ncurses).
# ? for Apple Macintosh with Mac OS X 10.3, "make macosx103"
# ? for Apple Macintosh with Mac OS X 10.3.9 or later, "make macosx"
# ? for Arix System 90 with AT&T SVR3, "make sys5r3na"
# - for AT&T 6300 with IN/ix, "make sys5"
# - for AT&T 6300 PLUS, "make att6300" or (with no debugging) "make att6300nd"
# ? for AT&T 6386 WGS UNIX PC, "make sys5r3"
# ? for AT&T 3B2, 3B20 systems, "make att3b2".
#   for AT&T 3B1, 7300 UNIX PC (see notes with the entries):
#     In C-Kermit 7.0, only the gcc entries work:
# ?   "make sys3upcg", "make sys3upcgc", "make att351gm"
#    The others fail with "too many defines" (usually in ckuusr.h):
# -   "make sys3upc", "make sys3upcold", "make sys3upcc", "make sys3upcx",
#       "make sys3upcm", "make att351m"
# ? for AT&T System III/System V R2 or earlier, "make sys3" or "make sys3nid"
# ? for AT&T System III/System V with Honey DanBer UUCP, "make sys3hdb"
# ? for AT&T System V on DEC VAX, "make sys3" or "make sys5r3"
# ? for AT&T System V R3, use "make sys5r3" or "make sys5r3c"
# ? for AT&T System V/386 R3.2 built on Interactive 4.1.1, "make sys5r32is".
# ? for AT&T System V/386 R320.0 Versyss Systems, use "make sys5r3"
#     or "make sys5r3c".
# ? for AT&T System V R4, "make sys5r4", "make sys5r4sx", or "make sys5r4nx",
#     or if the ANSI C function prototyping makes trouble, add -DNOANSI,
#     as in "sys5r4sxna" entry
# ? for AT&T (USL) System V R4.2 use the sys5r4* entries.
# ? for Atari Falcon with MiNT, "make posix"
# ? for Atari ST with Minix ST 1.5.10.3, "make minix68k" or "make minixc68"
# ? for BBN C/70 with IOS 2.0, "make c70"
# ? for BeBox with Be OS 1.x DR7, "make beboxdr7"
#     Compiles OK but doesn't link with default linker which is limited to 64K.
#     Links OK with "Code Warrior Gold".  Many hacks in the source code need
#     to be removed when DR8 and later come out.
#     (Last tested in C-Kermit 6.0)
# - for BeBox with Be OS 1.x DR8, "make bebox"
#     (Needed functions missing from operating system and/or not working.)
# - for Bell Labs UNIX Version 6 (6th Edition), there is no makefile entry.
# ? for Bell Labs UNIX Version 7 (7th Edition), "make v7" (but see notes below)
#    (last built successfully in C-Kermit 5A188)
# ? for Bell Labs Research UNIX Version 10, "make bellv10"
#    (last built successfully in C-Kermit 6.0)
# ? for Bell Labs / Lucent Plan 9, use separate makefile ckpker.mk:
#    can be built for Intel, MIPS, 680x0, and PowerPC (last built C-Kermit 7.0)
# ? for BSDI BSD/386 1.x, "make bsdi"
# ? for BSDI BSD/OS 2.x, "make bsdi2"
# ? for BSDI BSD/OS 3.0 or 3.1, "make bsdi3"
# ? for BSDI BSD/OS 4.x, "make bsdi4"
# ? for BSDI BSD/OS 4.x, to build a binary that also works on FreeBSD,
#     "make bsdix".
# ? for Berkeley Unix 2.4, "make v7" (but read v7 material below)
# ? for Berkeley Unix 2.9 (DEC PDP-11 or Pro-3xx), "make bsd29"
# - for Berkeley Unix 2.10, use ckubs2.mak (a separate makefile)
# - for Berkeley Unix 2.11, use ckubs2.mak (a separate makefile)
#     This makefile is too big.  Read the instructions in ckubs2.mak.
#     "make -f ckubs2.mak bsd210" or "make -f ckubs2.mak bsd211".
#     (last built successfully in C-Kermit 6.0 - later versions too big)
# ? for Berkeley Unix 2.11 "make -f ckubs2.mak bsd210noicp" (no command parser)
# ? for Berkeley Unix 4.1, "make bsd41"
# ? for Berkeley Unix 4.2 on VAX, "make bsd42" or "make bsd42c"
# ? for Berkeley Unix 4.2 or 4.3 with HoneyDanBer UUCP, "make bsdhdb"
# ? for Berkeley Unix 4.3 on VAX, "make bsd43", "make bsd43nc".
# ? for Berkeley Unix 4.3 on VAX, no networking "make bsd43nonet.
# ? for Berkeley Unix 4.3 without acucntrl program, "make bsd42" or "bsd42c"
#     NOTE: all the C-Kermit 7.0 full builds for old BSDs fail with
#     "too many defines" in CPP, even on big architectures like VAX.  This
#     can be worked around with a clever ruse.  See comments at target.
# ? for Berkeley Unix 4.3, command-line only, "make bsdm".
# ? for Berkeley Unix 4.3-Tahoe, same as 4.3 BSD
# ? for Berkeley Unix 4.3-Reno, "make bsd43" or "make bsd44" or "make bsd44c"
# ? for Berkeley Unix 4.3-Carson City, "make bsd44" or "make bsd44c"
# ? for Berkeley Unix 4.4-Networking/2 or -Alpha, "make bsd44" or "make bsd44c"
# ? for Berkeley Unix 4.4, "make bsd44" or "make bsd44c"
# ? for Berkeley Unix 4.4-Lite, "make bsd44" or "make bsd44c"
# ? for Bull DPX/2 with BOS/X, "make bulldpx2"
# ? for Cadmus, "make sys3"
#   for Caldera, see SCO, Linux.
# ? for Callan Unistar, "make sys3"
# ? for CDC VX/VE 5.2.1 System V emulation, "make vxve"
# ? for Charles River Data Systems Universe 680x0 with UNOS 9.2, maybe
#     also other UNOS versions, "make crds"
# ? for CIE Systems 680/20 with Regulus, "make cie"
# ? for Commodore Amiga 3000UX Sys V R4, "make sys5r4sx"
# ? for Commodore Amiga 3000UX Sys V R4 and TCP/IP, "make svr4amiganet"
# ? for Commodore Amiga with Minix 1.5.10, "make minix68k" of "make minixc68"
# ? for Concurrent/Masscomp with RTU 4.0 or later, BSD environment, "make
#     rtubsd", "make rtubsd2", "make rtubsd3" (depending on where ndir.h
#     is stored, see entries below).
# ? for Concurrent/Masscomp with RTU 4.0 or later, System V R2, "make rtus5"
# ? for Concurrent (Perkin-Elmer) 3200 series, "make sys5".
# ? for Concurrent (Perkin-Elmer) 3200 series with <dirent.h>, "make ccop1"
# ? for Concurrent PowerMAX OS SVR4, "make powermax"
# ? for Consensys UNIX SV/386 R4V3, "make sys5r4sxtcpc" or "make sys5r4sx"
# ? for Convergent with CTIX Sys V R2, "make sys5"
# ? for Convergent with CTIX 6.4.1, "make ctix"
# ? for Convex C1, "make convex"
# ? for Convex C210 with Convex/OS 8, "make convex8"
# ? for Convex C2 with Convex/OS 9.1, "make convex9"
# ? for Convex C2 with Convex/OS 10.1 and gcc 2.x, "make convex10gcc"
# ? for Cray Research X/MP or YMP or C90 with UNICOS 6.x (System V R3),
#	"make cray"
# ? for Cray Research X/MP or YMP or C90 with UNICOS 7.x (System V R4),
#	"make cray"
# ? for Cray Research X/MP or YMP or C90 with UNICOS 8.0 Alpha, "make cray8"
# ? for Cray Research X/MP or Y-MP or C90 with UNICOS 9.0, "make cray9"
# ? for Cray Computer Cray-2 or Cray3 with CSOS, "make craycsos"
# ? for Cyber 910 (Silicon-Graphics Iris) with Irix 3.3, "irix33"
# ? for Data General AViiON with DG/UX 5.4 before R3.00, "make dgux540"
#     or "make dgux540c" (compile ckwart separately if necessary)
# ? for DG/UX 5.4 on AViiON Intel models, "make dgux540i" or dgux540ic.
# ? for DG/UX 5.4R4.11 on AViiON, all models, "make dgux54411"
# ? for DG/UX 5.4R4.20 on AViiON, all models, "make dgux54420"
# ? for Data General AViiON with DG/UX 4.3x using Sys V-isms, "make dgux430"
# ? for Data General AViiON with DG/UX 4.3x using BSD-isms, "make dgux430bsd"
# ? for Data General AViiON, earlier UNIX versions,
#     "make sys5r3" (maybe compile ckwart separately, or "touch ckcpro.c")
# ? for Data General MV systems with DG/UX, ???
# ? for Data General MV systems with MV/UX, use AOS/VS C-Kermit (CKDKER.MAK)
# ? for Data General MV systems with AOS/VS, use CKDKER.MAK (last = C-K 7.0)
# ? for DEC PDP-11 with Berkeley UNIX 2.x, see Berkeley UNIX 2.x.
# ? for DEC PDP-11 with Mini-UNIX (Bell 6th Edition for PDP-11 with no MMU),
#     probably no way to fit C-Kermit without I&D space.
# ? for DEC PDP-11 with Ultrix-11 3.x, ??? (probably needs overlays)
# ? for DEC VAX with Ultrix 1.x "make bsd"
# ? for DEC VAX with Ultrix 2.x "make ultrix2x"
# ? for DEC VAX or DECstation with Ultrix 3.0, 3.1, "make ultrix3x"
# ? for DECstation or VAX with Ultrix 4.0 or 4.1, "make ultrix40"
# ? for DECstation or VAX with Ultrix 4.2, "make ultrix42" or "make ultrix42c"
# ? for DECstation or VAX with Ultrix 4.x, POSIX world, "make posix"
# ? for DECstation or VAX with Ultrix 4.3, "make ultrix43".
# ? for DECstation or VAX with Ultrix 4.4, "make ultrix44".
# ? for DECstation 5000/50, /150 or /260 (R4x00 MIPS CPU), Ultrix 4.3A or later
#     "make ultrix43-mips3" or "make ultrix43c-mips3"
# ? for DECstation (MIPS) with Berkeley Sprite, "make bsd44"?
# ? for DECstation (MIPS) with OSF/1 V1.0 to 1.3, "make dec-osf"
# ? for DEC Alpha with OSF/1 1.0 to 1.3, "make dec-osf"
# ? for DEC PC 486 with OSF/1, "make dec-osf"
# ? for DEC Alpha with OSF/1 2.x, "make dec-osf20"
# ? for DEC Alpha with OSF/1 3.0, "make dec-osf30"
# ? for DEC Alpha with Digital UNIX 3.2, "make du32"
# ? for DEC Alpha with Digital UNIX 4.0-4.0D, "make du40" or "make du40gcc"
# ? for DEC Alpha with Digital UNIX 4.0E or higher, see Tru64.
# + for DEC Alpha with any version of DU or OSF/1, "make dec-osf1"
# - for DEC Pro-350 with Pro/Venix V1.x, "make provx1" (version 5A is too big)
# ? for DEC Pro-380 with Pro/Venix V2.0 (Sys V), "make sys3" or "make sys3nid"
# ? for DEC Pro-380 with 2.9, 2.10, or 2.11 BSD, "make bsd29" or "make bsd210"
#   for DEC PDP-11 with 2.xBSD (use separate makefile ckubs2.mak)
# ? for Dell UNIX Issue 2.x (= USL Sys V/386 R4.x + fixes), "make dellsys5r4"
#     or "make dellsys5r4c" (last tested in C-Kermit 5A).
# ? for DIAB DS90 with DNIX (any version) create an empty <sys/file.h> if
#     this file does not already exist (or add -DNOFILEH to the make entry).
# ? for DIAB DS90 with DNIX 5.2 (Sys V.2) or earlier, "make dnix",
#     "make dnixnd", or (to add curses and TCP/IP) "make dnixnetc",
# ? for DIAB DS90 with DNIX 5.3 (Sys V.3), "make dnix5r3"
# ? for DIAB DS90 with DNIX 5.3 (Sys V.3) and TCP/IP, "make dnix5r3net"
# ? for DIAB DS90 with DNIX 5.3 2.2 (Sys V.3), ANSI C, "make dnix5r3ansi"
#     or, to include TCP/IP, "make dnix5r3ansinet",
#     but you have to fix a bug in /usr/include/stdlib.h first:
#     change "extern void free(char *str);" to "extern void free(void *str);"
# ? for Dolphin Server Technology Triton 88/17 with SV/88 R3.2, "make sv88r32"
# ? for Encore Multimax 310, 510 with Umax 4.2, "make umax42"
# ? for Encore Multimax 310, 510 with Umax 4.3, "make umax43"
# ? for Encore Multimax 310, 510 with Umax V 2.2, use Berkeley cc, "make bsd"
# ? for Encore 88K with Umax V 5.2, "make encore88k"
# ? for ESIX System V R4.0.3 or 4.04 with TCP/IP support, "make esixr4"
#     NOTE: You can also build on Unixware 2.x with "make esixr4", and run
#     on ESIX, but there you must first:
#       ln /usr/lib/libsocket.so /usr/lib/libsocket.so.1
#       ln /usr/lib/libnsl.so /usr/lib/libnsl.so.1
#     (This worked for C-Kermit 6.0 but does not work for 7.0)
#     (But you can probably still build a non-networking version this way)
# ? for Everex STEP 386/25 Rev G with ESIX Sys V R3.2D, "make sys5r3"
# ? for Fortune 32:16, For:Pro 1.8, "make ft18"
# ? for Fortune 32:16, For:Pro 2.1, "make ft21"
# ? for FPS 500 with FPX 4.1, "made bsd"
# ? for FreeBSD 1.0, "make freebsd1"
# ? for FreeBSD 2.x, "make freebsd2" (ncurses) or "make freebsd2c" (curses)
# ? for FreeBSD 3.x, "make freebsd3" (ncurses) or "make freebsd3c" (curses)
# ? for FreeBSD 4.0, "make freebsd40"
# ? for FreeBSD 4.1 or later, "make freebsd"
# + NOTE: Just use "make freebsd" for any reasonably recent FreeBSD version.
# ? for Harris HCX-2900, "make sys5r3"
# ? for Harris Night Hawk 88K or 68K with CX/UX pre-6.1, "make sys5r3"
# ? for Harris Night Hawk 88K or 68K with CX/UX 6.1 or later, "make cx_ux"
# ? for Heurikon, "make sys3"
# ? for HP-3000, MPE/ix, "make posix"?
# ? for HP-9000 Series 300 with 4.4BSD, "make bsd44"

# NOTE: Most of the HP-UX targets were tested successfully in 2010.
# Verification needed for C-Kermit 9.0 Beta.01...

# ? for HP-9000 Series 500, HP-UX 5.21 and no networking "make hpux0500"
# ? for HP-9000 Series 500, HP-UX 5.21 with WIN/TCP 1.2 "make hpux0500wintcp"
# ? for HP-9000 Series, HP-UX 6.5, without long filenames,
#     "make hpux0650", "make hpux0650c" or "make hpux0650tcpc"
# ? for HP-9000 Series, HP-UX 7.0 or later no long filenames, "make hpux0700sf"
#     or (to include tcp/ip, curses, etc) "make hpux0700sftcpc"
# ? for HP-9000 Series with HP-UX 7.0, TCP/IP,long filenames,"make hpux0700lfn"
# ? for HP-9000 300/400 Series (680x0) with HP-UX 8.0, TCP/IP, "make hpux0800"
#      or "make hpux0800c"
# ? for HP-9000 700/800 Series (PA-RISC), HP-UX 8.0, TCP/IP, "make hpux0800pa"
#      or "make hpux0800pac"
# ? for HP-9000 Series with HP-UX 8.0, no TCP/IP, long filenames,
#      "make hpux0800notcp"
# ? for HP-9000 Series, HP-UX 9.0 - 9.10, TCP/IP, curses, restricted compiler
#     (no optimization, no ANSI), all models, "make hpux0900".  Read the
#     hpux0900 entry below for more info.
# ? for HP-9000 700 and 800 Series, HP-UX 9.x, TCP/IP, curses,
#     HP optimizing ANSI C compiler, "make hpux0900o700".
# ? for HP-9000 with Motorola CPUs, HP-UX 9.x, TCP/IP, curses,
#     HP optimizing ANSI C compiler, "make hpux0900mot".
# ? for HP-9000 on other CPUs, HP-UX 9.x, TCP/IP, curses,
#     HP optimizing ANSI C compiler, "make hpux0900o".
# ? for HP-9000 series, HP-UX 9.x, TCP/IP, curses, gcc, all models,
#     "make hpux0900gcc"
# ? for HP-9000 700/800 Series, HP-UX 10.00,10.01,10.10,10.20,10.30, TCP/IP,
#     curses, restricted compiler (no optimization, no ANSI) "make hpux1000".
# ? for HP-9000 700/800 Series, HP-UX 10.00,10.01,10.10,10.20,10.30, TCP/IP,
#     curses, HP ANSI/optimizing compiler "make hpux1000o" or "make hpux1000o+"
# ? for HP-9000 HP-UX 10.00 or later with gcc, "make hpux1000gcc"
# ? for Trusted HP-UX 10.xx "make hpux1000t", "make hpux1000to",
#     or make hpux1000to+"
# ? for HP-9000 700/800 Series, HP-UX 11.00,TCP/IP,curses, restricted compiler
#     (no optimization, no ANSI) "make hpux1100".
# ? for HP-9000 700/800 Series, HP-UX 11.00,TCP/IP,curses, restricted compiler
#     HP ANSI/optimizing compiler "make hpux1100o" or "make hpux1100o+"
# ? for Trusted HP-UX 11.xx "make hpux1100t", "make hpux1100to",
#     make hpux1100to+"
# ? for HP-9000 PA-RISC models with NeXTSTEP 3.3, "make nextquadfat".
# ? for HP-9000 PA-RISC models with OPENSTEP/Mach 4.1, "make nextquadfat".
# ? for IBM 370 Series with IX/370, "make ix370"
# ? for IBM 370 Series with AIX/370 1.2, "make aix370"
# ? for IBM 370 Series with AIX/370 3.0, "make aix370"
# ? for IBM 370 Series with AIX/ESA 2.1, "make aixesa"
# - for IBM PC/AT 286 & compatibles with Mark Williams Coherent OS,
#     command-line-only version, "make coherent" (version 5A & later too big)
# ? for IBM PC 386 & compatibles with Mark Williams Coherent OS,
#     minimum interactive version, "make coherentmi"
# ? for IBM PC 386 & compatibles with Mark Williams Coherent OS,
#     full interactive version, prior to v4.2, "make coherentmax"
# ? for IBM PC 386 & compatibles with Mark Williams Coherent OS 4.2,
#     "make coherent42"
# ? for IBM PC 386 & compatibles with LynxOS 2.0 or 2.1, "make lynx21"
# ? for IBM PC 386 & compatibles with LynxOS 2.2, "make lynx"
# - for IBM PC/AT & compatibles with original MINIX, "make minix" (too big)
# ? for IBM PC family, 386-based, with MINIX/386 1.5, "make minix386"
#     or if you have GNU CC, "make minix386gcc"
# ? for IBM PC family, 386-based, with MINIX 2.0, "make minix20"
# ? for IBM PC family, 386-based, with MINIX 3.0, "make minix3"
# + for IBM PC family, 386-based, with MINIX 3.0, "make minix315"
# ? for IBM PS/2 with PS/2 AIX 1.0, 1.1, or 1.2, "make ps2aix" or ps2aixnetc.
# ? for IBM PS/2 with PS/2 AIX 1.3, "make ps2aix3"
# ? for IBM RISC System/6000 with AIX 3.0, "make aix30"
# ? for IBM RISC System/6000 with AIX 3.1.x, "make aix31"
# ? for IBM RISC System/6000 with AIX 3.2.0 thru 3.2.5, "make aix32"
# ? for IBM RS/6000 or Power Series with AIX 4.1.x, "make aix41"
# ? for IBM RS/6000 or Power Series with AIX 4.1.x with gcc, "make aix41g"
# ? for IBM RS/6000 or Power Series with AIX 4.1 with X.25, "make aix41x25"
# ? for IBM RS/6000 or Power Series with AIX 4.2 or later: "make aix"
#  (the following "make aixnn" targets are no longer necessary except for gcc)
# ? for IBM RS/6000 or Power Series with AIX 4.2, "make aix42"
# ? for IBM RS/6000 or Power Series with AIX 4.3, "make aix43" (or aix43gcc)
# ? for IBM RS/6000 or Power Series with AIX 4.4, "make aix44" (or aix44gcc)
# ? for IBM RS/6000 or Power Series with AIX 4.5, "make aix45" (or aix45gcc)
# ? for IBM RS/6000 or Power Series with AIX 5.0, "make aix50" (or aix50gcc)
# ? for IBM RS/6000 or Power Series with AIX 5.1, "make aix51" (or aix51gcc)
# ? for IBM RS/6000 or Power Series with AIX 5.2, "make aix52" (or aix52gcc)
# ? for IBM RS/6000 or Power Series with AIX 5.3, "make aix53" (or aix53gcc)
# ? for IBM RS/6000 or Power Series with AIX 6.1, "make aix61" (or aix53gcc)
# ? for IBM RT PC with AIX 2.1, "make sys3"
# ? for IBM RT PC with AIX 2.2.1, "make rtaix" or "make rtaixc"
# ? for IBM RT PC with ACIS 4.2, "make bsd"
# ? for IBM RT PC with ACIS 4.3, "make rtacis" or "make bsd KFLAGS=-DNOANSI"
# ? for IBM RT PC with 4.3BSD/Reno, "make bsd44" or "make bsd44c"
# ? for ICL DRS400 or 400E, "make iclsys5r3"
# ? for ICL DRS3000 (80486) with DRS/NX, "make iclsys5r4_486"
# ? for ICL DRS6000 (SPARC) with DRS/NX, "make iclsys5r4"
# ? for ICL DRS6000 (SPARC) with DRS/NX 4.2MP 7MPlus, "make iclsys5r4m+"
# ?     Ditto but with IKSD support included, "make iclsys5r4m+iksd"
# ? for Integrated Solutions Inc V8S VME 68020, "make isi"
# ? for Intel 302 with Bell Tech Sys V/386 R3.2, "make sys5r3"
# ? for Intel Xenix/286, "make sco286"
# ? for Interactive System III (PC/IX), "make pcix" or "make is3"
# ? for Interactive System III (PC/IX) with gcc, "make is3gcc"
# ? for Interactive 386/ix 1.0.6 with TCP/IP networking, "make is5r3net2"
# ? for Interactive 386/ix 2.0.x, "make is5r3" or (POSIX) "make is5r3p"
# ? for Interactive 386/ix 2.0.x with TCP/IP networking, "make is5r3net"
#     or "make is5r3net2"
# ? for Interactive 386/ix 2.2.1, job control, curses, no net, gcc,
#     "make is5r3gcc"
# ? for Interactive UNIX Sys V R3.2 V2.2 - 4.0 without TCP/IP, "make is5r3jc"
# ? for Interactive UNIX Sys V R3.2 V2.2 - 4.0 with TCP/IP, "make is5r3netjc"
# ? for Intergraph Clipper, "make clix" or "make clixnet"
# ? for Jolix (see 386BSD)
# + for Linux 1.2 and later, "make linux".  Uses ncurses.  This version
#     handles serial speeds up to 460800 bps, Linux FSSTD 1.2, TCP/IP, and
#     should work on both libc and glibc systems.  For static linking, use
#     "make linux LNKFLAGS=-static".  Please read the comments that accompany
#     the linux entry.  As of 8.0.212 Dev.10, this also includes Large File
#     Support (LFS).
# + for Linux builds that fail with "sys/select.h: No such file or directory",
#     "make linuxns"
# + for Linux 1.2 and later but with curses.h and libcurses (rather than
#     ncurses.h and libncurses), use "make linuxc".
# + for Linux 1.2 and later with no curses support at all, "make linuxnc".
# + for Linux with no TCP/IP, "make linuxnotcp"
# (The following Linux targets are historic and might not work...)
# ? for Red Hat Linux 7.1 through RH9, fully configured (krb5, SSL, etc):
#     "make redhat71", "make redhat72", "make redhat73", "make redhat80"
#     "make redhat9"
#     NOTE: You must use this target for Red Hat 7.1 since it
#     also includes a workaround for its broken curses library.
#     WARNING: These targets create binaries that include code for
#     strong encryption and are therefore not exportable. DO NOT PUT
#     THESE BINARIES ON US OR CANADIAN WEB OR FTP SITES.
# ? for Linux on PowerMac (Mklinux DR3), "make mklinux".
# ? for Linux 1.2 and later, to build with egcs, "make linuxegcs".
# ? for Linux with lcc compiler, no TCP/IP, "make linuxnotcp-lcc"
# ? for Linux 1.0 or earlier, "make linux10".
# (End old linux targets)
# ? for Mach 2.6 on (anything, e.g. DECstation), "make bsd42" or "make bsd43".
# ? for MachTen (Tenon) 2.1.1.D on (e.g.) Apple Powerbook, "make machten".
# ? for Masscomp RTU AT&T System III, "make rtu"
#   for other Masscomp, see Concurrent.
# ? for Microport SV/AT (System V R2), "make mpsysv" (last edit tested: 144)
# ? for Microport SVR4 2.2, 3.1, or 4.1 "make sys5r4sx"
# ? for Microsoft,IBM Xenix (/286, PC/AT, etc), "make xenix" or "make sco286"
# ? for MIPS System with RISC/os (UMIPS) 4.52 = AT&T SVR3, "make mips"
#     or "make mipstcpc"
# ? for MkLinux on Power Macintosh, "make mklinux"
# ? for Modcomp 9730, Real/IX, "make sys5r3" (or modify to use gcc = GLS cc)
# ? for Modcomp Realstar 1000 with REAL/IX D.1, "make sv88r32"
# ? for Motorola Four Phase, "make sys3" or "make sys3nid"
# ? for Motorola Delta System V/68 R3, "make sv68r3"
# ? for Motorola Delta System V/68 R3V5, "make sv68r3v5"
# ? for Motorola Delta System V/68 R3V5.1, "make sv68r3v51"
# ? for Motorola Delta System V/68 R3V6 with NSE TCP/IP, "make sv68r3v6"
# ? for Motorola Delta System V/88 R32, "make sv88r32"
# ? for Motorola Delta System V/88 R40, "make sv88r40"
# ? for Mt Xinu Mach386 on 386/486-based PCs, "make bsd43"
# ? for NCR Tower 1632, OS 1.02, "make tower1"
# ? for NCR Tower 1632 or Minitower with System V R2, "make sys3"
#     or "make sys3nv"
# ? for NCR Tower 32, OS Release 1.xx.xx, "make tower32-1"
# ? for NCR Tower 32, OS Release 2.xx.xx, "make tower32-2"
# ? for NCR Tower 32, OS Releases based on Sys V R3, "make tower32"
# ? for NCR Tower 32, OS Releases based on Sys V R3 with gcc "make tower32g"
# ? for NCR System 3000, AT&T UNIX System V R4 2.0, "make sys5r4sxna"
# ? for NCR System 3000, AT&T UNIX System V R4 2.0 with Wollongong TCP/IP,
#     "make sys5r4net2" or "make sys5r4net2c".
#      Some header files might be misplaced; try this:
#       ln /usr/include/netinet/in.h /usr/include/sys/in.h
#       ln /usr/include/arpa/inet.h /usr/include/sys/inet.h
#       ln /usr/include/sys/termiox.h /usr/include/termiox.h
# ? for NCR System 3000, NCR UNIX 02.02.01, same as above.
# ? for NCR MP-RAS System V R4 V2.03 or 3.02, "make mpras" or "make mprastcpc"
# + for NetBSD any version on any architecture, "make netbsd"
# + for NetBSD with OpenSSL, "make netbsd+ssl"
# ? for NetBSD with ncurses specified instead of curses, "make netbsdn"
# ? for NetBSD with all curses support omitted, "make netbsdnc"
# ? for NeXT with NeXTSTEP 1.0 through 3.2, "make next" (on a NeXT)
# ? for NeXT with NeXTSTEP 3.3, "make next33"
# ? for NeXT with OPENSTEP/Mach 4.1, "make nextquadfat".
# ? for NeXT with OPENSTEP/Mach 4.2, "make openstep42".
# ? for NeXTSTEP/486, "make next" (on a PC)
# ? for NeXTSTEP portable binary (runs on Intel or Motorola), "make nextfat"
# ? for NeXTSTEP portable binary (Intel, Motorola, HP PA-RISC, or SPARC),
#     "make nextquadfat"
# ? for Nixdorf Targon/31, "make t31tos40x"
# ? for Norsk Data Uniline 88/17 with SV/88 R3.2, "make sv88r32"
#   for Novell UnixWare - see UnixWare
# ? for OSF/1 (vanilla, from OS/F), "make posix"
# ? for OkiStation 7300 Series, "make sys5r4sxtcp"
# ? for Olivetti LSX-3020 with X/OS R.2.3, "make xos23" or "make xos23c"
# + for OpenBSD, "make openbsd" (also see secure targets listed below).
# ? for OPENSTEP/Mach 4.1, "make nextquadfat" (NeXT, Intel, PA-RISC, SPARC)
# ? for OPENSTEP/Mach 4.2, "make openstep42" (tested on NeXT)
# ? for Perkin-Elmer (Concurrent) 3200 series, "make sys5".
# ? for Perkin-Elmer (Concurrent) 3200 series with <dirent.h>, "make ccop1"
# ? for Perkin-Elmer/Concurrent 3200 with Xelos R02, "make ccop1"
# ? for PFU Compact A Series SX/A TISP V10/E50 (Japan), "make sxae50"
# ? for Plexus, "make sys3"
# ? for Pyramid 9XXX (e.g. 9845) or MIServer T series, OSx 4.4b thru 5.1,
#     "ucb make pyramid" or for HDB UUCP, "ucb make pyramid-hdb" or:
# ? for Pyramid MIServer S or ES Series, DataCenter/OSx, "make pyrdcosx"
# ? for Pyramid MIS-S MIPS R3000, DataCenter OSx System V R4, "make pyrdcosx"
# ? for POSIX on anything, "make posix" (but adjustments might be necessary).
#      NOTE: this target is not very useful - many features are missing.
# ? for Prime 8000 MIPS, SVR3, "make mips" or "make mipstcpc"
# - for QNX 2.x (sorry we don't have a version of C-Kermit for QNX 2.x)
# ? for QNX 4.0 or 4.1, 16-bit, on 286 PC, Watcom C 8.5, "make qnx16_41"
# ? for QNX 4.21 - 4.22A (286+), and 4.23 (386+), or higher, 16-bit,
#     Watcom C 9.5x or higher, "make qnx16"
# + for QNX 4.21-4.25, 32-bit, 386 or above, Watcom C 10.6, "make qnx32"
#     NOTE: ("make qnx" == "make qnx32")
# ? for QNX Neutrino 2+, "make qnx_nto2+" (crosscompiled on QNX4 with Watcom C)
# ? for QNX 6 = Neutrino 2.xx, "make qnx6"
# ? for Ridge 32 (ROS3.2), "make ridge32"
# ? for Samsung MagicStation, "make sys5r4"
# ? for SCO Xenix 2.2.1 with development system 2.2 on 8086/8 "make sco86"
# ? for SCO Xenix/286 2.2.1 with development system 2.2 on 80286, "make sco286"
#     NOTE: reportedly this makefile is too long for SCO Xenix/286 make, but it
#     works with "makeL", or if some of the other make entries are edited out.
# ? for SCO Xenix/386 2.2.2, "make sco386"
# ? for SCO Xenix/386 2.3.x, "make sco3r2"
# ? for SCO Xenix/386 SCO 2.3.3 or 2.3.4 with gcc 1.37 or later,
#     "make sco386gcc" or (to add curses) "make sco386gccc".
# ? for SCO Xenix/386 or UNIX/386 with Excelan TCP/IP, "make sco3r2net"
#     or (to add curses support) "make sco3r2netc" or "sco386netc"
# + for SCO XENIX 2.3.4, "make sco234" or "make sco234c" to add curses.
# ? for SCO XENIX 2.3.4 with SCO TCP/IP & curses, "make sco234netc".
# ? for SCO Xenix 2.3.x with Racal-InterLan TCP/IP, "make sco3r2netri"
#   for other UNIX varieties with Racal Interlan TCP/IP, read sco3r2netri entry
# ? for SCO Xenix 2.3.x with SCO (Lachman) TCP/IP, "make sco3r2lai"
#     or (to add curses) "make sco3r2laic"
#   for SCO UNIX...  ALSO READ COMMENTS in the SCO UNIX entries for more info!
# ? for SCO UNIX/386 3.2.0 or 3.2.1, "make sco3r2" or "make sco3r2x"
# ? for SCO UNIX/386 3.2.2, "make sco3r22" or "make sco3r22gcc"
#     or "make sco3r22c"
# ? for SCO UNIX/386 3.2.2 with SCO TCP/IP, "make sco3r22net"
#     or "make sco3r22netc" (curses)
# ? for SCO ODT 1.1, "make sco3r22net" or "make sco3r22netc" (curses)
# ? for SCO UNIX/386 3.2 V4.x, no network support, "make sco32v4"
# ?   or "make sco32v4ns" (this one uses no select() or sockets library)
# ? for SCO UNIX/386 3.2 V4.x with TCP/IP, "make sco32v4net"
#     (also sco32v4gcc, sco32v4netgcc)
# ? for SCO UNIX/386 3.2 V5.0 - see SCO OpenServer.
# ? for SCO UNIX 3.2v4.x with TCP/IP, <dirent.h> for Extended Acer File
#     System (EAFS), curses, ANSI C compilation, "make sco32v4net"
# ?   or (to use select()-based CONNECT module) "make sco32v4netx".
# ? for SCO UNIX 3.2v4.2, "make sco-odt30" (includes TCP/IP).
# ? for SCO MPX 3.0 - The SCO UNIX binary runs on the corresponding MPX system.
#
# NOTE: Also see below for other entries that are variations on these.
# Also be sure to read the comments accompanying each SCO entry.
# Also see Unixware section.
#
# ? for SCO ODT 2.0, "make sco32v4net"
# ? for SCO ODT 3.0, "make sco-odt30"
# ? for SCO OpenServer 5.0 (OSR5), "make sco32v500"
# ? for SCO OpenServer 5.0 (OSR5) with networking, "make sco32v500net"
# ? for SCO OpenServer 5.0 (OSR5), gcc, "make sco32v500gcc"
# ? for SCO OpenServer 5.0 (OSR5), gcc, with networking, "make sco32v500netgcc"
# ? for SCO OpenServer 5.0 (OSR5), as above, ELF, "make sco32v500netgccelf"
# ? for SCO OpenServer 5.0.2, use "make sco32v502xxx" entries as above.
# ? for SCO OpenServer 5.0.4, use "make sco32v504xxx" entries as above.
# ? for SCO OpenServer 5.0.5, use "make sco32v505xxx" entries as above.
#     Use the sco32v505udkxxx entries if you have the UDK rather than /bin/cc.
# ? for SCO OpenServer 5.0.6, use "make sco32v506xxx" entries as above.
# ? for SCO OpenServer 5.0.6a,use "make sco32v506axxx" entries as above.
# ? for SCO OpenServer 5.0.7, use "make sco32v507", "make sco32v507net"
# ? for SCO (Univel) UnixWare 1.x, "make unixware" or "make unixwarenetc".
#     If there are problems with this in C-K 7+ see notes at unixware entry.
# + for SCO OpenServer 6.0.0, "make sco_osr600"
# ? for SCO UnixWare 2.0.x, "make uw20"
# ? for SCO UnixWare 2.1.0, "make uw21"
# ? for SCO UnixWare 2.1.3, "make uw213"
# + for SCO UnixWare 7, "make uw7" (includes large file support)
# ? for SCO UnixWare 7 with IKSD support, "make uw7iksd" or "make uw7iksdudk"
# ? for SCO UnixWare 7 with OpenSSL, "make uw7ssl"
# ? for SCO (Caldera) Open UNIX 8, "make ou8"
# ? for Sharp Zaurus SL5500 PDA, "make zsl5500".
# ? for Sequent with DYNIX/ptx 1.2.1, "make dynixptx12"
# ? for Sequent with DYNIX/ptx 1.3 or 1.4 with TCP/IP, "make dynixptx13"
# ? for Sequent with DYNIX/ptx 2.0 or 2.1 with TCP/IP, "make dynixptx20"
#     or "dynixptx20c"
# ? for Sequent with DYNIX/ptx 2.1.6 on i486, "dynixptx216c"
# ? for Sequent with DYNIX/ptx V4.1.3 with TCP/IP, "make dynixptx41c"
# ? for Sequent with DYNIX/ptx V4.4.2 with TCP/IP, "make dynixptx44"
# ? for Sequent Balance 8000 or B8 with DYNIX 3.0.xx, "make dynix3"
#    or "make dynix3noacu"
# ? for Sequent Symmetry S81 with DYNIX 3.0.xx, "make dynix3"
# ? for Sequent DYNIX 3.1.xx, "make dynix31" or "make dynix31c"
# ? for Siemens/Nixdorf SINIX-L Intel V5.41, "make sinix541i"
# + for Siemens/Nixdorf SINIX-N MIPS V5.42, "make sinix542"
# ? for Siemens/Nixdorf SINIX-P MIPS V5.42 with gcc, "make sinix542g"
# ? for Siemens/Nixdorf SINIX-Z Intel V5.42, "make sinix542i"
# ? for Siemens/Nixdorf Reliant UNIX V5.43, "make sni543"
# ? for Siemens/Nixdorf Reliant UNIX V5.44, "make sni544"
# ? for Silicon Graphics Iris System V IRIX 3.2 or earlier, "make iris"
# ? for Silicon Graphics Sys V R3 with IRIX 3.3 or later, "make sys5r3"
# ? for Silicon Graphics Iris Indigo with IRIX 4.0 or 5.0, "make irix40" or
#     (to include Yellow Pages and Curses) "make irix40ypc"
# ? for Silicon Graphics Iris Indigo or Elan with IRIX 4.0.x with microcode
#     optimization and -O4, "make irix40u" or "irix40uc" (and read notes
#     accompanying these entries).
# ? for Silicon Graphics IRIX 5.1, "make irix51" or "irix51x" (no optimize)
# ? for Silicon Graphics IRIX 5.2, "make irix52"
# ? for Silicon Graphics IRIX 5.3, "make irix53" or "irix53x" (no optimize)
# ? for Silicon Graphics IRIX 6.0, "make irix60".
# ? for Silicon Graphics IRIX 6.2, "make irix62".
# ? for Silicon Graphics IRIX 6.3, "make irix63".
# ? for Silicon Graphics IRIX 6.4, "make irix64" or "make irix64gcc".
# + for Silicon Graphics (SGI) IRIX 6.5, "make irix65"
# +   or "make irix65mips2" to force MIPS2, or "make irix65gcc" for GCC.
# + for Silicon Graphics (SGI) IRIX 6.5, "make irix65" or "make irix65mips2"
# ? for SGI IRIX 6.5 with SSL/TLS, SRP, and ZLIB "make irix65+ssl+srp+zlib"
# ? for Solaris 2.0-2.3 on SPARC or Intel, SunPro CC, "make solaris2x",
# ?   or to add SunLink X.25 8.0x support, "make solaris2x25".
# ? for Solaris 2.4 built with gcc, "make solaris24g".
# ? for Solaris 2.0-2.3 on SPARC or Intel, GNU CC, "make solaris2xg".
# ? for Solaris 2.4 with X.25, "make solaris24x25".
# ? for Solaris 2.5 on SPARC or Intel, SunPro CC, "make solaris25".
# ?   or to add SunLink X.25 8.0x support, "make solaris25x25".
# ? for Solaris 2.5 on SPARC or Intel, GNU CC, "make solaris25g".
# ? for Solaris 2.6 on SPARC or Intel, "make solaris26".
# ? for Solaris 7 on SPARC or Intel, SunPro CC, "make solaris7".
# ? for Solaris 7 on SPARC or Intel, GNU CC, "make solaris7g".
# ? for Solaris 8 on SPARC or Intel, SunPro CC, "make solaris8".
# ? for Solaris 8 on SPARC or Intel, GNU CC, "make solaris8g".
# + for Solaris 9 on SPARC (or Intel?), 32-bit, SunPro CC, "make solaris9".
# + for Solaris 9 on SPARC (or Intel?), 32-bit, GNU CC, "make solaris9g".
# ? for Solaris 9 on SPARC (or Intel?), 64-bit, GNU CC, "make solaris9g64".
# + for Solaris 10 on SPARC (or Intel?), 32-bit, SunPro CC, "make solaris10".
# + for Solaris 10 on SPARC 64-bit, SunPro CC, "make solaris10_64".
# + for Solaris 10 on SPARC (or Intel?), 32-bit, GNU CC, "make solaris10g".
# ? for Solaris 10 on SPARC (or Intel?), 64-bit, GNU CC, "make solaris10g64".
# ? for Solbourne 4/500 with OS/MP 4 "make sunos4"
# ? for Solbourne 4/500 with OS/MP 4.1 "make sunos41" or "make sunos41c"
# ? for SONY NEWS with NEWS-OS 4.0.1C, "make sonynews"
# ? for SONY NEWS with NEWS-OS 4.1.2C, "make sonynews"
# ? for Sperry/UNISYS 5000/20, UTS V 5.2 3R1, "make sys5"
# ? for Sperry/UNISYS 5000/30/35/50/55, UTS V 5.2 2.01, "make unisys5r2"
# ? for Sperry/UNISYS 5000/80 with System V R3, "make sys5r3"
# ? for Sperry/UNISYS 5000/95 with System V R3, "make sys5r3"
#     For UNISYS SVR3 it might be necessary to "make sys5r3 KFLAGS=-UDYNAMIC"
# ? for Stardent 1520, "make sys5r3"
# ? for Stratus FTX 2.x, try "make ftx" or else "make sys5r4" or "sys5r4sx"
# ? for Stratus FTX 3.x, PA-RISC 1.0 or 2.0, "make ftx" or "make ftxtcp"
# ? for Sun with Sun UNIX 3.5 and gcc, "make sunos3gcc"
# ? for Sun with pre-4.0 SunOS versions, "make bsd" (or appropriate variant)
# ? for Sun with SunOS 4.0, BSD environment, "make sunos4"
# ? for Sun with SunOS 4.0, BSD, with SunLink X.25, make sunos4x25
# ? for Sun with SunOS 4.1 or 4.1.1, BSD environment, "make sunos41"
#     or "make sunos41c" (curses) or "make sunos41gcc" (compile with gcc)
# ? for Sun with SunOS 4.1.x, BSD, with SunLink X.25 7.00 or earlier,
#     "make sunos41x25" or "make sunos41x25c" (curses)
# ? for Sun with SunOS 4.1, 4.1.1, AT&T Sys V R3 environment, "make sunos41s5"
# ? for Sun with SunOS 4.1.2, "make sunos41" or any of its variations.
#     NOTE:  All SunOS 4.x systems -- Shared libraries are used by default.
#       If this causes problems, add -Bstatic to CFLAGS.
#     NOTE2: When building C-Kermit under SunOS for the BSD universe,
#       but /usr/5bin/cc is ahead of /usr/ucb/cc in your PATH, add
#       "CC=/usr/ucb/cc CC2=/usr/ucb/cc" to the make entry.
#     NOTE3: If an executable built on one type of Sun hardware does not work
#       on another type, rebuild the program from source on the target machine.
#   for Sun with Solaris 1.x use SunOS 4.1 entries.
#   for Sun with Solaris 2.0 and higher use Solaris entries.
# + for Sun SPARC with Linux, "make linux"
# ? for Sun SPARC with OPENSTEP/Mach 4.1, "make nextquadfat"
# ? for Sun SPARC with OPENSTEP/Mach 4.2, "make openstep42"
# - for Tandy 16/6000 with Xenix 3.0, "make trs16" (C-Kermit 7.0 is too big)
# ? for Tektronix 6130/4132/43xx (e.g.4301) with UTek OS, "make utek"
#     or (for models without hardware flow control), "make uteknohwfc"
# ? for Tektronix XD88 series with UTekV OS, "make utekvr3"
# ? for Tri Star Flash Cache with Esix SVR3.2, "make sys5r3"
# NOTE: The Tru64 builds have been failing since 2010, but "make dec-osf" is OK
# ? for Tru64 UNIX 4.0E, "make tru64-40e"
# ? for Tru64 UNIX 4.0F, "make tru64-40f"
# ? for Tru64 UNIX 4.0G, "make tru64-40g"
# ? for Tru64 UNIX 5.0A, "make tru64-50a"
# ? for Tru64 UNIX 5.1A, "make tru64-51a"
# ? for Tru64 UNIX 5.1B, "make tru64-51b"
# ? for Unistar, "make sys5"
# ? for Unisys S/4040 68040 CTIX SVR3.2 6.4.1, "make ctix" or "make sys5r3"
# ? for Unisys U5000 UNIX SVR3 6.x, "make sys5r3" or "make sys5r3c"
# ? for Unisys U6000 UNIX SVR4 1.x, "make sys5r4nx" or "make sys5r4nxnetc"
#   for Unisys ... (also see Sperry)
#   for Univel - see UnixWare
#   for Unixware - see SCO
# ? for Valid Scaldstar, "make valid"
# ? for Whitechapel MG01 Genix 1.3, "make white"
# ? for Zilog ZEUS 3.21, "make zilog"
#
# The result should be a runnable program called "wermit" in the current
# directory.  After satisfactory testing, you can rename wermit to "kermit"
# and put it in some directory that's in everybody's PATH, such as
# /usr/local or /opt/local.
#
# To remove intermediate and object files, "make clean".
# If your C compiler produces files with an extension other than "o",
# then "make clean EXT=u", "make clean EXT=s", or whatever.
#
# To run lint on the source files, "make lintsun", "make lintbsd",
# "make lints5", as appropriate.
#
# ******************************
# SECURE TARGETS
#
# Beginning with C-Kermit 7.0, secure targets are included, as are the
# source modules (ckuat*.[ch], ck_*.[ch]) needed to build them.  Secure
# target names are like the regular names, but with security features
# indicated by plus (+) signs.  The features are:
#
# krb4     MIT Kerberos IV
# krb5     MIT Kerberos V
# openssl  OpenSSL (SSL/TLS)
# zlib     ZLIB compression for SSL/TLS
# srp      Stanford Secure Remote Password
# pam      PAM (pluggable authentication module)
# shadow   Shadow Password File
#
# You can build these targets if you have the Kermit source files and the
# required libraries (Kerberos, OpenSSL, SRP, etc) and header files.  See:
#   http://www.columbia.edu/kermit/security.html
# for specific details regarding supported versions.
#
# NOTE: OpenSSL 0.9.6 and earlier are not compatible with 0.9.7 and later.
# C-Kermit code was originally designed for 0.9.6.  To build with 0.9.7 you
# must add -DOPENSSL_097 to avoid missing symbols in the DES library and to
# use the entry points that were renamed to avoid conflict with Kerberos 4.
# If you have OpenSSL 0.9.8, add -DOPENSSL_098, which is a synonym for
# -DOPENSSL_097.  If you have 1.0.0 or later, add -DOPENSSL_100, which is
# another synonym.

# In OpenSSL builds add -ldl if you get unresolved references for
# dlopen, dlclose, dlsym, and/or dlerror.
#
# In order to build a secure version of Kermit, you need to know the location
# of the header (include) files and libraries for the desired form of
# security.  Unless you specify a location, this makefile looks in /usr/local
# and if the required files are not found, the build fails.
#
# If the secure headers and libraries are not on your computer, you have
# to download and install them, for example from http://www.openssl.org .
#
# The following symbols are used to specify library and header file locations:
# 
prefix  = /usr/local
srproot = $(prefix)
sslroot = $(prefix)
manroot = $(prefix)

K4LIB=-L/usr/kerberos/lib
K4INC=-I/usr/kerberos/include
K5LIB=-L/usr/kerberos/lib
K5INC=-I/usr/kerberos/include
SRPLIB=-L$(srproot)/lib
SRPINC=-I$(srproot)/include
SSLLIB=-L$(sslroot)/ssl/lib
SSLINC=-I$(sslroot)/ssl/include

# To override these assignments; for example, if your OpenSSL files are
# not in /usr/local/ssl, invoke the desired target like this:
# 
#  make solaris9+openssl "SSLINC=-I/opt/openssl-0.9.8k/include" \
#   "SSLLIB=-L/opt/openssl-0.9.8k/lib"
#
# (don't set the variables and then do "make -e" because that breaks 
# chaining of makefile targets.)
#
# Here are some up-to-date secure targets as of Sep 2009: 
#
# aix+openssl:                        IBM AIX 4.2 or later with OpenSSL
# freebsd44+srp+openssl               FreeBSD 4.4 with SRP and OpenSSL
# freebsd50+openssl                   FreeBSD 5.0 with OpenSSL
# hpux1100o+openssl:                  HP-UX 11.xx with OpenSSL
# hpux1000gcc+openssl:                HP-UX 10.xx with OpenSSL (build with gcc)
# hpux1100gcc+openssl:                HP-UX 11.xx with OpenSSL (build with gcc)
# irix6x+krb5:                        IRIX 6.x with Kerberos V
# irix65+krb5:                        etc etc...
# solaris9+openssl                    Solaris 9,10, or 11 with Openssl (Sun cc)
# solaris9g+openssl                   Solaris 9,10, or 11 with Openssl (gcc)
# linux+ssl                           OpenSSL only
# linux+krb5+ssl                      Linux with Kerberos 5 and OpenSSL
# linux+krb5:                         Kerberos 5 only
# 
# The following secure Linux targets have not been updated or tested recently.
# linux+krb5+krb4:
# linux+srp:
# linux+srp+pam:
# linux+srp+gmp:
# linux+srp+gmp+no-des:
# linux+srp+gmp-export:
# linux+srp+gmp+pam:
# linux+shadow+pam:
# linux+openssl:
# linux+openssl+shadow:
# linux+openssl+zlib+shadow+pam:
# linux+srp+openssl:
# linux+krb5+krb4+srp:
# linux+krb5+krb4+srp+openssl:
# linux+krb5+krb4+openssl:
# linux+krb5+krb4+openssl+shadow:
# linux+krb5+krb4+openssl+zlib+shadow:
# linux+krb5+krb4+srp-export:
# linux+krb5+krb4+srp+pam:
# linux+krb5+krb4+srp+openssl+pam-debug:
# linux+krb5+krb4+srp+openssl+pam:
# linux+krb5+krb4+srp+openssl+zlib+pam:
# linux+krb5+krb4+openssl+shadow+pam:
# linux+krb5+openssl+zlib+shadow+pam:
# 
# The following have not been tested recently either and might
# need adjustment.
#
# macosx+krb5+ssl:     Mac OS X 10.3.9 or later + OpenSSL and Kerberos 5
# macosx103+secure:    This one is probably redundant
# netbsd+openssl:      NetBSD with OpenSSL
# openbsd30+ssl:       OpenBSD 3.0 with OpenSSL
# redhat71,redhat72,redhat73,redhat80,redhat9 (Krb5,OpenSSL,Showdow,PAM,Zlib)
# sco32v500net+ssl:
# sco32v505net+ssl:
# solaris2x+krb4:
# solaris2xg+krb4:
# solaris2xg+openssl+pam+shadow:
# solaris2xg+openssl+zlib+pam+shadow:
# solaris2xg+krb5+krb4+openssl+shadow:
# solaris25+krb4:
# solaris25g+krb4:
# solaris26g+openssl:
# solaris8g+openssl+zlib+pam+shadow:
# solaris8g+krb4:
# solaris9g+openssl+zlib+pam+shadow:
# solaris9g+openssl+shadow+pam+zlib
# sunos41gcc+krb4:                    SunOS 4.1 built with gcc with Kerberos IV
# sunos41gcc+openssl:                 SunOS 4.1 built with gcc with OpenSSL
# sunos41gcc+krb4+openssl:            ...with Kerberos IV and OpenSSL
# sunos41gcc+krb4+openssl+zlib:       ditto, plus ZLIB compression
# sunos41gcc+krb4+srp+openssl+zlib:   ditto, plus SRP
# sunos41gcc+srp+openssl+zlib:
# tru64-51b-openssl:                  Tru64 (Digital) Unix 5.1B with OpenSSL
# uw7ssl                              Unixware 7 with SSL
#
###########################################################################
#
#  Compile and Link variables:
#
#  EXT is the extension (file type) for object files, normally o.
#  See MINIX entry for what to do if another filetype must be used.
#
EXT=o
#LNKFLAGS=
SHAREDLIB=
CC= cc
CC2= cc
MAKE= make
SHELL=/bin/sh

###########################################################################
# (Ancient) UNIX V7-specific variables.
# These are set up for Perkin-Elmer 3230 V7 Unix:
#
PROC=proc
DIRECT=
NPROC=nproc
NPTYPE=int
BOOTFILE=/edition7
#
# ( For old Tandy TRS-80 Model 16A or 6000 V7-based Xenix, use PROC=_proc,
#   DIRECT=-DDIRECT, NPROC=_Nproc, NPTYPE=short, BOOTFILE=/xenix )
#

###########################################################################
# SAMPLE INSTALLATION SCRIPT
#
# Modify to suit your own computer's file organization and permissions.  If
# you don't have write access to the destination directories, "make install"
# fails.  In most cases, a real installation also requires you to chown /
# chgrp the Kermit binary for the UUCP lockfile and/or tty devices, and
# perhaps also to chmod +s the corresponding permission fields.
#
# Default binary, man, and doc directories are supplied below.  You can
# override them in your 'make' command.  Examples:
#
#   make install                                   # Accept defaults.
#   make "INFODIR=/usr/share/lib/kermit" install   # Override INFODIR default.
#
# You can also build and install in one step, e.g.:
#
#   make linux install
#
# If you use the 'install' target to install C-Kermit, it creates an
# UNINSTALL script that can be used to uninstall it.
#
WERMIT = makewhat
BINARY = wermit
DESTDIR =
BINDIR = $(prefix)/bin
MANDIR = $(manroot)/man/man1
MANEXT = 1
SRCDIR =
INFODIR =
CERTDIR =

TEXTFILES = COPYING.TXT ckcbwr.txt ckubwr.txt ckuins.txt ckccfg.txt \
		ckcplm.txt ckermit.ini ckermod.ini ckermit70.txt ckermit80.txt

ALL = $(WERMIT)

all: $(ALL)

.c.o:
	$(CC) $(CFLAGS) -DKTARGET=\"$(KTARGET)\" -c $<

#Clean up intermediate and object files
clean:
	@echo 'Removing object files...'
	-rm -f ckcmai.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckcpro.$(EXT) ckcfns.$(EXT) \
ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) ckucon.$(EXT) ckutio.$(EXT) \
ckufio.$(EXT) ckudia.$(EXT) ckuscr.$(EXT) ckwart.$(EXT) ckuusx.$(EXT) \
ckuusy.$(EXT) ckcnet.$(EXT) ckuus6.$(EXT) ckuus7.$(EXT) ckusig.$(EXT) \
ckucns.$(EXT) ckcmdb.$(EXT) ckuath.$(EXT) ckctel.$(EXT) ckclib.$(EXT) \
ckcuni.$(EXT) ck_crp.$(EXT) ck_ssl.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) \
ckcpro.c wart

show:
	@echo prefix=$(prefix)
	@echo srproot=$(srproot)
	@echo sslroot=$(sslroot)
	@echo manroot=$(manroot)
	@echo K4LIB=$(K4LIB)
	@echo K4INC=$(K4INC)
	@echo K5LIB=$(K5LIB)
	@echo K5INC=$(K5INC)
	@echo SRPLIB=$(SRPLIB)
	@echo SRPINC=$(SRPINC)
	@echo SSLLIB=$(SSLLIB)
	@echo SSLINC=$(SSLINC)
	@exit

# Install C-Kermit after building -- IMPORTANT: Read the instructions above
# (SAMPLE INSTALLATION SCRIPT).  For SSL/TLS versions, ca_certs.pem file
# should be installed in the appropriate place for your OpenSSL library, e.g.:
#
#   cp ca_certs.pem /usr/local/ssl/
#   cp ca_certs.pem /usr/share/ssl/
#
# To make sure 'man' notices the new source file and doesn't keep
# showing the old formatted version, remove the old formatted version,
# something like this:
#		rm -f $(MANDIR)/../cat$(MANEXT)/kermit.$(MANEXT)
# or this (which requires CATDIR to be defined):
#		rm -f $(CATDIR)/kermit.$(MANEXT)
#
# As of C-Kermit 8.0.205 this target also builds an UNINSTALL script, and
# so it might be too long for some old Bourne shells, in which case you can
# use a different shell:
#
#   make SHELL=ksh install
#   make SHELL=/bin/posix/sh install
#
install:
	@echo Installing C-Kermit version $(CKVER)...;\
	rm -f UNINSTALL;\
	exec 3>./UNINSTALL;\
	echo "# C-Kermit UNINSTALL script" >&3;\
	echo "# `date`\n" >&3;\
	echo "CKVER=$(CKVER)" >&3;\
	echo "PrN Uninstalling C-Kermit version $(CKVER)..." >&3;\
	echo DESTDIR=$(DESTDIR);\
	if test -n "$(DESTDIR)"; then\
		if test -d $(DESTDIR); then\
			echo  "$(DESTDIR) exists...\n";\
		else\
			echo "Creating $(DESTDIR)...";\
			DESTDIR=`echo $(DESTDIR) | sed 's!/*$$!!'`;\
			mkdir $$DESTDIR  || exit 1;\
		fi;\
		chmod 755 $(DESTDIR) || exit 1;\
	fi;\
	echo BINARY=$(BINARY);\
	if test -f $(BINARY); then\
		ls -l $(BINARY);\
	else\
		echo "?$(BINARY) not found";\
		exit 1;\
	fi;\
	if test -z "$(DESTDIR)$(BINDIR)"; then\
		echo "Binary directory not specified";\
		exit 1;\
	fi;\
	if test -d $(DESTDIR)$(BINDIR); then\
		echo  "$(DESTDIR)$(BINDIR) exists...";\
	else\
		echo "Creating $(DESTDIR)$(BINDIR)/...";\
		mkdir     $(DESTDIR)$(BINDIR) || exit 1;\
		chmod 755 $(DESTDIR)$(BINDIR);\
	fi;\
	rm -f $(DESTDIR)$(BINDIR)/kermit;\
	cp $(BINARY) $(DESTDIR)$(BINDIR)/kermit || exit 1;\
	chmod 755    $(DESTDIR)$(BINDIR)/kermit || exit 1;\
	rm -f        $(DESTDIR)$(BINDIR)/kermit-sshsub;\
	ln -s        $(DESTDIR)$(BINDIR)/kermit\
		     $(DESTDIR)$(BINDIR)/kermit-sshsub || exit 1;\
	echo 'set flag=f\nPrC Removing binaries' >&3;\
	echo "RmF $(DESTDIR)$(BINDIR)/kermit-sshsub" >&3;\
	echo "RmF $(DESTDIR)$(BINDIR)/kermit" >&3;\
	if test -f ckermit.ini; then\
		echo "#!$(BINDIR)/kermit" >\
			$(DESTDIR)$(BINDIR)/_tmp.ini;\
		cat ckermit.ini >> $(DESTDIR)$(BINDIR)/_tmp.ini;\
		mv $(DESTDIR)$(BINDIR)/_tmp.ini\
		   $(DESTDIR)$(BINDIR)/ckermit.ini;\
		chmod 755 $(DESTDIR)$(BINDIR)/ckermit.ini;\
		echo "RmF $(DESTDIR)$(BINDIR)/ckermit.ini" >&3;\
	fi;\
	echo;\
	echo 'EfM' >&3;\
	echo "Kermit binary installed:";\
	ls -l $(DESTDIR)$(BINDIR)/kermit\
	      $(DESTDIR)$(BINDIR)/kermit-sshsub\
	      $(DESTDIR)$(BINDIR)/ckermit.ini;\
	echo;\
	echo " WARNING: If C-Kermit is to be used for dialing out,";\
	echo " you must change its owner and group and permissions";\
	echo " to match the 'cu' program.  See the ckuins.txt file";\
	echo " for details.";\
	echo;\
	echo MANDIR=$(MANDIR);\
	if test -n "$(DESTDIR)$(MANDIR)"; then\
		if test -d $(DESTDIR)$(MANDIR); then\
			echo  "$(DESTDIR)$(MANDIR) exists...";\
		else\
			echo "Creating $(MANDIR)...";\
			mkdir $(MANDIR) || exit 1;\
			chmod 755 $(MANDIR) || exit 1;\
		fi;\
		rm -f $(DESTDIR)$(MANDIR)/kermit.$(MANEXT);\
		cp ckuker.nr $(DESTDIR)$(MANDIR)/kermit.$(MANEXT) || exit 1;\
		chmod 644 $(DESTDIR)$(MANDIR)/kermit.$(MANEXT) || exit 1;\
		echo 'set flag=f\nPrC Removing man pages' >&3;\
		echo "RmF $(DESTDIR)$(MANDIR)/kermit.$(MANEXT)" >&3;\
		echo 'EfM' >&3;\
		echo;\
	else\
		echo "Not installing man page!\n";\
	fi;\
	echo CERTDIR=$(CERTDIR);\
	if test -n "$(CERTDIR)"; then\
		if test -f ca_certs.pem; then\
			if test -d $(CERTDIR); then\
				echo  "$(CERTDIR) exists...";\
			else\
				echo "Creating $(CERTDIR)...";\
				mkdir $(CERTDIR) || exit 1;\
				chmod 755 $(CERTDIR) || exit 1;\
			fi;\
			echo "Installing certificates file...";\
			cp ca_certs.pem $(CERTDIR) || exit 1;\
			echo 'set flag=f' >&3;\
			echo 'PrC Removing certificates file' >&3;\
			echo "RmF $(CERTDIR)/ca_certs.pem" >&3;\
			echo 'EfM' >&3;\
			echo;\
		fi;\
	else\
		echo "Not installing certificates file!\n";\
	fi;\
	echo SRCDIR=$(DESTDIR)$(SRCDIR);\
	if test -n "$(SRCDIR)"; then\
		echo "Installing source files...";\
		if test -d $(DESTDIR)$(SRCDIR); then\
			echo  "$(DESTDIR)$(SRCDIR) exists...";\
		else\
			echo "Creating $(DESTDIR)$(SRCDIR)/...";\
			mkdir     $(DESTDIR)$(SRCDIR) || exit 1;\
			chmod 755 $(DESTDIR)$(SRCDIR);\
		fi;\
		echo "Copying source files to $(DESTDIR)$(SRCDIR)...";\
		echo 'set flag=f\nPrC Removing source files' >&3;\
		for TextFile in COPYING.TXT ck[cuw_]*.[cwh] makefile; do\
			cp $$TextFile $(DESTDIR)$(SRCDIR)/ && echo ".\c";\
			echo "RmF $(DESTDIR)$(SRCDIR)/$$TextFile" >&3;\
		done; echo;\
		echo 'EfM' >&3;\
		( cd $(DESTDIR)$(SRCDIR)/ &&\
		ls -l COPYING.TXT ck[cuw_]*.[cwh] makefile );echo;\
	else\
		echo "Not installing source code!\n";\
	fi;\
	echo INFODIR=$(DESTDIR)$(INFODIR);\
	if test -n "$(INFODIR)"; then\
		echo "Installing info files...";\
		if test -d $(DESTDIR)$(INFODIR); then\
			echo  "$(DESTDIR)$(INFODIR) exists...";\
		else\
			echo "Creating $(DESTDIR)$(INFODIR)/...";\
			mkdir     $(DESTDIR)$(INFODIR) || exit 1;\
			chmod 755 $(DESTDIR)$(INFODIR);\
		fi;\
		echo "Copying text files to $(DESTDIR)$(INFODIR)...";\
		echo 'set flag=f\nPrC Removing text files' >&3;\
		FileCopyList='';\
		for TextFile in $(TEXTFILES); do\
			test -f $$TextFile || continue;\
			cp $$TextFile $(DESTDIR)$(INFODIR) && echo ".\c" &&\
			FileCopyList="$$FileCopyList $$TextFile";\
			echo "RmF $(DESTDIR)$(INFODIR)/$$TextFile" >&3;\
		done; echo;\
		echo 'EfM' >&3;\
		( cd $(DESTDIR)$(INFODIR)/ && chmod  644   $$FileCopyList );\
		( cd $(DESTDIR)$(INFODIR)/ && pwd && ls -l $$FileCopyList );\
	else\
		echo "Not installing text files!\n";\
	fi;\
	echo "set flag=d\nPrN Removing empty dirs..." >&3;\
	echo "RmD $(DESTDIR)$(BINDIR)" >&3;\
	echo "RmD $(DESTDIR)$(SRCDIR)" >&3;\
	echo "RmD $(DESTDIR)$(INFODIR)" >&3;\
	echo "RmD $(CERTDIR)" >&3;\
	echo "RmD $(MANDIR)" >&3;\
	echo "RmD $(DESTDIR)" >&3;\
	echo "EfM" >&3;\
	echo "PrN C-Kermit version $(CKVER) is uninstalled!" >&3;\
	echo C-Kermit version $(CKVER) installed!

# UN-Install C-Kermit after building
# Please to not remove the extra blanks before and after '{}' within the
# functions. You would get syntax errors for some older Bourne shells! Best is 
# you don't change or remove anything.
#
uninstall:
	@if test ! -f UNINSTALL; then\
		echo "?C-Kermit UNINSTALL data file not found!";\
		exit 1;\
	fi; \
	X=`grep '^CKVER='$(CKVER)'$$' ./UNINSTALL || :`;\
	if test -z "$$X"; then\
		echo "?UNINSTALL file is not for C-Kermit version $(CKVER)";\
		exit 2;\
	fi;\
	PrN () { echo "$$*"; };\
	PrC () { echo "$$* \c"; };\
	RmF () { test -f "$$1" && rm -f "$$1" && echo ".\c" && flag=F ; };\
	RmD () { \
	dir=$$1;\
	while test -d "$$dir"; do\
		rmdir "$$dir" 2>&- || return && echo "$$dir" && flag=D;\
		dir=`echo "$$dir" | sed 's!/[^/]*/*$$!!'`;\
	done; \
	};\
	EfM () { \
	case "$$flag" in\
		f) echo "- Nothing to remove!";;\
		d) echo "Nothing to remove!";;\
		F) echo " done";;\
		D) echo "done";;\
	esac; \
	};\
	while read Act Args; do\
		case $$Act in\
			EfM) EfM;;\
			RmD) RmD $$Args;;\
			RmF) RmF $$Args;;\
			PrN) PrN $$Args;;\
			PrC) PrC $$Args;;\
			set) eval $$Args;;\
		esac;\
	done < ./UNINSTALL

makewhat:
	@echo 'make what?  You must tell which platform to make C-Kermit for.'
	@echo Examples: make linux, make aix, make solaris10, make hpux1100.
	@echo Please read the comments at the beginning of the makefile.

###########################################################################
#
# Dependencies Section:

wermit:	ckcmai.$(EXT) ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) ckcpro.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckucon.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT)
	$(CC2) $(LNKFLAGS) -o wermit \
		ckcmai.$(EXT) ckclib.$(EXT) ckutio.$(EXT) ckufio.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckcpro.$(EXT) ckucmd.$(EXT) ckuus2.$(EXT) ckuus3.$(EXT) \
		ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) ckuus7.$(EXT) \
		ckuusx.$(EXT) ckuusy.$(EXT) ckuusr.$(EXT) ckucon.$(EXT) \
		ckudia.$(EXT) ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) \
		ckusig.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) \
		$(LIBS)

# Preferred configuration with select()-based CONNECT

xermit:	ckcmai.$(EXT) ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) ckcpro.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckucns.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) ckuath.$(EXT) \
		ck_crp.$(EXT) ck_ssl.$(EXT)
	$(CC2) $(LNKFLAGS) -o wermit \
		ckcmai.$(EXT) ckclib.$(EXT) ckutio.$(EXT) ckufio.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckcpro.$(EXT) ckucmd.$(EXT) ckuus2.$(EXT) ckuus3.$(EXT) \
		ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) ckuus7.$(EXT) \
		ckuusx.$(EXT) ckuusy.$(EXT) ckuusr.$(EXT) ckucns.$(EXT) \
		ckudia.$(EXT) ckuscr.$(EXT) ckcnet.$(EXT) ckusig.$(EXT) \
		ckctel.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) \
		ckuath.$(EXT) ck_crp.$(EXT) ck_ssl.$(EXT) $(LIBS)

# Malloc Debugging version

mermit:	ckcmdb.$(EXT) ckcmai.$(EXT) ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckcpro.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) \
		ckuxla.$(EXT) ckucon.$(EXT) ckutio.$(EXT) ckufio.$(EXT) \
		ckudia.$(EXT) ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) \
		ckusig.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT)
	$(CC2) $(LNKFLAGS) -o mermit ckcmdb.$(EXT) ckclib.$(EXT) ckcmai.$(EXT)\
		ckutio.$(EXT) ckufio.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) \
		ckcfn3.$(EXT) ckuxla.$(EXT) ckcpro.$(EXT) ckucmd.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckuusr.$(EXT) ckucon.$(EXT) ckudia.$(EXT) ckuscr.$(EXT) \
		ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) ckcuni.$(EXT) \
		ckupty.$(EXT) ckcftp.$(EXT) $(LIBS)

# Kerberized Version - Subject to USA export restrictions.

# NOTE: We don't use this any more -- As of 15 Feb 2003, the "xermit"
# target is used for both secure and regular version.

krbmit:	ckcmai.$(EXT) ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) ckcpro.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckucns.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckuath.$(EXT) ck_crp.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) \
		ckcftp.$(EXT) ck_ssl.$(EXT)
	$(CC2) $(LNKFLAGS) -o krbmit ckcmai.$(EXT) ckclib.$(EXT) \
		ckutio.$(EXT) ckufio.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) \
		ckcfn3.$(EXT) ckuxla.$(EXT) ckcpro.$(EXT) ckucmd.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckuusr.$(EXT) ckucns.$(EXT) ckudia.$(EXT) ckuscr.$(EXT) \
		ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) ckuath.$(EXT) \
		ck_crp.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) \
		ck_ssl.$(EXT) $(LIBS)

krbmit-debug:	ckcmai.$(EXT) ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckcpro.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) \
		ckuxla.$(EXT) ckucns.$(EXT) ckutio.$(EXT) ckufio.$(EXT) \
		ckudia.$(EXT) ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) \
		ckusig.$(EXT) ckuath.$(EXT) ck_crp.$(EXT) ckcuni.$(EXT) \
		ckupty.$(EXT) ck_ssl.$(EXT) ckcmdb.$(EXT) ckcftp.$(EXT)
	$(CC2) $(LNKFLAGS) -o krbmit ckcmdb.$(EXT) ckcmai.$(EXT) \
		ckclib.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckcfns.$(EXT) \
		ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) ckcpro.$(EXT) \
		ckucmd.$(EXT) ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) \
		ckuus5.$(EXT) ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) \
		ckuusy.$(EXT) ckuusr.$(EXT) ckucns.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckuath.$(EXT) ck_crp.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) \
		ckcftp.$(EXT) ck_ssl.$(EXT) $(LIBS)

# SRP(TM) Version - Subject to USA export restrictions.

srpmit:	ckcmai.$(EXT) ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) ckcpro.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckucns.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckuath.$(EXT) ck_crp.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) \
		ckcftp.$(EXT) ck_ssl.$(EXT)
	$(CC2) $(LNKFLAGS) -o srpmit ckcmai.$(EXT) ckclib.$(EXT) \
		ckutio.$(EXT) ckufio.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) \
		ckcfn3.$(EXT) ckuxla.$(EXT) ckcpro.$(EXT) ckucmd.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckuusr.$(EXT) ckucns.$(EXT) ckudia.$(EXT) ckuscr.$(EXT) \
		ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) ckuath.$(EXT) \
		ck_crp.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ck_ssl.$(EXT) \
		ckcftp.$(EXT) $(LIBS)

# Kerberized Version - Not subject to USA export restrictions.

krbmit-export:	ckcmai.$(EXT) \
		ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) ckcpro.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckucns.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckuath.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT)
	$(CC2) $(LNKFLAGS) -o krbmit-export ckcmai.$(EXT) ckclib.$(EXT) \
		ckutio.$(EXT) ckufio.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) \
		ckcfn3.$(EXT) ckuxla.$(EXT) ckcpro.$(EXT) ckucmd.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckuusr.$(EXT) ckucns.$(EXT) ckudia.$(EXT) ckuscr.$(EXT) \
		ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) ckuath.$(EXT) \
		ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) $(LIBS)

# SRP(TM) Version - Not subject to USA export restrictions.

srpmit-export:	ckcmai.$(EXT) \
		ckclib.$(EXT) ckucmd.$(EXT) ckuusr.$(EXT) ckuus2.$(EXT) \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) ckcpro.$(EXT) \
		ckcfns.$(EXT) ckcfn2.$(EXT) ckcfn3.$(EXT) ckuxla.$(EXT) \
		ckucns.$(EXT) ckutio.$(EXT) ckufio.$(EXT) ckudia.$(EXT) \
		ckuscr.$(EXT) ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) \
		ckuath.$(EXT) ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT)
	$(CC2) $(LNKFLAGS) -o srpmit-export ckcmai.$(EXT) ckclib.$(EXT) \
		ckutio.$(EXT) ckufio.$(EXT) ckcfns.$(EXT) ckcfn2.$(EXT) \
		ckcfn3.$(EXT) ckuxla.$(EXT) ckcpro.$(EXT) ckucmd.$(EXT) \
		ckuus2.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
		ckuus6.$(EXT) ckuus7.$(EXT) ckuusx.$(EXT) ckuusy.$(EXT) \
		ckuusr.$(EXT) ckucns.$(EXT) ckudia.$(EXT) ckuscr.$(EXT) \
		ckcnet.$(EXT) ckctel.$(EXT) ckusig.$(EXT) ckuath.$(EXT) \
		ckcuni.$(EXT) ckupty.$(EXT) ckcftp.$(EXT) $(LIBS)

###########################################################################
# man page...
#
ckuker.nr:
	@echo This target is obsolete.
	@echo The ckuker.nr file no longer needs any preprocessing.

###########################################################################
# Dependencies for each module...
#
ckcmai.$(EXT): ckcmai.c ckcker.h ckcdeb.h ckcsym.h ckcasc.h ckcnet.h ckcsig.h \
		ckuusr.h ckctel.h ckclib.h

ckclib.$(EXT): ckclib.c ckclib.h ckcdeb.h ckcasc.h ckcsym.h

ckcpro.$(EXT): ckcpro.c ckcker.h ckcdeb.h ckcsym.h ckcasc.h ckclib.h

ckcpro.c: ckcpro.w wart ckcdeb.h ckcsym.h ckcasc.h ckcker.h ckcnet.h ckctel.h \
	 ckclib.h
	./wart ckcpro.w ckcpro.c

ckcfns.$(EXT): ckcfns.c ckcker.h ckcdeb.h ckcsym.h ckcasc.h ckcxla.h ckcuni.h \
		ckuxla.h ckclib.h ckcnet.h

ckcfn2.$(EXT): ckcfn2.c ckcker.h ckcdeb.h ckcsym.h ckcasc.h ckcxla.h \
		ckuxla.h ckctel.h ckclib.h ckcnet.h ckcuni.h

ckcfn3.$(EXT): ckcfn3.c ckcker.h ckcdeb.h ckcsym.h ckcasc.h ckcxla.h \
		ckuxla.h ckclib.h ckcuni.h

ckuxla.$(EXT): ckuxla.c ckcker.h ckcsym.h ckcdeb.h ckcxla.h ckuxla.h ckclib.h \
		 ckcuni.h

ckcuni.$(EXT): ckcuni.c ckcdeb.h ckcker.h ckucmd.h ckcuni.h ckcxla.h ckuxla.h

ckuusr.$(EXT): ckuusr.c ckucmd.h ckcker.h ckuusr.h ckcsym.h ckcdeb.h ckcxla.h \
		ckuxla.h ckcasc.h ckcnet.h ckctel.h ckclib.h ckcuni.h

ckuus2.$(EXT): ckuus2.c ckucmd.h ckcker.h ckuusr.h ckcdeb.h ckcxla.h ckuxla.h \
		ckcasc.h ckcnet.h ckcsym.h ckctel.h ckclib.h ckcuni.h

ckuus3.$(EXT): ckuus3.c ckucmd.h ckcker.h ckuusr.h ckcdeb.h ckcxla.h ckuxla.h \
		ckcasc.h ckcnet.h ckcsym.h ckctel.h ckclib.h ckcuni.h

ckuus4.$(EXT): ckuus4.c ckucmd.h ckcker.h ckuusr.h ckcdeb.h ckcxla.h ckuxla.h \
		ckcasc.h ckcnet.h ckuver.h ckcsym.h ckctel.h ckclib.h ckcuni.h

ckuus5.$(EXT): ckuus5.c ckucmd.h ckcker.h ckuusr.h ckcdeb.h ckcasc.h ckcnet.h \
		 ckcsym.h ckctel.h ckclib.h ckcxla.h ckuxla.h ckcuni.h

ckuus6.$(EXT): ckuus6.c ckucmd.h ckcker.h ckuusr.h ckcdeb.h ckcasc.h ckcnet.h \
		 ckcsym.h ckctel.h ckclib.h

ckuus7.$(EXT): ckuus7.c ckucmd.h ckcker.h ckuusr.h ckcdeb.h ckcxla.h ckuxla.h \
		ckcasc.h ckcnet.h ckcsym.h ckctel.h ckclib.h ckcuni.h

ckuusx.$(EXT): ckuusx.c ckcker.h ckuusr.h ckcdeb.h ckcasc.h ckcsym.h \
		ckcsig.h ckcnet.h ckctel.h ckclib.h ckcxla.h ckuxla.h ckcuni.h

ckuusy.$(EXT): ckuusy.c ckcker.h ckcdeb.h ckcasc.h ckcnet.h ckcsym.h ckctel.h \
		 ckclib.h

ckucmd.$(EXT): ckucmd.c ckcasc.h ckucmd.h ckcdeb.h ckcsym.h ckctel.h ckclib.h

ckufio.$(EXT): ckufio.c ckcdeb.h ckuver.h ckcsym.h ckclib.h \
		ckcxla.h ckuxla.h ckcuni.h

ckutio.$(EXT): ckutio.c ckcdeb.h ckcnet.h ckuver.h ckcsym.h ckctel.h ckclib.h

ckucon.$(EXT): ckucon.c ckcker.h ckcdeb.h ckcasc.h ckcnet.h ckcsym.h ckctel.h \
		 ckclib.h

ckucns.$(EXT): ckucns.c ckcker.h ckcdeb.h ckcasc.h ckcnet.h ckcsym.h ckctel.h \
		 ckclib.h ckcxla.h ckuxla.h ckcuni.h

ckcnet.$(EXT): ckcnet.c ckcdeb.h ckcker.h ckcnet.h ckcsym.h ckcsig.h ckctel.h \
		 ckclib.h

ckctel.$(EXT): ckcsym.h ckcdeb.h ckcker.h ckcnet.h ckctel.h ckclib.h

# ck_off_t: ck_off_t.$(EXT)
#	$(CC) -o ck_off_t ck_off_t.$(EXT)

wart: ckwart.$(EXT)
	$(CC) $(LNKFLAGS) -o wart ckwart.$(EXT) $(LIBS)

ckcmdb.$(EXT): ckcmdb.c ckcdeb.h ckcsym.h ckclib.h

ckwart.$(EXT): ckwart.c

ckudia.$(EXT): ckudia.c ckcker.h ckcdeb.h ckucmd.h ckcasc.h ckcsym.h ckcsig.h \
		ckcnet.h ckctel.h ckclib.h

ckuscr.$(EXT): ckuscr.c ckcker.h ckcdeb.h ckcasc.h ckcsym.h ckcsig.h \
		ckcnet.h ckctel.h ckclib.h

ckusig.$(EXT): ckusig.c ckcasc.h ckcdeb.h ckcker.h ckcnet.h ckuusr.h \
		ckcsig.h ckctel.h ckclib.h

ckcftp.$(EXT): ckcftp.c ckcdeb.h ckcasc.h ckcker.h ckucmd.h ckuusr.h \
		ckcnet.h ckctel.h ckcxla.h ckuxla.h ckcuni.h

ckupty.$(EXT): ckupty.c ckupty.h ckcdeb.h

ckuath.$(EXT): ckuath.c ckcdeb.h ckucmd.h ckuath.h ckuat2.h ckctel.h \
		 ckclib.h ckcnet.h

ck_crp.$(EXT): ck_crp.c ckcdeb.h ckcnet.h ckuath.h ckclib.h

ck_ssl.$(EXT): ck_ssl.c ckcdeb.h ckucmd.h ckuath.h ckuat2.h ckctel.h \
		 ckclib.h ck_ssl.h

###########################################################################
#
# Entries to make C-Kermit for specific systems.
#
# Put the ones that need short makefiles first.

#Apollo Aegis 9.x.  Includes TCP/IP support.
#You can also add processor-dependent optimization switches like -M570.
aegis:
	@echo Making C-Kermit $(CKVER) for Apollo Aegis 9.x...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DNOCSETS -DCK_CURSES -O $(KFLAGS)" \
	"LIBS = -lcurses -ltermcap"

#Apple Mac II, A/UX pre-3.0
#Warning, if "send *" doesn't work, try the auxufs makefile entry below.
aux:
	@echo Making C-Kermit $(CKVER) for Macintosh A/UX...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DAUX -DTCPSOCKET $(KFLAGS) -i -O" "LNKFLAGS = -i"

#Apple Mac II, A/UX pre-3.0, compiled with gcc
auxgcc:
	@echo Making C-Kermit $(CKVER) for Macintosh A/UX...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DAUX -DTCPSOCKET -traditional $(KFLAGS) -i -O" \
	"LNKFLAGS = " "CC = gcc" "CC2 = gcc"

#Apple Mac II, A/UX, pre-3.0, but with ufs file volumes, uses <dirent.h>.
auxufs:
	@echo Making C-Kermit $(CKVER) for Macintosh A/UX...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DAUX -DTCPSOCKET -DDIRENT $(KFLAGS) -i -O" "LNKFLAGS = -i"

#Apple Mac II, A/UX 3.0, compiled with gcc
aux3gcc:
	@echo Making C-Kermit $(CKVER) for Macintosh A/UX 3.0...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DAUX -DHDBUUCP -DLFDEVNO -DTCPSOCKET -DDIRENT $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS = $(LIBS)" \
	"CC=gcc -pipe -traditional" "CC2=gcc -pipe -traditional"

#Apple Mac II, A/UX 3.0, compiled with gcc, uses curses
aux3cgcc:
	@echo Making C-Kermit $(CKVER) for Macintosh A/UX 3.0...
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) aux3gcc \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DCK_CURSES" "LIBS = -lcurses $(LIBS)"

# Tenon MachTen, tested on Apple Powerbook with MachTen 2.1.1.D.
# NOTE: This doesn't do anything about UUCP.  It only works if /usr/spool/uucp
# has permission of 777, and dialout device is world read/writeable.
machten:
	@echo Making C-Kermit $(CKVER) for MachTen...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD43 -DTCPSOCKET -DSIG_V -DNDGPWNAM -DCK_CURSES -O \
	$(KFLAGS)"  "LIBS=-lcurses -ltermcap"

#Bell Labs Research UNIX V10
#Can't add TCP/IP because there is no sockets library.  It would have to
#be done using streams, but there is no code in C-Kermit for that.
#Remove -DNOJC if desired (if your system has csh, ksh, or bash).
bellv10:
	@echo Making C-Kermit $(CKVER) for Bell Labs Research UNIX V10...
	$(MAKE) wermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBELLV10 -DBSD4 -DNDIR -DNOJC -DNOSYSIOCTLH -DNOSETREU \
	-DNOCSETS -MINIDIAL $(KFLAGS)"

# WARNING: The early BSD entries do not build in version 7.0 with the stock
# BSD compiler: "Too many defines".  Unless you can rebuild cpp to have more
# space for defines, these builds must be accomplished by:
# copying the /usr/include tree to someplace else, preprocessing there with cc
# -E -I./include or whatever (plus all the same -D's, adding any necessary
# -U/-D to override the architecture)), renaming the the resulting files back
# to their original names, bringing them back to the original BSD system, and
# running the make target there.  This technique was used for 4.2 and 4.3 BSD
# on a VAX in C-Kermit 7.0 (later, cpp on that machine was rebuilt to allow
# more symbols, so the C-Kermit 8.0 build proceeds normally).

#Berkeley Unix 4.1
bsd41:
	@echo Making C-Kermit $(CKVER) for 4.1BSD...
	$(MAKE) wermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD41" "LIBS = -ljobs"

#Berkeley 4.2, 4.3, also Ultrix-32 1.x, 2.x, 3.x, many others
# Add -O, -s, etc, if they work.
# If you have a version of BSD but signal() is void rather than int,
# "make bsd KFLAGS=-DSIG_V".
bsd42:
	@echo Making C-Kermit $(CKVER) for 4.2BSD...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DNOREALPATH -DNOTIMEH -DNOIKSD \
	-DCK_CURSES -DSYSTIMEBH -DNOPUTENV -DNOANSI -DBIGBUFOK -DBSD42HACK \
	$(KFLAGS)" "LIBS=-lcurses -ltermcap $(LIBS)"

bsd:
	$(MAKE) CC=$(CC) CC2=$(CC2) bsd42 KTARGET=$${KTARGET-$(@)}

#Berkeley Unix 4.2 or 4.3 with HoneyDanBer UUCP
bsdhdb:
	@echo Making C-Kermit $(CKVER) for 4.2BSD with HDB UUCP...
	$(MAKE) CC=$(CC) CC2=$(CC2) bsd KTARGET=$${KTARGET-$(@)} \
	"KFLAGS= -DHDBUUCP $(KFLAGS)"

#Berkeley Unix 4.3 with acucntrl program, curses, TCP/IP included.
bsd43:
	@echo Making C-Kermit $(CKVER) for 4.3BSD...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DBSD43 -DTCPSOCKET -DNOREALPATH -DNOTIMEH -DNOIKSD \
	-DCK_CURSES -DACUCNTRL -DSYSTIMEBH -DNOPUTENV -DNOANSI -DBIGBUFOK \
	-DBSD42HACK $(KFLAGS)" "LIBS=-lcurses -ltermcap $(LIBS)"

#4.3BSD, curses excluded
bsd43nc:
	@echo Making C-Kermit $(CKVER) for 4.3BSD...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DBSD43 -DTCPSOCKET -DNOREALPATH -DNOTIMEH \
	-DACUCNTRL -DSYSTIMEBH -DNOIKSD -DNOPUTENV -DNOANSI -DBIGBUFOK \
	-DBSD42HACK $(KFLAGS)" "LIBS=$(LIBS)"

#4.3BSD, TCP/IP excluded.
bsd43nonet:
	@echo Making C-Kermit $(CKVER) for 4.3BSD + curses...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DBSD43 -DTCPSOCKET -DNOREALPATH -DNOTIMEH -DNOIKSD \
	-DCK_CURSES -DACUCNTRL -DSYSTIMEBH -DNOPUTENV -DNOANSI -DBIGBUFOK \
	-DBSD42HACK -DNONET $(KFLAGS)" "LIBS=-lcurses -ltermcap $(LIBS)"

#Berkeley Unix 4.2 or 4.3 with lock directory /usr/spool/uucp/LCK/LCK..ttyxx,
#but without acucntrl program
bsdlck:
	@echo Making C-Kermit $(CKVER) for 4.2BSD, /usr/spool/uucp/LCK/...
	$(MAKE) CC=$(CC) CC2=$(CC2) bsd KTARGET=$${KTARGET-$(@)} \
	"KFLAGS= -DLCKDIR $(KFLAGS)"

#Berkeley UNIX 4.4-Lite, 4.4-Encumbered, Net/2, etc (Post-Reno),
#with TCP/IP networking.  This was the basis for FreeBSD, NetBSD, OpenBSD,
#BSDI, BSD/OS, and Mac OS X (each of which has its own set of targets that
#are newer than this one).
#
#NOTE: This is not a pure POSIX configuration.  Using -DPOSIX instead of
# -DBSD44 prevents any kind of directory-reading (for wildcard expansion),
#and disallows use of ENOTCONN symbol for detecting broken network
#connections, and disallows RTS/CTS flow control, and would also require
#definition of the appropriate UUCP lockfile convention.
#Do not add -DCK_POSIX_SIG without reading <signal.h> first!  For example,
#sigsetjmp(), etc, tend to be defined but not implemented.
#
#NOTE: originally crypt was in libc - later it was unbundled.
#Remove the LIBS clause to build on an early 4.4BSD platform.
#
bsd44:
	@echo Making C-Kermit $(CKVER) for 4.4BSD...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DTCPSOCKET $(KFLAGS) -O" "LIBS=-lcrypt"

#Berkeley UNIX 4.4, as above, but with curses for fullscreen display
#Please read notes for bsd44 entry just above.
# NOTE: This one dumped core on the real 4.4BSD development system at
# UC Berkeley (an HP-9000/300), so the no-curses version was used
# for that one, which was unplugged years ago.
bsd44c:
	@echo Making C-Kermit $(CKVER) for 4.4BSD with curses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DTCPSOCKET $(KFLAGS) -O" \
	"LIBS= -lcurses -ltermcap -lcrypt $(LIBS)"

#For FreeBSD 1.x.
freebsd1:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DTCPSOCKET -DNOCOTFMC -funsigned-char \
	-DFNFLOAT -DNOHTERMCAP -DNOREALPATH -DNOSYSCONF $(KFLAGS) -O -pipe" \
	"LIBS= -lcurses -ltermcap -lm $(LIBS)"

#FreeBSD 2.x with ncurses
freebsd2:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD 2.x with ncurses...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_NCURSES -DTCPSOCKET -DNOCOTFMC -DUSE_STRERROR \
	-DTPUTSARGTYPE=int -DTPUTSARG1CONST -DFREEBSD2 -funsigned-char \
	-DFNFLOAT $(KFLAGS) -O -pipe" \
	"LIBS= -lncurses -ltermlib -lcrypt -lm $(LIBS)"

#For FreeBSD 2.x -- Uses curses rather than ncurses
freebsd2c:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD 2.x with curses...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DTCPSOCKET -DNOCOTFMC -DUSE_STRERROR \
	-DTPUTSARGTYPE=int -DTPUTSARG1CONST -DFREEBSD2 -DFNFLOAT \
	-funsigned-char $(KFLAGS) -O -pipe" \
	"LIBS= -lcurses -ltermlib -lcrypt -lm $(LIBS)"

#FreeBSD 3.x with ncurses and uu_lock()
#(Note: uu_lock() goes back to 2.2.2, but not necessarily 2.0)
#OK 2011/08/20 FreeBSD 3.3
freebsd3:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD 3.x with ncurses...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_NCURSES -DTCPSOCKET -DNOCOTFMC -funsigned-char \
	-DTPUTSARGTYPE=int -DUSE_STRERROR -DFREEBSD3 -DUSE_UU_LOCK -DFNFLOAT \
	$(KFLAGS) -O -pipe" \
	"LIBS= -lncurses -lcrypt -lutil -lm $(LIBS)"

#As above but with curses rather than ncurses.
freebsd3c:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD 3.x with curses...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DTCPSOCKET -DNOCOTFMC -DUSE_UU_LOCK \
	-DTPUTSARGTYPE=int -DUSE_STRERROR -DFREEBSD3 $(KFLAGS) -DFNFLOAT \
	-funsigned-char -pipe -O" \
	"LIBS= -lcurses -lcrypt -lutil -lm $(LIBS)"

#FreeBSD 4.0 with ncurses and uu_lock().  Note - there is no curses in 4.0.
#ncurses 5.0 is broken requiring us to work around with setbuf().
freebsd40:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD 4.x with ncurses...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_NCURSES -DTCPSOCKET -DNOCOTFMC -DFNFLOAT \
	-funsigned-char -DTPUTSARGTYPE=int -DUSE_STRERROR -DFREEBSD4 \
	-DNONOSETBUF -DUSE_UU_LOCK $(KFLAGS) -O -pipe" \
	"LIBS= -lncurses -lcrypt -lutil -lm $(LIBS)"

#FreeBSD 4.1 and above
#Like FreeBSD 4.0 but without the NONOSETBUF hack and with CK_NEWTERM.
#NOTE: This target definitely does not work for FreeBSD 3.3 in 9.0.302.
#and it has not been tested on 4 or 5.
#OK 2011/06/xx FreeBSD 3.3, 4,4, 4.7, and 8.2
#OK 2011/08/21 FreeBSD 3.3, 4.4, 6.4, 9.0
freebsd freebsd41 freebsd72 freebsd5 freebsd6 freebsd7 freebsd8 freebsd9:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD 4.1 or later...'
	@if test `uname -r | cut -d . -f 1` -ge 8; then \
	   HAVE_FBSD8='-DFREEBSD8'; \
	else HAVE_FBSD8=''; fi; \
	if test `uname -r | cut -d . -f 1` -ge 9; then \
	   HAVE_FBSD9='-DFREEBSD9'; \
	else HAVE_FBSD9='';  fi; \
	if test -f /usr/include/utmpx.h ; \
	then HAVE_UTMPX='-DHAVEUTMPX' ; \
	else HAVE_UTMPX='' ; fi; \
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_NCURSES -DCK_NEWTERM -DTCPSOCKET -DNOCOTFMC \
	-DFREEBSD4 $$HAVE_FBSD8 $$HAVE_FBSD9 -DUSE_UU_LOCK -DFNFLOAT \
	$$HAVE_UTMPX -DHERALD=\"\\\" `uname -rs`\\\"\" \
	-funsigned-char -DTPUTSARGTYPE=int -DUSE_STRERROR $(KFLAGS) \
	-O2 -pipe"\
	"LIBS= -lncurses -lcrypt -lutil -lm $(LIBS)"

#FreeBSD 5.0 or later with OpenSSL.
#OK 2011/06/15 FreeBSD 4.7 and 8.2
#OK 2011/08/20 FreeBSD 9.0-CURRENT
freebsd+ssl freebsd+openssl freebsd50+openssl:
	@echo 'Making C-Kermit $(CKVER) for FreeBSD with Kerberos 5...'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	$(MAKE) freebsd KTARGET=$${KTARGET:-$(@)} "CC = $(CC)" "CC2 = $(CC2)" \
	KFLAGS="-DCK_AUTHENTICATION -DCK_SSL $(SSLINC) -DZLIB $$OPENSSLOPTION \
	$$HAVE_DES $(KFLAGS)"  "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS= -lncurses -lcrypt -lssl -lcrypto -lutil -lm \
	$(SSLLIB) $$DES_LIB $(LIBS)"; \
	if [ ! -f ./wermit ] || [ ./ckcmai.o -nt ./wermit ] ; then \
		echo ""; \
		echo "If build failed try:"; \
		echo ""; \
		echo "  make clean ; make $${KTARGET:-$(@)} KFLAGS=-UCK_DES"; \
		echo ""; \
	fi

#NetBSD 1.4.1 or later with vanity banner automated with uname
#and automatic inclusion of large file support if it is available.
#This target tested successfully on NetBSD 1.4.1, 1.5.2, and 2.0.3 (Jan 2006).
#Fails on NetBSD 2.0 on Sun/3 mc68030 with gcc 3.3.3 unless optimization is
#disabled on ckcfn2.c ("KFLAGS=-O0") (Letter O Digit Zero).
#(This could be automated by testing `uname -m` for "sun3".)
#OK: 2011/06/15 on NetBSD 1.5.2 and 5.1.
#OK: 2011/08/21 on 5.1.
netbsd netbsd2 netbsd15 netbsd16 old-netbsd:
	@echo Making C-Kermit $(CKVER) for NetBSD with curses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS=`grep fseeko /usr/include/stdio.h > /dev/null && \
	echo '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'` \
	-DBSD44 -DCK_CURSES -DTCPSOCKET -DUSE_STRERROR -DHAVE_OPENPTY \
	-funsigned-char -DHERALD=\"\\\" NetBSD `uname -r`\\\"\" \
	-DCK_DTRCD -DCK_DTRCTS -DTPUTSARGTYPE=int -DFNFLOAT $(KFLAGS) -O" \
	"LIBS= -lcurses -lcrypt -lm -lutil $(LIBS)"

#NetBSD 1.4.1 or later with OpenSSL
#OK: 2011/06/15 on NetBSD 5.1 (but not 1.5.2 with OpenSSL 0.9.5a)
#OK: 2011/08/21 on 5.1.
netbsd+ssl netbsd+openssl:
	@echo 'Making C-Kermit $(CKVER) for NetBSD+OpenSSL SSLLIB=$(SSLLIB)'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	$(MAKE) netbsd KTARGET=$${KTARGET:-$(@)} "CC = $(CC)" "CC2 = $(CC2)" \
	"KFLAGS= -DCK_AUTHENTICATION -DCK_ENCRYPTION -DCK_CAST $$HAVE_DES \
	-DCK_SSL -DCK_PAM -DZLIB -DNO_DCL_INET_ATON $$OPENSSLOPTION \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS= -L/usr/pkg/lib -R/usr/pkg/lib -lssl $$DES_LIB -lcurses \
	-lcrypto -lcrypt -lz -lm -lpam -lutil $(LIBS)"

#NetBSD with MIT Kerberos 5:
# OK 2011/06/15 (once K5INC and K5LIB were set right).
# NOT OK for Heimdal - Heimdal Kerberos support in C-Kermit needs work.
# OK: 2011/08/21 on 5.1.
netbsd+krb5:
	@echo 'Making C-Kermit $(CKVER) for NetBSD with Kerberos 5...'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	$(MAKE) netbsd KTARGET=$${KTARGET:-$(@)} "CC = $(CC)" "CC2 = $(CC2)" \
	"KFLAGS= -DCK_AUTHENTICATION -DCK_ENCRYPTION -DCK_KERBEROS -DKRB5 \
	-DCK_CAST $$HAVE_DES -DNOFTP_GSSAPI $(K5INC) $(K5INC)/krb5 \
	$(KFLAGS)" \
	"LIBS= $(K5LIB) -L/usr/pkg/lib -R/usr/pkg/lib -lcurses $$DES_LIB \
	-lcrypto -lgssapi -lkrb5 -lm -lutil $(LIBS)"

# NetBSD - With Kerberos 5 and SSL and Zlib.
# OK: 2011/08/21 on 5.1 with MIT Kerberos.
netbsd+krb5+ssl netbsd+krb5+openssl+zlib:
	@echo 'Making C-Kermit $(CKVER) for NetBSD+OpenSSL+Kerberos5...'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	$(MAKE) netbsd KTARGET=$${KTARGET:-$(@)} "CC = $(CC)" "CC2 = $(CC2)" \
	"KFLAGS= -DCK_AUTHENTICATION -DCK_ENCRYPTION -DCK_CAST $$HAVE_DES \
	-DCK_KERBEROS -DKRB5 -DNOFTP_GSSAPI $(K5INC) $(K5INC)/krb5 \
	-DCK_SSL -DCK_PAM -DZLIB -DNO_DCL_INET_ATON $$OPENSSLOPTION \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS= $(K5LIB) -L/usr/pkg/lib -R/usr/pkg/lib -lssl $$DES_LIB \
	-lcrypto -lcrypt -lgssapi -lkrb5 -lz -lm -lpam -lutil -lcurses $(LIBS)"

#Special Security Enhanced NetBSD target with SRP, SSL, and zlib support.
#To build this, you need to BUILD the pkgsrc srp_client package.  After
#you build it, you must go into work/srp-x.y.z/libkrypto and "bmake install"
#then go to work/srp-x.y.z/libsrp and "bmake install".  As of 2005Q3, the
#pkgsrc install only installed the statically linked client applications.  You
#need to manually install the libraries to build your own applications.
#NOT TESTED RECENTLY - probably needs work.
netbsd+ssl+srp+zlib:
	@echo Making C-Kermit $(CKVER) for NetBSD with curses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DTCPSOCKET -DUSE_STRERROR -DNETBSD15 \
	-DCK_DTRCD -DCK_DTRCTS -DTPUTSARGTYPE=int -DHAVE_OPENPTY \
	-I/usr/include/openssl -I/usr/pkg/include \
	-DCK_AUTHENTICATION -DCK_SRP -DPRE_SRP_1_4_5 -DCK_ENCRYPTION \
	-DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DZLIB -DFNFLOAT $(KFLAGS) -O" \
	"LIBS= -L/usr/pkg/lib -R/usr/pkg/lib -lcurses -lsrp -lgmp -ldes \
	-lssl -lkrypto -lcrypto -lcrypt -lz -lm -lutil $(LIBS)"

#NetBSD with curses left out (e.g. for use as IKSD).
netbsdnc:
	@echo Making C-Kermit $(CKVER) for NetBSD with no curses...
	$(MAKE) CC=$(CC) CC2=$(CC2) netbsd KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOCURSES"

#NetBSD with ncurses requested explicitly rather than curses-which-is-ncurses
netbsdn:
	@echo Making C-Kermit $(CKVER) for NetBSD with curses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS=`grep fseeko /usr/include/stdio.h > /dev/null && \
	echo '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'` \
	-DBSD44 -DCK_CURSES -DTCPSOCKET -DUSE_STRERROR -DHAVE_OPENPTY \
	-DHERALD=\"\\\" NetBSD `uname -r`\\\"\" \
	-DCK_DTRCD -DCK_DTRCTS -DTPUTSARGTYPE=int -DFNFLOAT $(KFLAGS) -O" \
	"LIBS= -L/usr/pkg/lib -lncurses -lcrypt -lm -lutil $(LIBS)"

#OpenBSD before 2.3.
#Uses ncurses as its curses so use -ltermlib, not -ltermcap
#But it doesn't use uu_lock() which was introduced in OpenBSD 2.3.
#For that use the next entry.
#Add -DMAINTYPE=int if you get complaints about main: return type is not int.
openbsdold:
	@echo Making C-Kermit $(CKVER) for OpenBSD...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DCK_NEWTERM -DTCPSOCKET -DOPENBSD \
	-DFNFLOAT -DNDSYSERRLIST $(KFLAGS) -O" "LIBS= -lcurses -ltermlib -lm"

#OpenBSD 2.3 or later
#Add -DMAINTYPE=int if you get complaints about main: return type is not int.
#For C-Kermit 8.0 (Christian Weisgerber):
# -ltermlib removed (presumably because -lcurses==ncurses already includes it)
# -DUSE_UU_LOCK and -lutil added for uu_lock()
# -DNDSYSERRLIST changed to -DUSE_STRERROR
#If this gives you trouble use the previous entry.
#NOTE: The openbsd and openbsd+ssl should be reworked to be like the
#corresponding FreeBSD and NetBSD targets.  The mirbsd targets should
openbsd:
	@echo Making C-Kermit $(CKVER) for OpenBSD 2.3 or later...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DCK_NEWTERM -DTCPSOCKET -DOPENBSD \
	-DHERALD=\"\\\" OpenBSD `uname -r`\\\"\" \
	-DUSE_UU_LOCK -DFNFLOAT -DUSE_STRERROR $(KFLAGS) -O" \
	"LIBS= -lcurses -lutil -lm"

#Better to chain to the openbsd target but...
mirbsd:
	@echo Making C-Kermit $(CKVER) for OpenBSD 2.3 or later...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DCK_NEWTERM -DTCPSOCKET -DOPENBSD \
	-DHERALD=\"\\\" MirBSD `uname -r`\\\"\" \
	-DUSE_UU_LOCK -DFNFLOAT -DUSE_STRERROR $(KFLAGS) -O" \
	"LIBS= -lcurses -lutil -lm"

#OpenBSD 3.0 or later includes OpenSSL
#Add -DMAINTYPE=int if you get complaints about main: return type is not int.
#For C-Kermit 8.0 (Christian Weisgerber):
# -ltermlib removed (presumably because -lcurses==ncurses already includes it)
# -DUSE_UU_LOCK and -lutil added for uu_lock()
# -DNDSYSERRLIST changed to -DUSE_STRERROR
#If this gives you trouble use the previous entry.
openbsd+ssl:
	@echo Making C-Kermit $(CKVER) for OpenBSD 3.0 or later...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DCK_NEWTERM -DTCPSOCKET -DOPENBSD \
	-DHERALD=\"\\\" OpenBSD `uname -r`\\\"\" \
	-DUSE_UU_LOCK -DFNFLOAT -DUSE_STRERROR -DCK_AUTHENTICATION \
	-DCK_SSL $(KFLAGS) -O" \
	"LIBS= -lcurses -lutil -lm -lssl -lcrypto"

mirbsd+ssl:
	@echo Making C-Kermit $(CKVER) for OpenBSD 3.0 or later...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DCK_CURSES -DCK_NEWTERM -DTCPSOCKET -DOPENBSD \
	-DHERALD=\"\\\" MirBSD `uname -r`\\\"\" \
	-DUSE_UU_LOCK -DFNFLOAT -DUSE_STRERROR -DCK_AUTHENTICATION \
	-DCK_SSL -DNO_DCL_INET_ATON $(KFLAGS) -O" \
	"LIBS= -lcurses -lutil -lm -lssl -lcrypto"

# make 386bsd 0.0new, posix
# for  386bsd 0.1.24, change /usr/include/termios.h to #define NCCS if
#  _POSIX_SOURCE is #defined. (source: lewine, posix prgmrs guide, o`reilly)
#NOTE: Lock directory is /var/spool/lock.  Formerly, it was /var/spool/uucp,
#but reportedly <[email protected]> that was due to a typo in 'man tip'.
386bsd:
	@echo 'Making C-Kermit $(CKVER) for jolix 386BSD 0.0new and 0.1.24...'
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DSETREUID -DPIDSTRING -DUSLEEP \
	-D_386BSD -DCK_CURSES -DTCPSOCKET \
	-DLOCK_DIR=\\\"/var/spool/lock\\\" \
	$(KFLAGS) -O" "LNKFLAGS = -s" "LIBS = -lcurses -ltermcap"

# Mac OS X 10 early versions.
# For 10.3.9 and later, use the macosx target below.

#Mac OS X 1.0 (Rhapsody, Darwin) -- TCP/IP but no curses.
oldmacosx10:
	@echo Making C-Kermit $(CKVER) for `uname -s`...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DTCPSOCKET -DUSE_STRERROR -O $(KFLAGS)"

#Mac OS X 1.0 (Rhapsody, Darwin) -- TCP/IP and curses.
#Note: curses must be obtained separately.  See next entry for ncurses.
#Add "LIBS = -lcurses -ltermcap" if necessary (but reportedly it is not).
oldmacosx10c:
	@echo Making C-Kermit $(CKVER) for `uname -s` + curses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DCK_CURSES -DTPUTSFNTYPE=void -DTPUTSISVOID \
	-DTCPSOCKET -DUSE_STRERROR -O $(KFLAGS)"

#Mac OS X 1.0 (Rhapsody, Darwin) -- TCP/IP and ncurses.
#Note: ncurses must be obtained separately.
#In the event of trouble with this one try the next one.
oldmacosx10nc:
	@echo Making C-Kermit $(CKVER) for `uname -s` + ncurses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DCK_NCURSES -DTCPSOCKET -DUSE_STRERROR -O \
	$(KFLAGS)" "LIBS= -lncurses $(LIBS)"

#Mac OS X 10.2 (Jaguar) ncurses.
oldmacosx102nc:
	@echo Making C-Kermit $(CKVER) for `uname -s` + ncurses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DCK_NCURSES -DTCPSOCKET -DUSE_STRERROR -O \
	$(KFLAGS) " "LIBS= -lncurses $(LIBS)"

#The problem here is that if curses.h also exists, it conflicts with
#ncurses.h and and we have fatal errors.  If this happens to you, then
#try this target.
oldmacosx10ncx:
	@echo Making C-Kermit $(CKVER) for `uname -s` + ncurses...
	@rm -f ./curses.h; touch ./curses.h
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DCK_NCURSES -DTCPSOCKET -DUSE_STRERROR \
	-I. -O $(KFLAGS) " \
	"LIBS= -lncurses $(LIBS)"
	@rm -f ./curses.h

#Mac OS X 10.3 (Panther) - Assumes ncurses is installed.
oldmacosx103: 
	@echo Making C-Kermit $(CKVER) for `uname -s` + ncurses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DMACOSX103 -DCK_NCURSES -DTCPSOCKET -DCKHTTP \
	-DUSE_STRERROR -DUSE_NAMESER_COMPAT -O \
	$(KFLAGS) " "LIBS= -lncurses -lresolv $(LIBS)"

#Mac OS X 10.3 (Panther) with Kerberos 5 and SSL, assumes ncurses is installed.
oldmacosx103+secure:
	@echo Making Secure C-Kermit $(CKVER) for `uname -s` + ncurses...
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DMACOSX103 -DCK_NCURSES -DTCPSOCKET \
	-DUSE_STRERROR -DUSE_NAMESER_COMPAT -O -DCK_PAM \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DZLIB \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL \
	$(KFLAGS) " "LIBS= -lssl -lcrypto -lkrb5 -lcom_err \
	-lk5crypto -lgssapi_krb5 -lpam -lncurses -lresolv $(LIBS)"

# THIS IS THE MAIN MAC OS X TARGET (the next one is for Kerberos/SSL builds).
# Use this target for 10.3.9 (or maybe earlier) through 10.6 (maybe later)
# on both Power and Intel architectures.  This one uses utmp.h on 10.4 and
# earlier and utmpx.h on 10.5 onwards.
# Note: Mac OS X 10.5 and earlier are 32-bit; 10.6 and later 64-bit.
# Note 2: As of C-Kermit 9.0 -NOUUCP is included by default because
# Mac OS X doesn't support UUCP.  To undo this, use KFLAGS=-UNOUUCP.
#OK: 2011/06/14 (for 10.4.11, 10.5.8, 10.6.7)
macosx macosx10 macosx10.3.9 macosx10.4 macosx10.5 macosx10.6:
	@MACOSNAME=`/usr/bin/sw_vers -productName`; \
	MACOSV=`/usr/bin/sw_vers -productVersion`; \
	echo Making C-Kermit $(CKVER) for $$MACOSNAME $$MACOSV... ; \
	MACCPU=$$HOSTTYPE; \
	if test `uname -r | cut -d . -f 1` -gt 8; \
	then if test -f /usr/include/utmpx.h ; \
	then HAVE_UTMPX='-DHAVEUTMPX -D_UTMPX_COMPAT' ; \
	else HAVE_UTMPX='' ; fi ; fi; \
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 -DMACOSX103 -DCK_NCURSES -DTCPSOCKET -DCKHTTP \
	-DUSE_STRERROR -DUSE_NAMESER_COMPAT -DNOCHECKOVERFLOW -DFNFLOAT \
	-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $$HAVE_UTMPX \
	-funsigned-char -DNODCLINITGROUPS \
	-DNOUUCP -O -DHERALD=\"\\\" $${MACOSNAME} $${MACOSV}\\\"\" \
	-DCKCPU=\"\\\"$${MACCPU}\\\"\" \
	$(KFLAGS)" "LIBS= -lncurses -lresolv $(LIBS)"

# Mac OS X 10.3.9 or later with Kerberos 5 and OpenSSL...
# NOTE: Apple has removed all support for DES in OpenSSL and Kerberos
#   in Mac OS X 10.6 and later.  The DES flags are included or left out
#   automatically based on the Mac OS X version number.
# See note about UUCP in previous target.
#OK: 2009/11/16 (for 10.3.9, 10.4.11, 10.5.8, 10.6.1)
#OK: 2011/06/14 (for 10.4.11, 10.5.8, 10.6.7)
macosx+krb5+ssl macosx10.5+krb5+ssl macosx10.6+krb5+ssl \
macosx+krb5+openssl macosx10.5+krb5+openssl macosx10.6+krb5+openssl:
	@MACOSNAME=`/usr/bin/sw_vers -productName`; \
	MACOSV=`/usr/bin/sw_vers -productVersion`; \
	echo Making C-Kermit $(CKVER) for $$MACOSNAME $$MACOSV... ; \
	MACCPU=$$HOSTTYPE; \
	if test `uname -r | cut -d . -f 1` -gt 8; \
	then if test -f /usr/include/utmpx.h ; \
	then HAVE_UTMPX='-DHAVEUTMPX -D_UTMPX_COMPAT' ; \
	else HAVE_UTMPX='' ; fi ; fi; \
	if test `uname -r | cut -d . -f 1` -eq 7; \
	then IS_MACOSX103='-DMACOSX103' ; \
	else IS_MACOSX103='' ; fi; \
	case $$MACOSV in \
	  10.[012345].*) HAVE_DES='-DCK_DES -DLIBDES' ;; \
	  *.*) HAVE_DES='' ;; \
	esac ; \
	if test -x /usr/bin/krb5-config ; \
	then HAVE_KRB5CONFIG=`/usr/bin/krb5-config --libs krb5 gssapi` ; \
	else HAVE_KRB5CONFIG='-lgssapi_krb5 -lkrb5 -lk5crypto \
	-lcom_err -lresolv' ; fi; \
	$(MAKE) CC=$(CC) CC2=$(CC2) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMACOSX10 $$IS_MACOSX103 -DCK_NCURSES -DTCPSOCKET \
	-DUSE_STRERROR -DUSE_NAMESER_COMPAT -DNOCHECKOVERFLOW -DFNFLOAT \
	-DCKHTTP -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $$HAVE_UTMPX \
	-DNODCLINITGROUPS -DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DZLIB \
	-DCK_ENCRYPTION -DCK_CAST -DCK_SSL -DOPENSSL_098 $$HAVE_DES \
	-DNOUUCP -DHERALD=\"\\\" $${MACOSNAME} $${MACOSV}\\\"\" \
	-DCKCPU=\"\\\"$${MACCPU}\\\"\" \
	-funsigned-char -O $(KFLAGS)" \
	"LIBS= $$HAVE_KRB5CONFIG -lssl -lcrypto -lpam -lncurses $(LIBS)"

# End of Mac OS X Section

#Acorn RISCiX, based on ...
#Berkeley Unix 4.2 or 4.3 with lock directory /usr/spool/uucp/LCK/LCK..ttyxx,
#but without acucntrl program
riscix:
	@echo Making C-Kermit $(CKVER) for RISCiX, /usr/spool/uucp/LCK..ttyxx
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
		"CFLAGS= -DBSD42 -DBSD4 -DRISCIX -DNOCSETS \
		-DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DDIRENT -DCK_CURSES \
		-DMAXSP=9024 -DMAXRD=9024 -DSBSIZ=9050 -DRBSIZ=9050 \
		-DDFTTY=\\\"/dev/serial\\\" -DNOCSETS -DNOCYRIL \
		-DNOANSI -w -O2 -fomit-frame-pointer" \
		"LIBS= -lcurses -ltermcap " \
		"CC= /usr/ucb/cc" \
		"CC2= /usr/ucb/cc"

#Acorn RISCiX, as above, but using gcc
riscix-gcc:
	@echo Making C-Kermit $(CKVER) for RISCiX, /usr/spool/uucp/LCK..ttyxx
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
		"CFLAGS= -DBSD42 -DBSD4 -DRISCIX -DNOCSETS \
		-DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DDIRENT -DCK_CURSES \
		-DMAXSP=9024 -DMAXRD=9024 -DSBSIZ=9050 -DRBSIZ=9050 \
		-DDFTTY=\\\"/dev/serial\\\" -DNOCSETS -DNOCYRIL \
		-DNOANSI -w -O2 -fomit-frame-pointer" \
		"LIBS= -lcurses -ltermcap " \
		"CC= gcc -mbsd" \
		"CC2= gcc -mbsd"

#Convergent CTIX 6.4.1
ctix:
	@echo 'Making C-Kermit $(CKVER) for Convergent CTIX 6.4.1'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSVR3 -DDIRENT -DTCPSOCKET -DHDBUUCP -DCK_CURSES \
	-DNONAWS -DNOLEARN -DNOLONGLONG $(KFLAGS) -XO" \
	"LNKFLAGS=-s" "LIBS=-lsocket -lcurses -lc_s"
	mcs -d wermit

# The following makefile entry should work for any Harris Night Hawk system
# (either 88k or 68k based) running release 6.1 or later of the CX/UX
# operating system. This is a POSIX and ANSI-C compliant system which also
# supports BSD networking. (Earlier CX/UX releases will probably work with
# sys5r3, but this has not been verified).
#
cx_ux:
	@echo Making C-Kermit $(CKVER) for Harris Night Hawk CX/UX 6.1 or later
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS=-DPOSIX -DTCPSOCKET -DHDBUUCP -DPID_T=pid_t -DWAIT_T=int \
	-Dd_ino=d_fileno -DUID_T=uid_t -DGID_T=gid_t -DNOLONGLONG \
	$(KFLAGS) -Xa -O3 -g" "LNKFLAGS=-O3"

#Intergraph Clipper, CLIX, job control, HDB UUCP.
clix:
	@echo 'Making C-Kermit $(CKVER) for Intergraph CLIX...'
	$(MAKE) wermit "CC=acc" "CC2=acc" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -w -DSVR3 -DCLIX -DDIRENT -DHDBUUCP -DNOSYSLOG -DUSE_MEMCPY \
	-DNOGETUSERSHELL -DNOREALPATH -DNOLEARN $(KFLAGS) -O" \
	"LNKFLAGS=" "LIBS= -lbsd"

#As above + TCP/IP...
clixnet:
	@echo 'Making networked C-Kermit $(CKVER) for Intergraph CLIX...'
	$(MAKE) wermit "CC=acc" "CC2=acc" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -w -DSVR3 -DCLIX -DDIRENT -DHDBUUCP -DNOSYSLOG -DUSE_MEMCPY \
	-DTCPSOCKET -DNOGETUSERSHELL -DNOLEARN -DNOREALPATH $(KFLAGS) -O" \
	"LNKFLAGS=" "LIBS= -lbsd"

#Mark Williams Coherent 286 or 386 on IBM PC family.
#There is a 64K limit on program size, so this is a command-line only version.
coherent:
	$(MAKE) "CFLAGS = -O -DCOHERENT -DNOANSI -DNOICP -DNOSETKEY -DNOLEARN \
	-DNOCSETS -DNOHELP -DNODIAL -DNOSCRIPT -DNODEBUG -DNOTLOG -DNOXMIT \
	-DNOMSEND -DNOFRILLS -DNOSYSIOCTLH -DSELECT_H $(KFLAGS) -VSUVAR" \
	-DNOFLOAT KTARGET=$${KTARGET:-$(@)} wermit

#Mark Williams Coherent 386 on IBM PC family.
#This will make a "minimum interactive" version - no scripts,
#no character sets, no help, no dial, no debug/transaction logging, no
#transmit, msend, mail, type, etc.
coherentmi:
	$(MAKE) "CFLAGS = -O -DCOHERENT -DNOANSI -DNOSETKEY -DNOLEARN \
	-DNOSHOW -DNOCSETS -DNOHELP -DNODIAL -DNOSCRIPT -DNODEBUG -DNOTLOG \
	-DNOXMIT -DNOMSEND -DNOFRILLS -DNOSYSIOCTLH -DNOSERVER -DNOUUCP \
	-DNOSPL -DNOPUSH -DNOMDMHUP -DNOJC -DNOFDZERO -DNOESCSEQ -DNOFLOAT \
	-DNOCMDL $(KFLAGS) -VSUVAR -DSELECT_H" KTARGET=$${KTARGET:-$(@)} \
	wermit

#Mark Williams Coherent 386 on IBM PC/AT family.
coherentmax:
	$(MAKE) "CFLAGS = -O -DCOHERENT -DNOANSI -DSELECT_H -DNOLEARN \
	-DNOFLOAT -DNOSYSIOCTLH $(KFLAGS) -VSUVAR" "LNKFLAGS = -O -s" \
	KTARGET=$${KTARGET:-$(@)} wermit

#Mark Williams Coherent 386 4.2.  Includes curses but not TCP/IP.
#Requires updates to the 4.2.10 compiler; the regular compiler fails to
#to handle "complex expressions".  NOFLOAT is so it can work on old PCs
#without floating-point hardware.
coherent42:
	$(MAKE) "CFLAGS = -T500000 -DNOFLOAT -DCOHERENT -DNOANSI -DSELECT \
	-DNOSYSLOG -DDIRENT -DCK_CURSES -DCK_NEWTERM -DCK_WREFRESH -VSUVAR \
	-DDCLGETCWD -DNOSYSIOCTLH -DNOINITGROUPS -DNOSYMLINK -DSELECT_H \
	-DDCLGETCWD -O $(KFLAGS)" \
	"LNKFLAGS = -O -s" KTARGET=$${KTARGET:-$(@)} \
	"LIBS  = -lsocket -lcurses" wermit

#DEC Ultrix 2.x
# Add -O, -DDYNAMIC, -s, etc, if they work.
ultrix2x:
	@echo Making C-Kermit $(CKVER) for Ultrix 2.x ...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DDU2 -DNOGETUSERSHELL $(KFLAGS)"

du2:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET-$(@)} ultrix2x

#DEC Ultrix 3.0 and 3.1
ultrix30:
	@echo Making C-Kermit $(CKVER) for Ultrix 3.0...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DDIRENT -DSIG_V -DNOGETUSERSHELL \
	-DULTRIX3 -DCK_CURSES $(KFLAGS) -O" "LIBS= -lcurses -ltermcap"

du3:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET-$(@)} ultrix30

ultrix3x:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET-$(@)} ultrix30

#DEC Ultrix 4.0 or 4.1 on DECstation, VAXstation, VAX, etc.
ultrix40:
	@echo Making C-Kermit $(CKVER) for Ultrix 4.0 or 4.1...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DSIG_V -DDU4 -DNOGETUSERSHELL \
	$(KFLAGS) -Olimit 1450" "LNKFLAGS = -s"

#DEC Ultrix 4.2-4.5 on DECstation, DECsystem, VAXstation, VAX, etc.
#Like ultrix40, except now C compiler supports -O2 optimization.
ultrix42:
	@echo Making C-Kermit $(CKVER) for Ultrix 4.2 or later...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DSIG_V -DNOGETUSERSHELL $(KFLAGS) \
	-O2 -Olimit 1750" "LNKFLAGS = -s"

du42:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET-$(@)} ultrix42

#DEC Ultrix 4.2-4.5 on DECstation, DECsystem, VAXstation, VAX, etc.
#Like du42, but with curses support added and a couple features.
ultrix42c:
	@echo Making C-Kermit $(CKVER) for Ultrix 4.2 or later...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DSIG_V -DNOGETUSERSHELL \
	-DCK_CURSES -DNOIKSD $(KFLAGS)-G6 -O2 -Olimit 3000 " \
	"LNKFLAGS = -s" "LIBS= -lcurses -ltermcap"

ultrix43:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	"KFLAGS=-DULTRIX43 $(KFLAGS)" KTARGET=$${KTARGET-$(@)} ultrix42c

ultrix43notcp:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	"KFLAGS=-DULTRIX43 -DNONET $(KFLAGS)" \
	KTARGET=$${KTARGET-$(@)} ultrix42c

# NOTE: need -DNODEBUG on MIPS to avoid relocation errors at link time.
# Actually now (8.0) that we have discovered the -G option maybe debugging
# can be put back.
ultrix44:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	"KFLAGS=-DULTRIX44 -G7 -DNODEBUG -DNETPTY -DNO_DEVTTY $(KFLAGS)" \
	KTARGET=$${KTARGET-$(@)} ultrix42c

ultrix45:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	"KFLAGS=-DULTRIX45 $(KFLAGS)-DNETPTY -DNO_DEVTTY $(KFLAGS)" \
	KTARGET=$${KTARGET-$(@)} ultrix42c

du42c:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	KTARGET=$${KTARGET-$(@)} ultrix42c

#DEC Ultrix 4.3A or later on DECsystem and DECstation 5000/50, /150 or /260
#with MIPS R4x00 processor.  The "-mips3" switch generates R4000-specific
#code, which is faster and more compact, but *won't* run on earlier
#DECsystems and DECstations.
ultrix43-mips3:
	@echo Making C-Kermit $(CKVER) for Ultrix 4.3A or later, R4000 cpu...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DSIG_V -DNOGETUSERSHELL \
	$(KFLAGS) -O2 -Olimit 1750 -mips3" "LNKFLAGS = -s -mips3"

du43-mips3:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) ultrix43-mips3

#DEC Ultrix 4.3A or later on MIPS R4x000 based systems.
#Like ultrix43-mips3 but with curses support added
ultrix43c-mips3:
	@echo Making C-Kermit $(CKVER) for Ultrix 4.3A or later, R4000 cpu...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DSIG_V -DNOGETUSERSHELL -DCK_CURSES \
	$(KFLAGS) -O2 -Olimit 3000 -mips3" "LNKFLAGS = -s -mips3" \
	"LIBS= -lcurses -ltermcap"

du43c-mips3:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	KTARGET=$${KTARGET-$(@)} ultrix43c-mips3

#DEC Ultrix 4.4 on DECstation 5000/50 or /150 with R4000 MIPS processor,
#or 5000/260 with R4400.  The "-mips3" switch generates R4000-specific code,
#which is faster and more compact but *won't* run on earlier DECstations.
ultrix44-mips3:
	@echo Making C-Kermit $(CKVER) for Ultrix 4.4, R4000 cpu ...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DSIG_V -DNOGETUSERSHELL \
	$(KFLAGS) -O2 -Olimit 1450 -mips3" "LNKFLAGS = -s -mips3"

du44-mips3:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	KTARGET=$${KTARGET-$(@)} ultrix44c-mips3

#DEC Ultrix 4.2 on DECstation, VAXstation, VAX, etc, System V R4 environment
ultrix42s5r4:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4 on Ultrix...'
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS = -O2 -Olimit 1500 -DSVR4 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DTCPSOCKET $(KFLAGS)" "LNKFLAGS = -s"

#OSF/1
osf osf1:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD4 -DOSF -D_BSD -DTCPSOCKET -DCK_ANSIC -DSIG_V \
	-DCK_CURSES -DCK_RTSCTS -DFNFLOAT $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS = $(LIBS) -lbsd -lcurses -ltermcap -lm"

#DEC OSF/1 V1.0-1.3 on DECstation, VAX, Alpha, or PC.
dec-osf dec-osf1:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD4 -DOSF -DOSF13 -D_BSD -DTCPSOCKET -DCK_ANSIC -DSIG_V \
	-DNOREALPATH -DNOIKSD -DCK_CURSES -DCK_RTSCTS -DFNFLOAT -DNODEBUG \
	-DNOUNICODE $(KFLAGS)" \
	"LNKFLAGS = -non_shared" "LIBS = -lbsd -lcurses -ltermcap -lm"

# This one causes "relocation out-of-range" errors in the linker.
old-dec-osf:
	@echo Making C-Kermit $(CKVER) for DEC OSF/1 V1.x...
	@echo If you are building for DEC OSF/1 2.0, please use dec-osf20.
	@echo Remove or adjust -O2 and/or -Olimit if they cause trouble.
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -O2 -Olimit 2400 $(KFLAGS)"

#DEC OSF/1 2.0 on Alpha and probably nowhere else.
#The only difference from OSF/1 is that optimization is omitted.
#The optimized version gets strange runtime errors, like the PAUSE command
#not working.  Add "-unsigned" to make all chars unsigned.
dec-osf20:
	@echo Making C-Kermit $(CKVER) for DEC OSF/1 V2.0...
	@echo Optimization omitted because it causes runtime errors.
	@echo See comments in makefile.
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF20 $(KFLAGS)"

dec-osf30:
	@echo Making C-Kermit $(CKVER) for DEC OSF/1 V3.0...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF30 -O2 -Olimit 2400 $(KFLAGS)"

#Digital UNIX 3.2
# Must compile ckuus[6x].c separately without optimization otherwise
# the optimizer dumps core - keep CFLAGS here in sync with those from osf.
du32:
	@echo Making C-Kermit $(CKVER) for Digital UNIX 3.2...
	$(MAKE) CC=$(CC) CC2=$(CC2) ckuus6.$(EXT) \
	"CFLAGS= -DBSD4 -DOSF -D_BSD -DTCPSOCKET -DCK_ANSIC -DSIG_V \
	-DCK_CURSES -DCK_RTSCTS -DFNFLOAT -DOSF32 -DHDBUUCP $(KFLAGS)"
	$(MAKE) CC=$(CC) CC2=$(CC2) ckuusx.$(EXT) \
	"CFLAGS= -DBSD4 -DOSF -D_BSD -DTCPSOCKET -DCK_ANSIC -DSIG_V \
	-DCK_CURSES -DCK_RTSCTS -DFNFLOAT -DOSF32 -DHDBUUCP $(KFLAGS)"
	$(MAKE) CC=$(CC) CC2=$(CC2) osf \
	"KFLAGS= -DOSF32 -DHDBUUCP -O2 -Olimit 3200 $(KFLAGS)"

dec-osf32:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) du32 \
	KTARGET=$${KTARGET:-$(@)}

#Digital UNIX 4.0 through 4.0D (use tru64 targets for 4.0E and above)...
du40:
	@echo Making C-Kermit $(CKVER) for Digital UNIX 4.0...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF40 -DHDBUUCP -DFNFLOAT \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)" "LIBS=-lm"

du40gcc:
	@echo Making C-Kermit $(CKVER) for Digital UNIX 4.0 with gcc ...
	$(MAKE) osf CC=gcc CC2=gcc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF40 -DHDBUUCP $(KFLAGS)"

#Tru64 Unix 4.0E
tru64-40e:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 4.0E...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF40 -DOSF40E -DTRU64 -DHDBUUCP -DFNFLOAT -DNOCOTFMC \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)" "LIBS=-lm"

tru64-40f:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 4.0F...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF40 -DOSF40F -DTRU64 -DHDBUUCP -DFNFLOAT -DNOCOTFMC \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)" "LIBS=-lm"

tru64-40g:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 4.0G...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF40 -DOSF40G -DTRU64 -DHDBUUCP -DFNFLOAT -DNOCOTFMC \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)" "LIBS=-lm"

tru64-50a:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 5.0A...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DTRU64 -DOSF50 -DHDBUUCP \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)"

tru64-51a:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 5.1A...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DTRU64 -DOSF50 -DOSF51A -DHDBUUCP \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)"

tru64-51b:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 5.1B...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DTRU64 -DOSF50 -DOSF51A -DOSF51B -DHDBUUCP \
	-unsigned -std1 -O3 -Olimit 2400 $(KFLAGS)"

# Added 5.1b version with OpenSSL - CDW 6-13-2005...
tru64-51b+openssl:
	@echo Making C-Kermit $(CKVER) for Tru64 UNIX 5.1b
	@echo  including OpenSSL...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DTRU64 -DOSF50 -DOSF51A -DOSF51B -DHDBUUCP \
	-unsigned -std1 -O3 -Olimit 2400 \
	-DCK_AUTHENTICATION -DCK_SSL $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -rpath $(sslroot)/ssl/lib -lssl -lcrypto"

du50:
	$(MAKE) CC=$(CC) CC2=$(CC2) tru64-50a KTARGET=$${KTARGET:-$(@)}

du40-ridiculous-checking:
	@echo Making C-Kermit $(CKVER) for Digital UNIX 4.0.
	@echo Checking everything - assumes DECC...
	$(MAKE) CC=$(CC) CC2=$(CC2) osf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= -DOSF40 -DHDBUUCP -w0 -warnprotos -check -portable \
	-unsigned -std1 -O3 -Olimit 1760 $(KFLAGS)"

#Sequent DYNIX/ptx 1.2.1
dynixptx12:
	@echo Making C-Kermit $(CKVER) for Sequent DYNIX/ptx 1.2.1...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -DPTX -DNOGETUSERSHELL -DNOLEARN \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t $(KFLAGS) -i -O" \
	"LNKFLAGS = -i"

#Sequent DYNIX/ptx 1.3 or 1.4
dynixptx13:
	@echo Making C-Kermit $(CKVER) for Sequent DYNIX/ptx 1.3 TCP/IP...
	$(MAKE) xermit "CFLAGS= -O KTARGET=$${KTARGET:-$(@)} \
	-DSVR3 -DDIRENT -DHDBUUCP -DPTX -DCK_POLL -DNOGETUSERSHELL \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t -DTCPSOCKET $(KFLAGS) -i" \
	"LNKFLAGS = -i" "LIBS = -lsocket -linet -lnsl"

#Sequent DYNIX/ptx 2.0, ANSI C compilation
#Should work on any hardware platform when DYNIX/ptx runs, including
#386, 486, Pentium.
dynixptx20:
	@echo 'Making C-Kermit $(CKVER) for POSIX, Sequent DYNIX/ptx 2.0...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DHDBUUCP -DTCPSOCKET \
	-DWAIT_T=int -DPTX -DNOGETUSERSHELL $(KFLAGS) -O" \
	"LIBS = -lsocket -linet -lnsl"

#Sequent DYNIX/ptx 2.0, ANSI C compilation, with curses
dynixptx20c:
	@echo 'Making C-Kermit $(CKVER) for POSIX, Sequent DYNIX/ptx 2.0...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DHDBUUCP -DTCPSOCKET -DWAIT_T=int -DPTX -DCK_CURSES \
	-DCK_NEWTERM -DNOGETUSERSHELL $(KFLAGS) -O" \
	"LIBS = -lsocket -linet -lnsl -lcurses -ltermcap"

#Sequent DYNIX/ptx 2.1.6, 80486, ANSI C compilation, with curses:
# -Xa -- use ANSI compiler.
# -Wc,-pw -- suppress portability warnings.
# -Wc,-i386 -- 80386 cpu.
# -Wc,-i486 -- 80486 cpu.
# -Wc,-P5 -- Pentium (default).
# -Wc,-O3 -- highest optimization.
# -Wa,-N17061 -- increase symbol table from default of 15013 for ckcuni.c.
# Early versions of DYNIX/ptx 2.1.x may need -DCK_POLL instead of -DSELECT.
# Add "$&" after the colon in the "xermit" target for parallel makes.
dynixptx216c:
	@echo 'Making C-Kermit $(CKVER) for POSIX, Sequent DYNIX/ptx 2.1.6'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DHDBUUCP -DDYNAMIC -DTCPSOCKET \
	-DSELECT -DCK_REDIR -DCK_NAWS -DCK_WREFRESH -DSW_ACC_ID \
	-DTCP_NODELAY=1 -DTRMBUFL=2048 -DBIGBUFOK -DHADDRLIST \
	-DPTX  -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL -DNOREALPATH \
	$(KFLAGS) -Xa -Wc,-pw -Wc,-i486 -Wc,-O3 -Wa,-N17061" \
	"LIBS = -lXbsd -lseq -lsocket -linet -lnsl -lmalloc -lm -lcurses" \
	"LNKFLAGS = -s"

#Sequent DYNIX/ptx 2.1.6, gcc 2.7.2.2, with curses:
dynixptx216cgcc:
	@echo 'Making C-Kermit $(CKVER) for POSIX, Sequent DYNIX/ptx 2.1.6 gcc'
	$(MAKE) xermit "CC = gcc" "CC2 = gcc" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DHDBUUCP -DDYNAMIC -DTCPSOCKET \
	-DSELECT -DCK_REDIR -DCK_NAWS -DCK_WREFRESH -DSW_ACC_ID \
	-DTCP_NODELAY=1 -DTRMBUFL=2048 -DBIGBUFOK -DHADDRLIST \
	-DPTX  -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL -DNOREALPATH \
	$(KFLAGS) -O3 -pipe -funsigned-char" \
	"LIBS = -lXbsd -lseq -lsocket -linet -lnsl -lmalloc -lm -lcurses" \
	"LNKFLAGS = -s"

#Sequent DYNIX/ptx 4.0, ANSI C compilation, with curses
dynixptx41c:
	@echo 'Making C-Kermit $(CKVER) for POSIX, Sequent DYNIX/ptx 4.0...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DHDBUUCP -DTCPSOCKET \
	-DWAIT_T=int -DPTX -DPTX4 -DCK_CURSES -DCK_NEWTERM \
	-DNOGETUSERSHELL $(KFLAGS) -O" \
	"LIBS = -lsocket -lnsl -lcurses -ltermcap"

#Sequent DYNIX/ptx 4.4, ANSI C compilation, with curses
dynixptx44:
	@echo 'Making C-Kermit $(CKVER) for POSIX, Sequent DYNIX/ptx 4.4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPTX -DPTX4 -DPOSIX -DHDBUUCP -DTCPSOCKET -DWAIT_T=int \
	-DCK_CURSES -DCK_NEWTERM -DBIGBUFOK -DSELECT -DNOGETUSERSHELL \
	$(KFLAGS) -O" "LIBS = -lsocket -lnsl -lcurses -ltermcap"

#Sequent DYNIX 3.0.x
dynix3:
	@echo Making C-Kermit $(CKVER) for Sequent DYNIX 3.0.x...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD43 -DACUCNTRL -DTCPSOCKET -O \
	-DPWUID_T=int -DGID_T=int $(KFLAGS)"

#Sequent DYNIX 3.0.x, no ACUCNTRL
dynix3noacu:
	@echo Making C-Kermit $(CKVER) for Sequent DYNIX 3.0.x...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD43 -DLCKDIR -DTCPSOCKET -O \
	-DUID_T=int -DGID_T=int $(KFLAGS)"

#Sequent DYNIX 3.1.x
dynix31:
	@echo Making C-Kermit $(CKVER) for Sequent DYNIX 3.1.x...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DDCLPOPEN -DLCKDIR -DBSD4 -DTCPSOCKET $(KFLAGS)"

#Sequent DYNIX 3.1.2, as above but with curses, to be compiled by gcc 2.3.3.
dynix31c:
	@echo 'Making C-Kermit $(CKVER) for Sequent DYNIX 3.1.2, curses...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O2 -DDCLPOPEN -DACUCNTRL \
	-DBSD43 -DTCPSOCKET -DCK_CURSES -DUID_T=int \
	$(KFLAGS)" "LIBS= -lcurses -ltermcap"

#Convex C1 with Berkeley Unix
convex:
	@echo Making C-Kermit $(CKVER) for Convex C1 / BSD...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD4 -DNOLEARN $(KFLAGS) -Dmsleep=mnap"

#Convex C210 with Convex/OS 8
convex8:
	@echo Making C-Kermit $(CKVER) for Convex C210 with OS 8
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DNODEBUG -DDIRENT -DNOFILEH \
	$(KFLAGS) -DSIG_V -Dmsleep=mnap"

#Convex C2 with Convex OS 9.1 (should also work with 8.1 or later)
#with ANSI C compiler, uses BSD 4.3 uucp lockfile convention.
convex9:
	@echo Making C-Kermit $(CKVER) for Convex C210 with OS 9.1
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DCONVEX9 -DNOIEXTEN -DDIRENT -DNOFILEH -DTCPSOCKET \
	-D__STDC__ -DLCKDIR -Dmsleep=mnap -O -ext -tm c1 $(KFLAGS)" \
	"LNKFLAGS = -ext"

#Convex C2 with Convex OS 10.1 or later
#with gcc 2.x C compiler
convex10gcc:
	@echo Making C-Kermit $(CKVER) for Convex C2 with OS 10.1 using gcc
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DCONVEX9 -DNOIEXTEN -DDIRENT -DNOFILEH -DTCPSOCKET \
	-D__STDC__  -Dmsleep=mnap -O2 $(KFLAGS)" CC=gcc CC2=gcc

#Cray X-MP or Y-MP UNICOS 6.x or 7.x.
#NOTE: NPROC tells how many parallel makes to run.  If your Cray has multiple
#processors, you can set NPROC up to the number of CPUs, e.g. NPROC=16.
cray:
	@echo 'Making C-Kermit $(CKVER) for Cray X/Y-MP UNICOS 6.x or 7.0...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} NPROC=1 \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -DTCPSOCKET $(KFLAGS) -O1"

#Cray X-MP or Y-MP UNICOS 8.0 Alpha.
cray8:
	@echo 'Making C-Kermit $(CKVER) for Cray X/Y-MP UNICOS 8.0 Alpha...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} NPROC=1 \
	"CFLAGS= -DSVR4 -DDIRENT -DHDBUUCP -DTCPSOCKET $(KFLAGS) -O1"

#Cray X-MP or Y-MP UNICOS 9.0.
#This one was executed successfully for C-Kermit 8.0.209.
#Earlier versions of Unicos will probably need the same flags.
cray9:
	@echo 'Making C-Kermit $(CKVER) for Cray X/Y-MP UNICOS 9.0...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} NPROC=1 \
	"CFLAGS= -DSVR4 -DDIRENT -DHDBUUCP -DNOLFDEVNO \
	-DTCPSOCKET $(KFLAGS) -O1"

#Cray-2 or Cray 3-CSOS
#NOTE: NPROC tells how many parallel makes to run.  If your Cray has multiple
#processors, you can set NPROC up to the number of CPUs, e.g. NPROC=16.
craycsos:
	@echo 'Making C-Kermit $(CKVER) for Cray-2/3 CSOS
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} NPROC=1 \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -DTCPSOCKET \
	$(KFLAGS) -DCK_ANSIC -DCK_CURSES" "LIBS=-lnet"

#NeXTSTEP 1.0 through 3.2.
#Includes fullscreen file transfer display (curses) and TCP/IP support.
#Uses shared library to make executable program about 80K smaller.
#Remove "LIBS = -lsys_s" if this causes trouble.
next:
	@echo Making C-Kermit $(CKVER) for NeXTSTEP...
	@echo 'If you get errors in ckutio.c about w_S, w_T, etc,'
	@echo 'add KFGLAGS=-DNOREDIRECT to your make command.'
	$(MAKE) xermit CC=$(CC) CC2=$(CC2) KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNEXT -DTCPSOCKET -DLCKDIR -DNOPUTENV -DFNFLOAT \
	-pipe -DCK_CURSES $(KFLAGS) -O -w" "LIBS = -lsys_s -lcurses -ltermcap"

nextc:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) next \
	KTARGET=$${KTARGET:-$(@)}

nextg:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) next \
	KFLAGS=-Wall KTARGET=$${KTARGET:-$(@)}

nextgc:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) next \
	KFLAGS=-Wall KTARGET=$${KTARGET:-$(@)}

#NeXTSTEP 3.3.
#Includes fullscreen file transfer display and TCP/IP.
# You might have to add 1 line to 1 NeXT header file <ip.h>
# to declare n_long as u_long by adding #include <bsd/netinet/in_systm.h>

next33:
	@echo Making C-Kermit $(CKVER) for NeXTSTEP 3.3...
	$(MAKE) xermit CC=$(CC) CC2=$(CC2) KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNEXT33 -DTCPSOCKET -DLCKDIR -DNOPUTENV -DFNFLOAT \
	-pipe -DCK_CURSES $(KFLAGS) -O -w" "LIBS = -lsys_s -lcurses -ltermcap"

#OPENSTEP 4.2 for Sparc, m680x0, HP PA-RISC, and Intel.
#Includes fullscreen file transfer display and TCP/IP.
#ckcpro.c compiled without optimization because it crashes the compiler.
openstep42:
	@echo Making C-Kermit $(CKVER) for OPENSTEP 4.2...
	$(MAKE) ckcpro.$(EXT) \
	"CFLAGS= -DOPENSTEP42 -DNEXT33 -DTCPSOCKET -DLCKDIR -DNOPUTENV \
	-DFNFLOAT -pipe -DCK_CURSES $(KFLAGS) -w"
	$(MAKE) xermit CC=$(CC) CC2=$(CC2) KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DOPENSTEP42 -DNEXT33 -DTCPSOCKET -DLCKDIR -DNOPUTENV \
	-DFNFLOAT -pipe -DCK_CURSES $(KFLAGS) -O -w" \
	"LIBS = -lsys_s -lcurses -ltermcap"

#NeXT with malloc debugger
nextmd:
	@echo Making C-Kermit $(CKVER) for NeXT with malloc debugging...
	$(MAKE) mermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNEXT -DTCPSOCKET -DLCKDIR -DNOPUTENV -DFNFLOAT \
	-DCK_CURSES $(KFLAGS) -O -w -Dmalloc=dmalloc -Dfree=dfree -DMDEBUG" \
	"LIBS = -lsys_s -lcurses -ltermcap"

#Build for NeXTSTEP with "fat" binaries (MABs) that run on both Motorola
#and Intel platforms.
nextfat:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) \
	next KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-Wall -arch m68k -arch i386" "LNKFLAGS = -arch m68k -arch i386"

#NeXTSTEP on Intel Platforms.
next486:
	@echo Making C-Kermit $(CKVER) for NeXTSTEP on Intel Platforms...
	@echo 'If you get errors in ckutio.c about w_S, w_T, etc,'
	@echo 'add KFGLAGS=D-DNOREDIRECT to your make command.'
	$(MAKE) xermit CC=$(CC) CC2=$(CC2) KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNEXT -DTCPSOCKET -DLCKDIR -DNOPUTENV -DFNFLOAT \
	-DNODEBUG -O3 -fno-omit-frame-pointer -fschedule-insns2 -pipe \
	-DCK_CURSES $(KFLAGS) -w" "LIBS = -lsys_s -lcurses -ltermcap"

#Single binary that runs on NeXT 68030 and 68040, Intel, HP, and Sparc,
#as well as on OpenStep/Mach.
nextquadfat:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) next \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-Wall -arch m68k -arch i386 -arch hppa -arch sparc" \
	"LNKFLAGS = -arch m68k -arch i386 -arch hppa -arch sparc"

#BeBox
beboxdr7:
	@echo 'Making C-Kermit $(CKVER) for the BeBox...'
	@echo 'Link step will fail with default Metroworks linker 64K limit.'
	@echo 'Code Warrior Gold required to link big programs.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CC=/boot/develop/tools/mwcc" "CC2=/boot/develop/tools/mwld" \
	"CFLAGS= -DBEBOX -DBE_DR_7 -DPOSIX -DNOUUCP -DNOLEARN $(KFLAGS) -O"

#BeBox BeOS DR7 only
bebox:
	@echo 'Making C-Kermit $(CKVER) for BeBox...'
	@echo 'Link step will fail with default Metroworks linker 64K limit.'
	@echo 'Code Warrior Pro 3.0 for BeBox required to link big programs.'
	$(MAKE) wermit "CC=mwcc" "CC2=mwld" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBEBOX -DPOSIX -DNOLEARN -DNOUUCP $(KFLAGS) -O"

#BeOS 4.5
#We have to use the wermit target because 'fd_set' is unknown.
beos45:
	$(MAKE) wermit "CC=$(CC)" "CC2=$(CC2)" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBEOS -DBEOS45 -DPOSIX -DNOIKSD -DNOREALPATH -DSYSTIMEH \
	-DNOCOTFMC -DNOUUCP -DNOLEARN $(KFLAGS) -O" \
	"LIBS = $(LIBS)"

#BeOS 4.5
beos45net:
	$(MAKE) CC=$(CC) CC2=$(CC2) beos45 \
	"KFLAGS=-DTCPSOCKET -DNO_DNS_SRV $(KFLAGS)" "LIBS=-lnet -lnetapi"

#Plan 9 from Bell Labs
plan9:
	@echo 'C-Kermit for Plan 9 from Bell Labs - calling ckpker.mk...'
	make -f ckpker.mk

#POSIX
posix:
	@echo 'Making C-Kermit $(CKVER) for pure POSIX...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DNOUUCP -DNOLEARN $(KFLAGS) -O"

# PowerMAX OS (SVR4) from Concurrent (tested on PowerMAX 5.1)
powermax:
	@echo 'Making C-Kermit $(CKVER) for Concurrent PowerMAX OS...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DPOWERMAX \
	-DNETPTY -DHAVE_STREAMS -DHAVE_GRANTPT -DHAVE_PTSNAME -DPUSH_PTEM \
	-DPUSH_LDTERM -DPUSH_TTCOMPAT \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lresolv -lcurses -lgen -lc -lucbc"

#Berkeley Software Design Inc. BSDI
# Substitute "LIBS= -lnewcurses -ltermcap" if desired.
bsdi:
	@echo 'Making C-Kermit $(CKVER) for BSDI ...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD44 -DSETREUID -DSW_ACC_ID -DBIGBUFOK -DFIXCRTSCTS \
	-DTCPSOCKET -DCK_CURSES -DFNFLOAT $(KFLAGS) -O" \
	"LIBS= -lcurses -ltermcap -lm"

#Berkeley Software Design Inc. BSDI - has higher serial speeds than 1.x.
bsdi2:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) bsdi \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS=-DBSDI2 $(KFLAGS)"

bsdi3:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) bsdi \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS=-DBSDI2 -DBSDI3 $(KFLAGS)"

bsdi4:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) bsdi \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DBSDI2 -DBSDI3 -DBSDI4 -DTPUTSFNTYPE=void -DTPUTSISVOID \
	-DCKHTTP -m486 $(KFLAGS)"

# (old name for the above)
bsdiposix:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) bsdi


#Build a BSDI 4.x binary that also runs under FreeBSD (Terry Kennedy).
#But watch out for details like serial-port locking.
bsdix:
	$(MAKE) "MAKE=$(MAKE)" CC=$(CC) CC2=$(CC2) bsdi \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DBSDI2 -DBSDI3 -DBSDI4 -DTPUTSFNTYPE=void -DTPUTSISVOID \
	-m486 $(KFLAGS)" "LNKFLAGS=-static -Wl,-m,i386bsdi -Wl,-e,_start"

#Pyramid 9XXX (e.g. 9845) or MIServer T series, OSx 4.4b thru 5.1
pyramid:
	@echo Making C-Kermit $(CKVER) for Pyramid Dual Port OSx
	ucb $(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD43 -DTCPSOCKET -DPYRAMID -O $(KFLAGS)" "LNKFLAGS = -s"

#Pyramid Dual Port OSx using HoneyDanBer UUCP, curses and TCP
pyramid-hdb:
	@echo Making C-Kermit $(CKVER) for Pyramid Dual Port OSx
	ucb $(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DBSD43 -DTCPSOCKET -DHBDUUCP -DCK_CURSES -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lcurses -ltermcap"

#Pyramid DC/OSx (UNIX System V R4).
#Has <sys/termiox.h>, regular Berkeley sockets library, i.e. in.h and inet.h
#are not misplaced in sys (rather than netinet and arpa, respectively).
#Uses ANSI C.
#NOTE: Remove -O and Olimit:2500 from CFLAGS if TELNET connections do not work.
pyrdcosx:
	@echo 'Making C-Kermit $(CKVER) for Pyramid DC/OSx...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -Xa -O -DSVR4 -DDIRENT -DHDBUUCP -DSELECT -DNOGETUSERSHELL \
	-DCK_CURSES -DSTERMIOX -DTCPSOCKET -DPYRAMID -K Olimit:3100 \
	-DNO_DNS_SRV $(KFLAGS)" "LIBS= -lcurses -lsocket -lnsl" "LNKFLAGS = -s"

#IBM's AIX 3.0 on IBM 370 mainframe, tested on AIX F44 thru F50.
aix370:
	@echo Making C-Kermit $(CKVER) for IBM System/370 AIX 3.0...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIX370 -DTCPSOCKET -DLCKDIR -DDIRENT $(KFLAGS)" \
	"LIBS = -lbsd"

#IBM's AIX/ESA 2.1 (OSF/1) on IBM mainframe
aixesa:
	@echo Making C-Kermit $(CKVER) for IBM AIX/ESA...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXESA -DTCPSOCKET $(KFLAGS) -O"

#IBM PS/2 with AIX 1.0 thru 1.3.
#  Reports indicate that -O switch must be omitted.
#  It is also possible that "make bsd" will work (reports welcome).
#  One report said "make LIBS=-lbsd bsd" did the trick.
#  NOTLOG is to get around a 'tlog' symbol defined in one of the headers.
ps2aix:
	@echo 'Making C-Kermit $(CKVER) for IBM AIX 1.x PS/2...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DNOREALPATH -DPS2AIX10 -DSIG_V \
	-DNOUNICODE -DNOTLOG -DNOLEARN $(KFLAGS) -i" \
	"LNKFLAGS = -i"

ps2aixnetc:
	@echo 'Making C-Kermit $(CKVER) for IBM AIX 1.x PS/2...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DNOREALPATH -DPS2AIX10 -DTCPSOCKET -DCK_CURSES \
	-DSIG_V -DNOUNICODE -DNOTLOG -DNOLEARN $(KFLAGS) -i" \
	"LIBS = -lcurses" "LNKFLAGS = -i"

ps2aix3:
	$(MAKE) ps2aix KTARGET=$${KTARGET:-$(@)}

#IBM RT PC with AIX 2.2.1, valid as of C-Kermit 8.0.
#NOTLOG because of a conflict in <sys/termio.h>.
#This one has unique and strange lockfiles.
#  -O removed on purpose (8.0).
#  In case of "compiler error: symbol table full", increase the -Nn number.
#  In case of "compiler error: Constant pool too big", boost the -Np number.
#  Add -DNOPUTENV if putenv() causes trouble.
#  Put -DNOIKSD back if IKSD-related problems occur.
rtaix:
	@echo 'Making C-Kermit $(CKVER) for IBM RT PC, AIX 2.2.1...'
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS = -DATTSV -DRTAIX -DHDBUUCP -DDIRENT -DNOTLOG -DTCPSOCKET \
	-DNOGETUSERSHELL -DCLSOPN -DNOREALPATH -DNOUNICODE -DBSD_INCLUDES \
	-DUSE_LSTAT -DFNFLOAT -Nn2500 -Np1000 -Wq,-SJ2 -a -w $(KFLAGS)" \
	"LIBS = -lm $(LIBS)" "LNKFLAGS = -s"

#### IBM RT PC - these targets were last verified in C-Kermit 8.0.211.

#IBM RT PC with AIX 2.2.1 + curses
rtaixc:
	$(MAKE) rtaix CC=$(CC) CC2=$(CC2) "KFLAGS=-DCK_CURSES" "LIBS=-lcurses"

#IBM RT PC with AIX (ACIS) 2.2.1 (BSD 4.3)
# Add -O, -DDYNAMIC, -s, etc, if they work.
rtacis:
	@echo Making C-Kermit $(CKVER) for RT PC with ACIS 2.2.1 = BSD 4.3...
	$(MAKE) xermit KTARGET=$${KTARGET-$(@)} \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DNOREALPATH -DNOIKSD -DNOPUTENV \
	$(KFLAGS) -U__STDC__" "LNKFLAGS = -s"

#### IBM AIX.  The first two targets should work for any version of AIX
#### from 4.2 onwards.  The ones after that are for older versions or
#### specific configurations, and/or with gcc.

# This one should work for any AIX 4.2 or later: "make aix".
# Other tags are for compatibility with old makefile targets.
#OK: 2011/06/11
aix aix42 aix43 aix44 aix45 aix50 aix51 aix52 aix53 aix54 aix61:
	@echo Making C-Kermit $(CKVER) for IBM AIX...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DAIX42 -DSVR4 -DSTERMIOX -DTCPSOCKET \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DFNFLOAT \
	-DSELECT -DSELECT_H -DNOGETUSERSHELL -qmaxmem=16000 -O \
	-DCKCPU=\\\"`uname -p`\\\" \
	-DHERALD=\"\\\" IBM AIX `uname -v`.`uname -r`\\\"\" \
	-D_LARGE_FILES $(KFLAGS)" "LNKFLAGS = -s" "LIBS=-lcurses -lm"

# Same but using gcc instead of cc
# This works but we get "gcc: unrecognized option '-qmaxmem-..'" each module.
aixg:
	@echo "Using gcc..."
	$(MAKE) aix KTARGET=$${KTARGET:-$(@)} \
	CC=gcc CC2=gcc "KFLAGS=-pipe -funsigned-char"

# AIX 4.2 or later with OpenSSL 0.9.7 or later: "make aix+ssl"
# For earlier OpenSSL remove -DOPENSSL_097 or add "KFLAGS=-UOPENSSL_097".
# Synonym target names added to cover old redundant targets that were removed.
# If SSL is not installed in the /usr/local tree (see SSLINC and SSLLIB
# definitions near the top), you can specify the locations in your make
# command as in this example:
#
#  SSLINC=-I/opt/ssl/include SSLLIB=-L/opt/ssl/lib make -e aix+ssl
#
# To build with gcc use "make aix CC=gcc CC2=gcc", or "make aixg"
#
#OK: 2011/06/15
aix+ssl aix51+openssl aix52+openssl aix53+openssl:
	@echo "Making C-Kermit $(CKVER) for IBM AIX with OpenSSL..."
	@echo "SSLINC=$(SSLINC) SSLLIB=$(SSLLIB)"
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	CC=$(CC) CC2=$(CC2) \
	"CFLAGS=-DAIXRS -DAIX41 -DAIX42 -DSVR4 -DSTERMIOX -DTCPSOCKET \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DFNFLOAT \
	-D_LARGE_FILES -DSELECT -DSELECT_H -DNOGETUSERSHELL \
	-DCKCPU=\\\"`uname -p`\\\" \
	-DHERALD=\"\\\" IBM AIX `uname -v`.`uname -r`\\\"\" \
	-DCK_AUTHENTICATION -DCK_SSL -DOPENSSL_097 $(SSLINC) $(KFLAGS)" \
	"LNKFLAGS=-s" "LIBS=$(SSLLIB) -lssl -lcrypto -lcurses -lm -lcrypt"

# AIX 5.3 or 6.1 or later with IBM OpenSSL, which is always in the directories
# shown below so you don't have to set SSLINC and SSLLIB.  If for some reason
# the SSL include files and libraries are not in the places assumed, then use
# "make aix+ssl" (just above) and set SSLINC and SSLLIB to indicate where the
# SSL files are.  To build with gcc use "make aix+ibmssl CC=gcc CC2=gcc".
aix+ibmssl:
	@echo "Making C-Kermit $(CKVER) for IBM AIX 6.1 with OpenSSL..."
	@echo "If this fails use 'make aix+ss' and specify SSLINC and SSLLIB"
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	CC=$(CC) CC2=$(CC2) \
	"CFLAGS=-DAIXRS -DAIX41 -DAIX42 -DSVR4 -DSTERMIOX -DTCPSOCKET \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DFNFLOAT \
	-D_LARGE_FILES -DSELECT -DSELECT_H -DNOGETUSERSHELL \
	-DCKCPU=\\\"`uname -p`\\\" \
	-DHERALD=\"\\\" IBM AIX `uname -v`.`uname -r`\\\"\" \
	-DCK_AUTHENTICATION -DCK_SSL -DOPENSSL_098 \
	-I/usr/include/openssl $(KFLAGS)" \
	"LNKFLAGS=-s" \
	"LIBS=-L/usr/lib/openssl -lssl -lcrypto -lcurses -lm -lcrypt"

# Old AIX versions...

#IBM AIX 3.0, 3.1, or 3.2 for RISC System/6000.
rs6000:
	@echo Making C-Kermit $(CKVER) for IBM AIX 3.0 or 3.1, RS/6000...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DTCPSOCKET -DSVR3 -DDIRENT -DCK_ANSIC \
	-DCK_POLL -DCLSOPN -DSELECT_H -DNOTTYLOCK -O $(KFLAGS)" \
	"LNKFLAGS = -s"

#IBM AIX 3.0, 3.1, or 3.2 for RISC System/6000, with curses.
rs6000c:
	@echo Making C-Kermit $(CKVER) for IBM AIX 3.0 or 3.1, RS/6000...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DTCPSOCKET -DSVR3 -DDIRENT -DCK_ANSIC \
	-DCK_POLL -DCLSOPN -DCK_CURSES -DSELECT_H -DNOTTYLOCK -DNOREALPATH \
	-O $(KFLAGS)" "LIBS= -lcurses -ltermcap" "LNKFLAGS = -s"

aix30:
	$(MAKE) rs6000 CC=$(CC) CC2=$(CC2) KTARGET=$${KTARGET:-$(@)}

aix31:
	$(MAKE) rs6000 CC=$(CC) CC2=$(CC2) KTARGET=$${KTARGET:-$(@)}

#IBM AIX 3.2 for RISC System/6000.
#In case of "subprogram too complex" warnings, add "-qmaxmem=16000" to CFLAGS.
rs6aix32:
	@echo Making C-Kermit $(CKVER) for IBM AIX 3.2, RS/6000...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DTCPSOCKET -DSVR4 -DDIRENT -DCK_ANSIC -DNOREALPATH \
	-DSELECT_H -DCLSOPN -DNOTTYLOCK -O $(KFLAGS)" "LNKFLAGS = -s"

#IBM AIX 3.2 for RISC System/6000.
rs6aix32c:
	@echo Making C-Kermit $(CKVER) for IBM AIX 3.2, RS/6000, TCP+curses...
	@echo In case of Subprogram Too Complex warnings,
	@echo add -qmaxmem=16000 to CFLAGS.
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DTCPSOCKET -DSVR4 -DDIRENT -DCK_ANSIC -DNOREALPATH \
	-DCLSOPN -DCK_CURSES -DSELECT_H -DNOTTYLOCK -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS=-lcurses"

aix32:
	$(MAKE) rs6aix32c KTARGET=$${KTARGET:-$(@)}

#IBM AIX 4.1, 4.1.x on RISC System/6000 or Power Series.
#Generates common binary for all platforms if using xlc (IBM C compiler).
#When using gcc, add -mcpu=common to generate common binary.
#Note that this one needs CK_NEWTERM.
# Add -bbigtoc in case ld fails with TOC overflow.
aix41:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.1.1 RS/6000 or PowerPC...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DSVR4 -DSTERMIOX -DTCPSOCKET -DDIRENT \
	-DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -qmaxmem=16000 -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS=-lcurses"

#Ditto but with gcc.
#Remove "CC=gcc CC2=gcc" if you have gcc installed as cc.
aix41g:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.1.1 RS/6000 or PowerPC...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC=gcc" "CC2=gcc" \
	"CFLAGS= -DAIXRS -DAIX41 -DSVR4 -DSTERMIOX -DTCPSOCKET -DDIRENT \
	-DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -O $(KFLAGS)" \
	"LNKFLAGS = -s -Xlinker -bbigtoc" "LIBS=-lcurses"

# Add -bbigtoc in case ld fails with TOC overflow.
aix41+krb5+krb4:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.1.1 RS/6000 or PowerPC...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DSVR4 -DSTERMIOX -DTCPSOCKET -DDIRENT \
	-DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_DES $(K5INC) $(K5INC)/krb5  \
	-DNOGETUSERSHELL -qmaxmem=16000 -O $(KFLAGS)" \
	"LNKFLAGS = -s" \
	"LIBS = $(K5LIB) -lcurses -lkrb4 -ldes425 -lkrb5 \
	-lcom_err -lk5crypto -lgssapi_krb5"

#Old name for "aix41".
rs6aix41c:
	$(MAKE) aix41 KTARGET=$${KTARGET:-$(@)}

#IBM AIX 4.1, 4.1.x, or 4.2 on RISC System/6000 or Power Series,
# with X.25 support
#Generates common binary for all platforms if using xlc (IBM C compiler).
#When using gcc, add -mcpu=common to generate common binary.
# Add -bbigtoc in case ld fails with TOC overflow.
aix41x25:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.1.1 RS/6000 or PowerPC...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DSVR4 -DSTERMIOX -DTCPSOCKET -DDIRENT \
	-DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DIBMX25 -DDEBUG -DNOGETUSERSHELL -qmaxmem=16000 -g $(KFLAGS)" \
	"LNKFLAGS = -g -bI:/lib/pse.exp" "LIBS=-lcurses -lodm -lcfg"
	-@echo "�]0;kermit done�\c"

#As above but without -g in LNKFLAGS.
# Add -bbigtoc in case ld fails with TOC overflow.
aix41x25o:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.1.1 RS/6000 or PowerPC...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DSVR4 -DSTERMIOX -DTCPSOCKET -DDIRENT \
	-DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DIBMX25 -DNODEBUG -DNOGETUSERSHELL -qmaxmem=16000 $(KFLAGS)" \
	"LNKFLAGS = -bI:/lib/pse.exp" "LIBS=-lcurses -lodm -lcfg"
	-@echo "�]0;kermit done�\c"

#AIX 4.2 -- Use this target if the regular "make aix" doesn't work.
# Must have CK_NEWTERM or echoing is lost after curses.
# Add -bbigtoc in case ld fails with TOC overflow.  As of C-Kermit 8.0.212,
# all AIX builds 4.2 and later include large file support.
oldaix42:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.2 or higher...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DAIX42 -DSVR4 -DSTERMIOX -DTCPSOCKET \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DCK_NEWTERM -DFNFLOAT \
	-DSELECT -DSELECT_H -DNOGETUSERSHELL -qmaxmem=16000 -O \
	-DCKCPU=\\\"`uname -p`\\\" \
	-DHERALD=\\\"\ IBM\ AIX\ `uname -v`.`uname -r`\\\" \
	-D_LARGE_FILES $(KFLAGS)" "LNKFLAGS = -s" "LIBS=-lcurses -lm"

#AIX 4.3 - Use this target if the regular "make aix" doesn't work.
# Must NOT have CK_NEWTERM or else C-Kermit hangs after curses.
# -bbigtoc needed on some systems but not others to avoid TOC overflow.
# "man ld" says -bbigtoc makes program run slower.
oldaix43:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 or higher...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DAIX43 -DSVR4 -DSTERMIOX -DTCPSOCKET \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DFNFLOAT -DNOGETUSERSHELL -qmaxmem=16000 -bbigtoc -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS=-lcurses -lm"

#AIX 4.3 with IBM X.25.
aix43x25:
	@echo "Making C-Kermit $(CKVER) for IBM AIX 4.3 with X.25..."
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DAIXRS -DAIX41 -DAIX43 -DSVR4 -DSTERMIOX -DTCPSOCKET \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DFNFLOAT -DNOGETUSERSHELL -DIBMX25 \
	-qmaxmem=16000 -bbigtoc -O $(KFLAGS)" \
	"LNKFLAGS = -bI:/lib/pse.exp" "LIBS=-lcurses -lodm -lcfg -lm"

#AIX 4.3 -- Must NOT have CK_NEWTERM or else C-Kermit hangs after curses.
# -mminimal-toc needed on some systems but not others to avoid TOC overflow.
# "man ld" says -bbigtoc makes program run slower.
aix43g:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 gcc...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL $(KFLAGS)" \
	"LIBS=-lcurses -lm"

aix43gcc:
	$(MAKE) aix43g

# None of the following aix43gcc attempts work on a gcc-only AIX 4.3.3 box.
# It just plain can't find the math routines (fmod, pow, exp, sqrt, log10,...)
# Which is odd because nm /usr/lib/libC.a finds them...

#in case aix43gcc can't find its math library...
aix43gccx:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 gcc...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL $(KFLAGS)" \
	"LIBS= -L/usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.1.0/2.95.2 \
	-lcurses -bloadmap -bnoquiet"

#in case aix43gccx can't find its math library...
aix43gccy:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 gcc...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL $(KFLAGS)" \
	"LIBS= -lcurses -bloadmap -bnoquiet"

#in case aix43gccx can't find its math library...
aix43gccz:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 gcc...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL $(KFLAGS)" \
	"LIBS= -L. -lcurses -bloadmap -bnoquiet"

#AIX 4.3 with MIT Kerberos 5 and Kerberos 4 compatibility mode
# Must NOT have CK_NEWTERM or else C-Kermit hangs after curses.
# -mminimal-toc needed on some systems but not others to avoid TOC overflow.
# "man ld" says -bbigtoc makes program run slower.
aix43gcc+krb5+krb4:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 or higher w/Kerberos...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_DES -funsigned-char $(K5INC) $(K5INC)/krb5 \
	$(KFLAGS)" \
	"LIBS=$(K5LIB) -lcurses -lm -lkrb4 -ldes425 -lkrb5 \
	-lcom_err -lk5crypto -lcrypt -lgssapi_krb5"

#AIX 4.3 with MIT Kerberos 5, Kerberos 4 compatibility mode and OpenSSL
# Must NOT have CK_NEWTERM or else C-Kermit hangs after curses.
# -mminimal-toc needed on some systems but not others to avoid TOC overflow.
# "man ld" says -bbigtoc makes program run slower.
aix43gcc+krb5+krb4+openssl:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 or higher w/Kerberos...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_DES -DCK_CAST -DLIBDES -DCK_SSL \
	-funsigned-char $(K5INC) $(K5INC)/krb5 $(SSLINC) $(KFLAGS)" \
	"LIBS=$(K5LIB) $(SSLLIB) -lssl -lcrypto \
	-lcurses -lm -lkrb4 -ldes425 -lkrb5 -lcom_err -lk5crypto -lcrypt \
	-lgssapi_krb5"

aix43gcc+openssl:
	@echo Making C-Kermit $(CKVER) for IBM AIX 4.3 or higher w/OpenSSL...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS= -mminimal-toc -g -O -DAIXRS -DAIX41 -DAIX43 -DSVR4 \
	-DDIRENT -DCK_ANSIC -DCLSOPN -DCK_CURSES -DSELECT -DSELECT_H \
	-DSTERMIOX -DTCPSOCKET -DFNFLOAT -DNOGETUSERSHELL \
	-DCK_AUTHENTICATION -DCK_SSL -funsigned-char $(SSLINC) $(KFLAGS)" \
	"LIBS=$(SSLLIB) -lssl -lcrypto -lcurses -lm -lcrypt"

aix44gcc:
	$(MAKE) aix43g "KFLAGS=-DAIX44 $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)}

aix45gcc:
	$(MAKE) aix43g "KFLAGS=-DAIX45 $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)}

aix50gcc:
	$(MAKE) aix43g "KFLAGS=-DAIX50 $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)}

aix51gcc:
	$(MAKE) aix43g "KFLAGS=-DAIX51 $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)}

aix52gcc:
	$(MAKE) aix43g "KFLAGS=-DAIX52 $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)}

aix53gcc:
	$(MAKE) aix43g "KFLAGS=-DAIX53 $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)}

#Bull DPX/2 with BOS/X, like AIX/RS6000
bulldpx2:
	@echo Making C-Kermit $(CKVER) for Bull DPX/2 with BOS/X...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSVR3 -DDIRENT -DCK_ANSIC -DCKTYP_H=<sys/types.h> \
	-DCK_POLL -DNOGETUSERSHELL -DCLSOPN -DNOLEARN -O $(KFLAGS)" \
	"LNKFLAGS = -s"

#Sun UNIX 3.5 with gcc 2.3.3.
sunos3gcc:
	@echo Making C-Kermit $(CKVER) for Sun UNIX 3.5 and gcc...
	$(MAKE) xermit CC=gcc CC2=gcc KTARGET=$${KTARGET:-$(@)} \
	CFLAGS="-g -O -DBSD4 -DTCPSOCKET $(KFLAGS)"

#SunOS version 4.0, BSD environment, has saved original euid feature.
# Add "CC=/usr/ucb/cc CC2=/usr/ucb/cc" if necessary.
# Note: Including Unicode crashes the assembler in ckcuni.c.
sunos4:
	@echo Making C-Kermit $(CKVER) for SunOS 4.0, BSD environment...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DSUNOS4 -DFNFLOAT -DNOUNICODE $(KFLAGS)" \
	"LIBS=-lm"

#As above, but with SunLink X.25 support
sunos4x25:
	@echo SunLink X.25 support
	$(MAKE) "MAKE=$(MAKE)" sunos4 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DFNFLOAT -DSUNX25" \
	"LIBS=-lm"

#SUN OS version 4.1 - 4.1.3, BSD environment, has saved original euid feature.
#Uses Honey DanBer UUCP.  Requires presence of /usr/spool/locks directory.
# /var/spool/ should be a symbolic link to  /usr/spool/.
# ... or 'make xermit "CC= /usr/ucb/cc " \'
# Note: "xermit" means use the select() version of the CONNECT module.
# Note for C-Kermit 9.0: Reportedly 'you need to modify the sys/ioctl.h
# include file, i.e. comment out the "struct winsize" and "struct
# ttysize". Otherwise there will be a conflict with sys/ttycom.h (included by
# termios.h) which also declares these structs. But you need both includes.'
sunos41:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 / BSD...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNOUNICODE $(KFLAGS)" \
	"LIBS= $(LIBS) -lresolv -lm"

#As above, but compiled with gcc.  Gives 24-32K size reduction
#with gcc 2.1 or 2.2.2.  CAUTION: make sure "fixincludes" has been run on
#the include files, so gcc's are in sync with the regular Sun ones.
#This includes the curses library for fullscreen file transfer display.
#NDGPWNAM needed for GCC 2.5.6, not needed for 2.4.0, but it's uncertain
#whether it will do any harm for 2.4.0 compilation -- if so, remove it.
sunos41gcc:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 with gcc and curses...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-funsigned-char $(KFLAGS)" "LIBS= -lcurses -ltermcap -lresolv -lm"

# As above, but without -funsigned-char so I can see the warnings that
# everybody else will get when they use ANSI compilers that don't have this
# option (gsc = gcc signed char).
sunos41gsc:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 with gcc and curses...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	$(KFLAGS)" "LIBS= -lcurses -ltermcap -lresolv -lm"

#As above but with ckucon.c rather than ckucns.c (for testing only)
sunos41gccfork:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 with gcc and curses...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DNOLEARN -funsigned-char $(KFLAGS)" \
	"LIBS= -lcurses -ltermcap -lresolv -lm"

#as above but configured for Kerberos IV
sunos41gcc+krb4:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1, gcc, curses, krb4...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DTCPSOCKET -DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB4 \
	-DCK_ENCRYPTION -DCK_DES -DCK_CAST -DBIGBUFOK -funsigned-char \
	$(K4INC) $(KFLAGS)" \
	"LIBS= $(K4LIB) -lcurses -ltermcap -lresolv -lm -lkrb -ldes"

#as above but configured for SSL/TLS
sunos41gcc+openssl:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1, gcc, curses, ssl...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DCK_AUTHENTICATION -funsigned-char \
	-DCK_SSL -DTCPSOCKET -DBIGBUFOK $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -lcurses -ltermcap -lresolv -lm -lssl -lcrypto"

#as above but configured for Kerberos IV and SSL/TLS
sunos41gcc+krb4+openssl:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1, gcc, curses, krb4...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB4 -DCK_ENCRYPTION -DCK_DES \
	-DCK_CAST -DCK_SSL -DLIBDES -DTCPSOCKET -DBIGBUFOK -funsigned-char \
	$(K4INC) $(SSLINC) $(KFLAGS)" \
	"LIBS= $(K4LIB) $(SSLLIB) \
	-lcurses -ltermcap -lresolv -lm -lkrb -lssl -lcrypto"

#as above but configured for Kerberos IV and ZLIB enabled SSL/TLS
sunos41gcc+krb4+openssl+zlib:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1, gcc, curses, krb4...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB4 -DCK_ENCRYPTION -DCK_DES \
	-DCK_CAST -DCK_SSL -DLIBDES -DTCPSOCKET -DBIGBUFOK -funsigned-char \
	-DZLIB $(K4INC) $(SSLINC) \
	$(KFLAGS)" \
	"LIBS= $(K4LIB) $(SSLLIB) \
	-lcurses -ltermcap -lresolv -lm -lkrb -lssl -lcrypto -lz"

#as above but configured for Kerberos IV and SRP and ZLIB enabled SSL/TLS
sunos41gcc+krb4+srp+openssl+zlib:
	@echo "C-Kermit $(CKVER) SunOS 4.1: gcc,curses,krb4,srp,ssl,zlib..."
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB4 -DCK_ENCRYPTION -DCK_DES \
	-DCK_CAST -DCK_SSL -DLIBDES -DTCPSOCKET -DBIGBUFOK -funsigned-char \
	-DZLIB -DCK_SRP $(K4INC) $(SRPINC) $(SSLINC) $(KFLAGS)" \
	"LIBS= $(K4LIB) $(SRPLIB) $(SSLLIB) \
	-lcurses -ltermcap -lresolv -lm -lkrb -lkrypto \
	-lsrp -lssl -lcrypto -lz"

#as above but configured for Kerberos IV and SRP and ZLIB enabled SSL/TLS
sunos41gcc+srp+openssl+zlib:
	@echo "C-Kermit $(CKVER) SunOS 4.1: gcc,curses,srp,ssl,zlib..."
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNDGPWNAM -DCK_CURSES -DFNFLOAT \
	-DCK_AUTHENTICATION -DCK_ENCRYPTION -DCK_DES \
	-DCK_CAST -DCK_SSL -DLIBDES -DTCPSOCKET -DBIGBUFOK -funsigned-char \
	-DZLIB -DCK_SRP $(SRPINC) $(SSLINC) \
	$(KFLAGS)" \
	"LIBS= $(SRPLIB) $(SSLLIB) \
	-lcurses -ltermcap -lresolv -lm -lkrypto -lsrp -lssl -lcrypto -lz "

#SUNOS 4.1 as sunos41 above, but also with curses support
sunos41c:
	@echo Curses support
	$(MAKE) "MAKE=$(MAKE)" sunos41 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DCK_CURSES -DFNFLOAT " \
	"LIBS= -lcurses -ltermcap"

#As SunOS 4.1.x, gcc, configured as Internet Kermit Server.
# . NOLOCAL removes capability to make connections
# . TNCODE allows server-side Telnet negotiation.
# . used to include -lpwent, why?
# . used to include -L/usr/local/lib -lm, why?
sunos41giks:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 with gcc for IKS...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc" "CC2= gcc" \
	"CFLAGS= -O -DSUNOS41 -DNDGPWNAM -DFNFLOAT \
	-DNOLOCAL -DTCPSOCKET -DTNCODE -DNOPUSH $(KFLAGS)" \
	"LIBS= -lm -lresolv"

#SUNOS 4.1 with SunLink X.25 support
sunos41x25:
	@echo SunLink X.25 support
	$(MAKE) "MAKE=$(MAKE)" wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNOUNICODE -DFNFLOAT -DSUNX25 \
	-DNOLEARN $(KFLAGS)" "LIBS= $(LIBS) -lresolv -lm"

#SUNOS 4.1 with SunLink X.25 support and curses
sunos41x25c:
	@echo SunLink X.25 support + curses
	$(MAKE) "MAKE=$(MAKE)" wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DNOUNICODE -DFNFLOAT -DSUNX25 \
	-DCK_CURSES -DNOLEARN $(KFLAGS)" \
	"LIBS= $(LIBS) -lcurses -ltermcap -lresolv -lm"

#SUN with Solaris 2.0 = SunOS 5.0.
#Mostly the same as System V R4.  Don't use this with later Solaris versions.
solaris20:
	@echo 'Making C-Kermit $(CKVER) for Sun with Solaris 2.0 and curses...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DSOLARIS -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DTCPSOCKET -DCK_CURSES -DFNFLOAT -DCK_POLL $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermlib -lm" "LNKFLAGS = -s"

#SUN with Solaris 2.0.
#As above, but built with the gcc compiler from the Cygnus CD-ROM.
solaris20g:
	@echo 'Making C-Kermit $(CKVER) for Sun Solaris 2.0, gcc, and curses..'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DSOLARIS -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DTCPSOCKET -DCK_CURSES -DCK_POLL -DFNFLOAT $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermlib -lm" "LNKFLAGS = -s" \
	CC=/opt/cygnus-sol2-1.1/bin/gcc CC2=/opt/cygnus-sol2-1.1/bin/gcc

#SunOS 5.1 = Solaris 2.1.
#NOTE: A C compiler is no longer bundled with SunOS 5.1, so to compile C
#programs, you might have to change your PATH to include the directory
#/usr/ccs/bin AFTER the directory containing the compiler.  SunPRO C is
#installed by default in /opt/SUNWspro/bin.  So a sample PATH might be:
#
# /usr/local/bin:/usr/bin:/opt/SUNWspro/bin:/usr/ccs/bin:\
# /usr/ucb:/usr/sbin:/sbin:.
#
# or:
#
# /usr/openwin/bin:/export/home/SUNWspro/bin:/usr/ccs/bin:/usr/sbin:/usr/bin.
#
#NOTE 2: Compilation with the Apogee C compiler (apcc) might not work,
#because it refuses to allow "-Usun".  Reportedly, newer releases of apcc
#(such as 1.2.17) work OK, use: "make -e sunos51 CC=apcc CC2=apcc".
solaris21:
	@echo 'Making C-Kermit $(CKVER) for SunOS 5.x....'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -Usun -DSVR4 -DSOLARIS -DDIRENT -DHDBUUCP -DFNFLOAT \
	-DSELECT -DNODEBUG -DSTERMIOX $(KFLAGS)" "LIBS = -lm" "LNKFLAGS = -s"

#Solaris 2.0 - 2.4, SunPro compiler, includes curses and TCP/IP.
#When using SUNWspro CC 2.0.1 under Solaris 2.3, be sure all cc patches
#are applied, otherwise corrupt or truncated object files can result.
#To build, set your PATH as follows:
#  /usr/local/bin:/usr/bin:/opt/SUNWspro/bin:/usr/ccs/bin:\
#  /usr/ucb:/usr/sbin:/sbin:.
# or (depending on where the compiler has been installed):
#  /usr/openwin/bin:/export/home/SUNWspro/bin:/usr/ccs/bin:/usr/sbin:/usr/bin.
#For additional optimization try using "-fast -xO4 -xdepend".
solaris2x:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with SunPro cc...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -Usun -i -DSVR4 -DDIRENT -DSOLARIS -DHDBUUCP -DFNFLOAT \
	-DSELECT -DCK_CURSES -DCK_NEWTERM -DSTERMIOX -DTCPSOCKET $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS= -ltermlib -lsocket -lnsl -lm -lresolv"

#as above but configured for Kerberos IV
solaris2x+krb4:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x, SunPro cc, krb4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -Usun -i -DSVR4 -DDIRENT -DSOLARIS -DHDBUUCP -DFNFLOAT \
	-DSELECT -DCK_CURSES -DCK_NEWTERM -DSTERMIOX -DTCPSOCKET  \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB4 \
	-DCK_ENCRYPTION -DCK_DES -DCK_CAST $(K4INC) $(KFLAGS)" \
	"LNKFLAGS = -s" \
	"LIBS= $(K4LIB) -ltermlib -lsocket -lnsl -lm -lresolv -lkrb -ldes"

#C-Kermit for Solaris 2.0-2.4 compiled with gcc, includes curses and TCP/IP.
#Change -O2 to -O if -O2 gives trouble.
#Remove -Usun if it causes trouble.
#Your PATH should start with something like:
#  /usr/local/gnu/bin:/usr/ccs/bin:
#Produces a huge executable -- strip with /usr/ccs/bin/strip (not Gnu strip).
#Also don't add "LNKFLAGS = -s" -- strip manually instead.
#Also note: this can NOT be linked statically - Sun makes it impossible.
#And for Solaris 2.4, you might have to replace:
# /usr/local/lib/gcc-lib/i486-sun-solaris2/2.4.5/include/sys/stat.h
#with /usr/include/sys/stat.h.
solaris2xg:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with GNU cc...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -ltermlib -lsocket -lnsl -lm -lresolv $(LIBS)"

#ditto but no curses.
solaris2xgnc:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with GNU cc...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DDIRENT -DHDBUUCP -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lm -lresolv $(LIBS)"

#and with Kerberos IV
solaris2xg+krb4:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with GNU cc, krb4...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB4 -DCK_ENCRYPTION \
	-DCK_DES -DCK_CAST -DBIGBUFOK $(K4INC) $(KFLAGS)" \
	"LIBS= $(K4LIB) -ltermlib -lsocket -lnsl -lm -lresolv -lkrb -ldes \
	$(LIBS)"

#and with OpenSSL,ZLIB,PAM,SHADOW
solaris2xg+openssl+zlib+pam+shadow:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with gcc, OpenSSL...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DCK_AUTHENTICATION -DCK_SSL -DCK_PAM -DCK_SHADOW  -DZLIB \
	-DBIGBUFOK $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -ltermlib \
	-lsocket -lnsl -lm -lresolv -lssl -lcrypto -lpam -lz"

#Ditto but with GCC 3.1 in which you have to specify 32-bit with -m32.
#In Solaris 9 (and maybe 8) you'll also need specifiy the Library path.
#Reportedly this can be done here, but only with:
# crle -l /usr/lib:/usr/local/ssl/lib
#prior to building.  Note: 64-bit not tested with SSL.
#For no-crypto 64-bit builds see the solaris9g64 target.
solaris2xg32+openssl+zlib+pam+shadow:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with gcc, OpenSSL...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC="gcc -m32" CC2="gcc -m32" \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DCK_AUTHENTICATION -DCK_SSL -DCK_PAM -DCK_SHADOW  -DZLIB \
	-DBIGBUFOK $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -ltermlib \
	-lsocket -lnsl -lm -lresolv -lssl -lcrypto -lpam -lz"

#and with Krb5,Krb4,OpenSSL,SHADOW
solaris2xg+krb5+krb4+openssl+shadow:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with gcc,k5,k4,ssl...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_SSL -DCK_DES -DCK_CAST -DBIGBUFOK \
	$(K5INC) $(K5INC)/krb5 $(SSLINC) $(KFLAGS)" \
	"LIBS= $(K5LIB) $(SSLLIB) -ltermlib -lsocket -lnsl -lm -lresolv \
	-lkrb4 -lssl -lcrypto -lgssapi_krb5 -lkrb5 -lcom_err -lk5crypto \
	-ldes $(LIBS)"

#and with OpenSSL
solaris2xg+openssl+pam+shadow:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with gcc, OpenSSL...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DCK_AUTHENTICATION -DCK_SSL -DCK_PAM -DCK_SHADOW \
	-DBIGBUFOK $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -ltermlib \
	-lsocket -lnsl -lm -lresolv -lssl -lcrypto -lpam"

solaris2xg+openssl+zlib+srp+pam+shadow:	
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with gcc, OpenSSL...'
	@echo 'Please read the comments that accompany the solaris2xg target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET -DBIGBUFOK \
	-DCK_AUTHENTICATION -DCK_ENCRYPTION -DCK_DES -DLIBDES -DCK_CAST \
	-DCK_SSL -DCK_PAM -DCK_SHADOW -DZLIB -DCK_SRP $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -ltermlib -lsocket -lnsl -lm -lresolv -lsrp -lssl \
	-ldes -lkrypto -lcrypto -lpam -lz"

solaris22g:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=-DPOSIX_CRTSCTS $(KFLAGS)" solaris2xg \
	KTARGET=$${KTARGET:-$(@)}

solaris23g:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=-DPOSIX_CRTSCTS $(KFLAGS)" solaris2xg \
	KTARGET=$${KTARGET:-$(@)}

#Solaris 2.4 built with gcc
solaris24g:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET:-$(@)} \
	solaris2xg "KFLAGS=-DSOLARIS24 -DPOSIX_CRTSCTS $(KFLAGS)"

#Solaris 2.0-2.3, SunPro compiler, with SunLink X.25 support.
#This will only run if user has /opt/SUNWconn/lib/libsockx25.so.1
#exists and can be dynamically linked.
#NOTE: Do not change target to xermit -- it doesn't support X.25.
solaris2x25:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x+X.25 with SunPro cc...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -i -Usun -DSVR4 -DSOLARIS -DDIRENT \
	-DSUNX25 -DTCPSOCKET -DHDBUUCP -DFNFLOAT -DNOLEARN \
	-DSELECT -DCK_CURSES -DCK_NEWTERM -DSTERMIOX $(KFLAGS)" \
	"LNKFLAGS = -s" \
	"LIBS= -ltermlib -L/opt/SUNWconn/lib -R/opt/SUNWconn/lib \
	-lsockx25 -lsocket -lnsl -lm -lresolv"

#Solaris 2.0-2.4, gcc, SunLink X.25 added.
#NOTE: Can't use xermit target with X.25.
solaris2xgx25:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x + X.25 with GNU cc...'
	@echo 'Please read the comments that accompany the solaris2xg entry.'
	$(MAKE) wermit CC=gcc CC2=gcc KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -g -O -Usun -DSVR4 -DSOLARIS -DSTERMIOX -DSELECT -DSUNX25 \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET -DFNFLOAT \
	-DNOLEARN $(KFLAGS)" \
	"LIBS= -ltermlib -lm -L/opt/SUNWconn/lib -R/opt/SUNWconn/lib \
	-lsockx25 -lsocket -lnsl"

#Solaris 2.4, SunPro compiler, with SunLink X.25 support.
#This will only run if user has /opt/SUNWconn/lib/libsockx25.so.1
#exists and can be dynamically linked.
solaris24x25:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.4+X.25 with SunPro cc...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -i -Usun -DSVR4 -DSOLARIS -DSOLARIS24 -DDIRENT -DNOLEARN \
	-DSUNX25 -DTCPSOCKET -DHDBUUCP -DFNFLOAT -DPOSIX_CRTSCTS \
	-DSELECT -DCK_CURSES -DCK_NEWTERM -DSTERMIOX $(KFLAGS)" \
	"LNKFLAGS = -s" \
	"LIBS= -ltermlib -L/opt/SUNWconn/lib -R/opt/SUNWconn/lib \
	-lsockx25 -lsocket -lnsl -lm -lresolv"

#Solaris 2.5, SunPro compiler, with SunLink X.25 support.
solaris25x25:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.5+X.25 with SunPro cc...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -i -Usun -DSVR4 -DSOLARIS25 -DDIRENT -DSUNX25 \
	-DTCPSOCKET -DHDBUUCP -DSELECT -DCK_CURSES \
	-DCK_NEWTERM -DSTERMIOX -DFNFLOAT -DPOSIX_CRTSCTS -DNOLEARN \
	-I/opt/SUNWconn/include $(KFLAGS)" \
	"LIBS= -ltermlib -L/opt/SUNWconn/lib -R/opt/SUNWconn/lib \
	-lsockx25 -lsocket -lnsl -lm -lresolv"

solaris23:
	$(MAKE) "MAKE=$(MAKE)" solaris2x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS)"

solaris24:
	$(MAKE) "MAKE=$(MAKE)" solaris2x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS24 -DPOSIX_CRTSCTS $(KFLAGS)"

# template for Solaris 2.5 and above.
solaris25x:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.x with SunPro cc...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DFNFLOAT -O -Usun -i $(KFLAGS)" \
	"LNKFLAGS = -s" \
	"LIBS= -ltermlib -lsocket -lnsl -lm -lresolv $(LIBS)"

#Solaris 2.5, SunPro compiler, curses, TCP/IP
solaris25:
	$(MAKE) "MAKE=$(MAKE)" solaris25x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS25 $(KFLAGS)"

#Solaris 2.5, SunPro compiler, curses, TCP/IP, Kerberos IV
solaris25+krb4:
	$(MAKE) "MAKE=$(MAKE)" solaris25x+krb4 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS25 $(KFLAGS)"

#Solaris 2.5 built with gcc
solaris25g:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-funsigned-char -DSOLARIS25 $(KFLAGS)"

#Solaris 2.5 built with gcc and Kerberos IV
solaris25g+krb4:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+krb4 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-funsigned-char -DSOLARIS25 $(KFLAGS)"

#Solaris 2.5 built with gcc and Kerberos V/IV, SSL, ...
solaris25g+krb5+krb4+openssl+shadow:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+krb5+krb4+openssl+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-funsigned-char -DSOLARIS25 $(KFLAGS)"

#Solaris 2.5, gcc, SunLink X.25 added.
solaris25gx25:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET:-$(@)} solaris2xgx25 \
	"KFLAGS=-DSOLARIS25 $(KFLAGS)"

#Solaris 2.6, gcc, SunLink X.25 added.
solaris26gx25:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET:-$(@)} solaris2xgx25 \
	"KFLAGS=-DSOLARIS26 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 2.6, SunPro compiler, curses, TCP/IP
solaris26:
	$(MAKE) "MAKE=$(MAKE)" solaris25x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS26 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 2.6 with gcc
solaris26g:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET:-$(@)} solaris2xg \
	"KFLAGS= -DSOLARIS26 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS = -lpam"

#Solaris 2.6 with gcc and SSL
solaris26g+openssl:
	$(MAKE) "MAKE=$(MAKE)"  solaris2xg+openssl+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS= -DSOLARIS26 $(KFLAGS)"

#Solaris 2.6 with gcc, no curses (e.g. because libtermlib is missing).
solaris26gnc:
	$(MAKE) "MAKE=$(MAKE)" KTARGET=$${KTARGET:-$(@)} solaris2xgnc \
	"KFLAGS= -DSOLARIS26 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 2.6, SunPro compiler, with SunLink X.25 support.
solaris26x25:
	@echo 'Making C-Kermit $(CKVER) for Solaris 2.6+X.25 with SunPro cc...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -i -Usun -DSVR4 -DSOLARIS26 -DDIRENT -DSUNX25 \
	-DTCPSOCKET -DHDBUUCP -DSELECT -DCK_CURSES -DCK_PAM -DCK_SHADOW \
	-DCK_NEWTERM -DSTERMIOX -DFNFLOAT -DPOSIX_CRTSCTS -DNOLEARN \
	-I/opt/SUNWconn/include $(KFLAGS)" \
	"LIBS= -ltermlib -L/opt/SUNWconn/lib -R/opt/SUNWconn/lib \
	-lsockx25 -lsocket -lnsl -lm -lresolv -lpam"

#Solaris 7 (2.7) with Sun CC
solaris7:
	$(MAKE) "MAKE=$(MAKE)" solaris25x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS7 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 7 with gcc (32-bit)
solaris7g:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS7 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 7 with gcc + Kerberos IV (32-bit)
solaris7g+krb4:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+krb4 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS7 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

solaris7g+openssl+zlib+pam+shadow:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+openssl+zlib+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS7 -DCK_PAM -DCK_SHADOW $(KFLAGS)"

#Solaris 7 with gcc + OpenSSL (32-bit)
solaris7g+openssl+zlib+srp+pam+shadow:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+openssl+zlib+srp+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS7 -DCK_PAM -DCK_SHADOW $(KFLAGS)"

#Solaris 8
solaris8:
	$(MAKE) "MAKE=$(MAKE)" solaris25x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS8 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 8 with gcc (32-bit)
solaris8g:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS8 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

# In OpenSSL builds add -ldl if you get unresolved references for
# dlclose, dlsym, dlopen, dlerror.

#Solaris 8 with gcc + OpenSSL (32-bit)
solaris8g+openssl+zlib+pam+shadow:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+openssl+zlib+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS=-DSOLARIS8 $(KFLAGS)"

#Solaris 8 with gcc + Kerberos IV (32-bit)
solaris8g+krb4:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+krb4 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS8 -DCK_PAM -DCK_SHADOW $(KFLAGS)" \
	"LIBS= -lpam"

solaris9nolfs:
	$(MAKE) "MAKE=$(MAKE)" solaris25x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS9 -DCK_PAM -DCK_SHADOW -DUSE_STRERROR $(KFLAGS)" \
	"LIBS= -lpam"

#Solaris 9 with malloc debugging
solaris9md:
	$(MAKE) mermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DFNFLOAT -O -Usun -i -D_FILE_OFFSET_BITS=64 \
	-DSOLARIS9 -Dmalloc=dmalloc -Dfree=dfree -DMDEBUG \
	-DCK_PAM -DCK_SHADOW -DUSE_STRERROR $(KFLAGS)" \
	"LIBS= -lpam -ltermlib -lsocket -lnsl -lm -lresolv"

#Solaris 9 with gcc + OpenSSL + Shadow (32-bit)
#Add -DOPENSSL_097 for OpenSSL 0.9.7 or later.
solaris9g+openssl+shadow+pam+zlib:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+openssl+zlib+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS9 -DHDBUUCP -DDIRENT -D_FILE_OFFSET_BITS=64 \
	-DNO_DCL_INET_ATON -DZLIB -DCK_PAM -DCK_SHADOW -DLIBDES $(KFLAGS)" \
	"LIBS= -lpam -ldes425 -lz $(LIBS)"

#Solaris 9 with gcc + OpenSSL + Kerberos 5 + Krb4 + Shadow (32-bit)
#Add -DOPENSSL_097 for OpenSSL 0.9.7 or later.
solaris9g+krb5+krb4+openssl+shadow+pam+zlib:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg+krb5+krb4+openssl+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS9 -DHDBUUCP -DDIRENT -D_FILE_OFFSET_BITS=64 \
	-DNO_DCL_INET_ATON -DZLIB -DCK_PAM -DCK_SHADOW -DLIBDES $(KFLAGS)" \
	"LIBS= -lpam -ldes -lz $(LIBS)"

#Solaris 9 with gcc + Kerberos 4 and 5:
solaris9g+krb5+krb4:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -O -Usun -DSVR4 -DSOLARIS9 -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DKRB4 -DKRB524 \
	-D_FILE_OFFSET_BITS=64 \
	-DCK_ENCRYPTION -DCK_DES -DCK_CAST -DBIGBUFOK \
	$(K5INC) $(K5INC)/krb5 $(KFLAGS)" \
	"LIBS= $(K5LIB) -ltermlib -lsocket -lnsl -lm -lresolv \
	-lkrb4 -lcrypto -lgssapi_krb5 -lkrb5 -lcom_err -lk5crypto \
	-ldes $(LIBS)"

#Solaris 9, 10, or 11 with gcc...  
#Uses streams PTYs rather than BSD ptys as in C-Kermit 8.0 and earlier.
#This target is chained to be the secure solaris9g+xxx targets below.
solaris9g solaris10g solaris11g:
	@echo 'Making C-Kermit $(CKVER) for Solaris 9 or later with gcc'
	@case `uname -r` in \
	  5.9) SOLARISVERSION="-DSOLARIS9" ;; \
	  5.10) SOLARISVERSION="-DSOLARIS10" ;; \
	  5.11) SOLARISVERSION="-DSOLARIS11" ;; \
	  *) SOLARISVERSION="-DSOLARIS" ;; \
	esac ; \
	$(MAKE) "MAKE=$(MAKE)" CC="gcc -m32" CC2="gcc -m32" xermit \
	KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -g -O -Usun -DSVR4 $$SOLARISVERSION -DUSE_STRERROR \
	-DSTERMIOX -DSELECT -DFNFLOAT -DCK_PAM -DCK_SHADOW -funsigned-char \
	-DHAVE_STREAMS -DHAVE_GRANTPT -DHAVE_PTSNAME -DPUSH_PTEM \
	-DPUSH_LDTERM -DPUSH_TTCOMPAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-D_FILE_OFFSET_BITS=64 $(KFLAGS)" \
	"LIBS= -ltermlib -lsocket -lnsl -lm -lresolv -lpam $(LIBS)"

#Solaris 9, 10, or 11 with gcc + Kerberos 5 + OpenSSL.
#OK C-Kermit 9.0.301.
solaris9g+krb5+ssl solaris10g+krb5+ssl solaris11g+krb5+ssl:
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac ; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes425'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	GSSAPILIB=''; \
	K5DIR=`echo $(K5LIB) | sed 's|-L||'`; \
	echo K5DIR=$$K5DIR; \
	if ls $$K5DIR/libgssapi_krb5* > /dev/null 2> /dev/null; then \
              GSSAPILIB='-lgssapi_krb5'; \
          else GSSAPILIB='-lgssapi'; \
        fi; \
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -O -Usun -DSVR4 -DSOLARIS9 -DSTERMIOX -DSELECT -DFNFLOAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET  -DBIGBUFOK \
	-DCK_AUTHENTICATION -DCK_SSL -DZLIB -DCK_KERBEROS -DKRB5 \
	-DCK_ENCRYPTION -DCK_CAST $$OPENSSLOPTION \
	$$HAVE_DES $(SSLINC) $(K5INC) $(K5INC)/krb5 $(KFLAGS)" \
	"LIBS= $(SSLLIB) $(K5LIB) -lz -lssl -ltermlib -lsocket -lnsl -lm \
	-lresolv -lcrypto \
	$$GSSAPILIB -lkrb5 -lcom_err -lk5crypto $$DES_LIB $(LIBS)"

#Solaris 9, 10, or 11 with gcc, 64 bit build.
#Peeking inside FILE struct not allowed in 64-bit world.
#DON'T USE THIS ONE ON PC ARCHITECTURE - It compiles and links but won't run.
#OK: 2009/09/25 (but not tested on Solaris 11)
solaris9g64 solaris10g64 solaris11g64:
	@echo 'Making C-Kermit $(CKVER) for Solaris 9++ with gcc 64-bit'
	@case `uname -r` in \
	  5.9) SOLARISVERSION="-DSOLARIS9" ;; \
	  5.10) SOLARISVERSION="-DSOLARIS10" ;; \
	  5.11) SOLARISVERSION="-DSOLARIS11" ;; \
	  *) SOLARISVERSION="-DSOLARIS" ;; \
	esac ; \
	$(MAKE) "MAKE=$(MAKE)" CC="gcc -m64" CC2="gcc -m64" xermit \
	KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -g -O -Usun -funsigned-char \
	-DSVR4 $$SOLARISVERSION -DNOARROWKEYS \
	-DSTERMIOX -DSELECT -DFNFLOAT -DUSE_STRERROR -DCK_PAM -DCK_SHADOW \
	-DHAVE_STREAMS -DHAVE_GRANTPT -DHAVE_PTSNAME -DPUSH_PTEM \
	-DPUSH_LDTERM -DPUSH_TTCOMPAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -ltermlib -lsocket -lnsl -lm -lresolv -lpam $(LIBS)"

#Solaris 9, 10, or 11 with SunPro CC
#Uses streams PTYs rather than BSD ptys as in C-Kermit 8.0 and earlier.
#This target is chained to by the secure targets below.
#OK C-Kermit 9.0
solaris9 solaris10 solaris11:
	@echo 'Making C-Kermit $(CKVER) for Solaris 9 or later with Sun CC'
	@case `uname -r` in \
	  5.9) SOLARISVERSION="-DSOLARIS9" ;; \
	  5.10) SOLARISVERSION="-DSOLARIS10" ;; \
	  5.11) SOLARISVERSION="-DSOLARIS11" ;; \
	  *) SOLARISVERSION="-DSOLARIS" ;; \
	esac ; \
	$(MAKE) "MAKE=$(MAKE)" xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -Usun -DSVR4 $$SOLARISVERSION -DUSE_STRERROR \
	-DSTERMIOX -DSELECT -DFNFLOAT -DCK_PAM -DCK_SHADOW \
	-DHAVE_STREAMS -DHAVE_GRANTPT -DHAVE_PTSNAME -DPUSH_PTEM \
	-DPUSH_LDTERM -DPUSH_TTCOMPAT \
	-DCK_CURSES -DCK_NEWTERM -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-D_FILE_OFFSET_BITS=64 $(KFLAGS)" \
	"LIBS= $(LIBS) -ltermlib -lsocket -lnsl -lm -lresolv -lpam"

# Solaris 9, 10, or 11 with OpenSSL built with Sun CC.
# Here's an example of how to invoke this target in case your OpenSSL
# headers and libraries are not in /usr/local:
#
# make solaris9+openssl "SSLINC=" "SSLLIB=" \
#  "KFLAGS= -I/opt/openssl-0.9.8k/include -L/opt/openssl-0.9.8k/lib"
#
# Don't use 'make -e' because that inhibits passing of KFLAGS to
# the base (solaris9) target.
#
#OK C-Kermit 9.0
solaris9+ssl solaris10+ssl solaris11+ssl \
solaris9+openssl solaris10+openssl solaris11+openssl:
	@echo 'Making C-Kermit $(CKVER) for Solaris 9/10/11 with OpenSSL: cc'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac ; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes425'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	$(MAKE) "MAKE=$(MAKE)" solaris9 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DCK_AUTHENTICATION -DCK_SSL -DZLIB $$HAVE_DES \
	-DNO_DCL_INET_ATON $$OPENSSLOPTION $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -lz -lssl $$DES_LIB -lcrypto  $(LIBS)"

# Solaris 9 or later with OpenSSL, built with gcc.
# Remove -DNO_DCL_INET_ATON if inet_aton comes up missing.  This target nicely
# chains to the solaris{9,10,11}g target but for some reason it doesn't work if
# you add the -DFORWARD_X option, thus the solaris9g+openssl+forward_x target.
#
#OK: 2011/06/14
solaris9g+ssl solaris10g+ssl solaris11g+ssl \
solaris9g+openssl solaris10g+openssl solaris11g+openssl:
	@echo 'Making C-Kermit $(CKVER) for Solaris 9/10/11 with OpenSSL: gcc'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac ; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes425'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	$(MAKE) "MAKE=$(MAKE)" solaris9g KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DCK_AUTHENTICATION -DCK_SSL -DZLIB $$HAVE_DES \
	-DNO_DCL_INET_ATON $$OPENSSLOPTION $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -lz -lssl $$DES_LIB -lcrypto  $(LIBS)"

# Solaris 9 or later with gcc + OpenSSL + Shadow (32-bit).
# Remove -DNO_DCL_INET_ATON if inet_aton comes up missing.
# Includes long file support - not sure if this was available before Solaris 9.
# Detects Solaris version automatically.
#
solaris9g+openssl+forward_x:
	@echo 'Making C-Kermit $(CKVER) for Solaris 9 or later with OpenSSL...'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac ; case `uname -r` in \
	  5.9) SOLARISVERSION="-DSOLARIS9" ;; \
	  5.10) SOLARISVERSION="-DSOLARIS10" ;; \
	  5.11) SOLARISVERSION="-DSOLARIS11" ;; \
	  *) SOLARISVERSION="-DSOLARIS" ;; \
	esac ; \
	$(MAKE) xermit 	KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"CFLAGS = -g -O -Usun -DSVR4 $$SOLARISVERSION \
	-DHAVE_STREAMS -DHAVE_GRANTPT -DHAVE_PTSNAME -DPUSH_PTEM \
	-DPUSH_LDTERM -DPUSH_TTCOMPAT \
	-DSTERMIOX -DSELECT -DFNFLOAT -DBIGBUFOK -D_FILE_OFFSET_BITS=64 \
	-DCK_AUTHENTICATION -DCK_SSL -DCK_PAM -DCK_SHADOW -DZLIB -DLIBDES \
	-DFORWARD_X $$OPENSSLOPTION $(SSLINC) $(KFLAGS)" \
	"LIBS= $(SSLLIB) -lpam -ldes425 -lz -ltermlib \
	-lsocket -lnsl -lm -lresolv -lssl -lcrypto -lpam -lz $(LIBS)"

# These two should be folded in with the ones just above.

#Solaris 9 with gcc 3.1 + OpenSSL (32-bit)
solaris9g+openssl+zlib+pam+shadow:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg32+openssl+zlib+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS9 -DUSE_STRERROR $(KFLAGS)"

#Solaris 10 with gcc 3.1 + OpenSSL (32-bit)
solaris10g+openssl+zlib+pam+shadow:
	$(MAKE) "MAKE=$(MAKE)" solaris2xg32+openssl+zlib+pam+shadow \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSOLARIS10 -DUSE_STRERROR $(KFLAGS)"

#The following (old, old) sunosxxx entries are for debugging and testing only.

sunos41x:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DSUNOS41 -DDIRENT -DNOTLOG -DNOMSEND \
	-DNOUUCP -DNOSIGWINCH -DNOREDIRECT -DNOPUSH -DNOCCTRAP \
	-DNOICP -DNOLOCAL $(KFLAGS)"

#SunOS 4.1.x, debugging with Pure Software, Inc., Purify 2 (commercial runtime
#error-detection software for catching wild array references, etc).
#Before running the resulting wermit, you'll also need to define and export
#the following environment variables (as in this example):
#PURIFYHOME=/usr/local/purify ; export PURIFYHOME
#PURIFYCACHEDIR=/tmp ; export PURIFYCACHEDIR
sunos41cp:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 / BSD / Curses / Purify...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CC2= purify -cache_dir=/usr/tmp cc" \
	"CFLAGS= -g -DSUNOS41 -DHDBUUCP -DDIRENT -DTCPSOCKET \
	-DSAVEDUID -DCK_CURSES $(KFLAGS)" \
	"LIBS= -lcurses -ltermcap"

#SunOS 4.1 with malloc debugger
sunos41md:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 malloc debug...
	$(MAKE) mermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DSUNOS41 -DHDBUUCP -DDIRENT -DTCPSOCKET \
	-DSAVEDUID $(KFLAGS) -Dmalloc=dmalloc -Dfree=dfree -DMDEBUG"

sunos41gmd:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 with gcc and curses...
	$(MAKE) mermit KTARGET=$${KTARGET:-$(@)} "CC= gcc " "CC2= gcc" \
	"CFLAGS= -g -DSUNOS41 -DHDBUUCP -DDIRENT -DTCPSOCKET \
	-DNDGPWNAM -DSAVEDUID -DCK_CURSES -DRLOGCODE \
	$(KFLAGS) -Dmalloc=dmalloc -Dfree=dfree -DMDEBUG" \
	"LIBS= -lcurses -ltermcap"

#SunOS version 4.1, gcc, profiling with gprof, no debugging.
#To get profile, "make sunos41p" (on Sun), then "./wermit".  After running
#wermit, "gprof ./wermit | lpr" (or whatever) to get execution profile.
sunos41p:
	@echo Making C-Kermit $(CKVER) for SunOS 4.x with profiling...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC= gcc " "CC2= gcc" \
	"CFLAGS= -DSUNOS41 -DNODEBUG -DSAVEDUID -DDIRENT -DTCPSOCKET \
	-DNDGPWNAM $(KFLAGS) -pg" "LNKFLAGS = -pg"

#SunOS version 4.1 or later, BSD environment, minimum features.
sunos41min:
	@echo Minimum interactive
	$(MAKE) "MAKE=$(MAKE)" sunos41 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOSPL -DNOXMIT -DNOMSEND -DNOFRILLS -DNORETRY \
	-DNODIAL -DNOHELP -DNODEBUG -DNOTLOG -DNOSCRIPT -DNOCSETS \
	-DNOSHOW -DNOSETKEY -DNOUUCP -DNORECALL -DNOREDIRECT \
	-DNOPUSH -DNOMDMHUP -DNOJC -DNOFDZERO -DNOESCSEQ \
	-DNONET -DCK_SMALL -DNOCKSPEED -DNOCKTIMERS -DNOLOGIN \
	-DNOCKXYZ -DNOKERBEROS -DNOMKDIR -DNOPATTERNS -DNOPERMS -DNOPIPESEND \
	-DNORECURSIVE -DNORENAME -DNORESEND -DNOSETKEY \
	-DNOTRIGGER -DNOTUNING $(KFLAGS)" "LNKFLAGS = -s"

#SunOS version 4.1, BSD environment, min size, command-line only...
sunos41m:
	@echo Minimum size
	$(MAKE) "MAKE=$(MAKE)" sunos41min KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOICP $(KFLAGS)"

#SunOS version 4.1, BSD environment, min size, cmd-line only, remote only...
#
sunos41mr:
	@echo Minimum size
	$(MAKE) "MAKE=$(MAKE)" sunos41min KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOICP -DNOLOCAL $(KFLAGS)"

#SunOS version 4.1, BSD environment, min size, interactive...
sunos41mi:
	@echo Minimum size
	$(MAKE) "MAKE=$(MAKE)" sunos41min KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOCMDL $(KFLAGS)"

#SunOS version 4.1, BSD environment, min size, interactive, remote only...
sunos41mir:
	@echo Minimum size
	$(MAKE) "MAKE=$(MAKE)" sunos41min KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOCMDL -DNOLOCAL $(KFLAGS)"

#SunOS 4.1, System V R3 environment (-i option omitted).
sunos41s5:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 System V R3...
	@echo For testing purposes only - NOT for production use.
	@echo For a useable version, make sunos41 instead.
	$(MAKE) wermit "CC= /usr/5bin/cc " "CC2=/usr/5bin/cc " \
	KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSUN4S5 -DDIRENT -DHDBUUCP -DNOLEARN -DCK_POLL $(KFLAGS) -O"

#As above, but with curses support
sunos41s5c:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 System V R3...
	@echo Curses included.
	@echo For testing purposes only - NOT for production use.
	@echo For a useable version, make sunos41 instead.
	$(MAKE) wermit "CC= /usr/5bin/cc " "CC2=/usr/5bin/cc " \
	KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSUN4S5 -DDIRENT -DHDBUUCP -DNOLEARN \
	-DCK_POLL -DCK_CURSES -DCK_NEWTERM $(KFLAGS) -O" "LIBS= -lcurses"

#As above, but with curses support AND net support
sunos41s5tcpc:
	@echo Making C-Kermit $(CKVER) for SunOS 4.1 System V R3...
	@echo TCP/IP and curses included.  No debug log.
	@echo For testing purposes only - NOT for production use.
	@echo For a useable version, make sunos41 instead.
	$(MAKE) xermit "CC= /usr/5bin/cc " "CC2=/usr/5bin/cc " \
	KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSUN4S5 -DDIRENT -DHDBUUCP -DCK_POLL \
	-DNODEBUG -DCK_CURSES -DCK_NEWTERM -DTCPSOCKET $(KFLAGS) -O" \
	"LIBS= -lcurses -lresolv"

# (End of SunOS test entries...)

#Apollo with Domain SR10.0 or later, BSD environment
#Reportedly, it might also help to add '-A,systype=bsd4.3' to CFLAGS.
#Reportedly, there is also a problem with getc & putc macros that can
#be handled by using '#ifdef apollo' somewhere to redefine them???
#On the other hand, other reports indicate that it works fine as-is.
#NOTE: This entry was previously like this:
#	$(MAKE) wermit "CFLAGS= -DNOFILEH -DBSD4 $(KFLAGS) -Uaegis \
#	-DTCPSOCKET -U__STDC__"
#Reports (Dec 91) indicate SR10 has an ANSI-compliant C compiler,
#in addition to an older one that claimed to be ANSI-compliant but wasn't.
#The following make entry (plus checks that are made in ckcdeb.h) detect
#which compiler is used and define the CK_ANSIC or NOANSI flags accordingly.
sr10-bsd:
	@echo Making C-Kermit $(CKVER) for Apollo SR10.0 / BSD ...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DAPOLLOSR10 -DBSD43 -DTCPSOCKET -DCK_CURSES -DNOLEARN \
	-Uaegis $(KFLAGS)" "LIBS= -lcurses -ltermcap"

#Apollo with Domain SR10.0 or later, System V R3 environment.
#Don't use the optimizer (-O), it causes problems at runtime.
sr10-s5r3:
	@echo Making C-Kermit $(CKVER) for Apollo SR10.0 / Sys V R3 ...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNOFILEH -DSVR3 -DAPOLLOSR10 -DNOLEARN $(KFLAGS) \
	-Uaegis -U__STDC__"

#Apollo Domain/IX (untested, try this if sr10-bsd doesn't work)
# -DTCPSOCKET can probably be added here.
apollobsd:
	@echo Making C-Kermit $(CKVER) for Apollo Domain/IX...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CC= /bin/cc " "CC2= /bin/cc " \
	"CFLAGS= -DNOFILEH -DBSD4 -DAPOLLOBSD -DNOLEARN $(KFLAGS) -Uaegis"

#Version 7 Unix (see comments near top of makefile)
v7:
	@echo Making C-Kermit $(CKVER) for UNIX Version 7.
	@echo Read the makefile if you have trouble with this...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS=-DV7 -DPROCNAME=\\\"$(PROC)\\\" \
	-DBOOTNAME=\\\"$(BOOTFILE)\\\" -DNPROCNAME=\\\"$(NPROC)\\\" \
	-DNPTYPE=$(NPTYPE) $(DIRECT) -DO_RDWR=2 -DO_NDELAY=0 -DO_SCCS_ID \
	-DNOLEARN $(KFLAGS)"

#AT&T UNIX System V R3, signal() is void rather than int.
#Uses dirent.h and Honey DanBer UUCP.
#Add the -i link option if necessary.
#If you get errors like "ws_row undefined" in ckutio.c, add -DNONAWS.
sys5r3:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -DNOLEARN $(KFLAGS) -O" \
	"LNKFLAGS="

#As above, plus curses.
sys5r3c:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R3 + curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -DCK_CURSES -DNONAWS -DNOLEARN \
	$(KFLAGS) -O" "LNKFLAGS=" "LIBS = -ltermlib"

#System V R3.2 for PCs built on Interactive UNIX SV/386 R4.x
#but with all calls to dup2() disabled because generic SVR3 does not have dup2.
# (The -linet library might not need to be in this one.)
sys5r32is:
	@echo 'Making C-Kermit $(CKVER) for System V/386 R32
	$(MAKE) wermit CC="$(CC)" CC2="$(CC2)" \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -O -DNOCSETS -DNOREALPATH \
	-DUID_T=ushort -DGID_T=ushort -DI386IX -DSVR3JC -DCK_CURSES -DNONAWS \
	-DPOSIX_JC -DCK_REDIR -DCK_POLL -DDCLGETCWD -DNOFDZERO -DNOREDIRECT \
	-DNOZEXEC -DNOLEARN $(KFLAGS)" "LIBS=-lcurses -lc_s -linet"

#System V R3.2 for PCs built on Interactive UNIX SV/386 R4.x
#but with all calls to dup2() disabled because generic SVR3 does not have dup2.
#With TCP/IP added.
sys5r32isnet:
	@echo 'Making C-Kermit $(CKVER) for System V/386 R32 + TCP/IP
	$(MAKE) wermit CC="$(CC)" CC2="$(CC2)" \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -O -DNOCSETS -DNOREALPATH \
	-DUID_T=ushort -DGID_T=ushort -DI386IX -DSVR3JC -DCK_CURSES -DNONAWS \
	-DPOSIX_JC -DCK_REDIR -DCK_POLL -DDCLGETCWD -DNOFDZERO -DNOREDIRECT \
	-DNOLEARN -DNOZEXEC -DTCPSOCKET $(KFLAGS)" "LIBS=-lcurses -lc_s -linet"

iclsys5r3:
	make sys5r3 KTARGET=$${KTARGET:-$(@)} KFLAGS=-DICLSVR3

#AT&T UNIX System V R3.  As above, but no ANSI prototyping.
sys5r3na:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -DNOANSI -DNOLEARN $(KFLAGS) -O" \
	"LNKFLAGS="

#AT&T UNIX System V R3, for 3B computers with Wollongong TCP/IP.
sys5r3net3b:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX SVR3/3B/Wollongong...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DWOLLONGONG -DNOLEARN $(KFLAGS) \
	-O" "LIBS= -lnet -lnsl_s" "LNKFLAGS ="

#AT&T UNIX System V R3, signal() is void rather than int.
#Uses dirent.h and Honey DanBer uucp, has <termiox.h>.
#Has <termiox.h> for RTS/CTS flow control.
sys5r3tx:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DTERMIOX -DNOLEARN \
	$(KFLAGS) -i -O" "LNKFLAGS ="

#AT&T UNIX System V R3, signal() is void rather than int.
#Uses dirent.h and Honey DanBer uucp, has <termiox.h>.
#Has <sys/termiox.h> for RTS/CTS flow control.
sys5r3sx:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DSTERMIOX -DNOLEARN \
	$(KFLAGS) -i -O" "LNKFLAGS ="

#AT&T UNIX System V R4.
#Has <termiox.h>.
sys5r4:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DTERMIOX -DNOLEARN $(KFLAGS)" \
	"LNKFLAGS = -s"

#AT&T UNIX System V R4 with Wollongong TCP/IP.
#Has <termiox.h>.
sys5r4net:
	@echo 'Making C-Kermit $(CKVER) for System V R4 + Wollongong TCP/IP...'
	@echo ' If sockets-library routines are missing at link time, then'
	@echo ' try the sys5r4net2 entry.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DNOLEARN \
	-DTERMIOX -DWOLLONGONG $(KFLAGS)" "LNKFLAGS = -s"

#As above, but needs libs included.
sys5r4net2:
	@echo ' PLEASE READ ckuins.txt IF YOU GET MISSING HEADER FILES.'
	@echo ' (Search for WOLLONGONG...)'
	$(MAKE) sys5r4net KTARGET=$${KTARGET:-$(@)} "LIBS= -lsocket -lnsl"

#As above plus curses.
sys5r4net2c:
	echo 'Making C-Kermit $(CKVER) for System V R4 + Wollongong TCP/IP...'
	@echo ' PLEASE READ ckuins.txt IF YOU GET MISSING HEADER FILES.'
	@echo ' (Search for WOLLONGONG...)'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DNOLEARN \
	-DTERMIOX -DWOLLONGONG -DCK_CURSES $(KFLAGS)" "LNKFLAGS = -s" \
	"LIBS= -lsocket -lnsl -lcurses"

#DELL UNIX System V R4.
#Has <sys/termiox.h>, regular Berkeley sockets library, i.e. in.h and inet.h
#are not misplaced in sys (rather than netinet and arpa, respectively).
#Uses ANSI C constructs, advisory file locking on devices, etc.
#Warning: -DSTERMIOX enables hardware flow control (RTS/CTS), but reportedly
#this does not work with the normal drivers.  However, it might still work
#on non-Dell systems, or even Dell systems with different drivers installed.
dellsys5r4:
	@echo 'Making C-Kermit $(CKVER) for DELL UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDELL_SVR4 -DDIRENT -DHDBUUCP \
	-DTCPSOCKET -DSTERMIOX -DCK_POLL $(KFLAGS)" \
	"LIBS= -lsocket -lnsl" "LNKFLAGS = -s"

#As above, curses support added...
dellsys5r4c:
	@echo 'Making C-Kermit $(CKVER) for DELL UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDELL_SVR4 -DDIRENT -DHDBUUCP \
	-DTCPSOCKET -DSTERMIOX -DCK_CURSES -DCK_POLL \
	$(KFLAGS)" "LIBS= -lsocket -lnsl -lcurses -ltermcap" "LNKFLAGS = -s"

#Minimum interactive: As above, but with every conceivable option removed.
dellsys5r4mi:
	@echo 'Making C-Kermit $(CKVER) for DELL UNIX System V R4...'
	@echo 'Minimum-size interactive'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDELL_SVR4 -DDIRENT \
	-UTCPSOCKET -DNOCMDL -DNOSPL -DNOXMIT -DCK_POLL \
	-DNOMSEND -DNOFRILLS -DNODIAL -DNOHELP -DNODEBUG -DNOTLOG \
	-DNOSCRIPT -DNOCSETS -DNOSHOW -DNOSETKEY -DNOSERVER -DNOUUCP \
	-DNOPUSH -DNOMDMHUP -DNOJC -DNOFDZERO -DNOESCSEQ  \
	$(KFLAGS)" "LNKFLAGS = -s"

#Command-line only version.
dellsys5r4m:
	@echo 'Making C-Kermit $(CKVER) for DELL UNIX System V R4...'
	@echo 'Command-line only'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDELL_SVR4 -DDIRENT \
	-UTCPSOCKET -DNOICP -DNOFRILLS -DNODIAL -DNODEBUG -DNOTLOG -DNOCSETS \
	-DNOSETKEY -DNOESCSEQ -DNOJC -DNOFDZERO -DCK_POLL \
	$(KFLAGS)" "LNKFLAGS = -s"

#AT&T UNIX System V R4.
#Has <sys/termiox.h>.
sys5r4sx:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DSTERMIOX -DNOLEARN \
	$(KFLAGS)" "LNKFLAGS = -s" "LIBS=$(LIBS)"

#AT&T UNIX System V R4.
#Has <sys/termiox.h>, regular Berkeley sockets library, i.e. in.h and inet.h
#are not misplaced in sys (rather than netinet and arpa, respectively).
#Uses ANSI C constructs, <sys/termiox.h>, etc etc.
sys5r4sxtcp:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -lsocket -lnsl $(LIBS)" "LNKFLAGS= -s"

#AT&T UNIX System V R4.
#As above + curses.
sys5r4sxtcpc:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX  -DCK_CURSES -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap $(LIBS)" "LNKFLAGS = -s"

#AT&T UNIX System V R4.  CONSENSYS SVR4.2-1.
#Has <sys/termiox.h>, regular Berkeley sockets library, i.e. in.h and inet.h
#are not misplaced in sys (rather than netinet and arpa, respectively).
#Uses ANSI C constructs, <sys/termiox.h>, etc.
# Fullscreen -DCK_CURSES added (with curses & termcap libs)
# Submission by Robert Weiner/Programming Plus, [email protected]
sys5r4sxtcpf:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -L/usr/ccs/lib -lcurses -ltermcap" \
	"LIBS=$(LIBS)" "LNKFLAGS = -s"

#Smallest possible version for System V R4
s5r4m:
	@echo Minimum size
	$(MAKE) "MAKE=$(MAKE)" sys5r4sx KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DNODIAL -DNOHELP -DNODEBUG -DNOTLOG \
	-DNOSCRIPT -DNOCSETS -DNOICP -DNOMSEND -UTCPSOCKET" "LNKFLAGS = -s"

#Smallest possible interactive version of above
s5r4mi:
	@echo Minimum interactive
	$(MAKE) "MAKE=$(MAKE)" sys5r4sx \
	"KFLAGS=-DNOSPL -DNOXMIT -DNOMSEND -DNOFRILLS -DNOSHOW \
	-DNODIAL -DNOHELP -DNODEBUG -DNOTLOG -DNOSCRIPT -DNOCSETS -DNOSETKEY \
	-UTCPSOCKET $(KFLAGS)" "LNKFLAGS = -s"

#AT&T UNIX System V R4, has <sys/termiox.h>
#ANSI C function prototyping disabled.
sys5r4sxna:
	@echo No ANSI C prototyping...
	$(MAKE) "MAKE=$(MAKE)" sys5r4sx KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DNOANSI"

#Stratus FTX.
ftx:
	@echo 'Making C-Kermit $(CKVER) for Stratus FTX 3.x...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DFTX -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DNOGETUSERSHELL -DNOLEARN +DA1.1 $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS=$(LIBS)"

#Stratus FTX + TCP/IP.
ftxtcp:
	@echo 'Making C-Kermit $(CKVER) for Stratus FTX 3.x...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DFTX -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DSTERMIOX -DTCPSOCKET -DNO_DNS_SRV +DA1.1 $(KFLAGS)" \
	"LIBS= -lsocket -lnsl $(LIBS)" "LNKFLAGS= -s"

#NCR MP-RAS 2.03 or 3.02
mpras:
	@echo 'Making C-Kermit $(CKVER) for NCR MP-RAS...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DNCRMPRAS -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DNOGETUSERSHELL -DUSE_FILE__CNT -DNOLEARN -DNO_DNS_SRV $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS=$(LIBS)"

#NCR MP-RAS 2.03 or 3.02 with TCP/IP and curses
mprastcpc:
	@echo 'Making C-Kermit $(CKVER) for NCR MP-RAS + TCP/IP + curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CFLAGS=-DTCPSOCKET \
	-DCK_CURSES -DSVR4 -DNCRMPRAS -DDIRENT -DHDBUUCP -DSTERMIOX -DNOLEARN \
	-DNOGETUSERSHELL -DNO_DNS_SRV DUSE_FILE__CNT -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS= -lsocket -lnsl -lcurses -ltermcap $(LIBS)"

#SINIX-L V5.41 - includes curses, tcp/ip - Use this one for i386.
#This version of SINIX doesn't like fdopen() or popen().
sinix541:
	@echo 'Making C-Kermit $(CKVER) for Siemens/Nixdorf SINIX V5.41/i386'
	$(MAKE) ckcpro.$(EXT) "CFLAGS = -DSINIX -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX -DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC -DNO_DNS_SRV \
	-DSNI541 -DNOGETUSERSHELL -DNONETCMD -DNOPOPEN -kansi -W0 $(KFLAGS)"
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSINIX -DSVR4 -DDIRENT -DHDBUUCP -DNO_DNS_SRV -DNOPOPEN \
	-DFNFLOAT -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC \
	-DSNI541 -DNOGETUSERSHELL -DNONETCMD -kansi -W0 -O $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap -lm" "LNKFLAGS = -s"

sinix541i:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=$(KFLAGS)" sinix541

#SINIX V5.42 - includes curses, tcp/ip, everything - Use this one for MIPS.
# As of C-Kermit 7.1, optimization removed -- takes (literally) forever.
sinix542:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSINIX -DSVR4 -DDIRENT -DHDBUUCP -DNO_DNS_SRV \
	-DFNFLOAT -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC \
	-DSNI542 -DNOGETUSERSHELL -kansi -W0 $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap -lm" "LNKFLAGS = -s"

#SINIX V5.42 gcc - includes curses, tcp/ip, everything.
#This one was used to build the Pyramid-architecture RM600 version
#on SINIX-P 5.42 A10 with gcc but should work for SINIX 5.42 on any other
#architecture with gcc.
sinix542g:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC=gcc" "CC2=gcc" \
	"CFLAGS = -DSINIX -DSVR4 -DDIRENT -DHDBUUCP -DNO_DNS_SRV \
	-DFNFLOAT -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC \
	-DSNI542 -DNOGETUSERSHELL $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap -lm" \
	"LNKFLAGS = -s"

#SINIX V5.42 - includes curses, tcp/ip, everything - Use this one for Intel.
# (Note: SNI discontinued Intel support after 5.42.)
sinix542i:
	@echo 'Making C-Kermit $(CKVER) for Siemens/Nixdorf SINIX-Z V5.42...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSINIX -DSVR4 -DDIRENT -DHDBUUCP -DFNFLOAT -DSTERMIOX \
	-DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC -DNO_DNS_SRV -kansi \
	-DSNI542 $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap -lm" \
	"LNKFLAGS = -s"

#Siemens Nixdorf Reliant UNIX V5.43 - includes curses, tcp/ip, everything:
# . gettimeofday() suddenly has only one arg instead of two (GTODONEARG).
# . The syntax of the Olimit specifier changed.
# . The name was changed from SINIX to Reliant UNIX in version 5.43C.
sni543:
	@echo 'Making C-Kermit $(CKVER) for Siemens/Nixdorf Reliant UNIX V5.43'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSINIX -DSNI543 -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX -DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC -DGTODONEARG \
	-DNO_DNS_SRV -kansi -W0 -O -F Olimit,3100 $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap" "LNKFLAGS = -s"

#Siemens Nixdorf Reliant UNIX V5.44 - Like 5.43 but with different banner.
sni544:
	@echo 'Making C-Kermit $(CKVER) for Siemens/Nixdorf Reliant UNIX V5.44'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSINIX -DSNI544 -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX -DCK_CURSES -DTCPSOCKET -DSELECT -DCK_ANSIC -DGTODONEARG \
	-DNO_DNS_SRV -kansi -W0 -O -K Olimit,3100 $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap" "LNKFLAGS = -s"

#Commodore Amiga with AT&T UNIX System V R4 and TCP/IP support.
#Has <sys/termiox.h>.
svr4amiganet:
	@echo 'Making C-Kermit $(CKVER) for Amiga SVR4 + TCP/IP...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC=gcc" "CC2=gcc" \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DTCPSOCKET -DCK_CURSES $(KFLAGS)" "LNKFLAGS = -s" \
	"LIBS = -lsocket -lnsl -ltermlib"

#SCO (Novell (Univel)) UnixWare 1.x or 2.0, no TCP/IP.
#This assumes the Novell SDK 1.0, which has <sys/termiox.h>.
#UnixWare users with the "Prime Time Freeware" CD-ROM SDK will probably have
#to use the sys5r4 entry (no termiox.h file, so no hardware flow control).
#Change -DSELECT to -DCK_POLL if -DSELECT causes problems.
# NOTE: Unixware 1.x builds have not been tried in C-Kermit 7.0.
unixware:
	$(MAKE) "MAKE=$(MAKE)" sys5r4sx KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DOLD_UNIXWARE -DCK_NEWTERM -DSELECT -DNOGETUSERSHELL \
	-DNOSYSLOG $(KFLAGS)" "LIBS=-lcrypt"

#UnixWare 1.x or 2.0 with TCP/IP and curses.
#fork()-based CONNECT - no high serial speeds.
unixwarenetc:
	$(MAKE) "MAKE=$(MAKE)" sys5r4sxtcpc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DOLD_UNIXWARE -DCK_NEWTERM -DSELECT -DNOGETUSERSHELL \
	-DNOSYSLOG $(KFLAGS)" "LIBS=-lcrypt -lresolv"

uw10:
	$(MAKE) unixwarenetc KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS)"

#This is for Unixware 2.0.x only - use unixware21 for UW 2.1.x.
#Has special library search and enables special kludge around library
#foulup regarding vfork() (which Kermit doesn't use).  Forces POSIX-style
#hangup.
unixware20:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 2.0.x...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DOLD_UNIXWARE -DUNIXWARE2 -DSELECT -DSVR4 -DDIRENT \
	-DHDBUUCP -DBIGBUFOK -DNOGETUSERSHELL -DSTERMIOX  -DCK_CURSES \
	-DTCPSOCKET -DUW200 -DFNFLOAT -DCK_NEWTERM -DNOSYSLOG $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap -lcrypt -lgen -lm -lresolv" \
	"LNKFLAGS = -s"

uw20:
	$(MAKE) unixware20 KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS)"

#Adds big buffers ("large memory model") - otherwise the same as UnixWare 1.x.
unixware21:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 2.1.x...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DUNIXWARE -DSELECT -DSVR4 -DDIRENT -DHDBUUCP -DBIGBUFOK \
	-DNOSYSLOG -DSTERMIOX  -DCK_CURSES -DTCPSOCKET \
	-DCK_NEWTERM -DFNFLOAT -DUNIXWARE2 $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -ltermcap -lcrypt -lm -lresolv \
	$(LIBS)" "LNKFLAGS = -s"

#Unixware 2.1.0
uw21:
	$(MAKE) unixware21 KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS)"

#Unixware 2.1.3
uw213:
	$(MAKE) unixware21 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DUSE_FILE__CNT $(KFLAGS)"

#Unixware 2.1 with IKSD support
uw21iksd:
	$(MAKE) unixware21 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DCK_SHADOW $(KFLAGS)" "LIBS= -lgen"

#UnixWare 7 with tc[gs]etspeed() high serial speeds & select()-based CONNECT
#and as of C-Kermit 8.0.212, large file support (LFS).
#NOTE: This is the one we use.
unixware7t:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 7 with POSIX i/o...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DUNIXWARE -DSELECT -DSVR4 -DDIRENT -DHDBUUCP -DBIGBUFOK \
	-DFNFLOAT -DNOGETUSERSHELL -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DPOSIX \
	-DUW7 -DUSETCSETSPEED -DCK_NEWTERM -DNOLSTAT -DDCLTIMEVAL \
	-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DNEEDMDMDEFS $(KFLAGS)" \
	"LIBS=-lsocket -lnsl -lcurses -ltermcap -lcrypt -lm -lresolv $(LIBS)" \
	"LNKFLAGS = -s"

#UnixWare 7 - select()-based CONNECT - no POSIX i/o - no high serial speeds.
#In other words, just like the UnixWare 1 and 2 builds.
unixware7x:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 7...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DUNIXWARE -DSELECT -DSVR4 -DDIRENT -DHDBUUCP -DBIGBUFOK \
	-DUW7 -DNOGETUSERSHELL -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DNOLSTAT \
	-DFNFLOAT -DCK_NEWTERM $(KFLAGS)" \
	"LIBS=-lsocket -lnsl -lcurses -ltermcap -lcrypt -lm -lresolv $(LIBS)" \
	"LNKFLAGS = -s"

#UnixWare 7 with POSIX cfset[oi]speed() to allow high serial speeds.
#(but the high speeds don't work)
unixware7p:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 7 with POSIX i/o...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DUNIXWARE -DSELECT -DSVR4 -DDIRENT -DHDBUUCP -DBIGBUFOK \
	-DUW7 -DNOGETUSERSHELL -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DPOSIX \
	-DFNFLOAT -DCK_NEWTERM -DNOLSTAT $(KFLAGS)" \
	"LIBS=-lsocket -lnsl -lcurses -ltermcap -lcrypt -lm -lresolv $(LIBS)" \
	"LNKFLAGS = -s"

# UnixWare 7 built with gcc - This does not work at all...
# Reportedly gcc 2.8.1 is broken on Unixware 7.  Try egcs?
unixware7g:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 7 with gcc...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CC = gcc" "CC2 = gcc" "LNKFLAGS = -s -shlib"
	"CFLAGS = -O -DUNIXWARE -DSELECT -DSVR4 -DDIRENT -DHDBUUCP -DBIGBUFOK \
	-DUW7 -DNOGETUSERSHELL -DSTERMIOX  -DCK_CURSES -DTCPSOCKET -DNOLSTAT \
	-DFNFLOAT -DCK_NEWTERM $(KFLAGS)" \
	"LIBS=-lsocket -lnsl -lcurses -ltermcap -lcrypt -lm -lresolv $(LIBS)" \
	"LNKFLAGS = -s"

unixware7:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=$(KFLAGS)" unixware7t \
	KTARGET=$${KTARGET:-$(@)}

uw7:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=$(KFLAGS)" unixware7t \
	KTARGET=$${KTARGET:-$(@)}

#SCO OpenUNIX 8.0
ou8:
	@echo 'Making C-Kermit $(CKVER) for Open UNIX 8...'
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=-DOU8 $(KFLAGS)" unixware7t \
	KTARGET=$${KTARGET:-$(@)}

#UnixWare 7 with OpenSSL
uw7ssl uw7+ssl:
	@echo 'Making C-Kermit $(CKVER) for UnixWare 7 and OpenSSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DCK_AUTHENTICATION -DCK_SSL -DCK_SHADOW \
	-DUNIXWARE -DSELECT -DSVR4 -DDIRENT -DHDBUUCP -DBIGBUFOK \
	-DFNFLOAT -DNOGETUSERSHELL -DSTERMIOX -DCK_CURSES -DTCPSOCKET -DPOSIX \
	-DUW7 -DUSETCSETSPEED -DCK_NEWTERM -DNOLSTAT -DDCLTIMEVAL \
	$(SSLINC) $(KFLAGS)" \
	"LIBS=-lsocket -lnsl -lcurses -ltermcap -lcrypt -lm -lresolv \
	-lgen -lcudk70 $(SSLLIB) -lssl -lcrypto $(LIBS)" \
	"LNKFLAGS = -s"

#As above but includes Shadow password support needed for IKSD.
uw7iksd:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=-DCK_SHADOW $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)} "LIBS= -lgen" unixware7t

#As above but links with static API for realpath() so a binary built
#with this target on UW7.1 will also work on 7.0.  Requires SCO UDK
#rather than the stock compiler.
uw7iksdudk:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=-DCK_SHADOW $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)} "LIBS= -lgen -lcudk70" unixware7t

#ESIX SVR4.0.3 or 4.04 with TCP/IP support.
#Has <sys/termiox.h>, ANSI C function prototyping disabled.
#Add -m486 to CFLAGS if desired.
esixr4:
	@echo 'Making C-Kermit $(CKVER) for ESIX SVR4 + TCP/IP...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DNOANSI \
	-DSTERMIOX -DTCPSOCKET $(KFLAGS)" "LNKFLAGS = -s" \
	"LIBS = -lsocket -lnsl"

#AT&T UNIX System V R4.
#Has <sys/termiox.h>, Wollongong WIN/TCP TCP/IP.
sys5r4sxnet:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP \
	-DSTERMIOX -DWOLLONGONG $(KFLAGS)" "LNKFLAGS = -s"

#AT&T UNIX System V R4, no <termio.x> or <sys/termio.x>.
sys5r4nx:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DNOLEARN $(KFLAGS)" \
	"LNKFLAGS = -s"

#AT&T UNIX System V R4, no <termio.x> or <sys/termio.x>, curses, TCP/IP.
sys5r4nxnetc:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP \
	-DCK_CURSES -DTCPSOCKET $(KFLAGS)" \
	"LIBS = -lcurses -lsocket -lnsl -ltcpip" \
	"LNKFLAGS = -s"

#AT&T UNIX System V R4, no <termio.x> or <sys/termio.x>, Wollongong TCP/IP.
sys5r4nxtwg:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System V R4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DDIRENT -DHDBUUCP -DWOLLONGONG $(KFLAGS)"
	"LNKFLAGS = -s"

#ICL UNIX System V R4.(DRS N/X) version :-
#UNIX System V Release 4.0 ICL DRS 6000 (SPARC)
#DRS/NX 6000 SVR4 Version 5  Level 1  Increment 4
#Has <sys/termiox.h>, regular Berkeley sockets library, i.e. in.h and inet.h
#are not misplaced in sys (rather than netinet and arpa, respectively).
#Uses ANSI C constructs, advisory file locking on devices, etc.
#Remove -lnsl if it causes trouble.
iclsys5r4:
	@echo 'Making C-Kermit $(CKVER) for ICL UNIX System V R4 (DRS N/X)'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DICL_SVR4 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DSTERMIOX -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lresolv " "LNKFLAGS = -s"

#As above but for DRS/NX 4.2MP 7MPlus.
iclsys5r4m+:
	@echo 'Making C-Kermit $(CKVER) for ICL UNIX System V R4 DRS/NX 4.2MP+'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DICL_SVR4 -DDIRENT -DHDBUUCP -DNOIKSD \
	-DSTERMIOX -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lm -lc -g -lgen " "LNKFLAGS = -s"

#As above but for DRS/NX 4.2MP 7MPlus with IKSD support.
iclsys5r4m+iksd:
	@echo 'Making C-Kermit $(CKVER) for ICL UNIX System V R4 DRS/NX 4.2MP+'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DICL_SVR4 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DSTERMIOX -DTCPSOCKET $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lm -lc -g -lgen -lresolv " "LNKFLAGS = -s"

iclsys5r4_486:
	$(MAKE) "MAKE=$(MAKE)" iclsys5r4 KTARGET=$${KTARGET:-$(@)}

#Data General DG/UX 4.30 (System V R3) for DG AViiON, with TCP/IP support.
dgux430:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 4.30...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX430 -DSVR3 -DDIRENT -DTCPSOCKET \
	-DNOINADDRX -DNOGETUSERSHELL $(KFLAGS)"

#Data General DG/UX 4.30 for DG AViiON, with TCP/IP support with BSDisms.
dgux430bsd:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 4.30...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX430 -D_BSD_SOURCE -DBSD4 \
	-DNOINADDRX -DTCPSOCKET -DNOGETUSERSHELL $(KFLAGS)"

#Data General DG/UX 5.4 (System V R4) for DG AViiON, with TCP/IP support.
#Add -lsocket -lnsl if inet_addr comes up missing...
#Hmmm - I really think CK_POLL can be removed from this one in which case
#there is no difference between dgux540 and dgux540i.
dgux540:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 5.40...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDIRENT -DHDBUUCP -DNOINADDRX \
	-DSTERMIOX -DTCPSOCKET -DCK_POLL -DNOGETUSERSHELL $(KFLAGS)"

#Data General DG/UX 5.40 (System V R4) for Intel AViiON, with TCP/IP support.
dgux540i:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 5.40...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDIRENT -DHDBUUCP -DNOINADDRX \
	-DSTERMIOX -DTCPSOCKET -DNOGETUSERSHELL $(KFLAGS)" \
	"LIBS = -lsocket -lnsl"

dgux54:
	make dgux540 KTARGET=$${KTARGET:-$(@)}

#Data General DG/UX 5.4 (= System V R4) for DG AViiON, with TCP/IP support.
# And curses.
dgux540c:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 5.4...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDIRENT -DHDBUUCP -DNOINADDRX \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL \
	$(KFLAGS)" "LIBS= -lcurses8 -ltermcap" "LNKFLAGS = -s"

#As above but for Intel - only difference is name library names.
dgux540ic:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 5.40...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDIRENT -DHDBUUCP -DNOINADDRX \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL \
	$(KFLAGS)" "LIBS = -lsocket -lnsl -lcurses -ltermcap"

dgux54c:
	make dgux540c KTARGET=$${KTARGET:-$(@)}

#DG/UX 5.4R3.10
dgux54310:
	@echo 'Making C-Kermit $(CKVER) for DG AViiON DG/UX 5.4R3...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DDGUX540 -DDGUX54310 -DDIRENT -DHDBUUCP -DSELECT \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES -DCK_NEWTERM	-DNOGETUSERSHELL \
	-DNOINADDRX $(KFLAGS)" "LIBS= -lcurses8 -ltermcap" "LNKFLAGS = -s"

#DG/UX 5.4R4.10 - Includes everything.
dgux54410:
	@echo 'Making C-Kermit $(CKVER) for DG/UX 5.4R4.10...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDGUX54410 -DDIRENT -DHDBUUCP -DSELECT \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL \
	-DNOINADDRX $(KFLAGS)" "LIBS = -lsocket -lnsl -lcurses -ltermcap"

#DG/UX 5.4R4.11 - Includes everything.
dgux54411:
	@echo 'Making C-Kermit $(CKVER) for DG/UX 5.4R4.11...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDGUX54411 -DDIRENT -DHDBUUCP -DSELECT \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL \
	-DNOINADDRX $(KFLAGS)" "LIBS = -lsocket -lnsl -lcurses -ltermcap"

#DG/UX 5.4R4.20 - Includes everything.
dgux54420:
	@echo 'Making C-Kermit $(CKVER) for DG/UX 5.4R4.20...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DDGUX540 -DDGUX54420 -DDIRENT -DHDBUUCP -DSELECT \
	-DSTERMIOX -DTCPSOCKET -DCK_CURSES -DCK_NEWTERM -DNOGETUSERSHELL \
	-DNOINADDRX $(KFLAGS)" \
	"LIBS = -lsocket -lresolv -lnsl -lcurses -ltermcap"

#Silicon Graphics System V R3 with BSD file system (IRIS)
iris:
	@echo Making C-Kermit $(CKVER) for Silicon Graphics IRIX pre-3.3...
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR3 -DLONGFN -DNOLEARN $(KFLAGS) -I/usr/include/bsd" \
	"LIBS = -lbsd"

#Silicon Graphics IRIS System V R3
irix33:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 3.3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DNOLEARN $(KFLAGS) -O" \
	"LNKFLAGS = -s"

#Silicon Graphics Iris Indigo with IRIX 4.0.0 or 5.0...
#Strict ANSI C compilation, TCP/IP support included
irix40:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 4.0...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DIRIX40 -DSVR3 -DDIRENT -DHDBUUCP -DPWID_T=uid_t \
	-DCK_ANSIC -DTCPSOCKET $(KFLAGS) -O -Olimit 1600 -I/usr/include/bsd" \
	"LNKFLAGS = -s"

#As above, but with fullscreen display (curses) and Sun Yellow Pages support.
#NOTE: IRIX versions prior to 5 run COFF binaries.
irix40ypc:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 4.0.'
	@echo 'Includes fullscreen file display and Sun Yellow Pages...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DIRIX40 -DSVR3 -DDIRENT -DHDBUUCP -DCK_CURSES \
	-DPWID_T=uid_t -DCK_ANSIC -DTCPSOCKET $(KFLAGS) \
	-O -Olimit 1600 -I/usr/include/bsd" \
	"LIBS = -lcurses -lsun" "LNKFLAGS = -s"

# Silicon Graphics Iris Series 4D/*, IRIX 4.0.x, -O4 ucode optimized.
# Huge temporary file space needed for ucode optimizer.  If you get an error
# like "ugen: internal error writing to /tmp/ctmca08777: Error 0", define the
# the TMPDIR environment variable to point to a file system that has more
# space available, e.g. "setenv TMPDIR /usr/tmp".
irix40u:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 4.0...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DIRIX40 -DSVR3 -DDIRENT -DHDBUUCP -DPWID_T=uid_t \
	-DCK_ANSIC -DTCPSOCKET $(KFLAGS) -O4 -Olimit 1600" \
	"LNKFLAGS=-O4 -Olimit 1600 -s" "EXT=u"

# As above, with Curses Support added
irix40uc:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 4.0...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DIRIX40 -DSVR3 -DDIRENT -DHDBUUCP -DPWID_T=uid_t \
	-DCK_ANSIC -DCK_CURSES -DTCPSOCKET $(KFLAGS) -O4 -Olimit 1600" \
	"LNKFLAGS=-O4 -Olimit 1600 -s" "EXT=u" "LIBS= -lcurses -ltermcap"

#Silicon Graphics IRIX 5.x.
#Yellow Pages and Curses support included.
#IRIX version 5.x can run COFF or ELF binaries.
irix51:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 5.x'
	@echo 'Includes fullscreen file display and Yellow Pages...'
	@echo 'Add -mips<n> to CFLAGS specify a particular hardware target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DIRIX51 -DSVR4 -DDIRENT -DHDBUUCP -DCK_CURSES -DCK_NEWTERM \
	-DPWID_T=uid_t -DCK_ANSIC -DTCPSOCKET -DSELECT -DNOGETUSERSHELL \
	-DSYSTIMEH -DDCLPOPEN -DDCLFDOPEN $(KFLAGS) -ansi -O -Olimit 3000" \
	"LIBS = -lcurses" "LNKFLAGS = -s"

#Use this one if irix51 blows up due to lack of swap space or whatever.
irix51x:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 5.x'
	@echo 'Includes fullscreen file display and Yellow Pages...'
	@echo 'Add -mips<n> to CFLAGS specify a particular hardware target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DIRIX51 -DSVR4 -DDIRENT -DHDBUUCP -DCK_CURSES -DCK_NEWTERM \
	-DPWID_T=uid_t -DCK_ANSIC -DTCPSOCKET -DSELECT -DNOGETUSERSHELL \
	-DSYSTIMEH -DDCLPOPEN -DDCLFDOPEN $(KFLAGS)" \
	"LIBS = -lcurses" "LNKFLAGS = -s"

irix51ypc:
	$(MAKE) "MAKE=$(MAKE)" irix51 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS= $(KFLAGS)"

#IRIX 5.2 adds RTS/CTS
irix52:
	$(MAKE) "MAKE=$(MAKE)" irix51 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DIRIX52 -DCK_RTSCTS $(KFLAGS)"

irix53:
	$(MAKE) "MAKE=$(MAKE)" irix51 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DIRIX52 -DIRIX53 -DCK_RTSCTS $(KFLAGS)"

irix53x:
	$(MAKE) "MAKE=$(MAKE)" irix51x KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DIRIX52 -DIRIX53 -DCK_RTSCTS $(KFLAGS)"

#Silicon Graphics IRIX 6.[024] common stuff.
#Yellow Pages and Curses support included.
#IRIX version 6.0 and later runs only ELF binaries.
#Depends on code changes in ckcdeb.h that make -DIRIX6x define all
#lower IRIX6x values and IRIX51.
irix6x:
	@echo 'Includes fullscreen file display and Yellow Pages...'
	@echo 'Add -mips<n> to specify a particular hardware target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR4 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DCK_CURSES -DCK_NEWTERM -DPWID_T=uid_t -DCK_ANSIC -DTCPSOCKET \
	-DSELECT -DCK_RTSCTS -O $(KFLAGS)" \
	"LIBS = -lcurses" "LNKFLAGS = -s $(LNKFLAGS)"

#Silicon Graphics IRIX 6.0.
irix60:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 6.0'
	@$(MAKE) "MAKE=$(MAKE)" \
	"KFLAGS=-DIRIX60 -Olimit 2138 $(KFLAGS)" \
	irix6x KTARGET=$${KTARGET:-$(@)}

#Silicon Graphics IRIX 6.2.
#Serial speeds > 38400 are available in IRIX 6.2 on O-class machines only.
#Note: Olimit must be a number > 0.
irix62:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 6.2'
	@$(MAKE) "MAKE=$(MAKE)" \
	LNKFLAGS="-Wl,-woff,84" \
	"KFLAGS=-DIRIX62 -Olimit 4700 $(KFLAGS)" \
	irix6x KTARGET=$${KTARGET:-$(@)}

#Silicon Graphics IRIX 6.3.
irix63:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 6.3'
	@$(MAKE) "MAKE=$(MAKE)" irix62 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DIRIX63"

#Silicon Graphics IRIX 6.4.
# -woff,84 to linker stops complaints about no symbols loaded from
# curses, and -woff 1110 stops complaints about unreachable "break;"
# statements in ckcpro.c among others.
# tested on SGI Octane, running IRIX 6.4 up to 115200 bps.
# -Olimit 0 means infinite.
irix64:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 6.4'
	@$(MAKE) "MAKE=$(MAKE)" \
	LNKFLAGS="-Wl,-woff,84" \
	"KFLAGS=-DIRIX64 -DCK_RTSCTS -Olimit 3000 -woff 1110 $(KFLAGS)" \
	irix6x KTARGET=$${KTARGET:-$(@)}

irix64gcc:
	@echo 'Making C-Kermit $(CKVER) for Silicon Graphics IRIX 6.4 gcc'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS= -DSVR4 -DIRIX64 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DSELECT -DPWID_T=uid_t -DTCPSOCKET -DNOCOTFMC \
	-DCK_ANSIC -DCK_RTSCTS -DCK_NEWTERM -DCK_CURSES \
	$(KFLAGS) -O" "LIBS= -lcurses -ltermcap -lcrypt"

#Note the new Optimization option syntax for MIPSpro CC 7.2.1.2m.
#See note on irix65gcc target about Large File Support (LFS).
irix65:
	@echo 'Making C-Kermit $(CKVER) for SGI IRIX 6.5'
	@$(MAKE) "MAKE=$(MAKE)" LNKFLAGS="-Wl,-woff,84" \
	"KFLAGS=-DIRIX65 -D_LARGEFILE_SOURCE -DCK_RTSCTS -OPT:Olimit=0 \
	-woff 1110,1552,1174 $(KFLAGS)" \
	irix6x KTARGET=$${KTARGET:-$(@)}

#Build for those that have GCC instead of MIPSpro.
#
# Large File Support note: use the define _LARGEFILE_SOURCE to enable support
# for files larger than 2GB.  This may work on releases of Irix prior to
# 6.5.xx.  To verify, check the man page for fstat and verify that off_t is a
# 64 bit value for an -n32 build.  Also check the manpage for fseek and ftell
# to verify that the fseek64 and ftell64 functions are provided.  If so, then
# LFS support should work and you can try adding -D_LARGEFILE_SOURCE to CFLAGS
# for your selected Irix target.
#
irix65gcc:
	@echo 'Making C-Kermit $(CKVER) for SGI IRIX 6.5 with gcc'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CC = gcc" "CC2 = gcc" \
	"CFLAGS= -DSVR4 -DIRIX65 -D_LARGEFILE_SOURCE -DDIRENT -DHDBUUCP \
	-DNOGETUSERSHELL -DSELECT -DPWID_T=uid_t -DTCPSOCKET -DNOCOTFMC \
	-DCK_ANSIC -DCK_RTSCTS -DCK_NEWTERM -DCK_CURSES \
	$(KFLAGS) -O" "LIBS= -lcurses"

# The 64-bit IRIX target works but presumably is no longer needed given the
# large file support in the more portable and compact 32-bit version.
irix65_64:
	@echo 'Making C-Kermit $(CKVER) 64-bit for SGI IRIX 6.5'
	@$(MAKE) "MAKE=$(MAKE)" LNKFLAGS="-Wl,-woff,84" \
	"KFLAGS=-DIRIX65 -64 -DCK_RTSCTS -OPT:Olimit=0 -woff 1110,1552,1174 \
	-DCK_64BIT $(KFLAGS)" \
	irix6x KTARGET=$${KTARGET:-$(@)}

#Dumb down to MIPS-2 if building on R5000 or higher...
irix65mips2:
	@echo 'Making C-Kermit $(CKVER) for SGI IRIX 6.5 MIPS-2'
	@$(MAKE) "MAKE=$(MAKE)" LNKFLAGS="-o32 -mips2 -Wl,-woff,84" \
	"KFLAGS=-DIRIX65 -DCK_RTSCTS -OPT:Olimit=0 -o32 -mips2 \
	-woff 1110,1552,1174 $(KFLAGS)" \
	irix6x KTARGET=$${KTARGET:-$(@)}

#Special target that adds srp, ssl, and zlib support.  This requires
#that you have pkgsrc installed instead of Irix Freeware.  See
#NetBSD.org for pkgsrc for Irix.  You will need to BUILD the srp_client
#package yourself.  Install it manually using the directions found
#in the netbsds+ssl+srp+zlib target comments.
irix65+ssl+srp+zlib:
	@echo 'Making C-Kermit $(CKVER) for IRIX 6.5 with gcc and SSL SRP ZLIB'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CC = gcc" "CC2 = gcc" \
	"CFLAGS= -DIRIX65 -DSVR4 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL -DSELECT \
	-DTCPSOCKET -DNOCOTFMC -DCK_NEWTERM -DPWID_T=uid_t -DCK_ANSIC \
	-I/usr/pkg/include -DCK_AUTHENTICATION -DCK_SRP -DPRE_SRP_1_4_5 \
	-DCK_RTSCTS -DCK_NCURSES -DCK_ENCRYPTION -DCK_CAST -DCK_DES -DCK_SSL \
	-DLIBDES -DZLIB -DFNFLOAT -I/usr/pkg/include/openssl $(KFLAGS) -O" \
	"LIBS= -L/usr/pkg/lib -rpath /usr/pkg/lib -lncurses -lsrp -lgmp -ldes \
	-lssl -lkrypto -lcrypto -lcrypt -lz -lm"

irix6x+krb5:
	@echo 'Includes fullscreen file display and Yellow Pages...'
	@echo 'Add -mips<n> to specify a particular hardware target.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR4 -DDIRENT -DHDBUUCP -DNOGETUSERSHELL \
	-DCK_CURSES -DCK_NEWTERM -DPWID_T=uid_t -DCK_ANSIC -DTCPSOCKET\
	-DSELECT -DCK_RTSCTS -O \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 -DCK_ENCRYPTION -DCK_DES \
	$(K5INC) $(K5INC)/krb5 $(KFLAGS)" \
	"LIBS = -lcurses $(K5LIB) -ldes425 -lkrb5 \
	-lcom_err -lcrypto -lcrypt -lgssapi_krb5" \
	"LNKFLAGS = -s $(LNKFLAGS)"

irix65+krb5:
	@echo 'Making C-Kermit $(CKVER) for SGI IRIX 6.5'
	@$(MAKE) "MAKE=$(MAKE)" \
	LNKFLAGS="-Wl,-woff,84" \
	"KFLAGS=-DIRIX65 -DCK_RTSCTS -OPT:Olimit=0 -woff 1110,1552,1174 \
	$(KFLAGS)" \
	irix6x+krb5 KTARGET=$${KTARGET:-$(@)}

#In case they type "make sys5"...
sys5:
	$(MAKE) "MAKE=$(MAKE)" sys3 KTARGET=$${KTARGET:-$(@)}

#Generic ATT System III or System V (with I&D space)
sys3:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System III'
	@echo 'or System V R2 or earlier...'
	@echo 'add -DNOMKDIR if mkdir is an undefined symbol.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DNOUNICODE -DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL \
	-DNOINITGROUPS -DNOFTRUNCATE -DNOREALPATH -DNOLEARN $(KFLAGS) -i -O" \
	"LNKFLAGS = -i"

#Generic ATT System III or System V (no I&D space)
sys3nid:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System III'
	@echo 'or System V R2 or earlier, no I&D space...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DNOREALPATH -DNOUNICODE -DNOSYSLOG -DNOSYMLINK \
	-DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE -DNOLEARN $(KFLAGS) -O" \
	"LNKFLAGS ="

#Generic ATT System III or System V R2 or earlier, "no void":
#special entry to remove "Illegal pointer combination" warnings.
sys3nv:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System III'
	@echo 'or System V R2 or earlier...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DATTSV -DNOREALPATH -DNOUNICODE -DNOSYSLOG -DNOGETUSERSHELL \
	-DNOSYMLINK -DNOFTRUNCATE -DNOINITGROUPS -DNOLEARN \
	-Dvoid=int $(KFLAGS) -i -O" \
	"LNKFLAGS = -i"

# AT&T 7300 UNIX PC.  As of C-Kermit 6.1, many of these entries don't work
# any more due to "Out of memory" or "Too many defines" errors during
# compilation, at least not on systems without lots of memory.  The sys3upcgc
# entry works (using gcc) with optimization removed, and might also work
# with optimization enabled on machines with larger memories.

#AT&T 7300/UNIX PC (3B1) systems, sys3 but special handling for internal modem.
#Link with the shared library -- the conflict with openi in shared library
#is solved with -Dopeni=xopeni.  Note that the xermit target can't be used
#for the Unix PC; there is no select().
sys3upc:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC, shared lib...'
	@echo 'If shared lib causes trouble, use make sys3upcold.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DATT7300 -DNOMKDIR -DUSE_MEMCPY -DNOREALPATH -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOREDIRECT -DNOGFTIMER -DNOUNICODE $(KFLAGS) -Dopeni=xopeni" \
	"CC2 = ld /lib/crt0s.o /lib/shlib.ifile" "LNKFLAGS = -s"

#AT&T 7300/Unix PC systems, minimum kermit for those with smaller amounts
#of memory.
sys3upcm:
	@echo Minimum interactive
	$(MAKE) "MAKE=$(MAKE)" sys3upc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOSPL -DNOFRILLS -DNOHELP -DNODEBUG -DNOTLOG -DNOCSETS \
	-DNOSYSLOG -DNOSETKEY -DNOREALPATH"

#AT&T 7300/UNIX PC (3B1) systems, with curses support.
#Curses and the shared library don't get along, so we don't use the
#shared library.  We need to include CK_NEWTERM to avoid a conflict
#with curses and buffering on stdout.  Merged with submission by
#Robert Weiner/Programming Plus, [email protected].
#We don't need -Dopeni=xopeni since we're not using the shared library,
#but we keep it to be consistent with the other entries.
sys3upcc:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC, curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DATT7300 -DNOREALPATH \
	-DCK_CURSES -DCK_NEWTERM -DNOMKDIR -DNOREDIRECT -DNOGFTIMER -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DUSE_MEMCPY -DNOUNICODE $(KFLAGS) -Dopeni=xopeni" \
	"LIBS = -lcurses" "LNKFLAGS = -s"

#Like sys3upcc but for AT&T UNIX 3.51m (released as a patch on Fix Disk 2),
#adds hardware flow control.
att351m:
	$(MAKE) "MAKE=$(MAKE)" sys3upcc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DCK_RTSCTS -DUNIX351M"

#As above but with gcc.
att351gm:
	$(MAKE) "MAKE=$(MAKE)" sys3upcgc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DCK_RTSCTS -DUNIX351M"

#AT&T 7300 UNIX PC (3B1), as above, but no newterm().
sys3upcx:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC, curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DATT7300 -DNOREALPATH -DNOUNICODE -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DCK_CURSES -DNOMKDIR -DNOREDIRECT -DNOGFTIMER -DUSE_MEMCPY $(KFLAGS) \
	-Dopeni=xopeni" "LIBS = -lcurses -ltermcap" "LNKFLAGS = -s"

#AT&T 7300/UNIX PC (3B1) systems, with curses and shared library support.
sys3upcshcc:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC, shared lib...'
	@echo 'With curses.  Requires shcc.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DATT7300 -DNOMKDIR -DNOREALPATH -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DCK_NEWTERM -DCK_CURSES  -DNOREDIRECT -DNOGFTIMER \
	-DUSE_MEMCPY -DNOUNICODE $(KFLAGS) -Dopeni=xopeni" \
	"LNKFLAGS = -i -s" "CC = shcc" "CC2 = shcc" "LIBS = -lcurses"

#AT&T 7300/UNIX PC (3B1) systems, as above, no curses, but use gcc.
sys3upcg:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT7300 -DNOREDIRECT -DUSE_MEMCPY -DNOUNICODE -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOGFTIMER -DNOMKDIR -DNOREALPATH $(KFLAGS) -Dopeni=xopeni" \
	"CC = gcc" "CC2 = gcc" "LNKFLAGS = -s -shlib"

#AT&T 7300/UNIX PC (3B1) systems, curses and gcc.
#Optimization omitted -- add it back in if your machine has lots of memory.
sys3upcgc:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC, curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT7300 -DNOREDIRECT -DUSE_MEMCPY -DNOGFTIMER -DNOUNICODE \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DCK_CURSES -DCK_NEWTERM -DNOMKDIR -DNOREALPATH -DNOLEARN $(KFLAGS)" \
	"CC = gcc" "CC2 = gcc" "LIBS = -lcurses" "LNKFLAGS = -s"

#AT&T 7300/UNIX PC (3B1) systems, special handling for internal modem.
#No FULLSCREEN file transfer display (curses).
sys3upcold:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT7300 -DNOMKDIR -DUSE_MEMCPY -DNOUNICODE -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOGFTIMER -DNOREDIRECT -DNOREALPATH $(KFLAGS) -O" "LNKFLAGS = -i"

#As above, but with gcc. mininum features - fits on a 400K UNIX PC floppy
#after compression with room to spare; add -DNOSHOW or other -DNOxxxx items
#to reduce size even further.
sys3upcgm:
	@echo Minimum interactive
	$(MAKE) "MAKE=$(MAKE)" sys3upcg KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DNOSPL -DNOFRILLS -DNOHELP -DNODEBUG -DNOTLOG -DNOCSETS \
	-DNOSETKEY $(KFLAGS)"

#This target is designed to create a version with the most features possible
#that, after compression, still fits on a 400K UNIX PC floppy.
sys3upcgfd:
	@echo 'Making C-Kermit $(CKVER) for AT&T 7300 UNIX PC floppy...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT7300 -DNOREDIRECT -DUSE_MEMCPY -DNOSPL -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOGFTIMER -DNOREALPATH -Dopeni=xopeni \
	-DNOHELP -DNODEBUG -DNOTLOG -DNOCSETS -DNOSETKEY -DNOMKDIR $(KFLAGS)" \
	"CC = gcc" "CC2 = gcc" "LNKFLAGS = -s"

#AT&T 6300 PLUS (warning, -O might make it run out of space).
#NOTE: Remove -DHDBUUCP if not using Honey DanBer UUCP.
att6300:
	@echo 'Making C-Kermit $(CKVER) for AT&T 6300 PLUS...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT6300 -DHDBUUCP -DNOFILEH -DNOREALPATH -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOUNICODE $(KFLAGS) -O -Ml -i" "LNKFLAGS = -i -Ml"

#As above, but with curses support.  Debugging disabled to prevent thrashing.
att6300c:
	@echo 'Making C-Kermit $(CKVER) for AT&T 6300 PLUS...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT6300 -DHDBUUCP -DNOFILEH -DNOCSETS -DNOREALPATH \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DCK_CURSES -DNODEBUG -DNOUNICODE -DNOLEARN $(KFLAGS) -O -Ml -i" \
	"LNKFLAGS = -i -Ml" "LIBS = -lcurses"

#AT&T 6300 PLUS with no curses, no debugging (about 34K smaller)
# -Optimization saves about 20K too.
att6300nd:
	@echo 'Making C-Kermit $(CKVER) for AT&T 6300 PLUS, no debugging...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATT6300 -DHDBUUCP -DNODEBUG -DNOFILEH -DNOREALPATH \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOUNICODE -DNOLEARN $(KFLAGS) -O -i -Ml" "LNKFLAGS = -i -Ml"

#AT&T 3B2 and maybe 3B20-series computers running AT&T UNIX System V R3.
#This one was actually used to build C-Kermit 7.0 successfully on a 3B2/300.
att3b2:
	@echo 'Making C-Kermit $(CKVER) for AT&T 3B2'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DNOREDIRECT -DUSE_MEMCPY \
	-DNOTIMEVAL -DNOTIMEZONE -DMINIDIAL -DNOCHANNELIO -DNOBIGBUF \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOGFTIMER -DNOREALPATH -Dopeni=xopeni -DNOFRILLS -DNOLEARN \
	-DNOHELP -DNODEBUG -DNOTLOG -DNOCSETS -DNOSETKEY -DNOMKDIR $(KFLAGS)" \
	"CC = gcc" "CC2 = gcc" "LNKFLAGS = -s"

# The next two are likely not to work as-is.

#AT&T 3B2, 3B20-series computers running AT&T UNIX System V.
#This is just generic System V with Honey DanBer UUCP, so refer to sys3hdb.
#Remove -DNONAWS if you can get away with it.
att3bx:
	$(MAKE) "MAKE=$(MAKE)" sys3hdb KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DNONAWS -DNOTIMEVAL"

# 3Bx with charsets (except Unicode) but no curses.
att3bx1:
	@echo 'Making C-Kermit $(CKVER) for AT&T 3B2 or 3B20'
	@echo 'with Honey DanBer UUCP  no curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DHDBUUCP $(KFLAGS) -DNOREDIRECT \
	-DNOTIMEVAL -DNOTIMEZONE -DMINIDIAL -DNOCHANNELIO -DNOBIGBUF \
	-DNOHELP -DNODEBUG -DNOGFTIMER -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOREALPATH -DNOUNICODE -i" \
	"CC = gcc" "CC2 = gcc" "LNKFLAGS = -i -s"

#AT&T 3B2, 3B20-series computers running AT&T UNIX System V,
#with fullscreen file transfer display.
att3bxc:
	@echo 'Making C-Kermit $(CKVER) for AT&T 3B2 or 3B20'
	@echo 'with Honey DanBer UUCP and curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DHDBUUCP -DNONAWS -DNOTIMEVAL $(KFLAGS) \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOREALPATH -DCK_CURSES -DCK_NEWTERM -DNOUNICODE -DNOLEARN -i -O" \
	"LNKFLAGS = -i" "LIBS=-lcurses"

#3bx with curses but no charsets
att3bxc3:
	@echo 'Making C-Kermit $(CKVER) for AT&T 3B2 or 3B20'
	@echo 'with Honey DanBer UUCP with curses...  no CSETS'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DHDBUUCP $(KFLAGS) -DNOREDIRECT \
	-DNOTIMEVAL -DNOTIMEZONE -DMINIDIAL -DNOCHANNELIO -DNOBIGBUF \
	-DNOHELP -DNODEBUG -DNOGFTIMER -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOREALPATH -DNOCSETS -DCK_CURSES -DCK_NEWTERM -i" \
	"CC = gcc" "CC2 = gcc" "LNKFLAGS = -i -s" "LIBS = -lcurses"

#Any System V R2 or earlier with Honey DanBer UUCP (same as above)
sys3hdb:
	@echo 'Making C-Kermit $(CKVER) for AT&T UNIX System III'
	@echo 'or System V R2 or earlier with Honey DanBer UUCP...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DHDBUUCP -DNOREALPATH -DNOUNICODE -DNOLEARN \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	$(KFLAGS) -i -O" "LNKFLAGS = -i"

#Sperry/UNISYS 5000 UTS V 5.2 (System V R2), Honey DanBer UUCP
unisys5r2:
	@echo 'Making C-Kermit $(CKVER) for Sperry/UNISYS 5000 UTS V 5.2...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DUNISYS52 -DHDBUUCP -DNOREALPATH -DNOUNICODE \
	-DNOSYSLOG -DNOSYMLINK -DNOGETUSERSHELL -DNOINITGROUPS -DNOFTRUNCATE \
	-DNOLEARN $(KFLAGS) -i -O" "LNKFLAGS = -i"

#In case they say "make sys5hdb" instead of "make sys3hdb"...
sys5hdb:
	$(MAKE) "MAKE=$(MAKE)" sys3hdb

#Create the common header line for all hpux[5-11]* entries and above. This 
#extra entry is here because our header message length may differ for each 
#C-Kermit version. Don't use 'fold -s' for HP-UX 5.x - 7.x! This option is 
#available only for HP-UX 8.0 and above!
hpux-header:
	@HPUX=`uname -r | sed -e 's/^[^1-9]*//' -e 's/\.00$$/.0/'` ; \
	[ "$(MESSAGE0)" ] && MESSAGE1="$(MESSAGE0)" ; \
	Message0='Making C-Kermit $(CKVER) for HP9000 HP-UX' ; \
	Message1=$${MESSAGE1:='without any extra compiler optimization'} ; \
	MessageH="$$Message0 $$HPUX" ; \
	case $$HPUX in \
	  [567].*) echo "$$MessageH\n$$Message1" ;; \
	      *.*) echo "$$MessageH $${Message1}$(MESSAGE1A)" | fold -s ;; \
	esac | sed -e 's/^ //' -e 's/ *$$//'

# Peter E's updated HP-UX 5.xx entries Oct 2001.

#HP-9000 500 HP-UX 5.xx, no TCP/IP.
# Last known successful build: C-Kermit 8.0.206 2002/20/27.
hpux0500:
	@MESSAGE0="no TCP/IP and no compiler optimization";\
	MESSAGE0=$${MESSAGE1:-$$MESSAGE0} \
	$(MAKE) hpux-header
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DHPUX -DHPUX5 -DHPUXPRE65 -DNOREDIRECT -DDCLGETCWD \
	-DNOGETUSERSHELL -DNOGFTIMER -DNOSYSLOG -DNOTOMACROS -DNOLSTAT \
	-DNOSYMLINK -DNOINITGROUPS -DNOUNICODE -DNOLEARN -DNOLONGLONG \
	-DVOID=int -DCKVOID=int $(KFLAGS)" "LIBS = $(LIBS)" "LNKFLAGS = "

#HP-9000 500 HP-UX 5.21 with Wollongong WIN/TCP 1.2 TCP/IP.
#Requires /usr/wins/usr/include and /usr/lib/libnet.a from Wollongong.
#Optimization skipped - takes forever.	Really.
# WARNING: this doesn't work if a file called "hpux0500" is on the disk.
# Last known successful build: C-Kermit 8.0.206 2002/20/27.
hpux0500wintcp:
	@MESSAGE1="with WIN/TCP but without any extra compiler optimization" \
	$(MAKE) hpux0500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = -DTCPSOCKET -DHPUX5WINTCP -DINADDRX -DNO_DNS_SRV \
	-DNOMHHOST -DVOID=int -DCKVOID=int -DNOHADDRLIST -DNOLONGLONG \
	-I/usr/wins/usr/include $(KFLAGS)" "LIBS = /usr/lib/libnet.a"

#HP-UX 6.5, short filenames, no network and no curses support.
#ckcpro, ckuusr, ckuus3 and others are broken out because they make the
#optimizer run away.  Note that the XERMIT target does not work with HP-UX 6.5!
#
#If you get compiler warnings like:
#'Switch table overflow. Try the -Wc,-Nw option.' (for ckcuni.c, or
#other files) increase the '...' value in '-Wc,-Nw...'! The default maximum
#switch table stack (-Nw) is 250 table entries. ckcuni.c from Oct 16 2009
#needs 257 table entries (C-Kermit Version "9.0.299").
#OK: 2010/03/26
hpux0650:
	@$(MAKE) hpux-header
	@MESSAGE2=$${MESSAGE2:-'and NO network'}; \
	echo "supporting: NO long filenames $$MESSAGE2."

	$(MAKE) KTARGET=$${KTARGET:-$(@)} \
		ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) ckuus6.$(EXT) \
		ckuusr.$(EXT) ckuxla.$(EXT) ckcftp.$(EXT) ckcpro.$(EXT) \
	"CFLAGS = -DHPUX -DHPUX6 -DSIG_V -DNOSYSLOG -DNOSELECT -DFNFLOAT \
	-DDCLGETCWD -DNOGETUSERSHELL -DNO_DNS_SRV -DNOLEARN -DNOLONGLONG \
	$(KFLAGS)"

	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DHPUX -DHPUX6 -DSIG_V -DNOSYSLOG -DNOSELECT -DFNFLOAT \
	-DDCLGETCWD -DNOGETUSERSHELL -DNO_DNS_SRV -DNOLEARN -DNOLONGLONG \
	$(KFLAGS) -Wc,-Nw260 $(OFLAGS)" "LNKFLAGS = -s" "LIBS = -lm $(LIBS)"

#Exactly as above, plus curses:
#OK: 2009/10/06
hpux0650c:
	@MESSAGE2="and NO network but with curses" \
	$(MAKE) hpux0650 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = -DCK_CURSES $(KFLAGS)" \
	"LIBS = -lcurses"

#Exactly as above, plus curses + network:
#OK: 2009/10/02
hpux0650tcpc:
	@MESSAGE2="but with curses and with TCP/IP" \
	$(MAKE) hpux0650 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DCK_CURSES -DTCPSOCKET -DNOHADDRLIST \
	-DINTSELECT -DNOCKGETFQHOST $(KFLAGS)" \
	"LIBS=-lcurses"

#Exactly as hpux0650 but with compiler optimization:
#OK: 2009/10/06
hpux0650o:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0650 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#Exactly as hpux0650c but with compiler optimization:
#OK: 2009/10/06
hpux0650oc:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0650c KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#Exactly as hpux0650tcpc but with compiler optimization:
#OK: 2009/10/06
hpux0650otcpc:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0650tcpc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#Take this as startup entry for all 'non-optimized' files under HP-UX 7.x!
#Make sure we don't call it with the '-O' option because this will blow up
#the compiler!
#OK: 2009/09/30
hpux0700noopt:
	@case "$(CFLAGS)" in \
	*-O*) echo "Don't use CFLAGS= -O here!" ;; \
	   *) $(MAKE) KTARGET=$${KTARGET:-$(@)} \
	      ckuusr.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) ckuus5.$(EXT) \
	      ckuus6.$(EXT) ckuus7.$(EXT) ckuxla.$(EXT) \
	      ckcuni.$(EXT) ckcftp.$(EXT) ckcpro.$(EXT) \
	      ;; \
	esac

#HP-UX 7.0, no long filenames, no network support, no curses.
#If you get compiler warnings like:
#'Switch table overflow. Try the -Wc,-Nw option.' (for ckcuni.c, or
#other files) increase the '...' value in '-Wc,-Nw...'! The default maximum
#switch table stack (-Nw) is 250 table entries. ckcuni.c from Oct 16 2009
#needs 257 table entries (C-Kermit Version "9.0.299").
#OK: 2010/10/26
hpux0700sf:
	@$(MAKE) hpux-header
	@echo 'supporting: NO long filenames, NO network, NO curses.'
	$(MAKE) hpux0700noopt KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DHPUX -DHPUX7 -DSIG_V -DNOGETUSERSHELL -DFNFLOAT \
	-DNO_DNS_SRV $(KFLAGS) -Wc,-Nw260"

	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DHPUX -DHPUX7 -DSIG_V -DNOGETUSERSHELL -DFNFLOAT \
	-DNO_DNS_SRV $(KFLAGS) -Wc,-Nw260 $(OFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lm $(LIBS)"

#Exactly as hpux0700sf but with compiler optimization:
#OK: 2009/09/30
hpux0700osf:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0700sf KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#HP-UX 7.0, short filenames, but with tcp/ip and curses.
#To use this, you must have bought the ARPA Services Product from HP, and you
#must have /usr/lib/libBSD.a.
#
#If you get compiler warnings like:
#'Symbol table overflow. Try the -Wc,-Ns option.' (as for ckuus4.c or
#other files) increase the '...' value in '-Wc,-Ns...'! The default maximum
#symbol table size (-Ns) is 2000 table entries. ckuus4.c from Mar 12 2010
#needs 2031 table entries (C-Kermit Version "9.0.299").
#OK: 2010/03/24
hpux0700sftcpc:
	@$(MAKE) hpux-header
	@echo 'supporting: NO long filenames, \c'
	@echo 'but with networking, curses, HDB uucp...'
	$(MAKE) hpux0700noopt KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS =  -DHPUXDEBUG -DHPUX -DHPUX7 -DTCPSOCKET -DSIG_V \
	-DCK_REDIR -DCK_RTSCTS -DCK_CURSES -DNOGETUSERSHELL -DFNFLOAT \
	-DNO_DNS_SRV -DHDBUUCP -DLOCK_DIR=\\\"/usr/spool/uucp\\\" \
	-DNOLONGLONG $(KFLAGS) -Wc,-Nw260,-Ns2040"

	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS =  -DHPUXDEBUG -DHPUX -DHPUX7 -DTCPSOCKET -DSIG_V \
	-DCK_REDIR -DCK_RTSCTS -DCK_CURSES -DNOGETUSERSHELL -DFNFLOAT \
	-DNO_DNS_SRV -DHDBUUCP -DLOCK_DIR=\\\"/usr/spool/uucp\\\" \
	-DNOLONGLONG $(KFLAGS) -Wc,-Nw260,-Ns2040 $(OFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lm -lBSD -lcurses"

#Exactly as above but with compiler optimization:
#OK: 2009/09/30
hpux0700osftcpc:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0700sftcpc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#HP 9000 series 300/800 HP-UX 7.0, long filenames, network support, HDB uucp,
#but NO curses. See comments in hpux0700sftcpc about TCP/IP support.
#
#If you get compiler warnings like:
#'Symbol table overflow. Try the -Wc,-Ns option.' (as for ckuus4.c or
#other files) increase the '...' value in '-Wc,-Ns...'! The default maximum
#symbol table size (-Ns) is 2000 table entries. ckuus4.c from Mar 12 2010
#needs 2031 table entries (C-Kermit Version "9.0.299").
#OK: 2010/03/24
hpux0700lfn:
	@$(MAKE) hpux-header
	@echo 'supporting: long filenames, networking, HDB uucp$(MESSAGE2)...'
	$(MAKE) hpux0700noopt KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS =  -DHPUXDEBUG -DHPUX -DHPUX7 -DTCPSOCKET -DSIG_V -DFNFLOAT \
	-DNOGETUSERSHELL -DNOSETBUF -DCK_REDIR -DCK_RTSCTS -DLONGFN \
	-DNO_DNS_SRV -DDIRENT -DHDBUUCP -DLOCK_DIR=\\\"/usr/spool/uucp\\\" \
	-DNOLONGLONG $(KFLAGS) -Wc,-Nw260,-Ns2040"

	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS =  -DHPUXDEBUG -DHPUX -DHPUX7 -DTCPSOCKET -DSIG_V -DFNFLOAT \
	-DNOGETUSERSHELL -DNOSETBUF -DCK_REDIR -DCK_RTSCTS -DLONGFN \
	-DNO_DNS_SRV -DDIRENT -DHDBUUCP -DLOCK_DIR=\\\"/usr/spool/uucp\\\" \
	-DNOLONGLONG $(KFLAGS) -Wc,-Nw260,-Ns2040 $(OFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lm -lBSD $(LIBS)"

#Exactly as above + curses.
#OK: 2009/09/30
hpux0700lfnc:
	@MESSAGE2=', curses' \
	$(MAKE) hpux0700lfn KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = -DCK_CURSES $(KFLAGS)" \
	"LIBS = -lcurses"

#Exactly as above hpux0700lfn but with compiler optimization:
#OK: 2009/09/30
hpux0700olfn:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0700lfn KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#Exactly as above hpux0700lfnc but with compiler optimization:
#OK: 2009/09/30
hpux0700olfnc:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0700lfnc KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#HP 9000 Series 300 or 400, HP-UX 8.0, long filenames and TCP/IP support.
#This one should also work on 700/800, but without PA-specific optimization.
#In case -DCK_RTSCTS and -DCK_REDIR make trouble, remove them.
#NOTE: ckcpro.c, ckuusr.c and ckuus3.c blow up the optimizer, so don't optimize
#them.
#For HP-UX 8.0 on Motorola CPUs, you might have to reinstall your kernel with
#maxdsiz >= 0x03000000.  But if physical memory is small, that still will not
#help much.
#OK: 2009/10/01
hpux0800:
	@$(MAKE) hpux-header
	@MESSAGE3=$${MESSAGE3:='TCP/IP'}; \
	echo "supporting: long filenames, $$MESSAGE3, HDB UUCP$(MESSAGE2)..."
	$(MAKE) -B "CC=$(CC)" "CC2=$(CC2)" KTARGET=$${KTARGET:-$(@)} \
	ckcpro.$(EXT) ckuusr.$(EXT) ckuus3.$(EXT) \
	"CFLAGS =  -DCK_REDIR -DHPUXDEBUG -DHPUX -DHPUX8 -DRENAME -DSIG_V \
	-DNOSETBUF -DDIRENT -DCK_RTSCTS -DSTERMIOX -DLONGFN -DTCPSOCKET \
	-DHDBUUCP  -DNO_DNS_SRV -DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DFNFLOAT \
	-DNOLONGLONG $(KFLAGS)"

	$(MAKE) -B "CC=$(CC)" "CC2=$(CC2)" xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS =  -DCK_REDIR -DHPUXDEBUG -DHPUX -DHPUX8 -DRENAME -DSIG_V \
	-DNOSETBUF -DDIRENT -DCK_RTSCTS -DSTERMIOX -DLONGFN -DTCPSOCKET \
	-DHDBUUCP  -DNO_DNS_SRV -DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DFNFLOAT \
	-DNOLONGLONG -DNODCLENDUSERSHELL $(KFLAGS) $(OFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lm -lBSD $(LIBS)"

#Exactly as above hpux0800 + curses.
#OK: 2009/10/01
hpux0800c:
	@MESSAGE2=', curses' \
	$(MAKE) hpux0800  KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) -DCK_CURSES" "LIBS = -lcurses"

#HP 9000 HP-UX 8.0, no TCP/IP because /usr/lib/libBSD.a can't be found,
#or TCP/IP header files missing.
#OK: 2009/10/01
hpux0800notcp:
	@MESSAGE3='NO network, NO curses' \
	$(MAKE) "MAKE=$(MAKE)" hpux0800 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) -UTCPSOCKET"

#Now the same as above hpux0800 but with compiler optimization
#OK: 2009/10/01
hpux0800o:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0800 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#Exactly as above hpux0800 + curses and with compiler optimization.
#OK: 2009/10/01
hpux0800oc:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) hpux0800c KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O" "LIBS = -lcurses"

#Exactly as above hpux0800notcp but with compiler optimization
#OK: 2009/10/01
hpux0800onotcp:
	@MESSAGE1="with compiler optimization" \
	$(MAKE) "MAKE=$(MAKE)" hpux0800notcp KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -O"

#HP 9000 Series 700 or 800, HP-UX 8.0, long filenames and TCP/IP support.
# Like the previous entries, but with PA-RISC-specific optimization.
#OK: 2009/10/01
hpux0800pa:
	@MESSAGE1="with PA-RISC-specific optimization" \
	$(MAKE) hpux0800 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) +Obb1100"

#As above, but with curses.
#OK: 2009/10/01
hpux0800pac:
	@MESSAGE1="with PA-RISC-specific optimization" \
	$(MAKE) hpux0800c KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) +Obb1100"

#As above, but compiled with GCC 2.3.3.
#OK: 2009/10/01
hpux0800pagcc:
	@MESSAGE1='using the gcc compiler' \
	$(MAKE) hpux0800 KTARGET=$${KTARGET:-$(@)} \
	"CC=gcc" "CC2=gcc" "KFLAGS = -funsigned-char $(KFLAGS)"

#HP-UX 9.0, 9.01, 9.03, 9.04, 9.05, 9.07, 9.10 ..., + TCP/IP + curses, fully
#configured.  Use this entry with the restricted compiler: no optimization, no
#ANSI support.  If you get unresolved sockets library references at link time,
#then try adding -lBSD to LIBS, or else remove -DTCPSOCKET to build a version
#without TCP/IP support.
#
#Please note that we have to add the compiler option +DA1.0/+DA1.1 to avoid
#core-dumps for large arguments in IF MATCH. The man page says these options
#are default but C-Kermit dumps core without them! Therefore keep them
#untouched. If you want to overwrite or disable the +DA1.0/+DA1.1 option use
#'make hpux0900 OFLAGS=...'. An other possibility would be to create a new
#kernel with maxssiz >= 0x01185000 (default maxssiz=0x00800000).
#OK: 2009/09/24
hpux0900:
	@MESSAGE1A='. Read hpux0900 entry comments if you have trouble.' \
	$(MAKE) hpux-header
	@case `uname -m` in \
	  */[34]*) KFLAGS='-DNOLONGLONG $(KFLAGS)' ;; \
	  */7*)    AFLAGS='+DA1.1' ;; \
	  */8*)    AFLAGS='+DA1.0' ;; \
	esac ; \
	OFLAGS=$${OFLAGS:-$$AFLAGS} ; \
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DHPUXDEBUG -DHPUX9 -DSTERMIOX -DDIRENT -DUTIMEH \
	-DNOSETBUF -DCK_CURSES -DTCPSOCKET -DRENAME -DCK_REDIR -DLONGFN \
	-DHDBUUCP -DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DFNFLOAT \
	-DNODCLENDUSERSHELL $$KFLAGS $$OFLAGS" \
	"LNKFLAGS = -s" "LIBS = -lm -lcurses" "CC=$(CC)" "CC2=$(CC2)"

#Like hpux0900, but for the "value-added" compiler on all HP 9000 models.
#Adds optimization and ANSI compilation:
# +O2 makes smaller executable (= -O = Level-1 and global optimization)
# +O3 adds interprocedural global optimization, makes bigger executable.
# Please note: To support long-long we would need compiler switch '-Ae' but
# this one works only on Risc systems. But the equivalant compiler flags
# '-Aa -D_HPUX_SOURCE +e' works for Motorola and Risc.
# If optimization fails on some modules, you can add:
#  +Obb<n>, +Olimit <n>, or +Onolimit, depending on your cc version,
# where <n> is a number, e.g. +Obb1200.  In other words, if you get optimizer
# warnings, add (for example) +Obb1200; if you still get optimizer warnings,
# increase the number.  Repeat until warnings go away.  If your compiler
# permits it, use +Onolimit. If optimizer blows up on ckcpro.c, see next entry.
# Reportedly, on some configurations, such as HP9000/425e or /340, perhaps
# depending on the amount of main memory, this entry might fail no matter what
# you do ("Out of Memory", "cc: Fatal error in /lib/c.c1", etc).  In that case
# use "make hpux0900" (no "o").
#OK: 2009/09/24
hpux0900o:
	@MESSAGE1=$${MESSAGE1:-"with compiler optimization"} \
	$(MAKE) hpux0900 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) -Aa -DCK_ANSIC -D_HPUX_SOURCE +O2 +e"

# For HP-UX 9.0 on Motorola CPUs, optimization of ckcpro.c tends to blow up
# the compiler.  You might have to reinstall your kernel with maxdsiz >=
# 0x03000000.  But if physical memory is small, that still will not help much.
# In that case, use this entry to skip optimization of ckcpro.c.  But for
# C-Kermit 8.0.208 you need a kernel with maxdsiz >= 0x02000000 to compile an
# optimized ckcftp.c.
# Please note: To support long-long we would need compiler switch '-Ae' but
# this one works only on Risc systems. But the equivalant compiler flags
# '-Aa -D_HPUX_SOURCE +e' works for Motorola and Risc.
hpux0900m68ko:
	@MESSAGE1='without compiler optimization for ckcpro.$(EXT) ...' \
	$(MAKE) hpux-header
	$(MAKE) ckuusr.$(EXT) ckuus3.$(EXT) ckuus4.$(EXT) \
	ckcftp.$(EXT) ckcpro.$(EXT) \
	"CFLAGS = -DHPUXDEBUG -DHPUX9 -DSTERMIOX -DDIRENT \
	-DNOSETBUF -DCK_CURSES -DTCPSOCKET -DRENAME  -DCK_REDIR -DLONGFN \
	-DHDBUUCP -DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DFNFLOAT $(KFLAGS)"
	@echo
	@MESSAGE1="with compiler optimization for the rest" \
	$(MAKE) hpux0900 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) -Aa -DCK_ANSIC -D_HPUX_SOURCE +O2 +e"

# Old name for hpux0900m68ko.
hpux0900mot:
	$(MAKE) hpux0900m68ko KTARGET=$${KTARGET:-$(@)} "KFLAGS = $(KFLAGS)"

#Like hpux0900o but with additional model-700/800-specific optimizations.
# +ESlit = consolidate strings in read-only memory.
# +ESfsc = inline millicode calls when comparing pointers.
hpux0900o700:
	@echo 'If you get optimizer warnings \c'
	@echo 'try "make hpux0900o700 KFLAGS=+Obb1200"'
	@MESSAGE1="with PA-RISC-specific optimizations" \
	$(MAKE) hpux0900o KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) +ESlit +ESsfc"

#HP-UX 9.0, 9.01, 9.03, 9.04, 9.05, 9.07, 9.10 ..., + TCP/IP + curses, fully
#configured, built with gcc, all models except 800 series.
#You might need to add the include path for gcc headers, for example:
# 'KFLAGS=-I/usr/gnu/lib/gcc-lib/hppa1.1-hp-hpux/2.4.5/include/'
hpux0900gcc:
	@MESSAGE1='using the gcc compiler' \
	$(MAKE) hpux0900 KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"KFLAGS = -DCK_ANSIC $(KFLAGS)" \
	"OFLAGS = -funsigned-char -O2 $(OFLAGS)"

#HP-9000 HP-UX 10.0 + TCP/IP + curses, fully configured.
#Use with restricted (bundled) compiler: no optimization, no ANSI support.
#libcurses needed for fullscreen file xfer display in HP-UX 10.00 and 10.01.
#libHcurses (NOT libcurses!) for fullscreen display, to work around fatal bugs
#in HP-UX 10.10 and 10.20 curses. Maybe we could use lcurses for 10.30, since
#the 10.10 curses problem is supposedly fixed in 10.30.
# +DA1.0 = Generate PA-RISC 1.0 code that runs on both 700 and 800 models.
# +DA1.1 = Generate PA-RISC 1.1 code that runs on both 700 and 800 models.
# Note that HP-UX 10.20 and upwards do not support PA-RISC 1.0 systems.
# And that as of Dec 2001, 11.00 and 11.11 are PA-only and 11.20 is IA64-only.
# Later 11.2x releases are expected to be for both.  Architecture can be
# determined with the model command, at least in 10.20 and later...
#For future releases, we need to include +DA1.1 for PA builds, so that a
#binary built on PA 2.0 will still work on PA 1.1 machines, whereas +DA1.1
#must NOT be included for IA64 builds.
#4 Jan 2006 - Added Large File Support (LFS).  Large files (>2GB) are
#possible in HP-UX 10.20 and later.  The only change is to add:
# -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
#to KFLAGS.  These should be harmless in 10.00 and 10.10, if any of examples
#of those still exist, but I have no way to test this hypothesis.
#OK: 2009/11/16
hpux1000:
	@$(MAKE) hpux-header
	@LIBS='-lHcurses' ; \
	AFLAGS='+DA1.1' ; \
	case `uname -r` in \
	   [AB].10.0*)  KFLAGS='-DHPUX1000 $(KFLAGS)' ; \
	                AFLAGS='+DA1.0' ; LIBS='-lcurses'  ;; \
	   [AB].10.1*)  KFLAGS='-DHPUX1010 -D__HP_CURSES $(KFLAGS)' ; \
	                ;; \
	   [AB].10.2*)  KFLAGS='-DHPUX1020 -D__HP_CURSES $(KFLAGS)' ; \
	                ;; \
	   [AB].10.3*)  KFLAGS='-DHPUX1030 -D__HP_CURSES $(KFLAGS)' ; \
	                ;; \
	   [AB].10.?*)  KFLAGS='-DHPUX10XX -D__HP_CURSES $(KFLAGS)' ; \
	                ;; \
	   [AB].11.0*)  KFLAGS='-DHPUX1100 -D__HP_CURSES $(KFLAGS)' ; \
	                ;; \
	   [AB].11.1*)  KFLAGS='-DHPUX1100 -D__HP_CURSES $(KFLAGS)' ; \
	                ;; \
	   [AB].11.?*)  KFLAGS='-DHPUX1100 -D__HP_CURSES $(KFLAGS)' ; \
	                AFLAGS='' ; LIBS='-lcurses' ;; \
	esac ; \
	OFLAGS=$${OFLAGS:-$$AFLAGS} ; \
	$(MAKE) "SHELL=/usr/bin/sh" xermit KTARGET=$${KTARGET:-$(@)} \
	"CC=$(CC)" "CC2=$(CC2)" \
	"CFLAGS = -DHPUX10 -DDIRENT -DSTERMIOX -DCK_DSYSINI -DHDBUUCP \
	-DCK_CURSES -DCK_WREFRESH -DTCPSOCKET -DCK_REDIR -DRENAME -DFNFLOAT \
	-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
	$$KFLAGS $$OFLAGS" \
	"LNKFLAGS=-s $(LNKFLAGS)" "LIBS = -lm $$LIBS $(KLIBS)"

# This is a kludge, copying hpux0900gcc and adapting hpux1000
# (add CC and CC2, drop the A1.[0||1])
# Builds w/ no compiler warnings but minimally tested.
#
#OK: 2009/09/21
hpux1000gcc:
	@MESSAGE1="using the gcc compiler $(MESSAGE1)" \
	$(MAKE) hpux1000 KTARGET=$${KTARGET:-$(@)} CC=gcc CC2=gcc \
	"KFLAGS = $(KFLAGS)" "OFLAGS = -DCK_ANSIC -funsigned-char -O2"

# Trusted HP-UX 10
# echo KFLAGS=$(KFLAGS) YTARGET YTARGET=$(YTARGET) $(XTARGET) ;
hpux1000t:
	@case "$(KTARGET)" in \
	   *+openssl | *+ssl) \
		KENTRY=hpux1000o+openssl ;; \
	   *gcc) \
		KENTRY=hpux1000gcc ;; \
	   *o+) KENTRY=hpux1000o+ ;; \
	   *o)	KENTRY=hpux1000o ;; \
	   *)	KENTRY=hpux1000 ;; \
	esac ; \
	MESSAGE1="and support for 'Trusted HP-UX'" \
	$(MAKE) $$KENTRY KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS = $(KFLAGS) -DHPUX10_TRUSTED" "KLIBS=-lsec"

hpux1000to:
	$(MAKE) hpux1000t KTARGET=$${KTARGET:-$(@)}

hpux1000to+:
	$(MAKE) hpux1000t KTARGET=$${KTARGET:-$(@)}

hpux1000tgcc:
	$(MAKE) hpux1000t KTARGET=$${KTARGET:-$(@)}

hpux1000to+ssl hpux1000to+openssl:
	$(MAKE) hpux1000t KTARGET=$${KTARGET:-$(@)}

hpux1000tgcc+ssl hpux1000tgcc+openssl:
	$(MAKE) hpux1000t KTARGET=$${KTARGET:-$(@)}

#HP-9000 HP-UX 10.00 and higher with ANSI prototyping and optimization.
#PA-RISC only, no Motorola or other hardware is support in HP-UX 10.00++.
#The unbundled optional compiler is required.
#Your path should start with /opt/ansic/bin.
# -Wl,-Fw = Remove stack unwind table (info used by debuggers).
# +O2 makes a smaller executable (= -O = Level-1 and global optimization).
# +O3 adds interprocedural global optimization, makes a bigger executable.
# +Onolimit allows all modules to be optimized, no matter how complex.  But:
#  (a) +Onolimit does not seem to always be there in HP-UX 10.00, and:
#  (b) some modules might take hours on low-memory and/or slow systems.
# The following are PA-RISC-specific optimizations:
# +ESlit = Consolidate strings in read-only memory.
# +ESfsc = Inline millicode calls when comparing pointers.
# You might need to configure your kernel for a maxdsiz of 0x0B000000 (176MB)
# or greater to prevent the optimizer from running out of space.
# December 2001: +ESlit +ESsfc removed because not supported on IA64.
# Somebody who cares can use 'model' to see whether it's PA-RISC or IA64
# and include the architecture-specific optimization flags.  Also note:
# +DA1.1 is PA-only.  If this is included in in HP-UX 11.00 or later,
# then +DS2.0 should be included too (but don't use +DS2.0 without +DA1.1,
# or else the binary won't run on older PA hardware).
#OK: 2009/09/21
hpux1000o:
	@case `uname -m` in \
	  ia64) ;; \
	  *) MFLAGS='+ESlit +ESsfc' ;; \
	esac ; \
	MESSAGE1="with PA-RISC-specific optimizations $(MESSAGE1)" \
	$(MAKE) "SHELL=/usr/bin/sh" "PATH=/opt/ansic/bin:$$PATH" hpux1000 \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = $(KFLAGS) \
	-Ae -D_HPUX_SOURCE -DCK_ANSIC -DUTIMEH \
	+O2 -Wl,-Fw $$MFLAGS"

#Like hpux1000o but with "+Onolimit".
#On 700 series set kernel parameter maxdsiz >= 0x0D000000 (=208MB).
#Takes a long time.
hpux1000o+:
	@MESSAGE1="and +Onolimit $(MESSAGE1)" KTARGET=$${KTARGET:-$(@)} \
	$(MAKE) hpux1000o \
	"KFLAGS = $(KFLAGS) +Onolimit"

#HP-UX 10.xx + 11.xx with optimizing ANSI compiler and OpenSSL.
#Define SSLLIB and SSLINC appropriately for your OpenSSL installation.
#To overwrite the default SSLLIB and SSLINC settings you can also use the
#command-line variable KSSLLIB and KSSLINC like:
#make hpux1000o+openssl KSSLLIB=-L/opt/openssl/lib KSSLINC=-I/...
#Ditto for the Zlib location.
#This entry works for C-Kermit 8.0.206 on HP-UX 10.20 + 11.11
#with OpenSSL 0.9.6 + 0.9.7
#NOTE: an ANSI C compiler is required for the SSL interface.  If you don't
#have the HP Optimizing ANSI compiler, see the hpux1000gcc+openssl target
#below.
hpux1000o+ssl hpux1000o+openssl:
	@case "$(KTARGET)" in \
	   *gcc+*) \
	        KENTRY=hpux1000gcc ;; \
	   *)   KENTRY=hpux1000o ;; \
	esac ; \
	case "$(KTARGET)" in \
	   *-zlib*) \
	        DZLIB= LZLIB= ;; \
	   *)   DZLIB=-DZLIB LZLIB='-L/opt/zlib/lib -lz' ;; \
	esac ; \
	SSLINC=$${KSSLINC:-$(SSLINC)}; \
	SSLLIB=$${KSSLLIB:-$(SSLLIB)}; \
	MESSAGE1="and with OpenSSL $(MESSAGE1)" \
	$(MAKE) $$KENTRY KTARGET=$${KTARGET:-$(@)} \
	KFLAGS="-DCK_AUTHENTICATION -DCK_SSL -DOPENSSL_097 $$DZLIB \
	$$SSLINC $(KFLAGS)" \
	KLIBS="$(KLIBS) \
	$$SSLLIB -lssl -lcrypto \
	$$LZLIB \
	"

# Ditto but without Zlib:
hpux1000o+ssl-zlib hpux1000o+openssl-zlib:
	@MESSAGE1="but without Zlib $(MESSAGE1)" \
	$(MAKE) hpux1000o+ssl KTARGET=$${KTARGET:-$(@)}

#HP-UX 10.00 or higher with OpenSSL 0.9.7.  Compiled with gcc.
#From Chris Chaney, NEC America Inc.  His instructions:
# (1) Install gcc version 3.2.3 & binutils version 2.13.2
#     (used binary depot from http://hpux.cs.utah.edu/)
# (2) Install gcc make version 3.80 from http://hpux.cs.utah.edu/
#
# or: gcc 2.9.2000-12-1 from "Linux to hp-ux 11.0/11i porting kit version 1.0
#     (2CD)" free from:  http://www.software.hp.com
#
# (3) Install openSSL version 0.9.7b from http://www.software.hp.com
# (4) Install flex version 2.5.4 from http://hpux.cs.utah.edu/
# (5) Install gmp version 3.1.1 from http://hpux.cs.utah.edu/
#
#Note from Peter Eichhorn, assyst Munich. It works also without gcc make!
hpux1000gcc+ssl hpux1000gcc+openssl:
	$(MAKE) hpux1000o+openssl KTARGET=$${KTARGET:-$(@)}

# Ditto but without Zlib:
hpux1000gcc+ssl-zlib hpux1000gcc+openssl-zlib:
	$(MAKE) hpux1000o+openssl-zlib KTARGET=$${KTARGET:-$(@)}

# Same for HP-UX 11
hpux1100o+ssl hpux1100o+openssl:
	$(MAKE) hpux1000o+openssl KTARGET=$${KTARGET:-$(@)}

#OK: 2009/09/26
hpux1100gcc+ssl hpux1100gcc+openssl:
	$(MAKE) hpux1000gcc+openssl KTARGET=$${KTARGET:-$(@)}

hpux1100o+ssl-zlib hpux1100o+openssl-zlib:
	$(MAKE) hpux1000o+openssl-zlib KTARGET=$${KTARGET:-$(@)}

hpux1100gcc+ssl-zlib hpux1100gcc+openssl-zlib:
	$(MAKE) hpux1000gcc+openssl-zlib KTARGET=$${KTARGET:-$(@)}

# HP-UX 11
# Note: these are 32-bit builds even on IA64.
# Adding +DD64 to CFLAGS produces 64-bit object files,
# but the linker fails to find the needed 64-bit libs.
#OK: 2009/09/26
hpux1100:
	$(MAKE) hpux1000 KTARGET=$${KTARGET:-$(@)}

#OK: 2009/09/26
hpux1100o:
	$(MAKE) hpux1000o KTARGET=$${KTARGET:-$(@)}

hpux1100o+:
	$(MAKE) hpux1000o+ KTARGET=$${KTARGET:-$(@)}

#OK: 2009/09/26
hpux1100gcc:
	$(MAKE) hpux1000gcc KTARGET=$${KTARGET:-$(@)}

# Trusted HP-UX 11
hpux1100t:
	$(MAKE) hpux1000t KTARGET=$${KTARGET:-$(@)}

hpux1100to:
	$(MAKE) hpux1000to KTARGET=$${KTARGET:-$(@)}

hpux1100to+:
	$(MAKE) hpux1000to+ KTARGET=$${KTARGET:-$(@)}

hpux1100tgcc:
	$(MAKE) hpux1000tgcc KTARGET=$${KTARGET:-$(@)}

hpux1100to+ssl hpux1100to+openssl:
	$(MAKE) hpux1000to+openssl KTARGET=$${KTARGET:-$(@)}

hpux1100tgcc+ssl hpux1100tgcc+openssl:
	$(MAKE) hpux1000tgcc+openssl KTARGET=$${KTARGET:-$(@)}

#Regulus on CIE Systems 680/20
cie:
	@echo 'Making C-Kermit $(CKVER) for CIE Systems 680/20 Regulus...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DATTSV -DNOFILEH -DCIE -DNOLEARN $(KFLAGS) -O" "LNKFLAGS ="

# Linux 1.2 or later with gcc, dynamic libraries, ncurses, TCP/IP.
#
# If your Linux system has curses rather than ncurses, use the linuxc
# entry, or if that doesn't work, linuxnc.
#
# The Kermit "large memory model" is used by default to configure big packet
# and script buffers, etc.  For small-memory or limited-resource systems,
# "make linux KFLAGS=-DNOBIGBUF".
#
# -DLINUXFSSTND (Linux File System Standard 1.2) gives UUCP lockfile /var/lock
# with string pid.  Remove this to get /usr/spool/uucp with int pid, used in
# very early Linux versions.  FSSTND 1.2 also says that the PID string in the
# UUCP lock file has leading spaces.  This is a change from FSSTND 1.0, which
# used leading zeros.  Add -DFSSTND10 to support FSSTND 1.0 instead of 1.2.
# I hope subsequent editions of the file-system standard did not change these
# again.
#
# Add -DOLINUXHISPEED (Old Linux High Speed support) to turn on an ugly kludge
# in Linux 1.0 and earlier to support speeds of 57600 and 115200.  Extremely
# old Linux systems (pre-0.99pl15) will not support this.  If OLINUXHISPEED is
# not defined, then only the standard POSIX termios methods of setting the port
# speed will be used, and in this case speeds can be as high as 460800 in most
# modern Linux versions.
#
# -DCK_POSIX_SIG (POSIX signal handling) is good for Linux releases back to at
# least 0.99.14; if it causes trouble for you, remove it from the CFLAGS.
#
# -pipe removes the need for temp files - remove it if it causes trouble.
#
# -funsigned-char makes all characters unsigned, as they should have been
#  in the first place.
#
# Add -DCK_DSYSINI if you want a shared system-wide init file.
#
# See http://www.columbia.edu/kermit/ckubwr.html about -DNOCOTFMC.
# Better still, should read the entire Linux section of that document.
#
# The "linuxa" entry can be referenced directly on LIBC systems, but not
# GLIBC, where -lcrypt is required.  The "make linux" entry should normally
# be used for all builds on all Linux distributions unless you have special
# requirements, in which case keep reading.  CK_NEWTERM added after 7.0b04
# due to new complaints about ncurses changing buffering of tty.

linuxa:
	@echo 'Making C-Kermit $(CKVER) for Linux 1.2 or later...'
	@echo 'IMPORTANT: Read the comments in the linux section of the'
	@echo 'makefile if you have trouble.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -DLINUX -pipe -funsigned-char -DFNFLOAT -DCK_POSIX_SIG \
	-DCK_NEWTERM -DTCPSOCKET -DLINUXFSSTND -DNOCOTFMC -DPOSIX \
	-DUSE_STRERROR $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(LIBS) -lm"

# As above but with profiling
linuxp:
	$(MAKE) linuxa KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS) -pg" \
	"LIBS=-pg -lcrypt -lresolv"

#Linux.  This entry should work for any Linux distribution on any platform,
#32-bit or 64-bit, except for extremely ancient ones.  Automatically detects:
# . curses, ncurses, or no curses
# . Old versus new pty handling (new == glibc 2.1++)
# . Presence or absence of libcrypt.a and <crypt.h>
# . Presence or absence of libresolv.a
# . Transitional Long File API for 32-bit platforms (SUS V2 UNIX 98 LFS).
#Note: The HAVE_PTMX test was previously "if test -c /dev/ptmx" but this was
#not sufficient for Debian 2.1, because although it had /dev/ptmx, it did not
#have grantpt(), unlockpt(), or ptsname(), so has been changed to look for a
#grantpt() prototype in the header files.  Modified in 8.0.206 to allow for
#libraries that contain .so's but no .a's, e.g. Mandrake 9.0.
#HAVE_BAUDBOY added in 8.0.210 for Red Hat -- it's like AIX ttylock().
#Modified 17 Aug 2005 to use openpty() if available because the other stuff
#dumps core in 64-bit ia64 and x86_64 builds.
#Long file support for 32-bit builds added in 8.0.212 - if features.h contains
#__USE_LARGEFILE64 then we set the flags that must be set before reading any
#header files; on 32-bit platforms such as i386, this produces a 32-bit build
#capable of accessing, sending, receiving, and managing long (> 2GB) files.
#On 64-bit platforms, it does no harm.
#As of 3 March 2009 we detect automatically if we have curses, ncurses,
#or no curses at all.
#Added HAVE_LOCKDEV as openSuSE >= 11.3 uses ttylock directly instead of
#baudboy 2010/08/23
#OK: 2011/06/18
linux:
	@if test \
	`grep grantpt /usr/include/*.h /usr/include/sys/*.h | wc -l` -gt 0; \
	then if test -c /dev/ptmx; then HAVE_PTMX='-DHAVE_PTMX'; \
	else HAVE_PTMX=''; fi; fi ; \
	if test `grep openpty /usr/include/pty.h | wc -l` -gt 0; \
	then HAVE_OPENPTY='-DHAVE_OPENPTY'; \
	else HAVE_OPENPTY=''; fi ; \
	HAVE_LIBCURSES='-lncurses'; \
	if test -f /usr/lib64/libncurses.so || \
	   test -f /usr/lib/libncurses.a  || \
	   test -f /usr/lib/libncurses.so; then \
	  HAVE_LIBCURSES='-lncurses'; \
	else if test -f /usr/lib64/libcurses.so || \
	   test -f /usr/lib/libcurses.a || \
	   test -f /usr/lib/libcurses.so; then \
	     HAVE_LIBCURSES='-lcurses'; fi; fi; \
	HAVE_CURSES=''; \
	if test -n '$$HAVE_LIBCURSES'; then \
	  if test -f /usr/include/ncurses.h; then \
	    HAVE_CURSES='-DCK_NCURSES  -I/usr/include/ncurses'; \
	  else if test -f /usr/include/curses.h; then \
	    HAVE_CURSES='-DCK_CURSES'; \
	fi; fi; fi; \
	if test -f /usr/include/baudboy.h || test -f /usr/include/ttylock.h; \
	then HAVE_LOCKDEV='-DHAVE_LOCKDEV' ; \
	else HAVE_LOCKDEV='' ; fi ; \
	if test -f /usr/include/baudboy.h ; \
	then HAVE_BAUDBOY='-DHAVE_BAUDBOY' ; \
	else HAVE_BAUDBOY='' ; fi ; \
	$(MAKE) KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$$HAVE_CURSES $$HAVE_PTMX $$HAVE_LOCKDEV \
	$$HAVE_BAUDBOY $$HAVE_OPENPTY \
	`grep __USE_LARGEFILE64 /usr/include/features.h > /dev/null && \
	echo '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'` \
	`if test -f /usr/include/crypt.h; then echo -DHAVE_CRYPT_H; fi` \
	$(KFLAGS)" \
	"LIBS=$(LIBS) $$HAVE_LIBCURSES \
	`if test -n '$$HAVE_OPENPTY'; then echo -lutil; fi` \
	`if test -f /usr/lib64/libresolv.a || test -f /usr/lib64/libresolv.so \
	|| test -f /usr/lib/libresolv.a || test -f /usr/lib/libresolv.so \
	|| test -f /usr/lib/i386-linux-gnu/libresolv.a \
	|| test -f /usr/lib/i386-linux-gnu/libresolv.so \
	|| ls /lib/x86_64-linux-gnu/libresolv.* > /dev/null 2> /dev/null; \
	then echo -lresolv; fi` \
	`if test -f /usr/lib64/libcrypt.a || test -f /usr/lib64/libcrypt.so \
	|| test -f /usr/lib/libcrypt.a || test -f /usr/lib/libcrypt.so \
	|| ls /lib/x86_64-linux-gnu/libcrypt.* > /dev/null 2> /dev/null; \
	then echo -lcrypt; fi` \
	`if test -f /usr/lib64/liblockdev.a || \
	test -f /usr/lib64/liblockdev.so || \
	test -f /usr/lib/liblockdev.a || \
	test -f /usr/lib/liblockdev.so; \
	then echo -llockdev; fi`" \
	linuxa

# Linux + Shadow passwords + PAM
# OK 2011/06/18
linux+shadow+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux+Shadow+PAM...'
	$(MAKE) linux KTARGET=$${KTARGET:-$(@)} \
	KFLAGS="-DCK_SHADOW -DCK_PAM $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = -lpam"

# Linux systems that have no <sys/select.h>.
# (not tested in recent years, perhaps no longer needed)
linuxns:
	$(MAKE) linux KTARGET=$${KTARGET:-$(@)} KFLAGS=-DNO_SYS_SELECT_H

# Linux-script-only:
# A minimum-size version for Linux that does only scripting and
# serial communication -- no networks, no file transfer, no security.
# OK 2011/06/18
linuxso:
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -DLINUX -pipe -funsigned-char -DPOSIX -DCK_POSIX_SIG \
	-DLINUXFSSTND -DNOCOTFMC -DNOXFER -DNODEBUG -DNOCSETS -DNOHELP \
	-DNONET -DMINIDIAL -DNOSCRIPT -DNOIKSD -DNOPUSH $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS)" "LIBS = "

# Secure targets for Linux.  These work on RHAS4, RHEL4, and RHEL5,
# unlike some of the older targets that follow.  They hook into the main Linux
# target so we pick up all the other new stuff - large files, baudboy.h, the
# appropriate pty interface, etc.

# Linux with Kerberos 5.
# Use "make linux+krb5 KFLAGS=-DNO_KRB5_INIT_ETS" if necessary.
#OK 2011/06/16 on Fedora 14 with:
# make linux+krb5 "LIBS=$LIBS /lib/libk5crypto.so.3 /lib/libcom_err.so.2"
# On RHEL5: make linux+krb5 -UCK_DES
linux+krb5:
	@echo 'Making C-Kermit $(CKVER) for Linux with Kerberos 5...'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes425'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
              echo "HAVE DES"; \
           else echo "NO DES"; \
	fi; \
	K5CRYPTO=''; \
        if ls /lib/libk5crypto* > /dev/null 2> /dev/null; then \
                K5CRYPTO='-lk5crypto'; \
	else if ls /usr/lib/libk5crypto* > /dev/null 2> /dev/null; then \
		K5CRYPTO='-lk5crypto'; \
        else if ls /usr/lib64/libk5crypto* > /dev/null 2> /dev/null; then \
                K5CRYPTO='-lk5crypto'; \
        fi; fi; fi; \
	COM_ERR=''; \
	if ls /lib/libcom_err* > /dev/null 2> /dev/null; then \
		COM_ERR='-lcom_err'; \
	fi; \
	GSSAPILIB='-lgssapi'; \
	if ls /lib/libgssapi_krb5* > /dev/null 2> /dev/null; then \
		GSSAPILIB='-lgssapi_krb5'; \
	else if ls /usr/lib/libgssapi_krb5* > /dev/null 2> /dev/null; then \
		GSSAPILIB='-lgssapi_krb5'; \
	else K5DIR=`echo $(K5LIB) | sed 's|-L||'`; \
		if ls $$K5DIR/libgssapi_krb5* > /dev/null 2> /dev/null; then \
			GSSAPILIB='-lgssapi_krb5'; \
	fi; fi; fi; \
	$(MAKE) linux KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"KFLAGS= -DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 $$OPENSSLOPTION \
	-DCK_ENCRYPTION $$HAVE_DES $(K5INC) $(K5INC)/krb5 \
	-I/usr/include/et $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $$DES_LIB -lcrypto $$GSSAPILIB -lkrb5 \
	$$K5CRYPTO $$COM_ERR $(LIBS)" ; \
	if [ ! -f ./wermit ] || [ ./ckcmai.o -nt ./wermit ] ; then \
		echo ""; \
		echo "If build failed try:"; \
		echo ""; \
		echo "  make clean ; make $${KTARGET:-$(@)} KFLAGS=-UCK_DES"; \
		echo ""; \
	fi

# Linux with Kerberos 5 and Kerberos 4.
# Use "make linux+krb5 KFLAGS=-DNO_KRB5_INIT_ETS" if necessary.
# Add "KFLAGS=-UCK_DES" if failure messages look DES-related.
# UNTESTED (because I can't find a box with Krb4 and Krb5 installed)
linux+krb5+krb4:
	@echo 'Making C-Kermit for Linux with Kerberos 4 and Kerberos 5'
	$(MAKE) linux+krb5 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DKRB4 -DKRB524 $(KFLAGS)" "LIBS=$(LIBS) -lkrb4"

# Linux with OpenSSL 
# In Linux, SSL libs are often in /lib or /usr/lib and so found by default.
# This targets takes into account the DES library might or might not
# exist.  If it does exist, however, the target will require some editing
# if its basename is not libdes425.  - fdc Tue Sep 21 14:28:00 2010
# IMPORTANT: Some Linux platforms have DES libraries but they are missing
# functions used by Kermit.  In that case you will get fatal errors at
# link time involving routines such as des_ecb3_encrypt, des_random_seed,
# and des_set_odd_parity.  In that case, "make linux KFLAGS=-UCK_DES"
# There's a new warning at the end that should come out if this happens,
# and that should not come out if it didn't.
#
linux+ssl linux+openssl linux+openssl+zlib+shadow+pam linux+openssl+shadow:
	@echo 'Making C-Kermit $(CKVER) for Linux+OpenSSL SSLLIB=$(SSLLIB)'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes425'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
	      echo "HAVE DES"; \
	   else echo "NO DES"; \
	fi; \
	$(MAKE) linux KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"KFLAGS= -DCK_AUTHENTICATION -DCK_ENCRYPTION -DCK_CAST $$HAVE_DES \
	-DCK_SSL -DCK_PAM -DZLIB -DCK_SHADOW $$OPENSSLOPTION $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SSLLIB) -lssl $$DES_LIB -lcrypto -lpam -ldl -lz $(LIBS)" ; \
	if [ ! -f ./wermit ] || [ ./ckcmai.o -nt ./wermit ] ; then \
		echo ""; \
		echo "If build failed try:"; \
		echo ""; \
		echo "  make clean ; make $${KTARGET:-$(@)} KFLAGS=-UCK_DES"; \
		echo ""; \
	fi

# Linux with Kerberos 5 and OpenSSL
# OK 2011/05/16
# Add -UCK_DES if functions like des_ecb3_encrypt, es_random_seed,
# come up missing at link time.
linux+krb5+ssl linux+krb5+openssl:
	@echo 'Making C-Kermit $(CKVER) for Linux with Krb5 and OpenSSL...'
	@case `openssl version` in \
	  *0.9.7*) OPENSSLOPTION="-DOPENSSL_097" ;; \
	  *0.9.8*) OPENSSLOPTION="-DOPENSSL_098" ;; \
	  *1.[0-9].[0-9]*) OPENSSLOPTION="-DOPENSSL_100" ;; \
	  *) OPENSSLOPTION="" ;; \
	esac; \
	HAVE_DES=''; \
	DES_LIB=''; \
	if ls /usr/lib/libdes* > /dev/null 2> /dev/null || \
	   ls $(SSLLIB)/libdes* > /dev/null 2> /dev/null; then \
	      DES_LIB='-ldes425'; \
	      HAVE_DES='-DCK_DES -DLIBDES'; \
	      echo "HAVE DES"; \
	   else echo "NO DES"; \
	fi; \
	K5CRYPTO=''; \
        if ls /lib/libk5crypto* > /dev/null 2> /dev/null; then \
                K5CRYPTO='-lk5crypto'; \
	else if ls /usr/lib/libk5crypto* > /dev/null 2> /dev/null; then \
		K5CRYPTO='-lk5crypto'; \
        else if ls /usr/lib64/libk5crypto* > /dev/null 2> /dev/null; then \
                K5CRYPTO='-lk5crypto'; \
	fi; fi; fi; \
	COM_ERR=''; \
	if ls /lib/libcom_err* > /dev/null 2> /dev/null; then \
		COM_ERR='-lcom_err'; \
	fi; \
	GSSAPILIB='-lgssapi'; \
	if ls /lib/libgssapi_krb5* > /dev/null 2> /dev/null; then \
		GSSAPILIB='-lgssapi_krb5'; \
	else if ls /usr/lib/libgssapi_krb5* > /dev/null 2> /dev/null; then \
		GSSAPILIB='-lgssapi_krb5'; \
	else K5DIR=`echo $(K5LIB) | sed 's|-L||'`; \
		if ls $$K5DIR/libgssapi_krb5* > /dev/null 2> /dev/null; then \
			GSSAPILIB='-lgssapi_krb5'; \
	fi; fi; fi; \
	$(MAKE) linux KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"KFLAGS= -DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 \
	-DCK_SSL -DCK_PAM -DZLIB -DCK_SHADOW $$OPENSSLOPTION $(SSLINC) \
	-DCK_ENCRYPTION $$HAVE_DES $(K5INC) $(K5INC)/krb5 \
	-I/usr/include/et $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB) -lssl $$DES_LIB -lpam -lz \
	-lcrypto $$GSSAPILIB -lkrb5 $$K5CRYPTO $$COM_ERR $(LIBS)" ; \
	if [ ! -f ./wermit ] || [ ./ckcmai.o -nt ./wermit ] ; then \
		echo ""; \
		echo "If build failed try:"; \
		echo ""; \
		echo "  make clean ; make $${KTARGET:-$(@)} KFLAGS=-UCK_DES"; \
		echo ""; \
	fi

# ::BEGIN_OLD_LINUX_TARGETS::

# The remaining Linux entries are for special or customized builds.  They have
# not been generalized ("subroutinized") like the ones above.  Ideally, we
# should allow for every combination of libc vs glibc, gcc vs egcs, curses vs
# ncurses, Kerberos IV vs Kerberos V vs SRP (in any combination), and so on.
# The best way to do this is to set KFLAGS and LIBS values and then chain to
# the main "linux" target, as in the examples just above.  To skip past all of
# these old targets (and there are many) search for ::END_OLD_LINUX_TARGETS::
# (after this line).

#Sharp Zaurus SL-5500 - Linux based
zsl5500:
	@echo 'Making C-Kermit $(CKVER) for Sharp Zaurus SL-5500...'
	@touch ckcpro.c
	@touch wart
	$(MAKE) linuxnc KTARGET=$${KTARGET:-$(@)} "KFLAGS=-DZSL5500" \
	"CC = gcc" "CC2 = gcc"

#Mklinux DR3 has horrible bug in <utmpbits.h> - see ckufio.c.
mklinux:
	$(MAKE) KTARGET=$${KTARGET:-$(@)} "KFLAGS=-DUTMPBUG" \
	"LIBS=-lcrypt -lresolv" linuxa

#LinuxPPC 1999
linuxppc:
	@echo 'Making C-Kermit $(CKVER) for LinuxPPC 1999...'
	@if test -f /usr/lib/libcrypt.a; then \
	    if test -f /usr/lib/libresolv.a; then \
	        $(MAKE) KTARGET=$${KTARGET:-$(@)} \
		"KFLAGS=$(NCURSES_CPP) -DHAVE_CRYPT_H \
		-DLOCK_DIR=\\\\\\"\"/var/lock/modem\\\\\\"\" $(KFLAGS)" \
	        "LIBS=-lncurses -lresolv -lcrypt" linuxa ; \
	    else \
	        $(MAKE) KTARGET=$${KTARGET:-$(@)} \
		"KFLAGS=$(NCURSES_CPP) -DHAVE_CRYPT_H \
		-DLOCK_DIR=\\\\\\"\"/var/lock/modem\\\\\\"\" $(KFLAGS)" \
	        "LIBS=-lncurses -lcrypt" linuxa ; \
	    fi \
	else \
	    if test -f /usr/lib/libresolv.a; then \
	        $(MAKE) KTARGET=$${KTARGET:-$(@)} \
		"KFLAGS=$(NCURSES_CPP) \
		-DLOCK_DIR=\\\\\\"\"/var/lock/modem\\\\\\"\" $(KFLAGS)" \
	        "LIBS=-lncurses -lresolv" linuxa ; \
	    else \
	        $(MAKE) KTARGET=$${KTARGET:-$(@)} \
		"KFLAGS=$(NCURSES_CPP) \
		-DLOCK_DIR=\\\\\\"\"/var/lock/modem\\\\\\"\" $(KFLAGS)" \
	        "LIBS=-lncurses" linuxa ; \
	    fi \
	fi


# Like "make linux" but built with egcs rather than gcc.
# If you get "Internal compiler error xxx, output pipe has been closed",
# try removing -pipe.
linuxegcs:
	@echo 'Making C-Kermit $(CKVER) for Linux 1.2 or later with egcs...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = egcs" "CC2 = egcs" \
	"CFLAGS = -O -DLINUX -pipe -funsigned-char \
	-DPOSIX -DCK_POSIX_SIG -DCK_NCURSES -DNOCOTFMC \
	-DTCPSOCKET -DLINUXFSSTND $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS)" "LIBS = -lncurses -lcrypt -lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.1 (no K4 compatibility).
linux+krb5-old:
	@echo 'Making C-Kermit $(CKVER) for Linux on Intel with Kerberos...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS -DKRB5 \
	-DCK_ENCRYPTION -DCK_DES -DCK_CURSES -DCK_POSIX_SIG \
	-DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H $(K5INC) $(K5INC)/krb5 \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) -lncurses -ltermcap -ldes425 -lkrb5 \
	-lcom_err -lk5crypto -lgssapi_krb5 -lcrypt -lresolv"

# Linux on Intel PC with SRP 1.7.4 using GNU MP, Krypto, and Eric Young's
# DES library.  Remove the -DCK_DES, -DLIBDES and -ldes if you do not have
# Eric Young's# libdes.a installed.
#
linux+srp+gmp:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) srpmit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(SRPINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) \
	-lncurses -ltermcap -lsrp -lgmp -ldes -lkrypto -lcrypt -lresolv"

linux+srp+gmp+no-des:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP ...'
	$(MAKE) srpmit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP \
	-DCK_ENCRYPTION -DCK_CAST \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(SRPINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) \
	-lncurses -ltermcap -lsrp -lgmp -lkrypto -lcrypt -lresolv"

linux+srp+gmp-export:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) srpmit-export KTARGET=$${KTARGET:-$(@)} \
	"CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DFNFLOAT \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(SRPINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) \
	-lncurses -ltermcap -lsrp -lgmp -lkrypto -lcrypt -lm -lresolv"

linux+srp+gmp+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) srpmit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-DCK_PAM -DFNFLOAT $(SRPINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) -lncurses -ltermcap -lsrp -lgmp -ldes -lkrypto \
	-lcrypt -lpam -ldl -lm -lresolv"

#Linux on Intel PC with SRP 1.7.4 built with OpenSSL for Big Number Math
#and Cryptographic functionality.
#
linux+srp:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) srpmit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(SRPINC) $(SSLINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(SSLLIB) \
	-lncurses -ltermcap -lsrp -lkrypto -lcrypto -lcrypt -lresolv"

linux+srp+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) srpmit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-DCK_PAM -DFNFLOAT $(SRPINC) $(SSLINC) $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(SSLLIB) -lncurses -ltermcap -lsrp -lkrypto \
	-lcrypto -lcrypt -lpam -ldl -lm -lresolv"

#Linux on Intel PC with SRP and SSL/TLS.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 or higher to be compiled with KRB4 compatibility.
#Remove -ltermcap if it causes trouble e.g. in Debian 2.2.
#If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+srp+openssl:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(SRPINC) $(SSLINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(SSLLIB) \
	-lncurses -ltermcap -lsrp -lssl -lkrypto -lcrypto \
	-lcrypt -lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2 and SRP.
#
# libsrp.a should be build with GNU MP (libgmp.a)
# instead of AT&T CryptoLib (libcrypt.a) due to naming conflicts with
# standard distribution Linux libraries.
# Requires the Kerberos 1.2.2 or higher to be compiled with KRB4 compatibility.
linux+krb5+krb4+srp:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB54+SRP...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SRPINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SRPLIB) \
	-lncurses -ltermcap -lsrp -lgmp -lgssapi_krb5 -lkrypto \
	-ldes -lkrb4 -ldes425 -lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, SRP and SSL/TLS.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 or higher to be compiled with KRB4 compatibility.
# Requires OpenSSL 0.9.6a or higher
#If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+srp+openssl:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SRPINC) $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SRPLIB) $(SSLLIB) \
	-lncurses -ltermcap -lsrp \
	-lkrb4 -lssl -lkrypto -lcrypto \
	-lkrb5 -lcom_err -lk5crypto -lgssapi_krb5 -lcrypt -lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, SSL/TLS.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
#If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+openssl:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB) \
	-lncurses -ltermcap \
	-lkrb4 -lssl -lcrypto -lkrb5 -lcom_err \
	-lk5crypto -lgssapi_krb5 -lcrypt -lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.1, SSL/TLS.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+openssl+shadow:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_SHADOW \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB)  \
	-lncurses -ltermcap \
	-lkrb4 -lssl -lcrypto -lkrb5 -lcom_err \
	-lk5crypto -lgssapi_krb5 -lcrypt -lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2, SSL/TLS.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+openssl+zlib+shadow:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 -DZLIB \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_SHADOW \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB) \
	-lncurses -ltermcap \
	-lkrb4 -lssl -lcrypto -lkrb5 -lcom_err \
	-lk5crypto -lgssapi_krb5 -lcrypt -lresolv -lz"

linux+krb5+krb4+srp-export:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) xermit-export KTARGET=$${KTARGET:-$(@)} \
	"CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SRPINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(K5LIB) \
	-lncurses -ltermcap -lsrp -lgmp -lkrb4 -ldes425 -lkrb5 -lgssapi_krb5 \
	-lcom_err -lk5crypto -lkrypto -lcrypt -lresolv"

linux+krb5+krb4+srp+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with SRP...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-DCK_PAM $(K5INC) $(K5INC)/krb5 $(SRPINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(K5LIB) \
	-lncurses -ltermcap -lsrp -lgmp -ldes -lkrb4 -ldes425 -lkrb5 \
	-lcom_err -lk5crypto -lgssapi_krb5 -lkrypto -lcrypt -lpam -ldl \
	-lresolv"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, SRP and SSL/TLS.
# and PAM.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+srp+openssl+pam-debug:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit-debug KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-w -Dmalloc=dmalloc -Dfree=dfree -DMDEBUG $(K5INC) $(K5INC)/krb5 \
	$(SRPINC) $(SSLINC) $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(K5LIB) $(SSLLIB) \
	-lncurses -ltermcap -lsrp -lkrb4 -lssl -lkrypto -lcrypto \
	-lkrb5 -lcom_err -lk5crypto -lgssapi_krb5 -lcrypt -lresolv -lpam -ldl"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.1, SRP and SSL/TLS.
# and PAM.
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+srp+openssl+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SRPINC) $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(K5LIB) $(SSLLIB)  \
	-lm -lncurses -ltermcap -lsrp \
	-lkrb4 -lssl -lkrypto  -lcrypto -lgssapi_krb5 \
	-lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv -lpam -ldl"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, SRP, OpenSSL
# with ZLIB and PAM
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+srp+openssl+zlib+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM -DZLIB \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SRPINC) $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(K5LIB) $(SSLLIB) \
	-lm -lncurses -ltermcap -lsrp \
	-lkrb4 -lssl -lkrypto  -lcrypto -lgssapi_krb5 \
	-lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv -lpam -ldl -lz"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, SRP, OpenSSL
# with ZLIB, Shadow Passwords, and PAM
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+srp+openssl+zlib+shadow+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_SRP -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM -DZLIB \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-DCK_SHADOW $(K5INC) $(K5INC)/krb5 $(SRPINC) $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(SRPLIB) $(K5LIB) $(SSLLIB) \
	-lm -lncurses -ltermcap -lsrp -lkrypto \
	-lkrb4 -lssl -lcrypto -lgssapi_krb5 \
	-lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv -lpam -ldl -lz"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, OpenSSL
# with Shadow Passwords, PAM
#
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
linux+krb5+krb4+openssl+shadow+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SSL,...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-DCK_SHADOW $(K5INC) $(K5INC)/krb5 $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB) \
	-lm -lncurses -ltermcap \
	-lkrb4 -lssl -lcrypto -lgssapi_krb5 \
	-lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv -lpam -ldl"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, OpenSSL
# with ZLIB, Shadow Passwords, PAM
#
# libsrp.a should be build with OpenSSL
# Requires the Kerberos 1.2.2 be compiled with KRB4 compatibility.
# If you have OpenSSL 0.9.7 or later, add -DOPENSSL_097 to KFLAGS.
linux+krb5+krb4+openssl+zlib+shadow+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB,SRP,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB5 -DKRB4 -DKRB524 \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM -DZLIB \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	-DCK_SHADOW $(K5INC) $(K5INC)/krb5 $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB) \
	-lm -lncurses -ltermcap \
	-lkrb4 -lssl -lcrypto -lgssapi_krb5 \
	-lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv -lpam -ldl -lz"

#Red Hat 9 - full install includes Kerberos 5 (4 compat), PAM, SSL.
#Also works around bug in curses in which terminal goes dead after
#returning from file-transfer display.  Assumes OpenSSL 0.9.7 or later.
redhat9:
	@echo "Building SECURE Kermit for Red Hat 9.0..."
	$(MAKE) linux+krb5+krb4+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH90 -DOPENSSL_097 $(KFLAGS)"

#Ditto plus SRP (which is not normally included with RH Linux).
redhat9+srp:
	@echo "Building SECURE Kermit for Red Hat 9.0..."
	$(MAKE) linux+krb5+krb4+srp+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH90 -DOPENSSL_097 $(KFLAGS)"

#For Red Hat AS 2.1 with OpenSSL
redhat21+ssl:
	@echo "Building SECURE Kermit for Red Hat 2.1..."
	$(MAKE) linux+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS =  $(KFLAGS)"

#Red Hat Linux 8.0 - full install includes Kerberos 5 (4 compat), PAM, SSL.
#Also works around bug in curses in which terminal goes dead after
#returning from file-transfer display.
redhat80:
	@echo "Building SECURE Kermit for Red Hat 8.0..."
	$(MAKE) linux+krb5+krb4+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH80 $(KFLAGS)"

redhat80+srp:
	@echo "Building SECURE Kermit for Red Hat 8.0..."
	$(MAKE) linux+krb5+krb4+srp+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH80 $(KFLAGS)"

#Red Hat Linux 7.3 - full install includes Kerberos 5 (4 compat), PAM, SSL.
#Also works around bug in curses in which terminal goes dead after
#returning from file-transfer display.
redhat73:
	@echo "Building SECURE Kermit for Red Hat 7.3..."
	$(MAKE) linux+krb5+krb4+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH73 $(KFLAGS)"

redhat73+srp:
	@echo "Building SECURE Kermit for Red Hat 7.3..."
	$(MAKE) linux+krb5+krb4+srp+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH73 $(KFLAGS)"

#Red Hat Linux 7.2 - full install includes Kerberos 5 (4 compat), PAM, SSL.
#Also works around bug in curses in which terminal goes dead after
#returning from file-transfer display.
redhat72:
	@echo "Building SECURE Kermit for Red Hat 7.2..."
	$(MAKE) linux+krb5+krb4+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH72 $(KFLAGS)"

redhat72+srp:
	@echo "Building SECURE Kermit for Red Hat 7.2..."
	$(MAKE) linux+krb5+krb4+srp+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH72 $(KFLAGS)"

#Red Hat Linux 7.1 - full install includes Kerberos 5 (4 compat), PAM, SSL.
#Also works around bug in curses in which terminal goes dead after
#returning from file-transfer display.
redhat71:
	@echo "Building SECURE Kermit for Red Hat 7.1..."
	$(MAKE) linux+krb5+krb4+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH71 $(KFLAGS)"

redhat71+srp:
	@echo "Building SECURE Kermit for Red Hat 7.1..."
	$(MAKE) linux+krb5+krb4+srp+openssl+zlib+shadow+pam \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DRH71 $(KFLAGS)"

#Linux on Intel PC with Cygnus or MIT Kerberos 5 1.2.2, OpenSSL
# with ZLIB and PAM and Shadow passwords
linux+krb5+openssl+zlib+shadow+pam:
	@echo 'Making C-Kermit $(CKVER) for Linux on i386 with KRB5,SSL...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -g -O -funsigned-char -pipe -DPOSIX -DLINUX -DNOCOTFMC \
	-DCK_AUTHENTICATION -DCK_KERBEROS  -DKRB5 -DCK_SHADOW -DHAVE_PTMX \
	-DCK_ENCRYPTION -DCK_CAST -DCK_DES -DLIBDES -DCK_SSL -DCK_PAM -DZLIB \
	-DCK_CURSES -DCK_POSIX_SIG -DTCPSOCKET -DLINUXFSSTND -DHAVE_CRYPT_H \
	$(K5INC) $(K5INC)/krb5 $(SSLINC) \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
	"LIBS = $(K5LIB) $(SSLLIB) \
	-lm -lncurses -ltermcap -lssl -lcrypto -lgssapi_krb5 \
	-lkrb5 -lcom_err -lk5crypto -lcrypt -lresolv -lpam -ldl -lz"

linuxnotcp:
	$(MAKE) linux KTARGET=$${KTARGET:-$(@)} "KFLAGS = -DNONET $(KFLAGS)"

# "make linuxnotcp" with lcc (see http://www.cs.princeton.edu/software/lcc)
# lcc does not understand various gcc extensions:
#  "__inline__" -- can be eliminated by adding "-D__inline__="
#  "__asm__ and "long long" -- in header files, should be surrounded by
#                              "#ifndef(__STRICT_ANSI__)"/"#endif"
#  however, TCP requires some __asm__ functions, so cannot be compiled
linuxnotcp-lcc:
	@echo 'Making C-Kermit $(CKVER) for Linux with lcc ...'
	@echo 'Read comments in makefile for additional information.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC = lcc" "CC2 = lcc" \
	"CFLAGS = -DLINUX -DPOSIX -DCK_CURSES -DCK_POSIX_SIG \
	-UTCPSOCKET -DLINUXFSSTND -DNOLEARN $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS)" "LIBS = -lcurses -ltermcap"

# Linux 0.99.14 thru 1.0 with gcc, dynamic libraries, curses, TCP/IP.
# For Linux 1.2 or later, use "make linux" (above).
#
# -DLINUXFSSTND (Linux File System Standard) gives UUCP lockfile /var/lock with
# string pid.  Remove this and get /usr/spool/uucp with int pid, which was used
# in early Linux versions.
#
# If you get compiler errors regarding <linux/serial.h>, add -DNOHISPEED.
#
# -DCK_POSIX_SIG (POSIX signal handling) is good for Linux releases back to at
# least 0.99.14; if it causes trouble for you, just remove it.
#
# -DCK_CURSES: Here we link with the regular curses library.  But you should
# be using ncurses.  Internally, the ckuusx.c module includes <curses.h>, but
# this really should be <ncurses.h>.  Thus if you have the new curses
# material, you should either install it with the standard names, or else
# create symbolic links from the standard names to the new ones.  If you get
# compile-time errors complaining about data definitions in termcap.h, it
# means you have new kernel material mixed with older libc header files.  To
# fix, add "#include <termios.h>" to the <termcap.h> file.  Or if all this is
# too confusing, create a new makefile entry based on this one, but with
# -DCK_CURSES removed from CFLAGS and the entire LIBS= clause removed.
#
# But wait, there's more.  On most Linux systems, -ltermcap must be included
# in LIBS.  But on others, the linker complains that libtermcap can't be
# found.  In that case, try removing -ltermcap from LIBS=.
#
# But wait, there's more.  The format of the PID string in the UUCP lockfile
# changed between Linux FSSTND 1.0 and 1.2.  In the earlier standard, it had
# leading zeros; in the second, it has leading spaces.  By default this entry
# uses the newer standard.  To force the older one, add -DFSSTND10.
#
# "The nice thing about the Linux standard is there are so many to choose from"
#
# NOTE: Remove -DBIGBUFOK for small-memory or limited-resource systems.
linux10:
	@echo 'Making C-Kermit $(CKVER) for Linux 1.0 or earlier...'
	@echo 'IMPORTANT: Read the comments in the linux section of the'
	@echo 'makefile if you get compilation or link errors.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -DPOSIX -DCK_CURSES -DCK_POSIX_SIG -DLINUX \
	-DTCPSOCKET -DLINUXFSSTND -DOLINUXHISPEED -DNOLEARN $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS)" "LIBS = -lcurses -ltermcap"

#This version was used for Linux prior to C-Kermit 6.0.192.
#Now the "Linux File System Standard" is considered standard, ditto TCP/IP.
linuxold:
	@echo 'Making C-Kermit $(CKVER) for Linux...'
	@echo 'For FSSTND-recommended UUCP lockfiles, use:'
	@echo '  make linux "KFLAGS=-DLINUXFSSTND".'
	@echo 'Read comments in makefile for additional options.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS = -O -DLINUX -DPOSIX -DCK_CURSES -DCK_POSIX_SIG -DNOLEARN \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" "LIBS = -lcurses -ltermcap"

# ::END_OLD_LINUX_TARGETS::

# LynxOS 2.2 with GCC compiler, TCP/IP and fullscreen display.
# Probably also works with Lynx 2.1, and maybe even Lynx 2.0.
# -X means use termios serial drivers rather than BSD4.3-style sgtty drivers.
# If you have trouble with this, try "make bsd KFLAGS=-DNOFDZERO".
lynx:
	@echo 'Making C-Kermit $(CKVER) for LynxOS 2.2 with TCP/IP'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS= -O -DPOSIX -DDIRENT -DSETREUID -DCK_CURSES -DTCPSOCKET \
	-DCK_ANSIC -DLYNXOS -DNOLEARN" "LNKFLAGS = -X" "LIBS = -lcurses -lbsd"

lynx22:
	$(MAKE) lynx KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS)"

# LynxOS 2.1 with GCC compiler 1.40 and TCP/IP.
lynx21:
	@echo 'Making C-Kermit $(CKVER) for LynxOS 2.1 with TCP/IP'
	$(MAKE) kermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS= -O -DSETREUID -DTCPSOCKET -DCK_ANSIC -DBSD4 -DLYNXOS" \
	"LIBS = -lbsd"

#SCO Xenix 2.2.1 for IBM PC, XT, PS2/30, or other 8088 or 8086 machine
#Should this not work, try some of the tricks from sco286.
#NOTE: -DRENAME is omitted for early SCO Xenix releases because it didn't
#exist, or its semantics were different from the later POSIX-compliant
#version of rename().
sco86:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/86...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DXENIX -DNOFILEH -DNOIKSD -DNOUNICODE -DNOLEARN \
	$(KFLAGS) -Dunix -F 3000 -i -M0me" \
	"LNKFLAGS = -F 3000 -i -s -M0me" "LIBS = -lx"

#SCO Xenix/286 2.2.1, e.g. for IBM PC/AT, PS/2 Model 50, etc.
#Reportedly, this "make" can fail simply because of the size of this
#makefile.  If that happens, use "makeL", or edit out some of the
#other entries.  No debugging or character-set translation.
sco286:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/286...'
	@echo 'If make fails, try using makeL.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -xenix -s -O -LARGE -DXENIX -DNOFILEH -Dunix -DRDCHK -DNAP \
	-DNOIKSD -DNODEBUG -DNOTLOG -DNOCSETS -DNOLEARN \
	$(KFLAGS) -F 3000 -i -M2let16" \
	"LIBS = -lx" "LNKFLAGS = -xenix -s -O -LARGE -F 3000 -i -M2let16"

#SCO Xenix/286 2.2.1, e.g. for IBM PC/AT, PS/2 Model 50, etc.
#As above, but with HDBUUCP (This one might need fixing -- see sco286).
sco286hdb:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/286 with HDB UUCP...'
	@echo 'If make fails, try using makeL.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -s -O -LARGE -DXENIX -DNOFILEH -Dunix -DRDCHK -DNAP \
	-DHDBUUCP -DNOIKSD -DNOUNICODE -DNOLEARN \
	$(KFLAGS) -F 3000 -i -M2let32" \
	"LIBS = -lx" "LNKFLAGS = -s -O -LARGE -F 3000 -i -M2let32"

#SCO Xenix/386 2.2.2 and 2.2.3
sco386:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/386 2.2.2...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DXENIX -DNOFILEH -DNOIKSD -DNOREDIRECT -DNOLEARN \
	-Dunix -DRDCHK -DNAP -DNOUNICODE $(KFLAGS) -Otcl -M3e" \
	"LNKFLAGS = -s" "LIBS = -lx"

#SCO XENIX/386 2.2.3 with Excelan TCP/IP + curses.
# NOTE: This one might need some work in C-Kermit 6.0.
# You might need to include /usr/include/sys/types.h
# containing "typedef char *caddr_t;".  Then at least it compiles.
sco386netc:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/386 2.2.3 + Excelan TCP'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -I/usr/include/exos -DXENIX -DCK_CURSES -DNOUNICODE \
	-Dunix -DRDCHK -DNAP -DTCPSOCKET -DEXCELAN -DNOJC -DNOMKDIR -DNOFILEH \
	-DNOLEARN -DNOREDIRECT -DNOIKSD -DNO_DNS_SRV $(KFLAGS) -Otcl -M3e" \
	"LNKFLAGS = -s" "LIBS = -lc -lx -lsocket -lcurses -ltermcap"

#SCO XENIX/386 2.3.3 with gcc 1.37 or later...
sco386gcc:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/386 2.3.3, gcc...'
	@echo 'Add -D_NO_PROTOTYPE if you have trouble with Xenix header files'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS= -O -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP \
	-DNOJC -DNODEBUG -DNOUNICODE -DNOLEARN $(KFLAGS) \
	-traditional -fpcc-struct-return -fstrength-reduce \
	-DM_BITFIELDS -DM_COFF -DM_I386 -DM_I86 -DM_I86SM \
	-DM_INTERNAT -DM_SDATA -DM_STEXT -DM_SYS3 -DM_SYS5 \
	-DM_SYSIII -DM_SYSV -DM_WORDSWAP -DM_XENIX -DNOIKSD -DNOREDIRECT \
	-DPWID_T=int " "LNKFLAGS = -s" "LIBS = -lx"

#As above, but with curses...
sco386gccc:
	@echo 'Making C-Kermit $(CKVER) for SCO Xenix/386 2.3.3, gcc...'
	@echo 'Add -D_NO_PROTOTYPE if you have trouble with Xenix header files'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
	"CFLAGS= -O -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP \
	-DNOJC -DNODEBUG -DCK_CURSES -DNOUNICODE -DNOLEARN $(KFLAGS) \
	-traditional -fpcc-struct-return -fstrength-reduce \
	-DM_BITFIELDS -DM_COFF -DM_I386 -DM_I86 -DM_I86SM -DNOREDIRECT \
	-DM_INTERNAT -DM_SDATA -DM_STEXT -DM_SYS3 -DM_SYS5 \
	-DM_SYSIII -DM_SYSV -DM_WORDSWAP -DM_XENIX -DNOIKSD \
	-DPWID_T=int " "LNKFLAGS = -s" "LIBS = -lx -lcurses -ltermlib"

#SCO UNIX (and ODT) entries...
#
#NOTE: All SCO UNIX entry LIBS should have "-lc_s -lc -lx" IN THAT ORDER (if
#shared C library is desired), or else "-lc -lx" IN THAT ORDER.  Use shared C
#libraries to save memory, but then don't expect to run the resulting binary
#on a different machine.  When using -lc_s, you must also use -lc, because the
#shared C library does not contain all of libc.a.  And in all cases, -lc must
#ALWAYS precede -lx.
#
#ANOTHER NOTE: -DRENAME is included in all SCO UNIX entries.  Remove it if it
#causes trouble.  No harm is done by removing it (see ckuins.txt).
#
#AND ANOTHER: In theory, it should be possible to run SCO UNIX binaries on
#SCO Xenix 2.3 and later.  In practice, this might not work because of the
#libraries, etc.  Also, don't add the -link -z switch (which is supposed to
#root out references to null pointers) because it makes UNIX binaries core
#dump when they are run under Xenix.

#NOTE: -Otcl removed and replaced by -O, since -Otcl produced incorrect code.
#SCO UNIX/386 3.2.0, 3.2.1, and SCO Xenix 2.3.x
sco3r2:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2.0 or 3.2.1 ...'
	@echo 'Warning: If make blows up, edit the makefile to join'
	@echo 'the following three continued lines into one line.'
	@echo 'Also, remove -DRENAME if _rename unresolved at link time.'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP -DNOLEARN \
	-DRENAME -DNOIKSD -DNOJC $(KFLAGS) -O" \
	"LNKFLAGS = -s" "LIBS = -lc -lx"

#SCO UNIX/386 3.2.0 and SCO Xenix 2.3.x with Excelan TCP/IP support.
#In case of compilation or runtime problems, try adding
#"-DUID_T=int -DGID_T=int" to the CFLAGS.  If that doesn't work, try
#"-DUID_T=uid_t -DGID_T=gid_t".
sco3r2net:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 / Excelan...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -I/usr/include/exos -DXENIX -DSVR3 -DNOFILEH -DNOLEARN \
	-DHDBUUCP -DRDCHK -DNAP -DRENAME -DTCPSOCKET -DEXCELAN -DNOJC \
	-DNOIKSD -DNOREDIRECT $(KFLAGS) -O" \
	"LNKFLAGS = -s" "LIBS = -lc -lx -lsocket"

#SCO UNIX/386 3.2.0 and SCO Xenix 2.3.x with Excelan TCP/IP support.
#As above, with curses added.
sco3r2netc:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 / Excelan / curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -I/usr/include/exos -DXENIX -DSVR3 -DNOFILEH -DNOLEARN \
	-DHDBUUCP -DRDCHK -DNAP -DTCPSOCKET -DEXCELAN -DNOJC $(KFLAGS) \
	-DRENAME -DCK_CURSES -DNOREDIRECT -DNOIKSD -O" "LNKFLAGS = -s" \
	"LIBS = -lc -lx -lsocket -lcurses -ltermcap"

#SCO UNIX 3.2.x or SCO Xenix 2.3.x with Racal InterLan TCP/IP support
# Extra compile flags for other version of Racal InterLan TCP/IP:
# Xenix286/NP621-286, use -Ml -DPARAMH -DINTERLAN -Di286 -DSYSV
# Xenix386/NP621-386, use -DPARAMH -DINTERLAN -Di386 -DSYSV
# ISC386ix/NP622I, use -DSYSV -Di386
# SCO Unix3.2/NP622S, use -DSYSV -Di386 -DSCO_UNIX
# AT&T SVR3.2/NP622A, use -DSYSV -Di386 -DATT
sco3r2netri:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 / Racal InterLan...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -I/usr/include/interlan -DXENIX -DNOFILEH -DHDBUUCP \
	-DSVR3 -DRDCHK -DNAP -DTCPSOCKET -DPARAMH -DINTERLAN -Di386 -DSYSV \
	-DRENAME -DNOREDIRECT -DNOIKSD -DNOJC -DNOLEARN $(KFLAGS) -Otcl -M3e" \
	"LNKFLAGS = -s" "LIBS = -lc -lx -ltcp"

# SCO XENIX/386 2.3.3 SysV with SCO TCP/IP
# System V STREAMS TCP developed by Lachman Associates Inc and
# Convergent Technologies.
# -DRENAME removed since some reports indicate it is not supported
# (whereas others say it is.)
sco3r2lai:
	@echo 'Making C-Kermit $(CKVER) for SCO XENIX/386 2.3.3 + TCP/IP...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DLAI_TCP -Di386 -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK \
	-DNAP -DTCPSOCKET -DPWID_T=int -DNOREDIRECT -DNOIKSD -DNOLEARN \
	$(KFLAGS) -Otcl -i -M3e" \
	"LNKFLAGS = -i -s" "LIBS = -lc -lx -lsocket"

sco3r2laic:
	@echo 'Making C-Kermit $(CKVER) for SCO XENIX/386 2.3.3 + TCP/IP...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DLAI_TCP -Di386 -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK \
	-DNAP -DTCPSOCKET -DCK_ANSIC -DCK_CURSES -DM_TERMINFO -DNOLEARN \
	-DPWID_T=int -DNOREDIRECT -DNOIKSD $(KFLAGS) -Otcl -i -M3e" \
	"LNKFLAGS = -i -s" "LIBS = -ltinfo -lc -lx -lsocket"

#SCO UNIX/386 3.2v2 (POSIX job control), shared libraries.
sco3r22:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v2 ...'
	make wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNOLEARN \
	-DNAP -DRENAME -DPID_T=pid_t -DPWID_T=int -DDIRENT -DNOIKSD \
	-DNOREDIRECT $(KFLAGS) -O" \
	"LNKFLAGS = -s" "LIBS = -lc_s -lc -lx"

#SCO UNIX/386 3.2v2, POSIX job control, fullscreen file transfer display,
#dynamic memory allocation, shared C library
sco3r22c:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v2 ...'
	@echo 'Warning: If make blows up, edit the makefile to join'
	@echo 'the following four continued lines into one line.'
	make wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP -DNOLEARN \
	-DCK_CURSES -DDIRENT -DRENAME -DNOREDIRECT -DNOIKSD \
	-DPID_T=pid_t -DPWID_T=int $(KFLAGS) -O" \
	"LNKFLAGS = -s" "LIBS = -lcurses -lc_s -lc -lx"

#SCO UNIX/386 3.2v2 with gcc 1.40 or later (POSIX job control)
sco3r22gcc:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v2, gcc'
	@echo 'Warning: If make blows up, edit the makefile to join'
	@echo 'the following seven continued lines into one line.'
	make wermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" \
	"CFLAGS= -O -DPOSIX -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP \
	-DNOLEARN -DRENAME -traditional -fpcc-struct-return -fstrength-reduce \
	-DM_BITFIELDS -DM_COFF -DM_I386 -DM_I86 -DM_I86SM \
	-DM_INTERNAT -DM_SDATA -DM_STEXT -DM_SYS3 -DM_SYS5 \
	-DM_SYSIII -DM_SYSV -DM_UNIX -DM_WORDSWAP -DM_XENIX -Dunix \
	-DPID_T=pid_t -DPWID_T=int -DNOREDIRECT -DNOIKSD $(KFLAGS) " \
	"LNKFLAGS = -s" "LIBS = -lc_s -lc -lx"

#SCO UNIX/386 3.2v2 (ODT 1.1) (POSIX job control) with SCO TCP/IP, shared libs
#Requires SCO TCP/IP or ODT development system for telnet.h, etc.
sco3r22net:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2.2 + TCP/IP...'
	@echo 'Warning: If make blows up, edit the makefile to join'
	@echo 'the following three continued lines into one line.'
	make xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP -DTCPSOCKET \
	-DRENAME -DPID_T=pid_t -DPWID_T=int -DDIRENT -DNOREDIRECT -DNOIKSD \
	$(KFLAGS) -O" "LNKFLAGS = -s" "LIBS = -lsocket -lc_s -lc -lx"

#As above, but with curses for fullscreen file transfer display.
#Requires SCO TCP/IP or ODT development system for telnet.h, etc.
sco3r22netc:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v2 + TCP/IP...'
	@echo 'Warning: If make blows up, edit the makefile to join'
	@echo 'the following three continued lines into one line.'
	make xermit KTARGET=$${KTARGET:-$(@)} "CFLAGS= \
	-DXENIX -DSVR3 -DNOFILEH -DHDBUUCP -DRDCHK -DNAP -DTCPSOCKET -DRENAME \
	-DCK_CURSES -DDIRENT -DNOIKSD -DNOREDIRECT \
	-DPID_T=pid_t -DPWID_T=int -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lcurses -lsocket -lc_s -lc -lx"

#SCO XENIX 2.3.4, no curses, no TCP/IP, no IKSD.
#This one built and tested in C-Kermit 7.0.
#lcfp is C library floating-point support.
#Use -M3 to generate 32-bit i386 code instead of 16-bit segmented i286 code.
#Use -Me to enable MS nonstandard keywords in system headers.
#Use -W2 or W3 to increase the warning level.
#OK: 2011/06/15
sco234:
	@echo 'Making C-Kermit $(CKVER) for SCO XENIX 2.3.4...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSCO32 -DXENIX -DNOFILEH -DHDBUUCP -DRDCHK -DNOLEARN \
	-DNAP -DNOJC -DNOCOTFMC -DNOIKSD -DNOREDIRECT -DNOTNCODE -DNOGFTIMER \
	-DNOTIMEVAL -DNOTIMEZONE -DNOSYMLINK -DSCO234 -DDCLGETCWD $(KFLAGS) \
	-Otcl" "LNKFLAGS = -s" "LIBS = -lcfp -lc -lx"

#SCO XENIX 2.3.4, no TCP/IP, no IKSD, but with curses.
# Built and tested in C-Kermit 7.0.
# Note: XENIX 2.3.4 does not have newterm() so no point in adding -DCK_NEWTERM.
sco234c:
	@echo 'Making C-Kermit $(CKVER) for SCO XENIX 2.3.4 + curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSCO32 -DXENIX -DNOFILEH -DHDBUUCP -DRDCHK -DNOLEARN \
	-DNAP -DNOJC -DNOCOTFMC -DNOIKSD -DNOREDIRECT -DNOTNCODE -DNOGFTIMER \
	-DNOTIMEVAL -DNOTIMEZONE -DNOSYMLINK -DCK_CURSES -DSCO234 \
	-DDCLGETCWD $(KFLAGS) -Otcl" \
	"LNKFLAGS = -s" "LIBS = -lcfp -lc -ltinfo -lx"

#SCO XENIX 2.3.4 with SCO TCP/IP and curses, no IKSD.
# Built and tested in C-Kermit 7.0.  TCP/IP works and curses works.
# Previous versions of this target included -lmalloc, but this caused "error:
# " _calloc : symbol defined more than once" at link time so I removed it.
# Results are likely to vary depending on exactly which version of the SDK
# and TCP/IP SDK you have.
sco234netc:
	@echo 'Making C-Kermit $(CKVER) for SCO XENIX 2.3.4 + TCP + curses...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DSCO32 -DXENIX -DNOFILEH -DHDBUUCP -DRDCHK -DNOLEARN \
	-DNAP -DNOJC -DNOCOTFMC -DNOIKSD -DNOREDIRECT -DNOTNCODE -DNOGFTIMER \
	-DNOTIMEVAL -DNOTIMEZONE -DNOSYMLINK -DCK_CURSES -DSCO234 \
	-DDCLGETCWD -DTCPSOCKET -DNO_DNS_SRV $(KFLAGS) -Otcl" \
	"LNKFLAGS = -s" "LIBS = -ltinfo -lsocket -lcfp -lc -lx"

# SCO 3.2v4.x targets...

#  NOTE: Add -DDCLPOPEN and/or -DDCLFDOPEN to anySCO 3.2v4.x non-gcc entries
#  that complain about fdopen() or popen() at compile time.  They compile OK
#  without these flags as of July 1999.  However, the gcc entries seem to
#  need them, at least for gcc 2.7.2.2.

#  NOTE 2: To enable IKSD support, add:
#  -DCK_LOGIN -DNOGETUSERSHELL -DNOINITGROUPS
#  to CFLAGS (not tested).

#SCO UNIX/386 3.2v4 (POSIX job control), curses, ANSI C compilation,
#<dirent.h> (EAFS) file system.  Remove -lmalloc if it causes trouble.  It was
#put there to avoid core dumps caused by regular libc.a malloc.  Add -J to make
#all chars unsigned.  This version uses select() for CONNECT and also has
#high-precision timers and so might not work on non-TCP systems, in which case
#sco32v4ns should be used instead.
# If you get _ftime redefinition_ complaint, try adding -DODT30 to CFLAGS.
sco32v4:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v4...'
	make xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DCK_SCO32V4 -DNOFILEH -DHDBUUCP -DCK_CURSES -DM_TERMINFO \
	-DNOANSI -DSELECT -DNOIKSD -DDCLGETCWD -NOLSTAT \
	-DNOLINKBITS -DDCLGETCWD $(KFLAGS) -O" \
	"LNKFLAGS = -s" "LIBS = -lcurses -lmalloc -lsocket -lc_s -lc -lx"

# As above, but with no dependence on sockets library or select().
sco32v4ns:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v4...'
	@echo 'No select() and no sockets library.'
	make wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DCK_SCO32V4 -DNOFILEH -DHDBUUCP -DCK_CURSES -DM_TERMINFO \
	-DNOANSI -DNOIKSD -DNOGFTIMER -DCK_POLL -DNAP -DDCLGETCWD -DNOLSTAT \
	-DNOLINKBITS -DDCLGETCWD -DNOLEARN -O $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lcurses -lmalloc -lc_s -lc -lx"

#SCO UNIX/386 3.2v4 (POSIX job control), TCP/IP, curses, ANSI C compilation,
#<dirent.h> (EAFS) file system.  With DIRENT, -lc must come before -lx.
#Reportedly it's OK to add -DCK_REDIR and -DCK_WREFRESH, and to remove -lc_s.
#Requires SCO TCP/IP development system or ODT for telnet.h, etc.
#See sco32v4 above for additional comments.
#NOTE: No more room for -Dxxx -- 25 seems to be the limit.  Move some to
#ckcdeb.h or somewhere...
sco32v4net:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v4...'
	@echo 'If you get _ftime redefinition_ complaint,'
	@echo 'use make sco-odt30.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNOFILEH -DHDBUUCP -DTCPSOCKET -DCK_ANSIC -DCK_CURSES \
	-DNAP -DCK_WREFRESH -DNOLINKBITS -D_IBCS2 -DSELECT -DNOLSTAT \
	-DDCLGETCWD -DCK_SCO32V4 -DNOIKSD -O \
	$(KFLAGS)" "LNKFLAGS = $(LNKFLAGS) -s" \
	"LIBS = $(LIBS) -lcurses -lsocket -lmalloc -lsocket -lc_s -lc -lx"

#SCO UNIX/386 3.2v4 with gcc 1.40 or later, POSIX job control.
#Also see comments in sco32r4 entry.
sco32v4gcc:
	make xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" \
	"CFLAGS= -O -DNOFILEH -DHDBUUCP -DNOANSI -DCK_CURSES -DM_TERMINFO \
	-traditional -fpcc-struct-return -fstrength-reduce -funsigned-char \
	-D_KR -D_NO_PROTOTYPE -D_SVID -DNOIKSD -DCK_SCO32V4 -DNOLINKBITS \
	-DM_BITFIELDS -DM_COFF -DM_I386 -DM_I86 -DM_I86SM -DSELECT -DNOLSTAT \
	-DM_INTERNAT -DM_SDATA -DM_STEXT -DM_SYS3 -DM_SYS5 -DDCLGETCWD \
	-DM_SYSIII -DM_SYSV -DM_UNIX -DM_WORDSWAP -DM_XENIX -Dunix \
	-DDCLPOPEN -DDCLFDOPEN $(KFLAGS) " \
	"LNKFLAGS = -s" "LIBS = -lcurses -lsocket -lc_s -lc -lx"

#SCO UNIX/386 3.2v4 (POSIX job control), TCP/IP, curses, ANSI C compilation,
#Requires SCO TCP/IP or ODT development system for telnet.h, etc.
#<dirent.h> (EAFS) file system.  With DIRENT, -lc must come before -lx.
#gcc 1.40 or later.  Also see comments in sco32r4 entry.
sco32v4netgcc:
	make xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2=gcc" \
	"CFLAGS= -O2 -DNOFILEH -DHDBUUCP -DSELECT -DNOLSTAT \
	-DNOANSI -DTCPSOCKET -DCK_CURSES -DM_TERMINFO \
	-D_KR -D_NO_PROTOTYPE -D_SVID -DNOIKSD -DCK_SCO32V4 -DNOLINKBITS \
	-DM_BITFIELDS -DM_COFF -DM_I386 -DM_I86 -DM_I86SM -DDCLGETCWD \
	-DM_INTERNAT -DM_SDATA -DM_STEXT -DM_SYS3 -DM_SYS5 \
	-DM_SYSIII -DM_SYSV -DM_UNIX -DM_WORDSWAP -DM_XENIX -Dunix \
	-DDCLPOPEN -DDCLFDOPEN $(KFLAGS)" \
	"LNKFLAGS = -s" "LIBS = -lcurses -lsocket -lc_s -lc -lx"

#As above but with bgcc BOUNDS CHECKING (for developers only).  -lcheck has
#bounds-checking replacements for malloc, memcpy, bcopy, etc, so must come
#before -lsocket and -lc.
sco32v4netbgcc:
	make xermit KTARGET=$${KTARGET:-$(@)} \
	"CC = bgcc -pipe -m386" "CC2=bgcc -pipe -m386" \
	"CFLAGS= -O1 -g -DNOFILEH -DHDBUUCP -DSELECT \
	-DNOANSI -DTCPSOCKET -DCK_CURSES -DM_TERMINFO \
	-D_KR -D_NO_PROTOTYPE -D_SVID -DNOIKSD -DCK_SCO32V4 -DNOLSTAT \
	-DM_BITFIELDS -DM_COFF -DM_I386 -DM_I86 -DM_I86SM -DNOLINKBITS \
	-DM_INTERNAT -DM_SDATA -DM_STEXT -DM_SYS3 -DM_SYS5 -DDCLGETCWD \
	-DM_SYSIII -DM_SYSV -DM_UNIX -DM_WORDSWAP -DM_XENIX -Dunix \
	-DDCLPOPEN -DDCLFDOPEN $(KFLAGS) " \
	"LNKFLAGS = -g" "LIBS = -lcurses -lcheck -lsocket -lx"

sco32v4netnd:
	@echo sco32v4net with no debug
	$(MAKE) "MAKE=$(MAKE)" sco32v4net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DNODEBUG -DNOTLOG" "LIBS=$(LIBS)"

sco3r2netnd:
	@echo sco32v4netnd built for SCO XENIX 2.3 under SCO UNIX...
	@echo   requires copying /lib/386/Slibc.a to /lib/386/Slibc_s.a and
	@echo   getting /lib/386/Slibsocket.a from a XENIX devkit.
	@echo   WARNING: poll/CK_POLL supported only on XENIX 2.3.4
	echo    For earlier XENIX systems, replace CK_POLL with RDCHK.
	$(MAKE) "MAKE=$(MAKE)" sco32v4netnd KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -x2.3 -DNORENAME -DNOSYMLINK" \
	"LNKFLAGS = $(LNKFLAGS) -x2.3" \
	"LIBS=-ldir -lcfp $(LIBS)"

#SCO UNIX/386 3.2v4 (POSIX job control), TCP/IP, curses, ANSI C compilation,
#<dirent.h> (EAFS) file system.  With DIRENT, -lc must come before -lx.
#Reportedly it's OK to add -DCK_REDIR and -DCK_WREFRESH, and to remove -lc_s.
#Requires SCO TCP/IP development system or ODT for telnet.h, etc.
#See sco32v4 above for additional comments.
# Note: "xermit" means use the select() version of the CONNECT module.
sco32v4netx:
	@echo 'Making C-Kermit $(CKVER) for SCO UNIX/386 3.2v4...'
	@echo 'If you get _ftime redefinition_ complaint,'
	@echo 'use make sco-odt30.'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DNOFILEH -DHDBUUCP -DTCPSOCKET -DCK_ANSIC -DCK_CURSES -DNAP \
	-DCK_WREFRESH -DNOLINKBITS -D_IBCS2 -DSELECT -DDCLGETCWD \
	-DCK_SCO32V4 -DNOIKSD -DNOLSTAT -O $(KFLAGS)" \
	"LNKFLAGS = $(LNKFLAGS) -s" \
	"LIBS = $(LIBS) -lcurses -lsocket -lmalloc -lsocket -lc_s -lc -lx"

sco32v4netndx:
	@echo sco32v4netx with no debug
	$(MAKE) "MAKE=$(MAKE)" sco32v4netx KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DNODEBUG -DNOTLOG" "LIBS=$(LIBS)"

sco3r2netndx:
	@echo sco32v4netndx built for SCO XENIX 2.3 under SCO UNIX...
	@echo   requires copying /lib/386/Slibc.a to /lib/386/Slibc_s.a and
	@echo   getting /lib/386/Slibsocket.a from a XENIX devkit.
	@echo   WARNING: poll/CK_POLL supported only on XENIX 2.3.4
	echo    For earlier XENIX systems, replace CK_POLL with RDCHK.
	$(MAKE) "MAKE=$(MAKE)" sco32v4netndx KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -x2.3 -DNORENAME -DNOSYMLINK" \
	"LNKFLAGS = $(LNKFLAGS) -x2.3" \
	"LIBS=-ldir -lcfp $(LIBS)"

sco-odt30:
	@echo SCO ODT 3.0
	$(MAKE) "MAKE=$(MAKE)" sco32v4net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=$(KFLAGS) -DODT30"

#SCO OpenServer 5.0 (SCO UNIX 3.2v5.0) with SCO development tools, no TCP/IP.
#SCO OSR5 is much more like standard System V than previous SCO releases.
#The SCO development tools include TCP/IP, so this target is only for creating
#artificially limited versions of kermit required by site policy rather than
#the operating system.  NOSYSLOG is included because syslog() requires the
#sockets library.
sco32v500:
	@echo Making C-Kermit $(CKVER) for SCO OpenServer Release 5...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DDIRENT -DHDBUUCP -DSVR4 -DCK_SCOV5 -DCK_RTSCTS \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -DNOLSTAT -DNOLINKBITS -DNOSYSLOG \
	$(KFLAGS)" \
	"LIBS=-lcurses $(LIBS)" "LNKFLAGS=$(LNKFLAGS)"

sco32v5:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=$(KFLAGS)" sco32v500


#SCO OpenServer 5.0 with networking, SCO development tools.
#Networking libraries are now provided with the OS.
sco32v500net:
	@echo Making C-Kermit $(CKVER) for SCO OpenServer Release 5...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DDIRENT -DHDBUUCP -DSVR4 -DCK_SCOV5 -DCK_RTSCTS \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -DNOLSTAT -DNOLINKBITS -DTCPSOCKET \
	-DNO_DNS_SRV $(KFLAGS)" \
	"LIBS=-lcurses -lsocket $(LIBS)" "LNKFLAGS=$(LNKFLAGS)"

sco32v5net:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=$(KFLAGS)" sco32v500net

#SCO OpenServer 5.0 with networking and OpenSSL, SCO development tools.
#Networking libraries are now provided with the OS.
sco32v500net+ssl:
	@echo Making C-Kermit $(CKVER) for SCO OSR5 with OpenSSL...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DDIRENT -DHDBUUCP -DSVR4 -DCK_SCOV5 -DCK_RTSCTS \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -DNOLSTAT -DNOLINKBITS -DTCPSOCKET \
	-DNO_DNS_SRV -DCK_AUTHENTICATION -DCK_SSL -DCK_TRIGGER \
	$(SSLINC) $(SSLLIB) $(KFLAGS)" \
	"LIBS=$(SSLLIB) -lcurses -lsocket -lssl -lcrypto $(LIBS)" \
	"LNKFLAGS=$(LNKFLAGS)"

#SCO OpenServer 5.0 with gcc, no networking.
#Note: NOSYSLOG required for non-net entries because it requires <socket.h>
sco32v500gcc:
	@echo Using gcc...
	$(MAKE) "MAKE=$(MAKE)" sco32v500CC=gcc CC2=gcc \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS= $(KFLAGS)"

#SCO OpenServer 5.0 with networking, gcc.
sco32v500netgcc:
	@echo TCP/IP networking added - using gcc...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net CC=gcc CC2=gcc \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS)"

#SCO OpenServer 5.0 with networking, gcc, elf.
sco32v500netgccelf:
	@echo TCP/IP networking added - using gcc, dynamic elf library
	$(MAKE) "MAKE=$(MAKE)" sco32v500net "CC=gcc" "CC2=gcc" \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS=-O3 -belf" "LNKFLAGS=-belf"

sco32v502:
	$(MAKE) "MAKE=$(MAKE)" sco32v500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR502 $(KFLAGS)"

#SCO OpenServer 5.0.2 with networking, SCO development tools.
sco32v502net:
	@echo TCP/IP networking added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-b elf -DSCO_OSR502 $(KFLAGS)"

#SCO OpenServer 5.0.4 (SCO UNIX 3.2v5.0.4) with SCO development tools.
#Like 5.0, but adds high serial speeds.  First POSIX-based SCO version.
#Note: the -O flag is deliberately omitted for /bin/cc (= /usr/ccs/bin/cc).
sco32v504:
	@echo Making C-Kermit $(CKVER) for SCO OpenServer Release 5.0.4...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DDIRENT -DHDBUUCP -DSVR4 -DCK_SCOV5 -DCK_RTSCTS \
	-DSCO_OSR504 -b elf -DPOSIX \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -DNOLSTAT -DNOLINKBITS -DNOSYSLOG $(KFLAGS)" \
	"LIBS=-lcurses $(LIBS)" "LNKFLAGS=$(LNKFLAGS)"

#SCO OpenServer 5.0.4 with gcc, no networking.
sco32v504gcc:
	@echo Using gcc...
	$(MAKE) "MAKE=$(MAKE)" sco32v504 "CC=gcc" "CC2=gcc" \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS= $(KFLAGS)"

#SCO OpenServer 5.0.4 with networking.
#SCO development tools (/bin/cc = /usr/ccs/bin/cc).
#Optimization deliberately suppressed.
sco32v504net:
	@echo Making C-Kermit $(CKVER) for SCO OpenServer Release 5.0.4...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DDIRENT -DHDBUUCP -DSVR4 -DCK_SCOV5 -DCK_RTSCTS \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -DNOLSTAT -DNOLINKBITS -DTCPSOCKET \
	-b elf -DSCO_OSR504 -DPOSIX -DNO_DNS_SRV $(KFLAGS)" \
	"LIBS=-lcurses -lsocket $(LIBS)" "LNKFLAGS=$(LNKFLAGS)"

#SCO OpenServer 5.0.4 with networking, gcc.
sco32v504netgcc:
	@echo TCP/IP networking added - using gcc...
	@echo If gcc crashes on ckwart.c then build it by hand:
	@echo " gcc -o wart -DCK_SCOV5 ckwart.c"
	$(MAKE) "MAKE=$(MAKE)" sco32v500net "CC=gcc" "CC2=gcc" \
	KTARGET=$${KTARGET:-$(@)} "KFLAGS=-DSCO_OSR504 -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.4 with networking, gcc, elf.
sco32v504netgccelf:
	@echo TCP/IP networking added - using gcc, dynamic elf library
	$(MAKE) "MAKE=$(MAKE)" sco32v500net "CC=gcc" "CC2=gcc"
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR504 -DPOSIX -O3 -belf $(KFLAGS)" \
	LNKFLAGS="-belf"

#SCO OpenServer 5.0.5 (SCO UNIX 3.2v5.0.5) with SCO /bin/cc.
#Like 5.0, but adds high serial speeds.  First POSIX-based SCO version.
#You might have to add "LIBS=-ltinfo" (some do, some don't).
sco32v505:
	$(MAKE) "MAKE=$(MAKE)" sco32v500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DNOSHADOW -b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.5 (SCO UNIX 3.2v5.0.5) with SCO UDK.
#This one can't see the high serial speeds and anything to do with modem
#signals doesn't work because UKD cc has its own alternative universe of
#header files.
sco32v505udk:
	$(MAKE) "MAKE=$(MAKE)" sco32v500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DDCLTIMEVAL -DNOSHADOW -b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.5 with networking, SCO /bin/cc.
#See comments with sco32v505 targets.
sco32v505net:
	@echo TCP/IP networking added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DNOSHADOW -b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.5 with networking and OpenSSL, SCO /bin/cc.
#See comments with sco32v505 targets.
sco32v505net+ssl:
	@echo TCP/IP networking and OpenSSL added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net+ssl KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DNOSHADOW -b elf -DPOSIX $(KFLAGS) " \
	"LIBS=$(SSLLIB) -lcurses -lsocket -lssl -lcrypto $(LIBS)" \
	"LNKFLAGS=$(LNKFLAGS)"

#SCO OpenServer 5.0.5 with networking, SCO UDK.
#See comments with above sco32v505 targets.
sco32v505udknet:
	@echo TCP/IP networking added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DDCLTIMEVAL -DNOSHADOW -b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.5 with gcc, no networking.
sco32v505gcc:
	@echo Using gcc...
	$(MAKE) "MAKE=$(MAKE)" sco32v500 "CC=gcc" "CC2=gcc" \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DPOSIX -funsigned-char $(KFLAGS)"

#SCO OpenServer 5.0.5 with gcc, no networking, no shadow passwords.
sco32v505xgcc:
	@echo Using gcc...
	$(MAKE) "MAKE=$(MAKE)" sco32v500 "CC=gcc" "CC2=gcc" \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DNOSHADOW -DPOSIX -funsigned-char $(KFLAGS)"

#SCO OpenServer 5.0.5 with networking, gcc.
sco32v505netgcc:
	@echo TCP/IP networking added - using gcc...
	@echo If gcc crashes on ckwart.c then build it by hand:
	@echo " gcc -o wart -DCK_SCOV5 ckwart.c"
	$(MAKE) "MAKE=$(MAKE)" sco32v500net "CC=gcc" "CC2=gcc" \
	KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DNOSHADOW -DPOSIX -funsigned-char $(KFLAGS)"

#egcs is just like gcc but generates ELF by default.
#Or you can include -melf (not -belf) to force it.
sco32v505netegcs:
	$(MAKE) "MAKE=$(MAKE)" "KFLAGS=$(KFLAGS)" sco32v505netgcc \
	KTARGET=$${KTARGET:-$(@)}

#SCO OpenServer 5.0.5 with networking, gcc, elf.
sco32v505netgccelf:
	@echo TCP/IP networking added - using gcc, dynamic elf library
	$(MAKE) "MAKE=$(MAKE)" sco32v500net "CC=gcc" "CC2=gcc" \
	"KFLAGS=-DSCO_OSR505 -DPOSIX -funsigned-char -O3 -belf $(KFLAGS)" \
	KTARGET=$${KTARGET:-$(@)} LNKFLAGS="-belf"

#SCO OpenServer 5.0.6 with SCO /bin/cc.
# Add -DDCLTIMEVAL when building with UDK.
#Like 5.0.5.   IMPORTANT: Use sco32v506a target for 5.0.6a.
sco32v506:
	$(MAKE) "MAKE=$(MAKE)" sco32v500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DSCO_OSR506 -b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.6 with networking, SCO /bin/cc.
# Add -DDCLTIMEVAL when building with UDK.
# IMPORTANT: Use sco32v506a target for 5.0.6a.
sco32v506net:
	@echo TCP/IP networking added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DSCO_OSR506 -b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.6a, no networking, SCO development tools.
#This one has patched sio drivers that, for the first time,
#actually handle modem signals correctly.
# Add -DDCLTIMEVAL when building with UDK.
sco32v506a:
	$(MAKE) "MAKE=$(MAKE)" sco32v500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DSCO_OSR506 -DSCO_OSR506A -DNEEDMDMDEFS \
	-b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.6a with networking, SCO development tools.
# Add -DDCLTIMEVAL when building with UDK.
sco32v506anet:
	@echo TCP/IP networking added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DSCO_OSR506 -DSCO_OSR506A -DNEEDMDMDEFS \
	-b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.7, no networking, SCO development tools.
#Adds flags to make PTY and SSH commands work.  These have been tested
#only in 5.0.7 but probably they can also be added to earlier OSR5 targets.
sco32v507:
	$(MAKE) "MAKE=$(MAKE)" sco32v500 KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DSCO_OSR506 -DSCO_OSR507 -DNEEDMDMDEFS \
	-DHAVE_PTSNAME -DHAVE_PTMX -DHAVE_GRANTPT \
	-b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 5.0.7 as above but with networking.
sco32v507net:
	@echo TCP/IP networking added...
	$(MAKE) "MAKE=$(MAKE)" sco32v500net KTARGET=$${KTARGET:-$(@)} \
	"KFLAGS=-DSCO_OSR505 -DSCO_OSR506 -DSCO_OSR507 -DNEEDMDMDEFS \
	-DHAVE_PTSNAME -DHAVE_PTMX -DHAVE_GRANTPT \
	-b elf -DPOSIX $(KFLAGS)"

#SCO OpenServer 6 (new target 30 Jan 2006)
sco_osr600 sco600:
	@echo Making C-Kermit $(CKVER) for SCO OpenServer 6.0.0...
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -O -DDIRENT -DHDBUUCP -DSVR4 -DCK_SCOV5 -DCK_RTSCTS \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DSELECT -DSELECT_H \
	-DNOGETUSERSHELL -DNOLSTAT -DNOLINKBITS -DTCPSOCKET \
	-DNO_DNS_SRV -DSCO_OSR505 -DSCO_OSR506 -DSCO_OSR507 -DNEEDMDMDEFS \
	-DHAVE_PTSNAME -DHAVE_PTMX -DHAVE_GRANTPT -DDCLTIMEVAL \
	-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
	-DSOCKOPT_T=socklen_t -DGSOCKNAME_T=size_t -DGPEERNAME_T=size_t \
	-DHERALD=\"\\\" SCO OpenServer `uname -v`\\\"\" \
	-b elf -DPOSIX $(KFLAGS)" \
	"LIBS=-lcurses -lsocket $(LIBS)" "LNKFLAGS=$(LNKFLAGS)"

#Tandy 16/6000 with Xenix 3.0 (16 bits)
#C-Kermit 7.0 (and later) do not build here; "too many defines".
#Add more -DNOxxx options to remove features if program won't load.
#Successful operation is a function of program size, physical memory,
#available swap space, etc.  The following stripped-down configuration
#seems to work on most Tandy 6000s.  NOTE: "-+" means allow long variable
#names, needed for C-Kermit 6.0 because some identifiers are not unique
#within the first six characters.
trs16:
	@echo 'Making C-Kermit $(CKVER) for Tandy 16/6000, Xenix 3.0...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -+ -DATTSV -DTRS16 -DNOMKDIR -DDCLPOPEN -DCK_CURSES \
	-DNODEBUG -DNOTLOG -DNOHELP -DNOSCRIPT -DNOCSETS -DNOIKSD \
	-DNOREDIRECT -DNOSYSLOG -DNOPUTENV -DNOREALPATH -DNOLEARN \
	$(KFLAGS) -O" "LIBS= -lcurses -ltermcap" "LNKFLAGS = -+ -n -s"

# QNX 4.21 and above, 32-bit version, Watcom C32 10.6, fully configured,
# except no job control because QNX 4.x does not support it.  New NCURSES
# library used instead of CURSES.
#
# -Oatx optimizes to favor speed over size: loop optimization, inline fn's.
# -Os favors size over speed.  Saves 30-40K out of about 1.75M.
# -3r = generate 386 code with register-based arg passing.
# -3s = generate 386 code with stack-based arg passing.
# -ms = separate code & data 4GB segments (32-bit builds only).
# -mf = flat memory model code+data in one 4GB segment (ditto).
# -zc = place literal strings in code segment.
# -N4M = Big stack (increase the digit upon SIGSEGVs at runtime).
# chars are unsigned by default (-j makes them signed by default).
# -NOUUCP is included because QNX doesn't use it.
# Add these to the end if you like but they dump core on my QNX 4.25 system:
#
#	@wermit -h >use.qnx
#	@usemsg wermit use.qnx
#	@rm use.qnx
#
# If you get warnings about HEADER or C_IN add -DNO_DNS_SRV.
# OK 2011/06/14
qnx32:
	@echo 'Making C-Kermit $(CKVER) for QNX 4.2x, 32-bit...'
	$(MAKE) xermit \
	"LNKFLAGS = -N4M -3r" \
	"CFLAGS = -ms -3r -DQNX -DTCPSOCKET -DCK_CURSES -DNOGETUSERSHELL \
	-DCK_WREFRESH -DCK_REDIR -DSELECT -DSELECT_H -DCK_RTSCTS -DNOJC \
	-DNOINITGROUPS -DNOUUCP -DCK_ANSIC -DPID_T=pid_t -Oatx -zc $(KFLAGS)" \
	"LIBS= -lsocket -lncurses -ltermcap"

# As above but no networking since some QNX systems do not have TCP/IP
# installed, or the TCP/IP developers kit, which includes all the needed
# header files.  This entry has not been tested on a QNX system that, in
# fact, does not have TCP/IP installed; some adjustments might be necessary,
# in particular regarding the use of select(): is -lsocket needed, can we
# get the needed definitions from non-TCP/IP header files (FD_SET, etc)?
qnx32nonet:
	@echo 'Making C-Kermit $(CKVER) for QNX 4.2x, 32-bit, no net...'
	$(MAKE) xermit \
	"LNKFLAGS = -N4M -3r" \
	"CFLAGS = -3r -ms -DQNX -DNONET -DNOIKSD -DCK_CURSES \
	-DCK_WREFRESH -DCK_REDIR -DSELECT -DSELECT_H -DCK_RTSCTS -DNOJC \
	-DNOUUCP -DCK_ANSIC -DPID_T=pid_t -Oatx -zc $(KFLAGS)" \
	"LIBS= -lsocket -lncurses -ltermcap"
	@wermit -h >use.qnx
	@usemsg wermit use.qnx
	@rm use.qnx

# Synonym for qnx32.
qnx:
	$(MAKE) qnx32 "KFLAGS=$(KFLAGS)"

# QNX 4.21 and above, 16-bit version, Watcom C 8.5 - and higher on i286 PCs
# and above.
#
#	IMPORTANT: Do not use Watcom C 10.6!!!
#	If you have it installed, add "-v9.52 to CFLAGS"
#
# NOTE: QNX 4.23 onward does not work on 286's anyway.
# Stacksize 26000, objects larger than 100 bytes in their own segments,
# string constants to the codesegment, etc.  Fully configured except job ctrl.
# This entry works for building a 16-bit executable on a 32-bit system, but
# has not been tested on a 16-bit system.  Uses large memory model, links
# explicitly with large-model sockets library.  Correct-model curses library
# is chosen automatically.  See comment in qnx32 entry about -DNOUUCP.
#
# WARNING:
#
# Watcom C prior to 10.6 never had released curses library. To link against it,
# you must obtain ported free curses source from ftp://ftp.qnx.com/usr/free,
# then compile and build library (cursesl.lib) and place it in /usr/lib.  You
# must also copy curses.h to /usr/include.  Be aware that if you have Watcom
# 10.6 installed, you should already have curses.h, which is the new ncurses
# library. You must back it up and use free curses.h instead, since ncurses is
# only for 32-bit applications and some definitions in these files are
# different (e.g., clearok()).  For safety, curses is not defined in build.
#
# In 7.0 -DNOHELP added to keep ckuus2.c from blowing up; NOCSETS and NOSPL
# added because ckuus4 was blowing up, and NOFLOAT just because it seemed
# dangerous (remove -DNOFLOAT if you want to try it), The result works OK
# except for some mysterious beeps upon termination of the top-level keyword.
#
# Things to try next time we get in trouble:
#  . Change -zt100 to something smaller like -zt25
#  . Change -Oatx to -Omilerat (enable stack checking)
#  . Maybe get rid of -v9.52 -- it's only there because we were warned.
#
qnx16:
	@echo 'Making C-Kermit $(CKVER) for QNX 4.21, 16-bit...'
	$(MAKE) xermit \
	"LNKFLAGS = -2 -ml -N 26000" \
	"CFLAGS = -2 -Oatx -zc -zt100 -ml -DQNX -DQNX16 -DNOUUCP -DNOHELP \
	-DCK_REDIR -DSELECT -DSELECT_H -DNOJC -DNOGETUSERSHELL -DNOCSETS \
	-v9.52 -DTCPSOCKET -DCK_RTSCTS -DCK_ANSIC -DNOINITGROUPS -DNOKVERBS \
	-DNORANDOM -DNOCSETS -DNOSPL -DNOFLOAT -DPID_T=pid_t $(KFLAGS)"

# QNX 4.1, 16-bit version, with Watcom C 8.5 on i286 PCs and above.
# stacksize 26000, objects larger than 100 bytes in their own segments,
# string constants to the codesegment, etc.  Add -DNOUUCP if desired.
qnx16_41:
	@echo 'Making C-Kermit $(CKVER) for QNX 4.1, 16-bit...'
	$(MAKE) xermit \
	"LNKFLAGS = -mh -N 26000" "CFLAGS = -Wc,-fpc -Wc,-j -DNOGETUSERSHELL \
	-Wc,-Ols -Wc,-zdf -Wc,-zc -Wc,-zt100 -mh -DPOSIX -DQNX -DDIRENT \
	-DNOCYRIL -DNODEBUG -DNOMSEND -DMINIDIAL -DNOXMIT -DNOSCRIPT -DNOSPL \
	-DNOSETKEY -DNOINITGROUPS -DQNX16 -DPID_T=pid_t $(KFLAGS)"

# QNX Neutrino 2 ([email protected]) crosscompiled on QNX 4.25.
# Gets lots of compiler warnings.
qnx_nto2+:
	@echo 'Making C-Kermit $(CKVER) for QNX Neutrino 2+ '
	cc -o wart ckwart.c
	$(MAKE) xermit \
	"CC = qcc -Vgcc_ntox86" \
	"CC2 = qcc -Vgcc_ntox86" \
	"LNKFLAGS = " \
	"CFLAGS = -DNEUTRINO -DTCPSOCKET -DCK_CURSES -DNOGETUSERSHELL \
	-DNOUUCP -DCK_WREFRESH -DCK_REDIR -DSELECT -DSELECT_H -DCK_RTSCTS \
	-DNOJC -DNOINITGROUPS -DCK_ANSIC -DPID_T=pid_t -DUNIX -DDIRENT \
	-DMYREAD -DBSD44ORPOSIX -DSVORPOSIX -DNDGPWNAM $(KFLAGS)" \
	"LIBS= -lsocket -lncurses "

# QNX 6 (= Neutrino 2.xx) native build ([email protected]).
qnx6:
	@echo 'Making C-Kermit $(CKVER) for QNX6'
	$(MAKE) xermit KTARGET=QNX6 \
	"CFLAGS = -DPOSIX -DCK_POSIX_SIG -DNETPTY -DNOARROWKEYS \
	-DUSE_TIOCSDTR -DBIGBUFOK -DCKMAXOPEN=100 -DRLOGCODE -DNOREALPATH \
	-DMAXNAMLEN=48 -DQNX6 -DUSE_TERMIO -DINIT_SPTY \
	-DCK_CURSES -DCK_WREFRESH -DCK_NEWTERM -DDYNAMIC \
	-DTCPSOCKET -DNOGETUSERSHELL -DCK_REDIR -DSELECT -DSELECT_H \
	-DCK_RTSCTS -DNOJC -DSVORPOSIX -DBSD44ORPOSIX -DNOUUCP -DCK_ANSIC \
	$(KFLAGS) -O" \
	"LIBS= -lsocket  -lncurses"

#MINIX/2.0 32 Bit version for intel 386+ running the POSIX-compliant MINIX
# version 2.0 (The definition of fatal avoids a conflict with a symbol by
# the same name in the curses library.) It is impossible to compile with
# network support since Minix does not support Berkeley sockets.
# Note: use chmem liberally on the compiler passes, make, and the final
# kermit executable. (3 megabytes of memory for each is sufficient.)
# From Terry McConnell, Syracuse U, and Will Rose.  Will says:
# The stacks for make and some compiler passes needed to be increased
# with chmem as follows:
#   make 1MB
#   /usr/lib/em_cemcom.ansi 3MB
#   /usr/lib/em_opt 1MB
#   /usr/lib/i386/cg 1MB
#   /usr/lib/i386/as 1MB
# The compiler temporary directory was set to /usr/tmp via the TMPDIR
# environment variable; more than 1MB of temporary space was needed.
# Kermit itself needs at least 1MB of stack.
minix20:
	@echo 'Making C-Kermit $(CKVER) for MINIX 2.0/386...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} EXT=o \
	"CFLAGS=  -wo -DV7 -DMINIX2 -DMINIX -DSIG_V -D_POSIX_SOURCE \
	-DCKCPU=\\\"i-386\\\" -DNOIKSD -Dfatal=myfatal -DCK_CURSES -DNOLEARN \
	-DNOSYSLOG -DUSE_MEMCPY -DNOREALPATH $(KFLAGS)" "LIBS= -lcurses"

#MINIX/386 (PC Minix modified by Bruce Evans in Australia for 386 addressing)
# For MINIX 1.5+ (but < 2.0)
minix386:
	@echo 'Making C-Kermit $(CKVER) for MINIX/386...'
	@echo 'TOTALLY UNTESTED!'
	$(MAKE) wermit EXT=s KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DV7 -DMINIX -D_POSIX_SOURCE -DNOLEARN $(KFLAGS)"

#MINIX/386 Minix modified by Bruce Evans in Australia to use 386 addressing
minix386gcc:
	@echo 'Making C-Kermit $(CKVER) for MINIX/386 with gcc...'
	@echo 'TOTALLY UNTESTED!'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} "CC=gcc -g -O" "CC2=gcc -g" \
	"CFLAGS= -DV7 -DMINIX -D_POSIX_SOURCE -DNOLEARN $(KFLAGS)"

#MINIX - 68k version with ACK compiler.
# If you have trouble compiling or running wart, "touch wart".
# If it still doesn't work, "touch ckcpro.c".
# The version configured below has many features removed, including
# the TRANSMIT, MSEND, HELP, and SCRIPT commands, international
# character set support, and the entire script programming language.
# But it does have an interactive command parser.
# Make sure make(1) has (at least) 100000 chmemory!
# If you are using the Amsterdam C compiler, you might have to add "-D__ACK__".
minix68k:
	@echo 'Making C-Kermit $(CKVER) for MINIX 68k with ACK...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DV7 -DMINIX -D_MINIX -D_POSIX_SOURCE -DNOLEARN \
	-DNODIAL -DNOHELP -DNODEBUG -DNOTLOG \
	-DNOSCRIPT -DNOCSETS -DNOSPL $(KFLAGS) \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t -DSIG_V"

#MINIX - 68k version with c68 compiler.
# If you have trouble compiling or running wart, "touch wart" or
# "touch ckcpro.c". Compiling ckudia.c (no -DNODIAL!) might fail. :-(
# Give c68 250000 bytes of stack+heap; make sure make(1) has at least
# 100000 chmemory.  On a 1MB Atari ST this means that the recursive
# call of make fails due to memory shortage.  Try "make -n minixc68 >makeit",
# followed by ". makeit".  Otherwise, as above.
minixc68:
	@echo 'Making C-Kermit $(CKVER) for MINIX 68k with c68...'
	$(MAKE) wermit "CC= cc -c68" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DV7 -DMINIX -D_MINIX -D_POSIX_SOURCE -DNOLEARN \
	-DNODIAL -DNOHELP -DNODEBUG -DNOTLOG \
	-DNOSCRIPT -DNOCSETS -DNOSPL $(KFLAGS) \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t -DSIG_V"

#MINIX - 68k version with c68 compiler.
#A variation on the above that was recently (Sep 95) reported to work.
minixc68a:
	@echo 'Making C-Kermit $(CKVER) for MINIX 68k with c68...'
	$(MAKE) wermit "CC= cc -c68" KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DV7 -DMINIX -D_MINIX -D_POSIX_SOURCE \
	-DCK_ANSIC -DNODEBUG -DNOTLOG -DMINIDIAL -DEXTEN -DMYCURSES \
	-DNOSCRIPT -DNOCSETS -DNOSPL -DNOJC -DDIRENT -DNOLEARN \
	-DNOSETKEY -DNOESCSEQ $(KFLAGS) \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t -DSIG_V"

#MIPS Computer Systems with UMIPS RISC/OS 4.52 = AT&T UNIX System V R3.0.
#Remove -DNOJC if job control can be safely used.
mips:
	@echo 'Making C-Kermit $(CKVER) for MIPS RISC/OS...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DMIPS -DDIRENT -DCK_POLL -DNOJC -DNOLEARN -DPID_T=int \
	-DGID_T=gid_t -DUID_T=uid_t -i -O1500 $(KFLAGS)"

#As above, but with TCP/IP and fullscreen support.
mipstcpc:
	@echo 'Making C-Kermit $(CKVER) for MIPS RISC/OS...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DMIPS -DDIRENT -DCK_POLL -DNOJC \
	-DTCPSOCKET -DCK_CURSES -I/usr/include/bsd \
	-DPID_T=int -DGID_T=gid_t -DUID_T=uid_t -i -O1500 $(KFLAGS)" \
	"LIBS = -lcurses -lbsd"

#Motorola Delta System V/68 R3, signal() is void rather than int.
#Uses dirent.h and Honey DanBer uucp.  Supports TCP/IP.
#After building, use "mcs -d" to reduce size of the executable program.
sv68r3:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/68 R3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DSV68 -DDIRENT -DHDBUUCP -DNO_DNS_SRV -DTCPSOCKET \
	-DNOUNICODE -DNOLEARN -DUSE_MEMCPY $(KFLAGS) -O" "LNKFLAGS ="

#Motorola Delta System V/68 R3V5, signal() is void rather than int.
#Uses dirent.h and Honey DanBer UUCP.  Supports TCP/IP.
#After building, use "mcs -d" to reduce size of the executable program.
sv68r3v5:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/68 R3V5'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DSV68 -DDIRENT -DHDBUUCP -DNO_DNS_SRV -DUSE_MEMCPY \
	-DTCPSOCKET -DINADDRX -DNOUNICODE -DFNFLOAT -DNOLEARN $(KFLAGS) -O" \
	"LNKFLAGS =" "LIBS = -linet -lm"

#Motorola MVME147 System V/68 R3 V5.1. Requires gcc 2.1 to compile.
#After building, use "mcs -d" to reduce size of the executable program.
sv68r3v51:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/68 R3V5.1'
	$(MAKE) wermit "CC=gcc-delta" "CC2=gcc-delta" \
	KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DNODEBUG -DNO_DNS_SRV -DNOLEARN \
	-DNOUNICODE -DFNFLOAT -DSV68 -DUSE_MEMCPY $(KFLAGS) \
	-O2 -v -ftraditional" \
	"LNKFLAGS = -s -v" "LIBS = -lm881 -lm"

#Motorola MVME147 System V/68 R3V6. derived from Motorola Delta System R3V5.
#Checked on larger Motorola System V/68 R3V6 (with NSE Network Services Ext.)
#After building, use "strip" to reduce size of the executable program.
# "LIBS = -lnsl" removed in C-Kermit 6.1 - put back if needed.
# "LIBS = lm" added in 7.1/8.0 for floating-point math.
# ckuusr.c clobbers the optimizer.
sv68r3v6:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/68 R3V6'
	$(MAKE) ckuusr.$(EXT) KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSV68R3V6 -DDIRENT -DHDBUUCP -DNOLOGIN -DNOINITGROUPS \
	-DNOSYMLINK -DNOREDIRECT -DNOGFTIMER -DTCPSOCKET -DDCLGETCWD -DSV68 \
	-DNO_DNS_SRV -DNOUNICODE -DFNFLOAT -DSELECT -DUSE_MEMCPY $(KFLAGS)"
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSV68R3V6 -DDIRENT -DHDBUUCP -DNOLOGIN -DNOINITGROUPS \
	-DNOSYMLINK -DNOREDIRECT -DNOGFTIMER -DTCPSOCKET -DDCLGETCWD -DSV68 \
	-DNO_DNS_SRV -DNOUNICODE -DFNFLOAT -DSELECT -DUSE_MEMCPY $(KFLAGS)" \
	"LNKFLAGS =" "LIBS = -lm"

#Motorola Delta System V/88 R32, signal() is void rather than int.
#Uses dirent.h and Honey DanBer uucp.  Needs <sys/utime.h> for setting
#file dates.  Supports TCP/IP.
#After building, use "mcs -d" to reduce size of the executable program.
sv88r32:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/88 R32...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -DSV88R32 -DDIRENT -DHDBUUCP -DTCPSOCKET \
	-DSYSUTIMEH -DCK_CURSES -DNOGETUSERSHELL -DGTODONEARG $(KFLAGS) -O" \
	"LIBS= -lcurses -lresolv" "LNKFLAGS = -s"

#Motorola Delta System V/88 R40.  Has <sys/termiox.h>, regular Berkeley
#sockets library, i.e. in.h and inet.h are not misplaced in sys (rather than
#netinet and arpa, respectively).  Uses ANSI C constructs, advisory file
#locking on devices, etc.  curses support added.  Reportedly, the
#/usr/include/sys/vnode.h file has a bug which must be fixed before this
#makefile entry can work correctly.  The "if DEBUG" directive at about line
#320 must be changed to "ifdef DEBUG" (Reportedly, this was fixed in
#in System V/88 R4.3).
#After building, use "mcs -d" to reduce size of the executable program.
sv88r40:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/88 R40...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DMOTSV88R4 -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DTCPSOCKET -DCK_CURSES -DNOGETUSERSHELL -DGTODONEARG -DFNFLOAT \
	$(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -lresolv -lm" "LNKFLAGS = -s"

#As above but without the floating-point math library.
sv88r40nm:
	@echo 'Making C-Kermit $(CKVER) for Motorola UNIX System V/88 R40...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS = -O -DSVR4 -DMOTSV88R4 -DDIRENT -DHDBUUCP -DSTERMIOX \
	-DTCPSOCKET -DCK_CURSES -DNOGETUSERSHELL -DGTODONEARG $(KFLAGS)" \
	"LIBS= -lsocket -lnsl -lcurses -lresolv" "LNKFLAGS = -s"

#As above but with floating-point math library support \ffp...() functions
#and S-Expressions.

#Olivetti X/OS R2.3, 3.x.
#NOTES:
# . If you build the executable on 2.x X/OS, it will also run on 3.x.
# . If you build it on 3.x X/OS, it will NOT run on 2.x.
# . Kermit can run with no privileges unless the uucp lines are protected,
#   in which case kermit must be owned by uucp with suid bit set:
#   chown uucp kermit ; chmod 4111 kermit.
xos23:
	@echo 'Making C-Kermit $(CKVER) for Olivetti X/OS...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	'CFLAGS=-OLM -DOXOS -DTCPSOCKET -DHDBUUCP $(KFLAGS)' \
	"LIBS=" "LNKFLAGS="

#As above, but with curses.
xos23c:
	@echo 'Making C-Kermit $(CKVER) for Olivetti X/OS with curses...'
	$(MAKE) xermit KTARGET=$${KTARGET:-$(@)} \
	'CFLAGS=-OLM -DOXOS -DTCPSOCKET -DHDBUUCP -DCK_CURSES $(KFLAGS)' \
	"LIBS=-lcurses" "LNKFLAGS="

ckuuid:
	@echo 'building C-Kermit $(CKVER) set-UID/set-GID test programs'
	$(CC) -DANYBSD -DSAVEDUID -o ckuuid1 ckuuid.c
	$(CC) -DANYBSD -o ckuuid2 ckuuid.c
	$(CC) -DANYBSD -DNOSETREU -o ckuuid3 ckuuid.c
	$(CC) -DANYBSD -DSETEUID -DNOSETREU -o ckuuid4 ckuuid.c
	$(CC) -o ckuuid5 ckuuid.c
	@echo 'Read the top of ckuuid.c for directions...for testing'
	@echo 'you must make these programs setuid and setgid'

############################################################################
# A N T I Q U I T I E S
#
# The following are antique targets from C-Kermit 5A or earlier.  They have
# not been updated or tested in years.  Most of them will need recent features
# disabled, usually with some combination of -DNOUNICODE, -DNOIKSD, -DNOANSI,
# -DNOCKGHNLHOST, -DNO_DNS_SRV, -DNOREDIRECT, -DNOREALPATH, -DNOCURSES, etc.
# They are also missing the KTARGET=$${KTARGET:-$(@)} business.
# For details see ckuins.txt and ckccfg.txt.
#
############################################################################

#Berkeley Unix 2.8, 2.9 for PDP-11s with I&D space, maybe also Ultrix-11???
#C-Kermit(5A) is simply too large (even turning off almost every feature
#available) to run without both I&D space plus overlays.  The old comment
#suggested running 'pcc' but that won't help.  Changing 'cc' to 'ckustr.sed'
#will cause a string extraction to be done, saving D space by moving strings
#to a file.
bsd29:
	@echo Making C-Kermit $(CKVER) for 2.8 or 2.9BSD.
	@echo Read the makefile if you have trouble with this...
	$(MAKE) ovwermit \
	"CFLAGS= -DBSD29 -DNODEBUG -DNOTLOG -DNOCSETS -DNOHELP \
	-DNOSCRIPT -DNOSPL -DNOXMIT -DNODIAL $(KFLAGS)" \
	"LNKFLAGS= -i -lndir" "CC= cc " "CC2= cc"

bsd210:
	@echo Please use ckubs2.mak to build C-Kermit $(CKVER) for 2.10BSD.

bsd211:
	@echo Please use ckubs2.mak to build C-Kermit $(CKVER) for 2.11BSD.

#Charles River Data Systems Universe with UNOS Version 9.2
crds:
	@echo 'Making C-Kermit $(CKVER) for Charles River Data Systems...'
	make xermit \
	"CFLAGS = -DATTSV -DNOANSI -DDIRENT -DLONGFN -DTCPSOCKET \
	-DLOCK_DIR=\\\"/usr/spool/uucp\\\" -DNOSETREU \
	-Dsuspend=ksuspend $(KFLAGS) -O" "LNKFLAGS ="

#Microport SV/AT for IBM PC/AT 286 and clones, System V R2.
#The -O flag may fail on some modules (like ckuus2.c), in which case you
#should compile them by hand, omitting the -O.  If you get "hash table
#overflow", try adding -DNODEBUG.
#Also, reportedly this compiles better with gcc than with cc.
mpsysv:
	@echo 'Making C-Kermit $(CKVER) for Microport SV/AT 286...'
	$(MAKE) wermit \
	"CFLAGS= -DATTSV -DNOLEARN $(KFLAGS) -O -Ml" "LNKFLAGS = -Ml"

#Microsoft "Xenix/286" e.g. for IBM PC/AT
xenix:
	@echo 'Making C-Kermit $(CKVER) for Xenix/286'
	$(MAKE) wermit \
	"CFLAGS= -DXENIX -DNOFILEH -DNOLEARN $(KFLAGS) -Dunix -F 3000 -i" \
	"LNKFLAGS = -F 3000 -i"

#PC/IX, Interactive Corp System III for IBM PC/XT
pcix:
	@echo 'Making C-Kermit $(CKVER) for PC/IX...'
	$(MAKE) wermit \
	"CFLAGS= -DPCIX -DISIII -DNOLEARN $(KFLAGS) \
	-Dsdata=sdatax -O -i" "LNKFLAGS = -i"

#Integrated Solutions Inc V8S VME 68020
isi:
	@echo Making C-Kermit $(CKVER) for 4.2BSD on ISI...
	$(MAKE) wermit "CC = cc" \
	"CFLAGS= -DBSD4 -DTCPSOCKET -DINADDRX -DDCLPOPEN -DDEBUG -DNOSETREU \
	-DCK_CURSES -DNOLEARN $(KFLAGS)" "LIBS = -lcurses -ltermcap"

#Interactive Corp version of AT&T System III
#is3: (very old, probably not sufficient for 5A or later)
#	@echo 'Making C-Kermit $(CKVER) for Interactive System III...'
#	make wermit "CFLAGS = -DISIII -Ddata=datax -O -i" "LNKFLAGS = -i"
#The following should work, use it if you don't have gcc.
#Use is3gcc if you have gcc.
is3:
	@echo 'Making C-Kermit $(CKVER) for Interactive System III...'
	$(MAKE) wermit \
	"CFLAGS= -DISIII $(KFLAGS) -Ddata=datax -DNAP -DHDBUUCP
	-DLOCK_DIR=\"/usr/spool/uucp\" -DSIGTYP=void -O -i" "LNKFLAGS = -i"

#Interactive UNIX System V R3, no network support.  Uses <dirent.h> and Honey
#DanBer UUCP.  If this entry does not compile correctly, try any or all of the
#following.  These suggestions also apply more or less to the other is5r3xxx
#entries that follow this one.
# . Remove the UID_T and GID_T definitions, or change them as required.
# . Change -DDIRENT to -DSDIRENT.
# . Add -DSIGTYP=void.
# . Remove -g from LNKFLAGS.
# . Add -DNOANSI to remove compiler complaints about ANSI C constructions
# . Add other -DNOxxx's to save space (e.g. -DNOCSETS)
# See the next few makefile entries for related examples.
# Also see sys5r32is for making a portable i386 SVR3 binary.
is5r3:
	@echo 'Making C-Kermit $(CKVER) for Interactive 386/ix or later...'
	@echo 'If this does not work please read the makefile entry.'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -g -DNOCSETS -DNOREALPATH \
	-DUID_T=ushort -DGID_T=ushort -DI386IX $(KFLAGS)" \
	"LNKFLAGS = -g"

#Interactive Corp System System V R3 with gcc
is3gcc:
	@echo 'Making C-Kermit $(CKVER) for Interactive System V R3 / gcc...'
	$(MAKE) wermit CC=gcc CC2=gcc \
	'CFLAGS = -D_SYSV3 -DISIII -Ddata=datax -DNAP -DHDBUUCP -DNOREALPATH \
	-DLOCK_DIR=\"/usr/spool/uucp\" -DSIGTYP=void -O' "LNKFLAGS ="

#Interactive UNIX System V R3, POSIX variant.  Untested.
#Uses dirent.h and Honey DanBer uucp.  Read comments in is5r3 entry.
is5r3p:
	@echo 'Making C-Kermit $(CKVER) for Interactive 386/ix or later...'
	$(MAKE) wermit \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP -g -DNOCSETS -DNOREALPATH \
	-DI386IX -DPOSIX $(KFLAGS)" "LNKFLAGS=" "LIBS=-lcposix"

#Interactive UNIX SVR3 2.2.1, job control, curses, no net, gcc.
is5r3gcc:
	$(MAKE) wermit CC=gcc CC2=gcc \
	"CFLAGS=-g -posix -DSVR3 -DDIRENT -DNOREALPATH \
	-DHDBUUCP -O -DNOCSETS -DI386IX -DSVR3JC -DCK_CURSES \
	$(KFLAGS)" LNKFLAGS="-posix" LIBS="-lcurses -lc_s"

#Interactive UNIX System V R3 with TCP/IP network support.
#Needs -linet for net functions.  signal() is void rather than int.
#Uses dirent.h and Honey DanBer uucp. Read comments in is5r3 entry.
#Also see is5r3net2 if you have trouble with this entry.
is5r3net:
	@echo 'Making C-Kermit $(CKVER) for Interactive 386/ix...'
	@echo 'If this does not work please read the makefile entry.'
	$(MAKE) wermit CC="$(CC)" CC2="$(CC2)" \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DTCPSOCKET -DNOREALPATH \
	-DI386IX $(KFLAGS) -O" "LIBS = -linet"

is5r3netgcc:
	$(MAKE) is5r3net CC=gcc CC2=gcc

#Interactive UNIX System V R3, no job control, signal() void rather than int.
#Uses dirent.h and Honey DanBer uucp.  Needs -linet for net functions.
#Read comments in is5r3 entry.  Use this entry if is5r3net fails.
#Saves some space by stripping (-s) and using shared library (-lc_s).
is5r3net2:
	@echo 'Making C-Kermit $(CKVER) for Interactive 386/ix...'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DTCPSOCKET -DNOJC -DNOREALPATH \
	-DSIGTYP=void -DNOANSI -DI386IX $(KFLAGS) -O" \
	"LNKFLAGS= -s" "LIBS = -linet -lc_s"

#Interactive UNIX System V R3 (version 2.2 or later) with job control & curses.
#Uses dirent.h and Honey DanBer UUCP.
is5r3jc:
	@echo 'Making C-Kermit $(CKVER) for Interactive Unix 2.2 or later...'
	$(MAKE) wermit CC="$(CC)" CC2="$(CC2)" \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -O -DNOCSETS -DNOREALPATH \
	-DUID_T=ushort -DGID_T=ushort -DI386IX -DSVR3JC -DCK_CURSES \
	-DPOSIX_JC -DCK_REDIR -DCK_POLL -DDCLGETCWD \
	$(KFLAGS)" "LIBS=-lcurses -lc_s -linet"

is5r3jcgcc:
	$(MAKE) is5r3jc CC="gcc -DCK_ANSILIBS -DDCGPWNAM -O4" CC2=gcc \
	KFLAGS="$(KFLAGS)" LNKFLAGS="$(LNKFLAGS)"

#Sunsoft/Interactive UNIX System V R3 (version 2.2 or later)
#with job control, curses, and TCP/IP networking.
#Uses dirent.h and Honey DanBer UUCP.
is5r3netjc:
	@echo 'Making C-Kermit $(CKVER) for Interactive Unix 2.2 or later...'
	$(MAKE) wermit CC="$(CC)" CC2="$(CC2)" \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -O -DNOCSETS -DNOREALPATH \
	-DUID_T=ushort -DGID_T=ushort -DI386IX -DSVR3JC -DCK_CURSES \
	-DPOSIX_JC -DCK_REDIR -DTCPSOCKET -DSELECT \
	$(KFLAGS)" "LIBS=-linet -lcurses -lc_s"

is5r3netjcgcc:
	$(MAKE) is5r3netjc CC="gcc -DCK_ANSILIBS -DDCGPWNAM -O4" CC2=gcc \
	KFLAGS="$(KFLAGS)" LNKFLAGS="$(LNKFLAGS)"

#Masscomp System III
rtu:
	@echo 'Making C-Kermit $(CKVER) for Masscomp RTU System III...'
	$(MAKE) wermit \
	"CFLAGS= -UFIONREAD -DATTSV $(KFLAGS) -O" "LNKFLAGS =" "LIBS= -ljobs"

#Masscomp/Concurrent RTU 4.0 or later, Berkeley environment.
#Includes <ndir.h> = /usr/include/ndir.h
#Note "LIBS = -lndir" might not be necessary because of "ucb make".
rtubsd:
	@echo 'Making C-Kermit $(CKVER) for Masscomp RTU 4.1A...'
	ucb make wermit \
	"CFLAGS= -DBSD4 -DRTU -DNDIR -DHDBUUCP -DTCPSOCKET $(KFLAGS)" \
	"LIBS = -lndir"

#Masscomp/Concurrent RTU 4.0 or later, same as above,
#Includes "usr/lib/ndir.h"
#Note "LIBS = -lndir" might not be necessary because of "ucb make".
rtubsd2:
	@echo 'Making C-Kermit $(CKVER) for Masscomp RTU 4.1A...'
	ucb make wermit \
	"CFLAGS= -DBSD4 -DRTU -DXNDIR -DHDBUUCP $(KFLAGS)" \
	"LIBS = -lndir"

#Masscomp/Concurrent RTU 4.0 or later, same as above,
#Includes <sys/ndir.h>
#Note "LIBS = -lndir" might not be necessary because of "ucb make".
rtubsd3:
	@echo 'Making C-Kermit $(CKVER) for Masscomp RTU 4.x BSD...'
	ucb make wermit "CFLAGS= -DBSD4 -DRTU -DHDBUUCP $(KFLAGS)" \
	"LIBS = -lndir"

#Masscomp/Concurrent RTU 4.0 or later, System V R2, using <dirent.h>.
#In case of problems, add back the -DRTU switch.
#In case -DTCPSOCKET gives trouble, remove it.
rtus5:
	@echo 'Making C-Kermit $(CKVER) for Masscomp RTU 4.x...'
	$(MAKE) wermit \
	"CFLAGS= -DATTSV -DHDBUUCP -DDIRENT -DTCPSOCKET $(KFLAGS)"

#Masscomp/Concurrent RTU 4.x, System V R3, using <dirent.h>.
#Use this one if rtus5 gives warnings about pointer type mismatches.
#In case of problems, add back the -DRTU switch.
rtus5r3:
	@echo 'Making C-Kermit $(CKVER) for Masscomp RTU Sys V R3...'
	$(MAKE) wermit "CFLAGS= -DSVR3 -DHDBUUCP -DDIRENT $(KFLAGS)"

#DEC Pro-3xx with Pro/Venix V1.0 or V1.1
# Requires code-mapping on non-I&D-space 11/23 processor, plus some
# fiddling to get interrupt targets into resident code section.
# This almost certainly doesn't work any more.
provx1:
	@echo 'Making C-Kermit $(CKVER) for DEC Pro-3xx, Pro/Venix 1.x...'
	$(MAKE) wart "CFLAGS= -DPROVX1 $(KFLAGS)" "LNKFLAGS= "
	$(MAKE) wermit "CFLAGS = -DPROVX1 -DNOFILEH -md780" \
		"LNKFLAGS= -u _sleep -lc -md780"

#Nixdorf Targon/31.
#AT&T UNIX System V R3, signal() is void rather than int.
#Uses dirent.h without Honey DanBer uucp.
t31tos40x:
	@echo 'Making C-Kermit $(CKVER) for Targon/31 with TOS 4.0.xx...'
		$(MAKE) wermit \
		"CFLAGS= -DSVR3 -DDIRENT $(KFLAGS) -O" \
		"LNKFLAGS="

#NCR Tower 1632, OS 1.02
tower1:
	@echo 'Making C-Kermit $(CKVER) for NCR Tower 1632, OS 1.02...'
	$(MAKE) wermit "CFLAGS= -DTOWER1 $(KFLAGS)"

#NCR Tower 32, OS Release 1.xx.xx
tower32-1:
	@echo 'Making C-Kermit $(CKVER) for NCR Tower 32 Rel 1 System V R2...'
	@echo 'Add KFLAGS=-DISDIRBUG if you get errors about S_ISREG/S_ISDIR.'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV $(KFLAGS) -O" "LNKFLAGS = -n"

#NCR Tower 32, OS Release 2.xx.xx
tower32-2:
	@echo 'Making C-Kermit $(CKVER) for NCR Tower 32 Rel 2 System V R2...'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DHDBUUCP $(KFLAGS) -O2" \
	"LNKFLAGS = -n"

#NCR Tower 32, OS Releases based on System V R3
#Don't add -DNAP (doesn't work right) or -DRDCHK (not available in libc).
tower32:
	@echo 'Making C-Kermit $(CKVER) for NCR Tower 32 System V R3...'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DNOSYSIOCTLH $(KFLAGS) \
	-DUID_T=ushort -DGID_T=ushort -O1"

#NCR Tower 32, OS Releases based on System V R3
tower32g:
	@echo 'Making C-Kermit $(CKVER) for NCR Tower 32 System V R3, gcc...'
	$(MAKE) wermit "CC = gcc" \
	"CFLAGS = -DSVR3 -DDIRENT -DHDBUUCP -DNOSYSIOCTLH $(KFLAGS) \
	DUID_T=ushort -DGID_T=ushort -O -fstrength-reduce -fomit-frame-pointer"

#Fortune 32:16, For:Pro 1.8 (mostly like 4.1bsd)
ft18:
	@echo 'Making C-Kermit $(CKVER) for Fortune 32:16 For:Pro 1.8...'
	$(MAKE) wermit \
	"CFLAGS= -DNODEBUG -DBSD4 -DFT18 -DNOFILEH $(KFLAGS) \
	-DPID_T=short"

#Fortune 32:16, For:Pro 2.1 (mostly like 4.1bsd).
#The modules that break the optimizer are compiled separately.
ft21:
	@echo 'Making C-Kermit $(CKVER) for Fortune 32:16 For:Pro 2.1...'
	$(MAKE) ckuusx.$(EXT) "CFLAGS= -DNODEBUG -DBSD4 -DFT21 -DNOFILEH \
	-SYM 800  -DCK_CURSES $(KFLAGS) -DPID_T=short" \
	"LNKFLAGS= -n -s" "LIBS= -lcurses -ltermcap -lv -lnet"
	$(MAKE) ckuxla.$(EXT) "CFLAGS= -DNODEBUG -DBSD4 -DFT21 -DNOFILEH \
	-SYM 800  -DCK_CURSES $(KFLAGS) -DPID_T=short" \
	"LNKFLAGS= -n -s" "LIBS= -lcurses -ltermcap -lv -lnet"
	$(MAKE) ckudia.$(EXT) "CFLAGS= -DNODEBUG -DBSD4 -DFT21 -DNOFILEH \
	-SYM 800  -DCK_CURSES $(KFLAGS) -DPID_T=short" \
	"LNKFLAGS= -n -s" "LIBS= -lcurses -ltermcap -lv -lnet"
	$(MAKE) wermit \
	"CFLAGS= -O -DNODEBUG -DBSD4 -DFT21 -DNOFILEH -SYM 800 \
	-DCK_CURSES $(KFLAGS) -DPID_T=short" \
	"LNKFLAGS= -n -s" "LIBS= -lcurses -ltermcap -lv -lnet"

#Valid Scaldstar
#Berkeleyish, but need to change some variable names.
valid:
	@echo 'Making C-Kermit $(CKVER) for Valid Scaldstar...'
	$(MAKE) wermit \
	"CFLAGS= -DBSD4 -DNODEBUG -DNOTLOG -Dcc=ccx -DFREAD=1 $(KFLAGS)"

#IBM IX/370 on IBM 370 Series mainframes
#Mostly like sys3, but should buffer packets.
ix370:
	@echo 'Making C-Kermit $(CKVER) for IBM IX/370...'
	$(MAKE) wermit "CFLAGS = -DIX370 -DATTSV $(KFLAGS) -i -O" \
	"LNKFLAGS = -i"

#Amdahl UTS 2.4 on IBM 370 series compatible mainframes.
#Mostly like V7, but can't do initrawq() buffer peeking.
uts24:
	@echo 'Making C-Kermit $(CKVER) for Amdahl UTS 2.4...'
	$(MAKE) wermit "CFLAGS=-DV7 -DPROCNAME=\\\"$(PROC)\\\" \
	-DUTS24 -DBOOTNAME=\\\"$(BOOTFILE)\\\" -DNPROCNAME=\\\"$(NPROC)\\\" \
	-DNPTYPE=$(NPTYPE) $(DIRECT) $(KFLAGS)"

#Amdahl UTSV UNIX System V = System V R2 or earlier.
utsv:
	@echo 'Making C-Kermit $(CKVER) for Amdahl UTSV...'
	$(MAKE) wermit \
	"CFLAGS = -DUTSV $(KFLAGS) -i -O" "LNKFLAGS = -i"

#Amdahl UTSV UNIX System V = System V R2 or earlier, with TCP sockets library.
utsvtcp:
	@echo 'Making C-Kermit $(CKVER) for Amdahl UTSV w/tcp...'
	$(MAKE) wermit "CFLAGS = \
	-DTCPSOCKET -DUTSV $(KFLAGS) -i -O" "LNKFLAGS = -i" \
	"LIBS = -lsocket"

#BBN C/70 with IOS 2.0
#Mostly Berkeley-like, but with some ATTisms
c70:
	@echo 'Making C-Kermit $(CKVER) for BBN C/70 IOS 2.0...'
	$(MAKE) wermit "CFLAGS= -DBSD4 -DC70 $(KFLAGS)"

#Zilog ZEUS 3.21
zilog:
	@echo 'Making C-Kermit $(CKVER) for Zilog Zeus 3.21...'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DZILOG -DNODEBUG $(KFLAGS) -i -O" \
	"LNKFLAGS = -i -lpw"

#Whitechapel MG-1 Genix 1.3
white:
	@echo 'Making C-Kermit $(CKVER) for Whitechapel MG-1 Genix 1.3...'
	@touch ckcpro.c
	$(MAKE) wermit "CFLAGS= -DBSD4 -Dzkself()=0  $(KFLAGS)"

#Pixel 1000
pixel:
	@echo 'Making C-Kermit $(CKVER) for Pixel 1000...'
	$(MAKE) wermit "CFLAGS= -DBSD4 -Dzkself()=0 $(KFLAGS)"

ptx:
	$(MAKE) "MAKE=$(MAKE)" dynixptx12

#CDC VX/VE 5.2.1
vxve:
	@echo 'Making C-Kermit $(CKVER) for CDC VX/VE 5.2.1...'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DVXVE -DNODEBUG -DNOTLOG $(KFLAGS) -i -O" \
	"LNKFLAGS = -i"

#DIAB DS90 or LUXOR ABC-9000 with pre-5.2 DNIX.  Sys V with nap() and rdchk().
# nd = no opendir(), readdir(), closedir(), etc.
# Some of the modules fail to compile with -O.
dnixnd:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with very old DNIX 5.2.'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DNAP -DRDCHK -DDCLPOPEN \
	-U__STDC__ $(KFLAGS)"

#DIAB DS90 with DNIX 5.2.  Sys V with nap() and rdchk().
# This one has opendir(), readdir(), closedir(), etc.
# Some of the modules fail to compile with -O.
dnix:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with old DNIX 5.2...'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DNAP -DRDCHK -DDIRENT  \
	-U__STDC__ $(KFLAGS)"

#DIAB DS90 with DNIX 5.2.  Sys V with nap() and rdchk().
# As above, but with curses and TCP/IP.
# You might get complaints about redefinition of O_RDONLY, etc, because
# of bugs in the DNIX header files, which can be fixed by adding #ifndef...
# around the offending definitions in the header files.
dnixnetc:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with old DNIX 5.2...'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DNAP -DRDCHK -DDIRENT  \
	-DTCPSOCKET -DCK_CURSES -I/usr/include/bsd -U__STDC__ $(KFLAGS)" \
	"LIBS = -ln -lcurses"

#DIAB DS90 with DNIX 5.3 or later, with HDB UUCP, nap() and rdchk().
dnix5r3:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with DNIX 5.3...'
	@echo 'with Honey DanBer UUCP'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DHDBUUCP -DNAP -DRDCHK -DDIRENT \
	-DCK_CURSES -DRENAME $(KFLAGS) -O" "LIBS= -lcurses"

#DIAB DS90 with DNIX 5.3 or later, with HDB UUCP, nap() and rdchk() + TCP/IP
dnix5r3net:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with DNIX 5.3...'
	@echo 'with Honey DanBer UUCP and TCP/IP'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DHDBUUCP -DNAP -DRDCHK -DDIRENT \
	-DTCPSOCKET -DCK_CURSES -DRENAME $(KFLAGS) -O \
	-I/usr/include/bsd" "LIBS = -ln -lcurses"

#DIAB DS90 with DNIX 5.3 2.2 or later, with HDB UUCP, nap() and rdchk(),
#ANSI C compilation and libraries.
#Note that for DNIX 5.3 2.2 you have to correct a bug in /usr/include/stdlib.h:
#change "extern	void free(char *str);"
#to     "extern void free(void *str);"
#NOTE: This bug is reportedly fixed in DNIX 5.3 2.2.1.
#Should you get fatal errors caused by harmless pointer-type mismatches,
#like between signed and unsigned char, just remove -X7.
dnix5r3ansi:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with DNIX 5.3...'
	@echo 'with ANSI C Honey DanBer UUCP'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DDIAB -DHDBUUCP -DNAP -DRDCHK -DDIRENT \
	-DCK_ANSILIBS -DCK_CURSES -DRENAME -O -X7 -X9 $(KFLAGS)" \
	"LIBS= -lcurses"

#DIAB DS90 with DNIX 5.3 2.2 or later, with HDB UUCP, nap() and rdchk(),
# + TCP/IP, ANSI C compilation and libraries.
#Should you get fatal errors caused by harmless pointer-type mismatches,
#like between signed and unsigned char, just remove -X7.
dnix5r3ansinet:
	@echo 'Making C-Kermit $(CKVER) for DIAB DS90 with DNIX 5.3...'
	@echo 'with ANSI C Honey DanBer UUCP'
	$(MAKE) wermit \
	"CFLAGS = -DSVR3 -DDIAB -DHDBUUCP -DNAP -DRDCHK -DDIRENT \
	-DTCPSOCKET -DCK_ANSILIBS -DCK_CURSES -DRENAME -O -X7 -X9 $(KFLAGS) \
	-I/usr/include/bsd" "LIBS= -ln -lcurses"

#Ridge 32 with ROS 3.2
ridge32:
	@echo 'Making C-Kermit $(CKVER) Ridge 32 ROS 3.2'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DNOFILEH -DNODEBUG -DNOTLOG $(KFLAGS) -i -O" \
	"LNKFLAGS = -i"

#Altos 486, 586, or 986 with Xenix 3.0
altos:
	@echo 'Making C-Kermit $(CKVER) for Altos x86 with Xenix 3.0...'
	$(MAKE) wermit \
	"CFLAGS= -DATTSV -DA986 -DNODEBUG -DNOTLOG $(KFLAGS) -i -O" \
	"LNKFLAGS= -i"

#Altos 986 with Xenix 3.0, as above, but command-line only, minimal size.
#For systems with small memories.  It might also be necessary to chop certain
#modules up into smaller pieces, e.g. ckuus3-6, because of symbol table
#overflow.   If this makefile is too big or complex for the Altos, compile
#and link by hand or write shell scripts.
altosc:
	@echo 'Making C-Kermit $(CKVER) for Altos x86 Xenix 3.0, remote...'
	$(MAKE) wermit \
	"CFLAGS= -DATTSV -DA986 -DNODEBUG -DNOTLOG -DNOSCRIPT -DNODIAL \
	-DNOCSETS -DNOANSI -DNOMSEND -DNOSPL -DNOICP $(KFLAGS) -Mm -O" \
	"LNKFLAGS= -Mm -s"

#Altos 986 with Xenix 3.0, as above, but interactive only, minimal size.
altosi:
	@echo 'Making C-Kermit $(CKVER) for Altos x86 Xenix 3.0, local...'
	$(MAKE) wermit \
	"CFLAGS= -DATTSV -DA986 -DNODEBUG -DNOTLOG -DNOSCRIPT -DNODIAL \
	-DNOCSETS -DNOANSI -DNOMSEND -DNOSPL -DNOCMDL -DNOFRILLS -DNOHELP \
	-DNOSETKEY $(KFLAGS) -Mm -O" "LNKFLAGS= -Mm -s"

# Altos ACS68000 68000 System, UNIX System 3 Release 2, 512k memory.
# also needs getcwd() external function; see ckuins.txt file.
# also, sys/types.h needed modifying:
#   #ifdef __SYS_TYPES_H__, #define ..., #endif
# also, ckuus2.c MUST be compiled NOOPT else symbol table is destroyed!
# Submission by Robert Weiner/Programming Plus, [email protected].
#
altos3:
	@echo 'Making C-Kermit $(CKVER) for Altos ACS68k UNIX System III'
	$(MAKE) ckuus2.$(EXT) "CFLAGS = -DATTSV -DNOCSETS -DNOSETKEY -DNOJC \
	-DNODIAL -DDCLPOPEN -DNOSCRIPT -DNOHELP $(KFLAGS) -i"
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -DNOCSETS -DNOSETKEY -DNOJC \
	-DNODIAL -DDCLPOPEN -DNOSCRIPT -DNOHELP $(KFLAGS) -i -O" \
	"LNKFLAGS = -i" "LIBS = getcwd.$(EXT)"

#MINIX - Original PC version with 64K+64K limit.
# Reportedly, the linker (asld) can run out of space while linking.  The only
# way around this is to make a copy of libc.a from which all modules that are
# not used by Kermit are removed.  If you have trouble compiling or running
# wart, "touch wart".  If that doesn't help, "touch ckcpro.c".
# The version configured below has no interactive command parser.
# If you can build this version successfully, maybe there will be room for
# a minimal interactive command parser too; try replacing -DNOICP with
# -DNOSPL, plus every other -DNOxxx flag there is, except for -DNOICP
# (see ckccfg.txt).
minix:
	@echo 'Making C-Kermit $(CKVER) for MINIX, no command parser...'
	@echo 'TOTALLY UNTESTED!'
	$(MAKE) wermit EXT=s \
	"CFLAGS= -DV7 -DMINIX -i -D_MINIX -D_POSIX_SOURCE \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t -DSIG_V \
	-DNOXMIT -DNOMSEND -DNOFRILLS -DNODIAL -DNOHELP -DNODEBUG -DNOTLOG \
	-DNOSCRIPT -DNOCSETS -DNOICP -DNOSETKEY $(KFLAGS)" \
	"LNKFLAGS= -i -T"

#MINIX - PC version with 64K+64K limit, new (as yet unreleased) ACK 2.0 beta C
#compiler, which outputs .o object files, rather than .s.  But 'make' still
#expects .s files, so must be patched to use .o.  Tested on Minix 1.5.10.
minix15:
	@echo 'Making C-Kermit $(CKVER) for MINIX (new ACK 2.0 compiler),'
	@echo 'no command parser...  TOTALLY UNTESTED!'
	$(MAKE) wermit \
	"CFLAGS= -DV7 -DMINIX -i -D_MINIX -D_POSIX_SOURCE \
	-DPID_T=pid_t -DUID_T=uid_t -DGID_T=gid_t -DSIG_V -DNODIAL \
	-DNOHELP -DNODEBUG -DNOTLOG -DNOSCRIPT -DNOCSETS -DNOICP $(KFLAGS)" \
	"LNKFLAGS= -i -T"

#MINIX3 - MINIX 3.0 (no VM) - May-Aug 2005 (not sure if this ever worked...)
minix3:
	@echo 'Making C-Kermit $(CKVER) for MINIX3...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DPOSIX -DNOUUCP -DNOLEARN $(KFLAGS) -DMINIX2 \
	-DMINIX3 -DNO_PARAM_H -DNOSYSLOG -DNOGETUSERSHELL \
	-DNOINITGROUPS -DNOFTRUNCATE -DNOARROWKEYS -DDNOREALPATH \
	-DTCPSOCKET -DNOTIMEZONE -DNOFTP -DNO_DNS_SRV -O"

#MINIX315 - MINIX 3 1.5 - January 2010
minix315:
	@echo 'Making C-Kermit $(CKVER) for Minix 3 1.5...'
	$(MAKE) wermit KTARGET=$${KTARGET:-$(@)} \
	"CFLAGS= -DMINIX315 -DPOSIX -DNOUUCP -DNOJC -DNOLEARN $(KFLAGS) \
	-DHAVE_OPENPTY -DNO_PARAM_H -DNOSYSLOG -DNOGETUSERSHELL \
	-DSYSTIMEH -DNOINITGROUPS -DNOFTRUNCATE -DNOARROWKEYS -DNOREALPATH \
	-DTCPSOCKET -DNOTIMEZONE -DNO_DNS_SRV -DNOFTP -O"

#PFU Compact A Series UNIX System V R3, SX/A TISP V10/L50 (Japan)
#Maybe the -i link option should be removed?
sxae50:
	@echo 'Making C-Kermit $(CKVER) for PFU SX/A V10/L50...'
	$(MAKE) xermit \
	"CFLAGS= -DSVR3 -DDIRENT -DsxaE50 -DTCPSOCKET $(KFLAGS) -i -O" \
	"LNKFLAGS= "

#Tektronix 6130, 4319, 4301, etc, with UTek OS, /usr/spool/uucp/LCK./...
#The models that support hardware flow control.
utek:
	@echo 'Making C-Kermit $(CKVER) for 4.2BSD/UTek, hardware flow control'
	$(MAKE) wermit \
	"CFLAGS= -O -DLCKDIR -DBSD4 -DTCPSOCKET \
	-DUTEK -DDCLPOPEN -DLOCK_DIR=\\\"/usr/spool/uucp/LCK.\\\" \
	-DTRMBUFL=2048 -DCK_DTRCTS $(KFLAGS)"

#Tektronix 4315, 4316, 4317 with UTek OS, /usr/spool/uucp/LCK./...
#The models that do not fully support hardware flow control.
uteknohwfc:
	@echo 'Making C-Kermit $(CKVER) for 4.2BSD/UTek, no h/w flow control'
	$(MAKE) wermit \
	"CFLAGS= -O -DLCKDIR -DBSD4 -DTCPSOCKET \
	-DUTEK -DDCLPOPEN -DLOCK_DIR=\\\"/usr/spool/uucp/LCK.\\\" \
	-DTRMBUFL=2048 $(KFLAGS)"

#Tektronix XD88 with  UTekV OS
utekvr3:
	@echo 'Making C-Kermit $(CKVER) for Tektronix XD88 UTekV R3...'
	$(MAKE) wermit \
	"CFLAGS= -DSVR3 -DDIRENT -DHDBUUCP \
	-DTCPSOCKET -DSYSUTIMEH -DCK_CURSES $(KFLAGS) -O" \
	"LIBS= -lcurses" "LNKFLAGS= -s"

#Perkin-Elmer 3200 Xelos R02 or earlier
ccop1:
	@echo 'Making C-Kermit $(CKVER) for Xelos & Public Domain Dirent calls'
	@echo 'or System V R2 or earlier...'
	$(MAKE) wermit \
	"CFLAGS = -DATTSV -Dvoid=int -DDIRENT -DCK_CURSES \
	$(KFLAGS) -O" "LNKFLAGS =" "LIBS= -lcurses -ltermlib"

#Encore, UMAX 4.3 (BSD) but without acucntrl program.
encore:
	$(MAKE) "MAKE=$(MAKE)" umax43 "KFLAGS=$(KFLAGS)"

#Encore, as above, but with curses file transfer display included.
encorec:
	$(MAKE) "MAKE=$(MAKE)" umax43 "KFLAGS=-DCK_CURSES $(KFLAGS)" \
	"LIBS= -lcurses -ltermcap"

#Encore, UMAX 4.3 (BSD) but without acucntrl program.
umax43:
	@echo Making C-Kermit $(CKVER) for Encore UMAX 4.3...
	$(MAKE) "MAKE=$(MAKE)" PARALLEL=4 xermit \
	"CFLAGS= -DBSD43 -DENCORE -DTCPSOCKET $(KFLAGS) -O"

#Encore, UMAX 4.2 (BSD)
umax42:
	@echo Making C-Kermit $(CKVER) for Encore UMAX 4.2...
	$(MAKE) "MAKE=$(MAKE)" PARALLEL=4 xermit \
	"CFLAGS= -DBSD4 -DENCORE -DTCPSOCKET $(KFLAGS) -O"

#Encore 88K UMAX 5.3 with TCP/IP support
encore88k:
	@echo 'Making C-Kermit $(CKVER) for Encore 88K UMAX V, TCP/IP...'
	$(MAKE) xermit \
	"CFLAGS = -q ext=pcc -DSVR3 -DTCPSOCKET -DDIRENT \
	-DNOGETID_PROTOS -DHDBUUCP $(KFLAGS) -O" "LNKFLAGS ="

#Encore 88K UMAX 5.3 with TCP/IP support
encore88kgcc:
	@echo 'Making C-Kermit $(CKVER) for Encore 88K UMAX V, TCP/IP, gcc...'
	$(MAKE) xermit CC=gcc CC2=gcc \
	"CFLAGS = -DSVR3 -DTCPSOCKET -DDIRENT \
	-DNOGETID_PROTOS -DHDBUUCP $(KFLAGS) -O" "LNKFLAGS ="

#SONY NEWS, NEWS-OS 4.01C
sonynews:
	@echo Making C-Kermit $(CKVER) for SONY NEWS-OS 4.01C...
	$(MAKE) xermit "CFLAGS= -DBSD43 -DACUCNTRL -DTCPSOCKET -O"

#Run Lint on this mess for selected versions.
#These are pretty much obsolete since ANSI C / gcc.
lintsun:
	@echo 'Running Lint on C-Kermit $(CKVER) sources for SunOS version...'
	lint -x -DSUNOS4 -DDIRENT -DTCPSOCKET -DSAVEDUID \
	ck[cu]*.c > ckuker.lint.sun

lintbsd:
	@echo 'Running Lint on C-Kermit $(CKVER) sources for BSD 4.2 version..'
	lint -x -DBSD4 -DTCPSOCKET ck[cu]*.c > ckuker.lint.bsd42

lints5:
	@echo 'Running Lint on C-Kermit $(CKVER) sources for Sys V version...'
	lint -x -DATTSV ck[cu]*.c > ckuker.lint.s5

#Who remembers TECO?
love:
	@echo 'Not war?'

ckucmd.c

#include "ckcsym.h"

char *cmdv = "Command package 9.0.168, 12 March 2010";

/*  C K U C M D  --  Interactive command package for Unix  */

/* (In reality, it's for all platforms, not just Unix) */

/*
  Author: Frank da Cruz ([email protected]),
  Columbia University Academic Information Systems, New York City.

  Copyright (C) 1985, 2010,
    Trustees of Columbia University in the City of New York.
    All rights reserved.  See the C-Kermit COPYING.TXT file or the
    copyright text in the ckcmai.c module for disclaimer and permissions.
*/

#define TOKPRECHECK

#define DOCHKVAR

/* Command-terminal-to-C-Kermit character mask */

#ifdef OS2				/* K95 */
int cmdmsk = 255;			/* (always was 255) */
#else					/* All others... */
int cmdmsk = 255;			/* 31 Dec 2000 (was 127) */
#endif /* OS2 */

#ifdef BS_DIRSEP			/* Directory separator is backslash */
#undef BS_DIRSEP
#endif /* BS_DIRSEP */

#ifdef OS2
#define BS_DIRSEP
#endif /* BS_DIRSEP */

#define CKUCMD_C

#include "ckcdeb.h"                     /* Formats for debug(), etc. */
#include "ckcker.h"			/* Needed for BIGBUFOK definition */
#include "ckcnet.h"			/* Needed for server-side Telnet */
#include "ckucmd.h"			/* Needed for everything */
#include "ckuusr.h"                     /* Needed for prompt length */

#ifndef NOARROWKEYS
#ifndef NOESCSEQ
#ifdef VMSORUNIX
#define USE_ARROWKEYS			/* Use arrow keys for command recall */
#endif /* VMSORUNIX */
#endif /* NOESCSEQ */
#endif /* NOARROWKEYS */

#undef CKUCMD_C

_PROTOTYP( int unhex, (char) );
_PROTOTYP( static VOID cmdclrscn, (void) );

#ifdef CKLEARN
_PROTOTYP( VOID learncmd, (char *) );
#endif /* CKLEARN */

static char *moname[] = {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};

struct keytab cmonths[] = {
  { "april",     4, 0 },
  { "august",    8, 0 },
  { "december", 12, 0 },
  { "february",  2, 0 },
  { "january",   1, 0 },
  { "july",      7, 0 },
  { "june",      6, 0 },
  { "march",     3, 0 },
  { "may",       5, 0 },
  { "november", 11, 0 },
  { "october",  10, 0 },
  { "september", 9, 0 }
};

#ifndef NOICP     /* The rest only if interactive command parsing selected */

#ifndef NOSPL
_PROTOTYP( int chkvar, (char *) );
extern int askflag, echostars;
#endif /* NOSPL */

#ifdef CKROOT
extern int ckrooterr;
#endif /* CKROOT */

#ifdef IKSD
extern int inserver;
#endif /* IKSD */

int cmfldflgs = 0;			/* Flags for cmfld() */
int cmkwflgs = 0;			/* Flags from last keyword parse */
static int nomsg = 0;
static int blocklvl = 0;		/* Block nesting level */
static int linebegin = 0;		/* Flag for at start of a line */
static int quoting = 1;			/* Quoting is allowed */
static int swarg = 0;			/* Parsing a switch argument */
static int xcmfdb = 0;			/* Flag for parsing chained fdbs... */
static int chsrc = 0;			/* Source of character, 1 = tty */
static int newcmd = 0;			/* See addcmd() */

#ifdef BS_DIRSEP
static int dirnamflg = 0;
#endif /* BS_DIRSEP */

/*
Modeled after the DECSYSTEM-20 command parser (the COMND JSYS), RIP. Features:

 . parses and verifies keywords, filenames, text strings, numbers, other data
 . displays appropriate menu or help message when user types "?"
 . does keyword and filename completion when user types ESC or TAB
 . does partial keyword and filename completion
 . accepts any unique abbreviation for a keyword
 . allows keywords to have attributes, like "invisible" and "abbreviation"
 . can supply defaults for fields omitted by user
 . provides command retry and recall
 . provides character, word, and line deletion (but only from the end)
 . accepts input from keyboard, command files, macros, or redirected stdin
 . allows for full or half duplex operation, character or line input
 . allows \-escapes for special characters
 . allows specification of a user exit to expand variables, etc.
 . settable prompt, protected from deletion, dynamically re-evaluated each time
 . allows chained parse functions.

Functions:
 cmsetp - Set prompt (cmprom is prompt string)
 cmsavp - Save current prompt
 cmgetp = Get current prompt
 prompt - Issue prompt
 cmini  - Clear the command buffer (before parsing a new command)
 cmres  - Reset command buffer pointers (before reparsing)
 cmkey  - Parse a keyword or token (also cmkey2)
 cmswi  - Parse a switch
 cmnum  - Parse a number
 cmifi  - Parse an input file name
 cmofi  - Parse an output file name (also cmifip, cmifi2, ...)
 cmdir  - Parse a directory name (also cmdirp)
 cmfld  - Parse an arbitrary field
 cmtxt  - Parse a text string
 cmdate - Parse a date-time string
 cmcfm  - Parse command confirmation (end of line)
 cmfdb  - Parse any of a list of the foregoing (chained parse functions)

Return codes:
 -9: like -2 except this module already printed the error message
 -3: no input provided when required
 -2: input was invalid (e.g. not a number when a number was required)
 -1: reparse required (user deleted into a preceding field)
  0 or greater: success
See individual functions for greater detail.

Before using these routines, the caller should #include "ckucmd.h" and set the
program's prompt by calling cmsetp().  If the file parsing functions cmifi,
cmofi, or cmdir are to be used, this module must be linked with a ck?fio file
system support module for the appropriate system, e.g. ckufio for Unix.  If
the caller puts the terminal in character wakeup ("cbreak") mode with no echo,
then these functions will provide line editing -- character, word, and line
deletion, as well as keyword and filename completion upon ESC and help
strings, keyword, or file menus upon '?'.  If the caller puts the terminal
into character wakeup/noecho mode, care should be taken to restore it before
exit from or interruption of the program.  If the character wakeup mode is not
set, the system's own line editor may be used.

NOTE: Contrary to expectations, many #ifdef's have been added to this module.
Any operation requiring an #ifdef (like clear screen, get character from
keyboard, erase character from screen, etc) should eventually be turned into a
call to a function that is defined in ck?tio.c, but then all the ck?tio.c
modules would have to be changed...
*/

/* Includes */

#include "ckcker.h"
#include "ckcasc.h"			/* ASCII character symbols */
#include "ckucmd.h"                     /* Command parsing definitions */

#ifdef OSF13
#ifdef CK_ANSIC
#ifdef _NO_PROTO
#undef _NO_PROTO
#endif /* _NO_PROTO */
#endif /* CK_ANSIC */
#endif /* OSF13 */

#ifndef HPUXPRE65
#include <errno.h>			/* Error number symbols */
#else
#ifndef ERRNO_INCLUDED
#include <errno.h>			/* Error number symbols */
#endif	/* ERRNO_INCLUDED */
#endif	/* HPUXPRE65 */

#ifdef OS2
#ifndef NT
#define INCL_NOPM
#define INCL_VIO			/* Needed for ckocon.h */
#include <os2.h>
#undef COMMENT
#else
#define APIRET ULONG
#include <windows.h>
#endif /* NT */
#include "ckocon.h"
#include <io.h>
#endif /* OS2 */

#ifdef OSK
#define cc ccount			/* OS-9/68K compiler bug */
#endif /* OSK */

#ifdef GEMDOS				/* Atari ST */
#ifdef putchar
#undef putchar
#endif /* putchar */
#define putchar(x) conoc(x)
#endif /* GEMDOS */

#ifdef CK_AUTODL
extern int cmdadl, justone;
#endif /* CK_AUTODL */

extern int timelimit, nzxopts, nopush, nolocal, xcmdsrc, keepallchars;

#ifdef CKSYSLOG
#ifdef UNIX
#ifdef CKXPRINTF			/* Our printf macro conflicts with */
#undef printf				/* use of "printf" in syslog.h */
#endif /* CKXPRINTF */
#ifdef RTAIX
#include <sys/syslog.h>
#else  /* RTAIX */
#include <syslog.h>
#endif /* RTAIX */
#ifdef CKXPRINTF
#define printf ckxprintf
#endif /* CKXPRINTF */
#endif /* UNIX */
#endif /* CKSYSLOG */

/* Local variables */

static
int psetf = 0,                          /* Flag that prompt has been set */
    cc = 0,                             /* Character count */
    dpx = 0,                            /* Duplex (0 = full) */
    inword = 0;				/* In the middle of getting a word */

char *dfprom = "Command? ";             /* Default prompt */
#ifndef NOLASTFILE
char *lastfile = NULL;			/* Last filespec */
static char *tmplastfile = NULL;	/* Last filespec candidate */
#endif	/* NOLASTFILE */

int cmflgs;                             /* Command flags */
int cmfsav;				/* A saved version of them */

static char pushc = NUL;
static char brkchar = NUL;

#define CMDEFAULT 1023
static char cmdefault[CMDEFAULT+1];

#ifdef DCMDBUF
char *cmdbuf = NULL;			/* Command buffer */
char *savbuf = NULL;			/* Buffer to save copy of command */
char *atmbuf = NULL;			/* Atom buffer - for current field */
char *atxbuf = NULL;			/* For expanding the atom buffer */
char *prevcmd = NULL;
static char *atybuf = NULL;		/* For copying atom buffer */
static char *filbuf = NULL;		/* File name buffer */
static char *cmprom = NULL;		/* Program's prompt */
static char *cmprxx = NULL;		/* Program's prompt, unevaluated */

#ifdef CK_RECALL
/*
  Command recall is available only if we can make profligate use of malloc().
*/
#define R_MAX 10			/* How many commands to save */
int cm_recall = R_MAX;			/* Size of command recall buffer */
int on_recall = 1;			/* Recall feature is ON */
static int no_recall = 0;		/* Recall OFF for this cmd only */
static int force_add = 0;		/* Force cmd into recall buffer */
static int last_recall = -1;		/* Last recall-related action */
/*
  -1 = none
   0 = CR (a command was entered)
   1 = Up
   2 = Down
*/
int in_recall = 0;			/* Recall buffers are init'd */
static int
  current = -1,				/* Pointer to current command */
  rlast = -1;				/* Index of last command in buffer */
static char **recall = NULL;		/* Array of recall buffer pointers */
#endif /* CK_RECALL */
#else  /* !DCMDBUF */
char cmdbuf[CMDBL+4];                   /* Command buffer */
char savbuf[CMDBL+4];                   /* Buffer to save copy of command */
char atmbuf[ATMBL+4];                   /* Atom buffer */
char atxbuf[CMDBL+4];                   /* For expanding the atom buffer */
char prevcmd[CMDBL+4];			/* For displaying the last command */
static char atybuf[ATMBL+4];		/* For copying atom buffer */
static char filbuf[ATMBL+4];		/* File name buffer */
static char cmprom[PROMPTL+1];		/* Program's prompt */
static char cmprxx[PROMPTL+1];		/* Program's prompt, unevaluated */
#endif /* DCMDBUF */

/* Command buffer pointers */

#define PPVLEN VNAML			/* 20080305 Wolfram Sang (was 24) */
char ppvnambuf[PPVLEN+1] = { NUL, NUL };

char * cmbptr = NULL;			/* Current position (for export) */

static char *bp,                        /* Current command buffer position */
    *pp,                                /* Start of current field */
    *np;                                /* Start of next field */

static int ungw,			/* For ungetting words */
    atxn;				/* Expansion buffer (atxbuf) length */

#ifdef OS2
extern int wideresult;
#endif /* OS2 */

extern int cmd_cols, cmd_rows, local, quiet;

#ifdef TNCODE
#ifdef IAC
#undef IAC
#endif /* IAC */
#define IAC 255
#endif /* TNCODE */

_PROTOTYP( static int gtword, (int) );
_PROTOTYP( static int addbuf, (char *) );
_PROTOTYP( static int setatm, (char *, int) );
_PROTOTYP( static VOID cmdnewl, (char) );
_PROTOTYP( static VOID cmdchardel, (void) );
_PROTOTYP( static VOID cmdecho, (char, int) );
_PROTOTYP( static int test, (int, int) );
#ifdef GEMDOS
_PROTOTYP( extern char *strchr, (char *, int) );
#endif /* GEMDOS */

extern char * dftty;

/* The following are for use with chained FDB's */

static int crflag = 0;			/* Carriage return was typed */
static int qmflag = 0;			/* Question mark was typed */
static int esflag = 0;			/* Escape was typed */

/* Directory separator */

#ifdef GEMDOS
static char dirsep = '\\';
#else
#ifdef datageneral
static char dirsep = ':';
#else
#ifdef MAC
static char dirsep = ':';
#else
#ifdef VMS
static char dirsep = '.';
#else
#ifdef STRATUS
static char dirsep = '>';
#else
static char dirsep = '/';		/* UNIX, OS/2, OS-9, Amiga, etc. */
#endif /* STRATUS */
#endif /* VMS */
#endif /* MAC */
#endif /* datageneral */
#endif /* GEMDOS */

/*  H A S N O P A T H  */

/*  Returns 0 if filespec s includes any path segments; 1 if it doesn't. */

int
hasnopath(s) char * s; {
    char * p = NULL;
    if (!s) return(0);
    if (!*s) return(0);
    zstrip(s,&p);
    return(ckstrcmp(s,p,CKMAXPATH,filecase) == 0 ? 1 : 0);
}

/*  C K S P R E A D  --  Print string double-spaced  */

static char * sprptr = NULL;

static char *
ckspread(s) char * s; {
    int n = 0;
    char * p;
    n = strlen(s);
    if (sprptr)
      free(sprptr);
    sprptr = malloc(n + n + 3);
    if (sprptr) {
	p = sprptr;
	while (*s) {
	    *p++ = *s++;
	    *p++ = SP;
	}
	*p = NUL;
    }
    return(sprptr ? sprptr : "");
}

/*  T E S T  --  Bit test  */

static int
test(x,m) int x, m; { /*  Returns 1 if any bits from m are on in x, else 0  */
    return((x & m) ? 1 : 0);
}

/*  K W D H E L P  --  Given a keyword table, print keywords in columns.  */
/*
  Call with:
    s     - keyword table
    n     - number of entries
    pat   - pattern (left substring) that must match for each keyword
    pre   - prefix to add to each keyword
    post  - suffix to add to each keyword
    off   - offset on first screenful, allowing room for introductory text
    xhlp  - 1 to print any CM_INV keywords that are not also abbreviations.
            2 to print CM_INV keywords if CM_HLP also set
            4 if it's a switch table (to show ':' if CM_ARG)

  Arranges keywords in columns with width based on longest keyword.
  Does "more?" prompting at end of screen.
  Uses global cmd_rows and cmd_cols for screen size.
*/
VOID
kwdhelp(s,n,pat,pre,post,off,xhlp)
    struct keytab s[]; int n, off, xhlp; char *pat, *pre, *post;
/* kwdhelp */ {

    int width = 0;
    int cc;
    int cols, height, i, j, k, lc, n2 = 0;
    char *b = NULL, *p, *q;
    char *pa, *px;
    char **s2 = NULL;
    char *tmpbuf = NULL;

    cc = strlen(pat);

    if (!s) return;			/* Nothing to do */
    if (n < 1) return;			/* Ditto */
    if (off < 0) off = 0;		/* Offset for first page */
    if (!pre) pre = "";			/* Handle null string pointers */
    if (!post) post = "";
    lc = off;				/* Screen-line counter */

    if (xhlp & 4)			/* For switches */
      tmpbuf = (char *)malloc(TMPBUFSIZ+1);

    if ((s2 = (char **) malloc(n * sizeof(char *)))) {
	for (i = 0; i < n; i++) {	/* Find longest keyword */
	    s2[i] = NULL;
	    if (ckstrcmp(s[i].kwd,pat,cc,0))
	      continue;

	    if (s[i].flgs & CM_PSH	/* NOPUSH or nopush screening */
#ifndef NOPUSH
		&& nopush
#endif /* NOPUSH */
		)
	      continue;
	    if (s[i].flgs & CM_LOC	/* NOLOCAL or nolocal screening */
#ifndef NOLOCAL
		&& nolocal
#endif /* NOLOCAL */
		)
	      continue;

	    if (s[i].flgs & CM_INV) {
#ifdef COMMENT
/* This code does not show invisible keywords at all except for "help ?" */
/* and then only help topics (CM_HLP) in the top-level keyword list. */

		if ((xhlp & 2) == 0)
		  continue;
		else if ((s[i].flgs & CM_HLP) == 0)
		  continue;
#else
/* This code shows invisible keywords that are not also abbreviations when */
/* ? was typed AFTER the beginning of the field so the user can find out */
/* what they are and (for example) why completion doesn't work at this point */

		if (s[i].flgs & CM_ABR)
		  continue;
		else if ((xhlp & 3) == 0)
		  continue;
		else if ((xhlp & 2) && ((s[i].flgs & CM_HLP) == 0))
		  continue;
#endif /* COMMENT */
	    }
	    j = strlen(s[i].kwd);
	    if (!(xhlp & 4) || !tmpbuf) { /* Regular keyword table */
		s2[n2++] = s[i].kwd;	/* Copy pointers to visible ones */
	    } else {			/* Switches */
		ckmakmsg(tmpbuf,	/* Make a copy that shows ":" if */
			 TMPBUFSIZ,	/* the switch takes an argument. */
			 s[i].kwd,
			 (s[i].flgs & CM_ARG) ? ":" : "",
			 NULL,
			 NULL
			 );
		makestr(&(s2[n2]),tmpbuf);
		if (s[i].flgs & CM_ARG) j++;
		n2++;
	    }
	    if (j > width)
	      width = j;
	}
	/* Column width */
	n = n2;
    }
    if (s2 && (b = (char *) malloc(cmd_cols + 1))) { /* Make a line buffer   */
	char * bx;
	bx = b + cmd_cols;
	width += (int)strlen(pre) + (int)strlen(post) + 2;
	cols = cmd_cols / width;	/* How many columns? */
	if (cols < 1) cols = 1;
	height = n / cols;		/* How long is each column? */
	if (n % cols) height++;		/* Add one for remainder, if any */

	for (i = 0; i < height; i++) {	    /* Loop for each row */
	    for (j = 0; j < cmd_cols; j++)  /* First fill row with blanks */
	      b[j] = SP;
	    for (j = 0; j < cols; j++) {    /* Loop for each column in row */
		k = i + (j * height);       /* Index of next keyword */
		if (k < n) {		    /* In range? */
		    pa = pre;
		    px = post;
		    p = s2[k];		    /* Point to verb name */
		    q = b + (j * width) + 1; /* Where to copy it to */
		    while ((q < bx) && (*q++ = *pa++)) ; /* Copy prefix */
		    q--;		                 /* Back up over NUL */
		    while ((q < bx) && (*q++ = *p++)) ;	 /* Copy filename */
		    q--;		                 /* Back up over NUL */
		    while ((q < bx) && (*q++ = *px++)) ; /* Copy suffix */
		    if (j < cols - 1) {
			q--;
			*q = SP;	/* Replace the space */
		    }
		}
	    }
	    p = b + cmd_cols - 1;	/* Last char in line */
	    while (*p-- == SP) ;	/* Trim */
	    *(p+2) = NUL;
	    printf("%s\n",b);		/* Print the line */
	    if (++lc > (cmd_rows - 2)) { /* Screen full? */
		if (!askmore())		/* Do more-prompting... */
		  goto xkwdhelp;
		else
		  lc = 0;
	    }
	}
	/* printf("\n"); */		/* Blank line at end of report */
    } else {				/* Malloc failure, no columns */
	for (i = 0; i < n; i++) {
	    if (s[i].flgs & CM_INV)	/* Use original keyword table */
	      continue;			/* skipping invisible entries */
	    printf("%s%s%s\n",pre,s[i].kwd,post);
	    if (++lc > (cmd_rows - 2)) { /* Screen full? */
		if (!askmore())		/* Do more-prompting... */
		  goto xkwdhelp;
		else
		  lc = 0;
	    }
	}
    }
  xkwdhelp:
    if (xhlp & 4) {
	if (tmpbuf) free((char *)tmpbuf);
	for (i = 0; i < n; i++)
	  if (s2[i]) free(s2[i]);
    }
    if (s2) free(s2);			/* Free array copy */
    if (b) free(b);			/* Free line buffer */
    return;
}

/*  X F I L H E L P  --  Given a file list, print names in columns.  */
/*
  Call with:
    n     - number of entries
    pre   - prefix to add to each filename
    post  - suffix to add to each filename
    off   - offset on first screenful, allowing room for introductory text
    cmdirflg - 1 if only directory names should be listed, 0 to list all files
    fs    - call fileselect() to decide whether to include each file.
    The rest of the args are the same as for fileselect().

  Arranges filenames in columns with width based on longest filename.
  Does "more?" prompting at end of screen.
  Uses global cmd_rows and cmd_cols for screen size.
*/

int
#ifdef CK_ANSIC
xfilhelp(
    int n, char *pre, char *post, int off, int cmdirflag,
    int fs, char *sa, char *sb, char *sna, char *snb,
    CK_OFF_T minsiz, CK_OFF_T maxsiz,
    int nbu, int nxlist,
    char ** xlist
)
#else
xfilhelp(n,pre,post,off,cmdirflg,
	 fs,sa,sb,sna,snb,minsiz,maxsiz,nbu,nxlist,xlist)
    int n, off; char *pre, *post; int cmdirflg;
    int fs; char *sa,*sb,*sna,*snb; CK_OFF_T minsiz,maxsiz;
    int nbu,nxlist; char ** xlist;
#endif	/* CK_ANSIC */
 {
    char filbuf[CKMAXPATH + 1];		/* Temp buffer for one filename */
    int width = 0;
    int cols, height, i, j, k, lc, n2 = 0, rc = 0, itsadir = 0;
    char *b = NULL, *p, *q;
    char *pa, *px;
    char **s2 = NULL;
#ifdef VMS
    char * cdp = zgtdir();
#endif /* VMS */

    if (n < 1) return(0);
    if (off < 0) off = 0;		/* Offset for first page */
    if (!pre) pre = "";			/* Handle null string pointers */
    if (!post) post = "";

    lc = off;				/* Screen-line counter */

    if ((s2 = (char **) malloc(n * sizeof(char *)))) {
	for (i = 0; i < n; i++) {	/* Loop through filenames */
	    itsadir = 0;
	    s2[i] = NULL;		/* Initialize each pointer to NULL */
	    znext(filbuf);		/* Get next filename */
	    if (!filbuf[0])		/* Shouldn't happen */
	      break;
#ifdef COMMENT
	    itsadir = isdir(filbuf);	/* Is it a directory? */
	    if (cmdirflg && !itsadir)	/* No, listing directories only? */
	      continue;			/* So skip this one. */
#endif /* COMMENT */
	    if (fs) if (fileselect(filbuf,
			   sa,sb,sna,snb,
			   minsiz,maxsiz,nbu,nxlist,xlist) < 1) {
                    continue;
	    }
#ifdef VMS
	    ckstrncpy(filbuf,zrelname(filbuf,cdp),CKMAXPATH);
#endif /* VMS */
	    j = strlen(filbuf);
#ifndef VMS
	    if (itsadir && j < CKMAXPATH - 1 && j > 0) {
		if (filbuf[j-1] != dirsep) {
		    filbuf[j++] = dirsep;
		    filbuf[j] = NUL;
		}
	    }
#endif /* VMS */
	    if (!(s2[n2] = malloc(j+1))) {
		printf("?Memory allocation failure\n");
		rc = -9;
		goto xfilhelp;
	    }
	    if (j <= CKMAXPATH) {
		strcpy(s2[n2],filbuf);
		n2++;
	    } else {
		printf("?Name too long - %s\n", filbuf);
		rc = -9;
		goto xfilhelp;
	    }
	    if (j > width)		/* Get width of widest one */
	      width = j;
	}
	n = n2;				/* How many we actually got */
    }
    sh_sort(s2,NULL,n,0,0,filecase);	/* Alphabetize the list */

    rc = 1;
    if (s2 && (b = (char *) malloc(cmd_cols + 1))) { /* Make a line buffer */
	char * bx;
	bx = b + cmd_cols;
	width += (int)strlen(pre) + (int)strlen(post) + 2;
	cols = cmd_cols / width;	/* How many columns? */
	if (cols < 1) cols = 1;
	height = n / cols;		/* How long is each column? */
	if (n % cols) height++;		/* Add one for remainder, if any */

	for (i = 0; i < height; i++) {	    /* Loop for each row */
	    for (j = 0; j < cmd_cols; j++)  /* First fill row with blanks */
	      b[j] = SP;
	    for (j = 0; j < cols; j++) {    /* Loop for each column in row */
		k = i + (j * height);       /* Index of next filename */
		if (k < n) {		    /* In range? */
		    pa = pre;
		    px = post;
		    p = s2[k];		               /* Point to filename */
		    q = b + (j * width) + 1;             /* and destination */
		    while ((q < bx) && (*q++ = *pa++)) ; /* Copy prefix */
		    q--;		                 /* Back up over NUL */
		    while ((q < bx) && (*q++ = *p++)) ;	 /* Copy filename */
		    q--;		                 /* Back up over NUL */
		    while ((q < bx) && (*q++ = *px++)) ; /* Copy suffix */
		    if (j < cols - 1) {
			q--;
			*q = SP;	/* Replace the space */
		    }
		}
	    }
	    p = b + cmd_cols - 1;	/* Last char in line */
	    while (*p-- == SP) ;	/* Trim */
	    *(p+2) = NUL;
	    printf("%s\n",b);		/* Print the line */
	    if (++lc > (cmd_rows - 2)) { /* Screen full? */
		if (!askmore()) {	/* Do more-prompting... */
		    rc = 0;
		    goto xfilhelp;
		} else
		  lc = 0;
	    }
	}
	printf("\n");			/* Blank line at end of report */
	goto xfilhelp;
    } else {				/* Malloc failure, no columns */
	for (i = 0; i < n; i++) {
	    znext(filbuf);
	    if (!filbuf[0]) break;
	    printf("%s%s%s\n",pre,filbuf,post);
	    if (++lc > (cmd_rows - 2)) { /* Screen full? */
		if (!askmore()) {	 /* Do more-prompting... */
		    rc = 0;
		    goto xfilhelp;
		} else lc = 0;
	    }
	}
xfilhelp:
	if (b) free(b);
	for (i = 0; i < n2; i++)
	  if (s2[i]) free(s2[i]);
	if (s2) free((char *)s2);
	return(rc);
    }
}

/*
  Simpler front end for xfilhelp() with shorter arg list when no
  file selection is needed.
*/
int
filhelp(n,pre,post,off,cmdirflg) int n, off; char *pre, *post; int cmdirflg; {
    return(xfilhelp(n,pre,post,off,cmdirflg,
		    0,NULL,NULL,NULL,NULL,
		    (CK_OFF_T)0,(CK_OFF_T)0,0,0,(char **)NULL));
}

/*  C M S E T U P  --  Set up command buffers  */

#ifdef DCMDBUF
int
cmsetup() {
    if (!(cmdbuf = malloc(CMDBL + 4))) return(-1);
    if (!(savbuf = malloc(CMDBL + 4))) return(-1);
    savbuf[0] = '\0';
    if (!(prevcmd = malloc(CMDBL + 4))) return(-1);
    prevcmd[0] = '\0';
    if (!(atmbuf = malloc(ATMBL + 4))) return(-1);
    if (!(atxbuf = malloc(CMDBL + 4))) return(-1);
    if (!(atybuf = malloc(ATMBL + 4))) return(-1);
    if (!(filbuf = malloc(ATMBL + 4))) return(-1);
    if (!(cmprom = malloc(PROMPTL + 4))) return(-1);
    if (!(cmprxx = malloc(PROMPTL + 4))) return(-1);
#ifdef CK_RECALL
    cmrini(cm_recall);
#endif /* CK_RECALL */
    return(0);
}
#endif /* DCMDBUF */

/*  C M S E T P  --  Set the program prompt.  */

VOID
cmsetp(s) char *s; {
    if (!s) s = "";
    ckstrncpy(cmprxx,s,PROMPTL);
    psetf = 1;                          /* Flag that prompt has been set. */
}

/*  C M S A V P  --  Save a copy of the current prompt.  */

VOID
#ifdef CK_ANSIC
cmsavp(char s[], int n)
#else
cmsavp(s,n) char s[]; int n;
#endif /* CK_ANSIC */
/* cmsavp */ {
    if (psetf)				/* But not if no prompt is set. */
      ckstrncpy(s,cmprxx,n);
}

char *
cmgetp() {
    return(cmprxx);
}

int
cmgbrk() {
    return(brkchar);
}

int
cmgkwflgs() {
    return(cmkwflgs);
}

/*  P R O M P T  --  Issue the program prompt.  */

VOID
prompt(f) xx_strp f; {
    char *sx, *sy; int n;
#ifdef CK_SSL
    extern int ssl_active_flag, tls_active_flag;
#endif /* CK_SSL */
#ifdef OS2
    extern int display_demo;

    /* If there is a demo screen to be displayed, display it */
    if (display_demo && xcmdsrc == 0) {
        demoscrn(VCMD);
        display_demo = 0;
    }
#endif /* OS2 */

    if (psetf == 0)			/* If no prompt set, set default. */
      cmsetp(dfprom);

    sx = cmprxx;			/* Unevaluated copy */
    if (f) {				/* If conversion function given */
	sy = cmprom;			/* Evaluate it */
#ifdef COMMENT
	debug(F101,"prompt sx","",sx);
	debug(F101,"prompt sy","",sy);
#endif	/* COMMENT */
	n = PROMPTL;
	if ((*f)(sx,&sy,&n) < 0)	/* If evaluation failed */
	  sx = cmprxx;			/* revert to unevaluated copy */
	else if (!*cmprom)		/* ditto if it came up empty */
	  sx = cmprxx;
	else
	  sx = cmprom;
    } else
      ckstrncpy(cmprom,sx,PROMPTL);
    cmprom[PROMPTL-1] = NUL;
    if (!*sx)				/* Don't print if empty */
      return;

#ifdef OSK
    fputs(sx, stdout);
#else
#ifdef MAC
    printf("%s", sx);
#else
#ifdef IKSD
    if (inserver) {			/* Print the prompt. */
        ttoc(CR);			/* If TELNET Server */
        ttoc(NUL);			/* must folloW CR by NUL */
        printf("%s",sx);
    } else
#endif /* IKSD */
      printf("\r%s",sx);
#ifdef CK_SSL
    if (!(ssl_active_flag || tls_active_flag))
#endif /* CK_SSL */
      fflush(stdout);			/* Now! */
#endif /* MAC */
#endif /* OSK */
}

#ifndef NOSPL
VOID
pushcmd(s) char * s; {			/* For use with IF command. */
    if (!s) s = np;
    ckstrncpy(savbuf,s,CMDBL);		/* Save the dependent clause,  */
    cmres();				/* and clear the command buffer. */
    debug(F110, "pushcmd savbuf", savbuf, 0);
}

VOID
pushqcmd(s) char * s; {			/* For use with ELSE command. */
    char c, * p = savbuf;		/* Dest */
    if (!s) s = np;			/* Source */
    while (*s) {			/* Get first nonwhitespace char */
	if (*s != SP)
	  break;
	else
	  s++;
    }
    if (*s != '{') {			/* If it's not "{" */
	pushcmd(s);			/* do regular pushcmd */
	return;
    }
    while ((c = *s++)) {		/* Otherwise insert quotes */
	if (c == CMDQ)
	  *p++ = CMDQ;
	*p++ = c;
    }
    cmres();				/* and clear the command buffer. */
    debug(F110, "pushqcmd savbuf", savbuf, 0);
}
#endif /* NOSPL */

#ifdef COMMENT
/* no longer used... */
VOID
popcmd() {
    ckstrncpy(cmdbuf,savbuf,CMDBL);	/* Put back the saved material */
    *savbuf = '\0';			/* and clear the save buffer */
    cmres();
}
#endif /* COMMENT */

/*  C M R E S  --  Reset pointers to beginning of command buffer.  */

VOID
cmres() {
    inword = 0;				/* We're not in a word */
    cc = 0;				/* Character count is zero */

/* Initialize pointers */

    pp = cmdbuf;			/* Beginning of current field */
    bp = cmdbuf;			/* Current position within buffer */
    np = cmdbuf;			/* Where to start next field */

    cmfldflgs = 0;
    cmflgs = -5;                        /* Parse not yet started. */
    ungw = 0;				/* Don't need to unget a word. */
}

/*  C M I N I  --  Clear the command and atom buffers, reset pointers.  */

/*
The argument specifies who is to echo the user's typein --
  1 means the cmd package echoes
  0 somebody else (system, front end, terminal) echoes
*/
VOID
cmini(d) int d; {
#ifdef DCMDBUF
    if (!atmbuf)
      if (cmsetup()<0)
	fatal("fatal error: unable to allocate command buffers");
#endif /* DCMDBUF */
#ifdef USE_MEMCPY
    memset(cmdbuf,0,CMDBL);
    memset(atmbuf,0,ATMBL);
#else
    for (bp = cmdbuf; bp < cmdbuf+CMDBL; bp++) *bp = NUL;
    for (bp = atmbuf; bp < atmbuf+ATMBL; bp++) *bp = NUL;
#endif /* USE_MEMCPY */

    *atmbuf = *savbuf = *atxbuf = *atybuf = *filbuf = NUL;
    blocklvl = 0;			/* Block level is 0 */
    linebegin = 1;			/* At the beginning of a line */
    dpx = d;				/* Global copy of the echo flag */
    debug(F101,"cmini dpx","",dpx);
    crflag = 0;				/* Reset flags */
    qmflag = 0;
    esflag = 0;
#ifdef CK_RECALL
    no_recall = 0;			/* Start out with recall enabled */
#endif /* CK_RECALL */
    cmres();				/* Sets bp etc */
    newcmd = 1;				/* See addcmd() */
}

#ifndef NOSPL
/*
  The following bits are to allow the command package to call itself
  in the middle of a parse.  To do this, begin by calling cmpush, and
  end by calling cmpop.  As you can see, this is rather expensive.
*/
#ifdef DCMDBUF
struct cmp {
    int i[5];				/* stack for integers */
    char *c[3];				/* stack for pointers */
    char *b[8];				/* stack for buffer contents */
};
struct cmp *cmp = 0;
#else
int cmp_i[CMDDEP+1][5];			/* Stack for integers */
char *cmp_c[CMDDEP+1][5];		/* for misc pointers */
char *cmp_b[CMDDEP+1][7];		/* for buffer contents pointers */
#endif /* DCMDBUF */

int cmddep = -1;			/* Current stack depth */

int
cmpush() {				/* Save the command environment */
    char *cp;				/* Character pointer */

    if (cmddep >= CMDDEP)		/* Enter a new command depth */
      return(-1);
    cmddep++;
    debug(F101,"&cmpush to depth","",cmddep);

#ifdef DCMDBUF
    /* allocate memory for cmp if not already done */
    if (!cmp && !(cmp = (struct cmp *) malloc(sizeof(struct cmp)*(CMDDEP+1))))
      fatal("cmpush: no memory for cmp");
    cmp[cmddep].i[0] = cmflgs;		/* First do the global ints */
    cmp[cmddep].i[1] = cmfsav;
    cmp[cmddep].i[2] = atxn;
    cmp[cmddep].i[3] = ungw;

    cmp[cmddep].c[0] = bp;		/* Then the global pointers */
    cmp[cmddep].c[1] = pp;
    cmp[cmddep].c[2] = np;
#else
    cmp_i[cmddep][0] = cmflgs;		/* First do the global ints */
    cmp_i[cmddep][1] = cmfsav;
    cmp_i[cmddep][2] = atxn;
    cmp_i[cmddep][3] = ungw;

    cmp_c[cmddep][0] = bp;		/* Then the global pointers */
    cmp_c[cmddep][1] = pp;
    cmp_c[cmddep][2] = np;
#endif /* DCMDBUF */

    /* Now the buffers themselves.  A lot of repititious code... */

#ifdef DCMDBUF
    cp = malloc((int)strlen(cmdbuf)+1);	/* 0: Command buffer */
    if (cp) strcpy(cp,cmdbuf);
    cmp[cmddep].b[0] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(savbuf)+1);	/* 1: Save buffer */
    if (cp) strcpy(cp,savbuf);
    cmp[cmddep].b[1] = cp;
    if (cp == NULL) return(-1);

    cmp[cmddep].b[2] = NULL;

    cp = malloc((int)strlen(atmbuf)+1);	/* 3: Atom buffer */
    if (cp) strcpy(cp,atmbuf);
    cmp[cmddep].b[3] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(atxbuf)+1);	/* 4: Expansion buffer */
    if (cp) strcpy(cp,atxbuf);
    cmp[cmddep].b[4] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(atybuf)+1);	/* 5: Atom buffer copy */
    if (cp) strcpy(cp,atybuf);
    cmp[cmddep].b[5] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(filbuf)+1);	/* 6: File name buffer */
    if (cp) strcpy(cp,filbuf);
    cmp[cmddep].b[6] = cp;
    if (cp == NULL) return(-1);
#else
    cp = malloc((int)strlen(cmdbuf)+1);	/* 0: Command buffer */
    if (cp) strcpy(cp,cmdbuf);
    cmp_b[cmddep][0] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(savbuf)+1);	/* 1: Save buffer */
    if (cp) strcpy(cp,savbuf);
    cmp_b[cmddep][1] = cp;
    if (cp == NULL) return(-1);

    cmp_b[cmddep][2] = NULL;

    cp = malloc((int)strlen(atmbuf)+1);	/* 3: Atom buffer */
    if (cp) strcpy(cp,atmbuf);
    cmp_b[cmddep][3] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(atxbuf)+1);	/* 4: Expansion buffer */
    if (cp) strcpy(cp,atxbuf);
    cmp_b[cmddep][4] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(atybuf)+1);	/* 5: Atom buffer copy */
    if (cp) strcpy(cp,atybuf);
    cmp_b[cmddep][5] = cp;
    if (cp == NULL) return(-1);

    cp = malloc((int)strlen(filbuf)+1);	/* 6: File name buffer */
    if (cp) strcpy(cp,filbuf);
    cmp_b[cmddep][6] = cp;
    if (cp == NULL) return(-1);
#endif /* DCMDBUF */

    cmini(dpx);				/* Initize the command parser */
    return(0);
}

int
cmpop() {				/* Restore the command environment */
    if (cmddep < 0) {
	debug(F100,"&cmpop called from top level","",0);
	return(-1);			/* Don't pop too much! */
    }
#ifdef DCMDBUF
    cmflgs = cmp[cmddep].i[0];		/* First do the global ints */
    cmfsav = cmp[cmddep].i[1];
    atxn = cmp[cmddep].i[2];
    ungw = cmp[cmddep].i[3];

    bp = cmp[cmddep].c[0];		/* Then the global pointers */
    pp = cmp[cmddep].c[1];
    np = cmp[cmddep].c[2];
#else
    cmflgs = cmp_i[cmddep][0];		/* First do the global ints */
    cmfsav = cmp_i[cmddep][1];
    atxn = cmp_i[cmddep][2];
    ungw = cmp_i[cmddep][3];

    bp = cmp_c[cmddep][0];		/* Then the global pointers */
    pp = cmp_c[cmddep][1];
    np = cmp_c[cmddep][2];
#endif /* DCMDBUF */

    /* Now the buffers themselves. */
    /* Note: strncpy(), not ckstrncpy() -- Here we WANT the NUL padding... */

#ifdef DCMDBUF
    if (cmp[cmddep].b[0]) {

	strncpy(cmdbuf,cmp[cmddep].b[0],CMDBL); /* 0: Command buffer */
	free(cmp[cmddep].b[0]);
	cmp[cmddep].b[0] = NULL;
    }
    if (cmp[cmddep].b[1]) {
	strncpy(savbuf,cmp[cmddep].b[1],CMDBL); /* 1: Save buffer */
	free(cmp[cmddep].b[1]);
	cmp[cmddep].b[1] = NULL;
    }
    if (cmp[cmddep].b[3]) {
	strncpy(atmbuf,cmp[cmddep].b[3],ATMBL); /* 3: Atomic buffer! */
	free(cmp[cmddep].b[3]);
	cmp[cmddep].b[3] = NULL;
    }
    if (cmp[cmddep].b[4]) {
	strncpy(atxbuf,cmp[cmddep].b[4],ATMBL); /* 4: eXpansion buffer */
	free(cmp[cmddep].b[4]);
	cmp[cmddep].b[4] = NULL;
    }
    if (cmp[cmddep].b[5]) {
	strncpy(atybuf,cmp[cmddep].b[5],ATMBL); /* 5: Atom buffer copY */
	free(cmp[cmddep].b[5]);
	cmp[cmddep].b[5] = NULL;
    }
    if (cmp[cmddep].b[6]) {
	strncpy(filbuf,cmp[cmddep].b[6],ATMBL); /* 6: Filename buffer */
	free(cmp[cmddep].b[6]);
	cmp[cmddep].b[6] = NULL;
    }
#else
    if (cmp_b[cmddep][0]) {
	strncpy(cmdbuf,cmp_b[cmddep][0],CMDBL); /* 0: Command buffer */
	free(cmp_b[cmddep][0]);
	cmp_b[cmddep][0] = NULL;
    }
    if (cmp_b[cmddep][1]) {
	strncpy(savbuf,cmp_b[cmddep][1],CMDBL); /* 1: Save buffer */
	free(cmp_b[cmddep][1]);
	cmp_b[cmddep][1] = NULL;
    }
    if (cmp_b[cmddep][3]) {
	strncpy(atmbuf,cmp_b[cmddep][3],ATMBL); /* 3: Atomic buffer! */
	free(cmp_b[cmddep][3]);
	cmp_b[cmddep][3] = NULL;
    }
    if (cmp_b[cmddep][4]) {
	strncpy(atxbuf,cmp_b[cmddep][4],ATMBL); /* 4: eXpansion buffer */
	free(cmp_b[cmddep][4]);
	cmp_b[cmddep][4] = NULL;
    }
    if (cmp_b[cmddep][5]) {
	strncpy(atybuf,cmp_b[cmddep][5],ATMBL); /* 5: Atom buffer copY */
	free(cmp_b[cmddep][5]);
	cmp_b[cmddep][5] = NULL;
    }
    if (cmp_b[cmddep][6]) {
	strncpy(filbuf,cmp_b[cmddep][6],ATMBL); /* 6: Filename buffer */
	free(cmp_b[cmddep][6]);
	cmp_b[cmddep][6] = NULL;
    }
#endif /* DCMDBUF */

    cmddep--;				/* Rise, rise */
    debug(F101,"&cmpop to depth","",cmddep);
    return(cmddep);
}
#endif /* NOSPL */

#ifdef COMMENT
VOID					/* Not used */
stripq(s) char *s; {                    /* Function to strip '\' quotes */
    char *t;
    while (*s) {
        if (*s == CMDQ) {
            for (t = s; *t != '\0'; t++) *t = *(t+1);
        }
        s++;
    }
}
#endif /* COMMENT */

/* Convert tabs to spaces, one for one */
VOID
untab(s) char *s; {
    while (*s) {
	if (*s == HT) *s = SP;
	s++;
    }
}

/*  C M N U M  --  Parse a number in the indicated radix  */

/*
 The radix is specified in the arg list.
 Parses unquoted numeric strings in the given radix.
 Parses backslash-quoted numbers in the radix indicated by the quote:
   \nnn = \dnnn = decimal, \onnn = octal, \xnn = Hexadecimal.
 If these fail, then if a preprocessing function is supplied, that is applied
 and then a second attempt is made to parse an unquoted decimal string.
 And if that fails, the preprocessed string is passed to an arithmetic
 expression evaluator.

 Returns:
   -3 if no input present when required,
   -2 if user typed an illegal number,
   -1 if reparse needed,
    0 otherwise, with argument n set to the number that was parsed
*/
/* This is the traditional cmnum() that gets an int */
int
cmnum(xhlp,xdef,radix,n,f) char *xhlp, *xdef; int radix, *n; xx_strp f; {
    CK_OFF_T z = (CK_OFF_T)0, check;
    int x;
    x = cmnumw(xhlp,xdef,radix,&z,f);
    *n = z;
    check = *n;
    if (check != z) {
	printf("?Magnitude of result too large for integer - %s\n",ckfstoa(z));
	return(-9);
    }
    return(x);
}

/*
  This is the new cmnum() that gets a "wide" result, whatever CK_OFF_T
  is defined to be, normally 32 or 64 bits, depending on the platform.
  fdc, 24 Dec 2005.
*/
int
cmnumw(xhlp,xdef,radix,n,f)
    char *xhlp, *xdef; int radix; CK_OFF_T *n; xx_strp f; {
    int x; char *s, *zp, *zq;
#ifdef COMMENT
    char lbrace, rbrace;
#endif /* COMMENT */

    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";

#ifdef COMMENT
    if (cmfldflgs & 1) {
	lbrace = '(';
	rbrace = ')';
    } else {
	lbrace = '{';
	rbrace = '}';
    }
#endif /* COMMENT */

    if (radix != 10 && radix != 8) {	/* Just do bases 8 and 10 */
        printf("cmnum: illegal radix - %d\n",radix);
        return(-2);
    } /* Easy to add others but there has never been a need for it. */
    x = cmfld(xhlp,xdef,&s,(xx_strp)0);
    debug(F101,"cmnum: cmfld","",x);
    if (x < 0) return(x);		/* Parse a field */
    zp = atmbuf;
/*
  Edit 192 - Allow any number field to be braced.  This lets us include
  spaces in expressions, but perhaps more important lets us have user-defined
  functions in numeric fields.
*/
    zp = brstrip(zp);			/* Strip braces */
    if (cmfldflgs & 1 && *zp == '(') {	/* Parens too.. */
	x = (int) strlen(atmbuf);
	if (x > 0) {
	    if (*(atmbuf+x-1) == ')') {
		*(atmbuf+x-1) = NUL;
		zp++;
	    }
	}
    }
    if (chknum(zp)) {			/* Check for number */
	if (radix == 8) {		/* If it's supposed to be octal */
	    zp = ckradix(zp,8,10);	/* convert to decimal */
	    if (!zp) return(-2);
	    if (!strcmp(zp,"-1")) return(-2);
	}
	errno = 0;			/* Got one, we're done. */
        *n = ckatofs(zp);
	if (errno) {
	    perror(zp);
	    return(-9);
	}
	debug(F101,"cmnum 1st chknum ok","",*n);
        return(0);
    } else if ((x = xxesc(&zp)) > -1) {	/* Check for backslash escape */

#ifndef OS2
	*n = x;
#else
	*n = wideresult;
#endif /* OS2 */

	debug(F101,"cmnum xxesc ok","",*n);
	return(*zp ? -2 : 0);
    } else if (f) {			/* If conversion function given */
	zq = atxbuf;			/* Try that */
	atxn = CMDBL;
	if ((*f)(zp,&zq,&atxn) < 0)	/* Convert */
	  return(-2);
	zp = atxbuf;
    }
    debug(F110,"cmnum zp 1",zp,0);
    if (!*zp) zp = xdef;		/* Result empty, substitute default */
    debug(F110,"cmnum zp 2",zp,0);
    if (chknum(zp)) {			/* Check again for decimal number */
	if (radix == 8) {		/* If it's supposed to be octal */
	    zp = ckradix(zp,8,10);	/* convert to decimal */
	    if (!zp) return(-2);
	    if (!strcmp(zp,"-1")) return(-2);
	}
	errno = 0;
        *n = ckatofs(zp);
	if (errno) {
	    perror(zp);
	    return(-9);
	}
	debug(F101,"cmnum 2nd chknum ok","",*n);
        return(0);
#ifndef NOSPL
    }  else if ((x = xxesc(&zp)) > -1) { /* Check for backslash escape */
#ifndef OS2
	*n = x;
#else
	*n = wideresult;
#endif /* OS2 */
	debug(F101,"cmnum xxesc 2 ok","",*n);
	return(*zp ? -2 : 0);
    } else if (f) {			/* Not numeric, maybe an expression */
	char * p;
	p = evala(zp);
	if (chknum(p)) {
	    if (radix == 8) {		/* If it's supposed to be octal */
		zp = ckradix(zp,8,10);	/* convert to decimal */
		if (!zp) return(-2);
		if (!strcmp(zp,"-1")) return(-2);
	    }
	    errno = 0;
	    *n = ckatofs(p);
	    if (errno) {
		perror(p);
		return(-9);
	    }
	    debug(F101,"cmnum exp eval ok","",*n);
	    return(0);
	} else return(-2);
#endif /* NOSPL */
    } else {				/* Not numeric */
	return(-2);
    }
}

#ifdef CKCHANNELIO
extern int z_error;
#endif /* CKCHANNELIO */

/*  C M O F I  --  Parse the name of an output file  */

/*
 Depends on the external function zchko(); if zchko() not available, use
 cmfld() to parse output file names.

 Returns:
   -9 like -2, except message already printed,
   -3 if no input present when required,
   -2 if permission would be denied to create the file,
   -1 if reparse needed,
    0 or 1 if file can be created, with xp pointing to name.
    2 if given the name of an existing directory.
*/
int
cmofi(xhlp,xdef,xp,f) char *xhlp, *xdef, **xp; xx_strp f; {
    int x; char *s, *zq;
#ifdef DOCHKVAR
    int tries;
#endif /* DOCHKVAR */
#ifdef DTILDE
    char *dirp;
#endif /* DTILDE */

    cmfldflgs = 0;

    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";

    if (*xhlp == NUL) xhlp = "Output file";
    *xp = "";

    debug(F110,"cmofi xdef",xdef,0);
    x = cmfld(xhlp,xdef,&s,(xx_strp)0);
    debug(F111,"cmofi cmfld returns",s,x);
    if (x < 0)
      return(x);

    s = brstrip(s);			/* Strip enclosing braces */
    debug(F110,"cmofi 1.5",s,0);

#ifdef DOCHKVAR
    tries = 0;
    {
	char *p = s;
    /*
      This is really ugly.  If we skip conversion the first time through,
      then variable names like \%a will be used as filenames (e.g. creating
      a file called %A in the root directory).  If we DON'T skip conversion
      the first time through, then single backslashes used as directory
      separators in filenames will be misinterpreted as variable lead-ins.
      So we prescan to see if it has any variable references.  But this
      module is not supposed to know anything about variables, functions,
      etc, so this code does not really belong here, but rather it should
      be at the same level as zzstring().
    */
/*
  Hmmm, this looks a lot like chkvar() except it that includes \nnn number
  escapes.  But why?  This makes commands like "mkdir c:\123" impossible.
  And in fact, "mkdir c:\123" creates a directory called "c:{".  What's worse,
  rmdir(), which *does* call chkvar(), won't let us remove it.  So let's at
  least try making cmofi() symmetrical with cmifi()...
*/
#ifdef COMMENT
	char * q;
	while ( (tries == 0) && (p = strchr(p,CMDQ)) ) {
	    q = *(p+1);			/* Char after backslash */
	    if (!q)			/* None, quit */
	      break;
	    if (isupper(q))		/* If letter, convert to lowercase */
	      q = tolower(q);
	    if (isdigit(q)) {		/* If it's a digit, */
		tries = 1;		/* assume it's a backslash code  */
		break;
	    }
	    switch (q) {
	      case CMDQ:		/* Double backslash */
		tries = 1;		/* so call the conversion function */
		break;
	      case '%':			/* Variable or array reference */
	      case '&':			/* must be followed by letter */
		if (isalpha(*(p+2)) || (*(p+2) >= '0' && *(p+2) <= '9'))
		  tries = 1;
		break;
	      case 'm': case 'v': case '$': /* \m(), \v(), \$() */
		if (*(p+2) == '(')
		  if (strchr(p+2,')'))
		    tries = 1;
		break;
	      case 'f':			/* \Fname() */
		if (strchr(p+2,'('))
		  if (strchr(p+2,')'))
		      tries = 1;
		break;
	      case '{':			/* \{...} */
		if (strchr(p+2,'}'))
		  tries = 1;
		break;
	      case 'd': case 'o':	/* Decimal or Octal number */
	        if (isdigit(*(p+2)))
		  tries = 1;
		break;
	      case 'x':			/* Hex number */
		if (isdigit(*(p+2)) ||
		    ((*(p+2) >= 'a' && *(p+2) <= 'f') ||
		     ((*(p+2) >= 'A' && *(p+2) <= 'F'))))
		  tries = 1;
	      default:
		break;
	    }
	    p++;
	}
#else
#ifndef NOSPL
	if (f) {			/* If a conversion function is given */
	    char *s = p;		/* See if there are any variables in */
	    while (*s) {		/* the string and if so, expand them */
		if (chkvar(s)) {
		    tries = 1;
		    break;
		}
		s++;
	    }
	}
#endif /* NOSPL */
#endif /* COMMENT */
    }
#ifdef OS2
o_again:
#endif /* OS2 */
    if (tries == 1)
#endif /* DOCHKVAR */
    if (f) {				/* If a conversion function is given */
	zq = atxbuf;			/* do the conversion. */
	atxn = CMDBL;
	if ((x = (*f)(s,&zq,&atxn)) < 0)
	  return(-2);
	s = atxbuf;
	if (!*s)			/* Result empty, substitute default */
	  s = xdef;
    }
    debug(F111,"cmofi 2",s,x);

#ifdef DTILDE
    dirp = tilde_expand(s);		/* Expand tilde, if any, */
    if (*dirp != '\0') {		/* right in the atom buffer. */
	if (setatm(dirp,1) < 0) {
	    printf("?Name too long\n");
	    return(-9);
	}
    }
    s = atmbuf;
    debug(F110,"cmofi 3",s,0);
#endif /* DTILDE */

    if (iswild(s)) {
        printf("?Wildcards not allowed - %s\n",s);
        return(-2);
    }
    debug(F110,"cmofi 4",s,0);

#ifdef CK_TMPDIR
    /* isdir() function required for this! */
    if (isdir(s)) {
	debug(F110,"cmofi 5: is directory",s,0);
        *xp = s;
	return(2);
    }
#endif /* CK_TMPDIR */

    if (strcmp(s,CTTNAM) && (zchko(s) < 0)) { /* OK to write to console */
#ifdef COMMENT
#ifdef OS2
/*
  We don't try again because we already prescanned the string to see if
  if it contained anything that could be used by zzstring().
*/
	if (tries++ < 1)
	  goto o_again;
#endif /* OS2 */
#endif /* COMMENT */
/*
  Note: there are certain circumstances where zchko() can give a false
  positive, so don't rely on it to catch every conceivable situation in
  which the given output file can't be created.  In other words, we print
  a message and fail here if we KNOW the file can't be created.  If we
  succeed but the file can't be opened, the code that tries to open the file
  has to print a message.
*/
	debug(F110,"cmofi 6: failure",s,0);
#ifdef CKROOT
	if (ckrooterr)
	  printf("?Off Limits: %s\n",s);
	else
#endif /* CKROOT */
	  printf("?Write permission denied - %s\n",s);
#ifdef CKCHANNELIO
	z_error = FX_ACC;
#endif /* CKCHANNELIO */
        return(-9);
    } else {
	debug(F110,"cmofi 7: ok",s,0);
        *xp = s;
        return(x);
    }
}

/*  C M I F I  --  Parse the name of an existing file  */

/*
 This function depends on the external functions:
   zchki()  - Check if input file exists and is readable.
   zxpand() - Expand a wild file specification into a list.
   znext()  - Return next file name from list.
 If these functions aren't available, then use cmfld() to parse filenames.
*/
/*
 Returns
   -4 EOF
   -3 if no input present when required,
   -2 if file does not exist or is not readable,
   -1 if reparse needed,
    0 or 1 otherwise, with:
        xp pointing to name,
        wild = 1 if name contains '*' or '?', 0 otherwise.
*/

#ifdef COMMENT /* This horrible hack has been replaced - see further down */
/*
   C M I O F I  --  Parse an input file OR the name of a nonexistent file.

   Use this when an existing file is wanted (so we get help, completion, etc),
   but if a file of the given name does not exist, the name of a new file is
   accepted.  For example, with the EDIT command (edit an existing file, or
   create a new file).  Returns -9 if file does not exist.  It is up to the
   caller to check creatability.
*/
static int nomsg = 0;
int
cmiofi(xhlp,xdef,xp,wild,f) char *xhlp, *xdef, **xp; int *wild; xx_strp f; {
    int msgsave, x;
    msgsave = nomsg;
    nomsg = 1;
    x = cmifi2(xhlp,xdef,xp,wild,0,NULL,f,0);
    nomsg = msgsave;
    return(x);
}
#endif	/* COMMENT */

int
cmifi(xhlp,xdef,xp,wild,f) char *xhlp, *xdef, **xp; int *wild; xx_strp f; {
    return(cmifi2(xhlp,xdef,xp,wild,0,NULL,f,0));
}
/*
  cmifip() is called when we want to supply a path or path list to search
  in case the filename that the user gives is (a) not absolute, and (b) can't
  be found as given.  The path string can be the name of a single directory,
  or a list of directories separated by the PATHSEP character, defined in
  ckucmd.h.  Look in ckuusr.c and ckuus3.c for examples of usage.
*/
int
cmifip(xhlp,xdef,xp,wild,d,path,f)
    char *xhlp,*xdef,**xp; int *wild, d; char * path; xx_strp f; {
    return(cmifi2(xhlp,xdef,xp,wild,0,path,f,0));
}

/*  C M D I R  --  Parse a directory name  */

/*
 This function depends on the external functions:
   isdir(s)  - Check if string s is the name of a directory
   zchki(s)  - Check if input file s exists and what type it is.
 If these functions aren't available, then use cmfld() to parse dir names.

 Returns
   -9 For all sorts of reasons, after printing appropriate error message.
   -4 EOF
   -3 if no input present when required,
   -2 if out of space or other internal error,
   -1 if reparse needed,
    0 or 1, with xp pointing to name, if directory specified,
*/
int
cmdir(xhlp,xdef,xp,f) char *xhlp, *xdef, **xp; xx_strp f; {
    int wild;
    return(cmifi2(xhlp,xdef,xp,&wild,0,NULL,f,1));
}

/* Like CMDIR but includes PATH search */

int
cmdirp(xhlp,xdef,xp,path,f) char *xhlp, *xdef, **xp; char * path; xx_strp f; {
    int wild;
    return(cmifi2(xhlp,xdef,xp,&wild,0,path,f,1));
}

/*
  cmifi2() is the base filename parser called by cmifi, cmifip, cmdir, etc.
  Use it directly when you also want to parse a directory or device
  name as an input file, as in the DIRECTORY command.  Call with:
    xhlp  -- help message on ?
    xdef  -- default response
    xp    -- pointer to result (in our space, must be copied from here)
    wild  -- flag set upon return to indicate if filespec was wild
    d     -- 0 to parse files, 1 to parse files or directories
             Add 2 to inhibit following of symlinks.
    path  -- search path for files
    f     -- pointer to string processing function (e.g. to evaluate variables)
    dirflg -- 1 to parse *only* directories, 0 otherwise
*/
int
cmifi2(xhlp,xdef,xp,wild,d,path,f,dirflg)
    char *xhlp,*xdef,**xp; int *wild, d; char * path; xx_strp f; int dirflg; {
    extern int recursive, diractive, cdactive, dblquo;
    int i, x, itsadir, xc, expanded = 0, nfiles = 0, children = -1;
    int qflag = 0;
    long y;
    CK_OFF_T filesize;
    char *sp = NULL, *zq, *np = NULL;
    char *sv = NULL, *p = NULL;
#ifdef DTILDE
    char *dirp;
#endif /* DTILDE */

#ifndef NOPARTIAL
#ifndef OS2
#ifdef OSK
    /* This large array is dynamic for OS-9 -- should do for others too... */
    extern char **mtchs;
#else
#ifdef UNIX
    /* OK, for UNIX too */
    extern char **mtchs;
#else
#ifdef VMS
    extern char **mtchs;
#else
    extern char *mtchs[];
#endif /* VMS */
#endif /* UNIX */
#endif /* OSK */
#endif /* OS2 */
#endif /* NOPARTIAL */

    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";

#ifndef NOLASTFILE
    makestr(&tmplastfile,NULL);
#endif	/* NOLASTFILE */
    nzxopts = 0;			/* zxpand() options */
    debug(F101,"cmifi d","",d);
    if (d & 2) {			/* d & 2 means don't follow symlinks */
	d ^= 2;
	nzxopts = ZX_NOLINKS;
    }
    debug(F101,"cmifi nzxopts","",nzxopts);
    cmfldflgs = 0;
    if (path)
      if (!*path)
	path = NULL;
    if (path) {				/* Make a copy we can poke */
	x = strlen(path);
	np = (char *) malloc(x + 1);
	if (np) {
	    strcpy(np, path);
	    path = sp = np;
	}
    }
    debug(F110,"cmifi2 path",path,0);

    ckstrncpy(cmdefault,xdef,CMDEFAULT); /* Copy default */
    xdef = cmdefault;

    inword = 0;				/* Initialize counts & pointers */
    cc = 0;
    xc = 0;
    *xp = "";				/* Pointer to result string */
    if ((x = cmflgs) != 1) {            /* Already confirmed? */
#ifdef BS_DIRSEP
	dirnamflg = 1;
        x = gtword(0);			/* No, get a word */
	dirnamflg = 0;
#else
        x = gtword(0);                  /* No, get a word */
#endif /* BS_DIRSEP */
    } else {				/* If so, use default, if any. */
        if (setatm(xdef,1) < 0) {
	    printf("?Default name too long\n");
	    if (np) free(np);
	    return(-9);
	}
    }
  i_path:
    *xp = atmbuf;                       /* Point to result. */

    while (1) {
        xc += cc;                       /* Count this character. */
        debug(F111,"cmifi gtword",atmbuf,xc);
	debug(F101,"cmifi switch x","",x);
        switch (x) {			/* x = gtword() return code */
	  case -10:
	    if (gtimer() > timelimit) {
#ifdef IKSD
                if (inserver) {
                    printf("\r\nIKSD IDLE TIMEOUT: %d sec\r\n", timelimit);
                    doexit(GOOD_EXIT,0);
                }
#endif /* IKSD */
		/* if (!quiet) printf("?Timed out\n"); */
		return(-10);
	    } else {
		x = gtword(0);
		continue;
	    }
	  case -9:
	    printf("Command or field too long\n");
	  case -4:			/* EOF */
	  case -2:			/* Out of space. */
	  case -1:			/* Reparse needed */
	    if (np) free(np);
	    return(x);
	  case 1:			/* CR */
	  case 0:			/* SP */
	    if (xc == 0)		/* If no input... */
	      *xp = xdef;		/* substitute the default */
#ifndef NOLASTFILE
	    makestr(&tmplastfile,*xp);	/* Make a copy before bstripping */
#endif	/* #ifndef NOLASTFILE */
	    *xp = brstrip(*xp);		/* Strip braces */
	    if (**xp == NUL) {		/* 12 mar 2001 */
		if (np) free(np);
		return(-3);
	    }
	    debug(F110,"cmifi brstrip",*xp,0);
#ifndef NOSPL
	    if (f) {			/* If a conversion function is given */
#ifdef DOCHKVAR
		char *s = *xp;		/* See if there are any variables in */
		int x;
		while (*s) {		/* the string and if so, expand them */
		    x = chkvar(s);
		    /* debug(F111,"cmifi chkvar",*xp,x); */
		    if (x) {
#endif /* DOCHKVAR */
			zq = atxbuf;
			atxn = CMDBL;
			if ((*f)(*xp,&zq,&atxn) < 0) {
			    if (np) free(np);
			    return(-2);
			}
			*xp = atxbuf;
			if (!atxbuf[0])
			  *xp = xdef;
#ifdef DOCHKVAR
			break;
		    }
		    s++;
		}
#endif /* DOCHKVAR */
	    }
#endif /* NOSPL */
	    if (**xp == NUL) {		/* 12 mar 2001 */
		if (np) free(np);
		return(-3);
	    }
#ifdef DTILDE
	    if (dirflg) {
		dirp = tilde_expand(*xp); /* Expand tilde, if any, */
		if (*dirp != '\0') {	/* in the atom buffer. */
		    if (setatm(dirp,1) < 0) {
			printf("Expanded name too long\n");
			if (np) free(np);
			return(-9);
		    }
		}
		*xp = atmbuf;
		debug(F110,"cmifi tilde_expand",*xp,0);
	    }
#endif /* DTILDE */
	    if (!sv) {			/* Only do this once */
		sv = malloc((int)strlen(*xp)+1); /* Make a safe copy */
		if (!sv) {
		    printf("?cmifi: malloc error\n");
		    if (np) free(np);
		    return(-9);
		}
		strcpy(sv,*xp);
		debug(F110,"cmifi sv",sv,0);
	    }

/* This is to get around "cd /" failing because "too many directories match" */

	    expanded = 0;		/* Didn't call zxpand */
#ifdef datageneral
	    debug(F110,"cmifi isdir 1",*xp,0);
	    {
		int y; char *s;
		s = *xp;
		y = strlen(s);
		if (y > 1 &&
		    (s[y-1] == ':' ||
		     s[y-1] == '^' ||
		     s[y-1] == '=')
		    )
		  s[y-1] = NUL;
	    }
	    debug(F110,"cmifi isdir 2",*xp,0);
#endif /*  datageneral */

#ifdef VMS
	    if (dirflg) {
		if (!strcmp(*xp,"..")) { /* For UNIXers... */
		    setatm("-",0);
		    *xp = atmbuf;
		} else if (!strcmp(*xp,".")) {
		    setatm("[]",0);
		    *xp = atmbuf;
		}
	    }
#endif /* VMS */
	    itsadir = isdir(*xp);	/* Is it a directory? */
	    debug(F111,"cmifi itsadir",*xp,itsadir);
#ifdef VMS
	    /* If they said "blah" where "blah.dir" is a directory... */
	    /* change it to [.blah]. */
	    if (!itsadir) {
		char tmpbuf[600];
		int flag = 0; char c, * p;
		p = *xp;
		while ((c = *p++) && !flag)
		  if (ckstrchr(".[]:*?<>",c))
		    flag = 1;
		debug(F111,"cmifi VMS dirname flag",*xp,flag);
		if (!flag) {
		    ckmakmsg(tmpbuf,TMPBUFSIZ,"[.",*xp,"]",NULL);
		    itsadir = isdir(tmpbuf);
		    if (itsadir) {
			setatm(tmpbuf,0);
			*xp = atmbuf;
		    }
		    debug(F111,"cmifi VMS dirname flag itsadir",*xp,itsadir);
		}
	    } else if (itsadir == 1 && *(xp[0]) == '.' && *(xp[1])) {
		char *p;
		if (p = malloc(cc + 4)) {
		    ckmakmsg(p,cc+4,"[",*xp,"]",NULL);
		    setatm(p,0);
		    *xp = atmbuf;
		    debug(F110,"cmdir .foo",*xp,0);
		    free(p);
		}
	    } else if (itsadir == 2 && !diractive) {
		int x;			/* [FOO]BAR.DIR instead of [FOO.BAR] */
		char *p;
		p = malloc(cc + 4);
		if (p) {
		    x = cvtdir(*xp,p,ATMBL); /* Convert to [FOO.BAR] */
		    if (x > 0) {
			setatm(p,0);
			*xp = atmbuf;
			debug(F110,"cmdir cvtdir",*xp,0);
		    }
		    free(p);
		}
	    }
#endif /* VMS */

	    debug(F101,"cmifi dirflg","",dirflg);
	    if (dirflg) {		/* Parsing a directory name? */
		/* Yes, does it contain wildcards? */
		if (iswild(*xp) ||
		    (diractive && (!strcmp(*xp,".")  || !strcmp(*xp,"..")))
		    ) {
		    nzxopts |= ZX_DIRONLY; /* Match only directory names */
		    if (matchdot)  nzxopts |= ZX_MATCHDOT;
		    if (recursive) nzxopts |= ZX_RECURSE;
		    debug(F111,"cmifi nzxopts 2",*xp,nzxopts);
		    y = nzxpand(*xp,nzxopts);
		    debug(F111,"cmifi nzxpand 2",*xp,y);
		    nfiles = y;
		    expanded = 1;
		} else {
#ifdef VMS
/*
  This is to allow (e.g.) "cd foo", where FOO.DIR;1 is in the
  current directory.
*/
		    debug(F111,"cmdir itsadir",*xp,itsadir);
		    if (!itsadir) {
			char *s;
			int n;
			s = *xp;
			n = strlen(s);
			if (n > 0 &&
#ifdef COMMENT
			    *s != '[' && s[n-1] != ']' &&
			    *s != '<' && s[n-1] != '>' &&
#else
			    ckindex("[",s,0,0,1) == 0 &&
			    ckindex("<",s,0,0,1) == 0 &&
#endif /* COMMENT */
			    s[n-1] != ':') {
			    char * dirbuf = NULL;
			    dirbuf = (char *)malloc(n+4);
			    if (dirbuf) {
				if (*s == '.')
				  ckmakmsg(dirbuf,n+4,"[",s,"]",NULL);
				else
				  ckmakmsg(dirbuf,n+4,"[.",s,"]",NULL);
				itsadir = isdir(dirbuf);
				debug(F111,"cmdir dirbuf",dirbuf,itsadir);
				if (itsadir) {
				    setatm(dirbuf,0);
				    *xp = atmbuf;
				    debug(F110,"cmdir new *xp",*xp,0);
				}
				free(dirbuf);
			    }

/* This is to allow CDPATH to work in VMS... */

			} else if (n > 0) {
			    char * p; int i, j, k, d;
			    char rb[2] = "]";
			    if (p = malloc(x + 8)) {
				ckstrncpy(p,*xp,x+8);
				i = ckindex(".",p,-1,1,1);
				d = ckindex(".dir",p,0,0,0);
				j = ckindex("]",p,-1,1,1);
				if (j == 0) {
				    j = ckindex(">",p,-1,1,1);
				    rb[0] = '>';
				}
				k = ckindex(":",p,-1,1,1);
				if (i < j || i < k) i = 0;
				if (d < j || d < k) d = 0;
				/* Change [FOO]BAR or [FOO]BAR.DIR */
				/* to [FOO.BAR] */
				if (j > 0 && j < n) {
				    p[j-1] = '.';
				    if (d > 0) p[d-1] = NUL;
				    ckstrncat(p,rb,x+8);
				    debug(F110,"cmdir xxx",p,0);
				}
				itsadir = isdir(p);
				debug(F111,"cmdir p",p,itsadir);
				if (itsadir) {
				    setatm(p,0);
				    *xp = atmbuf;
				    debug(F110,"cmdir new *xp",*xp,0);
				}
				free(p);
			    }
			}
		    }
#endif /* VMS */
		    y = (!itsadir) ? 0 : 1;
		    debug(F111,"cmifi y itsadir",*xp,y);
		}
	    } else {			/* Parsing a filename. */
		debug(F110,"cmifi *xp pre-zxpand",*xp,0);
#ifndef COMMENT
		nzxopts |= (d == 0) ? ZX_FILONLY : 0; /* So always expand. */
		if (matchdot)  nzxopts |= ZX_MATCHDOT;
		if (recursive) nzxopts |= ZX_RECURSE;
		y = nzxpand(*xp,nzxopts);
#else
/* Here we're trying to fix a problem in which a directory name is accepted */
/* as a filename, but this breaks too many other things. */
		/* nzxopts = 0; */
		if (!d) {
		    if (itsadir & !iswild(*xp)) {
			debug(F100,"cmifi dir when filonly","",0);
			printf("?Not a regular file: \"%s\"\n",*xp);
			if (sv) free(sv);
			if (np) free(np);
			return(-9);
		    } else {
			nzxopts |= ZX_FILONLY;
			if (matchdot)  nzxopts |= ZX_MATCHDOT;
			if (recursive) nzxopts |= ZX_RECURSE;
			y = nzxpand(*xp,nzxopts);
		    }
		}
#endif /* COMMENT */
		nfiles = y;
		debug(F111,"cmifi y nzxpand",*xp,y);
		debug(F111,"cmifi y atmbuf",atmbuf,itsadir);
		expanded = 1;
	    }
	    /* domydir() calls zxrewind() so we MUST call nzxpand() here */
	    if (!expanded && diractive) {
		debug(F110,"cmifi diractive catch-all zxpand",*xp,0);
		nzxopts |= (d == 0) ? ZX_FILONLY : (dirflg ? ZX_DIRONLY : 0);
		if (matchdot)  nzxopts |= ZX_MATCHDOT;
		if (recursive) nzxopts |= ZX_RECURSE;
		y = nzxpand(*xp,nzxopts);
		debug(F111,"cmifi diractive nzxpand",*xp,y);
		nfiles = y;
		expanded = 1;
	    }
	    *wild = (iswild(sv) || (y > 1)) && (itsadir == 0);

#ifdef RECURSIVE
	    if (!*wild) *wild = recursive;
#endif /* RECURSIVE */

	    debug(F111,"cmifi sv wild",sv,*wild);
	    debug(F101,"cmifi y","",y);
	    if (dirflg && *wild && cdactive) {
		if (y > 1) {
		    printf("?Wildcard matches more than one directory\n");
		    if (sv) free(sv);
		    if (np) free(np);
		    return(-9);
		} else {
		    znext(*xp);
		}
	    }
	    if (itsadir && d && !dirflg) { /* It's a directory and not wild */
		if (sv) free(sv);	/* and it's ok to parse directories */
		if (np) free(np);
#ifndef NOLASTFILE
		makestr(&lastfile,tmplastfile);
#endif	/* NOLASTFILE */
		return(x);
	    }
	    if (y == 0) {		/* File was not found */
		int dosearch = 0;
		dosearch = (path != NULL); /* A search path was given */
		if (dosearch) {
		    dosearch = hasnopath(sv); /* Filename includes no path */
		    debug(F111,"cmifip hasnopath",sv,dosearch);
		}
		if (dosearch) {		/* Search the path... */
		    char * ptr = path;
		    char c;
		    while (1) {
			c = *ptr;
			if (c == PATHSEP || c == NUL) {
			    if (!*path) {
				path = NULL;
				break;
			    }
			    *ptr = NUL;
#ifdef UNIX
/* By definition of CDPATH, an empty member denotes the current directory */
			    if (!*path)
			      ckstrncpy(atmbuf,".",ATMBL);
			    else
#endif /* UNIX */
			      ckstrncpy(atmbuf,path,ATMBL);
#ifdef VMS
			    atmbuf[ATMBL] = NUL;
/* If we have a logical name, evaluate it recursively */
			    if (*(ptr-1) == ':') { /* Logical name ends in : */
				char *p; int n;
				while (((n = strlen(atmbuf))  > 0) &&
				       atmbuf[n-1] == ':') {
				    atmbuf[n-1] = NUL;
				    for (p = atmbuf; *p; p++)
				      if (islower(*p)) *p = toupper(*p);
				    debug(F111,"cmdir CDPATH LN 1",atmbuf,n);
				    p = getenv(atmbuf);
				    debug(F110,"cmdir CDPATH LN 2",p,0);
				    if (!p)
				      break;
				    strncpy(atmbuf,p,ATMBL);
				    atmbuf[ATMBL] = NUL;
				}
			    }
#else
#ifdef OS2
			    if (*(ptr-1) != '\\' && *(ptr-1) != '/')
			      ckstrncat(atmbuf,"\\",ATMBL);
#else
#ifdef UNIX
			    if (*(ptr-1) != '/')
			      ckstrncat(atmbuf,"/",ATMBL);
#else
#ifdef datageneral
			    if (*(ptr-1) != ':')
			      ckstrncat(atmbuf,":",ATMBL);
#endif /* datageneral */
#endif /* UNIX */
#endif /* OS2 */
#endif /* VMS */
			    ckstrncat(atmbuf,sv,ATMBL);
			    debug(F110,"cmifip add path",atmbuf,0);
			    if (c == PATHSEP) ptr++;
			    path = ptr;
			    break;
			}
			ptr++;
		    }
		    x = 1;
		    inword = 0;
		    cc = 0;
		    xc = (int) strlen(atmbuf);
		    *xp = "";
		    goto i_path;
		}
		if (d) {
		    if (sv) free(sv);
		    if (np) free(np);
		    return(-2);
		} else {
		    if (!nomsg) {
#ifdef CKROOT
			if (ckrooterr)
			  printf("?Off Limits: %s\n",sv);
			else
#endif /* CKROOT */
			  if (!quiet)
			    printf("?No %s match - %s\n",
				 dirflg ? "directories" : "files", sv);
		    }
		    if (sv) free(sv);
		    if (np) free(np);
		    return(-9);
		}
	    } else if (y < 0) {
#ifdef CKROOT
		if (ckrooterr)
		  printf("?Off Limits: %s\n",sv);
		else
#endif /* CKROOT */
		  printf("?Too many %s match - %s\n",
			 dirflg ? "directories" : "files", sv);
		if (sv) free(sv);
		if (np) free(np);
		return(-9);
	    } else if (*wild || y > 1) {
		if (sv) free(sv);
		if (np) free(np);
#ifndef NOLASTFILE
		makestr(&lastfile,tmplastfile);
#endif	/* NOLASTFILE */
		return(x);
	    }

	    /* If not wild, see if it exists and is readable. */

	    debug(F111,"cmifi sv not wild",sv,*wild);
	    if (expanded)
	      znext(*xp);		/* Get first (only?) matching file */
	    if (dirflg)			/* Maybe wild and expanded */
	      itsadir = isdir(*xp);	/* so do this again. */
	    filesize = dirflg ? itsadir : zchki(*xp); /* Check accessibility */
	    if (expanded) {
#ifdef ZXREWIND
		nfiles = zxrewind();	/* Rewind so next znext() gets 1st */
#else

		nzxopts |= dirflg ? ZX_DIRONLY : 0;
		if (matchdot)  nzxopts |= ZX_MATCHDOT;
		if (recursive) nzxopts |= ZX_RECURSE;
		nfiles = nzxpand(*xp,nzxopts);
#endif /* ZXREWIND */
	    }
	    debug(F111,"cmifi nfiles",*xp,nfiles);
	    debug(F101,"cmifi filesize","",filesize);
	    free(sv);			/* done with this */
	    sv = NULL;
	    if (dirflg && !filesize) {
		printf("?Not a directory - %s\n",*xp);
#ifdef CKCHANNELIO
		z_error = FX_ACC;
#endif /* CKCHANNELIO */
		return(-9);
	    } else if (filesize == (CK_OFF_T)-3) {
		if (!xcmfdb) {
		    if (diractive)
		      /* Don't show filename if we're not allowed to see it */
		      printf("?Read permission denied\n");
		    else
		      printf("?Read permission denied - %s\n",*xp);
		}
		if (np) free(np);
#ifdef CKCHANNELIO
		z_error = FX_ACC;
#endif /* CKCHANNELIO */
		return(xcmfdb ? -6 : -9);
	    } else if (filesize == (CK_OFF_T)-2) {
		if (!recursive) {
		    if (np) free(np);
		    if (d) {
#ifndef NOLASTFILE
			makestr(&lastfile,tmplastfile);
#endif	/* NOLASTFILE */
			return(0);
		    }
		    if (!xcmfdb)
		      printf("?File not readable - %s\n",*xp);
#ifdef CKCHANNELIO
		    z_error = FX_ACC;
#endif /* CKCHANNELIO */
		    return(xcmfdb ? -6 : -9);
		}
	    } else if (filesize < (CK_OFF_T)0) {
		if (np) free(np);
		if (!nomsg && !xcmfdb)
		  printf("?File not found - %s\n",*xp);
#ifdef CKCHANNELIO
		z_error = FX_FNF;
#endif /* CKCHANNELIO */
		return(xcmfdb ? -6 : -9);
	    }
	    if (np) free(np);
#ifndef NOLASTFILE
	    makestr(&lastfile,tmplastfile);
#endif	/* NOLASTFILE */
	    return(x);

#ifndef MAC
	  case 2:			/* ESC */
	    debug(F101,"cmifi esc, xc","",xc);
	    if (xc == 0) {
		if (*xdef) {
		    printf("%s ",xdef); /* If at beginning of field */
#ifdef GEMDOS
		    fflush(stdout);
#endif /* GEMDOS */
		    inword = cmflgs = 0;
		    addbuf(xdef);	/* Supply default. */
		    if (setatm(xdef,0) < 0) {
			printf("Default name too long\n");
			if (np) free(np);
			return(-9);
		    }
		} else {		/* No default */
		    bleep(BP_WARN);
		}
		break;
	    }
	    if (**xp == '{') {		/* Did user type opening brace... */
		*xp = *xp + 1;
		xc--;
		cc--;
		qflag = '}';
	    } else if (dblquo && **xp == '"') {	/* or doublequote? */
		*xp = *xp + 1;		/* If so ignore it and space past it */
		xc--;
		cc--;
		qflag = '"';
	    }
#ifndef NOSPL
	    if (f) {			/* If a conversion function is given */
#ifdef DOCHKVAR
		char *s = *xp;		/* See if there are any variables in */
		while (*s) {		/* the string and if so, expand it.  */
		    if (chkvar(s)) {
#endif /* DOCHKVAR */
			zq = atxbuf;
			atxn = CMDBL;
			if ((x = (*f)(*xp,&zq,&atxn)) < 0) {
			    if (np) free(np);
			    return(-2);
			}
#ifdef DOCHKVAR
		    /* reduce cc by number of \\ consumed by conversion */
		    /* function (needed for OS/2, where \ is path separator) */
			cc -= (strlen(*xp) - strlen(atxbuf));
#endif /* DOCHKVAR */
			*xp = atxbuf;
			if (!atxbuf[0]) { /* Result empty, use default */
			    *xp = xdef;
			    cc = strlen(xdef);
			}
#ifdef DOCHKVAR
			break;
		    }
		    s++;
		}
#endif /* DOCHKVAR */
	    }
#endif /* NOSPL */

#ifdef DTILDE
	    if (dirflg && *(*xp) == '~') {
		debug(F111,"cmifi tilde_expand A",*xp,cc);
		dirp = tilde_expand(*xp); /* Expand tilde, if any... */
		if (!dirp) dirp = "";
		if (*dirp) {
		    int i, xx;
		    char * sp;
		    xc = cc;		/* Length of ~thing */
		    xx = setatm(dirp,0); /* Copy expansion to atom buffer */
		    debug(F111,"cmifi tilde_expand B",atmbuf,cc);
		    if (xx < 0) {
			printf("Expanded name too long\n");
			if (np) free(np);
			return(-9);
		    }
		    debug(F111,"cmifi tilde_expand xc","",xc);
		    for (i = 0; i < xc; i++) {
			cmdchardel();	/* Back up over ~thing */
			bp--;
		    }
		    xc = cc;		/* How many new ones we just got */
		    sp = atmbuf;
		    printf("%s",sp);	/* Print them */
		    while ((*bp++ = *sp++)) ;	/* Copy to command buffer */
		    bp--;	    	        /* Back up over NUL */
		}
		*xp = atmbuf;
	    }
#endif /* DTILDE */

	    sp = *xp + cc;

#ifdef UNIXOROSK
	    if (!strcmp(atmbuf,"..")) {
		printf(" ");
		ckstrncat(cmdbuf," ",CMDBL);
		cc++;
		bp++;
		*wild = 0;
		*xp = atmbuf;
		break;
	    } else if (!strcmp(atmbuf,".")) {
		bleep(BP_WARN);
		if (np) free(np);
		return(-1);
	    } else {
		/* This patches a glitch when user types "./foo<ESC>" */
		/* in which the next two chars are omitted from the */
		/* expansion.  There should be a better fix, however, */
		/* since there is no problem with "../foo<ESC>". */
		char *p = *xp;
		if (*p == '.' && *(p+1) == '/')
		  cc -= 2;
	    }
#endif /* UNIXOROSK */

#ifdef datageneral
	    *sp++ = '+';		/* Data General AOS wildcard */
#else
	    *sp++ = '*';		/* Others */
#endif /* datageneral */
	    *sp-- = '\0';
#ifdef GEMDOS
	    if (!strchr(*xp, '.'))	/* abde.e -> abcde.e* */
	      strcat(*xp, ".*");	/* abc -> abc*.* */
#endif /* GEMDOS */
	    /* Add wildcard and expand list. */
#ifdef COMMENT
	    /* This kills partial completion when ESC given in path segment */
	    nzxopts |= dirflg ? ZX_DIRONLY : (d ? 0 : ZX_FILONLY);
#else
	    /* nzxopts = 0; */
#endif /* COMMENT */
	    if (matchdot)  nzxopts |= ZX_MATCHDOT;
	    if (recursive) nzxopts |= ZX_RECURSE;
	    y = nzxpand(*xp,nzxopts);
	    nfiles = y;
	    debug(F111,"cmifi nzxpand",*xp,y);
	    if (y > 0) {
#ifdef OS2
                znext(filbuf);		/* Get first */
#ifdef ZXREWIND
		zxrewind();		/* Must "rewind" */
#else
		nzxpand(*xp,nxzopts);
#endif /* ZXREWIND */
#else  /* Not OS2 */
                ckstrncpy(filbuf,mtchs[0],CKMAXPATH);
#endif /* OS2 */
	    } else
	      *filbuf = '\0';
	    filbuf[CKMAXPATH] = NUL;
	    *sp = '\0';			/* Remove wildcard. */
	    debug(F111,"cmifi filbuf",filbuf,y);
	    debug(F111,"cmifi *xp",*xp,cc);

	    *wild = (y > 1);
	    if (y == 0) {
		if (!nomsg) {
#ifdef CKROOT
		    if (ckrooterr)
		      printf("?Off Limits: %s\n",atmbuf);
		    else
#endif /* CKROOT */
		      printf("?No %s match - %s\n",
			   dirflg ? "directories" : "files", atmbuf);
		    if (np) free(np);
		    return(-9);
		} else {
		    bleep(BP_WARN);
		    if (np) free(np);
		    return(-1);
		}
	    } else if (y < 0) {
#ifdef CKROOT
		if (ckrooterr)
		  printf("?Off Limits: %s\n",atmbuf);
		else
#endif /* CKROOT */
		  printf("?Too many %s match - %s\n",
			 dirflg ? "directories" : "files", atmbuf);
		if (np) free(np);
		return(-9);
	    } else if (y > 1		/* Not unique */
#ifndef VMS
		       || (y == 1 && isdir(filbuf)) /* Unique directory */
#endif /* VMS */
		       ) {
#ifndef NOPARTIAL
/* Partial filename completion */
		int j, k; char c;
		k = 0;
		debug(F111,"cmifi partial",filbuf,cc);
#ifdef OS2
		{
		    int cur = 0,
		    len = 0,
		    len2 = 0,
		    min = strlen(filbuf),
		    found = 0;
		    char localfn[CKMAXPATH+1];

		    len = min;
		    for (j = 1; j <= y; j++) {
			znext(localfn);
			if (dirflg && !isdir(localfn))
			  continue;
			found = 1;
			len2 = strlen(localfn);
			for (cur = cc;
			     cur < len && cur < len2 && cur <= min;
			     cur++
			     ) {
                            /* OS/2 or Windows, case doesn't matter */
			    if (tolower(filbuf[cur]) != tolower(localfn[cur]))
			      break;
			}
			if (cur < min)
			  min = cur;
		    }
		    if (!found)
		      min = cc;
		    filbuf[min] = NUL;
		    if (min > cc)
		      k++;
		}
#else /* OS2 */
		for (i = cc; (c = filbuf[i]); i++) {
		    for (j = 1; j < y; j++)
		      if (mtchs[j][i] != c) break;
		    if (j == y) k++;
		    else filbuf[i] = filbuf[i+1] = NUL;
		}
#endif /* OS2 */


#ifndef VMS
		/* isdir() function required for this! */
		if (y == 1 && isdir(filbuf)) { /* Dont we already know this? */
		    int len;
		    len = strlen(filbuf);
		    if (len > 0 && len < ATMBL - 1) {
			if (filbuf[len-1] != dirsep) {
			    filbuf[len] = dirsep;
			    filbuf[len+1] = NUL;
			}
		    }
/*
  At this point, before just doing partial completion, we should look first to
  see if the given directory does indeed have any subdirectories (dirflg) or
  files (!dirflg); if it doesn't we should do full completion.  Otherwise, the
  result looks funny to the user and "?" blows up the command for no good
  reason.
*/
		    {
			int flags = 0;
			filbuf[len+1] = '*';
			filbuf[len+2] = NUL;
			if (dirflg) flags = ZX_DIRONLY;
			children = nzxpand(filbuf,flags);
			debug(F111,"cmifi children",filbuf,children);
			filbuf[len+1] = NUL;
			nzxpand(filbuf,flags); /* Restore previous list */
			if (children == 0)
			  goto NOSUBDIRS;
		    }
		    if (len + 1 > cc)
		      k++;
		}
                /* Add doublequotes if there are spaces in the name */
		{
		    int x;
		    if (qflag) {
			x = (qflag == '}'); /* (or braces) */
		    } else {
			x = !dblquo;
		    }
		    if (filbuf[0] != '"' && filbuf[0] != '{')
		      k = dquote(filbuf,ATMBL,x);
		}
#endif /* VMS */
		debug(F111,"cmifi REPAINT filbuf",filbuf,k);
		if (k > 0) {		/* Got more characters */
		    debug(F101,"cmifi REPAINT cc","",cc);
		    debug(F101,"cmifi REPAINT xc","",xc);
		    debug(F110,"cmifi REPAINT bp-cc",bp-cc,0);
		    debug(F110,"cmifi REPAINT bp-xc",bp-xc,0);
		    sp = filbuf + cc;	/* Point to new ones */
		    if (qflag || strncmp(filbuf,bp-cc,cc)) { /* Repaint? */
			int x;
			x = cc;
			if (qflag) x++;
			for (i = 0; i < x; i++) {
			    cmdchardel(); /* Back up over old partial spec */
			    bp--;
			}
			sp = filbuf;	/* Point to new word start */
			debug(F110,"cmifi erase ok",sp,0);
		    }
		    cc = k;		/* How many new ones we just got */
		    printf("%s",sp);	/* Print them */
		    while ((*bp++ = *sp++)) ;	/* Copy to command buffer */
		    bp--;	    	        /* Back up over NUL */
		    debug(F110,"cmifi partial cmdbuf",cmdbuf,0);
		    if (setatm(filbuf,0) < 0) {
			printf("?Partial name too long\n");
			if (np) free(np);
			return(-9);
		    }
		    debug(F111,"cmifi partial atmbuf",atmbuf,cc);
		    *xp = atmbuf;
		}
#endif /* NOPARTIAL */
		bleep(BP_WARN);
	    } else {			/* Unique, complete it.  */
#ifndef VMS
#ifdef CK_TMPDIR
		/* isdir() function required for this! */
	      NOSUBDIRS:
		debug(F111,"cmifi unique",filbuf,children);
		if (isdir(filbuf) && children > 0) {
		    int len;
		    len = strlen(filbuf);
		    if (len > 0 && len < ATMBL - 1) {
			if (filbuf[len-1] != dirsep) {
			    filbuf[len] = dirsep;
			    filbuf[len+1] = NUL;
			}
		    }
		    sp = filbuf + cc;
		    bleep(BP_WARN);
		    printf("%s",sp);
		    cc++;
		    while ((*bp++ = *sp++)) ;
		    bp--;
		    if (setatm(filbuf,0) < 0) {
			printf("?Directory name too long\n");
			if (np) free(np);
			return(-9);
		    }
		    debug(F111,"cmifi directory atmbuf",atmbuf,cc);
		    *xp = atmbuf;
		} else {		/* Not a directory or dirflg */
#endif /* CK_TMPDIR */
#endif /* VMS */
#ifndef VMS				/* VMS dir names are special */
#ifndef datageneral			/* VS dirnames must not end in ":" */
		    if (dirflg) {
			int len;
			len = strlen(filbuf);
			if (len > 0 && len < ATMBL - 1) {
			    if (filbuf[len-1] != dirsep) {
				filbuf[len] = dirsep;
				filbuf[len+1] = NUL;
			    }
			}
		    }
#endif /* datageneral */
#endif /* VMS */
		    sp = filbuf + cc;	/* Point past what user typed. */
		    {
			int x;
			if (qflag) {
			    x = (qflag == '}');
			} else {
			    x = !dblquo;
			}
			if (filbuf[0] != '"' && filbuf[0] != '{')
			  dquote(filbuf,ATMBL,x);
		    }
		    if (qflag || strncmp(filbuf,bp-cc,cc)) { /* Repaint? */
			int x;
			x = cc;
			if (qflag) x++;
			for (i = 0; i < x; i++) {
			    cmdchardel(); /* Back up over old partial spec */
			    bp--;
			}
			sp = filbuf;	/* Point to new word start */
			debug(F111,"cmifi after erase sp=",sp,cc);
		    }
		    printf("%s ",sp);	/* Print the completed name. */
#ifdef GEMDOS
		    fflush(stdout);
#endif /* GEMDOS */
		    addbuf(sp);		/* Add the characters to cmdbuf. */
		    if (setatm(filbuf,0) < 0) { /* And to atmbuf. */
			printf("?Completed name too long\n");
			if (np) free(np);
			return(-9);
		    }
		    inword = cmflgs = 0;
		    *xp = brstrip(atmbuf); /* Return pointer to atmbuf. */
		    if (dirflg && !isdir(*xp)) {
			printf("?Not a directory - %s\n", filbuf);
			if (np) free(np);
			return(-9);
		    }
		    if (np) free(np);
#ifndef NOLASTFILE
		    makestr(&lastfile,tmplastfile);
#endif	/* NOLASTFILE */
		    return(0);
#ifndef VMS
#ifdef CK_TMPDIR
		}
#endif /* CK_TMPDIR */
#endif /* VMS */
	    }
	    break;

	  case 3:			/* Question mark - file menu wanted */
	    if (*xhlp == NUL)
	      printf(dirflg ? " Directory name" : " Input file specification");
	    else
	      printf(" %s",xhlp);
#ifdef GEMDOS
	    fflush(stdout);
#endif /* GEMDOS */
	    /* If user typed an opening quote or brace, just skip past it */

	    if (**xp == '"' || **xp == '{') {
		*xp = *xp + 1;
		xc--;
		cc--;
	    }
#ifndef NOSPL
	    if (f) {			/* If a conversion function is given */
#ifdef DOCHKVAR
		char *s = *xp;		/* See if there are any variables in */
		while (*s) {		/* the string and if so, expand them */
		    if (chkvar(s)) {
#endif /* DOCHKVAR */
			zq = atxbuf;
			atxn = CMDBL;
			if ((x = (*f)(*xp,&zq,&atxn)) < 0) {
			    if (np) free(np);
			    return(-2);
			}
#ifdef DOCHKVAR
		    /* reduce cc by number of \\ consumed by conversion */
		    /* function (needed for OS/2, where \ is path separator) */
			cc -= (strlen(*xp) - strlen(atxbuf));
#endif /* DOCHKVAR */
			*xp = atxbuf;
#ifdef DOCHKVAR
			break;
		    }
		    s++;
		}
#endif /* DOCHKVAR */
	    }
#endif /* NOSPL */
	    debug(F111,"cmifi ? *xp, cc",*xp,cc);
	    sp = *xp + cc;		/* Insert "*" at end */
#ifdef datageneral
	    *sp++ = '+';		/* Insert +, the DG wild card */
#else
	    *sp++ = '*';
#endif /* datageneral */
	    *sp-- = '\0';
#ifdef GEMDOS
	    if (! strchr(*xp, '.'))	/* abde.e -> abcde.e* */
	      strcat(*xp, ".*");	/* abc -> abc*.* */
#endif /* GEMDOS */
	    debug(F110,"cmifi ? wild",*xp,0);

	    nzxopts |= dirflg ? ZX_DIRONLY : (d ? 0 : ZX_FILONLY);

	    debug(F101,"cmifi matchdot","",matchdot);
	    if (matchdot)  nzxopts |= ZX_MATCHDOT;
	    if (recursive) nzxopts |= ZX_RECURSE;
	    y = nzxpand(*xp,nzxopts);
	    nfiles = y;
	    *sp = '\0';
	    if (y == 0) {
		if (nomsg) {
		    printf(": %s\n",atmbuf);
		    printf("%s%s",cmprom,cmdbuf);
		    fflush(stdout);
		    if (np) free(np);
		    return(-1);
		} else {
#ifdef CKROOT
		    if (ckrooterr)
		      printf("?Off Limits: %s\n",atmbuf);
		    else
#endif /* CKROOT */
		      printf("?No %s match - %s\n",
			     dirflg ? "directories" : "files", atmbuf);
		    if (np) free(np);
		    return(-9);
		}
	    } else if (y < 0) {
#ifdef CKROOT
		if (ckrooterr)
		  printf("?Off Limits: %s\n",atmbuf);
		else
#endif /* CKROOT */
		  printf("?Too many %s match - %s\n",
			 dirflg ? "directories" : "files", atmbuf);
		if (np) free(np);
		return(-9);
	    } else {
		printf(", one of the following:\n");
		if (filhelp((int)y,"","",1,dirflg) < 0) {
		    if (np) free(np);
		    return(-9);
		}
	    }
	    printf("%s%s",cmprom,cmdbuf);
	    fflush(stdout);
	    break;
#endif /* MAC */
	}
#ifdef BS_DIRSEP
        dirnamflg = 1;
        x = gtword(0);                  /* No, get a word */
	dirnamflg = 0;
#else
        x = gtword(0);                  /* No, get a word */
#endif /* BS_DIRSEP */
	*xp = atmbuf;
    }
}

/*  C M F L D  --  Parse an arbitrary field  */
/*
  Returns:
    -3 if no input present when required,
    -2 if field too big for buffer,
    -1 if reparse needed,
     0 otherwise, xp pointing to string result.

  NOTE: Global flag keepallchars says whether this routine should break on CR
  or LF: needed for MINPUT targets and DECLARE initializers, where we want to
  keep control characters if the user specifies them (March 2003).  It might
  have been better to change the calling sequence but that was not practical.
*/
int
cmfld(xhlp,xdef,xp,f) char *xhlp, *xdef, **xp; xx_strp f; {
    int x, xc;
    char *zq;

    inword = 0;				/* Initialize counts & pointers */
    cc = 0;
    xc = 0;
    *xp = "";

    debug(F110,"cmfld xdef 1",xdef,0);

    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";
    ckstrncpy(cmdefault,xdef,CMDEFAULT); /* Copy default */
    xdef = cmdefault;

    debug(F111,"cmfld xdef 2",xdef,cmflgs);
    debug(F111,"cmfld atmbuf 1",atmbuf,xc);

    if ((x = cmflgs) != 1) {            /* Already confirmed? */
        x = gtword(0);                  /* No, get a word */
    } else {
	if (setatm(xdef,0) < 0) {	/* If so, use default, if any. */
	    printf("?Default too long\n");
	    return(-9);
	}
    }
    *xp = atmbuf;                       /* Point to result. */
    debug(F111,"cmfld atmbuf 2",atmbuf,cmflgs);

    while (1) {
        xc += cc;                       /* Count the characters. */
        debug(F111,"cmfld gtword",atmbuf,xc);
        debug(F101,"cmfld x","",x);
        switch (x) {
	  case -9:
	    printf("Command or field too long\n");
	  case -4:			/* EOF */
	  case -3:			/* Empty. */
	  case -2:			/* Out of space. */
	  case -1:			/* Reparse needed */
	    return(x);
	  case 1:			/* CR */
	  case 0:			/* SP */
	    debug(F111,"cmfld 1",atmbuf,xc);
	    if (xc == 0) {		/* If no input, return default. */
		if (setatm(xdef,0) < 0) {
		    printf("?Default too long\n");
		    return(-9);
		}
	    }
	    *xp = atmbuf;		/* Point to what we got. */
	    debug(F111,"cmfld 2",atmbuf,((f) ? 1 : 0));
	    if (f) {			/* If a conversion function is given */
		zq = atxbuf;		/* employ it now. */
		atxn = CMDBL;
		if ((*f)(*xp,&zq,&atxn) < 0)
		  return(-2);
		debug(F111,"cmfld 3",atxbuf,xc);
		/* Replace by new value -- for MINPUT only keep all chars */
		if (setatm(atxbuf,keepallchars ? 3:1) < 0) { /* 16 Mar 2003 */
		    printf("Value too long\n");
		    return(-9);
		}
		*xp = atmbuf;
	    }
	    debug(F111,"cmfld 4",atmbuf,xc);
	    if (**xp == NUL) {		/* If variable evaluates to null */
		if (setatm(xdef,0) < 0) {
		    printf("?Default too long\n");
		    return(-9);
		}
		if (**xp == NUL) x = -3; /* If still empty, return -3. */
	    }
	    debug(F111,"cmfld returns",*xp,x);
	    return(x);
	  case 2:			/* ESC */
	    if (xc == 0 && *xdef) {
		printf("%s ",xdef); /* If at beginning of field, */
#ifdef GEMDOS
		fflush(stdout);
#endif /* GEMDOS */
		addbuf(xdef);		/* Supply default. */
		inword = cmflgs = 0;
		if (setatm(xdef,0) < 0) {
		    printf("?Default too long\n");
		    return(-9);
		} else			/* Return as if whole field */
		  return(0);		/* typed, followed by space. */
	    } else {
		bleep(BP_WARN);
	    }
	    break;
	  case 3:			/* Question mark */
	    debug(F110,"cmfld QUESTIONMARK",cmdbuf,0);
	    if (*xhlp == NUL)
	      printf(" Please complete this field");
	    else
	      printf(" %s",xhlp);
	    printf("\n%s%s",cmprom,cmdbuf);
	    fflush(stdout);
	    break;
        }
	debug(F111,"cmfld gtword A x",cmdbuf,x);
	x = gtword(0);
	debug(F111,"cmfld gtword B x",cmdbuf,x);
    }
}


/*  C M T X T  --  Get a text string, including confirmation  */

/*
  Print help message 'xhlp' if ? typed, supply default 'xdef' if null
  string typed.  Returns:

   -1 if reparse needed or buffer overflows.
    1 otherwise.

  with cmflgs set to return code, and xp pointing to result string.
*/
int
cmtxt(xhlp,xdef,xp,f) char *xhlp; char *xdef; char **xp; xx_strp f; {

    int x, i;
    char *xx, *zq;
    static int xc;

    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";

    cmfldflgs = 0;

    cmdefault[0] = NUL;
    if (*xdef)
      ckstrncpy(cmdefault,xdef,CMDEFAULT); /* Copy default */
    xdef = cmdefault;

    debug(F101,"cmtxt cmflgs","",cmflgs);
    inword = 0;				/* Start atmbuf counter off at 0 */
    cc = 0;
    if (cmflgs == -1) {                 /* If reparsing, */
	*xp = pp;
        xc = (int)strlen(*xp);		/* get back the total text length, */
	bp = *xp;			/* and back up the pointers. */
	np = *xp;
	pp = *xp;
    } else {                            /* otherwise, */
	/* debug(F100,"cmtxt: fresh start","",0); */
        *xp = "";                       /* start fresh. */
        xc = 0;
    }
    *atmbuf = NUL;                      /* And empty the atom buffer. */
    rtimer();				/* Reset timer */
    if ((x = cmflgs) != 1) {
	int done = 0;
	while (!done) {
	    x = gtword(0);		/* Get first word. */
	    *xp = pp;			/* Save pointer to it. */
	    /* debug(F111,"cmtxt:",*xp,cc); */
	    if (x == -10) {
		if (gtimer() > timelimit) {
		    /* if (!quiet) printf("?Timed out\n"); */
		    return(x);
		}
	    } else
	      done = 1;
	}
    }
    while (1) {				/* Loop for each word in text. */
        xc += cc;                       /* Char count for all words. */
        /* debug(F111,"cmtxt gtword",atmbuf,xc); */
        /* debug(F101,"cmtxt x","",x); */
        switch (x) {
	  case -10:
	    if (gtimer() > timelimit) {
#ifdef IKSD
                extern int inserver;
                if (inserver) {
                    printf("\r\nIKSD IDLE TIMEOUT: %d sec\r\n", timelimit);
                    doexit(GOOD_EXIT,0);
                }
#endif /* IKSD */
		/* if (!quiet) printf("?Timed out\n"); */
		return(-10);
	    } else {
		x = gtword(0);
		continue;
	    }
	  case -9:			/* Buffer overflow */
	    printf("Command or field too long\n");
	  case -4:			/* EOF */
#ifdef MAC
	  case -3:			/* Quit/Timeout */
#endif /* MAC */
	  case -2:			/* Overflow */
	  case -1:			/* Deletion */
	    return(x);
	  case 0:			/* Space */
	    xc++;			/* Just count it */
	    break;
	  case 1:			/* CR or LF */
	    if (xc == 0) *xp = xdef;
	    if (f) {			/* If a conversion function is given */
		char * sx = atxbuf;
		zq = atxbuf;		/* Point to the expansion buffer */
		atxn = CMDBL;		/* specify its length */
		/* debug(F111,"cmtxt calling (*f)",*xp,atxbuf); */
		if ((x = (*f)(*xp,&zq,&atxn)) < 0) return(-2);
		sx = atxbuf;
#ifndef COMMENT
		cc = 0;
		while (*sx++) cc++;	/* (faster than calling strlen) */
#else
		cc = (int)strlen(atxbuf);
#endif /* COMMENT */
		/* Should be equal to (CMDBL - atxn) but isn't always. */
		/* Why not? */
		if (cc < 1) {		/* Nothing in expansion buffer? */
		    *xp = xdef;		/* Point to default string instead. */
#ifndef COMMENT
		    sx = xdef;
		    while (*sx++) cc++;	/* (faster than calling strlen) */
#else
		    cc = strlen(xdef);
#endif /* COMMENT */
		} else {		/* Expansion function got something */
		    *xp = atxbuf;	/* return pointer to it. */
		}
		debug(F111,"cmtxt (*f)",*xp,cc);
	    } else {			/* No expansion function */
#ifndef COMMENT
		/* Avoid a strlen() call */
		xx = *xp;
		cc = 0;
		while (*xx++) cc++;
#else
		/* NO!  xc is apparently not always set appropriately */
		cc = xc;
#endif /* COMMENT */
	    }
	    xx = *xp;
#ifdef COMMENT
	    /* strlen() no longer needed */
	    for (i = (int)strlen(xx) - 1; i > 0; i--)
#else
	    for (i = cc - 1; i > 0; i--)
#endif /* COMMENT */
	      if (xx[i] != SP)		/* Trim trailing blanks */
		break;
	      else
		xx[i] = NUL;
	    return(x);
	  case 2:			/* ESC */
	    if (xc == 0) {		/* Nothing typed yet */
		if (*xdef) {		/* Have a default for this field? */
		    printf("%s ",xdef);	/* Yes, supply it */
		    inword = cmflgs = 0;
#ifdef GEMDOS
		    fflush(stdout);
#endif /* GEMDOS */
		    cc = addbuf(xdef);
		} else bleep(BP_WARN);	/* No default */
	    } else {			/* Already in field */
		int x; char *p;
		x = strlen(atmbuf);
		if (ckstrcmp(atmbuf,xdef,x,0)) {    /* Matches default? */
		    bleep(BP_WARN);	            /* No */
		} else if ((int)strlen(xdef) > x) { /* Yes */
		    p = xdef + x;
		    printf("%s ", p);
#ifdef GEMDOS
		    fflush(stdout);
#endif /* GEMDOS */
		    addbuf(p);
		    inword = cmflgs = 0;
		    debug(F110,"cmtxt: addbuf",cmdbuf,0);
		} else {
		    bleep(BP_WARN);
		}
	    }
	    break;
	  case 3:			/* Question Mark */
	    if (*xhlp == NUL)
	      printf(" Text string");
	    else
	      printf(" %s",xhlp);
	    printf("\n%s%s",cmprom,cmdbuf);
	    fflush(stdout);
	    break;
	  default:
	    printf("?Unexpected return code from gtword() - %d\n",x);
	    return(-2);
        }
        x = gtword(0);
    }
}

/*  C M K E Y  --  Parse a keyword  */

/*
 Call with:
   table    --  keyword table, in 'struct keytab' format;
   n        --  number of entries in table;
   xhlp     --  pointer to help string;
   xdef     --  pointer to default keyword;
   f        --  string preprocessing function (e.g. to evaluate variables)
   pmsg     --  0 = don't print error messages
                1 = print error messages
                2 = include CM_HLP keywords even if invisible
                3 = 1+2
                4 = parse a switch (keyword possibly ending in : or =)
                8 = don't strip comments (used, e.g., for "help #")
 Returns:
   -3       --  no input supplied and no default available
   -2       --  input doesn't uniquely match a keyword in the table
   -1       --  user deleted too much, command reparse required
    n >= 0  --  value associated with keyword
*/

/*
  Front ends for cmkey2(): 
  cmkey()  - The normal keyword parser
  cmkeyx() - Like cmkey() but suppresses error messages
  cmswi()  - Switch parser
*/
int
cmkey(table,n,xhlp,xdef,f)
/* cmkey */  struct keytab table[]; int n; char *xhlp, *xdef; xx_strp f; {
    return(cmkey2(table,n,xhlp,xdef,"",f,1));
}
int
cmkeyx(table,n,xhlp,xdef,f)
/* cmkeyx */  struct keytab table[]; int n; char *xhlp, *xdef; xx_strp f; {
    return(cmkey2(table,n,xhlp,xdef,"",f,0));
}
int
cmswi(table,n,xhlp,xdef,f)
/* cmswi */  struct keytab table[]; int n; char *xhlp, *xdef; xx_strp f; {
    return(cmkey2(table,n,xhlp,xdef,"",f,4));
}

int
cmkey2(table,n,xhlp,xdef,tok,f,pmsg)
    struct keytab table[];
    int n;
    char *xhlp, *xdef;
    char *tok;
    xx_strp f;
    int pmsg;
{ /* cmkey2 */
    extern int havetoken;
    int i, tl, y, z = 0, zz, xc, wordlen = 0, cmswitch;
    char *xp, *zq;

    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";

    cmfldflgs = 0;
    if (!table) {
	printf("?Keyword table missing\n");
	return(-9);
    }
    tl = (int)strlen(tok);

    inword = xc = cc = 0;		/* Clear character counters. */
    cmswitch = pmsg & 4;		/* Flag for parsing a switch */

    debug(F101,"cmkey: pmsg","",pmsg);
    debug(F101,"cmkey: cmflgs","",cmflgs);
    debug(F101,"cmkey: cmswitch","",cmswitch);
    /* debug(F101,"cmkey: cmdbuf","",cmdbuf);*/

    ppvnambuf[0] = NUL;

    if ((zz = cmflgs) == 1) {		/* Command already entered? */
	if (setatm(xdef,0) < 0) {	/* Yes, copy default into atom buf */
	    printf("?Default too long\n");
	    return(-9);
	}
        rtimer();			 /* Reset timer */
    } else {				 /* Otherwise get a command word */
        rtimer();			 /* Reset timer */
	if (pmsg & 8)			 /* 8 is for parsing HELP tokens */
	  zz = gtword(4);
	else
	  zz = gtword((pmsg == 4) ? 1 : 0);
    }

    debug(F101,"cmkey table length","",n);
    debug(F101,"cmkey cmflgs","",cmflgs);
    debug(F101,"cmkey cc","",cc);

    while (1) {
	xc += cc;
	debug(F111,"cmkey gtword xc",atmbuf,xc);
	debug(F101,"cmkey gtword zz","",zz);

	switch (zz) {
	  case -10:			/* Timeout */
	    if (gtimer() < timelimit) {
		if (pmsg & 8)		/* 8 is for parsing HELP tokens */
		  zz = gtword(4);
		else
		  zz = gtword((pmsg == 4) ? 1 : 0);
		continue;
	    } else {
#ifdef IKSD
                extern int inserver;
                if (inserver) {
                    printf("\r\nIKSD IDLE TIMEOUT: %d sec\r\n", timelimit);
                    doexit(GOOD_EXIT,0);
                }
#endif /* IKSD */
		return(-10);
            }
	  case -5:
	    return(cmflgs = 0);
	  case -9:
	    printf("Command or field too long\n");
	  case -4:			/* EOF */
	  case -3:			/* Null Command/Quit/Timeout */
	  case -2:			/* Buffer overflow */
	  case -1:			/* Or user did some deleting. */
	    return(cmflgs = zz);


	  case 1:			/* CR */
	  case 0:			/* User terminated word with space */
	  case 4:			/* or switch ending in : or = */
	    wordlen = cc;		/* Length if no conversion */
	    if (cc == 0) {		/* Supply default if we got nothing */
		if ((wordlen = setatm(xdef,(zz == 4) ? 2 : 0)) < 0) {
		    printf("?Default too long\n");
		    return(-9);
		}
	    }
	    if (zz == 1 && cc == 0)	/* Required field missing */
	      return(-3);

	    if (f) {			/* If a conversion function is given */
		char * p2;
		zq = atxbuf;		/* apply it */
		p2 = atxbuf;
		atxn = CMDBL;
		if ((*f)(atmbuf,&zq,&atxn) < 0) return(-2);
		debug(F110,"cmkey atxbuf after *f",atxbuf,0);
		if (!*p2)		/* Supply default if we got nothing */
		  p2 = xdef;
		ckstrncpy(ppvnambuf,atmbuf,PPVLEN);
		if ((wordlen = setatm(p2,(zz == 4) ? 2 : 0)) < 0) {
		    printf("Evaluated keyword too long\n");
		    return(-9);
		}
#ifdef M_UNGW
		/*
		  This bit lets us save more than one "word".
		  For example, "define \%x echo one two three", "\%x".
		  It works too, but it breaks labels, and therefore
		  WHILE and FOR loops, etc.
		*/
		if (p2[wordlen] >= SP) {
		    p2 += wordlen;
		    while (*p2 == SP) p2++;
		    if (*p2) {
			ungword();
			pp = p2;
		    }
		}
#endif /* M_UNGW */
	    }
#ifdef COMMENT				/* ^^^ */
	    if (cmswitch && *atmbuf != '/') {
		if (pmsg & 1) {
		    bleep(BP_FAIL);
                    printf("?Not a switch - %s\n",atmbuf);
		}
		cmflgs = -2;
		return(-6);
	    }
#endif	/* COMMENT */
	    if (cmswitch) {
		int i;
		for (i = 0; i < wordlen; i++) {
		    if (atmbuf[i] == ':' || atmbuf[i] == '=') {
			brkchar = atmbuf[i];
			atmbuf[i] = NUL;
			break;
		    }
		}
	    }

#ifdef TOKPRECHECK
/* This was an effective optimization but it breaks sometimes on labels. */
	    if (tl && !isalpha(atmbuf[0])) { /* Precheck for token */
		for (i = 0; i < tl; i++) { /* Save function call to ckstrchr */
		    if (tok[i] == atmbuf[0]) {
			debug(F000,"cmkey token:",atmbuf,*atmbuf);
			ungword();  /* Put back the following word */
			return(-5); /* Special return code for token */
		    }
		}
	    }
#endif /* TOKPRECHECK */

	    y = lookup(table,atmbuf,n,&z); /* Look up word in the table */
	    debug(F111,"cmkey lookup",atmbuf,y);
	    debug(F101,"cmkey zz","",zz);
	    debug(F101,"cmkey cmflgs","",cmflgs);
	    debug(F101,"cmkey crflag","",crflag);
	    switch (y) {
	      case -3:			/* Nothing to look up */
		break;
	      case -2:			/* Ambiguous */
		cmflgs = -2;
		if (pmsg & 1) {
		    bleep(BP_FAIL);
                    printf("?Ambiguous - %s\n",atmbuf);
		    return(-9);
		}
		return(-2);
	      case -1:			/* Not found at all */
#ifndef TOKPRECHECK
		if (tl) {
		    for (i = 0; i < tl; i++) /* Check for token */
		      if (tok[i] == *atmbuf) { /* Got one */
			  debug(F000,"cmkey token:",atmbuf,*atmbuf);
			  ungword();  /* Put back the following word */
			  return(-5); /* Special return code for token */
		      }
		}
#endif /* TOKPRECHECK */

		if (tl == 0) {		/* No tokens were included */
#ifdef OS2
		    /* In OS/2 and Windows, allow for a disk letter like DOS */
		    if (isalpha(*atmbuf) && *(atmbuf+1) == ':')
		      return(-7);
#endif /* OS2 */
		    if ((pmsg & 1) && !quiet) {
			bleep(BP_FAIL);
			printf("?No keywords match - %s\n",atmbuf); /* cmkey */
		    }
		    return(cmflgs = -9);
		} else {
		    if (cmflgs == 1 || cmswitch) /* cmkey2 or cmswi */
		      return(cmflgs = -6);
		    else
		      return(cmflgs = -2);
		    /* The -6 code is to let caller try another table */
		}
		break;
	      default:
#ifdef CK_RECALL
		if (test(table[z].flgs,CM_NOR)) no_recall = 1;
#endif /* CK_RECALL */
		if (zz == 4)
		  swarg = 1;
		cmkwflgs = table[z].flgs;
		break;
	    }
	    return(y);

	  case 2:			/* User terminated word with ESC */
	    debug(F101,"cmkey Esc cc","",cc);
            if (cc == 0) {
		if (*xdef != NUL) {     /* Nothing in atmbuf */
		    printf("%s ",xdef); /* Supply default if any */
#ifdef GEMDOS
		    fflush(stdout);
#endif /* GEMDOS */
		    addbuf(xdef);
		    if (setatm(xdef,0) < 0) {
			printf("?Default too long\n");
			return(-9);
		    }
		    inword = cmflgs = 0;
		    debug(F111,"cmkey: default",atmbuf,cc);
		} else {
		    debug(F101,"cmkey Esc pmsg","",0);
#ifdef COMMENT
/*
  Chained FDBs...  The idea is that this function might not have a default,
  but the next one might.  But if it doesn't, there is no way to come back to
  this one.  To be revisited later...
*/
		    if (xcmfdb)		/* Chained fdb -- try next one */
		      return(-3);
#endif /* COMMENT */
		    if (pmsg & (1|4)) {	/* So for now just beep */
			bleep(BP_WARN);
		    }
		    break;
		}
            }
	    if (f) {			/* If a conversion function is given */
		char * pp;
		zq = atxbuf;		/* apply it */
		pp = atxbuf;
		atxn = CMDBL;
		if ((*f)(atmbuf,&zq,&atxn) < 0)
		  return(-2);
		if (!*pp)
		  pp = xdef;
		if (setatm(pp,0) < 0) {
		    printf("Evaluated keyword too long\n");
		    return(-9);
		}
	    }
	    y = lookup(table,atmbuf,n,&z); /* Something in atmbuf */
	    debug(F111,"cmkey lookup y",atmbuf,y);
	    debug(F111,"cmkey lookup z",atmbuf,z);
	    if (y == -2 && z >= 0 && z < n) { /* Ambiguous */
#ifndef NOPARTIAL
		int j, k, len = 9999;	/* Do partial completion */
		/* Skip past any abbreviations in the table */
		for ( ; z < n; z++) {
		    if ((table[z].flgs & CM_ABR) == 0)
		      break;
		    if (!(table[z].flgs & CM_HLP) || (pmsg & 2))
		      break;
		}
		debug(F111,"cmkey partial z",atmbuf,z);
		debug(F111,"cmkey partial n",atmbuf,n);
		for (j = z+1; j < n; j++) {
		    debug(F111,"cmkey partial j",table[j].kwd,j);
		    if (ckstrcmp(atmbuf,table[j].kwd,cc,0))
		      break;
		    if (table[j].flgs & CM_ABR)
		      continue;
		    if ((table[j].flgs & CM_HLP) && !(pmsg & 2))
		      continue;
		    k = ckstrpre(table[z].kwd,table[j].kwd);
		    debug(F111,"cmkey partial k",table[z].kwd,k);
		    if (k < len)
		      len = k; /* Length of longest common prefix */
		}
		debug(F111,"cmkey partial len",table[z].kwd,len);
		if (len != 9999 && len > cc) {
		    ckstrncat(atmbuf,table[z].kwd+cc,ATMBL);
		    atmbuf[len] = NUL;
		    printf("%s",atmbuf+cc);
		    ckstrncat(cmdbuf,atmbuf+cc,CMDBL);
		    xc += (len - cc);
		    cc = len;
		}
#endif /* NOPARTIAL */
		bleep(BP_WARN);
		break;
	    } else if (y == -3) {
		bleep(BP_WARN);
		break;
	    } else if (y == -1) {	/* Not found */
		if ((pmsg & 1) && !quiet) {
		    bleep(BP_FAIL);
		    printf("?No keywords match - \"%s\"\n",atmbuf);
		}
		cmflgs = -2;
		return(-9);
	    }
/*
  If we found it, but it's a help-only keyword and the "help" bit is not
  set in pmsg, then not found.
*/
	    debug(F101,"cmkey flgs","",table[z].flgs);
	    if (test(table[z].flgs,CM_HLP) && ((pmsg & 2) == 0)) {
		if ((pmsg & 1) && !quiet) {
		    bleep(BP_FAIL);
		    printf("?No keywords match - %s\n",atmbuf);
		}
		cmflgs = -2;
		return(-9);
	    }
/*
  See if the keyword just found has the CM_ABR bit set in its flgs field, and
  if so, search forwards in the table for a keyword that has the same kwval
  but does not have CM_ABR (or CM_INV?) set, and then expand using the full
  keyword.  WARNING: This assumes that (a) keywords are in alphabetical order,
  and (b) the CM_ABR bit is set only if the the abbreviated keyword is a true
  abbreviation (left substring) of the full keyword.
*/
	    if (test(table[z].flgs,CM_ABR)) {
		int zz;
		for (zz = z+1; zz < n; zz++)
		  if ((table[zz].kwval == table[z].kwval) &&
		      (!test(table[zz].flgs,CM_ABR)) &&
		      (!test(table[zz].flgs,CM_INV))) {
		      z = zz;
		      break;
		  }
	    }
	    xp = table[z].kwd + cc;
	    if (cmswitch && test(table[z].flgs,CM_ARG)) {
#ifdef VMS
		printf("%s=",xp);
		brkchar = '=';
#else
		printf("%s:",xp);
		brkchar = ':';
#endif /* VMS */
	    } else {
		printf("%s ",xp);
		brkchar = SP;
	    }
#ifdef CK_RECALL
	    if (test(table[z].flgs,CM_NOR)) no_recall = 1;
#endif /* CK_RECALL */
	    cmkwflgs = table[z].flgs;
#ifdef GEMDOS
	    fflush(stdout);
#endif /* GEMDOS */
	    addbuf(xp);
	    if (cmswitch && test(table[z].flgs,CM_ARG)) {
		bp--;			/* Replace trailing space with : */
#ifdef VMS
		*bp++ = '=';
#else
		*bp++ = ':';
#endif /* VMS */
		*bp = NUL;
		np = bp;
		swarg = 1;
	    }
	    inword = 0;
	    cmflgs = 0;
	    debug(F110,"cmkey: addbuf",cmdbuf,0);
	    return(y);

	  case 3:			/* User typed "?" */
	    if (f) {			/* If a conversion function is given */
		char * pp;
		zq = atxbuf;		/* do the conversion now. */
		pp = atxbuf;
		atxn = CMDBL;
		if ((*f)(atmbuf,&zq,&atxn) < 0) return(-2);
		if (setatm(pp,0) < 0) {
		    printf("?Evaluated keyword too long\n");
		    return(-9);
		}
	    }
	    y = lookup(table,atmbuf,n,&z); /* Look up what we have so far. */
	    if (y == -1) {
		/*
		  Strictly speaking if the main keyword table search fails,
		  then we should look in the token table if one is given.
		  But in practice, tokens are also included in the main
		  keyword table.
		*/
		cmflgs = -2;
		if ((pmsg & 1) && !quiet) {
		    bleep(BP_FAIL);
		    printf(" No keywords match\n");
		    return(-9);
		}
		return(-2);
	    }
#ifndef COMMENT
	    /* This is to allow ?-help to work immediately after a token */
	    /* without having to type an intermediate space */
	    if (tl) {
		for (i = 0; i < tl; i++) /* Check for token */
		  if (tok[i] == *atmbuf) { /* Got one */
		      debug(F000,"cmkey token:",atmbuf,*atmbuf);
		      ungword();	/* Put back the following word */
		      cmflgs = 3;	/* Force help next time around */
		      return(-5);	/* Special return code for token */
		  }
	    }
#endif /* COMMENT */

	    if (*xhlp == NUL)
	      printf(" One of the following:\n");
	    else
	      printf(" %s, one of the following:\n",xhlp);
	    {
		int x;
		x = pmsg & (2|4);	/* See kwdhelp() comments */
		if (atmbuf[0])		/* If not at beginning of field */
		  x |= 1;		/* also show invisibles */
		kwdhelp(table,n,atmbuf,"","",1,x);
	    }
#ifndef NOSPL
	    if (!havetoken) {
		extern int topcmd;
		if (tl > 0 && topcmd != XXHLP) /* This is bad... */
		  printf("or a macro name (\"do ?\" for a list) ");
	    }
#endif /* NOSPL */
	    if (*atmbuf == NUL && !havetoken) {
		if (tl == 1)
		  printf("or the token %c\n",*tok);
		else if (tl > 1)
		  printf("or one of the tokens: %s\n",ckspread(tok));
	    }
	    printf("%s%s", cmprom, cmdbuf);
	    fflush(stdout);
	    break;

	  default:
	    printf("\n%d - Unexpected return code from gtword\n",zz);
	    return(cmflgs = -2);
	}
	zz = (pmsg & 8) ? gtword(4) : gtword((pmsg == 4) ? 1 : 0);
	debug(F111,"cmkey gtword zz",atmbuf,zz);
    }
}

int
chktok(tlist) char *tlist; {
    char *p;
    p = tlist;
    while (*p != NUL && *p != *atmbuf) p++;
    return((*p) ? (int) *p : 0);
}

/* Routines for parsing and converting dates and times */

#define isdatesep(c) (ckstrchr(" -/._",c))

#define CMDATEBUF 1024
char cmdatebuf[CMDATEBUF+4] = { NUL, NUL };
static char * cmdatebp = cmdatebuf;
char * cmdatemsg = NULL;

static struct keytab timeunits[] = {
    { "days",   TU_DAYS,   0 },
    { "months", TU_MONTHS, 0 },
    { "weeks",  TU_WEEKS,  0 },
    { "wks",    TU_WEEKS,  0 },
    { "years",  TU_YEARS,  0 },
    { "yrs",    TU_YEARS,  0 }
};
static int nunits = (sizeof(timeunits) / sizeof(struct keytab));

#define SYM_NOW  0
#define SYM_TODA 1
#define SYM_TOMO 2
#define SYM_YEST 3

static struct keytab symdaytab[] = {
    { "now",       SYM_NOW,  0 },
    { "today",     SYM_TODA, 0 },
    { "tomorrow",  SYM_TOMO, 0 },
    { "yesterday", SYM_YEST, 0 }
};
static int nsymdays = (sizeof(symdaytab) / sizeof(struct keytab));

static struct keytab daysofweek[] = {
    { "Friday",    5, 0 },
    { "Monday",    1, 0 },
    { "Saturday",  6, 0 },
    { "Sunday",    0, 0 },
    { "Thursday",  4, 0 },
    { "Tuesday",   2, 0 },
    { "Wednesday", 3, 0 }
};

static struct keytab usatz[] = {	/* RFC 822 timezones  */
    { "cdt",  5, 0 },			/* Values are GMT offsets */
    { "cst",  6, 0 },
    { "edt",  4, 0 },
    { "est",  5, 0 },
    { "gmt",  0, 0 },
    { "mdt",  6, 0 },
    { "mst",  7, 0 },
    { "pdt",  7, 0 },
    { "pst",  8, 0 },
    { "utc",  0, 0 },
    { "zulu", 0, 0 }
};
static int nusatz = (sizeof(usatz) / sizeof(struct keytab));


/*  C M C V T D A T E  --  Converts free-form date to standard form.  */

/*
   Call with
     s = pointer to free-format date, time, or date and time.
     t = 0: return time only if time was given in s.
     t = 1: always return time (00:00:00 if no time given in s).
     t = 2: allow time to be > 24:00:00.
   Returns:
     NULL on failure;
     Pointer to "yyyymmdd hh:mm:ss" (local date-time) on success.
*/

/*
  Before final release the following long lines should be wrapped.
  Until then we leave them long since wrapping them wrecks EMACS's
  C indentation.
*/

/* asctime pattern */
static char * atp1 = "[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]";

/* asctime pattern with timezone */
static char * atp2 = "[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [A-Z][A-Z][A-Z] [0-9][0-9][0-9][0-9]";

#define DATEBUFLEN 127
#define YYYYMMDD 12

#define isleap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
static int mdays[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

#define NEED_DAYS 1
#define NEED_HRS  2
#define NEED_MINS 3
#define NEED_SECS 4
#define NEED_FRAC 5

#define DELTABUF 256
static char deltabuf[DELTABUF];
static char * deltabp = deltabuf;

char *
cmdelta(yy, mo, dd, hh, mm, ss, sign, dyy, dmo, ddd, dhh, dmm, dss)
    int yy, mo, dd, hh, mm, ss, sign, dyy, dmo, ddd, dhh, dmm, dss;
/* cmdelta */ {
    int zyy, zmo, zdd, zhh, zmm, zss;
    long t1, t2, t3, t4;
    long d1 = 0, d2, d3;
    char datebuf[DATEBUFLEN+1];

#ifdef DEBUG
    if (deblog) {
	debug(F101,"cmdelta yy","",yy);
	debug(F101,"cmdelta mo","",mo);
	debug(F101,"cmdelta dd","",dd);
	debug(F101,"cmdelta hh","",hh);
	debug(F101,"cmdelta mm","",mm);
	debug(F101,"cmdelta ss","",ss);
	debug(F101,"cmdelta sign","",sign);
	debug(F101,"cmdelta dyy","",dyy);
	debug(F101,"cmdelta dmo","",dmo);
	debug(F101,"cmdelta ddd","",ddd);
	debug(F101,"cmdelta dhh","",dhh);
	debug(F101,"cmdelta dmm","",dmm);
	debug(F101,"cmdelta dss","",dss);
    }
#endif /* DEBLOG */

    if (yy < 0 || yy > 9999) {
	makestr(&cmdatemsg,"Base year out of range");
	debug(F111,"cmdelta",cmdatemsg,-1);
	return(NULL);
    }
    if (mo < 1 || mo > 12) {
	makestr(&cmdatemsg,"Base month out of range");
	debug(F111,"cmdelta",cmdatemsg,-1);
	return(NULL);
    }
    if (dd < 1 || dd > mdays[mo]) {
	makestr(&cmdatemsg,"Base day out of range");
	debug(F111,"cmdelta",cmdatemsg,-1);
	return(NULL);
    }
    if (hh < 0 || hh > 23) {
	makestr(&cmdatemsg,"Base hour out of range");
	debug(F111,"cmdelta",cmdatemsg,-1);
	return(NULL);
    }
    if (mm < 0 || mm > 59) {
	makestr(&cmdatemsg,"Base minute out of range");
	debug(F111,"cmdelta",cmdatemsg,-1);
	return(NULL);
    }
    if (ss < 0 || ss > 60) {
	makestr(&cmdatemsg,"Base second out of range");
	debug(F111,"cmdelta",cmdatemsg,-1);
	return(NULL);
    }
    sign = (sign < 0) ? -1 : 1;
    if (dmo != 0) {
        if (sign > 0) {
            mo += (sign * dmo);
            if (mo > 12) {
                yy += mo / 12;
                mo = mo % 12;
            }
        } else if (sign < 0) {
            while (dmo > 12) {
                yy--;
                dmo -= 12;
            }
            if (dmo < mo) {
                mo -= dmo;
            } else {
                yy--;
                mo = 12 - (dmo - mo);
            }
        }
    }
    if (dyy != 0) {
	yy += (sign * dyy);
	if (yy > 9999 || yy < 0) {
	    makestr(&cmdatemsg,"Result year out of range");
	    debug(F111,"cmdelta",cmdatemsg,-1);
	    return(NULL);
	}
    }
    sprintf(datebuf,"%04d%02d%02d %02d:%02d:%02d",yy,mo,dd,hh,mm,ss);
    d1 = mjd(datebuf);
    debug(F111,"cmdelta mjd",datebuf,d1);    

    t1 = hh * 3600 + mm * 60 + ss;	/* Base time to secs since midnight */
    t2 = dhh * 3600 + dmm * 60 + dss;	/* Delta time, ditto */
    t3 = t1 + (sign * t2);		/* Get sum (or difference) */
    
    d2 = (sign * ddd);			/* Delta days */
    d2 += t3 / 86400L;

    t4 = t3 % 86400L;			/* Fractional part of day */
    if (t4 < 0) {			/* If negative */
	d2--;				/* one less delta day */
	t4 += 86400L;			/* get positive seconds */
    }
    hh = (int) (t4 / 3600L);
    mm = (int) (t4 % 3600L) / 60;
    ss = (int) (t4 % 3600L) % 60;

    sprintf(datebuf,"%s %02d:%02d:%02d", mjd2date(d1+d2),hh,mm,ss);
    {
	int len, k, n;
	char * p;
	len = strlen(datebuf);
	k = deltabp - (char *)deltabuf;	/* Space used */
	n = DELTABUF - k - 1;		/* Space left */
	if (n < len) {			/* Not enough? */
	    deltabp = deltabuf;		/* Wrap around */
	    n = DELTABUF;
	}
	ckstrncpy(deltabp,datebuf,n);
	p = deltabp;
	deltabp += len + 1;
	return(p);
    }
}


/* Convert Delta Time to Seconds */

int
delta2sec(s,result) char * s; long * result; {
    long ddays = 0L, zz;
    int dsign = 1, dhours = 0, dmins = 0, dsecs = 0, units;
    int state = NEED_DAYS;
    char *p, *p2, *p3, c = 0;
    char buf[64];

    if (!s) s = "";
    if (!*s)
      return(-1);
    if ((int)strlen(s) > 63)
      return(-1);
    ckstrncpy(buf,s,64);
    p = buf;

    if (*p != '+' && *p != '-')
      return(-1);

    if (*p++ == '-')
      dsign = -1;
    while (*p == SP)			/* Skip intervening spaces */
      p++;

    while (state) {			/* FSA to parse delta time */
	if (state < 0 || !isdigit(*p))
	  return(-1);
	p2 = p;				/* Get next numeric field */
	while (isdigit(*p2))
	  p2++;
	c = *p2;			/* And break character */
	*p2 = NUL;			/* Terminate the number */
	switch (state) {		/* Interpret according to state */
	  case NEED_DAYS:		/* Initial */
	    if ((c == '-') ||		/* VMS format */
		((c == 'd' || c == 'D')
		 && !isalpha(*(p2+1)))) { /* Days */
		ddays = atol(p);
		if (!*(p2+1))			
		  state = 0;
		else			/* if anything is left */
		  state = NEED_HRS;	/* now we want hours. */
	    } else if (c == ':') {	/* delimiter is colon */
		dhours = atoi(p);	/* so it's hours */
		state = NEED_MINS;	/* now we want minutes */
	    } else if (!c) {		/* end of string */
		dhours = atoi(p);	/* it's still hours */
		state = 0;		/* and we're done */
	    } else if (isalpha(c) || c == SP) {
		if (c == SP) {		/* It's a keyword? */
		    p2++;		/* Skip spaces */
		    while (*p2 == SP)
		      p2++;
		} else {		/* or replace first letter */
		    *p2 = c;
		}
		p3 = p2;		/* p2 points to beginning of keyword */
		while (isalpha(*p3))	/* Find end of keyword */
		  p3++;
		c = *p3;		/* NUL it out so we can look it up */
		if (*p3)		/* p3 points to keyword terminator */
		  *p3 = NUL;
		if ((units = lookup(timeunits,p2,nunits,NULL)) < 0)
		  return(-1);
		*p2 = NUL;		/* Re-terminate the number */
		*p3 = c;
		while (*p3 == SP)	/* Point at field after units */
		  p3++;
		p2 = p3;
		switch (units) {
		  case TU_DAYS:
		    ddays = atol(p);
		    break;
		  default:
		    return(-1);
		}
		if (*p2) {
		    state = NEED_HRS;
		    p2--;
		} else
		  state = 0;
	    } else {			/* Anything else */
		state = -1;		/* is an error */
	    }
	    break;
	  case NEED_HRS:		/* Looking for hours */
	    if (c == ':') {
		dhours = atoi(p);
		state = NEED_MINS;
	    } else if (!c) {
		dhours = atoi(p);
		state = 0;
	    } else {
		state = -1;
	    }
	    break;
	  case NEED_MINS:		/* Looking for minutes */
	    if (c == ':') {
		dmins = atoi(p);
		state = NEED_SECS;
	    } else if (!c) {
		dmins = atoi(p);
		state = 0;
	    } else {
		state = -1;
	    }
	    break;
	  case NEED_SECS:		/* Looking for seconds */
	    if (c == '.') {
		dsecs = atoi(p);
		state = NEED_FRAC;
	    } else if (!c) {
		dsecs = atoi(p);
		state = 0;
	    } else {
		state = -1;
	    }
	    break;
	  case NEED_FRAC:		/* Fraction of second */
	    if (!c && rdigits(p)) {
		if (*p > '4')
		  dsecs++;
		state = 0;
	    } else {
		state = -1;
	    }
	    break;
	}
	if (c)				/* next field if any */
	  p = p2 + 1;
    }
    if (state < 0)
      return(-1);

    /* if days > 24854 and sizeof(long) == 32 we overflow */

    zz = ddays * 86400L;
    if (zz < 0L)			/* This catches it */
      return(-2);
    zz += dhours * 3600L + dmins * 60L + dsecs;
    zz *= dsign;
    *result = zz;
    return(0);
}


char *
cmcvtdate(s,t) char * s; int t; {
    int x, i, j, k, hh, mm, ss, ff, pmflag = 0, nodate = 0, len, dow;
    int units, isgmt = 0, gmtsign = 0, d = 0, state = 0, nday;
    int kn = 0, ft[8], isletter = 0, f2len = 0;

    int zhh = 0;			/* Timezone adjustments */
    int zmm = 0;
    int zdd = 0;

    int dsign = 1;			/* Delta-time adjustments */
    int ddays = 0;
    int dmonths = 0;
    int dyears = 0;
    int dhours = 0;
    int dmins = 0;
    int dsecs = 0;
    int havedelta = 0;

    char * fld[8], * p = "", * p2, * p3; /* Assorted buffers and pointers  */
    char * s2, * s3;
    char * year = NULL, * month = NULL, * day = NULL;
    char * hour = "00", * min = "00", * sec = "00";
    char datesep = 0;
    char tmpbuf[8];
    char xbuf[DATEBUFLEN+1];
    char ybuf[DATEBUFLEN+1];
    char zbuf[DATEBUFLEN+1];
    char yyyymmdd[YYYYMMDD];
    char dbuf[26];
    char daybuf[3];
    char monbuf[3];
    char yearbuf[5];
    char timbuf[16], *tb, cc;
    char * dp = NULL;			/* Result pointer */

    if (!s) s = "";
    tmpbuf[0] = NUL;

    while (*s == SP) s++;		/* Gobble any leading blanks */
    if (isalpha(*s))			/* Remember if 1st char is a letter */
      isletter = 1;

    len = strlen(s);
    debug(F110,"cmcvtdate",s,len);
    if (len == 0) {			/* No arg - return current date-time */
	dp = ckdate();
	goto xcvtdate;
    }
    if (len > DATEBUFLEN) {		/* Check length of arg */
	makestr(&cmdatemsg,"Date-time string too long");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    hh = 0;				/* Init time to 00:00:00.0 */
    mm = 0;
    ss = 0;
    ff = 0;
    ztime(&p);
    if (!p)
      p  = "";
    if (*p) {				/* Init time to current time */
	x = ckstrncpy(dbuf,p,26);
	if (x > 17) {
	    hh = atoi(&dbuf[11]);
	    mm = atoi(&dbuf[14]);
	    ss = atoi(&dbuf[17]);
	}
    }
    ckstrncpy(yyyymmdd,zzndate(),YYYYMMDD); /* Init date to current date */
    ckstrncpy(yearbuf,yyyymmdd,5);
    ckstrncpy(monbuf,&yyyymmdd[4],3);
    ckstrncpy(daybuf,&yyyymmdd[6],3);
    year = yearbuf;
    month = monbuf;
    day = daybuf;
    nday = atoi(daybuf);
    ckstrncpy(xbuf,s,DATEBUFLEN);	/* Make a local copy we can poke */
    s = xbuf;				/* Point to it */
    s[len] = NUL;
    if (s[0] == ':') {
	p = s;
	goto dotime;
    }
    /* Special preset formats... */

    if (len >= 14) {			/* FTP MDTM all-numeric date */
	char c;
	c = s[14];			/* e.g. 19980615100045.014 */
	s[14] = NUL;
	x = rdigits(s);
	s[14] = c;
	if (x) {
	    ckstrncpy(yyyymmdd,s,8+1);
	    year = NULL;
	    p = &s[8];
	    goto dotime;
	}
    }
    x = 0;				/* Becomes > 0 for asctime format */
    if (isalpha(s[0])) {
	if (len == 24) {		/* Asctime format? */
	    /* Sat Jul 14 15:57:32 2001 */
	    x = ckmatch(atp1,s,0,0);
	    debug(F111,"cmcvtdate asctime",s,x);
	} else if (len == 28) {		/* Or Asctime plus timezone? */
	    /* Sat Jul 14 15:15:39 EDT 2001 */
	    x = ckmatch(atp2,s,0,0);
	    debug(F111,"cmcvtdate asctime+timezone",s,x);
	}
    }
    if (x > 0) {			/* Asctime format */
        int xx;
        strncpy(yearbuf,s + len - 4,4);
        yearbuf[4] = NUL;
        for (i = 0; i < 3; i++)
          tmpbuf[i] = s[i+4];
        tmpbuf[3] = NUL;
	if ((xx = lookup(cmonths,tmpbuf,12,NULL)) < 0) {
	    makestr(&cmdatemsg,"Invalid month");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
        debug(F101,"cmcvtdate asctime month","",xx);
        monbuf[0] = (xx / 10) + '0'; 
        monbuf[1] = (xx % 10) + '0'; 
        monbuf[2] = NUL;
        daybuf[0] = (s[8] == ' ' ? '0' : s[8]);
        daybuf[1] = s[9];
        daybuf[2] = NUL;
	xbuf[0] = SP;
        for (i = 11; i < 19; i++)
          xbuf[i-10] = s[i];
        xbuf[9] = NUL;
	ckmakmsg(zbuf,18,yearbuf,monbuf,daybuf,xbuf);
	debug(F110,"cmcvtdate asctime ok",zbuf,0);
	if (len == 24) {
	    dp = zbuf;
	    goto xcvtdate;
	} else {
	    int n;
	    n = ckmakmsg(ybuf,DATEBUFLEN-4,zbuf," ",NULL,NULL);
	    ybuf[n++] = s[20];
	    ybuf[n++] = s[21];
	    ybuf[n++] = s[22];
	    ybuf[n++] = NUL;
	    ckstrncpy(xbuf,ybuf,DATEBUFLEN);
	    s = xbuf;
	    isletter = 0;
	}
    }

/* Check for day of week */

    p = s;
    while (*p == SP) p++;
    dow = -1;
    if (*p) {
	p2 = p;
	cc = NUL;
	while (1) {
	    if (*p2 == ',' || *p2 == SP || !*p2) {
		cc = *p2;		/* Save break char */
		*p2 = NUL;		/* NUL it out */
		p3 = p2;		/* Remember this spot */
		if ((dow = lookup(daysofweek,p,7,NULL)) > -1) {
		    debug(F111,"cmcvtdate dow",p,dow);
		    s = p2;
		    if (cc == ',' || cc == SP) { /* Point to next field */
			s++;
			while (*s == SP) s++;
		    }
		    p = s;
		    debug(F111,"cmcvtdate dow new p",p,dow);
		    break;
		} else if (isalpha(*p) && cc == ',') {
		    makestr(&cmdatemsg,"Unrecognized day of week");
		    debug(F111,"cmcvtdate",cmdatemsg,-1);
		    return(NULL);
		} else {
		    *p3 = cc;
		    break;
		}
	    }
	    p2++;
	}
    }
    len = strlen(s);		/* Update length */
    debug(F111,"cmcvtdate s",s,len);

    debug(F111,"cmcvtdate dow",s,dow);
    if (dow > -1) {			/* Have a day-of-week number */
	long zz; int n, j;
	zz = mjd(zzndate());		/* Get today's MJD */
	debug(F111,"cmcvtdate zz","",zz);
	j = (((int)(zz % 7L)) + 3) % 7; /* Today's day-of-week number */
	debug(F111,"cmcvtdate j","",j);
	hh = 0;				/* Init time to midnight */
	mm = 0;
	ss = 0;
	if (j == dow) {
	    ckstrncpy(yyyymmdd,zzndate(),YYYYMMDD);
	    year = NULL;
	} else {
	    n = dow - j;		/* Days from now */
	    if (dow < j)
	      n += 7;
	    if (n < 0) n += 7;		/* Add to MJD */
	    zz += n;
	    ckstrncpy(yyyymmdd,mjd2date(zz),YYYYMMDD); /* New date */
	    year = NULL;
	}
	debug(F111,"cmcvtdate A",yyyymmdd,len);
	if (len == 0) {			/* No more fields after this */
	    ckmakmsg(zbuf,18,yyyymmdd," 00:00:00",NULL,NULL);
	    dp = zbuf;
	    goto xcvtdate;
	}
	isletter = 0;
	if (rdigits(p) && len < 8)	/* Next field is time? */
	  goto dotime;			/* If so go straight to time section */
	if (isdigit(*p)) {
	    if (*(p+1) == ':')
	      goto dotime;
	    else if (isdigit(*(p+1)) && (*(p+2) == ':'))
	      goto dotime;
	}
    }
    debug(F111,"cmcvtdate B s",s,dow);
    debug(F111,"cmcvtdate B p",p,dow);

    if (*s == '+' || *s == '-') {	/* Delta time only - skip ahead. */
	p = s;
	goto delta;
    }
#ifdef COMMENT
/*
  What is the purpose of this?  It breaks parsing of email dates like
  "Wed, 13 Feb 2002 17:43:02 -0800 (PST)".  Removing this code fixes the
  problem and Kermit still passes the 'dates' script.
  - fdc, Sat Nov 26 10:52:45 2005.
*/
    if (dow > -1) {
	/* Day of week given followed by something that is not a time */
	/* or a delta so it can't be valid */
	makestr(&cmdatemsg,"Invalid tokens after day of week");
	debug(F111,"cmcvtdate fail",cmdatemsg,-1);
	return(NULL);
    }
#endif	/* COMMENT */

    /* Handle "today", "yesterday", "tomorrow", and +/- n units */

    if (ckstrchr("TtYyNn",s[0])) {
	int i, k, n, minus = 0;
	char c;
	long jd;
	jd = mjd(ckdate());
	debug(F111,"cmcvtdate mjd",s,jd);

	/* Symbolic date: TODAY, TOMORROW, etc...? */

	s2 = s;				/* Find end of keyword */
	i = 0;
	while (isalpha(*s2)) {		/* and get its length */
	    i++;
	    s2++;
	}
	c = *s2;			/* Zap but save delimiter */
	*s2 = NUL;
	k = lookup(symdaytab,s,nsymdays,NULL); /* Look up keyword */
	*s2 = c;			/* Replace delimiter */
	if (k < 0)			/* Keyword not found */
	  goto normal;
	s3 = &s[i];
	while (*s3 == SP)		/* Skip whitespace */
	  s3++;
	if (*s3 == '_' || *s3 == ':')
	  s3++;

	switch (k) {			/* Have keyword */
	  case SYM_NOW:			/* NOW */
	    ckstrncpy(ybuf,ckdate(),DATEBUFLEN);
	    ckstrncpy(yyyymmdd,ybuf,YYYYMMDD);
	    year = NULL;
	    if (*s3) {			/* No overwriting current time. */
		ckstrncat(ybuf," ",DATEBUFLEN);
		ckstrncat(ybuf,s3,DATEBUFLEN);
	    }
	    break;
	  default:			/* Yesterday, Today, and Tomorrow */
	    if (k == SYM_TOMO) {	/* TOMORROW */
		strncpy(ybuf,mjd2date(jd+1),8);
	    } else if (k == SYM_YEST) {	/* YESTERDAY */
		strncpy(ybuf,mjd2date(jd-1),8);
	    } else {			/* TODAY */
		strncpy(ybuf,ckdate(),8);
	    }
	    strncpy(ybuf+8," 00:00:00",DATEBUFLEN-8); /* Default time is 0 */
	    ckstrncpy(yyyymmdd,ybuf,YYYYMMDD);
	    year = NULL;
	    if (*s3) {			/* If something follows keyword... */
		if (isdigit(*s3)) {	/* Time - overwrite default time */
		    strncpy(ybuf+8,s+i,DATEBUFLEN-8);
		} else {		/* Something else, keep default time */
		    ckstrncat(ybuf," ",DATEBUFLEN); /* and append */
		    ckstrncat(ybuf,s3,DATEBUFLEN); /* whatever we have */
		}
	    }
	}
	s = ybuf;			/* Point to rewritten date-time */
	len = strlen(s);		/* Update length */
	isletter = 0;			/* Cancel this */
    }

/* Regular free-format non-symbolic date */

  normal:

    debug(F111,"cmcvtdate NORMAL",s,len);
    debug(F111,"cmcvtdate dow",s,dow);
    if (yyyymmdd[0] && !year) {
	ckstrncpy(yearbuf,yyyymmdd,5);
	ckstrncpy(monbuf,&yyyymmdd[4],3);
	ckstrncpy(daybuf,&yyyymmdd[6],3);
	year = yearbuf;
	month = monbuf;
	day = daybuf;
	nday = atoi(daybuf);
    }
    if (isdigit(s[0])) {		/* Time without date? */
	p = s;
	if (s[1] == ':') {
	    debug(F111,"cmcvtdate NORMAL X1",s,len);
	    goto dotime;
	} else if (len > 1 && isdigit(s[1]) && s[2] == ':') {
	    debug(F111,"cmcvtdate NORMAL X2",s,len);
	    goto dotime;
	} else if (rdigits(s) && len < 8) {
	    debug(F111,"cmcvtdate NORMAL X3",s,len);
	    goto dotime;
	}
    }
    if (len >= 8 && isdigit(*s)) {	/* Check first for yyyymmdd* */
	debug(F111,"cmcvtdate NORMAL A",s,len);
	cc = s[8];
	s[8] = NUL;			/* Isolate first 8 characters */
	if (rdigits(s)) {
	    /* Have valid time separator? */
	    p2 = cc ? ckstrchr(" Tt_-:",cc) : NULL;
	    if (!cc || p2) {
		ckstrncpy(yyyymmdd,s,YYYYMMDD);	/* Valid separator */
		year = NULL;
		s += 8;			        /* or time not given */
		if (cc) s++;		        /* Keep date */
		p = s;			        /* and go handle time */
		goto dotime;
	    } else if (!p2) {
		if (isdigit(cc))
		  makestr(&cmdatemsg,"Numeric date too long");
		else
		  makestr(&cmdatemsg,"Invalid date-time separator");
		debug(F111,"cmcvtdate",cmdatemsg,-1);
		return(NULL);
	    }
	}
	s[8] = cc;			/* Put this back! */
    }
    debug(F111,"cmcvtdate NORMAL non-yyyymmdd",s,len);

    /* Free-format date -- figure it out */

#ifdef COMMENT
    if (*s && !isdigit(*s)) {
	makestr(&cmdatemsg,"Unrecognized word in date");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
#endif /* COMMENT */
    for (i = 0; i < 8; i++)		/* Field types */
      ft[i] = -1;
    fld[i = 0] = (p = s);		/* First field */
    while (*p) {			/* Get next two fields */
	if (isdatesep(*p)) {		/* Have a date separator */
	    if (i == 0) {
		datesep = *p;
	    } else if (i == 1 && *p != datesep) {
		makestr(&cmdatemsg,"Inconsistent date separators");
		debug(F111,"cmcvtdate",cmdatemsg,-1);
		return(NULL);
	    }
	    *p++ = NUL;			/* Replace by NUL */
	    if (*p) {			/* Now we're at the next field */
		while (*p == SP) p++;	/* Skip leading spaces */
		if (!*p) break;		/* Make sure we still have something */
		if (i == 2)		/* Last one? */
		  break;
		fld[++i] = p;		/* No, record pointer to this one */
	    } else {
		break;
	    }	    
	} else if ((*p == 'T' || *p == 't') && isdigit(*(p+1))) { /* Time */
	    *p++ = NUL;
	    break;
	} else if (*p == ':') {
	    if (i == 0 && p == s) {
		nodate = 1;
		break;
	    } else if (i != 0) {	/* After a date */
		if (i == 2) {		/* OK as date-time separator (VMS) */
		    *p++ = NUL;
		    break;
		}
		if (i < 2)
		  makestr(&cmdatemsg,"Too few fields in date");
		else
		  makestr(&cmdatemsg,"Misplaced time separator");
		debug(F111,"cmcvtdate",cmdatemsg,-1);
		return(NULL);
	    }
	    nodate = 1;			/* Or without a date */
	    break;
	}
	p++;
    }
    if (p > s && i == 0)		/* Make sure we have a date */
      nodate = 1;			/* No date. */

    if (nodate && dow > -1) {		/* Have implied date from DOW? */
	goto dotime;			/* Use, use that, go do time. */

    } else if (nodate) {		/* No date and no implied date */
	char *tmp = NULL;		/* Substitute today's date */
	ztime(&tmp);
	if (!tmp)
	  tmp  = "";
	if (!*tmp) {
	    makestr(&cmdatemsg,"Problem supplying current date");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
	ckstrncpy(dbuf,tmp,26);		/* Reformat */
	if (dbuf[8] == SP) dbuf[8] = '0';
	fld[0] = dbuf+8;		/* dd */
	dbuf[10] = NUL;
	fld[1] = dbuf+4;		/* mmm */
	dbuf[7] = NUL;
	fld[2] = dbuf+20;		/* yyyy */
	dbuf[24] = NUL;
	hh = atoi(&dbuf[11]);
	mm = atoi(&dbuf[14]);
	ss = atoi(&dbuf[17]);
	p = s;				/* Back up source pointer to reparse */
    } else if (i < 2) {
	makestr(&cmdatemsg,"Too few fields in date");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    /* Have three date fields - see what they are */

    for (k = 0, j = 0; j < 3; j++) {	/* Get number of non-numeric fields */
	ft[j] = rdigits(fld[j]);
	debug(F111,"cmcvtdate fld",fld[j],j);
	if (ft[j] == 0)
	  k++;
    }
    kn = k;				/* How many numeric fields */
    month = NULL;			/* Strike out default values */
    year = NULL;
    day = NULL;

    if (k == 2 && ft[2] > 0) {		/* Jul 20, 2001 */
	int xx;
	xx = strlen(fld[1]);
	p3 = fld[1];
	if (xx > 0) if (p3[xx-1] == ',') {
	    p3[xx-1] = NUL;
	    if (rdigits(p3)) {
		k = 1;	
		ft[1] = 1;
	    } else p3[xx-1] = ',';
	}
    }
    if (k > 1) {			/* We can have only one non-numeric */
	if (nodate)
	  makestr(&cmdatemsg,"Unrecognized word in date"); 
	else if (!ft[2] && isdigit(*(fld[2])))
	  makestr(&cmdatemsg,"Invalid date-time separator"); 
	else
	  makestr(&cmdatemsg,"Too many non-numeric fields in date");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    if (!ft[0]) {
	k = 0;
    } else if (!ft[1]) {
	k = 1;
    } else if (!ft[2]) {
	makestr(&cmdatemsg,"Non-digit in third date field");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    } else
      k = -1;

    if (k > -1) {
	if ((x = lookup(cmonths,fld[k],12,NULL)) < 0) {
	    makestr(&cmdatemsg,"Unknown month");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
	sprintf(tmpbuf,"%02d",x);
	month = tmpbuf;
    }
    f2len = strlen(fld[2]);		/* Length of 3rd field */

    if (k == 0) {			/* monthname dd, yyyy */
	day = fld[1];
	year = fld[2];
    } else if (((int)strlen(fld[0]) == 4)) { /* yyyy-xx-dd */
	year = fld[0];
	day = fld[2];
	if (!month)
	  month = fld[1];		/* yyyy-mm-dd */
    } else if (f2len == 4) {		/* xx-xx-yyyy */
	year = fld[2];
	if (month) {			/* dd-name-yyyy */
	    day = fld[0];
	} else {			/* xx-xx-yyyy */
	    int f0, f1;
	    f0 = atoi(fld[0]);
	    f1 = atoi(fld[1]);
	    if (((f0 > 12) && (f1 <= 12)) || (f1 <= 12 && f0 == f1)) {
		day = fld[0];		/* mm-dd-yyyy */
		month = fld[1];
	    } else if ((f0 <= 12) && (f1 > 12)) {
		if (!rdigits(fld[1])) {
		    makestr(&cmdatemsg,"Day not numeric");
		    debug(F111,"cmcvtdate",cmdatemsg,-1);
		    return(NULL);
		} else {
		    day = fld[1];	/* dd-mm-yyyy */
		}
		month = fld[0];
	    } else {
		if (!f0 || !f1)
		  makestr(&cmdatemsg,"Day or month out of range");
		else
		  makestr(&cmdatemsg,"Day and month are ambiguous");
		debug(F111,"cmcvtdate",cmdatemsg,-1);
		return(NULL);
	    }
	}
    } else if ((f2len < 4) &&		/* dd mmm yy (RFC822) */
	       !rdigits(fld[1]) &&	/* middle field is monthname */
	       rdigits(fld[2])) {
	int tmpyear;
	day = fld[0];
	if (!fld[2][1]) {
	    makestr(&cmdatemsg,"Too few digits in year");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
	tmpyear = atoi(fld[2]);
	if (tmpyear < 50)		/* RFC 2822 windowing */
	  tmpyear += 2000;
	else				/* This includes 3-digit years. */
	  tmpyear += 1900;
	year = ckitoa(tmpyear);

    } else if ((f2len < 4) && (k < 0) && ((int)strlen(fld[0]) < 4)) {
	makestr(&cmdatemsg,"Ambiguous numeric date");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    } else if ((f2len > 4) && ft[2]) {
	makestr(&cmdatemsg,"Too many digits in year");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    } else {
	makestr(&cmdatemsg,"Unexpected date format");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    x = atoi(month);
    sprintf(tmpbuf,"%02d",x);		/* 2-digit numeric month */

/*
   state = 1 = hours
   state = 2 = minutes
   state = 3 = seconds
   state = 4 = fractions of seconds
*/

  dotime:
    if (isletter && (s == p)) {
	makestr(&cmdatemsg,"Unknown date-time word");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    if (!year && yyyymmdd[0]) {
	debug(F110,"cmcvtdate dotime yyyymmdd",yyyymmdd,0);
	for (i = 0; i < 4; i++)
	  yearbuf[i] = yyyymmdd[i];
	yearbuf[4] = NUL;
	monbuf[0] = yyyymmdd[4];
	monbuf[1] = yyyymmdd[5];
	monbuf[2] = NUL;
	daybuf[0] = yyyymmdd[6];
	daybuf[1] = yyyymmdd[7];
	daybuf[2] = NUL;
	day = daybuf;
	nday = atoi(daybuf);
	month = monbuf;
	year = yearbuf;
    }
    if (!year) {
	makestr(&cmdatemsg,"Internal error - date not defaulted");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    /* Get here with day, month, and year set */
    debug(F110,"cmcvtdate dotime day",day,0);
    debug(F110,"cmcvtdate dotime month",month,0);
    debug(F110,"cmcvtdate dotime year",year,0);
    debug(F110,"cmcvtdate dotime s",s,0);
    debug(F110,"cmcvtdate dotime p",p,0);
    x = atoi(month);
    if (x > 12 || x < 1) {
	makestr(&cmdatemsg,"Month out of range");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    nday  = atoi(day);
    i = mdays[x];
    if (x == 2) if (isleap(atoi(year))) i++;
    if (nday > i || nday < 1) {
	makestr(&cmdatemsg,"Day out of range");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    if (!*p && t == 0) {
	sprintf(zbuf,"%04d%02d%02d",atoi(year),atoi(month),nday);	
	dp = zbuf;
	goto xcvtdate;
    }
    if (*p == '+' || *p == '-') {	/* GMT offset without a time */
	hh = 0;				/* so default time to 00:00:00 */
	mm = 0;
	ss = 0;
	goto cmtimezone;		/* and go do timezone */
    }
    if (*p && !isdigit(*p) && *p != ':') {
	makestr(&cmdatemsg,"Invalid time");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    sprintf(yyyymmdd,"%s%s%02d",year,month,nday); /* for tz calculations... */

    state = 1;				/* Initialize time-parsing FSA */
    hh = 0;				/* hours */
    mm = 0;				/* minutes */
    ss = 0;				/* seconds */
    ff = -1;				/* fraction */
    d = 0;				/* Digit counter */
    p2 = p;				/* Preliminary digit count... */
    while (isdigit(*p2)) {
	d++;
	p2++;
    }
    if (d > 6) {
	makestr(&cmdatemsg,"Too many time digits");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    d = (d & 1 && *p2 != ':') ? 1 : 0;	/* Odd implies leading '0' */

    while (*p) {			/* Get the time, if any */
	if (isdigit(*p)) {		/* digit */
	    if (d++ > 1) {
		state++;
		d = 1;
	    }
	    switch (state) {
	      case 1:			/* Hours */
		hh = hh * 10 + (*p - '0');
		break;
	      case 2:			/* Minutes */
		mm = mm * 10 + (*p - '0');
		break;
	      case 3:			/* Seconds */
		ss = ss * 10 + (*p - '0');
		break;
	      case 4:			/* Fraction of second */
		if (ff < 0)
		  ff = (*p > '4') ? 1 : 0;
		break;
	    }
	} else if (*p == ':') {		/* Colon */
	    state++;
	    d = 0;
	    if (state > 3) {
		makestr(&cmdatemsg,"Too many time fields");
		debug(F111,"cmcvtdate",cmdatemsg,-1);
		return(NULL);
	    }
	} else if (*p == '.') {
	    if (state == 3) {
		state = 4;
		d = 0;
	    } else {
		makestr(&cmdatemsg,"Improper fraction");
		debug(F111,"cmcvtdate",cmdatemsg,-1);
		return(NULL);
	    }
	} else if (*p == SP) {		/* Space */
	    while (*p && (*p == SP))	/* position to first nonspace */
	      p++;
	    break;
	} else if (isalpha(*p)) {	/* AM/PM/Z or timezone */
	    break;
	} else if (*p == '+' || *p == '-') { /* GMT offset */
	    break;
	} else {
	    makestr(&cmdatemsg,"Invalid time characters");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
	p++;
    }
    if (!*p)				/* If nothing left */
      goto xcmdate;			/* go finish up */

    /* At this point we have HH, MM, SS, and FF */
    /* Now handle the rest: AM, PM, and/or timezone info */

    if (!ckstrcmp(p,"am",2,0)) {	/* AM/PM... */
	pmflag = 0;
	p += 2;
    } else if (!ckstrcmp(p,"a.m.",4,0)) {
	pmflag = 0;
	p += 4;
    } else if (!ckstrcmp(p,"pm",2,0)) {
	pmflag = 1;
	p += 2;
    } else if (!ckstrcmp(p,"p.m.",4,0)) {
	pmflag = 1;
	p += 4;
    }
    if (pmflag && hh < 12)		/* If PM was given */
      hh += 12;				/* add 12 to the hour */

    /* Now handle timezone */

  cmtimezone:
    debug(F110,"cmcvtdate timezone",p,0);

    zhh = 0;				/* GMT offset HH */
    zmm = 0;				/* GMT offset MM */
    gmtsign = 0;			/* Sign of GMT offset */
    isgmt = 0;				/* 1 if time is GMT */

    while (*p && *p == SP)		/* Gobble spaces */
      p++;
    if (!*p)				/* If nothing left */
      goto xcmdate;			/* we're done */

    if (isalpha(*p)) {			/* Something left */
	int zone = 0;			/* Alphabetic must be timezone */
	p2 = p;				/* Isolate timezone */
	p++;
	while (isalpha(*p))
	  p++;
	p3 = p;
	cc = *p;
	*p = NUL;
	p = p2;				/* Have timezone, look it up */
	zone = lookup(usatz,p,nusatz,NULL);
	debug(F111,"cmcvtdate timezone alpha",p,zone);

	if (zone < 0) {			/* Not found */
	    makestr(&cmdatemsg,"Unknown timezone");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
	isgmt++;			/* All dates are GMT from here down */
	if (zone != 0) {		/* But not this one so make it GMT */
	    hh += zone;			/* RFC 822 timezone: EST etc */
	    debug(F101,"cmcvtdate hh + zone","",hh);
	    if (hh > 23) {		/* Offset crosses date boundary */
		int i;
		long jd;
		jd = mjd(yyyymmdd);	/* Get MJD */
		jd += hh / 24;		/* Add new day(s) */
		hh = hh % 24;		/* and convert back to yyyymmdd */
		ckstrncpy(yyyymmdd,mjd2date(jd),YYYYMMDD);
		debug(F111,"cmcvtdate zone-adjusted date",yyyymmdd,hh);
		for (i = 0; i < 4; i++)
		  yearbuf[i] = yyyymmdd[i];
		yearbuf[4] = NUL;
		monbuf[0] = yyyymmdd[4];
		monbuf[1] = yyyymmdd[5];
		monbuf[2] = NUL;
		daybuf[0] = yyyymmdd[6];
		daybuf[1] = yyyymmdd[7];
		daybuf[2] = NUL;
		day = daybuf;
		nday = atoi(daybuf);
		month = monbuf;
		year = yearbuf;
	    }
	}
	p = p3;				/* Put back whatever we poked above */
	*p = cc;

    } else if (*p == '+' || *p == '-') { /* GMT/UTC offset */
	p3 = p;
	debug(F110,"cmcvtdate timezone GMT offset",p,0);
	gmtsign = (*p == '+') ? -1 : 1;
	isgmt++;
	p++;
	while (*p == SP) p++;
	d = 0;
	p2 = p;
	while (isdigit(*p)) {		/* Count digits */
	    d++;
	    p++;
	}
	if (d != 4) {			/* Strict RFC [2]822 */
	    isgmt = 0;			/* If not exactly 4 digits */
	    p = p3;			/* it's not a GMT offset. */
	    goto delta;			/* So treat it as a delta time. */
	}
	d = (d & 1 && *p != ':') ? 1 : 0; /* Odd implies leading '0' */
	p = p2;
	debug(F111,"cmcvtdate GMT offset sign",p,gmtsign);
	debug(F101,"cmcvtdate GMT offset d","",d);
	state = 1;
	while (*p) {
	    if (isdigit(*p)) {		/* digit */
		if (d++ > 1) {
		    state++;
		    d = 1;
		}
		switch (state) {
		  case 1:
		    zhh = zhh * 10 + (*p - '0');
		    break;
		  case 2:
		    zmm = zmm * 10 + (*p - '0');
		    break;
		  default:		/* Ignore seconds or fractions */
		    break;
		}			
	    } else if (*p == ':') {	/* Colon */
		state++;
		d = 0;
	    } else if (*p == SP || *p == '(') {
		break;
	    } else {
		p = p3;			/* Maybe it's not a GMT offset. */
		goto delta;		/* So treat it as a delta time. */
	    }
	    p++;
	}
    }
    debug(F110,"cmcvtdate source string after timezone",p,0);

    if (*p) {				/* Anything left? */
	p2 = p;
	while (*p2 == SP)		/* Skip past spaces */
	  p2++;
	if (*p2 == '(') {		/* RFC-822 comment? */
	    int pc = 1;			/* paren counter */
	    p2++;
	    while (*p2) {
		if (*p2 == ')') {
		    if (--pc == 0) {
			p2++;
			break;
		    }
		} else if (*p2 == ')') {
		    pc++;
		}
		p2++;
	    }		
	    while (*p2 == SP)		/* Skip past spaces */
	      p2++;
	    if (!*p2)			/* Anything left? */
	      *p = NUL;			/* No, erase comment */
	}
	if (!*p2)			/* Anything left? */
	  goto xcmdate;			/* No, done. */
	p = p2;

      delta:
	debug(F110,"cmcvtdate delta yyyymmdd",yyyymmdd,0);
	debug(F110,"cmcvtdate delta year",year,0);
	debug(F110,"cmcvtdate delta p",p,0);

	if (*p == '+' || *p == '-') {	/* Delta time */
	    int state = NEED_DAYS;	/* Start off looking for days */
	    char c = 0;
	    dsign = 1;			/* Get sign */
	    if (*p++ == '-')
	      dsign = -1;
	    while (*p == SP)		/* Skip intervening spaces */
	      p++;
	    while (state) {		/* FSA to parse delta time */
		if (state < 0 || !isdigit(*p)) {
		    makestr(&cmdatemsg,"Invalid delta time");
		    debug(F111,"cmcvtdate",cmdatemsg,-1);
		    return(NULL);
		}
		p2 = p;			/* Get next numeric field */
		while (isdigit(*p2))
		  p2++;
		c = *p2;		/* And break character */
		*p2 = NUL;		/* Terminate the number */

		switch (state) {	/* Interpret according to state */
		  case NEED_DAYS:	/* Initial */
		    if ((c == '-') ||	/* VMS format */
			((c == 'd' || c == 'D')
			 && !isalpha(*(p2+1)))) { /* Days */
			ddays = atoi(p);
			if (!*(p2+1))			
			  state = 0;
			else		      /* if anything is left */
			  state = NEED_HRS;   /* now we want hours. */
		    } else if ((c == 'W' || c == 'w') && !isalpha(*(p2+1))) {
			ddays = atoi(p) * 7;   /* weeks... */
			if (!*(p2+1))			
			  state = 0;
			else
			  state = NEED_HRS;
		    } else if ((c == 'M' || c == 'm') && !isalpha(*(p2+1))) {
			dmonths = atoi(p); /* months... */
			if (!*(p2+1))			
			  state = 0;
			else
			  state = NEED_HRS;
		    } else if ((c == 'Y' || c == 'y') && !isalpha(*(p2+1))) {
			dyears = atoi(p); /* years... */
			if (!*(p2+1))			
			  state = 0;
			else
			  state = NEED_HRS;
		    } else if (c == ':') { /* delimiter is colon */
			dhours = atoi(p);  /* so it's hours */
			state = NEED_MINS; /* now we want minutes */
		    } else if (!c) {       /* end of string */
			dhours = atoi(p);  /* it's still hours */
			state = 0;         /* and we're done */
		    } else if (isalpha(c) || c == SP) {
			if (c == SP) {	/* It's a keyword? */
			    p2++;	/* Skip spaces */
			    while (*p2 == SP)
			      p2++;
			} else {	/* or replace first letter */
			    *p2 = c;
			}
			p3 = p2;	/* p2 points to beginning of keyword */
			while (isalpha(*p3)) /* Find end of keyword */
			  p3++;
			c = *p3;	/* NUL it out so we can look it up */
			if (*p3)	/* p3 points to keyword terminator */
			  *p3 = NUL;
			units = lookup(timeunits,p2,nunits,NULL);
			if (units < 0) {
			    makestr(&cmdatemsg,"Invalid units in delta time");
			    debug(F111,"cmcvtdate",cmdatemsg,-1);
			    return(NULL);
			}
			*p2 = NUL;	/* Re-terminate the number */
			*p3 = c;
			while (*p3 == SP) /* Point at field after units */
			  p3++;
			p2 = p3;
			switch (units) {
			  case TU_DAYS:
			    ddays = atoi(p);
			    break;
			  case TU_WEEKS:
			    ddays = atoi(p) * 7;
			    break;
			  case TU_MONTHS:
			    dmonths = atoi(p);
			    break;
			  case TU_YEARS:
			    dyears = atoi(p);
			    break;
			}
			if (*p2) {
			    state = NEED_HRS;
			    p2--;
			} else
			  state = 0;

		    } else {		/* Anything else */
			state = -1;	/* is an error */
		    }
		    break;
		  case NEED_HRS:	/* Looking for hours */
		    debug(F000,"cmcvtdate NEED_HRS",p,c);
		    if (c == ':') {
			dhours = atoi(p);
			state = NEED_MINS;
		    } else if (!c) {
			dhours = atoi(p);
			state = 0;
		    } else {
			state = -1;
		    }
		    break;
		  case NEED_MINS:	/* Looking for minutes */
		    if (c == ':') {
			dmins = atoi(p);
			state = NEED_SECS;
		    } else if (!c) {
			dmins = atoi(p);
			state = 0;
		    } else {
			state = -1;
		    }
		    break;
		  case NEED_SECS:	/* Looking for seconds */
		    if (c == '.') {
			dsecs = atoi(p);
			state = NEED_FRAC;
		    } else if (!c) {
			dsecs = atoi(p);
			state = 0;
		    } else {
			state = -1;
		    }
		    break;
		  case NEED_FRAC:	/* Fraction of second */
		    if (!c && rdigits(p)) {
			if (*p > '4')
			  dsecs++;
			state = 0;
		    } else {
			state = -1;
		    }
		    break;
		}
		if (c)			/* next field if any */
		  p = p2 + 1;
	    }
	    havedelta = 1;

	} else {
	    makestr(&cmdatemsg,"Extraneous material at end");
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
    }

 xcmdate:

    if ((t != 2 && hh > 24) || hh < 0) { /* Hour range check */
	makestr(&cmdatemsg,"Invalid hours");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    if (mm > 59) {			/* Minute range check */
	makestr(&cmdatemsg,"Invalid minutes");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    if (ff > 0) {			/* Fraction of second? */
	if (ss < 59) {
	    ss++;
	    ff = 0;
	} else if (mm < 59) {
	    ss = 0;
	    mm++;
	    ff = 0;
	} else if (hh < 24) {
	    ss = 0;
	    mm = 0;
	    hh++;
	    ff = 0;
	}
	/* Must add a day -- leave ff at 1... */
	/* (DO SOMETHING ABOUT THIS LATER) */
    }
    if (ss > 60) {			/* Seconds range check */
	makestr(&cmdatemsg,"Invalid seconds"); /* 60 is ok because of */
	debug(F111,"cmcvtdate",cmdatemsg,-1);  /* Leap Second. */
	return(NULL);
    }
    if ((mm < 0 || ss < 0) ||
	(t != 2 && (ss > 0 || mm > 0) && hh > 23)) {
	makestr(&cmdatemsg,"Invalid minutes or seconds");
	debug(F111,"cmcvtdate",cmdatemsg,-1);
	return(NULL);
    }
    debug(F110,"cmcvtdate year",year,0);
    debug(F110,"cmcvtdate month",month,0);
    debug(F101,"cmcvtdate nday","",nday);
    debug(F101,"cmcvtdate hh","",hh);
    debug(F101,"cmcvtdate mm","",mm);
    debug(F101,"cmcvtdate ss","",ss);
    debug(F101,"cmcvtdate gmtsign","",gmtsign);
    debug(F101,"cmcvtdate zhh","",zhh);
    debug(F101,"cmcvtdate zmm","",zmm);
    debug(F101,"cmcvtdate isgmt","",isgmt);

#ifdef ZLOCALTIME
/* Handle timezone -- first convert to GMT */

    zdd = 0;				/* Days changed */
    if (isgmt && (zmm || zhh)) {	/* If GMT offset given */
	long sec1, sec2, zz;
	sec1 = ss + 60 * mm + 3600 * hh;
	sec2 = gmtsign * (60 * zmm + 3600 * zhh);
	sec1 += sec2;
	if (sec1 < 0) {
	    sec1 = 0 - sec1;
	    zdd = 0L - (sec1 / 86400L);
	    sec1 = sec1 % 86400L;
	} else if (sec1 > 86400L) {
	    zdd = sec1 / 86400L;
	    sec1 = sec1 % 86400L;
	}
	ss = sec1 % 60;
	zz = sec1 / 60;
	mm = zz % 60;
	hh = zz / 60;
	debug(F101,"cmcvtdate NEW hh","",hh);
	debug(F101,"cmcvtdate NEW mm","",mm);
	debug(F101,"cmcvtdate NEW dd","",zdd);

/* At this point hh:mm:ss is in GMT and zdd is the calendar adjustment */

    }
#endif /* ZLOCALTIME */

    if (yyyymmdd[0] && !year) {
	ckstrncpy(yearbuf,yyyymmdd,5);
	ckstrncpy(monbuf,&yyyymmdd[4],3);
	ckstrncpy(daybuf,&yyyymmdd[6],3);
	year = yearbuf;
	month = monbuf;
	day = daybuf;
	nday = atoi(daybuf);
    }
    sprintf(zbuf,"%04d%02d%02d %02d:%02d:%02d", /* SAFE */
	    atoi(year),atoi(month),nday,hh,mm,ss
	    );
    dp = zbuf;

#ifdef ZLOCALTIME
    /* Now convert from GMT to local time */

    if (isgmt) {			/* If GMT convert to local time */
	debug(F110,"cmcvtdate GMT 1",dp,0);
	if (zdd) {			/* Apply any calendar adjustment */
	    long zz;
	    zz = mjd(dp) + zdd;
	    sprintf(zbuf,"%s %02d:%02d:%02d",mjd2date(zz),hh,mm,ss);
	}
	debug(F110,"cmcvtdate GMT 2",dp,0);
	if ((p = zlocaltime(dp))) {
	    debug(F110,"cmcvtdate asctime zlocaltime",p,0);
	    if (p) ckstrncpy(zbuf,p,18);
	}
	debug(F110,"cmcvtdate GMT 3",dp,0);
	for (i = 0; i < 4; i++)
	  yearbuf[i] = dp[i];
	yearbuf[4] = NUL;
	monbuf[0] = dp[4];
	monbuf[1] = dp[5];
	monbuf[2] = NUL;
	daybuf[0] = dp[6];
	daybuf[1] = dp[7];
	daybuf[2] = NUL;
	day = daybuf;
	nday = atoi(daybuf);
	month = monbuf;
	year = yearbuf;
	hh = atoi(&dp[9]);
	mm = atoi(&dp[12]);
	ss = atoi(&dp[15]);
    }
#endif /* ZLOCALTIME */

#ifdef DEBUG
    if (deblog) {
	debug(F101,"cmcvtdate hour","",hh);
	debug(F101,"cmcvtdate minute","",mm);
	debug(F101,"cmcvtdate second","",ss);
    }
#endif /* DEBLOG */

    makestr(&cmdatemsg,NULL);
    if (havedelta) {
#ifdef DEBUG
	if (deblog) {
	    debug(F110,"cmcvtdate base ",dp,0);
	    debug(F101,"cmcvtdate delta sign","",dsign);
	    debug(F101,"cmcvtdate delta yrs ","",dyears);
	    debug(F101,"cmcvtdate delta mos ","",dmonths);
	    debug(F101,"cmcvtdate delta days","",ddays);
	    debug(F101,"cmcvtdate delta hrs ","",dhours);
	    debug(F101,"cmcvtdate delta mins","",dmins);
	    debug(F101,"cmcvtdate delta secs","",dsecs);
	}
#endif /* DEBLOG */
	if (!(dp = cmdelta(atoi(year),
		    atoi(month),
		    nday, hh, mm, ss,
		    dsign, dyears, dmonths, ddays, dhours, dmins, dsecs))) {
	    debug(F111,"cmcvtdate",cmdatemsg,-1);
	    return(NULL);
	}
    }

  xcvtdate:				/* Exit point for success */
    {
	int len, k, n;
	char * p;
	debug(F110,"cmcvtdate xcvtdate dp",dp,0);
	if (!dp) dp = "";		/* Shouldn't happen */
	if (!*dp) return(NULL);		/* ... */
	len = strlen(dp);
	debug(F111,"cmcvtdate result",dp,len);
	k = cmdatebp - (char *)cmdatebuf; /* Space used */
	n = CMDATEBUF - k - 1;		/* Space left */
	if (n < len) {			/* Not enough? */
	    cmdatebp = cmdatebuf;	/* Wrap around */
	    n = CMDATEBUF;
	}
	ckstrncpy(cmdatebp,dp,n);
	p = cmdatebp;
	cmdatebp += len + 1;
	return(p);
    }
}

int
cmvdate(d) char * d; {			/* Verify date-time */
    int i;
    if (!d) return(0);
    if ((int)strlen(d) != 17) return(0);
    for (i = 0; i < 8; i++) { if (!isdigit(d[i])) return(0); }
    if (!isdigit(d[9])  || !isdigit(d[10]) ||
	!isdigit(d[12]) || !isdigit(d[13]) ||
	!isdigit(d[15]) || !isdigit(d[16]))
      return(0);
    if (!ckstrchr(" Tt_-:",d[8])) return(0);
    if (d[11] != ':' && d[14] != ':') return(0);
    return(1);
}

/* c m d i f f d a t e  --  Get difference between two date-times */

char *
cmdiffdate(d1,d2) char * d1, * d2; {
    char d1buf[9], d2buf[9];
    char x1buf[18], x2buf[18];
    char * p;

    int hh1 = 0, mm1 = 0, ss1 = 0;
    int hh2 = 0, mm2 = 0, ss2 = 0;
    int hh, mm, ss;
    int sign;
    long jd1, jd2, jd, f1, f2, fx;
    static char result[24], *rp;

    debug(F110,"cmdiffdate d1 A",d1,0);
    debug(F110,"cmdiffdate d2 A",d2,0);

    if (!(p = cmcvtdate(d1,1)))		/* Convert dates to standard format */
      return(NULL);
    ckstrncpy(x1buf,p,18);
    d1 = x1buf;

    if (!(p = cmcvtdate(d2,1)))
      return(NULL);
    ckstrncpy(x2buf,p,18);
    d2 = x2buf;

    debug(F110,"cmdiffdate d1 B",d1,0);
    debug(F110,"cmdiffdate d2 B",d2,0);
    if (!cmvdate(d1) || !cmvdate(d2))
      return(NULL);

    hh1 = atoi(&d1[9]);			/* Get hours, minutes, and seconds */
    mm1 = atoi(&d1[12]);		/* for first date */
    ss1 = atoi(&d1[15]);
    ckstrncpy(d1buf,d1,9);

    hh2 = atoi(&d2[9]);			/* ditto for second date */
    mm2 = atoi(&d2[12]);
    ss2 = atoi(&d2[15]);
    ckstrncpy(d2buf,d2,9);
    
    jd1 = mjd(d1buf);			/* Get the two Julian dates */
    jd2 = mjd(d2buf);
    f1 = ss1 + 60 * mm1 + 3600 * hh1;	/* Convert first time to seconds */

    f2 = ss2 + 60 * mm2 + 3600 * hh2;	/* Ditto for second time */
    debug(F101,"cmdiffdate jd1","",jd1);
    debug(F101,"cmdiffdate f1","",f1);
    debug(F101,"cmdiffdate jd2","",jd2);
    debug(F101,"cmdiffdate f2","",f2);
  
    if (jd2 > jd1 || (jd1 == jd2 && f2 > f1)) {
        sign = -1; 
        if (f1 > f2) {jd2--; f2 += 86400L;}
        jd = jd2 - jd1;
        fx = f2 - f1;
    } else {
        sign = 1;
        if (f2 > f1) {jd1--; f1 += 86400L;}
        jd = jd1 - jd2;
        fx = f1 - f2;
    }
    debug(F111,"cmdiffdate sign jd",sign<0?"-":"+",jd);
    debug(F101,"cmdiffdate fx","",fx);
  
    hh = (int) (fx / 3600L);		/* Convert seconds to hh:mm:ss */

    mm = (int) (fx % 3600L) / 60L;
    ss = (int) (fx % 3600L) % 60L;

    rp = result;			/* Format the result */
    *rp++ = (sign < 0) ? '-' : '+';
    if (jd != 0 && hh+mm+ss == 0) {
	sprintf(rp,"%ldd",jd);
    } else if (jd == 0) {
	if (ss == 0)
	  sprintf(rp,"%d:%02d",hh,mm);
	else
	  sprintf(rp,"%d:%02d:%02d",hh,mm,ss);
    } else {
	if (ss == 0)
	  sprintf(rp,"%ldd%d:%02d",jd,hh,mm);
	else
	  sprintf(rp,"%ldd%d:%02d:%02d",jd,hh,mm,ss);
    }
    debug(F110,"cmdiffdate result",result,0);
    return((char *)result);
}

#ifndef NOSPL
/* s h u f f l e d a t e  --  Rearrange date string */

/*
  Call with:
    A date string in standard format: yyyymmdd hh:mm:ss (time optional).
    Options:
      1: Reformat date to yyyy-mmm-dd (mmm = English month abbreviation).
      2: Reformat date to dd-mmm-yyyy (mmm = English month abbreviation).
      3: Reformat as numeric yyyymmddhhmmss.
      4: Reformat in asctime() format Sat Nov 26 11:10:34 2005
    Returns:
      Pointer to result if args valid, otherwise original arg pointer.
*/
char *
shuffledate(p,opt) char * p; int opt; {
    extern char * wkdays[];
    int len;
    char ibuf[32];
    static char obuf[48];
    char c;
    int yy, dd, mm;

    if (!p) p = "";
    if (!*p) p = ckdate();
    if (opt < 1 || opt > 4)
      return(p);
    len = strlen(p);
    if (len < 8 || len > 31) return(p);
    if (opt == 4) {			/* Asctime format (26 Nov 2005) */
	char c, * s;
	long z; int k;
	ckstrncpy(ibuf,p,31);
	k = len;
	while (k >= 0 && ibuf[k] == CR || ibuf[k] == LF)
	  ibuf[k--] = NUL;
	while (k >= 0 && ibuf[k] == SP || ibuf[k] == HT)
	  ibuf[k--] = NUL;
	if (k < 9) ckstrncpy(&ibuf[8]," 00:00:00",9);
	p = ibuf;
        z = mjd(p);                     /* Convert to modified Julian date */
        z = z % 7L;
        if (z < 0) {
            z = 0 - z;
            k = 6 - ((int)z + 3) % 7;
        } else {
            k = ((int)z + 3) % 7;	/* Day of week */
        }
	s = wkdays[k];
        obuf[0] = s[0];			/* Day of week */
        obuf[1] = s[1];
        obuf[2] = s[2];
        obuf[3] = SP;			/* Space */
	c = p[6];
        p[6] = NUL;
	mm = atoi(&ibuf[4]);		/* Month */
	s = moname[mm-1];		/* Name of month */
	p[6] = c;

        obuf[4] = s[0];			/* Month */
        obuf[5] = s[1];
        obuf[6] = s[2];
        obuf[7] = SP;			/* Space */
	if (p[6] == '0')		/* Date of month */
	  obuf[8] = SP;
	else
	  obuf[8] = p[6];
        obuf[9] = p[7];
	ckstrncpy(&obuf[10],&p[8],10);	/* Time */
        obuf[19] = SP;			/* Space */
	obuf[20] = p[0];		/* Year */
	obuf[21] = p[1];
	obuf[22] = p[2];
	obuf[23] = p[3];
	obuf[24] = NUL;
	return((char *)obuf);
    }
    if (opt == 3) {
	ckstrncpy(obuf,p,48);
	/* yyyymmdd hh:mm:ss */
	/* 01234567890123456 */
	/* yyyymmddhhmmss    */
	obuf[8] = obuf[9];
	obuf[9] = obuf[10];
	obuf[10] = obuf[12];
	obuf[11] = obuf[13];
	obuf[12] = obuf[15];
	obuf[13] = obuf[16];
	obuf[14] = NUL;
	return((char *)obuf);
    }
    ckstrncpy(ibuf,p,32);
    c = ibuf[4];			/* Warning: not Y10K compliant */
    ibuf[4] = NUL;
    if (!rdigits(ibuf))
      return(p);
    yy = atoi(ibuf);
    if (yy < 1 || yy > 9999)
      return(p);
    ibuf[4] = c;
    c = ibuf[6];
    ibuf[6] = NUL;
    if (!rdigits(&ibuf[4]))
      return(p);
    mm = atoi(&ibuf[4]);
    if (mm < 1 || mm > 12)
      return(p);
    ibuf[6] = c;
    c = ibuf[8];
    ibuf[8] = NUL;
    if (!rdigits(&ibuf[6]))
      return(p);
    dd = atoi(&ibuf[6]);
    ibuf[8] = c;
    if (dd < 1 || mm > 31)
      return(p);
    /* IGNORE WARNINGS ABOUT moname[] REFS OUT OF RANGE - it's prechecked. */
    switch (opt) {
      case 1:
	sprintf(obuf,"%04d-%s-%02d%s",yy,moname[mm-1],dd,&ibuf[8]);
	break;
      case 2:
	sprintf(obuf,"%02d-%s-%04d%s",dd,moname[mm-1],yy,&ibuf[8]);
    }
    return((char *)obuf);
}
#endif	/* NOSPL */

/*  C K C V T D A T E  --  Like cmcvtdate(), but returns string.  */
/*  For use by date-related functions */
/*  See calling conventions for cmcvtdate() above. */

char *
ckcvtdate(p,t) char * p; int t; {
    char * s;
    if (!(s = cmcvtdate(p,t)))
      return("<BAD_DATE_OR_TIME>");	/* \fblah() error message */
    else
      return(s);
}


/*  C M D A T E  --  Parse a date and/or time  */

/*
  Accepts date in various formats.  If the date is recognized,
  this routine returns 0 or greater with the result string pointer
  pointing to a buffer containing the date as "yyyymmdd hh:mm:ss".
*/
int
cmdate(xhlp,xdef,xp,quiet,f) char *xhlp, *xdef, **xp; int quiet; xx_strp f; {
    int x, rc;
    char *o, *s, *zq, *dp;

    cmfldflgs = 0;
    if (!xhlp) xhlp = "";
    if (!xdef) xdef = "";
    if (!*xhlp) xhlp = "Date and/or time";
    *xp = "";

    rc = cmfld(xhlp,xdef,&s,(xx_strp)0);
    debug(F101,"cmdate cmfld rc","",rc);
    if (rc < 0)
      return(rc);
    debug(F110,"cmdate 1",s,0);
    o = s;				/* Remember what they typed. */
    s = brstrip(s);
    debug(F110,"cmdate 2",s,0);

    x = 0;
    if (f) {				/* If a conversion function is given */
	char * pp;
	zq = atxbuf;			/* do the conversion. */
	pp = atxbuf;
	atxn = CMDBL;
	if ((x = (*f)(s,&zq,&atxn)) < 0) return(-2);
	if (!*pp)
	  pp = xdef;
	if (setatm(pp,0) < 0) {
	    if (!quiet) printf("?Evaluated date too long\n");
	    return(-9);
	}
	s = atxbuf;
    }
    dp = cmcvtdate(s,1);
    if (!dp) {
	if (!quiet) printf("?%s\n",cmdatemsg);
	return(-9);
    }
    *xp = dp;
    return(0);
}

#ifdef CK_RECALL			/* Command-recall functions */

/*  C M R I N I  --  Initialize or change size of command recall buffer */

int
cmrini(n) int n; {
    int i;
    if (recall && in_recall) {		/* Free old storage, if any */
	for (i = 0; i < cm_recall; i++) {
	    if (recall[i]) {
		free(recall[i]);
		recall[i] = NULL;
	    }
	}
	free(recall);
	recall = NULL;
    }
    cm_recall = n;			/* Set new size */
    rlast = current = -1;		/* Initialize pointers */
    if (n > 0) {
	recall = (char **)malloc((cm_recall + 1) * sizeof(char *));
	if (!recall)
	  return(1);
	for (i = 0; i < cm_recall; i++) {
	    recall[i] = NULL;
	}
	in_recall = 1;			/* Recall buffers init'd */
    }
    return(0);
}

/*  C M A D D N E X T  --  Force addition of next command */

VOID
cmaddnext() {
    if (on_recall && in_recall) {	/* Even if it doesn't come */
	force_add = 1;			/* from the keyboard */
	newcmd = 1;
	no_recall = 0;
    }
}

/*  C M G E T C M D  --  Find most recent matching command  */

char *
cmgetcmd(s) char * s; {
    int i;
    for (i = current; i >= 0; i--) {	/* Search backward thru history list */
	if (!recall[i]) continue;	/* This one's null, skip it */
	if (ckmatch(s,recall[i],0,1))	/* Match? */
	  return(recall[i]);		/* Yes, return pointer */
    }
    return(NULL);			/* No match, return NULL pointer */
}
#endif /* CK_RECALL */

/*  A D D C M D  --  Add a command to the recall buffer  */

VOID
addcmd(s) char * s; {
    int len = 0, nq = 0;
    char * p;
#ifdef CKLEARN
    extern int learning;
#endif /* CKLEARN */

    if (xcmdsrc)			/* Only for interactive commands */
      return;

    if (!newcmd)			/* The command has been here already */
      return;				/* so ignore it. */
    newcmd = 0;				/* It's new but do this only once. */

    if (!s) s = cmdbuf;
    if (s[0])
      len = strlen(s);

    if (len < 1)			/* Don't save empty commands */
      return;

    p = s;
    while (*p) { if (*p++ == '?') nq++; } /* Count question marks */

#ifdef CKLEARN
    if (learning)			/* If a learned script is active */
      learncmd(s);			/* record this command. */
#endif /* CKLEARN */

    debug(F010,"CMD(P)",s,0);		/* Maybe record it in the debug log */

#ifdef CKSYSLOG
    if (ckxlogging) {			/* Maybe record it in syslog */
	if (ckxsyslog >= SYSLG_CX || ckxsyslog >= SYSLG_CM)
	  cksyslog(SYSLG_CX, 1, "command", s, NULL);
    }
#endif /* CKSYSLOG */

#ifdef CK_RECALL
    last_recall = 0;

    if (on_recall &&			/* Command recall is on? */
	cm_recall > 0 &&		/* Recall buffer size is > 0? */
	!no_recall) {			/* Not not saving this command? */

	if (!force_add && rlast > -1)	/* If previous command was identical */
	  if (!strcmp(s,recall[rlast])) /* don't add another copy */
	    return;

	force_add = 0;			/* Reset now in case it was set */

        if (rlast >= cm_recall - 1) {	/* Recall buffer full? */
	    int i;
	    if (recall[0]) {		/* Discard oldest command */
		free(recall[0]);
		recall[0] = NULL;
	    }
	    for (i = 0; i < rlast; i++) {  /* The rest */
		recall[i] = recall[i+1];   /* move back */
	    }
	    rlast--;			/* Now we have one less */
	}
        rlast++;			/* Index of last command in buffer */
	current = rlast;		/* Also now the current command */
	if (current >= cm_recall) {	/* Shouldn't happen */
	    printf("?Command history error\n");	/* but if it does */
	    on_recall = 0;		        /* turn off command saving */
#ifdef COMMENT
	} else if (nq > 0) {		/* Have at least one question mark */
	    recall[current] = malloc(len+nq+1);
	    if (recall[current]) {
		p = recall[current];
		while (*s) {
		    if (*s == '?')
		      *p++ = '\\';
		    *p++ = *s++;
		}
		*p = NUL;
	    }
#endif /* COMMENT */
	} else {			/* Normal case, just copy */
	    recall[current] = malloc(len+1);
	    if (recall[current])
	      ckstrncpy(recall[current],s,len+1);
	}
    }
#endif /* CK_RECALL */
}


#ifdef CK_RECALL

/* C M H I S T O R Y */

VOID
cmhistory() {
    int i, lc = 1;
    for (i = 0; i <= current; i++) {
	printf(" %s\n", recall[i]);
	if (++lc > (cmd_rows - 2)) {	/* Screen full? */
	    if (!askmore())		/* Do more-prompting... */
	      break;
	    else
	      lc = 0;
	}
    }
}

int
savhistory(s,disp) char *s; int disp; {
    FILE * fp;
    int i;

    fp = fopen(s, disp ? "a" : "w");
    if (!fp) {
	perror(s);
	return(0);
    }
    for (i = 0; i <= current; i++)
      fprintf(fp,"%s\n", recall[i]);
    fclose(fp);
    return(1);
}
#endif /* CK_RECALL */

#ifdef COMMENT
/* apparently not used */
int
cmgetlc(s) char * s; {			/* Get leading char */
    char c;
    while ((c = *s++) <= SP) {
	if (!c)
	  break;
    }
    return(c);
}
#endif /* COMMENT */


/*  C M C F M  --  Parse command confirmation (end of line)  */

/*
 Returns
   -2: User typed anything but whitespace or newline
   -1: Reparse needed
    0: Confirmation was received
*/
int
cmcfm() {
    int x, xc;
    debug(F101,"cmcfm: cmflgs","",cmflgs);
    debug(F110,"cmcfm: atmbuf",atmbuf,0);
    inword = xc = cc = 0;

    setatm("",0);			/* (Probably unnecessary) */

    while (cmflgs != 1) {
        x = gtword(0);
        xc += cc;

        switch (x) {
	  case -9:
	    printf("Command or field too long\n");
	  case -4:			/* EOF */
	  case -2:
	  case -1:
	    return(x);
	  case 1:			/* End of line */
	    if (xc > 0) {
		if (xcmfdb) {
		    return(-6);
		} else {
		    printf("?Not confirmed - %s\n",atmbuf);
		    return(-9);
		}
	    } else
	      break;			/* Finish up below */
	  case 2:			/* ESC */
	    if (xc == 0) {
		bleep(BP_WARN);
		continue;		/* or fall thru. */
	    }
	  case 0:			/* Space */
	    if (xc == 0)		/* If no chars typed, continue, */
	      continue;			/* else fall thru. */
	    /* else fall thru... */

	  case 3:			/* Question mark */
	    if (xc > 0) {
		if (xcmfdb) {
		    return(-6);
		} else {
		    printf("?Not confirmed - %s\n",atmbuf);
		    return(-9);
		}
	    }
	    printf(
	       "\n Press the Return or Enter key to confirm the command\n");
	    printf("%s%s",cmprom,cmdbuf);
	    fflush(stdout);
	    continue;
	}
    }
    debok = 1;
    return(0);
}


/* The following material supports chained parsing functions. */
/* See ckucmd.h for FDB and OFDB definitions. */

struct OFDB cmresult = {		/* Universal cmfdb result holder */
    NULL,				/* Address of succeeding FDB struct */
    0,					/* Function code */
    NULL,				/* String result */
    0,					/* Integer result */
    (CK_OFF_T)0				/* Wide result */
};

VOID
cmfdbi(p,fc,s1,s2,s3,n1,n2,f,k,nxt)	/* Initialize an FDB */
    struct FDB * p;
    int fc;
    char * s1, * s2, * s3;
    int n1, n2;
    xx_strp f;
    struct keytab * k;
    struct FDB * nxt; {

    p->fcode = fc;
    p->hlpmsg = s1;
    p->dflt = s2;
    p->sdata = s3;
    p->ndata1 = n1;
    p->ndata2 = n2;
    p->spf = f;
    p->kwdtbl = k;
    p->nxtfdb = nxt;
}

/*  C M F D B  --  Parse a field with several possible functions  */

int
cmfdb(fdbin) struct FDB * fdbin; {
#ifndef NOSPL
    extern int x_ifnum;                 /* IF NUMERIC - disables warnings */
#endif /* NOSPL */
    struct FDB * in = fdbin;
    struct OFDB * out = &cmresult;
    int x = 0, n, r;
    CK_OFF_T w = (CK_OFF_T)0;
    char *s, *xp, *m = NULL;
    int errbits = 0;

    xp = bp;

    out->fcode = -1;			/* Initialize output struct */
    out->fdbaddr = NULL;
    out->sresult = NULL;
    out->nresult = 0;
/*
  Currently we make one trip through the FDBs.  So if the user types Esc or
  Tab at the beginning of a field, only the first FDB is examined for a
  default.  If the user types ?, help is given only for one FDB.  We should
  search through the FDBs for all matching possibilities -- and in particular
  display the pertinent context-sensitive help for each function, rather than
  the only the first one that works, and then rewind the FDB pointer so we
  are not locked out of the earlier ones.
*/
    cmfldflgs = 0;
    while (1) {				/* Loop through the chain of FDBs */
	nomsg = 1;
	xcmfdb = 1;
	s = NULL;
	n = 0;
	debug(F101,"cmfdb in->fcode","",in->fcode);
	switch (in->fcode) {		/* Current parsing function code */
	  case _CMNUM:
	    r = in->ndata1;
	    if (r != 10 && r != 8) r = 10;
#ifndef NOSPL
            x_ifnum = 1;                /* Disables warning messages */
#endif /* NOSPL */
	    x = cmnum(in->hlpmsg,in->dflt,r,&n,in->spf);
#ifndef NOSPL
            x_ifnum = 0;
#endif /* NOSPL */
	    debug(F101,"cmfdb cmnum","",x);
	    if (x < 0) errbits |= 1;
	    break;
	  case _CMNUW:			/* Wide cmnum - 24 Dec 2005 */
	    r = in->ndata1;
	    if (r != 10 && r != 8) r = 10;
#ifndef NOSPL
            x_ifnum = 1;                /* Disables warning messages */
#endif /* NOSPL */
	    x = cmnumw(in->hlpmsg,in->dflt,r,&w,in->spf);
#ifndef NOSPL
            x_ifnum = 0;
#endif /* NOSPL */
	    debug(F101,"cmfdb cmnumw","",w);
	    if (x < 0) errbits |= 1;
	    break;
	  case _CMOFI:
	    x = cmofi(in->hlpmsg,in->dflt,&s,in->spf);
	    debug(F101,"cmfdb cmofi","",x);
	    if (x < 0) errbits |= 2;
	    break;
	  case _CMIFI:
	    x = cmifi2(in->hlpmsg,
		       in->dflt,
		       &s,
		       &n,
		       in->ndata1,
		       in->sdata,
		       in->spf,
		       in->ndata2
		       );
	    debug(F101,"cmfdb cmifi2 x","",x);
	    debug(F101,"cmfdb cmifi2 n","",n);
	    if (x < 0) errbits |= 4;
	    break;
	  case _CMFLD:
	    cmfldflgs = in->ndata1;
	    x = cmfld(in->hlpmsg,in->dflt,&s,in->spf);
	    debug(F101,"cmfdb cmfld","",x);
	    if (x < 0) errbits |= 8;
	    break;
	  case _CMTXT:
	    x = cmtxt(in->hlpmsg,in->dflt,&s,in->spf);
	    debug(F101,"cmfdb cmtxt","",x);
	    if (x < 0) errbits |= 16;
	    break;
	  case _CMKEY:
	    x = cmkey2(in->kwdtbl,
		       in->ndata1,
		       in->hlpmsg,in->dflt,in->sdata,in->spf,in->ndata2);
	    debug(F101,"cmfdb cmkey","",x);
	    if (x < 0) errbits |= ((in->ndata2 & 4) ? 32 : 64);
	    break;
	  case _CMCFM:
	    x = cmcfm();
	    debug(F101,"cmfdb cmcfm","",x);
	    if (x < 0) errbits |= 128;
	    break;
	  default:
	    debug(F101,"cmfdb - unexpected function code","",in->fcode);
	    printf("?cmfdb - unexpected function code: %d\n",in->fcode);
	}
	debug(F101,"cmfdb x","",x);
	debug(F101,"cmfdb cmflgs","",cmflgs);
	debug(F101,"cmfdb crflag","",crflag);
	debug(F101,"cmfdb qmflag","",qmflag);
	debug(F101,"cmfdb esflag","",esflag);

	if (x > -1) {			/* Success */
	    out->fcode = in->fcode;	/* Fill in output struct */
	    out->fdbaddr = in;
	    out->sresult = s;
	    out->nresult = (in->fcode == _CMKEY) ? x : n;
	    out->wresult = w;
	    out->kflags = (in->fcode == _CMKEY) ? cmkwflgs : 0;
	    debug(F111,"cmfdb out->nresult",out->sresult,out->nresult);
	    debug(F111,"cmfdb out->wresult",out->sresult,out->wresult);
	    nomsg = 0;
	    xcmfdb = 0;
	    /* debug(F111,"cmfdb cmdbuf & crflag",cmdbuf,crflag); */
	    if (crflag) {
		cmflgs = 1;
	    }
	    return(x);			/* and return */
	}
	in = in->nxtfdb;		/* Failed, get next parsing function */
	nomsg = 0;
	xcmfdb = 0;
	if (!in) {			/* No more */
	    debug(F101,"cmfdb failure x","",x);
	    debug(F101,"cmfdb failure errbits","",errbits);
	    if (x == -6)
	      x = -9;
	    if (x == -9) {
#ifdef CKROOT
		if (ckrooterr)
		  m = "Off Limits";
		else
#endif /* CKROOT */
		/* Make informative messages for a few common cases */
		switch (errbits) {
		  case 4+32: m = "Does not match filename or switch"; break;
		  case 4+64: m = "Does not match filename or keyword"; break;
		  case 1+32: m = "Not a number or valid keyword"; break;
		  case 1+64: m = "Not a number or valid switch"; break;
		  default: m = "Not valid in this position";
		}
		printf("?%s: \"%s\"\n",m, atmbuf);
	    }
	    return(x);
	}
	if (x != -2 && x != -6 && x != -9 && x != -3) /* Editing or somesuch */
	  return(x);			/* Go back and reparse */
	pp = np = bp = xp;		/* Back up pointers */
	cmflgs = -1;			/* Force a reparse */

#ifndef NOSPL
	if (!askflag) {			/* If not executing ASK-class cmd... */
#endif /* NOSPL */
	    if (crflag) {		/* If CR was typed, put it back */
		pushc = LF;		/* But as a linefeed */
	    } else if (qmflag) {	/* Ditto for Question mark */
		pushc = '?';
	    } else if (esflag) {	/* and Escape or Tab */
		pushc = ESC;
	    }
#ifndef NOSPL
	}
#endif /* NOSPL */
    }
}

/*
   C M I O F I  --  Parse an input file OR the name of a nonexistent file.

   Replaces the commented-out version above.  This one actually works and
   has the expected straightforward interface.
*/
int
cmiofi(xhlp,xdef,xp,wild,f) char *xhlp, *xdef, **xp; int *wild; xx_strp f; {
    int x;
    struct FDB f1, f2;
    cmfdbi(&f1,_CMIFI,xhlp,xdef,"",0,0,f,NULL,&f2);
    cmfdbi(&f2,_CMOFI,"","","",0,0,f,NULL,NULL);
    x = cmfdb(&f1);
    if (x < 0) {
	if (x == -3) {
	    x = -9;
	    printf("?Filename required\n");
	}
    }
    *wild = cmresult.nresult;
    *xp = cmresult.sresult;
    return(x);
}

/*  G T W O R D  --  Gets a "word" from the command input stream  */

/*
Usage: retcode = gtword(brk);
  brk = 0 for normal word breaks (space, CR, Esc, ?)
  brk = 1 to add ':' and '=' (for parsing switches).  These characters
        act as break characters only if the first character of the field
        is slash ('/'), i.e. switch introducer.
  brk = 4 to not strip comments (used only for "help #" and "help ;").

Returns:
-10 Timelimit set and timed out
 -9 if input was too long
 -4 if end of file (e.g. pipe broken)
 -3 if null field
 -2 if command buffer overflows
 -1 if user did some deleting
  0 if word terminates with SP or tab
  1 if ... CR
  2 if ... ESC
  3 if ... ? (question mark)
  4 if ... : or = and called with brk != 0

With:
  pp pointing to beginning of word in buffer
  bp pointing to after current position
  atmbuf containing a copy of the word
  cc containing the number of characters in the word copied to atmbuf
*/

int
ungword() {				/* Unget a word */
    debug(F101,"ungword cmflgs","",cmflgs);
    if (ungw) return(0);
    cmfsav = cmflgs;
    ungw = 1;
    cmflgs = 0;
    return(0);
}

/* Un-un-get word.  Undo ungword() if it has been done. */

VOID
unungw() {
    debug(F010,"unungw atmbuf",atmbuf,0);
    if (ungw) {
	ungw = 0;
	cmflgs = cmfsav;
	atmbuf[0] = NUL;
    }
}

static int
gtword(brk) int brk; {
    int c;                              /* Current char */
    int quote = 0;                      /* Flag for quote character */
    int echof = 0;                      /* Flag for whether to echo */
    int comment = 0;			/* Flag for in comment */
    char *cp = NULL;			/* Comment pointer */
    int eintr = 0;			/* Flag for syscall interrupted */
    int bracelvl = 0;			/* nested brace counter [jrs] */
    int iscontd = 0;			/* Flag for continuation */
    int realtty = 0;			/* Stdin is really a tty */
    char firstnb  = NUL;
    char lastchar = NUL;
    char prevchar = NUL;
    char lbrace, rbrace;
    int dq = 0;				/* Doublequote flag */
    int dqn = 0;			/* and count */
    int isesc = 0;

#ifdef RTU
    extern int rtu_bug;
#endif /* RTU */

#ifdef IKSD
    extern int inserver;
#endif /* IKSD */
    extern int kstartactive;

#ifdef datageneral
    extern int termtype;                /* DG terminal type flag */
    extern int con_reads_mt;            /* Console read asynch is active */
    if (con_reads_mt) connoi_mt();      /* Task would interfere w/cons read */
#endif /* datageneral */

#ifdef COMMENT
#ifdef DEBUG
    if (deblog) {
	debug(F101,"gtword brk","",brk);
	debug(F101,"gtword cmfldflgs","",cmfldflgs);
	debug(F101,"gtword swarg","",swarg);
	debug(F101,"gtword dpx","",dpx);
	debug(F101,"gtword echof","",echof);
#ifndef NOSPL
	debug(F101,"gtword askflag","",askflag);
	debug(F101,"gtword timelimit","",timelimit);
#ifndef NOLOCAL
#ifndef NOXFER
#ifdef CK_AUTODL
	debug(F101,"gtword cmdadl","",cmdadl);
#endif /* CK_AUTODL */
#endif /* NOXFER */
#endif /* NOLOCAL */
#endif /* NOSPL */
    }
#endif /* DEBUG */
#endif /* COMMENT */

    realtty = is_a_tty(0);		/* Stdin is really a tty? */

    if (cmfldflgs & 1) {
	lbrace = '(';
	rbrace = ')';
    } else {
	lbrace = '{';
	rbrace = '}';
    }
    crflag = 0;
    qmflag = 0;
    esflag = 0;

    if (swarg) {			/* No leading space for switch args */
	inword = 1;
	swarg = 0;
    }
    if (ungw) {				/* Have a word saved? */
#ifdef M_UNGW
	/* Experimental code to allow ungetting multiple words. */
	/* See comments in ckmkey2() above. */
	int x;
	if (np > pp) pp = np;
	while (*pp == SP) pp++;
	if (!*pp) {
	    ungw = 0;
	    cmflgs = cmfsav;
	} else {
	    if ((x = setatm(pp,2)) < 0) {
		printf("?Saved word too long\n");
		return(-9);
	    }
	    if (pp[x] >= SP) {
		char *p2;
		p2 = pp;
		p2 += x;
		while (*p2 == SP) p2++;
		if (*p2) {
		    np = p2;
		    ungword();
		}
	    } else {
		ungw = 0;
		cmflgs = cmfsav;
		debug(F010,"gtword ungw return atmbuf",atmbuf,0);
	    }
	}
	return(cmflgs);
#else
	/*
	   You would think the following should be:
             while (*pp == SP) pp++;
           but you would be wrong -- making this change breaks GOTO.
        */
	while (*pp++ == SP) ;
	if (setatm(pp,2) < 0) {
	    printf("?Saved word too long\n");
	    return(-9);
	}
	ungw = 0;
	cmflgs = cmfsav;
	debug(F010,"gtword ungw return atmbuf",atmbuf,0);
	return(cmflgs);
#endif /* M_UNGW */
    }
    pp = np;                            /* Start of current field */

#ifdef COMMENT
#ifdef DEBUG
    if (deblog) {
	debug(F110,"gtword cmdbuf",cmdbuf,0);
	debug(F110,"gtword bp",bp,0);
	debug(F110,"gtword pp",pp,0);
    }
#endif /* DEBUG */
#endif /* COMMENT */
    {
	/* If we are reparsing we have to recount any braces or doublequotes */
	char * p = pp;
	char c;
	if (*p == '"')
	  dq++;
	while ((c = *p++))
	  if (c == lbrace)
	    bracelvl++;
	  else if (c == rbrace)
	    bracelvl--;
	  else if (dq && c == '"')
	    dqn++;
    }
    while (bp < cmdbuf+CMDBL) {         /* Big get-a-character loop */
	echof = 0;			/* Assume we don't echo because */
	chsrc = 0;			/* character came from reparse buf. */
#ifdef BS_DIRSEP
CMDIRPARSE:
#endif /* BS_DIRSEP */

	c = *bp;
        if (!c) {			/* If no char waiting in reparse buf */
	    if ((dpx
#ifndef NOSPL
		 || echostars
#endif /* NOSPL */
		 ) && (!pushc
#ifndef NOSPL
			|| askflag
#endif /* NOSPL */
			))		/* Get from tty, set echo flag */
	      echof = 1;
	    c = cmdgetc(timelimit);	/* Read a command character. */
#ifdef DEBUG
	    debug(F101,"gtword c","",c);
#endif /* DEBUG */

	    if (timelimit && c < -1) {	/* Timed out */
		return(-10);
	    }

#ifndef NOXFER
/*
  The following allows packet recognition in the command parser.
  Presently it works only for Kermit packets, and if our current protocol
  happens to be anything besides Kermit, we simply force it to Kermit.
  We don't use the APC mechanism here for mechanical reasons, and also
  because this way, it works even with minimally configured interactive
  versions.  Add Zmodem later...
*/
#ifdef CK_AUTODL
	    if ((!local && cmdadl)	/* Autodownload enabled? */
#ifdef IKS_OPTION
		|| TELOPT_SB(TELOPT_KERMIT).kermit.me_start
#endif /* IKS_OPTION */
		) {
		int k;
		k = kstart((CHAR)c);	/* Kermit S or I packet? */
		if (k) {
		    int ksign = 0;
		    if (k < 0) {	/* Minus-Protocol? */
#ifdef NOSERVER
			goto noserver;	/* Need server mode for this */
#else
			ksign = 1;	/* Remember */
			k = 0 - k;	/* Convert to actual protocol */
			justone = 1;	/* Flag for protocol module */
#endif /* NOSERVER */
		    } else
		      justone = 0;
		    k--;		/* Adjust kstart's return value */
		    if (k == PROTO_K) {
			extern int protocol, g_proto;
			extern CHAR sstate;
			g_proto = protocol;
			protocol = PROTO_K; /* Crude... */
			sstate = ksign ? 'x' : 'v';
			cmdbuf[0] = NUL;
			return(-3);
		    }
		}
	    }
#ifdef NOSERVER
	  noserver:
#endif /* NOSERVER */
#endif /* CK_AUTODL */
#endif /* NOXFER */

	    chsrc = 1;			/* Remember character source is tty. */
	    brkchar = c;

#ifdef IKSD
            if (inserver && c < 0) {    /* End of session? */
                debug(F111,"gtword c < 0","exiting",c);
                return(-4);             /* Cleanup and terminate */
            }
#endif /* IKSD */

#ifdef OS2
           if (c < 0) {			/* Error */
	       if (c == -3) {		/* Empty word? */
		   if (blocklvl > 0)	/* In a block */
		     continue;		/* so keep looking for block end */
		   else
		     return(-3);	/* Otherwise say we got nothing */
	       } else {			/* Not empty word */
		   return(-4);		/* So some kind of i/o error */
	       }
           }
#else
#ifdef MAC
	   if (c == -3)			/* Empty word... */
	     if (blocklvl > 0)
	       continue;
	     else
	       return(-3);
#endif /* MAC */
#endif /* OS2 */
	   if (c == EOF) {		/* This can happen if stdin not tty. */
#ifdef EINTR
/*
  Some operating and/or C runtime systems return EINTR for no good reason,
  when the end of the standard input "file" is encountered.  In cases like
  this, we get into an infinite loop; hence the eintr counter, which is reset
  to 0 upon each call to this routine.
*/
		debug(F101,"gtword EOF","",errno);
		if (errno == EINTR && ++eintr < 4) /* When bg'd process is */
		  continue;		/* fg'd again. */
#endif /* EINTR */
		return(-4);
	    }
	    c &= cmdmsk;		/* Strip any parity bit */
	}				/* if desired. */

/* Now we have the next character */

	isesc = (c == ESC);		/* A real ESC? */

	if (!firstnb && c > SP) {	/* First nonblank */
	    firstnb = c;
	    if (c == '"')		/* Starts with doublequote */
	      dq = 1;
	}
	if (c == '"')			/* Count doublequotes */
	  dqn++;

	if (quote && (c == CR || c == LF)) { /* Enter key following quote */
	    *bp++ = CMDQ;		/* Double it */
	    *bp = NUL;
	    quote = 0;
	}
        if (quote == 0) {		/* If this is not a quoted character */
	    switch (c) {
	      case CMDQ:		/* Got the quote character itself */
		if (!comment && quoting)
		  quote = 1;		/* Flag it if not in a comment */
		break;
	      case FF:			/* Formfeed. */
                c = NL;                 /* Replace with newline */
		cmdclrscn();		/* Clear the screen */
		break;
	      case HT:			/* Horizontal Tab */
		if (comment)		/* If in comment, */
		  c = SP;		/* substitute space */
		else			/* otherwise */
		  c = ESC;		/* substitute ESC (for completion) */
		break;
	      case ';':			/* Trailing comment */
	      case '#':
		if (! (brk & 4) ) {	/* If not keeping comments */
		    if (inword == 0 && quoting) { /* If not in a word */
			comment = 1;	/* start a comment. */
			cp = bp;	/* remember where it starts. */
		    }
		}
		break;
	    }
	    if (!kstartactive &&	/* Not in possible Kermit packet */
		!comment && c == SP) {	/* Space not in comment */
                *bp++ = (char) c;	/* deposit in buffer if not already */
		/* debug(F101,"gtword echof 2","",echof); */
#ifdef BEBOX
                if (echof) {
		    cmdecho((char) c, 0); /* Echo what was typed. */
                    fflush(stdout);
                    fflush(stderr);
                }
#else
                if (echof) {
		    cmdecho((char) c, 0); /* Echo what was typed. */
		    if (timelimit)
		      fflush(stdout);
		}
#endif /* BEBOX */
                if (inword == 0) {      /* If leading, gobble it. */
                    pp++;
                    continue;
                } else {                /* If terminating, return. */
		    if ((!dq && ((*pp != lbrace) || (bracelvl == 0))) ||
			(dq && dqn > 1 && *(bp-2) == '"')) {
			np = bp;
			cmbptr = np;
			if (setatm(pp,0) < 0) {
			    printf("?Field too long error 1\n");
			    debug(F111,"gtword too long #1",pp,strlen(pp));
			    return(-9);
			}
			brkchar = c;
			inword = cmflgs = 0;
			return(0);
		    }
                    continue;
                }
            }
            if (c == lbrace) {
		bracelvl++;
		/* debug(F101,"gtword bracelvl++","",bracelvl); */
	    }
            if (c == rbrace && bracelvl > 0) {
                bracelvl--;
		/* debug(F101,"gtword bracelvl--","",bracelvl); */
                if (linebegin)
		  blocklvl--;
            }
	    if ((c == '=' || c == ':') &&
		/* ^^^ */
		!kstartactive && !comment && brk /* && (firstnb == '/') */
		) {
                *bp++ = (char) c;	/* Switch argument separator */
		/* debug(F111,"gtword switch argsep",cmdbuf,brk); */
#ifdef BEBOX
                if (echof) {
		    cmdecho((char) c, 0); /* Echo what was typed. */
                    fflush(stdout);
                    fflush(stderr);
                }
#else
		if (echof) {
		    cmdecho((char) c, 0); /* Echo what was typed. */
		    if (timelimit)
		      fflush(stdout);
		}
#endif /* BEBOX */
		if ((*pp != lbrace) || (bracelvl == 0)) {
		    np = bp;
		    cmbptr = np;
		    if (setatm(pp,2) < 0) { /* ^^^ */
			printf("?Field too long error 1\n");
			debug(F111,"gtword too long #1",pp,strlen(pp));
			return(-9);
		    }
		    inword = cmflgs = 0;
		    brkchar = c;
		    return(4);
		}
            }
            if (c == LF || c == CR) {	/* CR or LF. */
		if (echof) {
                    cmdnewl((char)c);	/* echo it. */
#ifdef BEBOX
                    fflush(stdout);
                    fflush(stderr);
#endif /* BEBOX */
                }
		{
		    /* Trim trailing comment and whitespace */
		    char *qq;
		    if (comment) {	/* Erase comment */
			while (bp >= cp) /* Back to comment pointer */
			  *bp-- = NUL;
			bp++;
			pp = bp;	/* Adjust other pointers */
			inword = 0;	/* and flags */
			comment = 0;
			cp = NULL;
		    }
		    qq = inword ? pp : (char *)cmdbuf;
		    /* Erase trailing whitespace */
		    while (bp > qq && (*(bp-1) == SP || *(bp-1) == HT)) {
			bp--;
			/* debug(F000,"erasing","",*bp); */
			*bp = NUL;
		    }
		    lastchar = (bp > qq) ? *(bp-1) : NUL;
		    prevchar = (bp > qq+1) ? *(bp-2) : NUL;
		}
		if (linebegin && blocklvl > 0) /* Blank line in {...} block */
		  continue;

		linebegin = 1;		/* At beginning of next line */
		iscontd = prevchar != CMDQ &&
		  (lastchar == '-' || lastchar == lbrace);
		debug(F101,"gtword iscontd","",iscontd);

                if (iscontd) {		/* If line is continued... */
                    if (chsrc) {	/* If reading from tty, */
                        if (*(bp-1) == lbrace) { /* Check for "begin block" */
                            *bp++ = SP;	/* Insert a space for neatness */
                            blocklvl++;	/* Count block nesting level */
                        } else {	/* Or hyphen */
			    bp--;	/* Overwrite the hyphen */
                        }
                        *bp = NUL;	/* erase the dash, */
                        continue;	/* and go back for next char now. */
                    }
		} else if (blocklvl > 0) { /* No continuation character */
		    if (chsrc) {	/* But we're in a "block" */
			*bp++ = ',';	/* Add comma */
			*bp = NUL;
			continue;
		    }
		} else {		/* No continuation, end of command. */
		    *bp = NUL;		/* Terminate the command string. */
		    if (comment) {	/* If we're in a comment, */
			comment = 0;	/* Say we're not any more, */
			*cp = NUL;	/* cut it off. */
		    }
		    np = bp;		/* Where to start next field. */
		    cmbptr = np;
		    if (setatm(pp,0) < 0) { /* Copy field to atom buffer */
			debug(F111,"gtword too long #2",pp,strlen(pp));
			printf("?Field too long error 2\n");
			return(-9);
		    }
		    inword = 0;		/* Not in a word any more. */
		    crflag = 1;
                    /* debug(F110,"gtword","crflag is set",0); */
#ifdef CK_RECALL
		    current = rlast;
#endif /* CK_RECALL */
		    cmflgs = 1;
		    if (!xcmdsrc
#ifdef CK_RECALL
			|| force_add
#endif /* CK_RECALL */
			)
  		      addcmd(cmdbuf);
		    return(cmflgs);
		}
            }
/*
  This section handles interactive help, completion, editing, and history.
  Rearranged as a switch statement executed only if we're at top level since
  there is no need for any of this within command files and macros: Aug 2000.
  Jun 2001: Even if at top level, skip this if the character was fetched from
  the reparse or recall buffer, or if stdin is redirected.
*/
	    if ((xcmdsrc == 0		/* Only at top level */
#ifndef NOSPL
		|| askflag		/* or user is typing ASK response */
#endif /* NOSPL */
		 ) && chsrc != 0 && realtty) { /* from the real keyboard */

/* Use ANSI / VT100 up and down arrow keys for command recall.  */

		if (isesc && (
#ifdef IKSD
		    inserver
#else
		    0
#endif /* IKSD */
#ifdef USE_ARROWKEYS
                              || 1
#endif /* USE_ARROWKEYS */
                             )
                     ) {		/* A real ESC was typed */
		    int x;
		    msleep(200);	/* Wait 1/5 sec */
		    x = cmdconchk();	/* Was it followed by anything? */
		    debug(F101,"Arrowkey ESC cmdconchk","",x);

		    if (x > 1) {	/* If followed by at least 2 chars */
			int c2;
			c2 = cmdgetc(0); /* Get the first one */
			debug(F101,"Arrowkey ESC c2","",c2);

			if (c2 != '[' && c2 != 'O') { /* If not [ or O */
			    pushc = c2;	/* Push it and take the ESC solo */
			} else {
			    c2 = cmdgetc(0); /* Get the second one */
			    debug(F101,"Arrowkey ESC c3","",c2);
			    switch (c2) {
#ifndef NORECALL
			      case 'A':	/* Up */
				c = BEL;
				c = C_UP;
				break;
			      case 'B':	/* Down */
				c = BEL;
				c = C_DN;
				break;
			      case 'C':	/* Right */
			      case 'D':	/* Left */
#else
			      default:
#endif /* NORECALL */
				c = BEL; /* We don't use these yet */
				break;
			    }
			}
		    }
		}

		switch (c) {
		  case '?':		/* ?-Help */
#ifndef NOSPL
		    if (askflag)	/* No help in ASK response */
		      break;
#endif /* NOSPL */
		    if (quoting
			&& !kstartactive
			&& !comment
			) {
			cmdecho((char) c, 0);
			*bp = NUL;
			if (setatm(pp,0) < 0) {
			    debug(F111,"gtword too long ?",pp,strlen(pp));
			    printf("?Too long\n");
			    return(-9);
			}
			qmflag = 1;
			return(cmflgs = 3);
		    }

		  case ESC:		/* Esc or Tab completion */
		    if (!comment) {
			*bp = NUL;
			if (setatm(pp,0) < 0) {
			    debug(F111,"gtword too long Esc",pp,strlen(pp));
			    printf("?Too long\n");
			    return(-9);
			}
			esflag = 1;
			return(cmflgs = 2);
		    } else {
			bleep(BP_WARN);
			continue;
		    }

		  case BS:		/* Character deletion */
		  case RUB:
		    if (bp > cmdbuf) {	/* If still in buffer... */
			cmdchardel();	/* erase it. */
			bp--;		/* point behind it, */
			if (*bp == lbrace) bracelvl--; /* Adjust brace count */
			if (*bp == rbrace) bracelvl++;
			if ((*bp == SP) && /* Flag if current field gone */
			    (*pp != lbrace || bracelvl == 0))
			  inword = 0;
			*bp = NUL;	/* Erase character from buffer. */
		    } else {		/* Otherwise, */
			bleep(BP_WARN);
			cmres();	/* and start parsing a new command. */
			*bp = *atmbuf = NUL;
		    }
		    if (pp < bp)
		      continue;
		    else
		      return(cmflgs = -1);

		  case LDEL:		/* ^U, line deletion */
		    while ((bp--) > cmdbuf) {
			cmdchardel();
			*bp = NUL;
		    }
		    cmres();		/* Restart the command. */
		    *bp = *atmbuf = NUL;
		    inword = 0;
		    return(cmflgs = -1);

		  case WDEL:		/* ^W, word deletion */
		    if (bp <= cmdbuf) {	/* Beep if nothing to delete */
			bleep(BP_WARN);
			cmres();
			*bp = *atmbuf = NUL;
			return(cmflgs = -1);
		    }
		    bp--;
		    /* Back up over any trailing nonalphanums */
		    /* This is dependent on ASCII collating sequence */
		    /* but isalphanum() is not available everywhere. */
		    for ( ;
			 (bp >= cmdbuf) &&
			 ((*bp < '0') ||
			 ((*bp > '9') && (*bp < '@')) ||
			 ((*bp > 'Z') && (*bp < 'a')) ||
			 (*bp > 'z'));
			 bp--
			 ) {
			cmdchardel();
			*bp = NUL;
		    }
		    /* Now delete back to rightmost remaining nonalphanum */
		    for ( ; (bp >= cmdbuf) && (*bp) ; bp--) {
			if ((*bp < '0') ||
			    (*bp > '9' && *bp < '@') ||
			    (*bp > 'Z' && *bp < 'a') ||
			    (*bp > 'z'))
			  break;
			cmdchardel();
			*bp = NUL;
		    }
		    bp++;
		    inword = 0;
		    return(cmflgs = -1);

		  case RDIS: {		/* ^R, redisplay */
		      char *cpx; char cx;
		      *bp = NUL;
		      printf("\n%s",cmprom);
		      cpx = cmdbuf;
		      while ((cx = *cpx++)) {
			  cmdecho(cx,0);
		      }
		      fflush(stdout);
		      continue;
		  }
#ifndef NOLASTFILE
		  case VT:
		    if (lastfile) {
			printf("%s ",lastfile);
#ifdef GEMDOS
			fflush(stdout);
#endif /* GEMDOS */
			inword = cmflgs = 0;
			addbuf(lastfile);	/* Supply default. */
			if (setatm(lastfile,0) < 0) {
			    printf("Last name too long\n");
			    if (np) free(np);
			    return(-9);
			}
		    } else {		/* No default */
			bleep(BP_WARN);
		    }
		    return(0);
#endif	/* NOLASTFILE */
		}

#ifdef CK_RECALL
		if (on_recall &&	/* Reading commands from keyboard? */
		    (cm_recall > 0) &&	/* Saving commands? */
		    (c == C_UP || c == C_UP2)) { /* Go up one */
		    if (last_recall == 2 && current > 0)
		      current--;
		    if (current < 0) {	/* Nowhere to go, */
			bleep(BP_WARN);
			continue;
		    }
		    if (recall[current]) { /* We have a previous command */
			while ((bp--) > cmdbuf) { /* Erase current line */
			    cmdchardel();
			    *bp = NUL;
			}
			ckstrncpy(cmdbuf,recall[current],CMDBL);
#ifdef OSK
			fflush(stdout);
			write(fileno(stdout), "\r", 1);
			printf("%s%s",cmprom,cmdbuf);
#else
			printf("\r%s%s",cmprom,cmdbuf);
#endif /* OSK */
			current--;
		    }
		    last_recall = 1;
		    return(cmflgs = -1); /* Force a reparse */
		}
		if (on_recall &&	/* Reading commands from keyboard? */
		    (cm_recall > 0) &&	/* Saving commands? */
		    (c == C_DN)) {	/* Down one */
		    int x = 1;
		    if (last_recall == 1)
		      x++;
		    if (current + x > rlast) { /* Already at bottom, beep */
			bleep(BP_WARN);
			continue;
		    }
		    current += x;	/* OK to go down */
		    if (recall[current]) {
			while ((bp--) > cmdbuf) { /* Erase current line */
			    cmdchardel();
			    *bp = NUL;
			}
			ckstrncpy(cmdbuf,recall[current],CMDBL);
#ifdef OSK
			fflush(stdout);
			write(fileno(stdout), "\r", 1);
			printf("%s%s",cmprom,cmdbuf);
#else
			printf("\r%s%s",cmprom,cmdbuf);
#endif /* OSK */
			last_recall = 2;
			return(cmflgs = -1); /* Force reparse */
		    }
		}
#endif /* CK_RECALL */
	    }

	    if (c < SP && quote == 0) { /* Any other unquoted control char */
		if (!chsrc) {		/* If cmd file, point past it */
		    bp++;
		} else {
		    bleep(BP_WARN);
		}
		continue;		/* continue, don't put in buffer */
	    }
	    linebegin = 0;		/* Not at beginning of line */
#ifdef BEBOX
	    if (echof) {
                cmdecho((char) c, 0);	/* Echo what was typed. */
                fflush (stdout);
                fflush(stderr);
            }
#else
#ifdef NOSPL
            if (echof || chsrc)
#else
            if (echof || (echostars && chsrc))
#endif	/* NOSPL */
	      cmdecho((char) c, 0);	/* Echo what was typed. */
#endif /* BEBOX */
        } else {			/* This character was quoted. */
	    int qf = 1;
	    quote = 0;			/* Unset the quote flag. */
	    /* debug(F000,"gtword quote 0","",c); */
	    /* Quote character at this level is only for SP, ?, and controls */
            /* If anything else was quoted, leave quote in, and let */
	    /* the command-specific parsing routines handle it, e.g. \007 */
	    if (c > 32 && c != '?' && c != RUB && chsrc != 0) {
		/* debug(F000,"gtword quote 1","",c); */
		*bp++ = CMDQ;		/* Deposit \ if it came from tty */
		qf = 0;			/* and don't erase it from screen */
		linebegin = 0;		/* Not at beginning of line */
#ifdef BS_DIRSEP
/*
  This is a hack to handle "cd \" or "cd foo\" on OS/2 and similar systems.
  If we were called from cmdir() and the previous character was the quote
  character, i.e. backslash, and this character is the command terminator,
  then we stuff an extra backslash into the buffer without echoing, then
  we stuff the carriage return back in again, and go back and process it,
  this time with the quote flag off.
*/
	    } else if (dirnamflg && (c == CR || c == LF || c == SP)) {
		/* debug(F000,"gtword quote 2","",c); */
		*bp++ = CMDQ;
		linebegin = 0;		/* Not at beginning of line */
		*bp = (c == SP ? SP : CR);
		goto CMDIRPARSE;
#endif /* BS_DIRSEP */
	    }
#ifdef BEBOX
	    if (echof) {
                cmdecho((char) c, qf);	/* Echo what was typed. */
                fflush (stdout);
                fflush(stderr);
            }
#else
	    if (echof) cmdecho((char) c, qf); /* Now echo quoted character */
#endif /* BEBOX */
	    /* debug(F111,"gtword quote",cmdbuf,c); */
	}
#ifdef COMMENT
        if (echof) cmdecho((char) c,quote); /* Echo what was typed. */
#endif /* COMMENT */
        if (!comment) inword = 1;	/* Flag we're in a word. */
	if (quote) continue;		/* Don't deposit quote character. */
        if (c != NL) {			/* Deposit command character. */
	    *bp++ = (char) c;		/* and make sure there is a NUL */
#ifdef COMMENT
	    *bp = NUL;			/* after it */
#endif /* COMMENT */
	}
    }                                   /* End of big while */
    bleep(BP_WARN);
    printf("?Command too long, maximum length: %d.\n",CMDBL);
    cmflgs = -2;
    return(-9);
}

/* Utility functions */

/* A D D B U F  -- Add the string pointed to by cp to the command buffer  */

static int
addbuf(cp) char *cp; {
    int len = 0;
    while ((*cp != NUL) && (bp < cmdbuf+CMDBL)) {
        *bp++ = *cp++;                  /* Copy and */
        len++;                          /* count the characters. */
    }
    *bp++ = SP;                         /* Put a space at the end */
    *bp = NUL;                          /* Terminate with a null */
    np = bp;                            /* Update the next-field pointer */
    cmbptr = np;
    return(len);                        /* Return the length */
}

/*  S E T A T M  --  Deposit a token in the atom buffer.  */
/*
  Break on space, newline, carriage return, or NUL.
  Call with:
    cp = Pointer to string to copy to atom buffer.
    fcode = 0 means break on whitespace or EOL.
    fcode = 1 means don't break on space.
    fcode = 2 means break on space, ':', or '='.
    fcode = 3 means copy the whole string.
  Null-terminate the result.
  Return length of token, and also set global "cc" to this length.
  Return -1 if token was too long.
*/
static int
setatm(cp,fcode) char *cp; int fcode; {
    char *ap, *xp, *dqp = NULL, lbrace, rbrace;
    int bracelvl = 0, dq = 0;

    register char * s;
    register int n = 0;

    if (cmfldflgs & 1) {		/* Handle grouping */
	lbrace = '(';
	rbrace = ')';
    } else {
	lbrace = '{';
	rbrace = '}';
    }
    cc = 0;				/* Character counter */
    ap = atmbuf;			/* Address of atom buffer */

    s = cp;

    while (*s++) n++;			/* Save a call to strlen */

    if (n > ATMBL) {
	printf("?Command buffer overflow\n");
	return(-1);
    }
    /* debug(F111,"setatm",cp,n); */
    if (cp == ap) {			/* In case source is atom buffer */
	xp = atybuf;			/* make a copy */
#ifdef COMMENT
	strncpy(xp,ap,ATMBL);		/* so we can copy it back, edited. */
	cp = xp;
#else
	s = ap;
	while ((*xp++ = *s++)) ;	/* We already know it's big enough */
	cp = xp = atybuf;
#endif /* COMMENT */
    }
    *ap = NUL;				/* Zero the atom buffer */
    if (fcode == 1) {			/* Trim trailing blanks */
	while (--n >= 0 && cp[n] == SP)
	  ;
	cp[n+1] = NUL;
    }
    while (*cp == SP) {			/* Trim leading spaces */
	cp++;
	n--;
    }
    if (*cp == '"') {			/* Starts with doublequote? */
	dq = 1;
	dqp = cp;
    }
    while (*cp) {
        if (*cp == lbrace)
	  bracelvl++;
        else if (*cp == rbrace)
	  bracelvl--;
	if (bracelvl < 0)
	  bracelvl = 0;
	if (bracelvl == 0) {
	    if (dq) {
		if (*cp == SP || *cp == HT) {
		    if (cp > dqp+1) {
			if (*(cp-1) == '"' && *(cp-2) != CMDQ) {
			    break;
			}
		    }
		}
	    } else if ((*cp == SP || *cp == HT) && fcode != 1 && fcode != 3)
	      break;
	    if ((fcode == 2) && (*cp == '=' || *cp == ':')) break;
	    if ((fcode != 3) && (*cp == LF || *cp == CR)) break;
	}
        *ap++ = *cp++;
        cc++;
    }
    *ap = NUL;				/* Terminate the string. */
    /* debug(F111,"setatm result",atmbuf,cc); */
    return(cc);                         /* Return length. */
}

/*
  These functions attempt to hide system dependencies from the mainline
  code in gtword().  Dummy arg for cmdgetc() needed for compatibility with
  coninc(), ttinc(), etc, since a pointer to this routine can be passed in
  place of those to tn_doop().

  No longer static.  Used by askmore().  Fri Aug 20 15:03:34 1999.
*/
#define CMD_CONINC			/* How we get keyboard chars */

int
cmdgetc(timelimit) int timelimit; {	/* Get a character from the tty. */
    int c;
#ifdef IKSD
    extern int inserver;
#endif /* IKSD */
#ifdef CK_LOGIN
    extern int x_logged;
#endif /* CK_LOGIN */
#ifdef TNCODE
    static int got_cr = 0;
    extern int ckxech;
    int tx = 0, is_tn = 0;
#endif /* TNCODE */

    if (pushc
#ifndef NOSPL
	&& !askflag
#endif /* NOSPL */
	) {
        debug(F111,"cmdgetc()","pushc",pushc);
	c = pushc;
	pushc = NUL;
	if (xcmfdb && c == '?')		/* Don't echo ? twice if chaining. */
	  cmdchardel();
	return(c);
    }
#ifdef datageneral
    {
	char ch;
	c = dgncinb(0,&ch,1);		/* -1 is EOF, -2 TO,
                                         * -c is AOS/VS error */
	if (c == -2) {			/* timeout was enabled? */
	    resto(channel(0));		/* reset timeouts */
	    c = dgncinb(0,&ch,1);	/* retry this now! */
	}
	if (c < 0) return(-4);		/* EOF or some error */
	else c = (int) ch & 0177;	/* Get char without parity */
/*	echof = 1; */
    }
#else /* Not datageneral */
#ifndef MINIX2
    if (
#ifdef IKSD
	(!local && inserver) ||
#endif /* IKSD */
	timelimit > 0) {
#ifdef TNCODE
          GETNEXTCH:
            is_tn = !pushc && !local && sstelnet;
#endif /* TNCODE */
#ifdef COMMENT
	    c = coninc(timelimit > 0 ? 1 : 0);
#else /* COMMENT */
	    /* This is likely to break the asktimeout... */
	    c = coninc(timelimit);
#endif /* COMMENT */
	    /* debug(F101,"cmdgetc coninc","",c); */
#ifdef TNCODE
            if (c >= 0 && is_tn) {	/* Server-side Telnet */
                switch (c) {
		  case IAC:
                    /* debug(F111,"gtword IAC","c",c); */
                    got_cr = 0;
                    if ((tx = tn_doop((CHAR)(c & 0xff),ckxech,coninc)) == 0) {
                        goto GETNEXTCH;
                    } else if (tx <= -1) { /* I/O error */
                        /* If there was a fatal I/O error then ttclos()    */
                        /* has been called and the next GETNEXTCH attempt  */
                        /* will be !is_tn since ttclos() sets sstelnet = 0 */
                        doexit(BAD_EXIT,-1); /* (or return(-4)? */
                    } else if (tx == 1) { /* ECHO change */
                        ckxech = dpx = 1; /* Get next char */
                        goto GETNEXTCH;
                    } else if (tx == 2) { /* ECHO change */
                        ckxech = dpx = 0; /* Get next char */
                        goto GETNEXTCH;
                    } else if (tx == 3) { /* Quoted IAC */
                        c = 255;	/* proceeed with it. */
                    }
#ifdef IKS_OPTION
                    else if (tx == 4) {	/* IKS State Change */
                        goto GETNEXTCH;
                    }
#endif /* IKS_OPTION */
                    else if (tx == 6) {	/* Remote Logout */
			doexit(GOOD_EXIT,0);
                    } else {
			goto GETNEXTCH;	/* Unknown, get next char */
		    }
                    break;
#ifdef COMMENT
                  case CR:
                    if (!TELOPT_U(TELOPT_BINARY)) {
			if (got_cr) {
			    /* This means the sender is violating Telnet   */
			    /* protocol because we received two CRs in a   */
			    /* row without getting either LF or NUL.       */
			    /* This will not solve the problem but it      */
			    /* will at least allow two CRs to do something */
			    /* whereas before the user would have to guess */
			    /* to send LF or NUL after the CR.             */
			    debug(F100,"gtword CR telnet error","",0);
			    c = LF;
			} else {
			    debug(F100,"gtword skipping CR","",0);
			    got_cr = 1;	/* Remember a CR was received */
			    goto GETNEXTCH;
			}
                    } else {
			debug(F100,"gtword CR to LF","",0);
			c = LF;
                    }
                    break;
                  case LF:
                    if (!TELOPT_U(TELOPT_BINARY)) {
			got_cr = 0;
			debug(F100,"gtword LF","",0);
                    } else {
			if (got_cr) {
			    got_cr = 0;
			    debug(F100,"gtword skipping LF","",0);
			    goto GETNEXTCH;
			}
                    }
                    break;
                  case NUL:
                    if (!TELOPT_U(TELOPT_BINARY) && got_cr) {
			c = LF;
			debug(F100,"gtword NUL to LF","",0);
                    } else {
			debug(F100,"gtword NUL","",0);
                    }
                    got_cr = 0;
                    break;
#else /* COMMENT */
                  case CR:
                    if ( !TELOPT_U(TELOPT_BINARY) && got_cr ) {
                        /* This means the sender is violating Telnet   */
                        /* protocol because we received two CRs in a   */
                        /* row without getting either LF or NUL.       */
                        /* This will not solve the problem but it      */
                        /* will at least allow two CRs to do something */
                        /* whereas before the user would have to guess */
                        /* to send LF or NUL after the CR.             */
                        debug(F100,"gtword CR telnet error","",0);
                    } else {
                        got_cr = 1;	/* Remember a CR was received */
                    }
                    /* debug(F100,"gtword CR to LF","",0); */
                    c = LF;
		    break;
                  case LF:
                    if (got_cr) {
                        got_cr = 0;
                        /* debug(F100,"gtword skipping LF","",0); */
                        goto GETNEXTCH;
                    }
		    break;
                  case NUL:
                    if (got_cr) {
                        got_cr = 0;
                        /* debug(F100,"gtword skipping NUL","",0); */
                        goto GETNEXTCH;
#ifdef COMMENT
                    } else {
                      debug(F100,"gtword NUL","",0);
#endif /* COMMENT */
                    }
                    break;
#endif /* COMMENT */
#ifdef IKSD
		  case ETX:		/* Ctrl-C... */
                  case EOT:		/* EOT = EOF */
                      if (inserver
#ifdef CK_LOGIN
			  && !x_logged
#endif /* CK_LOGIN */
			  )
                          return(-4);
		    break;
#endif /* IKSD */
		  default:
                      got_cr = 0;
                }
            }
#endif /* TNCODE */
    } else {
#ifdef OS2
	c = coninc(0);
#else /* OS2 */
#ifdef CMD_CONINC
#undef CMD_CONINC
#endif /* CMD_CONINC */
	c = getchar();
#endif /* OS2 */
    }
#else  /* MINIX2 */
#undef getc
#ifdef CMD_CONINC
#undef CMD_CONINC
#endif /* CMD_CONINC */
    c = getc(stdin);
    /* debug(F101,"cmdgetc getc","",c); */
#endif /* MINIX2 */
#ifdef RTU
    if (rtu_bug) {
#ifdef CMD_CONINC
#undef CMD_CONINC
#endif /* CMD_CONINC */
	c = getchar();			/* RTU doesn't discard the ^Z */
	rtu_bug = 0;
    }
#endif /* RTU */
#endif /* datageneral */
    return(c);				/* Return what we got */
}

/* #ifdef USE_ARROWKEYS */

/* Mechanism to use for peeking into stdin buffer */

#ifndef USE_FILE_CNT			/* stdin->__cnt */
#ifndef USE_FILE__CNT			/* Note: two underscores */
#ifdef HPUX				/* HPUX 7-11 */
#ifndef HPUX5
#ifndef HPUX6
#define USE_FILE__CNT
#endif /* HPUX6 */
#endif /* HPUX5 */
#else
#ifdef ANYSCO				/* SCO UNIX, OSR5, Unixware, etc */
#ifndef OLD_UNIXWARE			/* But not Unixware 1.x or 2.0 */
#ifndef UNIXWARE2			/* or 2.1.0 */
#define USE_FILE__CNT
#endif /* UNIXWARE2 */
#endif /* OLD_UNIXWARE */
#endif /* ANYSCO */
#endif /* HPUX */
#endif /* USE_FILE__CNT */
#endif /* USE_FILE_CNT */

#ifndef USE_FILE_R			/* stdin->_r */
#ifndef USE_FILE_CNT
#ifndef USE_FILE__CNT
#ifdef BSD44				/* {Free,Open,Net}BSD, BSDI */
#define USE_FILE_R
#endif /* BSD44 */
#endif /* USE_FILE__CNT */
#endif /* USE_FILE_CNT */
#endif /* USE_FILE_R */

#ifndef USE_FILE_R			/* stdin->_cnt */
#ifndef USE_FILE_CNT
#ifndef USE_FILE__CNT
#define USE_FILE_CNT			/* Everybody else (but Linux) */
#endif /* USE_FILE__CNT */
#endif /* USE_FILE_CNT */
#endif /* USE_FILE_R */


/*
  c m d c o n c h k

  How many characters are waiting to be read at the console?  Normally
  conchk() would tell us, but in Unix and VMS cmdgetc() uses stdio getchar(),
  thus bypassing coninc()/conchk(), so we have to peek into the stdin buffer,
  which is totally nonportable.  Which is why this routine is, at least for
  now, used only for checking for arrow-key sequences from the keyboard after
  an ESC was read.  Wouldn't it be nice if the stdio package had a function
  that returned the number of bytes waiting to be read from its buffer?
  Returns 0 or greater always.
*/
int
cmdconchk() {
    int x = 0, y;
    y = pushc ? 1 : 0;			/* Have command character pushed? */
#ifdef OS2
    x = conchk();			/* Check device-driver buffer */
    if (x < 0) x = 0;
#else /* OS2 */
#ifdef CMD_CONINC			/* See cmdgetc() */
    x = conchk();			/* Check device-driver buffer */
    if (x < 0) x = 0;
#else  /* CMD_CONINC */

/* Here we must look inside the stdin buffer - highly platform dependent */

#ifdef _IO_file_flags			/* Linux */
    x = (int) ((stdin->_IO_read_end) - (stdin->_IO_read_ptr));
    debug(F101,"cmdconchk _IO_file_flags","",x);
#else  /* _IO_file_flags */
#ifdef USE_FILE_CNT			/* Traditional */
#ifdef VMS
    debug(F101,"cmdconchk (*stdin)->_cnt","",(*stdin)->_cnt);
    x = (*stdin)->_cnt;
#else
#ifdef NOARROWKEYS
    debug(F101,"cmdconchk NOARROWKEYS x","",0);
#else
    /* debug(F101,"cmdconchk stdin->_cnt","",stdin->_cnt);
    x = stdin->_cnt; */
#endif /* NOARROWKEYS */
#endif /* VMS */
    if (x == 0) x = conchk();
    if (x < 0) x = 0;
#else  /* USE_FILE_CNT */
#ifdef USE_FILE__CNT			/* HP-UX */
    debug(F101,"cmdconchk stdin->__cnt","",stdin->__cnt);
    x = stdin->__cnt;
    if (x == 0) x = conchk();
    if (x < 0) x = 0;
#else  /* USE_FILE_CNT */
#ifdef USE_FILE_R			/* FreeBSD, OpenBSD, etc */
    debug(F101,"cmdconchk stdin->_r","",stdin->_r);
    x = stdin->_r;
    if (x == 0) x = conchk();
    if (x < 0) x = 0;

    /* Fill in any others here... */

#endif /* USE_FILE_R */
#endif /* USE_FILE__CNT */
#endif /* USE_FILE_CNT */
#endif /* _IO_file_flags */
#endif /* CMD_CONINC */
#endif /* OS2 */
    return(x + y);
}
/* #endif */ /* USE_ARROWKEYS */


static VOID
cmdclrscn() {				/* Clear the screen */
    ck_cls();
}

static VOID				/* What to echo at end of command */
#ifdef CK_ANSIC
cmdnewl(char c)
#else
cmdnewl(c) char c;
#endif /* CK_ANSIC */
/* cmdnewl */ {
#ifdef OS2
#ifdef IKSD
    extern int inserver;
    if (inserver && c == LF)
      putchar(CR);
#endif /* IKSD */
#endif /* OS2 */

    putchar(c);				/* c is the terminating character */

#ifdef WINTCP				/* what is this doing here? */
    if (c == CR) putchar(NL);
#endif /* WINTCP */

/*
  A.A. Chernov, who sent in changes for FreeBSD, said we also needed this
  for SVORPOSIX because "setup terminal by termios and curses does
  not convert \r to \n, so additional \n needed in newline function."  But
  it is also very likely to result in unwanted blank lines.
*/
#ifdef BSD44
    if (c == CR) putchar(NL);
#endif /* BSD44 */

#ifdef COMMENT
    /* OS2 no longer needs this as all CR are converted to NL in coninc() */
    /* This eliminates the ugly extra blank lines discussed above.        */
#ifdef OS2
    if (c == CR) putchar(NL);
#endif /* OS2 */
#endif /* COMMENT */
#ifdef aegis
    if (c == CR) putchar(NL);
#endif /* aegis */
#ifdef AMIGA
    if (c == CR) putchar(NL);
#endif /* AMIGA */
#ifdef datageneral
    if (c == CR) putchar(NL);
#endif /* datageneral */
#ifdef GEMDOS
    if (c == CR) putchar(NL);
#endif /* GEMDOS */
#ifdef STRATUS
    if (c == CR) putchar(NL);
#endif /* STRATUS */
}

static VOID
cmdchardel() {				/* Erase a character from the screen */
#ifndef NOSPL
    if (!echostars)
#endif	/* NOSPL */
      if (!dpx) return;
#ifdef datageneral
    /* DG '\b' is EM (^y or \031) */
    if (termtype == 1)
      /* Erase a character from non-DG screen, */
      dgncoub(1,"\010 \010",3);
    else
#endif /* datageneral */
      printf("\b \b");
#ifdef GEMDOS
    fflush(stdout);
#else
#ifdef BEBOX
    fflush(stdout);
#endif /* BEBOX */
#endif /* GEMDOS */
}

static VOID
#ifdef CK_ANSIC
cmdecho(char c, int quote)
#else
cmdecho(c,quote) char c; int quote;
#endif /* CK_ANSIC */
{ /* cmdecho */
#ifdef NOSPL
    if (!dpx) return;
#else
    if (!echostars) {
	if (!dpx) return;
    } else {
	c = (char)echostars;
    }
#endif	/* NOSPL */
    /* Echo tty input character c */
    if (quote) {
	putchar(BS);
	putchar(SP);
	putchar(BS);
#ifdef isprint
	putchar((CHAR) (isprint(c) ? c : '^' ));
#else
	putchar((CHAR) ((c >= SP && c < DEL) ? c : '^'));
#endif /* isprint */
    } else {
	putchar(c);
    }
#ifdef OS2
    if (quote==1 && c==CR) putchar((CHAR) NL);
#endif /* OS2 */
    if (timelimit)
      fflush(stdout);
}

/* Return pointer to current position in command buffer. */

char *
cmpeek() {
    return(np);
}
#endif /* NOICP */


#ifdef NOICP
#include "ckcdeb.h"
#include "ckucmd.h"
#include "ckcasc.h"
#endif /* NOICP */

/*  X X E S C  --  Interprets backslash codes  */
/*  Returns the int value of the backslash code if it is > -1 and < 256 */
/*  and updates the string pointer to first character after backslash code. */
/*  If the argument is invalid, leaves pointer unchanged and returns -1. */

int
xxesc(s) char **s; {			/* Expand backslash escapes */
    int x, y, brace, radix;		/* Returns the int value */
    char hd = '9';			/* Highest digit in radix */
    char *p;

    p = *s;				/* pointer to beginning */
    if (!p) return(-1);			/* watch out for null pointer */
    x = *p++;				/* character at beginning */
    if (x != CMDQ) return(-1);		/* make sure it's a backslash code */

    x = *p;				/* it is, get the next character */
    if (x == '{') {			/* bracketed quantity? */
	p++;				/* begin past bracket */
	x = *p;
	brace = 1;
    } else brace = 0;
    switch (x) {			/* Start interpreting */
      case 'd':				/* Decimal radix indicator */
      case 'D':
	p++;				/* Just point past it and fall thru */
      case '0':				/* Starts with digit */
      case '1':
      case '2':  case '3':  case '4':  case '5':
      case '6':  case '7':  case '8':  case '9':
	radix = 10;			/* Decimal */
	hd = '9';			/* highest valid digit */
	break;
      case 'o':				/* Starts with o or O */
      case 'O':
	radix = 8;			/* Octal */
	hd = '7';			/* highest valid digit */
	p++;				/* point past radix indicator */
	break;
      case 'x':				/* Starts with x or X */
      case 'X':
	radix = 16;			/* Hexadecimal */
	p++;				/* point past radix indicator */
	break;
      default:				/* All others */
#ifdef COMMENT
	*s = p+1;			/* Treat as quote of next char */
	return(*p);
#else
	return(-1);
#endif /* COMMENT */
    }
    /* For OS/2, there are "wide" characters required for the keyboard
     * binding, i.e \644 and similar codes larger than 255 (byte).
     * For this purpose, give up checking for < 256. If someone means
     * \266 should result in \26 followed by a "6" character, he should
     * always write \{26}6 anyway.  Now, return only the lower byte of
     * the result, i.e. 10, but eat up the whole \266 sequence and
     * put the wide result 266 into a global variable.  Yes, that's not
     * the most beautiful programming style but requires the least
     * amount of changes to other routines.
     */
    if (*p == '{') {			/* Sun May 11 20:00:40 2003 */
	brace = 1;			/* Allow {} after radix indicator */
	p++;
    }
    if (radix <= 10) {			/* Number in radix 8 or 10 */
	for ( x = y = 0;
 	      (*p) && (*p >= '0') && (*p <= hd)
#ifdef OS2
                   && (y < 5) && (x*radix < KMSIZE);
              /* the maximum needed value \8196 is 4 digits long */
              /* while as octal it requires \1377, i.e. 5 digits */
#else
                   && (y < 3) && (x*radix < 256);
#endif /* OS2 */
	      p++,y++) {
	    x = x * radix + (int) *p - 48;
	}
#ifdef OS2
        wideresult = x;			/* Remember wide result */
        x &= 255;
#endif /* OS2 */
	if (y == 0 || x > 255) {	/* No valid digits? */
	    *s = p;			/* point after it */
	    return(-1);			/* return failure. */
	}
    } else if (radix == 16) {		/* Special case for hex */
	if ((x = unhex(*p++)) < 0) { *s = p - 1; return(-1); }
	if ((y = unhex(*p++)) < 0) { *s = p - 2; return(-1); }
	x = ((x << 4) & 0xF0) | (y & 0x0F);
#ifdef OS2
        wideresult = x;
        if ((y = unhex(*p)) >= 0) {
           p++;
	   wideresult = ((x << 4) & 0xFF0) | (y & 0x0F);
           x = wideresult & 255;
        }
#endif /* OS2 */
    } else x = -1;
    if (brace && *p == '}' && x > -1)	/* Point past closing brace, if any */
      p++;
    *s = p;				/* Point to next char after sequence */
    return(x);				/* Return value of sequence */
}

int					/* Convert hex string to int */
#ifdef CK_ANSIC
unhex(char x)
#else
unhex(x) char x;
#endif /* CK_ANSIC */
/* unhex */ {

    if (x >= '0' && x <= '9')		/* 0-9 is offset by hex 30 */
      return(x - 0x30);
    else if (x >= 'A' && x <= 'F')	/* A-F offset by hex 37 */
      return(x - 0x37);
    else if (x >= 'a' && x <= 'f')	/* a-f offset by hex 57 */
      return(x - 0x57);			/* (obviously ASCII dependent) */
    else return(-1);
}

/*  L O O K U P  --  Lookup the string in the given array of strings  */

/*
  Call this way:  v = lookup(table,word,n,&x);

    table - a 'struct keytab' table.
    word  - the target string to look up in the table.
    n     - the number of elements in the table.
    x     - address of an integer for returning the table array index,
	    or NULL if you don't need a table index.

  The keyword table must be arranged in ascending alphabetical order;
  alphabetic case doesn't matter but letters are treated as lowercase
  for purposes of ordering; thus "^" and "_" come *before* the letters,
  not after them.

  Returns the keyword's associated value (zero or greater) if found,
  with the variable x set to the keyword-table index.  If is lookup()
  is not successful, it returns:

   -3 if nothing to look up (target was null),
   -2 if ambiguous,
   -1 if not found.

  A match is successful if the target matches a keyword exactly, or if
  the target is a prefix of exactly one keyword.  It is ambiguous if the
  target matches two or more keywords from the table.

  Lookup() is the critical routine in scripts and so is optimized with a
  simple static cache plus some other tricks.  Maybe it could be improved
  further with binary search or hash techniques but I doubt it since most
  keyword tables are fairly short.
*/

#ifdef USE_LUCACHE			/* Lookup cache */
extern int lusize;			/* (initialized in ckuus5.c) */
extern char * lucmd[];
extern int luval[];
extern int luidx[];
extern struct keytab * lutab[];
long luhits = 0L;
long lucalls = 0L;
long xxhits = 0L;
long luloop = 0L;
#endif /* USE_LUCACHE */

int
lookup(table,cmd,n,x) char *cmd; struct keytab table[]; int n, *x; {

    register int i, m;
    int v, len, cmdlen = 0;
    char c = NUL, c1, *s;

/* Get 1st char of search object, if it's null return -3. */

    if (!cmd || n < 1)			/* Defense de nullarg */
      return(-3);
    c1 = *cmd;				/* First character */
    if (!c1)				/* Make sure there is one */
      return(-3);
    if (isupper(c1))			/* If letter make it lowercase */
      c1 = tolower(c1);

#ifdef USE_LUCACHE			/* lookup() cache */
    m = lusize;
    lucalls++;				/* Count this lookup() call */
    for (i = 0; i < m; i++) {		/* Loop thru cache */
	if (*(lucmd[i]) == c1) {	/* Same as 1st char of search item? */
	    if (lutab[i] == table) {	/* Yes - same table too? */
		if (!strcmp(cmd,lucmd[i])) { /* Yes - compare */
		    if (x) *x = luidx[i];    /* Match - return index */
		    luhits++;                /* Count cache hit */
		    return(luval[i]);        /* Return associated value */
		}
	    }
	}
    }
#endif /* USE_LUCACHE */

/* Not null, not in cache, look it up */

    s = cmd;
    while (*s++) cmdlen++;		/* Length of target */
/*
  Quick binary search to find last table entry whose first character is
  lexically less than the first character of the search object.  This is
  the starting point of the next loop, which must go in sequence since it
  compares adjacent table entries.
*/
    if (n < 5) {			/* Not worth it for small tables */
	i = 0;
    } else {
	int lo = 0;
	int hi = n;
	int count = 0;
	while (lo+2 < hi && ++count < 12) {
	    i = lo + ((hi - lo) / 2);
	    c = *(table[i].kwd);
	    if (isupper(c)) c = tolower(c);
	    if (c < c1) {
		lo = i;
	    } else {
		hi = i;
	    }
	}
	i = (c < c1) ? lo+1 : lo;
#ifdef USE_LUCACHE
	if (i > 0) xxhits++;
#endif /* USE_LUCACHE */
    }
    for ( ; i < n-1; i++) {
#ifdef USE_LUCACHE
	luloop++;
#endif /* USE_LUCACHE */
	v = 0;
	c = *(table[i].kwd);
	if (c) {
	    if (isupper(c)) c = tolower(c);

	    /* The following is a big performance booster but makes it */
	    /* absolutely essential that all lookup() tables are in order. */

	    if (c > c1)			/* Leave early if past our mark */
	      return(-1);

#ifdef DEBUG
	    /* Use LOG DEBUG to check */

	    if (deblog) {
		if (ckstrcmp(table[i].kwd,table[i+1].kwd,0,0) > 0) {
		    printf("TABLE OUT OF ORDER [%s] [%s]\n",
			   table[i].kwd,table[i+1].kwd);

		}
	    }
#endif /* DEBUG */

	    if (c == c1) {
		len = 0;
		s = table[i].kwd;
		while (*s++) len++;
		if ((len == cmdlen && !ckstrcmp(table[i].kwd,cmd,len,0)) ||
		    ((v = !ckstrcmp(table[i].kwd,cmd,cmdlen,0)) &&
		     ckstrcmp(table[i+1].kwd,cmd,cmdlen,0))) {
		    if (x) *x = i;
		    return(table[i].kwval);
		}
	    } else v = 0;
	}
        if (v) {			/* Ambiguous */
	    if (x) *x = i;		/* Set index of first match */
	    return(-2);
	}
    }

/* Last (or only) element */

    if (!ckstrcmp(table[n-1].kwd,cmd,cmdlen,0)) {
        if (x) *x = n-1;
	/* debug(F111,"lookup",table[i].kwd,table); */
        return(table[n-1].kwval);
    } else return(-1);
}

/*
  x l o o k u p

  Like lookup, but requires a full (but case-independent) match
  and does NOT require the table to be in order.
*/
int
xlookup(table,cmd,n,x) struct keytab table[]; char *cmd; int n, *x; {
    register int i;
    int len, cmdlen, one = 0;
    register char c, c2, * s, * s2;

    if (!cmd) cmd = "";			/* Check args */
    if (!*cmd || n < 1) return(-3);

    c = *cmd;				/* First char of string to look up */
    if (!*(cmd+1)) {			/* Special handling for 1-char names */
	cmdlen = 1;
	if (isupper(c))
	  c = tolower(c);
	one = 1;
    } else {
	cmdlen = 0;
	s = cmd;
	while (*s++) cmdlen++;
	c = *cmd;
	if (isupper(c))
	  c = tolower(c);
    }
    if (cmdlen < 1)
      return(-3);

    for (i = 0; i < n; i++) {
	s = table[i].kwd;		/* This entry */
	if (!s) s = "";
	if (!*s) continue;		/* Empty table entry */
	c2 = *s;
	if (isupper(c2)) c2 = tolower(c2);
	if (c != c2) continue;		/* First char doesn't match */
	if (one) {			/* Name is one char long */
	    if (!*(s+1)) {
		if (x) *x = i;
                *cmd = c; 
		return(table[i].kwval);	/* So is table entry */
	    }
	} else {			/* Otherwise do string comparison */
	    s2 = s;
	    len = 0;
	    while (*s2++) len++;
	    if (len == cmdlen && !ckstrcmp(s,cmd,-1,0)) {
		if (x) *x = i;
		return(table[i].kwval);
	    }
	}
    }
    return(-1);
}

/* Reverse lookup */

char *
rlookup(table,n,x) struct keytab table[]; int n, x; {
    int i;
    for (i = 0; i < n; i++) {
        if (table[i].kwval == x)
	  return(table[i].kwd);
    }
    return(NULL);
}

#ifndef NOICP
int
cmdsquo(x) int x; {
    quoting = x;
    return(1);
}

int
cmdgquo() {
    return(quoting);
}
#endif /* NOICP */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment