# Makefile

# name of executable file
#
EXE=tin

# command line compile flags
#
# -D DONT_USE_START_LINE
#   stop editor being started with line offset into file
#
# -D DONT_USE_REGEX
#   don't match strings using regular expressions
#
# -D USE_LONG_FILENAMES
#   include -DUSE_LONG_FILENAMES if filesystem supports filenames
#   longer than 14 chars. (default for BSD type systems)
#
# -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.
#
# -D LIBDIR=\"\"
#   defaults to /usr/lib/news if not defined
#
# -D SPOOLDIR=\"\"
#   defaults to /usr/spool/news if not defined
#
# -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.
#
#  You only need to worry about the following two defines if you have
#  defined NNTP to build a version to access news locally & remotely
#
#  NNTPLIB=
#    point NNTPLIB at the nntp clientlib.o support library
#
#  NETLIBS=
#    NETLIBS should be the networking libraries you need to link with
#    the nntp clientlib.o

BINDIR = /lln-cs3/staff/fg/bin.sparc
TROFF=drf
PRINT=-Pps0

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

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

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

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)"
	@echo "    make norisc    (Site specific)"
	@echo "    make estevax   (Site specific)"

# 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" \
			 STRIP=strip EXE=tin linkit

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

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

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

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

# SITE SPECIFIC - IGNORE
norisc:
	@echo "Compiling for NORISC with NNTP..."
	@$(MAKE) CFLAGS='-c -O -DBSD -DUSE_NNTP -DLIBDIR=\"/news/lib\" -DSPOOLDIR=\"/news/spool\"' \
			 NNTPLIB=/news/nntp/clientlib.o \
			 LIBS="-lcurses -ltermcap" \
			 STRIP=strip 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" \
			 STRIP=strip EXE=tin linkit

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

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

proto:
	@echo "generating function prototypes for proto.h..."
	@echo "#ifdef __STDC__" > PROTO.H
	@echo " " >> PROTO.H
	@cproto *.c >> PROTO.H
	@echo " " >> PROTO.H
	@echo "#else" >> PROTO.H
	@echo " " >> PROTO.H
	@cproto -f1 *.c >> PROTO.H
	@echo " " >> PROTO.H
	@echo "#endif" >> PROTO.H
	@-mv PROTO.H proto.h

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

shar:
	@-mv -f ../$(EXE).shar ../$(EXE).shar-
	@shar -a -n $(EXE) -s iain@estevax.uucp -L50 -o ../$(EXE).shar [A-Z]* [A-Za-z0-9]*.[ch] $(EXE).1

tar:
	@echo "archiving files to $(EXE).tar..."
	@-rm $(EXE).tar $(EXE).tar.Z > /dev/null 2>&1
	@tar cvf $(EXE).tar $(HFILES) $(CFILES) Makefile README TODO UPDATE_INDEX $(EXE).1
	@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 $(HFILES) $(CFILES) Makefile README TODO UPDATE_INDEX $(EXE).1
	@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) $(CFILES) > LINT

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

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

man:
	@echo "printing $(EXE) manual to $(PRINT)..."
	@+ $(TROFF) -F Helvetica -man3 $(PRINT) $(EXE).1

print:
	@echo "printing to $(PRINT)..."
	@expand -4 art.c     | enscript -2r -h -G $(PRINT) -b art.c
	@expand -4 curses.c  | enscript -2r -h -G $(PRINT) -b curses.c
	@expand -4 debug.c   | enscript -2r -h -G $(PRINT) -b debug.c
	@expand -4 group.c   | enscript -2r -h -G $(PRINT) -b group.c
	@expand -4 hashstr.c | enscript -2r -h -G $(PRINT) -b hashstr.c
	@expand -4 help.c    | enscript -2r -h -G $(PRINT) -b help.c
	@expand -4 kill.c    | enscript -2r -h -G $(PRINT) -b kill.c
	@expand -4 lang.c    | enscript -2r -h -G $(PRINT) -b lang.c
	@expand -4 lang.h    | enscript -2r -h -G $(PRINT) -b lang.h
	@expand -4 mail.c    | enscript -2r -h -G $(PRINT) -b mail.c
	@expand -4 main.c    | enscript -2r -h -G $(PRINT) -b main.c 
	@expand -4 memory.c  | enscript -2r -h -G $(PRINT) -b memory.c
	@expand -4 misc.c    | enscript -2r -h -G $(PRINT) -b misc.c
	@expand -4 newsrc.c  | enscript -2r -h -G $(PRINT) -b newsrc.c
	@expand -4 nntp.h    | enscript -2r -h -G $(PRINT) -b nntp.h
	@expand -4 open.c    | enscript -2r -h -G $(PRINT) -b open.c
	@expand -4 page.c    | enscript -2r -h -G $(PRINT) -b page.c
	@expand -4 posted.c  | enscript -2r -h -G $(PRINT) -b posted.c
	@expand -4 prompt.c  | enscript -2r -h -G $(PRINT) -b prompt.c
	@expand -4 rcfile.c  | enscript -2r -h -G $(PRINT) -b rcfile.c
	@expand -4 save.c    | enscript -2r -h -G $(PRINT) -b save.c
	@expand -4 screen.c  | enscript -2r -h -G $(PRINT) -b screen.c
	@expand -4 search.c  | enscript -2r -h -G $(PRINT) -b search.c
	@expand -4 select.c  | enscript -2r -h -G $(PRINT) -b select.c
	@expand -4 tin.h     | enscript -2r -h -G $(PRINT) -b tin.h
	@expand -4 time.c    | enscript -2r -h -G $(PRINT) -b time.c

vaxb:
	@echo "copying to estevax..."
	@rcp $(EXE).tar.Z estevax:.src/tin &

kommu:
	@echo "copying to kommu..."
	@uncompress $(EXE).tar.Z 
	@rcp $(EXE).tar kommu:.src/tin &
	@compress $(EXE).tar 

art.o:		art.c $(HFILES)
curses.o:	curses.c
debug.o:	debug.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)
mail.o:		mail.c
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)
posted.o:	posted.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)
time.o:		time.c
wildmat.o:	wildmat.c $(HFILES)
