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

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

include ${BUILDRULES}

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

SRCS=   main.c vers.c cmds.c cmdtab.c ftp.c glob.c ruserpass.c domacro.c
OBJS=   main.o vers.o cmds.o cmdtab.o ftp.o glob.o ruserpass.o domacro.o
HDRS=   ftp_var.h pathnames.h

COMMON_OBJS= main.o ftp.o cmds.o vers.o

CCFLAGS=$(INCLUDES) $(CFLAGS) -Ae -Dunix -Dhpux
LF_FLAGS=-D__STDC_EXT__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

KRB5_CCFLAGS=-DGSSAPI

LDLIBRARIES=    ../util/libutil.a

LD_KRB5_LIBS=   -lgssapi_krb5 -lkrb5 -lcrypto -lisode -lcom_err

#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 *.o
	$(RM) -f core
	$(RM) -f ftp
	$(RM) -f kftp
	$(RM) -f vers.c
	
build:  ftp 

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

# The ftp and kftp targets share common source that differ only
# in their use of compilation flags.  Both targets will re-compile 
# the sources for COMMON_OBJS to ensure that the source files have 
# been compiled with the correct compilation flag.  This is safe, 
# but not optimum.

ftp:    common_source $(SRCS)
	$(ECHO) "Building ftp..."
	if \
		grep -q -E "(inet_mlp|inet_100)"  RMTBRANCH ; \
	then \
		$(CC) -c -DNO_LARGE_UID $(CCFLAGS) -D_SVID2 $(SRCS) ; \
		$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBRARIES) -lV3 ; \
	elif \
		grep -q inet_wc  RMTBRANCH ; \
	then \
		$(CC) -c -DNO_LARGE_UID $(CCFLAGS) $(SRCS) ; \
		$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBRARIES) ; \
	else \
		$(CC) -c $(CCFLAGS) $(LF_FLAGS) $(SRCS) ; \
		$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBRARIES) ; \
	fi

kftp:   common_source $(SRCS)
	$(ECHO) "Building kftp..."
	if \
		grep -q -E "(inet_mlp|inet_100)" RMTBRANCH ; \
	then \
		echo "KFTP IS NOT AVAILABLE FOR PRE WALNUT CREEK" ; \
	elif \
		grep -q inet_wc RMTBRANCH ; \
	then \
		$(CC) -c $(CCFLAGS) $(KRB5_CCFLAGS) $(SRCS) ; \
		$(CC) $(LDFLAGS) -o $@ $(OBJS) -L ../klib $(LD_KRB5_LIBS) ; \
	else \
		$(CC) -c $(CCFLAGS) $(KRB5_CCFLAGS) $(LF_FLAGS) $(SRCS) ; \
		$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LD_KRB5_LIBS) ; \
	fi

common_source: 
	$(RM) -f $(COMMON_OBJS)
	
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 ftp sources:\n" >version.log
	for i in $(SRCS) $(HDRS) ; do \
		if [ "$$i" = "vers.c" ] ; then \
			continue; \
		fi ; \
		ident $$i | grep Header | \
		awk ' {printf ("%-20s %-20s\n", FILE, $$3)}' FILE=$$i ; \
	done | sort | pr -2 -t >>version.log
