#  makefile for shar
#
# $Header: /u/rhg/src/shar/Makefile,v 3.49 90/09/12 15:14:18 rhg Exp $
#
#+:EDITS:
#:09-09-1990-20:12-rhg@cps.com-added CLOSEDIR_VOID
#:09-09-1990-11:31-bill@netagw.com-add SHELL variable/-ldir for XENIX/UNIX 386
#:08-07-1990-21:25-rhg@cps.com-compress man pages if MANEXT ends with .Z
#:08-05-1990-23:50-rhg@cps.com-add post and compressed.
#:08-05-1990-12:19-rhg@cps.com-add LIBS and -ldirent
#:08-04-1990-18:51-rhg@cps.com-add CC, LD; move strip; reorder chgrp/chown.
#:05-14-1990-17:33-wht@n4hgf-add -F 5000 for XENIX 286
#:05-14-1990-17:32-bill@netagw.com-expanded Makefile
#:03-28-1990-14:54-wht@n4hgf-for 3.10, add who@where.c

SHELL=/bin/sh

BINDIR	= /usr/local/bin
OWNER	= bin
GROUP	= bin
BINMODE	= 0755
MANDIR	= /usr/man/manl
MANEXT	= l
MANOWN	= bin
MANGRP	= bin
MANMODE	= 0644

CC	= cc
LD	= ${CC}

# If you don't have Doug Gwyn's dirent routines or equivalent, then remove
# -ldirent from LIBS and add -DNO_WALKTREE to CFLAGS.  All you will give up
# is the ability to shar directorys without using "find ... -type f | shar -S".
# Note that many systems have the equivalent of the dirent library built into
# the standard C library.  For such systems, just remove -ldirent from LIBS.
# (note by RHG@CPS.COM: I don't know which systems listed below are like that.)
# Some systems, such as SCO XENIX/UNIX 386 use -ldir instead.
# Some systems, such as SunOS 3, use <sys/dir.h> instead of <dirent.h>.  For
# these systems, add -DNO_DIRENT to CFLAGS.  Many of these same systems, such
# as BSD, have a closedir that has no return value.  For these systems, add
# both -DNO_DIRENT and -DCLOSEDIR_VOID to CFLAGS.

# For VAX, PYRAMID, SEQUENT, AT&T 3B1/7300
CFLAGS	= -O 
LDFLAGS	=
#LIBS	= -ldirent

# For SUN
#CFLAGS	= -O -DNO_DIRENT -DCLOSEDIR_VOID
#LDFLAGS	=
#LIBS	=

# For SCO XENIX/UNIX 386
#CFLAGS	= -O -DNO_DIRENT -DCLOSEDIR_VOID
#LDFLAGS	=
#LIBS	= -ldir

# For SCO XENIX 286
#CFLAGS	= -O 
#LDFLAGS	= -F 5000
#LIBS	= -ldirent

# For other System V systems I did not catch
#CFLAGS	= -O -DSYS5
#LDFLAGS	=
#LIBS	= -ldirent

# For BSD-like systems
#CFLAGS	= -O -DBSD42 -DNO_DIRENT -DCLOSEDIR_VOID
#LDFLAGS	=
#LIBS	=

SOURCES	= README Makefile shar.1 unshar.1 uushar.c who@where.c unshar.c shar.c

SHAR	= shar.o uushar.o who@where.o
UNSHAR	= unshar.o

all: shar unshar

shar: ${SHAR}
	${LD} ${LDFLAGS} ${SHAR} ${LIBS} -o shar

unshar : ${UNSHAR}
	${LD} ${LDFLAGS} ${UNSHAR} ${LIBS} -o unshar

shar.o : shar.c
	${CC} ${CFLAGS} -c shar.c

unshar.o : unshar.c
	${CC} ${CFLAGS} -c unshar.c

uushar.o : uushar.c
	${CC} ${CFLAGS} -c uushar.c

who@where.o : who@where.c
	${CC} ${CFLAGS} -c who@where.c

install : shar unshar
	strip shar unshar
	cp shar unshar ${BINDIR}
	chmod ${BINMODE} ${BINDIR}/shar ${BINDIR}/unshar
	chgrp ${GROUP} ${BINDIR}/shar ${BINDIR}/unshar
	chown ${OWNER} ${BINDIR}/shar ${BINDIR}/unshar
	if expr "${MANEXT}" : ".*\.Z$$" >/dev/null; then \
		compress -b14 < shar.1   > ${MANDIR}/shar.${MANEXT}; \
		compress -b14 < unshar.1 > ${MANDIR}/unshar.${MANEXT}; \
	else \
		cp shar.1   ${MANDIR}/shar.${MANEXT}; \
		cp unshar.1 ${MANDIR}/unshar.${MANEXT}; \
	fi
	chmod ${MANMODE} ${MANDIR}/shar.${MANEXT} ${MANDIR}/unshar.${MANEXT}
	chgrp ${MANGRP}  ${MANDIR}/shar.${MANEXT} ${MANDIR}/unshar.${MANEXT}
	chown ${MANOWN}  ${MANDIR}/shar.${MANEXT} ${MANDIR}/unshar.${MANEXT}

clean :
	rm -f *.o core

clobber : clean
	rm -f shar unshar

SETV =	X="`head -1 shar.c`"; \
	V=`expr "$$X" : 'char \*revision = "\([1-9][0-9]*\.[0-9.a-zA-Z]*\)";$$'`;

post : ${SOURCES}
	${SETV} test -n "$$V" && ( \
	rm -f shar$$V.[0-9][0-9]; \
	shar -l50 -acF -n "shar$$V" -o "shar$$V" ${SOURCES} )

compressed : ${SOURCES}
	${SETV} test -n "$$V" && \
	shar -acFm -b16 -n "shar$$V" > "shar$$V" ${SOURCES}

