# $Id: Makefile,v 1.1.1.1 1992/09/28 01:51:43 trent Exp $
# Define A4 if you use A4 rather than letter size paper.
# Define IIg to enable a workaround for a bug in the serial
# driver of the Laserwriter IIf and IIg; this requires the POSIX
# tcdrain() function.
DEFINES=#-DA4 #-DIIg
PREFIX=/usr/contrib
# Where to install public executables.
BINDIR=$(PREFIX)/bin
# Where to install private executables.
LIBDIR=$(PREFIX)/lib/lprps
# Define REV_COMMAND to be empty if documents don't need to
# be printed in reverse order.
REV_COMMAND=$(BINDIR)/psrev |
# Where to install the filter for text files.
TEXT_FILTER=$(LIBDIR)/psif-text
# Where to install the filter for PostScript files.
PS_FILTER=$(LIBDIR)/psif-ps
# Where to install PostScript banner printing code
BANNER=$(LIBDIR)/banner.ps
# Filter to convert text to PostScript.  You can use your own instead.
# It must be able to read from standard input.
TEXT_TO_PS=$(BINDIR)/textps
MANROOT=$(PREFIX)/man
# Manual section for user commands.
MAN1EXT=1
MAN1DIR=$(MANROOT)/man$(MAN1EXT)
# Manual section for system maintenance and operation commands.
MAN8EXT=8
MAN8DIR=$(MANROOT)/man$(MAN8EXT)

CC=cc
CFLAGS=-O $(DEFINES)
#CFLAGS=-g -Bstatic $(DEFINES)
INSTALL=install -c
# Command for installing man pages.
MANINSTALL=install -c -m 0444

SOURCES=README INSTALL TODO Makefile psrev.c lprps.c psif.c textps.c psof.c \
	textps.man psrev.man lprps.man psif.man psof.man banner.ps lpr.diff
PROGS=psrev psif lprps textps psof

.SUFFIXES: .man .n

.man.n:
	@echo Making $@ from $<
	@-rm -f $@
	@sed -e "s;@MAN1EXT@;$(MAN1EXT);" \
	-e "s;@MAN8EXT@;$(MAN8EXT);" \
	-e "s;@PS_FILTER@;$(PS_FILTER);" \
	-e "s;@TEXT_FILTER@;$(TEXT_FILTER);" \
	-e "s;@BANNER@;$(BANNER);" \
	$< >$@
	@chmod 444 $@

all: psif-text psif-ps $(PROGS) textps.n psrev.n lprps.n psif.n psof.n

install: all
	$(INSTALL) psif lprps psof $(LIBDIR)
	$(MANINSTALL) banner.ps $(BANNER)
	$(INSTALL) textps psrev $(BINDIR)
	$(INSTALL) psif-text $(TEXT_FILTER)
	$(INSTALL) psif-ps $(PS_FILTER)
	$(MANINSTALL) textps.n $(MAN1DIR)/textps.$(MAN1EXT)
	$(MANINSTALL) psrev.n $(MAN1DIR)/psrev.$(MAN1EXT)
	$(MANINSTALL) lprps.n $(MAN8DIR)/lprps.$(MAN8EXT)
	$(MANINSTALL) psif.n $(MAN8DIR)/psif.$(MAN8EXT)
	$(MANINSTALL) psof.n $(MAN8DIR)/psof.$(MAN8EXT)
	@echo Now edit /etc/printcap

lprps: lprps.c
	$(CC) $(CFLAGS) -o $@ lprps.c

psif: psif.c
	$(CC) $(CFLAGS) -DTEXT_FILTER=\"$(TEXT_FILTER)\" \
	-DPS_FILTER=\"$(PS_FILTER)\" -o $@ psif.c

textps: textps.c
	$(CC) $(CFLAGS) -o $@ textps.c

psrev: psrev.c
	$(CC) $(CFLAGS) -o $@ psrev.c

psof: psof.c
	$(CC) $(CFLAGS) -DLPRPS=\"$(LIBDIR)/lprps\" \
	-DBANNER=\"$(BANNER)\" -o $@ psof.c

psif-text: Makefile
	@echo Creating $@
	@-rm -f $@
	@echo "#! /bin/sh" > $@
	@echo "$(TEXT_TO_PS) | $(REV_COMMAND) $(LIBDIR)/lprps \"\$$@\"" >>$@
	@chmod +x $@

psif-ps: Makefile
	@echo Creating $@
	@-rm -f $@
	@echo "#! /bin/sh" > $@
	@echo "$(REV_COMMAND) $(LIBDIR)/lprps \"\$$@\"" >>$@
	@chmod +x $@

lprps.shar: $(SOURCES)
	shar $(SOURCES) >$@

clean:
	-rm -f $(PROGS) psif-text psif-ps *.n
