# Top level Makefile for tin
# for configuration options read the doc/INSTALL file.
#
# Updated   : 31.12.1997
#
PROJECT		= tin
EXE		= tin
MANEXT		= 1
LVER		= 1.4.0
PVER		= 19991113
VER		= $(LVER)
MAIL_ADDR	= "urs@tin.org"

@SET_MAKE@

# directory structure
TOPDIR = .
AMGDIR = ./amiga
DOCDIR = ./doc
INCDIR = ./include
OBJDIR = ./src
SRCDIR = ./src
OLDDIR = ./old

# OS2DIR    = ./os2
# MISCDIR   = ./misc
# NNTPDIR   = ./nntp
# DOCDEDIR  = ./doc/german
# VMSDIR    = ./vms
# VMSSIODIR = ./sio
# WIN32DIR  = ./win32

HFILES	= \
	$(INCDIR)/bool.h \
	$(INCDIR)/bugrep.h \
	$(INCDIR)/config.h \
	$(INCDIR)/extern.h \
	$(INCDIR)/menukeys.h \
	$(INCDIR)/nntplib.h \
	$(INCDIR)/proto.h \
	$(INCDIR)/stpwatch.h \
	$(INCDIR)/tin.h \
	$(INCDIR)/version.h
#	$(OLDDIR)/msmail.h
#	$(OLDDIR)/os_2.h
#	$(OLDDIR)/win32.h
#	$(OLDDIR)/win32tcp.h
#	$(INCDIR)/conf.h

CFILES	= \
	$(SRCDIR)/active.c \
	$(SRCDIR)/art.c \
	$(SRCDIR)/attrib.c \
	$(SRCDIR)/auth.c \
	$(SRCDIR)/charset.c \
	$(SRCDIR)/config.c \
	$(SRCDIR)/curses.c \
	$(SRCDIR)/debug.c\
	$(SRCDIR)/envarg.c \
	$(SRCDIR)/feed.c \
	$(SRCDIR)/filter.c \
	$(SRCDIR)/getline.c \
	$(SRCDIR)/group.c \
	$(SRCDIR)/hashstr.c \
	$(SRCDIR)/help.c\
	$(SRCDIR)/inews.c \
	$(SRCDIR)/init.c \
	$(SRCDIR)/joinpath.c \
	$(SRCDIR)/lang.c \
	$(SRCDIR)/list.c \
	$(SRCDIR)/mail.c \
	$(SRCDIR)/main.c \
	$(SRCDIR)/memory.c \
	$(SRCDIR)/misc.c \
	$(SRCDIR)/newsrc.c\
	$(SRCDIR)/nntplib.c \
	$(SRCDIR)/open.c \
	$(SRCDIR)/page.c \
	$(SRCDIR)/parsdate.y \
	$(SRCDIR)/pgp.c \
	$(SRCDIR)/post.c \
	$(SRCDIR)/prompt.c\
	$(SRCDIR)/read.c \
	$(SRCDIR)/refs.c\
	$(SRCDIR)/regex.c\
	$(SRCDIR)/save.c \
	$(SRCDIR)/screen.c \
	$(SRCDIR)/search.c \
	$(SRCDIR)/select.c \
	$(SRCDIR)/sigfile.c \
	$(SRCDIR)/signal.c \
	$(SRCDIR)/strftime.c \
	$(SRCDIR)/string.c \
	$(SRCDIR)/thread.c \
	$(SRCDIR)/wildmat.c \
	$(SRCDIR)/xref.c \
	$(SRCDIR)/vms.c
#	$(OLDDIR)/msmail.c
#	$(OLDDIR)/nntpw32.c
#	$(OLDDIR)/nntpvms.c
#	$(OLDDIR)/os_2.c
#	$(OLDDIR)/win32.c
#	$(OLDDIR)/win32tcp.c

DOC	= \
	$(DOCDIR)/HACKERS \
	$(DOCDIR)/HOWTOGET \
	$(DOCDIR)/README.PGP \
	$(DOCDIR)/attrib.txt \
	$(DOCDIR)/cmdref1.txt \
	$(DOCDIR)/cmdref2.txt \
	$(DOCDIR)/cmdref3.txt \
	$(DOCDIR)/cmdref4.txt \
	$(DOCDIR)/faq.html \
	$(DOCDIR)/faq.txt \
	$(DOCDIR)/filter.txt \
	$(DOCDIR)/forward.txt \
	$(DOCDIR)/intro.txt \
	$(DOCDIR)/iso2asc.txt \
	$(DOCDIR)/procmail.txt \
	$(DOCDIR)/rfc977.txt \
	$(DOCDIR)/rfc1036.txt \
	$(DOCDIR)/son1036.txt \
	$(DOCDIR)/$(EXE).$(MANEXT) \
	$(DOCDIR)/$(EXE).nrf \
	$(DOCDIR)/$(EXE).lsm \
	$(DOCDIR)/strftime.3 \
	$(DOCDIR)/wildmat.3

DOCDE = \
	$(DOCDEDIR)/README \
	$(DOCDEDIR)/tin.1

TOP	= \
	$(TOPDIR)/Makefile \
	$(TOPDIR)/CHANGES \
	$(TOPDIR)/INSTALL \
	$(TOPDIR)/MANIFEST \
	$(TOPDIR)/README \
	$(TOPDIR)/TODO

MISC	= \
	$(SRCDIR)/Makefile \
	$(SRCDIR)/descrip.mms \
	$(MISCDIR)/scroll.dif

AMIGA	= \
	$(AMGDIR)/README \
	$(AMGDIR)/smakefile \
	$(AMGDIR)/amiga.h \
	$(AMGDIR)/amigatcp.h \
	$(AMGDIR)/actived.c \
	$(AMGDIR)/amiga.c \
	$(AMGDIR)/amigatcp.c \
	$(AMGDIR)/parsdate.c

NNTP	= \
	$(NNTPDIR)/README \
	$(NNTPDIR)/INSTALL \
	$(NNTPDIR)/patch.srv

OS2	= \
	$(OS2DIR)/README \
	$(OS2DIR)/Makefile.bcc \
	$(OS2DIR)/Makefile.icc

WIN32	= \
	$(WIN32DIR)/README \
	$(WIN32DIR)/parsdate.c \
	$(WIN32DIR)/tin.mak

VMS	= \
	$(VMSDIR)/cc-multinet.opt \
	$(VMSDIR)/decc-multinet.opt \
	$(VMSDIR)/decc-ucx.opt \
	$(VMSDIR)/descrip.mms \
	$(VMSDIR)/dir.h \
	$(VMSDIR)/filetypes.h \
	$(VMSDIR)/gcc-multinet.opt \
	$(VMSDIR)/gcc-ucx.opt \
	$(VMSDIR)/getopt.c \
	$(VMSDIR)/getopt.h \
	$(VMSDIR)/getopt1.c \
	$(VMSDIR)/isxterm.c \
	$(VMSDIR)/make.com \
	$(VMSDIR)/makefile. \
	$(VMSDIR)/makevmslib.com \
	$(VMSDIR)/ndir.h \
	$(VMSDIR)/parse.c \
	$(VMSDIR)/parse.h \
	$(VMSDIR)/pwd.h \
	$(VMSDIR)/qsort.c \
	$(VMSDIR)/select.h \
	$(VMSDIR)/strings.h \
	$(VMSDIR)/uaf.h \
	$(VMSDIR)/vms-multinet.opt \
	$(VMSDIR)/vmsdir.c \
	$(VMSDIR)/vmsfile.c \
	$(VMSDIR)/vmspwd.c \
	$(VMSDIR)/vmstimval.h

VMSSIO	= \
	$(VMSSIODIR)/COPYRIGHT \
	$(VMSSIODIR)/Makefile \
	$(VMSSIODIR)/README \
	$(VMSSIODIR)/Sprint.3 \
	$(VMSSIODIR)/descrip.mms \
	$(VMSSIODIR)/events.h \
	$(VMSSIODIR)/impl.h \
	$(VMSSIODIR)/sio.3 \
	$(VMSSIODIR)/sio.c \
	$(VMSSIODIR)/sio.h \
	$(VMSSIODIR)/sioconf.h \
	$(VMSSIODIR)/siosup.c \
	$(VMSSIODIR)/sprint.c

ALL_FILES = $(TOP) $(DOC) $(DOCDE) $(HFILES) $(CFILES) $(AMIGA) $(MISC) $(NNTP) $(OS2) $(WIN32) $(VMS) $(VMSSIO)

# standard commands
@SET_MAKE@
CD	= cd
CHMOD	= chmod
COMPRESS= compress
CP	= cp -p
CSCOPE	= cscope
DIFF	= diff
ECHO	= echo
LS	= ls -l
LP	= lpr -h
MKDIR	= mkdir
MV	= mv
NROFF	= nroff
#NROFF	= groff -Tascii
RM	= rm
SHAR	= shar
SHELL	= /bin/sh
TAR	= tar
#TROFF	= troff
TROFF	= groff
UUENCODE= uuencode
WC	= wc
ZIP	= zip
GZIP	= gzip -9

all:
	@$(ECHO) "Top level Makefile for the TIN v$(VER) Usenet newsreader."
	@$(ECHO) " "
	@$(ECHO) "To compile the source code change to the source directory by"
	@$(ECHO) "typing 'cd src' and then type 'make' for more instructions."
	@$(ECHO) " "
	@$(ECHO) "This Makefile offers the following general purpose options:"
	@$(ECHO) " "
	@$(ECHO) "    make clean           [ Delete all object files & backup files ]"
	@$(ECHO) "    make clobber         [ Delete all object files, backup files & binaries ]"
	@$(ECHO) "    make diff            [ Generate context diffs against old version ]"
	@$(ECHO) "    make ftptar          [ Create compressed tar archive for ftp sites ]"
	@$(ECHO) "    make build           [ Compile tin ]"
	@$(ECHO) "    make install         [ Install the binary & the manual page ]"
	@$(ECHO) "    make install_daemon  [ Install the index daemon binary ]"
	@$(ECHO) "    make install_setuid  [ Install the binary setuid & the manual page ]"
	@$(ECHO) "    make manpage         [ Generate & print troff version of manual page ]"
	@$(ECHO) "    make nrfpage         [ Generate nroff version of manual page ]"
	@$(ECHO) "    make patch           [ Generate multi-part patch kit against old version ]"
	@$(ECHO) "    make print           [ Print all source code to printer ]"
	@$(ECHO) "    make shar            [ Create multi-part shell archive distribution ]"
	@$(ECHO) "    make tar             [ Create gzipped tar archive of the distribution ]"
	@$(ECHO) "    make uuencode        [ Create uuencoded compressed tar distribution ]"
	@$(ECHO) "    make zip             [ Create zip archive of the distribution ]"
	@$(ECHO) "    make ztar            [ Create compressed tar archive of the distribution ]"

build:
	@$(CD) $(SRCDIR) && $(MAKE) @cf_cv_makeflags@

install:
	@$(CD) $(SRCDIR) && $(MAKE) @cf_cv_makeflags@ install

install_setuid:
	@$(CD) $(SRCDIR) && $(MAKE) @cf_cv_makeflags@ install_setuid

install_daemon:
	@$(CD) $(SRCDIR) && $(MAKE) @cf_cv_makeflags@ install_daemon

version:
	@$(ECHO) "TIN v$(VER)"

clean:
	@$(CD) $(SRCDIR) && $(MAKE) @cf_cv_makeflags@ clean
	@$(RM) -f *~
	@$(RM) -f $(AMGDIR)/*~
	@$(RM) -f $(DOCDIR)/*~
	@$(RM) -f $(INCDIR)/*~
	@$(RM) -f $(MISCDIR)/*~
	@$(RM) -f $(NNTPDIR)/*~
	@$(RM) -f $(OBJDIR)/*~
	@$(RM) -f $(OS2DIR)/*~
	@$(RM) -f $(SRCDIR)/*~

clobber:
	@$(CD) $(SRCDIR) && $(MAKE) @cf_cv_makeflags@ clobber
	@$(RM) -f *~
	@$(RM) -f $(AMGDIR)/*~
	@$(RM) -f $(DOCDIR)/*~
	@$(RM) -f $(INCDIR)/*~
	@$(RM) -f $(MISCDIR)/*~
	@$(RM) -f $(NNTPDIR)/*~
	@$(RM) -f $(OBJDIR)/*~
	@$(RM) -f $(OS2DIR)/*~
	@$(RM) -f $(SRCDIR)/*~

manpage:
	@$(ECHO) "Printing $(TROFF) man page for $(EXE)..."
	@$(TROFF) -man $(DOCDIR)/$(EXE).$(MANEXT) | $(LP)

nrfpage:
	@$(ECHO) "Creating $(NROFF) man page for $(EXE)..."
	@$(NROFF) -man $(DOCDIR)/$(EXE).1 > $(DOCDIR)/$(EXE).nrf

manifest:
	@$(ECHO) "Creating MANIFEST..."
	@$(ECHO) "MANIFEST for $(PROJECT)-$(VER) (`date`)" > MANIFEST
	@$(ECHO) "----------------------------------------------------" >> MANIFEST
	@$(WC) -c $(ALL_FILES) >> MANIFEST

chmod:
	@$(CHMOD) 755 $(AMGDIR) $(DOCDIR) $(INCDIR) $(NNTPDIR) $(OBJDIR) $(SRCDIR)
	@$(CHMOD) 644 $(ALL_FILES)

shar:
	@$(ECHO) "Generating multi-part shell archive..."
	@$(MAKE) nrfpage
	@$(MAKE) manifest
	@$(MAKE) chmod
	@$(SHAR) -a -F -L60 -n $(PROJECT)-$(VER) -s $(MAIL_ADDR) \
		-o ../$(PROJECT)-$(VER) $(ALL_FILES)

uuencode:
	@$(MAKE) tar
	@$(ECHO) "Uuencoding $(PROJECT).t.gz..."
	@$(UUENCODE) $(PROJECT).t.gz $(PROJECT).t.gz > $(PROJECT).t.gz.uu
	@$(LS) $(PROJECT).t.gz.uu

diff:
	@$(ECHO) "Generating diffs against $(PROJECT)-$(BASE_VER)..."
	@-$(RM) -f $(INCDIR)/protoold.h $(INCDIR)/protonew.h
	@$(MAKE) nrfpage
	@$(MAKE) manifest
	@$(MAKE) chmod
	@-$(MV) -f $(PROJECT)-$(VER).diff $(PROJECT)-$(VER).diff-
	@-$(DIFF) -rusNP ../$(BASE_VER) . > ../$(PROJECT)-$(VER).diff
	@$(LS) ../$(PROJECT)-$(VER).diff

patch:
	@$(MAKE) diff
	@$(ECHO) "Generating patch against $(PROJECT)-$(BASE_VER)..."
	@-$(MV) $(PROJECT)-$(VER).diff $(PROJECT)-$(VER).patch
	@$(SHAR) -a -n $(PROJECT)-$(VER) -s $(MAIL_ADDR) -L60 \
		-o ../patch-$(VER) $(PROJECT)-$(VER).patch
	@$(LS) ../patch-$(VER).*

ftptar:
	@$(ECHO) "Creating FTP tar file with a directory of $(PROJECT)-$(VER)..."
	@$(MAKE) nrfpage
	@$(MAKE) manifest
	@$(MAKE) chmod
	@-$(MKDIR) $(PROJECT)-$(VER)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(AMGDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(DOCDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(DOCDEDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(INCDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(MISCDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(NNTPDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(OS2DIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(SRCDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(WIN32DIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(VMSDIR)
	@-$(MKDIR) $(PROJECT)-$(VER)/$(VMSSIODIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(AMGDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(DOCDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(DOCDEDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(INCDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(MISCDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(NNTPDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(OS2DIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(SRCDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(WIN32DIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(VMSDIR)
	@$(CHMOD) 755 $(PROJECT)-$(VER)/$(VMSSIODIR)
	@$(CP) $(TOP) $(PROJECT)-$(VER)
	@$(CP) $(AMIGA) $(PROJECT)-$(VER)/$(AMGDIR)
	@$(CP) $(DOC) $(PROJECT)-$(VER)/$(DOCDIR)
	@$(CP) $(DOCDE) $(PROJECT)-$(VER)/$(DOCDEDIR)
	@$(CP) $(HFILES) $(PROJECT)-$(VER)/$(INCDIR)
	@$(CP) $(NNTP) $(PROJECT)-$(VER)/$(NNTPDIR)
	@$(CP) $(OS2) $(PROJECT)-$(VER)/$(OS2DIR)
	@$(CP) $(CFILES) $(PROJECT)-$(VER)/$(SRCDIR)
	@$(CP) $(WIN32) $(PROJECT)-$(VER)/$(WIN32DIR)
	@$(CP) $(VMS) $(PROJECT)-$(VER)/$(VMSDIR)
	@$(CP) $(VMSSIO) $(PROJECT)-$(VER)/$(VMSSIODIR)
	@$(CP) $(SRCDIR)/Makefile $(PROJECT)-$(VER)/$(SRCDIR)
	@$(CP) $(SRCDIR)/descrip.mms $(PROJECT)-$(VER)/$(SRCDIR)
	@$(CP) $(MISCDIR)/scroll.dif $(PROJECT)-$(VER)/$(MISCDIR)
	@$(TAR) cvf $(PROJECT)-$(VER).tar $(PROJECT)-$(VER)
	@$(ECHO) "Compressing $(PROJECT)-$(VER).tar..."
	@$(GZIP) $(PROJECT)-$(VER).tar
	@$(LS) $(PROJECT)-$(VER).tar.gz
	@-$(RM) -rf $(PROJECT)-$(VER)

tar:
	@$(ECHO) "Generating gzipped tar file..."
	@-$(RM) $(PROJECT).t $(PROJECT).t.gz > /dev/null 2>&1
	@$(MAKE) chmod
	@$(TAR) cvf $(PROJECT).t $(ALL_FILES)
	@$(ECHO) "Gzipping $(PROJECT).t..."
	@$(GZIP) $(PROJECT).t
	@$(LS) $(PROJECT).t.gz

ztar:
	@$(ECHO) "Generating compressed tar file..."
	@-$(RM) $(PROJECT).t $(PROJECT).t.Z > /dev/null 2>&1
	@$(MAKE) chmod
	@$(TAR) cvf $(PROJECT).t $(ALL_FILES)
	@$(ECHO) "Compressing $(PROJECT).t..."
	@$(COMPRESS) $(PROJECT).t
	@$(LS) $(PROJECT).t.Z

zip:
	@$(ECHO) "Generating zip archive file..."
	@-$(RM) $(PROJECT).zip > /dev/null 2>&1
	@$(ZIP) $(PROJECT).zip  $(ALL_FILES)
	@$(LS) $(PROJECT).zip

cscope:
	@$(ECHO) "Creating cscope database $(PROJECT)..."
	@$(CSCOPE) $(ALL_FILES)

print:
	for FILE in $(HFILES) $(CFILES) $(MISC); do \
	$(ECHO) "Printing $$FILE..."; \
	a2ps $$FILE | $(LP); \
	done

distclean:
	$(CD) pcre && $(MAKE) @cf_cv_makeflags@ $@
	$(CD) src && $(MAKE) @cf_cv_makeflags@ $@
	$(RM) -f config.cache config.log config.status makefile */Makefile include/autoconf.h td-conf.out

configure: configure.in aclocal.m4
	autoconf
