##########################################################
#
#	@(#)Makefile.dst	2.3 5/9/91 - USENET Source Archiver
#
# This software is Copyright (c) 1989, 1990, 1991 by Kent Landfield.
#
# Permission is hereby granted to copy, distribute or otherwise 
# use any part of this package as long as you do not try to make 
# money from it or pretend that you wrote it.  This copyright 
# notice must be maintained in any copy made.
#
# Use of this software constitutes acceptance for use in an AS IS 
# condition. There are NO warranties with regard to this software.  
# In no event shall the author be liable for any damages whatsoever 
# arising out of or in connection with the use or performance of this 
# software.  Any use of this software is at the user's own risk.
#
#  If you make modifications to this software that you feel 
#  increases it usefulness for the rest of the community, please 
#  email the changes, enhancements, bug fixes as well as any and 
#  all ideas to me. This software is going to be maintained and 
#  enhanced as deemed necessary by the community.
#		
#		Kent Landfield
#		uunet!sparky!kent
#		kent@sparky.imd.sterling.com
#
##########################################################

#
# Do you wish to have this built with NNTP capabilities ?
# This requires that you have networking libraries and the
# NNTP source code available to you during compilation.
#
# Excelan support needed for nntp 
#     Uncomment if needed...
#
#EXOSFLAGS= -I/usr/include/EXOS -DUSG -DEXCELAN
#EXOSLIBS= -lsocket
#
# Specify the base directory location of the nntp sources
# if you wish to give rkive the ability to use nntp to archive.
#
NNTPSRCDIR=/afs/sipb/project/news/src/nntp
#NNTPDEBUG=-DDEBUG
NNTPFLAGS=$(EXOSFLAGS) -I$(NNTPSRCDIR)/common -DNNTP $(NNTPDEBUG)
NNTPSRCS= $(NNTPSRCDIR)/common/clientlib.c nntpart.c
NNTPOBJS= clientlib.o nntpart.o

#
# Sequent's Compilation flags..
#
SFLAGS=-Iport
#
# If your system does not have getopt,
# uncomment the next two lines.
#
#GETOPTO=getopt.o
#GETOPTC=./port/getopt.c
#TEMPNAMO=tempnam.o
#TEMPNAMC=./port/tempnam.c
#TEMPNAMFLAGS=-DTEMPNAM
STRDUPO=strdup.o
STRDUPC=./port/strdup.c
STRDUPFLAGS=-DSTRDUP

#
# Define your favorite C compiler here...
#
CC=cc

#
# Compilation flags..
#
FLAGS=-g 
CFLAGS=$(SFLAGS) $(FLAGS) $(NNTPFLAGS) $(TEMPNAMFLAGS) $(STRDUPFLAGS)

#
# Yacc flags for compilation of match.y
#
YFLAGS=
YACC=yacc

#
# Define flags to be passed to lint.
#
LINTFLAGS=$(NNTPFLAGS) 

# rkive needs to have POSIX Compatible directory access routines.
# If you do not have it builtin to your system libraries then specify
# the -l option. If you use Doug Gwyn's routines, (or other compatible
# routines) define the library in which they appear such as -lndir or
# -lposix.
#
ACCESSLIB=

LDFLAGS=$(EXOSLIBS) $(ACCESSLIB)

#
# If your system requires additional libraries or if you wish to
# use shared libraries, add the -l declarations to LIBS below such
# as -lc_s
#
LIBS=

I = /usr/include
LP=lpr
PR=nl -n
NROFF=nroff
BINDIR=/usr/local/bin
RKIVEDIR=/usr/local/lib/rkive
MAN1=/usr/man/man1
MAN5=/usr/man/man5

MANS=	$(MAN1)/article.1 \
	$(MAN1)/rkive.1 \
	$(MAN1)/ckconfig.1 \
	$(MAN5)/rkive.5

CONFIG=	$(RKIVEDIR)/rkive.cf 

SCRIPTS= $(RKIVEDIR)/update_netdocs

SUPPORT = Makefile README IDEAS MANIFEST
INCLUDES = rkive.h article.h cfg.h patchlevel.h suffix.h

ARTICLE_SRCS =  article.c format.c header.c str.c version.c zfopen.c $(GETOPTC)
ARTICLE_OBJS =  article.o afmt.o header.o str.o version.o zfopen.o $(GETOPTO)

CKCONFIG_SRCS= ckconfig.c disp_grp.c efopen.c setup.c str.c version.c $(GETOPTC) $(STRDUPC)
CKCONFIG_OBJS= ckconfig.o disp_grp.o efopen.o setup.o str.o version.o $(GETOPTO) $(STRDUPO)

ARCHIVE_SRCS =  ck_name.c disp_grp.c efopen.c format.c header.c \
	makedir.c news_arc.c $(NNTPSRCS) record_arc.c retrieve.c \
	rkive.c setup.c str.c suffix.c version.c  $(GETOPTC) \
	$(TEMPNAMC) $(STRDUPC) maxart.c
ARCHIVE_OBJS =  ck_name.o disp_grp.o efopen.o rfmt.o header.o \
	makedir.o news_arc.o $(NNTPOBJS) record_arc.o retrieve.o \
	match.o rkive.o setup.o str.o suffix.o version.o  $(GETOPTO) \
	$(TEMPNAMO) $(STRDUPO) maxart.o

SRCS = article.c ckconfig.c ck_name.c disp_grp.c efopen.c format.c \
	header.c makedir.c news_arc.c nntpart.c retrieve.c rkive.c \
	match.y record_arc.c setup.c str.c suffix.c version.c zfopen.c \
	$(GETOPTC) $(TEMPNAMC) $(STRDUPC) maxart.c

INSTALLED_PROGS=\
	$(BINDIR)/article \
	$(BINDIR)/ckconfig \
	$(BINDIR)/rkive

PROGS = article ckconfig rkive

#all: $(PROGS) $(MANS) $(SCRIPTS)
all: $(PROGS) 

$(MANS):
	cp `basename $@` $@
	chmod 444 $@

#install: $(MANS) $(SCRIPTS) $(CONFIG) $(INSTALLED_PROGS)
#install: $(INSTALLED_PROGS)

install:
	install -c -s rkive /usr/local/bin

$(INSTALLED_PROGS):
	@strip $@ > /dev/null 2>&1
	cp `basename $@` $@

$(CONFIG):
	cp `basename $@` $@
	chmod 444 $@
	
$(SCRIPTS):
	cp `basename $@` $@
	chmod 755 $@

$(RKIVEDIR) $(MAN1) $(MAN5):
	mkdir $(MKDIRFLAGS) $@
	chmod 775 $@

cf: $(CONFIG)

ckconfig: $(CKCONFIG_OBJS) 
	$(CC) $(CFLAGS) -o ckconfig $(CKCONFIG_OBJS) $(LIBS)

article: $(ARTICLE_OBJS) 
	$(CC) $(CFLAGS) -o article $(ARTICLE_OBJS) $(LIBS)

rkive: $(ARCHIVE_OBJS) 
	$(CC) $(CFLAGS) -o rkive $(ARCHIVE_OBJS) $(LDFLAGS) $(LIBS)

$(BINDIR)/article:	article
$(BINDIR)/ckconfig:	ckconfig
$(BINDIR)/rkive:	rkive

$(CKCONFIG_OBJS):	$(INCLUDES)
$(ARTICLE_OBJS):	$(INCLUDES)
$(ARCHIVE_OBJS):	$(INCLUDES)
################################
#           Print
################################

print: print_docs print_support print_include 
	$(LP) $(SRCS)

print_support:
	 $(PR) $(SUPPORT) | $(LP)

print_include:
	$(LP) $(INCLUDES)

print_article:
	$(LP) $(ARTICLE_SRCS)

print_ckconfig:
	$(LP) $(CKCONFIG_SRCS)

print_rkive:
	$(LP) $(ARCHIVE_SRCS)

print_docs:
	$(NROFF) -man $(DOCS) | $(LP)

################################
#           LINT
################################

lint:  
	@echo "linting Article sources: " > Lint.out
	lint $(LINTFLAGS) $(ARTICLE_SRCS) | tee -a Lint.out
	@echo "linting Ckconfig sources: " >> Lint.out
	lint $(LINTFLAGS) $(CKCONFIG_SRCS) | tee -a Lint.out
	@echo "linting Archiver sources: " >> Lint.out
	lint $(LINTFLAGS) $(ARCHIVE_SRCS) | tee -a Lint.out

lint_article:
	@echo "linting Article sources: " > Lint.out
	lint $(LINTFLAGS) $(ARTICLE_SRCS) 2>&1 | tee -a Lint.out

lint_ckconfig:
	@echo "linting Ckconfig sources: " > Lint.out
	lint $(LINTFLAGS) $(CKCONFIG_SRCS) | tee -a Lint.out

lint_rkive:
	@echo "linting Archiver sources: " > Lint.out
	lint $(LINTFLAGS) $(ARCHIVE_SRCS) | tee -a Lint.out

################################
#      	    General        
################################

clean:
	rm -f *.o Lint.out *.bak

clobber: clean
	rm -f $(PROGS)
	rm -f Makefile.old rkive.h.old
	rm -f y.output y.tab.h y.tab.c 

inspection:  
	-inspect -abv $(ARTICLE_SRCS) 
	-inspect -abv $(CKCONFIG_SRCS) 
	-inspect -abv $(ARCHIVE_SRCS) 

inspect_rkive:
	-inspect -abv $(ARCHIVE_SRCS) 

saber_article_src:
	#load $(CFLAGS) $(ARTICLE_SRCS) $(LIBS)

saber_article_obj:
	#load $(ARTICLE_OBJS) $(LIBS)

saber_ckconfig_src:
	#load $(CFLAGS) $(CKCONFIG_SRCS) $(LIBS)

saber_ckconfig_obj:
	#load $(CKCONFIG_OBJS) $(LIBS)

saber_rkive_src:
	#load $(CFLAGS) $(ARCHIVE_SRCS) $(LIBS)

saber_rkive_obj:
	#load $(ARCHIVE_OBJS) $(LIBS)

man:
	$(NROFF) -man $(MANS)

depend:
	makedepend -- $(CFLAGS) -- $(SRCS)
	
################################
#        Dependencies
################################

getopt.o: ./port/getopt.c
	$(CC) $(CFLAGS) $(TARGET_ARCH) -c ./port/getopt.c

tempnam.o: ./port/tempnam.c
	$(CC) $(CFLAGS) $(TARGET_ARCH) -c ./port/tempnam.c

strdup.o: ./port/strdup.c
	$(CC) $(CFLAGS) $(TARGET_ARCH) -c ./port/strdup.c

clientlib.o: $(NNTPSRCDIR)/common/clientlib.c
	$(CC) $(CFLAGS) $(TARGET_ARCH) -c $(NNTPSRCDIR)/common/clientlib.c

match.o: match.y article.h

#
# The format junk here could be cleaned up with -o if all
# versions of make had it... I could reorg the code but that's
# work... :-)
#
rfmt.o: format.c
	$(CC) -DRKIVE $(CFLAGS) $(TARGET_ARCH) -c format.c
	mv format.o rfmt.o

afmt.o: format.c
	$(CC) $(CFLAGS) $(TARGET_ARCH) -c format.c
	mv format.o afmt.o

$(RKIVEDIR)/rkive.cf:		rkive.cf $(RKIVEDIR)
$(RKIVEDIR)/update_netdocs:	update_netdocs $(RKIVEDIR)
$(MAN1)/article.1:		article.1 $(MAN1)
$(MAN1)/rkive.1:		rkive.1 $(MAN1)
$(MAN1)/ckconfig.1:		ckconfig.1 $(MAN1)
$(MAN5)/rkive.5:		rkive.5  $(MAN5)

# DO NOT DELETE THIS LINE -- make depend depends on it.
