# $Header: Makefile,v 2.2 89/06/09 13:19:53 network Exp $
#
# Makefile for deliver
#
#  +----------------+
#  | Things to make |
#  +----------------+
#
#       deliver         Compile and link the deliver program.
#       header          Compile and link the header program.
#       install         Install deliver and header.  (You must be root.)
#       lint            Run lint on all sources, creating lint.out.
#       shar            Create distribution sharchives.
#       clean           Clean up.
#       clobber         Remove everything that can be regenerated.
#
#  +---------------+
#  | Configuration |
#  +---------------+
#
# SHELL
#       I don't have to tell you...
#
# COPY
#       Your local copy program.  SCO Xenix users may want to change this
#       to "copy -m" which preserves file modification time.
#
# SHAR
#       Your local sharchive generator.
#
# CFLAGS
#       Compile-time flags to cc.
#       For BSD systems, include "-DBSD".
#       For USG (System III and System V) systems, include "-DUSG".
#
# LDFLAGS
#       Link-time flags to cc.  The -i flag creates pure (sharable) code.
#
# LIBS
#       Depending on your environment, you may or may not need to link
#       with "-lx".  SCO Xenix System V needs it; Altos Xenix doesn't.
#
# BIN
#       Target directory for installation; /usr/bin is recommended.
#       You may use /usr/local/bin (or whatever), but you must be sure
#       that the directory you choose is in your PATH during mail
#       transmission and delivery.
#
# DELSHAR
#       Basename of sharchives created by "make shar".
#

SHELL = /bin/sh
COPY =  cp
SHAR =  shar
CFLAGS = -O
LDFLAGS = -i
LIBS = -lx
BIN =   /usr/bin
DELSHAR =  deliver.sh

#
# The files that make up the deliver distribution.
#

DOCS =  README deliver.8
MF   =  Makefile

HDRS =  config.h context.h deliver.h dest.h patchlevel.h misc.h

DELSRC1 = context.c copymsg.c
DELSRC2 = debug.c dest.c dfile.c lock.c main.c
DELSRC3 = mbox.c procs.c subs.c sysdep.c unctime.y uucp.c
DELSRCS = $(DELSRC1) $(DELSRC2) $(DELSRC3)
UIDSRCS = uid.c
HDRSRCS = header.c
COMSRCS = getopt.c
SAMPLES = samples samples/*

DELOBJS = context.o copymsg.o debug.o dest.o dfile.o lock.o \
	  main.o mbox.o procs.o subs.o sysdep.o unctime.o uucp.o
UIDOBJS = uid.o
HDROBJS = header.o
COMOBJS = getopt.o

#
# For GNU Make.  Sorry about the ugliness.
#

.PHONY: all install lint shar clean clobber

#
# The default target.
#

all: deliver header uid

#
# "make clobber" implies "make clean".
#

clobber:: clean

#
# How to install deliver and associated utilities.
#

install: deliver header uid
	@if [ `./uid -uU | fgrep '(root)' | wc -l` -ne 2 ]; \
	then \
		echo "Sorry!  You must be root to install deliver."; \
		exit 1; \
	fi
	$(COPY) deliver $(BIN)/deliver
	chgrp root $(BIN)/deliver
	chown root $(BIN)/deliver
	chmod 4711 $(BIN)/deliver
	$(COPY) header $(BIN)/header
	chmod 755 $(BIN)/header

#
# How to compile and link the program.
#

deliver: $(DELOBJS) $(COMOBJS)
	$(CC) $(LDFLAGS) -o $@ $(DELOBJS) $(COMOBJS) $(LIBS)
$(DELOBJS): $(HDRS)

clean::
	rm -f $(DELOBJS)
clobber::
	rm -f deliver

#
# A header parsing program.
#

header: $(HDRSRCS) $(COMOBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(HDRSRCS) $(COMOBJS) $(LIBS)
	rm -f $(HDROBJS)

clobber::
	rm -f header

#
# A little program to check on user and group id's.
# (I wish that the System V "id" program were available everywhere.)
#

uid: $(UIDSRCS) $(COMOBJS) config.h
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(UIDSRCS) $(COMOBJS) $(LIBS)
	rm -f $(UIDOBJS)

clobber::
	rm -f uid

#
# Common subroutines
#

$(COMOBJS): config.h

clean::
	rm -f $(COMOBJS)

#
# Look for fuzz.
#

lint: deliver.lint uid.lint

deliver.lint: $(HDRS) $(DELSRCS) $(COMSRCS)
	lint $(DELSRCS) $(COMSRCS) -lc $(LIBS) >$@

uid.lint: config.h $(UIDSRCS) $(COMSRCS)
	lint $(UIDSRCS) $(COMSRCS) -lc $(LIBS) >$@

clean::
	rm -f *.lint

#
# Make distribution sharchives.
#

shar:   $(DELSHAR).01 $(DELSHAR).02 $(DELSHAR).03 $(DELSHAR).04
$(DELSHAR).01: $(DOCS) $(MF) $(UIDSRCS) $(HDRSRCS) $(COMSRCS) $(SAMPLES)
	$(SHAR) >$@ $(DOCS) $(MF) $(UIDSRCS) $(HDRSRCS) $(COMSRCS) $(SAMPLES)
$(DELSHAR).02: $(HDRS) $(DELSRC1)
	$(SHAR) >$@ $(HDRS) $(DELSRC1)
$(DELSHAR).03: $(DELSRC2)
	$(SHAR) >$@ $(DELSRC2)
$(DELSHAR).04: $(DELSRC3)
	$(SHAR) >$@ $(DELSRC3)

clobber::
	rm -f $(DELSHAR).??
