# Makefile for tin
#
# NB. NNTP (NetNews Transport Protocol RFC 977) is required if you 
#     wish to read news remotely. It is a seperate package that is
#     available from many FTP and mailserver sites. 

# command line compile flags
#
#  -D LIBDIR=\"\"
#    defaults to /usr/lib/news if not defined.
#
#  -D INEWSDIR=\"\"
#    define if inews is not in LIBDIR. defaults to LIBDIR if not defined.
#
#  -D SPOOLDIR=\"\"
#    defaults to /usr/spool/news if not defined.
#
#  You only need to worry about the following three defines if you have
#  defined NNTP to build a version to access news locally & remotely
#
#  -D USE_NNTP
#    include -DUSE_NNTP if you want to allow reading of news locally 
#    and also remotely via the -r option over an NNTP server.
#
#  -D NNTPLIB=
#    point NNTPLIB at the nntp clientlib.o support library
#
#  -D NETLIBS=
#    NETLIBS should be the networking libraries you need to link with
#    the nntp clientlib.o
#
#  -D POSIX_JOB_CONTROL
#    define if your machine uses sigaction() POSIX signal handling.
#    This is defined as default for SysVR4 machines in this makefile.
#
#  -D USE_MKDIR
#    define if your machine does not have the mkdir() system call.
#
#  -D USE_LONG_FILENAMES
#    include -DUSE_LONG_FILENAMES if filesystem supports filenames
#    longer than 14 chars. (default for BSD type systems)
#
#  -D USE_INVERSE_HACK
#    define if you want inverse video and highlighted bar disabled.
#    (default for SCO Unix & SysVR4) Can be toggled in tin by the
#    'I' command & highlight bar by 'M' command.
#
#  -D USE_CLEARSCREEN
#    define if the you wish screen to use ClearScreen() and not MoveCursor()
#    and CleartoEOLN(). This is perhaps faster on slow terminals but I have
#    not really run any speed tests. Not sure this option works anymore.
#
#  -D DONT_USE_REGEX
#    don't match strings using regular expressions, just use strstr().
#
#  -D DONT_USE_START_LINE
#    stop editor being started with line offset into file
#
#  -D SLOW_SCREEN_UPDATE
#    useful if running over a low speed connection (ie. 2400baud).
#    1) stops percentage being shown at bottom of select and group menus.
#    2) stops group being written to screen as it is subscribed/unsubscribed.
#

# name of executable file
#
EXE=tin

# name of dir where base version is for use by diff program
#
BASE_DIR=../tin-1.01
 
#BINDIR = /piez/iain/bin
BINDIR = /usr/local/bin
STRIP = strip
ROFF = + drf -F Helvetica -man3 
PRINT= -Pps0

HFILES	=	tin.h lang.h nntp.h proto.h patchlevel.h

CFILES	=	art.c curses.c debug.c feed.c group.c hashstr.c help.c kill.c \
		lang.c main.c memory.c misc.c newsrc.c open.c page.c post.c \
		prompt.c rcfile.c save.c screen.c search.c select.c signal.c wildmat.c

OBJECTS	=	art.o curses.o debug.o feed.o group.o hashstr.o help.o kill.o \
		lang.o main.o memory.o misc.o newsrc.o open.o page.o post.o \
		prompt.o rcfile.o save.o screen.o search.o select.o signal.o wildmat.o

SUPPORT = Makefile MANIFEST README CHANGES TODO UPDATE_INDEX *.[13]

LINTFLAGS=-a -c -h -n -x 

.c.o:
	$(CC) $(CFLAGS) $*.c

all: 
	@echo "There is no default. Specify one of the following targets."
	@echo "    make bsd       (BSD/Ultrix)"
	@echo "    make sysv      (SysV)"
	@echo "    make sysvr4    (SysV R4)"
	@echo "    make sco       (SCO Unix)"
	@echo "    make xenix     (Xenix 386)"

# For Berkeley systems:
bsd:
	@echo "Compiling for BSD/Ultrix..."
	@$(MAKE) CFLAGS='-c -O -DBSD -DUSE_NNTP -DLIBDIR=\"/usr/local/lib/news\" -DSPOOLDIR=\"/usr/spool/news\"' \
			 LIBS="-lcurses -ltermcap" \
			 NNTPLIB="clientlib.o" \
			 NETLIBS="-lnsl" \
			 EXE=tin linkit

# For System V:
sysv:
	@echo "Compiling for System V..."
	@$(MAKE) CFLAGS='-c -O -DUSE_NNTP  -DAUTO_RESIZE -DLIBDIR=\"/usr/lib/news\" -DSPOOLDIR=\"/usr/spool/news\"' \
			 NNTPLIB="clientlib.o" \
			 NETLIBS="-lnet -lnsl_s" \
			 LIBS="-lcurses -ltermcap" \
			 EXE=tin linkit

# For System V Release 4:
sysvr4:
	@echo "Compiling for System V Release 4..."
	@$(MAKE) CFLAGS='-c -O -DUSE_NNTP -DPOSIX_JOB_CONTROL -DUSE_INVERSE_HACK -DAUTO_RESIZE -DLIBDIR=\"/usr/lib/news\" -DSPOOLDIR=\"/usr/spool/news\"' \
			 NNTPLIB="./nntp/clientlib.o" \
			 NETLIBS="-lnsl -lsocket" \
			 LIBS="-lcurses -ltermcap -L/usr/ucblib -lucb" \
			 EXE=tin linkit

# For SCO Unix:
sco:
	@echo "Compiling for SCO Unix..."
	@$(MAKE) CFLAGS='-c -O -UM_XENIX -DUSE_INVERSE_HACK  -DAUTO_RESIZE -DLIBDIR="\"/usr/lib/news\"" -DSPOOLDIR="\"/usr/spool/news\""' \
			 LIBS="-lcurses -lgen -lc_s" \
			 EXE=tin linkit

# For Xenix 386:
#			 NNTPLIB=clientlib.o
#			 NETLIBS="-lsocket"
xenix:
	@echo "Compiling for Xenix 386..."
	@$(MAKE) CFLAGS='-c -Zi -DSYSV -DLIBDIR="\\"/usr/lib/news\\"" -DSPOOLDIR="\\"/usr/spool/news\\""' \
			 LIBS="-lcurses -ltinfo -lx" \
			 EXE=tin linkit

# SITE SPECIFIC - IGNORE
norisc:
	@echo "Compiling for NORISC with NNTP..."
	@$(MAKE) CFLAGS='-c -g -DBSD -DUSE_NNTP -DAUTO_RESIZE -DLIBDIR=\"/news/lib\" -DSPOOLDIR=\"/news/spool\"' \
			NNTPLIB=/news/nntp/clientlib.o \
			LIBS="-lcurses -ltermcap" \
			EXE=tin linkit

# SITE SPECIFIC - IGNORE
estevax:
	@echo "Compiling for ESTEVAX with NNTP..."
	@$(MAKE) CFLAGS='-c -O -DBSD -DUSE_NNTP -DLIBDIR=\"/usr/lib/news\" -DSPOOLDIR=\"/usr/spool/news\"' \
			 NNTPLIB=/others/mtz/bnews2/NNTP/common/clientlib.o \
			 LIBS="-lcurses -ltermcap" \
			 EXE=tin linkit

# SITE SPECIFIC - IGNORE
kommu:
	@echo "Compiling for KOMMU with NNTP..."
	@$(MAKE) CFLAGS='-c -O -UM_XENIX -DUSE_INVERSE_HACK  -DAUTO_RESIZE -DUSE_NNTP -DLIBDIR="\\"/usr/lib/news\\"" -DSPOOLDIR="\\"/usr/spool/news\\""' \
			 NNTPLIB=/usr/spool/user/TONI/bnews2/NNTP/common/clientlib.o \
			 NETLIBS="-lnsl_s -lsocket" \
			 LIBS="-lcurses -lgen -lc_s" \
			 EXE=tin linkit

linkit: $(OBJECTS)
	@echo "Linking $(EXE)..."
#	$(CC) -Zi -o $(EXE) $(OBJECTS) $(NNTPLIB) $(NETLIBS) $(LIBS) 
	$(CC) -o $(EXE) $(OBJECTS) $(NNTPLIB) $(NETLIBS) $(LIBS) 
	@ls -l $(EXE)

install: all
	@echo "installing $(EXE)..."
	@$(STRIP) $(EXE)
	@-mv $(EXE) $(BINDIR)
	@chmod 755 $(BINDIR)/$(EXE)

install_setuid: all
	@echo "installing SETUID $(EXE)..."
	@mv $(EXE) $(BINDIR)
	@chown news $(BINDIR)/$(EXE) 
	@su news -c "chmod 4755 $(BINDIR)/$(EXE)"

proto:
	@echo "generating function prototypes for proto.h..."
	@echo "#ifdef __STDC__" > PROTO.H
	@echo " " >> PROTO.H
	@cproto $(CFILES) >> PROTO.H
	@echo " " >> PROTO.H
	@echo "#else" >> PROTO.H
	@echo " " >> PROTO.H
	@cproto -f1 $(CFILES) >> PROTO.H
	@echo " " >> PROTO.H
	@echo "#endif" >> PROTO.H
	@-mv PROTO.H proto.h

shar:
	@echo "generating shell archive..."
	@echo "MANIFEST for tin newsreader (`date`)" > MANIFEST
	@echo "--------------------------------------------------------------" >> MANIFEST
	@wc -c README CHANGES TODO UPDATE_INDEX Makefile *.[13] $(HFILES) $(CFILES) >> MANIFEST
	@shar -a -n $(EXE)1.02 -s iain@estevax.uucp -L50 -o ../$(EXE).shar $(SUPPORT) $(CFILES) $(HFILES)

uuencode:
	make tar
	@echo "uuencoding $(EXE).tar.Z..."
	@uuencode $(EXE).tar.Z $(EXE).tar.Z > $(EXE).tar.Z.uue
	@ls -l $(EXE).tar.Z.uue
 
diff:
	@echo "generating diffs against $(BASE_DIR) (results in $(EXE).diff)..."
	@-mv -f $(EXE).diff $(EXE).diff-
	@diff $(BASE_DIR) . > $(EXE).diff

tar:
	@echo "archiving files to $(EXE).tar..."
	@-rm $(EXE).tar $(EXE).tar.Z > /dev/null 2>&1
	@tar cvf $(EXE).tar $(SUPPORT) $(CFILES) $(HFILES) 
	@echo "compressing $(EXE).tar..."
	@compress $(EXE).tar 
	@ls -l $(EXE).tar.Z

zoo:
	@echo "archiving files to $(EXE).zoo..."
	@-rm $(EXE).zoo > /dev/null 2>&1
	@zoo ah $(EXE).zoo  $(SUPPORT) $(CFILES) $(HFILES)
	@ls -l $(EXE).zoo

tags:
	@echo "generating tags (results in ./tags)..."
	@-rm tags
	@ctags $(HFILES) $(CFILES) 

lint:
	@echo "linting source (results in ./LINT)..."
	@lint $(LINTFLAGS) -DUSE_NNTP $(CFILES) > LINT

clean:
	@echo "cleaning..."
	@-'rm' -rf *.o #* $(EXE).diff*

clobber:
	@echo "clobbering..."
	@-'rm' -rf *.o #* tags $(EXE) $(EXE).diff*

cflow:
	@echo "creating cflow for $(EXE)..."
	@cflow $(CFILES) > cflow.$(EXE) &

grind:
	@echo "grinding tags index..."
	@ctags -v *.[ch] | sort -f > $(EXE).index

man:
	@echo "printing $(EXE) manual to $(PRINT)..."
	@$(ROFF) $(PRINT) $(EXE).1

print:
	@for FILE in $(HFILES) $(CFILES); do \
	echo "printing $$FILE to $(PRINT)..."; \
	expand -4 $$FILE | enscript -2r -h -G $(PRINT) -b $$FILE; \
	done

dist:
	@for HOST in estevax kommu beperl; do \
	echo "copying to $$HOST..."; \
	rcp $(CFILES) $(HFILES) $(SUPPORT) $$HOST:.src/tin &; \
	done

art.o:		art.c $(HFILES)
curses.o:	curses.c
debug.o:	debug.c $(HFILES)
feed.o:		feed.c $(HFILES)
group.o:	group.c $(HFILES)
hashstr.o:	hashstr.c $(HFILES)
help.o:		help.c $(HFILES)
kill.o:		kill.c $(HFILES)
lang.o:		lang.c $(HFILES)
main.o:		main.c $(HFILES)
memory.o:	memory.c $(HFILES)
misc.o:		misc.c $(HFILES)
newsrc.o:	newsrc.c $(HFILES)
open.o:		open.c $(HFILES)
page.o:		page.c $(HFILES)
post.o:		post.c $(HFILES)
prompt.o:	prompt.c $(HFILES)
rcfile.o:	rcfile.c $(HFILES)
save.o:		save.c $(HFILES)
screen.o:	screen.c $(HFILES)
search.o:	search.c $(HFILES)
select.o:	select.c $(HFILES)
signal.o:	signal.c $(HFILES)
wildmat.o:	wildmat.c $(HFILES)
