#***************************************************************************
#* U. Minnesota LPD Software * Copyright 1987, 1988, Patrick Powell
#***************************************************************************
#* MODULE: Makefile
#***************************************************************************
#* Revision History:  Recreated
#* Sun Jan  3 07:27:44 CST 1988: V1
#***************************************************************************
#$Log:	Makefile,v $
# Revision 3.2  88/06/24  17:58:54  papowell
# MODS for VAX 4.3BSD UNIX
# 
# Revision 3.1  88/06/18  09:33:48  papowell
# Version 3.0- Distributed Sat Jun 18 1988
# 
# Revision 3.0  88/06/18  09:29:46  papowell
# Version 3.0- Distributed Sat Jun 18 1988
# 
# Revision 2.3  88/05/16  12:09:58  papowell
# Added a "test" entry to make XPERIMENT version
# 
# Revision 2.2  88/05/11  09:53:19  papowell
# Modified installation targets to be compatible with Berkeley LPR
# 
# Revision 2.1  88/05/09  10:07:22  papowell
# PLP: Released Version
# 
# Revision 1.10  88/04/29  07:44:51  papowell
# Added USE_LOCKF for alternative form of locking
# 
# Revision 1.9  88/04/28  17:30:23  papowell
# Fixed installation
# 
#
# This makefile will generate and install the PLP software.
# You should create a "bin" directory,  and copy this Makefile to the bin
# directory.  All binaries and executables will be created in the bin directory.
#
# The PLP stuff runs SUID ROOT.
#
# There are various compilation options;  see the following for details.
#
# Note that this Makefile does NOT create spool directories;
# you have to do that yourself, whenever a new entry is added to /etc/printcap
# See the "checkpc" program for help.
#
.SUFFIXES:

# commands made by this script
COMMANDS= lpd lpr lpq lprm lpc pac checkpc

# where daemons are installed: lpd
#LIB=/usr/lib/
#LIB=/usr/local/new/lib
LIB=/usr/lib/

# where user commands are installed: lpr, lpq, lprm, lpc
#BIN=/usr/local/new/bin/
BIN=/usr/ucb/

# where maintenance commands are installed: pac, checkpc
#MAINTDIR=/etc/
MAINTDIR=$(BIN)

# source directory, holds all source
SRC=../src

# lint directory, where the output of the various lintings will go
LNT=../lint

#**************** OPTIONS *******************************
# The following flags are used to control compile time dependent options

# MACHINE - IS_SUN, IS_VAX, IS_UMAX (ENCORE NS32000)
# Oh, this is sick.  You should check the lp.h file for dependencies
# These are explained below. Most are "ifndef" or "ifdef" in a very few files.
# Some systems do not have certain data types available,  so that you have to
# define some types.  See "lp.h" for the set of definitions and some options
# that have been hardwired there for ease of installation.
  MACHINE = -DIS_SUN=1
# MACHINE = -DIS_VAX4BSD=1
# MACHINE = -DIS_DATAGEN=1
# MACHINE = -DIS_UMAX=1
# MACHINE = -DIS_APOLLO=1


# XPERIMENT: Generation a version that can be used to experiment
# DEBUG: Generate a version that has -X option enabled
#   The XPERIMENT option specifies -X option always to be used
 XPERIMENT=-DXPERIMENT=1
#DEBUG=-DDEBUG=1

# SYSLOG: syslog(8) is a 4BSD logging facility.
# If you do not have syslog, define NOSYSLOG and error messages will
# be printed to /dev/console.  See syslogmsg.c for details.
# The <syslog.h> include file contains a set of definitions for values
# to be used by the SYSLOG software.  Different systems have different
# error values, which means that the values are compile time dependent.
# This  is usually set in lp.h based on "IS_??"
#NOSYSLOG=-DNOSYSLOG=1

# SYMLINK: If you do not have symbolic links, you cannot use them.
# This  is usually set in lp.h based on "IS_??"
#NOSYMLINK=-DNOSYMLINK=1

# ETCPC:  printcap file; default is /etc/printcap
# ETCPERMS:  printer permissions file; default is /etc/printer_perms
# Modify the following.
#ETCPC=-DETCPC='"/usr/etc/printcap"'
#ETCPERMS=-DETCPERMS='"/usr/etc/printer_perms"'

# NO_LOCKF: some systems do not have lockf() which is used to lock files;
# The alternative is to use flock().  If you do not have either,  modify
# the do_lock() procedure in lockfile.c to provide locking, although this has
# proven to be fairly unsucessful in the past.
# NOTE: lockf is essential to use in an NFS environment
#NO_LOCKF=-DNO_LOCKF=1

# Define TERMCAP and TERMLIB if curses is to be used by lpq
TERMCAP=-DTERMCAP=1
TERMLIB=-lcurses -ltermcap

FLAGS= -I. -I${SRC} ${DEBUG} ${XPERIMENT} ${MACHINE} \
	${NOSYMLINK} ${ETCPC} ${ETCPERMS} ${TERMCAP} ${USE_LOCKF}
#CFLAGS= -O ${FLAGS}
CFLAGS= -g ${FLAGS}
LINTFLAGS= -huv ${FLAGS}
LINTFILTER = \
	| sed -e '/warning: struct.union iovec never defined/d' -e '/:$$/d' \
		-e '/warning: possible pointer alignment problem/d'

COMPILE= ${CC} -c ${CFLAGS}
CXREF=/usr/ucb/ctags -x
PRINT=cpr -r

all:	${COMMANDS}

#
# Binary : Object    dependencies
# LPD
DEPlpd =  \
	banner.o checkperm.o control_ops.o displayq.o errormsg.o getopt.o global.o \
	link_support.o localprinter.o lockfile.o lpd.o mexecv.o print_support.o \
	printcap.o recvfiles.o remote_ops.o remoteprinter.o rmjob.o sendmail.o \
	servicereq.o setstatus.o setup_filter.o setup_test.o startserver.o \
	startprinter.o utils.o find_name.o
SRClpd =  \
	${SRC}/banner.c ${SRC}/checkperm.c ${SRC}/control_ops.c ${SRC}/displayq.c \
	${SRC}/errormsg.c ${SRC}/getopt.c ${SRC}/global.c ${SRC}/link_support.c \
	${SRC}/localprinter.c ${SRC}/lockfile.c ${SRC}/lpd.c ${SRC}/mexecv.c \
	${SRC}/print_support.c ${SRC}/printcap.c ${SRC}/recvfiles.c \
	${SRC}/remote_ops.c ${SRC}/remoteprinter.c ${SRC}/rmjob.c \
	${SRC}/sendmail.c ${SRC}/servicereq.c ${SRC}/setstatus.c \
	${SRC}/setup_filter.c ${SRC}/setup_test.c ${SRC}/startserver.c \
	${SRC}/startprinter.c ${SRC}/utils.c ${SRC}/find_name.c
lpd: $(DEPlpd)
	${CC}  ${CFLAGS}  -o lpd $(DEPlpd)
DEPlpr =  \
	checkperm.o errormsg.o getopt.o global.o lockfile.o lpr.o lpr_canprint.o \
	lpr_filters.o lpr_global.o lpr_job.o lpr_parms.o lpr_temp.o mexecv.o \
	printcap.o setup_filter.o setup_test.o startserver.o utils.o getprinter.o \
	remote_ops.o link_support.o
SRClpr =  \
	${SRC}/checkperm.c ${SRC}/errormsg.c ${SRC}/getopt.c ${SRC}/global.c \
	${SRC}/lockfile.c ${SRC}/lpr.c ${SRC}/lpr_canprint.c ${SRC}/lpr_filters.c \
	${SRC}/lpr_global.c ${SRC}/lpr_job.c ${SRC}/lpr_parms.c ${SRC}/lpr_temp.c \
	${SRC}/mexecv.c ${SRC}/printcap.c ${SRC}/setup_filter.c \
	${SRC}/setup_test.c ${SRC}/startserver.c ${SRC}/utils.c \
	${SRC}/getprinter.c ${SRC}/remote_ops.c ${SRC}/link_support.c
lpr: $(DEPlpr)
	${CC}  ${CFLAGS}  -o lpr $(DEPlpr)
DEPlpq =  \
	lpq.o getprinter.o global.o displayq.o utils.o setup_test.o \
	lockfile.o errormsg.o printcap.o remote_ops.o link_support.o \
	termclear.o getopt.o
SRClpq =  \
	${SRC}/lpq.c ${SRC}/getprinter.c ${SRC}/global.c ${SRC}/displayq.c \
	${SRC}/utils.c ${SRC}/setup_test.c ${SRC}/lockfile.c ${SRC}/errormsg.c \
	${SRC}/printcap.c ${SRC}/remote_ops.c ${SRC}/link_support.c \
	${SRC}/termclear.c ${SRC}/getopt.c 
lpq: $(DEPlpq)
	${CC}  ${CFLAGS}  -o lpq $(DEPlpq) ${TERMLIB}
DEPlpc =  \
	checkperm.o control_ops.o errormsg.o getopt.o getprinter.o global.o \
	lockfile.o lpc.o printcap.o setup_test.o startserver.o utils.o \
	remote_ops.o link_support.o
SRClpc =  \
	${SRC}/checkperm.c ${SRC}/control_ops.c ${SRC}/errormsg.c \
	${SRC}/getopt.c ${SRC}/getprinter.c ${SRC}/global.c \
	${SRC}/lockfile.c ${SRC}/lpc.c ${SRC}/printcap.c ${SRC}/setup_test.c \
	${SRC}/startserver.c ${SRC}/utils.c ${SRC}/remote_ops.c \
	${SRC}/link_support.c
lpc: $(DEPlpc)
	${CC}  ${CFLAGS}  -o lpc $(DEPlpc)
DEPlprm =  \
	checkperm.o errormsg.o getopt.o getprinter.o global.o link_support.o \
	lockfile.o lprm.o printcap.o remote_ops.o rmjob.o setup_test.o \
	startserver.o utils.o
SRClprm =  \
	${SRC}/checkperm.c ${SRC}/errormsg.c ${SRC}/getopt.c ${SRC}/getprinter.c \
	${SRC}/global.c ${SRC}/link_support.c ${SRC}/lockfile.c ${SRC}/lprm.c \
	${SRC}/printcap.c ${SRC}/remote_ops.c ${SRC}/rmjob.c ${SRC}/setup_test.c \
	${SRC}/startserver.c ${SRC}/utils.c
lprm: $(DEPlprm)
	${CC}  ${CFLAGS}  -o lprm $(DEPlprm)
DEPcheckpc= \
	checkpc.o global.o printcap.o errormsg.o setup_test.o utils.o \
	lockfile.o getopt.o
SRCcheckpc= \
	${SRC}/checkpc.c ${SRC}/global.c ${SRC}/printcap.c ${SRC}/errormsg.c \
	${SRC}/setup_test.c ${SRC}/utils.c ${SRC}/lockfile.c ${SRC}/getopt.c
checkpc: $(DEPcheckpc)
	${CC}  ${CFLAGS}  -o checkpc $(DEPcheckpc)
DEPpac= \
	pac.o global.o printcap.o errormsg.o setup_test.o \
	getopt.o getprinter.o utils.o lockfile.o
SRCpac= \
	${SRC}/pac.c ${SRC}/global.c ${SRC}/printcap.c ${SRC}/errormsg.c  \
	${SRC}/setup_test.c ${SRC}/getopt.c ${SRC}/getprinter.c ${SRC}/utils.c \
	${SRC}/lockfile.c
pac: $(DEPpac)
	${CC}  ${CFLAGS}  -o pac $(DEPpac)
#
# Object - Source  dependencies
#
banner.o:	$(SRC)/banner.c
	${COMPILE} ${SRC}/banner.c
checkpc.o:	$(SRC)/checkpc.c
	${COMPILE} ${SRC}/checkpc.c
checkperm.o:	$(SRC)/checkperm.c
	${COMPILE} ${SRC}/checkperm.c
control_ops.o:	$(SRC)/control_ops.c
	${COMPILE} ${SRC}/control_ops.c
displayq.o:	$(SRC)/displayq.c
	${COMPILE} ${SRC}/displayq.c
errormsg.o:	$(SRC)/errormsg.c
	${COMPILE} ${SRC}/errormsg.c
find_name.o:	$(SRC)/find_name.c
	${COMPILE} ${SRC}/find_name.c
getprinter.o:	$(SRC)/getprinter.c
	${COMPILE} ${SRC}/getprinter.c
getopt.o:	$(SRC)/getopt.c
	${COMPILE} ${SRC}/getopt.c
global.o:	$(SRC)/global.c
	${COMPILE} ${SRC}/global.c
link_support.o:	$(SRC)/link_support.c
	${COMPILE} ${SRC}/link_support.c
localprinter.o:	$(SRC)/localprinter.c
	${COMPILE} ${SRC}/localprinter.c
lockfile.o:	$(SRC)/lockfile.c
	${COMPILE} ${SRC}/lockfile.c
lpc.o:	$(SRC)/lpc.c
	${COMPILE} ${SRC}/lpc.c
lpd.o:	$(SRC)/lpd.c
	${COMPILE} ${SRC}/lpd.c
lpr.o:	$(SRC)/lpr.c
	${COMPILE} ${SRC}/lpr.c
lprm.o:	$(SRC)/lprm.c
	${COMPILE} ${SRC}/lprm.c
lpq.o:	$(SRC)/lpq.c
	${COMPILE} ${SRC}/lpq.c
lpr_canprint.o:	$(SRC)/lpr_canprint.c
	${COMPILE} ${SRC}/lpr_canprint.c
lpr_filters.o:	$(SRC)/lpr_filters.c
	${COMPILE} ${SRC}/lpr_filters.c
lpr_global.o:	$(SRC)/lpr_global.c
	${COMPILE} ${SRC}/lpr_global.c
lpr_job.o:	$(SRC)/lpr_job.c
	${COMPILE} ${SRC}/lpr_job.c
lpr_parms.o:	$(SRC)/lpr_parms.c
	${COMPILE} ${SRC}/lpr_parms.c
lpr_temp.o:	$(SRC)/lpr_temp.c
	${COMPILE} ${SRC}/lpr_temp.c
mexecv.o:	$(SRC)/mexecv.c
	${COMPILE} ${SRC}/mexecv.c
pac.o:	$(SRC)/pac.c
	${COMPILE} ${SRC}/pac.c
print_support.o:	$(SRC)/print_support.c
	${COMPILE} ${SRC}/print_support.c
printcap.o:	$(SRC)/printcap.c
	${COMPILE} ${SRC}/printcap.c
recvfiles.o:	$(SRC)/recvfiles.c
	${COMPILE} ${SRC}/recvfiles.c
remote_ops.o:	$(SRC)/remote_ops.c
	${COMPILE} ${SRC}/remote_ops.c
remoteprinter.o:	$(SRC)/remoteprinter.c
	${COMPILE} ${SRC}/remoteprinter.c
rmjob.o:	$(SRC)/rmjob.c
	${COMPILE} ${SRC}/rmjob.c
sendmail.o:	$(SRC)/sendmail.c
	${COMPILE} ${SRC}/sendmail.c
servicereq.o:	$(SRC)/servicereq.c
	${COMPILE} ${SRC}/servicereq.c
setstatus.o:	$(SRC)/setstatus.c
	${COMPILE} ${SRC}/setstatus.c
setup_filter.o:	$(SRC)/setup_filter.c
	${COMPILE} ${SRC}/setup_filter.c
setup_test.o:	$(SRC)/setup_test.c
	${COMPILE} ${SRC}/setup_test.c
startserver.o:	$(SRC)/startserver.c
	${COMPILE} ${SRC}/startserver.c
startprinter.o:	$(SRC)/startprinter.c
	${COMPILE} ${SRC}/startprinter.c
termclear.o:	$(SRC)/termclear.c
	${COMPILE} ${SRC}/termclear.c
utils.o:	$(SRC)/utils.c
	${COMPILE} ${SRC}/utils.c
#
# Installation of commands
#
install: all
	install -s -c -o root -m u=sxr,g=xr,o=xr lpd ${LIB}
	install -s -c -o root -m u=sxr,g=xr,o=xr lpq ${BIN}
	install -s -c -o root -m u=sxr,g=xr,o=xr lprm ${BIN}
	install -s -c -o root -m u=sxr,g=xr,o=xr lpc ${MAINTDIR}
	install -s -c -o root -m u=sxr,g=xr,o=xr lpr ${BIN}
	install -s -c -o root pac ${MAINTDIR}
	install -s -c -o root checkpc ${MAINTDIR}

remove:
	rm -f ${LIB}/lpd
	rm -f ${BIN}/lpq
	rm -f ${BIN}/lprm
	rm -f ${MAINTDIR}/lpc
	rm -f ${BIN}/lpr
	rm -f ${MAINTDIR}/pac
	rm -f ${MAINTDIR}/checkpc
#
# Lint dependencies
#

lint:	$(LNT)/lpd $(LNT)/lpr $(LNT)/lpq $(LNT)/lprm \
		$(LNT)/lpc $(LNT)/checkpc $(LNT)/pac

$(LNT)/lpd: $(SRClpd)
	lint  ${LINTFLAGS} $(SRClpd)  ${LINTFILTER} > $(LNT)/lpd

$(LNT)/lpr: $(SRClpr)
	lint  ${LINTFLAGS} $(SRClpr)  ${LINTFILTER} > $(LNT)/lpr

$(LNT)/lpq: $(SRClpq)
	lint  ${LINTFLAGS} $(SRClpq)  ${LINTFILTER} > $(LNT)/lpq

$(LNT)/lprm: $(SRClprm)
	lint  ${LINTFLAGS} $(SRClprm)  ${LINTFILTER} > $(LNT)/lprm

$(LNT)/lpc: $(SRClpc)
	lint  ${LINTFLAGS} $(SRClpc)  ${LINTFILTER} > $(LNT)/lpc

$(LNT)/checkpc: $(SRCcheckpc)
	lint  ${LINTFLAGS} $(SRCcheckpc)  ${LINTFILTER} > $(LNT)/checkpc

$(LNT)/pac: $(SRCpac)
	lint  ${LINTFLAGS} $(SRCpac)  ${LINTFILTER} > $(LNT)/pac

#
# Miscellaneous
#
clean:
	-rm -f ${COMMANDS} *.o core ?

print:
	@${PRINT} Makefile *.h ${SRCS} | lpr -J lpd

xref:
	@${CXREF} *.c | pr -h XREF

Tags:
	ctags -t *.c *.h >.ctags_warnings 2>&1
perms:
	chown root lp? lp??
	chmod  u=sxr,g=xr,o=xr lp? lp??
unperms:
	for i in ${COMMANDS} ; \
	do \
	case $$i in \
		lp? | lp??)	\
			echo $$i ;	\
			cat $$i >x; rm $$i ; mv x $$i; \
			chmod a+x $$i	;	\
			;;	\
	esac				\
	done
test:
	-rm checkpc.o lpc.o lpd.o lpq.o lpr.o lprm.o pac.o
	make  XPERIMENT=-DXPERIMENT=1 all
