# Make file for telnet directory
#
# Things you might want to change.  Pass them in on the command line:
# ROOT - should point to the root where the commands will be installed
#        (e.g. /deliver/INETSVCS/indnetwk)

ROOT=

PRODUCTS=/usr/bin/telnet

# Defaults file containing the shell, compiler options, etc
BUILDRULES=/source/INETSVCS/$(LOGNAME)/config/defaults

include ${BUILDRULES}

INCLUDES= -I../include -I/usr/include
CCFLAGS=$(INCLUDES) $(CFLAGS) 

OBJS=	main.o commands.o network.o ring.o sys_bsd.o \
	telnet.o terminal.o tn3270.o utilities.o

SRCS=	main.c commands.c network.c ring.c \
	sys_bsd.c telnet.c terminal.c \
	tn3270.c utilities.c

HDRS=	defines.h externs.h fdset.h general.h \
	ring.h types.h

LDLIBRARIES=    ../util/libutil.a

#Install database name
INSTALLDB=/source/INETSVCS/$(LOGNAME)/config/installdb

#Script called to parse the install deliverable
INSTALLSCPT=/source/INETSVCS/$(LOGNAME)/config/install_script

default: all

all: clean build install

clean:
	$(RM) -f $(OBJS) authenc.o vers.o vers.c
	$(RM) -f telnet ktelnet
	
install:
	for file in $(PRODUCTS) ; do \
		$(INSTALLSCPT) $$file $(INSTALLDB) ;  \
	done

build:  telnet

vers.c:
	$(SHELL) newvers.sh
	$(CC) $(CCFLAGS) -c vers.c

kvers.c:
	$(SHELL) newvers.sh
	$(CC) $(CCFLAGS) -DAUTHENTICATION -c vers.c

telnet: $(SRCS) vers.c
	$(ECHO) "Building telnet..."
	$(CC) -c $(CCFLAGS) $(SRCS) vers.c
	$(CC) $(LDFLAGS) -o $@ vers.o $(OBJS) $(LDLIBRARIES)

ktelnet: $(SRCS) kvers.c authenc.c
	$(ECHO) "Building ktelnet..."
	$(CC) -c $(CCFLAGS) -DAUTHENTICATION $(SRCS) vers.c authenc.c
	$(CC) $(LDFLAGS) -o $@ vers.o $(OBJS) authenc.o $(LDLIBRARIES) \
		../libtelnet/libtelnet.a -lkrb5 -lisode \
		-lcom_err -lcrypto -lndbm

versionlog:
	$(RM) -f version.log
	VERSION=`awk '{print $$2}' version` ; \
	$(ECHO) "Revision $$VERSION contains the following telnet sources:\n" >version.log
	for i in $(SRCS) $(HDRS) ; do \
		if [ "$$i" = "vers.c" ] ; then \
			continue; \
		fi ; \
		ident $$i | grep Header | \
		awk 'BEGIN { spaces="             ";\
			     tablen=15-length(FILE)+1;\
			     tab=substr(spaces,1,tablen);\
			    }\
		     {print FILE tab $$3}' FILE=$$i ; \
	done | sort | pr -2 -t >>version.log

