#
# Copyright (c) y2k Micha Moskal <malekith@topnet.pl>
#
# This file is part of cryptoFTP - cftp protocol implementation.
# CryptoFTP is free software. You can redistribute it and/or modify it under
# the terms of the GNU General Public License (see COPYING.GPL for details).
#
# $Id: Makefile,v 1.12 2000/06/05 17:52:43 malekith Exp $
#

ifneq (Make.common,$(wildcard Make.common))
all:
	echo "auto - configuring ..."
	./configure

else

include Make.common

subdirs      := libcftp server client conf
backup_files := ${subdirs} \
    Makefile VERSION acconfig.h configure.in make-makecommon TODO
dist_files   := ${backup_files} \
    Make.common.in config.h.in configure

zip=gzip
zip_ext=gz
#zip=bzip2
#zip_ext=bz2

all:
	for dir in ${subdirs} ; do ${MAKE} -C $$dir || exit 1 ; done

backup:
	tar cf - ${backup_files} | gzip > /adm/backup/$(shell date +cftp-%D-%T | sed -e 's|/|-|g').tar.gz

b: backup

dist:
	cvs -Q commit
	cvs -Q tag `echo v${VERSION} | sed -e 's/\./-/g'`
	perl make-makecommon
	autoheader
	autoconf
	mkdir cftp-${VERSION}
	cp -ar ${dist_files} files/root/* cftp-${VERSION}
	cd cftp-${VERSION} && rm -r `find -name CVS`
	tar cf - cftp-${VERSION} | ${zip} > files/dist/cftp-${VERSION}.tar.${zip_ext}
	rm -rf cftp-${VERSION}

clean:
	for dir in ${subdirs} ; do ${MAKE} -C $$dir clean || exit 1 ; done

# this can't be ${prefix}/sbin for tcpd
daemon_dir=/usr/sbin
dd=${root}${daemon_dir}
p=${root}${prefix}

install-files:
	install -d ${dd} ${p}/bin ${p}/sbin ${root}${etcdir}
	install -m 755 in.cftpd ${dd}
	install -m 755 keygen ${p}/sbin/cftp-keygen
	install -m 755 cftp ${p}/bin
	[ -f ${root}${etcdir}/cftpd.config -o \
	  -s ${root}${etcdir}/cftpd.config ] || \
	install -m 640 conf/default.config ${root}${etcdir}/cftpd.config

.PHONY: keys auto-inetd install install-files

keys:
	if [ ! -f ${etcdir}/cftp.key.private -o \
	     ! -s ${etcdir}/cftp.key.private ]; then \
		./keygen \
	fi

auto-inetd:
	grep -v '^#' /etc/inetd.conf | grep cftp || \
		echo "cftp stream tcp nowait root " \
			"/usr/sbin/in.cftpd in.cftpd" >> /etc/inetd.conf
	grep -v '^#' /etc/services | grep cftp || \
		echo "cftp	26/tcp	cryptoftp" >> /etc/services
	killall -HUP inetd

install: all install-files keys
	@echo
	@echo
	@echo "now you should enable in.cftpd in your inetd configuration"
	@echo "file. you can also consider adding cftp to your /etc/services"
	@echo "file (add line ``cftp    26/tcp    cryptoftp'')"
	@echo  
	@echo "for normal inetd you can add following line to /etc/inetd.conf"
	@echo "26 stream tcp nowait root /usr/sbin/tcpd in.cftpd"
	@echo "you can also replace ``26'' with ``cftp'' if you have added"
	@echo "cftp to your /etc/services. you can also change"
	@echo "/usr/sbin/tcpd if you don't have tcpd or don't want to"
	@echo "to use it"
	@echo
	@echo "you can also use ``make auto-inetd'' to add these lines"
	@echo "automagicly if they aren't there"
	@echo
	@echo

endif
