VERSION=$(shell awk '/Version/ { print $$2 }' rhs-printfilters.spec)
CVSTAG = r$(subst .,-,$(VERSION))
CVSROOT = $(shell /bin/cat CVS/Root)

PREFIX = $(INSTALL_DIR)/usr
BINDIR = $(PREFIX)/bin
FILTERDIR = $(INSTALL_DIR)/usr/lib/rhs/rhs-printfilters/

BINOWN = root
BINGRP = root

INSTALLBIN = install -o $(BINOWN) -g $(BINGRP) -m 755
INSTALLDATA = install -o $(BINOWN) -g $(BINGRP) -m 644

RM = rm -f
LN = ln -s

FILTERS = master-filter \
	  asc-to-printer.fpi  ps-to-printer.fpi \
	  rpm-to-asc.fpi ppaprint smbprint ncpprint directprint \
	  asc-to-ps.fpi

FILTERDATA = general.cfg.in postscript.cfg.in textonly.cfg.in printerdb \
	     testpage.asc testpage.ps testpage-a4.ps

#OTHER = filter-template

all: testpage.ps testpage-a4.ps

testpage.ps:
	fig2dev -Lps -zLetter testpage.fig testpage.ps

testpage-a4.ps:
	fig2dev -Lps -zA4 testpage-a4.fig testpage-a4.ps

rewindstdin: rewindstdin.c
	cc -o rewindstdin rewindstdin.c

install: all
	mkdir -p $(FILTERDIR)

# should only really copy MINIMUM filters, rest should come from RPMs
	for i in $(FILTERS) ; do \
		$(INSTALLBIN) $$i $(FILTERDIR); \
	done

	for i in $(FILTERDATA) ; do \
		$(INSTALLDATA) $$i $(FILTERDIR); \
	done

#	$(INSTALLBIN) rewindstdin $(FILTERDIR)

clean:
	rm -f *.a *.o core errs *~ \#* TAGS *.E a.out errors rewindstdin
	rm -f testpage.ps testpage-a4.ps

archive:
	@cvs tag -F $(CVSTAG) .
	@rm -rf /tmp/rhs-printfilters-$(VERSION) /tmp/rhs-printfilters
	@cd /tmp; cvs -d $(CVSROOT) export -r$(CVSTAG) rhs-printfilters || :
	@mv /tmp/rhs-printfilters /tmp/rhs-printfilters-$(VERSION)
	@dir=$$PWD; cd /tmp; tar cvzf $$dir/rhs-printfilters-$(VERSION).tar.gz rhs-printfilters-$(VERSION)
	@rm -rf /tmp/rhs-printfilters-$(VERSION)
	@echo "The archive is in rhs-printfilters-$(VERSION).tar.gz"
