##########################################################
#
#	@(#)Makefile	1.1 6/1/89 - USENET Source Archiver
#
#
# This software is Copyright (c) 1989 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!ssbell!kent
#
#  History:
#	Creation: Tue Feb 21 08:52:35 CST 1989 due to necessity.
#                                                               
##########################################################
#
# 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. 
#
#CFLAGS=-O -DUSE_SYSMKDIR
#CFLAGS=-O -DHAVE_MKDIR
CFLAGS= -O 
#
# Define your favorite C compiler here...
#
CC=gcc

#
# Define flags to be passed to lint.
#
LINTFLAGS=

#
# 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.
#
LDFLAGS=-lndir

I = /usr/include
LP = /usr/lbin/clist
NROFF = /usr/bin/nroff
BINDIR=/usr/lbin

DOCS = article.1 rkive.1 ckconfig.1 rkive.5
SUPPORT = rkive.cf Makefile README IDEAS MANIFEST
INCLUDES = rkive.h article.h cfg.h patchlevel.h

ARTICLE_SRCS =  article.c efopen.c format.c header.c str.c version.c
ARTICLE_OBJS =  article.o efopen.o format.o header.o str.o version.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 =  disp_grp.c efopen.c format.c header.c \
		makedir.c news_arc.c record_arc.c rename.c \
		rkive.c setup.c str.c version.c
ARCHIVE_OBJS =  disp_grp.o efopen.o format.o header.o \
		makedir.o news_arc.o record_arc.o rename.o \
		rkive.o setup.o str.o version.o

SRCS = article.c ckconfig.c disp_grp.c efopen.c format.c \
	header.c news_arc.c rkive.c rename.c record_arc.c \
	makedir.c setup.c str.c version.c

PROGS = article ckconfig rkive

all: $(PROGS)

install: $(PROGS)
	strip $(PROGS)
	cp $(PROGS) $(BINDIR)

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

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

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

man:
	$(NROFF) -man $(DOCS)

################################
#        Dependencies
################################

rkive.o: $(I)/sys/types.h
rkive.o: $(I)/sys/stat.h
rkive.o: $(I)/dirent.h
rkive.o: $(I)/stdio.h
rkive.o: article.h
rkive.o: cfg.h
rkive.o: rkive.h

article.o: $(I)/stdio.h
article.o: $(I)/ctype.h
article.o: $(I)/sys/types.h
article.o: article.h

ckconfig.o: $(I)/sys/types.h
ckconfig.o: $(I)/dirent.h
ckconfig.o: $(I)/stdio.h
ckconfig.o: $(I)/pwd.h
ckconfig.o: $(I)/grp.h
ckconfig.o: cfg.h
ckconfig.o: rkive.h

disp_grp.o: $(I)/sys/types.h
disp_grp.o: $(I)/dirent.h
disp_grp.o: $(I)/stdio.h
disp_grp.o: $(I)/pwd.h
disp_grp.o: $(I)/grp.h
disp_grp.o: cfg.h
disp_grp.o: rkive.h

efopen.o: $(I)/stdio.h

format.o: $(I)/stdio.h
format.o: $(I)/sys/types.h
format.o: article.h

header.o: $(I)/stdio.h
header.o: $(I)/ctype.h
header.o: $(I)/sys/types.h
header.o: article.h

makedir.o: $(I)/sys/types.h
makedir.o: $(I)/sys/stat.h
makedir.o: $(I)/stdio.h
makedir.o: $(I)/dirent.h
makedir.o: rkive.h

news_arc.o: $(I)/sys/types.h
news_arc.o: $(I)/sys/stat.h
news_arc.o: $(I)/dirent.h
news_arc.o: $(I)/stdio.h
news_arc.o: $(I)/ctype.h
news_arc.o: article.h
news_arc.o: cfg.h
news_arc.o: rkive.h

record_arc.o: $(I)/sys/types.h
record_arc.o: $(I)/sys/stat.h
record_arc.o: $(I)/dirent.h
record_arc.o: $(I)/stdio.h
record_arc.o: cfg.h
record_arc.o: rkive.h

rename.o: $(I)/stdio.h

setup.o: $(I)/sys/types.h
setup.o: $(I)/sys/stat.h
setup.o: $(I)/stdio.h
setup.o: $(I)/ctype.h
setup.o: $(I)/pwd.h
setup.o: $(I)/grp.h
setup.o: $(I)/dirent.h
setup.o: cfg.h
setup.o: rkive.h

version.o: $(I)/stdio.h
version.o: patchlevel.h

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

################################
#      	    CLEANUP        
################################

clean:
	rm -f *.o Lint.out

clobber: clean
	rm -f $(PROGS)

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

inspect_rkive:
	-inspect -abv $(ARCHIVE_SRCS) 
