# Makefile to set up /tmp directories for testing
# This Makefile assumes that ${BIN}/checkpc exists, as it uses it
#
#  The following entries are available:
# 1. make bin - will make the binaries, install them in temp
# 2. make test1 - creates a printcap, runs ${BIN}/checkpc on it.
#     This is the first level test printcap
# 3. make test2 - creates a printcap, runs ${BIN}/checkpc on it.
#     This is a second, more complex printcap
#
# The HOST is the name of the local host, should be fully-qualified,
#         otherwise printer_perms lookups won't work properly
#
# The USER is the name of the local user

# CHANGE THESE!!
HOST=destructor.iona.ie
USER=jmason
BIN=../sol2/
TMP=/share/tmp/
# the next should be as found in ../$OS/Makefile.
CONFIG_FILE=${TMP}plp.conf

LEVEL=1

help:
	@echo "uses the HOST and USER environment variables unless overridden"
	@echo "make bin, make test1, make test1"
	exit 1

$(CONFIG_FILE): plp.conf.proto
	sed -e s/HOST/${HOST}/ -e "s:TMP:${TMP}:g" -e s/USER/${USER}/ \
		plp.conf.proto  >${CONFIG_FILE}

pc: $(CONFIG_FILE) printcap.proto
	sed -e s/HOST/${HOST}/ -e 's/^#[0-$(LEVEL)]//' -e "s:TMP:${TMP}:g" \
		printcap.proto  >${TMP}printcap.${HOST}
	${BIN}/checkpc  -f -l ${TMP}printcap.${HOST}

perms: printer_perms.proto
	sed -e s/HOST/${HOST}/ -e s/USER/${USER}/ printer_perms.proto \
		 >${TMP}printer_perms.${HOST}

test1:
	make LEVEL=1 TMP=${TMP} HOST=${HOST} pc
test2:
	make LEVEL=2 TMP=${TMP} HOST=${HOST} pc
test3:
	make LEVEL=3 TMP=${TMP} HOST=${HOST} pc
test4:
	make LEVEL=4 TMP=${TMP} HOST=${HOST} pc
	-touch $(TMP)ms1/outputsv1
	-touch $(TMP)ms1/outputsv2

bin: perms
	install -c -m 755 filter.sh ${TMP}filter
	install -c -m 755 qh.sh ${TMP}qh
	$(CC) -o ${TMP}lpf -DDEBUG ../contrib/old-filters/main.c
clean:
	-rm -f *.o core lpf

veryclean: 	clean
	-rm -rf $(TMP)simple
	-rm -rf $(TMP)test
	-rm -rf $(TMP)remote
	-rm -rf $(TMP)ms1
	-rm -f  $(TMP)lpf $(TMP)filter $(TMP)qh
	-rm -f  $(TMP)lpd.lo* $(TMP)printcap.* $(TMP)printer_perms.* $(TMP)plp.conf
