# Make file for rdist 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/rdist

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

include ${BUILDRULES}

INCLUDES=-I. -I../include -I/usr/include

SRCS=   docmd.c expand.c gram.c lookup.c main.c server.c vers.c
OBJS=   docmd.o expand.o gram.o lookup.o main.o server.o vers.o
HDRS=   defs.h pathnames.h

CCFLAGS=$(INCLUDES) $(CFLAGS)

KSH=/usr/bin/ksh
YACC=/opt/langtools/bin/yacc
MV=/usr/bin/mv

YFLAGS=-d

#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)
	$(RM) -f y.tab.?
	$(RM) -f rdist
	$(RM) -f vers.c
	
build:  rdist

gram.o: gram.y
	$(YACC) $(YFLAGS) gram.y
	$(MV) y.tab.c gram.c

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

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

install:
	for file in $(PRODUCTS) ; do \
		$(INSTALLSCPT) $$file $(INSTALLDB) ;  \
	done

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

