#!/usr/bin/make

FILTERPATH = /usr/libexec/filters/fax
LIBPATH = /usr/lib/mgetty+sendfax
FAXHOST = mobius
FAXNAME = fax
FAXALIAS = faxprint
PRINTCAP = /etc/printcap

all: all-host all-remote

all-host: prefilter filter

all-remote: prefilter

testing:
	rm -f filter prefilter
	FILTERPATH=/home/conon/cube/lprfax/test \
	LIBPATH=/home/conon/cube/lprfax/test make -e all
	mv prefilter test
	mv filter test

clean:
	rm -f printcap.host printcap.remote

install:
	@echo -e "\n\nTo install you must use either install-remote or "\
	"install-host targets\n\n"

uninstall:
	@echo -e "\n\nTo uninstall you must use either uninstall-remote or "\
	"uninstall-host targets\n\n"

install-host: all-host
	install -d -g root -m 0755 -o root ${FILTERPATH}
	install -g root -m 0755 -o root filter ${FILTERPATH}/filter
	install -g root -m 0755 -o root prefilter ${FILTERPATH}/prefilter
	install -g root -m 0755 -o root lprfax ${FILTERPATH}/lprfax
	install -d -g root bin -m 0755 -o root ${LIBPATH}
	install -g root -m 0755 -o root make.coverpg  ${LIBPATH}/make.coverpg

uninstall-host:
	rm -f ${FILTERPATH}/filter ${FILTERPATH}/prefilter ${FILTERPATH}/lprfax \
	 ${LIBPATH}/make.coverpg
	echo " You will have to remove the printcap entry by hand"

install-remote: all-remote
	install -d -g lp -m 0755 -o lp ${FILTERPATH}
	install -g lp -m 0755 -o lp prefilter ${FILTERPATH}/prefilter
	install -g lp -m 0755 -o lp lprfax ${FILTERPATH}/lprfax
	install -d -g bin -m 0755 -o bin ${LIBPATH}
	install -g bin -m 0755 -o bin make.coverpg  ${LIBPATH}/make.coverpg

uninstall-remote:
	rm -f ${FILTERPATH}/prefilt ${FILTERPATH}/lprfax ${LIBPATH}/make.coverpg
	echo " You will have to remove the printcap entry by hand"

filter: filter.in
	sed -n -e "{\
	s\\%FILTERPATH%\\${FILTERPATH}\\g ;\
	s\\%LIBPATH%\\${LIBPATH}\\g ;\
	p ;}" filter.in |cat -s >> filter
	chmod 755 filter

prefilter: prefilter.in
	sed -n -e "{\
	s\\%FILTERPATH%\\${FILTERPATH}\\g ;\
	s\\%LIBPATH%\\${LIBPATH}\\g ;\
	p ;}" prefilter.in |cat -s >> prefilter
	chmod 755 prefilter
