#
# You must get the source code for cipher first; then edit DESDIR.
#   ftp.uu.net:/pub/security/des/cipher-3.0.tar.Z
#
# Find the set of lines which corresponds to your configuration, and uncomment
# them.  If you have a machine not listed here, the most likely configuration
# to work is the one for SunOS 4.1.1, or Gnu CC.   
#
# Type "make".
#
# If you get the error "Don't know how to make target `desblock.o'", just type
# "make" again; this is a symlink dependency which was resolved by the 1st make.
# This shouldn't happen anymore, but I thought I'd mention it just in case.
# 
# You will have to supply a default decryption key if you wish to compile
# the server process "deslogind".
#
# If everything compiles, type "make install" to see how to finish 
# installation and configuration.
#
# Read the man pages for deslogin and deslogind with "nroff -man"
#
# Test your installation.  Login via deslogin.  Verify the following:
#    The "who -a" command prints your correct username, tty, login time,
#        deslogind's pid, and remote host.
#    The "tty" command prints your correct login pty.
#    The pty returned by the tty command has correct ownership and permissions.
#    The "groups" command prints your correct supplementary group id's.
#    The "id" command prints your correct user/group name and id.
#    The "last -10" command prints correct login name.
#    Interrupt and job-control signals (usually Ctl-C, Ctl-Z) work correctly
#    Reading and writing from /dev/tty work correctly.
#    Login as a user without a .profile/.login file, and verify that
#       the environment is initialized the same as the login program.
#    Examine the deslogind log file for warnings or error messages.
#    Kill the current shell with signal SIGILL using the command "kill -4 $$"
#       verify "who -a": id=<last two chars of tty>, term=132, exit=0
#       verify that the date and time are the time of the process death.
#       verify that the duration of the login was correct.
#    Repeat the previous test, but exit with the command "exit 99".
#       verify "who -a": id=<last two chars of tty>, term=0, exit=99
#    Verify that "last -10" shows the correct information.
#
# If you must create a new configuration, see the comments below.
#
# Dave Barrett (barrett@asgard.cs.Colorodo.EDU
#
# Makefile  RCS: $Revision: 1.10 $ $Date: 95/03/08 02:30:33 $
# 
SHELL=/bin/sh
CC=@echo "you really must edit the makefile for your machine"; exit 1

#
# For "make install"
#
MANDIR=/usr/local/man/man1
BINDIR=/usr/local/bin

#
# Get cipher-3.0.tar.Z from ftp.uu.net:/pub/security/des
# and untar it into $(DESDIR)
#
DESDIR	= ../cipher-3.0

#
# When using a dialup line to a non-slip capable terminal server, there
# is a package which allows you to multiplex the serial line.  See
# sunsite.unc.edu:/pub/Linux/apps/comm/term/term/term117.tar.gz for details.
#    For term installations - Set these variables to point to the right place
# You must have compiled term before making this so that client.a exists
#
# If you don't know what this means, just leave these lines as they are.
# 
# Thanks to Mark (Mookie) mark@netsys.com for adding this feature.
#
TERMDIR=
TERMLIBS=
TERMINC=
TERMDEFINES=
TERMBIN=
##Example:
#TERMDIR=/work/term114
#TERMLIBS=$(TERMDIR)/client.a
#TERMINC=$(TERMDIR)
#TERMDEFINES=-I$(TERMINC) -DTERM_LINK
#TERMBIN=termdeslogin

#
# Configuration options to deslogind.  Others in deslogind.c and deslogin.h 
# should be correct; if not, see note above "LOGINDFLAGS" below.
#
USER_FILE=\"/usr/local/etc/deslogind.users\"
LOG_FILE=\"/usr/adm/deslogind.log\"
PWDLOG_FILE=\"/usr/adm/dlpwd.log\"
GW_LOG_FILE=\"/usr/adm/deslogingw.log\"
# LOGIN_PROC is only used for the -w option to deslogind; nowhere else.
LOGIN_PROG=\"/bin/login\"
#
# Add -D_USE_SYSLOG to NSTCFLAGS if you want to log messages via to syslogd 
# instead of the logfile.  It only affects code in the file log.c.  I prefer to
# use a logfile instead of syslogd so that I don't have to worry about a hostile
# user hijacking the connection to syslogd, or installing a Trojan horse for
# for syslogd, or, even worse, having syslogd be on a remote unsecure machine.
# This feature may go away when I add encryption to the logging facility.
#
# Add -D_USE_STREAMS if you prefer to use System V style streams for pty
# handling.  Some machines require this for pty.c to work correctly.
#
#DEBUG=-g
DEBUG=-O # -D_USE_SYSLOG

## HP-UX Ansi C compiler
#CC      = cc -Aa
#CFLAGS	= $(DEBUG)
#LDFLAGS	= $(DEBUG) -Wl,-a,archive -s
#NSTCFLAGS=$(DEBUG) -D_HPUX_SOURCE # make non-posix symbols visable 

## HP-UX C++ compiler (won't work because typedef pfv in posignal.h)
#CC	= CC
#CFLAGS	= $(DEBUG)
#LDFLAGS= $(DEBUG) -Wl,-a,archive # -s 
#NSTCFLAGS=$(DEBUG) -D_HPUX_SOURCE

## DEC MIPS Ultrix 4.3 ANSI C compiler 
#CC	  = cc -std -non_shared
#CFLAGS	  = $(DEBUG)
#LDFLAGS  = $(DEBUG) -non_shared  # -s 
#NSTCFLAGS=$(DEBUG) -DONLCR=0x00000004

## DEC MIPS Ultrix 4.2 Non-ANSI C compiler 
#CC	= cc -YPOSIX
#CFLAGS	= $(DEBUG)
#LDFLAGS	= $(DEBUG) -YSYSTEM_FIVE # -s 
#NSTCFLAGS=$(DEBUG) -D__MIPS -DONLCR=0x00000004

## DEC Alpha OSF/1 C compiler
#CC	= cc -std -non_shared
#CFLAGS	= $(DEBUG)
#LDFLAGS = $(DEBUG) -non_shared  # -s 
#NSTCFLAGS=$(DEBUG) -D_XOPEN_SOURCE -D_OSF_SOURCE -D__ALPHA

## DEC Alpha OSF/1 C++ compiler  (OSF1 V2.0 240 alpha)
##  don't enable -O: generates incorrect code: progName output as junk
#CC	= cxx -non_shared
#CFLAGS	= $(DEBUG)
#LDFLAGS  =$(DEBUG) -non_shared # -s
#NSTCFLAGS=$(DEBUG) -non_shared -D_XOPEN_SOURCE -D_OSF_SOURCE -D__ALPHA
## ONLCR, non-posix symbols, controlling terminal

## Sun SPARC SunOS 4.1.1 BSD C compiler
##
## Must add -DWTMP_FILE=\"/var/adm/wtmp\" on installations that
## don't have #define WTMP_FILE in /usr/include/utmp.h.
##
#CC       = cc
#CFLAGS	  =$(DEBUG) -Bstatic -Dsparc	# need -Dsparc if missing atexit
#LDFLAGS  =$(DEBUG) -Bstatic # -s
#NSTCFLAGS=$(DEBUG) -Bstatic -Dsparc -DONLCR=0x00000004
#LIBS = -lresolv

## Sun Sun3 SunOS 4.1 BSD C compiler
#CC       = cc
#CFLAGS   =$(DEBUG) -Bstatic -Dsun3
#LDFLAGS  =$(DEBUG) -Bstatic # -s
#NSTCFLAGS=$(DEBUG) -Bstatic -Dsun3 -DONLCR=0x00000004

## Data General DG/UX 5.4.R2.01 Gnu Compiler 
#CC	 = gcc -static
#CFLAGS	 = $(DEBUG) -DDGUX
#LDFLAGS  = $(DEBUG)
#NSTCFLAGS= $(DEBUG) -DDGUX

## SGI MIPS IRIX ANSI C Compiler using _getpty
##
## -D__sgi necessary to compile utmp.c pty.c
## -D__EXTENSIONS__ for _getpty declaration in <unistd.h> for pty.c
##
## SGI in their infinite wisdom has decided not to support non-shared libraries
## by default as of IRIX 5.1.1.2.  This feature causes serious security 
## problems because there are subtle ways to trojan horse library calls.
## If at all possible, install /usr/lib/nonshared and compile and link with
## the -non_shared option.
##
#CC	 = cc -ansi -non_shared
#CFLAGS	 = $(DEBUG) -D__sgi  -D__EXTENSIONS__
#LDFLAGS  = $(DEBUG) -non_shared
#NSTCFLAGS= $(DEBUG) -D__sgi -D_XOPEN_SOURCE  -D__EXTENSIONS__

## SGI MIPS IRIX C Compiler using _getpty.
##
## IRIX 5.1.1.2 will not compile with -ansi because the include file for 
## tcp.h won't compile a u_char bitfield.  
##
#CC	 = cc -non_shared
#CFLAGS	 = $(DEBUG) -D__sgi
#LDFLAGS  = $(DEBUG) -non_shared
#NSTCFLAGS= $(DEBUG) -D__sgi -D_XOPEN_SOURCE

## SGI MIPS IRIX ANSI C Compiler 
## using AT&T System V Streams Package instead of _getpty.
##
## (fails to work as of 08-Mar-95 <barrett@asgard.cs.colorado.edu>)
##
#CC	 = cc -ansi -non_shared
#CFLAGS	 = $(DEBUG) -D__sgi -D_USE_STREAMS
#LDFLAGS  = $(DEBUG) -non_shared
#NSTCFLAGS= $(DEBUG) -D__sgi -D_XOPEN_SOURCE

##
## Solaris <barrett@asgard.cs.colorado.edu>
##
## C Compiler (cc) or Gnu C compiler (gcc)
##
## Dynamic linking is required because NIS (alias yp) routines
## require it  (as listed under "BUGS" in the man page for getpwent).
##
## SunOS 5.4 cc
## SunOS 5.3 gcc 2.5.8
## SunOS 5.4 gcc 2.6.0 requires -D__EXTENSIONS__ for struct timeval
## SunOS 5.4 requires -Dtimespec=_timespec to fix problem in sys/types.h
##           when __EXTENSIONS__ is defined.  I don't use timespec anyway.
##           Tested by <barrett@asgard.cs.colorado.edu> 25-Jan-95
##
## -DUTMPX if you want utmpx & wtmpx records updated in addition to utmp & wtmp.
##           Tested by <gertz@tds.com> 04-Mar-95
##
#CC = cc
#CC = gcc
#CFLAGS = $(DEBUG) -D__SOLARIS__ -D_USE_STREAMS -DUTMPX
#LDFLAGS = $(DEBUG)
#NSTCFLAGS= $(DEBUG) -D__SOLARIS__ -D_USE_STREAMS -D_XOPEN_SOURCE -D__EXTENSIONS__ -Dtimespec=_timespec
#LIBS = -lsocket -lnsl

## Cray UNICOS Compiler (untested)
#CC	 = cc
#CFLAGS	 = $(DEBUG) -D__UNICOS__
#LDFLAGS  = $(DEBUG)
#NSTCFLAGS= $(DEBUG) -D__UNICOS__ -D_XOPEN_SOURCE

## Sequent Dynix 386 (untested) <skrenta@pbm.com>
## -D__DYNIX__ needed for utmp.c txfr.c
## _SEQUENT_ and i386 are the normal compiler predifines
#CC	  = cc
#CFLAGS	  = $(DEBUG) -D__DYNIX__
#LDFLAGS  = $(DEBUG)
#NSTCFLAGS= $(DEBUG) -D__DYNIX__ -D_XOPEN_SOURCE
#LIBS     = -lseq -linet -lnsl -lsocket -linet

## BSD/386 1.1 0 i386 gcc - Probably any net/2.  
#LOG_FILE=\"/var/log/deslogind.log\"
#GW_LOG_FILE=\"/var/log/deslogingw.log\"
#LOGIN_PROG=\"/usr/bin/login\"
#CC       =gcc -ansi
#CFLAGS	 =$(DEBUG)
#LDFLAGS  =$(DEBUG)
#NSTCFLAGS=$(DEBUG) -D__bsdi__ -D_USE_SYSLOG

## Gnu C compiler
#CC	= gcc -ansi
#CFLAGS	= $(DEBUG)
#LDFLAGS = $(DEBUG)

## Gnu C compiler with lots of warnings (not useful except for debugging)
#CC	= gcc -ansi -pedantic
#CFLAGS	= $(DEBUG) -Wall
#LDFLAGS = $(DEBUG)
#NSTCFLAGS=$(DEBUG) -Wall -D_HPUX_SOURCE
#NSTCFLAGS=$(DEBUG) -D_XOPEN_SOURCE -D_OSF_SOURCE -D__ALPHA

# Linux GNU C compiler
# -D_LINUX_SOURCE is necessary for to compile getkey.c for cipher.
# If you already have cipher installed, you don't need the one here.
CC	 = gcc -ansi
CFLAGS	 = $(DEBUG) -Dlinux -D_LINUX_SOURCE
LDFLAGS  = $(DEBUG)
NSTCFLAGS= $(DEBUG) -Dlinux
LIBS= -lndbm

## AIX 3.2.5 GNU C compiler (not tested) <gl8f@fermi.clas.virginia.edu>
## -DAIX necessary for txfr.c
## -DONLCR necessary for tty.c
#CC	  = gcc -ansi
#CFLAGS	  = $(DEBUG) -DAIX
#LDFLAGS  = $(DEBUG)
#NSTCFLAGS= $(DEBUG) -DAIX -DONLCR=0x00000004

# Gnu C++ compiler cannot handle old-style function argument declaratons 
# If you figure out how to make it accept them, please send mail to the author.

#
# If you have to read this comment, send mail to barrett@asgard.cs.Colorado.EDU.
# The file "Notes" includes some old notes I wrote which may help you.
#
# Non-standard object files require special non-posix features be available in 
# order to compile and link.  NSTCFLAGS are flags to the compiler to make 
# non-posix symbols and features available.  
#
# Here are the problem areas in porting to new machines:
#
#    log.c:   vsprintf must return an int.  If it doesn't, you have a
#             non-ANSI machine.  It also needs ANSI's stdarg.h.
#             The default source should work, since it tries to detect these.
#             openlog doesn't return a value on some BSD machines.
#    tty.c:   If you don't have POSIX termios, you're hosed.  This code is
#             completely POSIX except:  The flag ONLCR is not part of POSIX.  
#             Some machines require an ioctl to acquire the controlling terminal
#             for the session leader.  See the function mkCtrlTty.
#   txfr.c:   depends heavily upon the BSD select(2) semantics, which are
#             only vaguely documented.  If the code runs incorrectly here, 
#             it's a bitch to diagnose and fix.
#  socket.c:  Networking isn't POSIX yet.  This isolates all networking calls.
#  posignal.h: The arguments to a signal handler are machine-specific.
#     pty.c:  Many newer POSIX style machines do pty stuff completely
#             differently from eachother. I've had to hack this a bit.
#
# If any of the above files fail to compile, it's most likely because the
# header files on your system require a compilation option to make non-posix
# symbols visible.  For example, <sys/types.h> declares u_short which is
# required to compile socket.c.  To get around this problem, I've not defined
# _POSIX_SOURCE until *after* <sys/types.h> and <sys/time.h> are included,
# which "fixes" the problem on most machines.  For the ONLCR problem, 
# grep for "ONLCR" in /usr/include{/sys}/termio*.h.  Once you find that 
# symbol, look for an #ifdef to enable it and add that flag to NSTCFLAGS
# in this Makefile.
#
# Make *SURE* to enable the compile options to not use shared libraries or
# run-time procedure binding because it enables a serious trojan horse.
# Many vendors enable dynmaic binding by default; so be careful.
#
# The include files and source is constructed to make it easy to change some 
# of the default source in this makefile rather than hacking on the C source 
# directly.  This will make your life easier when new releases come out.
# Just add a "-D<name>=<value>" to LOGINDFLAGS below.  For example see 
# the -DLOG_FILE=...below.  All these values have suitable defaults.  You 
# don't need to touch them unless you want to or I've set them incorrectly by 
# default.
#
# deslogin.h:
#    SETUP_TIMEOUT	ms for login sequence handshake
#    LOGIN_TIMEOUT	seconds to wait for passphrase response
#    INACTIVITY_TIMEOUT	seconds of no I/O activity before terminationg session
#    DESLOGIN_PORT	"Well-known" Port to post listen to for deslogind
#    SERVICE_NAME	The name of the deslogin service in /etc/services
#    LOGIN_PROG		Full pathname of login program for -w option
#
# deslogind.c:
#    DEFAULT_UMASK	Passed to umask(2) upon login.
#    TTY_MODE		Permissions for controlling terminal slave pty device
#    USERPATH		Default path
#    SYSTEMPATH		Default path for user id 0.
#    DEFAULT_TERM	What to set the TERM envt variable to.
#    USER_FILE		Path of file containing passphrase username pairs
#    NOLOGIN_FILE	File which denies all logins containing denial message
#    LOG_FILE		Where to output all logging messages
#
# txfr.c:
#    WRITE_RETRY_TIME	ms timeout for EAGAIN error on write attempt
#

# Don't change anything below this line unless you are porting to a new
# incompatable platform and the existing configuration fails to work.
LOGINDFLAGS=-DUSER_FILE=$(USER_FILE) -DLOG_FILE=$(LOG_FILE) -DLOGIN_PROG=$(LOGIN_PROG)
GWFLAGS=-DGW_LOG_FILE=$(GW_LOG_FILE)

DESSRC	= desblock.c deskey.c descfb.c sboxp.c
DESBINSRC = cipher.c getkey.c
DESBINOBJ = $(DESBINSRC:.c=.o)
DESOBJ	= $(DESSRC:.c=.o)
DESHDR	= cipher.h des.h desdefs.h
DESMAN	= cipher.1

DIST	= deslogin
CLIHDR	= posignal.h tty.h auth.h txfr.h socket.h log.h deslogin.h utmp.h \
          dlg2dbm.h dbm2dlg.h dladduser.h dlrmuser.h
SERHDR  = $(CLIHDR) pty.h  group.h
HDR	= $(SERHDR)
CSRC	= deslogin.c deslogind.c deslogingw.c log.c pty.c socket.c txfr.c \
          group.c tty.c posignal.c utmp.c auth.c gendeskd.c dlg2dbm.c \
	  dbm2dlg.c dlpasswd.c dlpasswdd.c dladduser.c dlrmuser.c
MANSRC	= deslogin.1 deslogind.1
NSTOBJ	= socket.o txfr.o group.o
OBJS	= $(DESSRC:.c=.o) $(DESBINSRC:.c=.o) $(CSRC:.c=.o)
BINS	= deslogin deslogingw cipher deslogind dlpasswdd gendeskd dlg2dbm \
	  dbm2dlg dlpasswd dladduser dlrmuser $(TERMBIN)

SRC	= README Makefile deslogind.users Notes	keymsg \
	  $(HDR) $(CSRC) $(MANSRC)

COMOBJ  = tty.o posignal.o auth.o log.o $(DESOBJ)


all:		$(BINS)

deslogin:	deslogin.o $(COMOBJ) socket.o txfr.o utmp.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(COMOBJ) socket.o txfr.o utmp.o $(LIBS)

$(TERMBIN) dummy: deslogin.o $(COMOBJ) termsocket.o txfr.o utmp.o
		$(CC) $(LDFLAGS) -o $@ deslogin.o $(COMOBJ) termsocket.o \
		txfr.o utmp.o $(TERMLIBS)
		mv $@ $(TERMBIN)

deslogind:	deslogind.o $(COMOBJ) pty.o utmp.o $(NSTOBJ) defkey.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(COMOBJ) pty.o utmp.o defkey.o \
		$(NSTOBJ) $(LIBS)

dlpasswdd:	dlpasswdd.o $(COMOBJ) $(NSTOBJ) defkey.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(COMOBJ) defkey.o \
		$(NSTOBJ) $(LIBS)
		cat dlpasswdd.o >defkey.o
		rm defkey.o

dlpasswd:   	dlpasswd.o $(COMOBJ) socket.o txfr.o utmp.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(COMOBJ) socket.o txfr.o utmp.o $(LIBS) 

deslogingw:	deslogingw.o $(COMOBJ) socket.o txfr.o 
		$(CC) $(LDFLAGS) -o $@ $@.o $(COMOBJ) socket.o txfr.o $(LIBS)


dlg2dbm:	dlg2dbm.o $(DESOBJ) tty.o log.o posignal.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(DESOBJ) tty.o log.o posignal.o \
                $(LIBS)

dbm2dlg:	dbm2dlg.o $(DESOBJ) tty.o log.o posignal.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(DESOBJ) tty.o log.o posignal.o \
                $(LIBS)

dladduser:	dladduser.o $(DESOBJ) tty.o log.o posignal.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(DESOBJ) tty.o log.o posignal.o \
		$(LIBS)

dlrmuser:	dlrmuser.o $(DESOBJ) tty.o log.o posignal.o
		$(CC) $(LDFLAGS) -o $@ $@.o $(DESOBJ) tty.o log.o posignal.o \
		$(LIBS)

deslogind.o:	deslogind.c $(SERHDR) $(DESHDR)
		$(CC) $(LOGINDFLAGS) $(CFLAGS) -c deslogind.c

deslogingw.o:	deslogingw.c $(SERHDR) $(DESHDR)
		$(CC) $(GWFLAGS) $(CFLAGS) -c deslogingw.c

deslogin.o:	deslogin.c $(CLIHDR) $(DESHDR)
		$(CC) $(CFLAGS) -c deslogin.c

cipher:		$(DESBINOBJ) $(DESOBJ)
		$(CC) $(LDFLAGS) -o $@ $(DESBINOBJ) $(DESOBJ)

gendeskd:	gendeskd.o getkey.o $(DESOBJ)
		$(CC) $(LDFLAGS) -o $@ $@.o getkey.o $(DESOBJ)

defkey.o:	defkey.c
		$(CC) $(CFLAGS) -c defkey.c
		cat deslogin.h >defkey.c
		rm defkey.c

# Force symlinks to be created before attempting to compile $(DESOBJ)

cipher.h:	links

defkey.c:	gendeskd
		@if [ ! -f keymsg-ok ]; then cat keymsg; touch keymsg-ok; fi
		@./gendeskd > $@.tmp
		@mv $@.tmp $@

socket.o:	socket.c
		$(CC) $(NSTCFLAGS) -c socket.c

termsocket.o:	termsocket.c
		$(CC) $(NSTCFLAGS) $(TERMDEFINES) -c termsocket.c

termsocket.c:	socket.c
		rm -f $@
		ln socket.c $@

txfr.o:		txfr.c
		$(CC) $(NSTCFLAGS) -c txfr.c

group.o:	group.c
		$(CC) $(NSTCFLAGS) -c group.c

getkey.o:	getkey.c
		$(CC) $(NSTCFLAGS) -c getkey.c

log.o:		log.c
		$(CC) $(NSTCFLAGS) -c log.c

tty.o:		tty.c
		$(CC) $(NSTCFLAGS) -c tty.c

man:		$(MANSRC)
		nroff -man <$(MANSRC)

# No changes needed below here

install:	# $(BINS) $(MANSRC) 
	@echo
	@echo You must install by hand.  Running automatic installation
	@echo scripts \(especially as root\) is extremely dangerous.
	@echo
	@echo It's more secure if $(BINS) are 
	@echo stripped, linked statically, and not readable or writeable by 
	@echo users other than owner.  They should *NOT* be setuid but 
	@echo they can and should be executable by anyone.
	@echo 
	@echo The following two commands should work:
	@echo "   strip $(BINS)
	@echo "   chmod 111 $(BINS)"
	@echo
	@echo --- For system-wide installations ---
	@echo Deslogind should be owned by root.
	@echo Add to /etc/services:
	@echo "   deslogin 3005/tcp"
	@echo "   deslogingw 3006/tcp"
	@echo Add to /etc/inetd.conf: 
	@echo "   deslogin stream tcp nowait root $(BINDIR)/deslogind deslogind -c"
	@echo "   deslogingw stream tcp nowait root $(BINDIR)/deslogingw deslogingw -c"
	@echo Make sure $(USER_FILE) exists. 
	@echo "   If you use deslogind with -c, make sure the file is encrypted"
	@echo with cipher using the same passphrase you specifed when building 
	@echo deslogind.  See the deslogind man page for details.
	@echo
	@echo Install the executables with the following commands:
	@echo "   cp $(BINS) $$(BINDIR)"
	@echo "   cp $(MANSRC) $(MANDIR)"
	@echo

links:		$(DESDIR)
		if [ ! -f  "$(DESDIR)/des.h" ]; then \
		   echo get cipher source code and install in $(DESDIR); \
		   exit 1; \
		else \
		   for i in $(DESSRC) $(DESBINSRC) $(DESHDR); do \
		      if [ ! -r $$i ]; then ln -s $(DESDIR)/$$i .; fi; \
		   done \
		fi
		touch links

cleanlinks:	$(DESDIR)
		for i in $(DESSRC) $(DESBINSRC) $(DESHDR); do \
		   if [ -r $$i ]; then rm -f $$i; fi; \
		done
		rm termsocket.c
		rm -f links

$(DIST).tar:	$(SRC)
		tar -cvhf - $(SRC) >$(DIST).tar

tar:		$(DIST).tar
		touch tar
	
tar.Z:		tar
		compress <$(DIST).tar >$(DIST).tar.Z

tar.gz:		tar
		gzip <$(DIST).tar >$(DIST).tar.gz

dist:		tar
		@set -x; \
		VERS=`grep version deslogind.c | \
		sed -e 's/^.*version \([0-9.]\{1,3\}\).*$$/\1/'`; \
		NAME=$(DIST)-$${VERS}; \
		echo "$${NAME}"; \
		if [ -d "$${NAME}" ]; then \
		   rm -f $${NAME}/*; rmdir $${NAME}; \
		fi; \
		mkdir $${NAME}; \
		cd $${NAME}; \
		tar -xf ../$(DIST).tar; \
		cd ..; \
		tar -cf - $${NAME} | gzip >$${NAME}.tar.gz;
		touch dist

shar:		$(SRC)
		shar $(SRC) >$(DIST).shar

btoa:		tar
		btoa <$(DIST).tar.Z >$(DIST).btoa

clean:
		rm -f $(OBJS) termsocket.o defkey.c keymsg-ok $(BINS)

clobber: 	clean cleanlinks
