#! /bin/make -f
#
#ident	"@(#)uutraf:Makefile	1.2.2.9	92/11/08 16:35:41 (woods)"
#
#	Makefile - for uutraf
#
# Usage:
#	make [OPTIM=] [DEBUG=-DDEBUG] [SDB=-g] [uutraf]
#	make install
#	make clean
#	make clobber
#	make shar
#
# History:
#	woods@robohack.UUCP - Sun Jul 05 23:43:43 EDT 1992
#	- many changes getting ready for new release
#	woods@robohack.UUCP - Sun Jul 15 12:38:34 EDT 1990
#	- minor cleanups
#	- added list library modules
#
# @(#) FILE:	Makefile
# @(#) Release:	1.2
# @(#) Date:	2/2/90
# @(#) Author:	Greg Hackney (hack@texbell.swbt.com)

SHELL = /bin/sh

LOCAL = /usr/local

BINDIR = $(LOCAL)/bin
LIBDIR = $(LOCAL)/lib
INCDIR = $(LOCAL)/include
MANEXT = 1
MANDIR = $(LOCAL)/man/man1

# Select the right definition for your system, unless you are compiling on
# one of the following:  SunOS, ULTRIX, AIX, XENIX.
# 
#	v7:	SYSTYPE= -DV7		/* UNTESTED "The Real Thing!"(tm) ;-) */
#   any BSD:	SYSTYPE= -DBSD		/* UNTESTED (not required?) */
#  fake BSD:	SYSTYPE= -UBSD		/* UNTESTED [for POSIX/ANSI systems] */
#	SysIII: SYSTYPE= -DSYSIII	/* UNTESTED */
#	SysV:	SYSTYPE= -DSYSV	 	/* generic AT&T or USG unix */
#	SysVr1:	SYSTYPE= -DSYSVR1	/* UNTESTED i.e. the original SysV */
#	SysVr2:	SYSTYPE= -DSYSVR2	/* yes, 3b1'ers, this is you too! */
#	SysVr3: SYSTYPE= -DSYSVR3
#	SysVr4: SYSTYPE= -DSYSVR4	/* Solaris 2.0 too! */
#	XENIX:	SYSTYPE= 		/* let the compiler do it, please! */
#	AIX:	SYSTYPE= 		/* let the compiler do it, please! */
#   any P1003.1:SYSTYPE= -D_POSIX_SOURCE	/* may combine with above */
#
SYSTYPE		= -DSYSVR3

# NOTE:  you'll have to define DUMB_VOID if your compiler doesn't fully
# understand the 'void' keyword.  (The most common error indicating this
# symptom is "operands of ':' have incompatible types" for invocations of
# the lst_top()/lst_bottom() macros.)  If your compiler doesn't understand
# 'void' at all, then you should also define REDEF_VOID.
#
#DEFS = $(SYSTYPE) -DDUMB_VOID
#DEFS = $(SYSTYPE) -DDUMB_VOID -DREDEF_VOID
#
# If your system has <stdlib.h>, but your compiler isn't ANSI-C
#	add -DUSE_STDLIB
# If your compiler is ANSI-C, and you want <malloc.h>,
#	add -DUSE_MALLOC
# If your system has <stddef.h>, but isn't ANSI-C (or POSIX),
#	add -DUSE_STDDEF
# If your compiler is almost ANSI-C, but doesn't have (__STDC__ == 1),
#	add -DREALSTDC=1 [(or -D__STDC__=1), BUT -- BE CAREFUL!]
# If your system is POSIX 1003.1 compliant,
#	add -D_POSIX_SOURCE
# If your system has <malloc.h>, but your compiler isn't ANSI-C,
#	add -DUSE_MALLOC [and perhaps include -lmalloc in LIBS]
# If your system has <stdarg.h>, but your compiler isn't (ANSI-C && BSD),
#	add -DUSE_STDARGS [and you'll likely also need -DUSE_PROTOTYPES]
# If your compiler understands prototypes, but isn't ANSI-C,
#	add -DUSE_PROTOTYPES
# If your compiler doesn't understand prototypes for pointers to functions,
#	add -DNO_PTRPROTO
# If your compiler has old-style support (V7) for 'void', and isn't ANSI-C
#	add -DDUMB_VOID
# If your compiler doesn't understand 'void' at all,
#	add -DREDEF_VOID
# If your compiler understands 'const', but isn't ANSI-C
#	add -DUSE_CONST
# If your compiler understands 'volatile', but isn't ANSI-C
#	add -DUSE_VOLATILE
# If your compiler understands 'signed', but isn't ANSI-C
#	add -DUSE_SIGNED
# If your compiler understands 'void *' as the universal pointer, but isn't ANSI-C
#	add -DUSE_VOIDPTR
# If your system doesn't typedef 'size_t', and <sysdefs.h> doesn't either
#	add -DNEED_SIZE_T
# If your system doesn't typedef 'wchar_t', and <sysdefs.h> doesn't either
#	add -DNEED_WCHAR_T
# If your system doesn't typedef 'ptrdiff_t', and <sysdefs.h> doesn't either
#	add -DNEED_PTRDIFF_T
#
DEFS = $(SYSTYPE)

# Use -lc_s if your system supports AT&T shared libraries.
# Use -lmalloc if your libc(malloc.o) is ancient.  [see -DUSE_MALLOC above]
#
#LIBS = -ldlst
#LIBS = -ldlst -lmalloc
#LIBS = -ldlst -lc_s
#LIBS = -ldlst -lmalloc -lc_s
#
LIBS = -ldlst -lmalloc -lc_s

# BSD derivatives might need strtok() & getopt()
#BSDOBJS = strtok.o getopt.o

# Use 'make DEBUG=-DDEBUG' to compile in debugging code.
# Use 'make DEBUG=-DNDEBUG' to turn off assert()s.
#
DEBUG = 

# Use 'make OPTIM= SDB=-g' to build for a symbolic debugger.
#
OPTIM = -O
SDB = 

CFLAGS = $(OPTIM) $(SDB) -I$(INCDIR) $(DEBUG) $(DEFS)
LDFLAGS = -L$(LIBDIR)

# Another sample:
#
#CFLAGS = $(OPTIM) $(SDB) -I$(LOCAL)/include $(DEBUG) $(DEFS) -pipe -ansi \
#	-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \
#	-Dscanf=DONT_USE_SCANF -Dgets=DONT_USE_GETS
#CC = gcc
#LIBS = -ldlst

#
#	The rest should be OK.
#

PROG = uutraf

OBJECTS = uutraf.o version.o $(BSDOBJS)
SOURCES = uutraf.c version.c pdstrtok.c
INCLUDES = uutraf.h version.h patchlevel.h
OTHER = README Makefile-dist CREDITS defs.h-dist CHANGES RELEASES Letter Letter-1.2
DOCS = uutraf.1
OTHERSTUFF = $(OTHER) $(DOC)

.PRECIOUS:	$(OTHERSTUFF)

# for building distributions only!!!!
#
DLSTDIR = ../lib/dlst
DLST = $(DLSTDIR)/dlst.shar
EXTERN_HDRS = ../head/sccsid.h ../head/sysdefs.h ../head/libc.h ../head/str.h \
	../head/extern.h ../head/intern.h
EXTERN_SRCS = ../lib/pdlibc/getopt.c ../../ucblib/string/strtok.c
EXTERN_STUFF = $(EXTERN_SRCS) $(EXTERN_HDRS)
EXTSHARS = externhdr.shar externsrc.shar $(DLST)

FILES = $(DOCS) $(INCLUDES) $(SOURCES) $(OTHER) $(EXTSHARS)

default: $(PROG)

all: $(PROG)

$(PROG): $(OBJECTS)
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS)

uutraf.o: uutraf.h defs.h version.h

version.o: version.h patchlevel.h

defs.h: defs.h-dist
	@echo "Copy defs.h-dist to defs.h and edit to suit." ; exit 1

install: all
	cp $(PROG) $(BINDIR)/$(PROG)
	chmod 755 $(BINDIR)/$(PROG)
	cp uutraf.1 $(MANDIR)/$(PROG).$(MANEXT)

clean:
	rm -f $(OBJECTS) core

clobber: clean clean-ext-shars
	rm -f $(PROG)

shar:	$(PROG).shar clean-dlst-dist

clean-ext-shars:
	rm -f $(EXTSHARS)

simple-dist:	Makefile-dist $(PROG).shar clean-dlst-dist clean-ext-shars

# using 'make dist' prevents ever applying official patches to Makefile-dist...
#
Makefile-dist:	Makefile
	@echo "'cp Makefile Makefile-dist'  Are you sure? [<DEL> to abort] \c"; read junk
	rm -f Makefile-dist
	cp Makefile Makefile-dist

$(PROG).shar: $(OTHER) $(DOCS) $(INCLUDES) $(SOURCES) $(EXTSHARS)
	( sed -e '/^TO COMPILE$$/,/^#ident/d' README ; \
	  shar -b -t 'NOTE:  contains dlst library sources shar.  Read the README!' \
		$(OTHER) $(DOCS) $(INCLUDES) $(SOURCES) $(EXTSHARS) ; \
	) > $(PROG).shar

$(DLST):
	cd $(DLSTDIR); $(MAKE) -$(MAKEFLAGS) shar

clean-dlst-dist:
	cd $(DLSTDIR); $(MAKE) -$(MAKEFLAGS) cleandist

echo:
		@echo Makefile defs.h $(INCLUDES) $(SOURCES)

echoall:
		@echo $(FILES)

externhdr.shar:	$(EXTERN_HDRS)
		shar -b -t 'Put these in your local include directory.' $(EXTERN_HDRS) > $@

externsrc.shar:	$(EXTERN_SRCS)
		shar -b -t 'Modules for libfake...' $(EXTERN_SRCS) > $@

ADMIN		= sccs enter
ADMINFLAGS	= -fb -ftuutraf -fqwoods
VCSDIR		= SCCS

# I'll only ever use this once, but you can use it for each major
# release to start over your local change monitoring
#
# WARNING: this is a first hack
#
mksccs:
		-mkdir $(VCSDIR)
		$(ADMIN) $(ADMINFLAGS) $(OTHERSTUFF) $(INCLUDES) $(SOURCES)

# You can probably do this kind of stuff with RCS too....
#
CHANGEFORMAT	= -d":Z::Y:\::M:\t:Dt:\t(:Q:)\n\t:C:"
PRS		= prs
PRSFLAGS	= -l
RELEASEFORMAT	= date '+%y/%m/%d-%T'
PATCHFORMAT	= date '+%y%m%d'
VEDITING	= sccs tell

# Create an actual "release" by updating RELEASES and CHANGES.  A release is
# defined as any change in patchlevel.h, followed by 'make dist'.
#
CHANGES:	patchlevel.h
		@if [ -n "`$(VEDITING)`" ] ; then echo "Checked out for editing: `$(VEDITING)`"; exit 1; fi
		@echo '-------------------------------------------------------------------------------' > /tmp/uutraf.$@
		-$(PRS) $(PRSFLAGS) -c`tail -1 RELEASES` $(CHANGEFORMAT) $(VCSDIR) >> /tmp/uutraf.$@
		echo '----' >> /tmp/uutraf.$@ ; echo '' >> /tmp/uutraf.$@
		$(RELEASEFORMAT) >> RELEASES
		echo "Changes for Release dated:  `tail -1 RELEASES`" | cat - /tmp/uutraf.$@ $@ > $@.new
		mv -f $@.new $@
		@rm -f /tmp/uutraf.$@
		@-chmod -w $@

GET		= sccs get
DIFF		= diff
DIFFFLAGS	= -c

# Make a Patch file for changes since the most recent release.
#
# WARNING: this is a first hack.  A patch is always made from the most recent
# full release.  Sequential patches must be interspersed with "fake" releases.
#
# Both this, and probably the update of CHANGES (above) should be done in
# a separate script.
#
# NOTE: This can be called at any time without doing a full release.
#
# ALSO: Does not update CHANGES.
#
Patch:		patchlevel.h
		@if [ -n "`sccs tell`" ] ; then echo "Do your deltas [make mass-delta]! (`sccs tell`)" ; exit 1 ; fi
		echo "Patch-Creation-Date: `$(RELEASEFORMAT)`" > $@
		@: remainder must be one command line, and must append to $@
		tdir=/tmp/pgen.$$$$ ; \
		mkdir $$tdir ; \
		oldver=`tail -1 RELEASES` ; \
		echo "Changes-Since: $$oldver" >> $@ ; \
		for mod in `prs -d:M: $(VCSDIR)` ; do \
			$(GET) -s -p -c$$oldver $$mod > $$tdir/$$mod ; \
			$(DIFF) $(DIFFFLAGS) $$tdir/$$mod $$mod > $$tdir/diff.out ; \
			if [ -s $$tdir/diff.out ] ; then \
				echo "" ; \
				echo "Index: $$mod" ; \
				echo "Prereq: `prs -e -c$$oldver -d:I: $$mod`" ; \
				cat $$tdir/diff.out ; \
			fi >> $@ ; \
		done
		@echo "You should try the patch against $$tdir"

# build a distribution shar set using makekit (from Rich Salz's cshar)
#
dist:		$(PROG).dist clean-dlst-dist clean-ext-shars

$(PROG).dist:	DIST MANIFEST
		@if [ ! -d DIST ] ; then mkdir DIST ; else rm -i DIST/* ; fi
		makekit -n./DIST/Part. -m -t'Please read the file README first'
		touch $(PROG).dist

DIST:
		-mkdir $@

# building a manifest for makekit requires all other files in the "release"
# to be ready and up-to-date.  we hide the actual first-stage run of makekit,
# as it is both boring and has a very long command line.
#
# NOTE: this precludes editing of the file MANIFEST (for silly things like
#	including more descriptive comments...
#
MANIFEST:	CHANGES Makefile-dist defs.h-dist $(EXTSHARS)
		@-rm -f $@
		@-rm -f makekit.in
		@echo $(FILES) | tr '\040' '\012' > makekit.in
		makekit -x -n./DIST/Part. < makekit.in > $@
		@-rm -f makekit.in

test-MANIFEST:
		-rm -f makekit.in
		echo $(FILES) | tr '\040' '\012' > makekit.in
		makekit -x -n./DIST/Part. < makekit.in > $@
