# $Header: Makefile,v 2.7 90/05/09 12:26:11 chip 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.
#
# CC
#       Your favorite C compiler.
#
# CFLAGS
#       Compile-time flags to cc.
#       For BSD systems, include "-DBSD".
#       For USG (System III and System V) systems, include "-DUSG".
#       For Xenix systems, don't define anything.
#
# 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.
#
# LINT
#	Your favorite lint program, with flags.
#
# BIN
#       Target directory for installation; /usr/bin is recommended.
#       You may use /usr/local/bin (or whatever), but if you do,
#       be sure that the directory you choose is in your SAFEPATH
#       as defined in config.h.
#
# DELSHAR
#       Basename of sharchives created by "make shar".
#

SHELL = /bin/sh
COPY =  cp
SHAR =  shar
CC = gcc
CFLAGS = -O -DUSG
LDFLAGS = -i
LIBS =
LINT = lint -x
BIN =   /usr/bin
DELSHAR =  deliver.sh
STRIP = strip

#
# 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 = addr.c context.c copymsg.c
DELSRC2 = debug.c dest.c dfile.c lock.c log.c main.c
DELSRC3 = mbox.c procs.c subs.c sysdep.c uucp.c
DELYY   = unctime.y
DELYC   = unctime.c
DELSRCY = $(DELSRC1) $(DELSRC2) $(DELSRC3) $(DELYY)
DELSRCC = $(DELSRC1) $(DELSRC2) $(DELSRC3) $(DELYC)
UIDSRCS = uid.c
HDRSRCS = header.c
COMSRCS = getopt.c
SAMPLES = samples samples/*

DELOBJS = addr.o context.o copymsg.o debug.o dest.o dfile.o lock.o \
	  log.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
	$(STRIP) deliver header
	$(COPY) deliver $(BIN)/deliver
	chown root.mail $(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)
unctime.o: unctime.c

clean::
	rm -f $(DELOBJS) $(DELYC)
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 header.lint uid.lint

deliver.lint: $(HDRS) $(DELSRCC) $(COMSRCS)
	$(LINT) $(DELSRCC) $(COMSRCS) $(LIBS) >$@

header.lint: $(HDRSRCS) $(COMSRCS)
	$(LINT) $(HDRSRCS) $(COMSRCS) $(LIBS) >$@

uid.lint: config.h $(UIDSRCS) $(COMSRCS)
	$(LINT) $(UIDSRCS) $(COMSRCS) $(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) $(DELYY)
	$(SHAR) >$@ $(DELSRC3) $(DELYY)

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