##########################################################
#
#	@(#)Makefile	2.2 2/23/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
#
##########################################################
#
# Which mkdir function do you want to use ?
#
# Define HAVE_MKDIR if there is a mkdir() function in your 
# system library (AT&T 5.2 or earlier systems are probably
# out of luck..)
#
# Define USE_SYSMKDIR if you wish to system off /bin/mkdir.
# (not recommended for *real* use...)
#
# If you do not define either, the function makedir will
# create the directory itself. 
#
#MKDIR=
#MKDIR=-DUSE_SYSMKDIR
MKDIR=-DHAVE_MKDIR

#
# 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
#
#NNTPSRCDIR=/usr/src/local/cmd/nntp
##NNTPDEBUG=-DDEBUG
#NNTPFLAGS=$(EXOSFLAGS) -I$(NNTPSRCDIR)/common -DNNTP $(NNTPDEBUG)
#NNTPSRCS = $(NNTPSRCDIR)/common/clientlib.c nntpart.c
#NNTPOBJS = clientlib.o nntpart.o

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

#
# Compilation flags..
#
FLAGS=-g #-Wall
CFLAGS=$(FLAGS) $(NNTPFLAGS) $(MKDIR) 

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

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

# rkive needs to have POSIX Compatible directory access routines.
# If you have it builtin to your system libraries then comment
# out the following. If you use Doug Gwyn's routines, (or other
# compatible routines) define the library in which they appear.
#
#ACCESSLIB=-lndir

LDFLAGS=$(EXOSLIBS) $(ACCESSLIB)

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

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
ARTICLE_OBJS =  article.o afmt.o header.o str.o version.o zfopen.o

CKCONFIG_SRCS = ckconfig.c disp_grp.c efopen.c setup.c str.c version.c
CKCONFIG_OBJS = ckconfig.o disp_grp.o efopen.o setup.o str.o version.o

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 
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 

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

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

PROGS = article ckconfig rkive

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

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

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

$(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

################################
#           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 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
################################

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.
