#-----------------------------------------------------------------------------
#
# NcFTP makefile for the platform @OS@, on the host @host@.
#
#-----------------------------------------------------------------------------

VER=@NCFTP_VERSION@
@SET_MAKE@
CC=@CC@
CFLAGS=@CFLAGS@@NDEFS@
#CC=gcc
#CFLAGS=-O2 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wbad-function-cast -Wwrite-strings -Wconversion
STRIPFLAG=@SFLAG@
STRIP=@STRIP@
prefix=@prefix@
exec_prefix=@exec_prefix@
BINDIR=@bindir@
SYSCONFDIR=@sysconfdir@
mandir=@mandir@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@
SHELL=/bin/sh

all: progs
	-@/bin/ls -l bin
	-@echo 'Done.'
	-@echo
	-@echo '** Please report any problems to http://www.NcFTP.com/contact/ **'

libs:
	@( cd Strn ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" )
	@( cd sio ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" )
	@( cd libncftp ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" )

progs: libs
	@[ -d bin ] || mkdir bin
	@( cd ncftp ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" )
	@( cd sh_util ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" )
	@( cd vis ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" )

install:
	@( cd ncftp ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" )
	@( cd sh_util ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" )
	@( cd vis ; $(MAKE) "CC=$(CC)" "CFLAGS=$(CFLAGS)" )
	-mkdir "$(prefix)" "$(BINDIR)" "$(SYSCONFDIR)" "$(mandir)" "$(mandir)/man1" 2>/dev/null
	-@echo '..... Installing the programs .....'
	$(INSTALL_PROGRAM) bin/ncftp@EXEEXT@ "$(BINDIR)/ncftp@EXEEXT@"
	$(INSTALL_PROGRAM) bin/ncftpget@EXEEXT@ "$(BINDIR)/ncftpget@EXEEXT@"
	$(INSTALL_PROGRAM) bin/ncftpput@EXEEXT@ "$(BINDIR)/ncftpput@EXEEXT@"
	$(INSTALL_PROGRAM) bin/ncftpls@EXEEXT@ "$(BINDIR)/ncftpls@EXEEXT@"
	$(INSTALL_PROGRAM) bin/ncftpbatch@EXEEXT@ "$(BINDIR)/ncftpbatch@EXEEXT@"
	-@/bin/rm -f "$(BINDIR)/ncftpspooler@EXEEXT@"
	ln "$(BINDIR)/ncftpbatch@EXEEXT@" "$(BINDIR)/ncftpspooler@EXEEXT@"
#
# The visual programs are only built if a working Curses was found.
#
	-test -f bin/ncftpbookmarks@EXEEXT@ && $(INSTALL_PROGRAM) bin/ncftpbookmarks@EXEEXT@ "$(BINDIR)/ncftpbookmarks@EXEEXT@"
	-@echo '..... Installing the manual pages .....'
	$(INSTALL_DATA) doc/man/ncftp.1 "$(mandir)/man1/ncftp.1"
	$(INSTALL_DATA) doc/man/ncftpget.1 "$(mandir)/man1/ncftpget.1"
	$(INSTALL_DATA) doc/man/ncftpput.1 "$(mandir)/man1/ncftpput.1"
	$(INSTALL_DATA) doc/man/ncftpbatch.1 "$(mandir)/man1/ncftpbatch.1"
	$(INSTALL_DATA) doc/man/ncftpspooler.1 "$(mandir)/man1/ncftpspooler.1"
	$(INSTALL_DATA) doc/man/ncftpls.1 "$(mandir)/man1/ncftpls.1"
	-@echo '..... Finishing up .....'
	-@( cd "$(BINDIR)" ; echo ""; echo "$(BINDIR):" ; /bin/ls -l "ncftp@EXEEXT@" "ncftpget@EXEEXT@" "ncftpput@EXEEXT@" "ncftpls@EXEEXT@" "ncftpbatch@EXEEXT@" "ncftpspooler@EXEEXT@" "ncftpbookmarks@EXEEXT@" 2>/dev/null | sed 's/^/  /;' ; echo "" )
	-@echo 'Done installing NcFTP.'

clean:
	/bin/rm -f ncftp_all.ncb ncftp_all.opt ncftp_all.plg *.pch
	@( cd Strn ; $(MAKE) clean )
	@( cd sio ; $(MAKE) clean )
	@( cd libncftp ; $(MAKE) clean )
	@( cd ncftp ; $(MAKE) clean )
	@( cd sh_util ; $(MAKE) clean )
	@( cd vis ; $(MAKE) clean )

distclean: clean
	/bin/rm -f config.cache config.h config.log config.status libncftp/Makefile libncftp/config.h ncftp/Makefile sh_util/Makefile vis/Makefile Makefile.bin Strn/Makefile Strn/config.h Strn/Strn.version sio/Makefile sio/config.h sio/sio.version Makefile ccdv
	/bin/rm -rf bin
	@echo "Warning: configure may have automatically patched libncftp/ncftp.h"

TMPDIR=/tmp
TARDIR=ncftp-$(VER)
STGZFILE=$(TARDIR)-src.tar.gz
DTARFILE=$(TARDIR)-@OS@-export.tar
DTGZFILE=$(TARDIR)-@OS@-export.tar.gz
DBGZFILE=$(TARDIR)-@OS@-export.tar.bz2

dtar:
	-@mkdir $(TMPDIR)/TAR
	-@mkdir $(TMPDIR)/TAR/$(TARDIR)
	cp Makefile.bin $(TMPDIR)/TAR/$(TARDIR)/Makefile
	-@mkdir $(TMPDIR)/TAR/$(TARDIR)/bin $(TMPDIR)/TAR/$(TARDIR)/doc
	cp -r bin $(TMPDIR)/TAR/$(TARDIR)
	chmod 755 $(TMPDIR)/TAR/$(TARDIR)/bin/*
	-@rm -f $(TMPDIR)/TAR/$(TARDIR)/bin/ncftpspooler
	-@ln $(TMPDIR)/TAR/$(TARDIR)/bin/ncftpbatch $(TMPDIR)/TAR/$(TARDIR)/bin/ncftpspooler
	for f in CHANGELOG.txt FIREWALLS_AND_PROXIES.txt LICENSE.txt what_changed_between_v2_v3.txt ; do \
		cp doc/$$f $(TMPDIR)/TAR/$(TARDIR)/doc/$$f ; \
	done
	cp -r doc/man doc/html $(TMPDIR)/TAR/$(TARDIR)/doc
	find $(TMPDIR)/TAR/$(TARDIR) -type d -exec chmod a+rx {} \;
	find $(TMPDIR)/TAR/$(TARDIR) -type f -exec chmod a+r {} \;
	( cd $(TMPDIR)/TAR ; @TAR@ @TARFLAGS@ $(TMPDIR)/TAR/$(DTARFILE) $(TARDIR) )
	-@cp $(TMPDIR)/TAR/$(DTARFILE) .
	-@chmod 644 $(DTARFILE)
	-@rm -rf $(TMPDIR)/TAR
	-@/bin/ls -l $(DTARFILE)

dgz: dtar
	gzip $(DTARFILE)
	-@chmod 644 $(DTGZFILE)
	-@/bin/ls -l $(DTGZFILE)

dbz: dtar
	bzip2 $(DTARFILE)
	-@chmod 644 $(DTBZFILE)
	-@/bin/ls -l $(DTBZFILE)

sgz gz:
	./sh/mksrctar.sh $(TARDIR) $(STGZFILE) '@TAR@' '@TARFLAGS@'
