INSTALL=/usr/bin/install
INSTALLdir = $(INSTALL) -d
prefix=/usr/local/
datarootdir=$(prefix)/share/
mandir=$(datarootdir)/man
bindir=$(prefix)/bin
sysconfdir=/etc
progname=printipp
docdir=$(datarootdir)/doc/$(progname)
MANDIR = $(mandir)
DOCDIR = $(docdir)
HTMLDIR = $(docdir)/html
SHAREDLIBSDIR = $(datarootdir)/php/$(progname)
BINDIR = $(bindir)
BANNERDIR = $(datarootdir)/cups/banners
WWWDIR = $(datarootdir)/$(progname)/
WWWETC = $(sysconfdir)/apache2/sites-available
PHPINCLUDEDIR=/usr/share/php
documentation = \
	phpprintipp.html \
	attributes.html \
	readable-attributes.html \
	CupsPrintIPP-usage.html \
	usage.html \
	rc_example \
	install.html \
	cups-attributes.html

offdoc = AUTHORS NEWS README

bin = phpprintipp

manpages = documentation/phpprintipp.1

banners = \
	txtbanner \
	psbanner

wwwpages = \
	basicpage.php \
	advancedpage.php \
	printipp-logo.png

samplescripts = \
	test_cli.php \
	test_exceptions.php \
	TEST_PrintIPP.php

sampledata = \
	COPYING \
	photo.jpg \
	printipp-logo.ps \
	printipp-logo.svg \
	README \
	test.pdf \
	test-pdf.ps \
	test.png \
	test.ps \
	test.txt \
	test-utf8-compressed.txt.gz \
	test-utf8.txt

man_MANS = $(manpages)

all: mans etc_apache_phpprintipp
	

clean:

install: install-data-local

install-data-local: install-shared install-bin install-doc install-samples \
	install-banners install-wwwpages install-official


install-bin:
	$(INSTALLdir) $(BINDIR)
	for i in $(bin) ; do \
	$(INSTALL) -m 755 bin/$$i $(BINDIR)/$$i ;\
	done
	$(INSTALLdir) $(sysconfdir)/printipp

install-shared:
	$(INSTALLdir) $(SHAREDLIBSDIR)
	$(INSTALL) -m 644 php_classes/ExtendedPrintIPP.php \
	  $(SHAREDLIBSDIR)/ExtendedPrintIPP.php
	$(INSTALL) -m 644 php_classes/PrintIPP.php \
	  $(SHAREDLIBSDIR)/PrintIPP.php
	$(INSTALL) -m 644 php_classes/BasicIPP.php \
	  $(SHAREDLIBSDIR)/BasicIPP.php
	$(INSTALL) -m 644 php_classes/CupsPrintIPP.php \
	  $(SHAREDLIBSDIR)/CupsPrintIPP.php
	$(INSTALL) -m 644 php_classes/http_class.php \
	  $(SHAREDLIBSDIR)/http_class.php
	$(INSTALLdir) $(PHPINCLUDEDIR)
	test -r $(PHPINCLUDEDIR)/printipp || \
	  ln -s $(SHAREDLIBSDIR) $(PHPINCLUDEDIR)        

install-doc:
	$(INSTALLdir) $(HTMLDIR)
	for i in $(documentation) ; do \
		install -m 644 documentation/$$i $(HTMLDIR)/$$i ;\
	done

install-samples:
	$(INSTALLdir) $(DOCDIR)/samples
	for i in $(samplescripts) ; do \
	  if test -f testfiles/$$i ; then \
	    install -m 644 testfiles/$$i $(DOCDIR)/samples/$$i.src ;\
	  fi;\
	done
	for i in $(sampledata) ; do \
	  if test -f testfiles/$$i ; then \
	    install -m 644 testfiles/$$i $(DOCDIR)/samples/$$i ;\
	  fi;\
	done

install-official:
	$(INSTALLdir) $(DOCDIR)
	for i in $(offdoc) ; do \
	  if test -f $$i ; then \
	    install -m 644 $$i $(DOCDIR)/$$i ;\
	  fi;\
	done

install-wwwpages: etc_apache_phpprintipp
	$(INSTALLdir) $(WWWDIR)
	for i in $(wwwpages) ; do \
	  if test -f www/$$i ; then \
	    install -m 644 www/$$i $(WWWDIR)/$$i ;\
	  fi;\
	done
	cd $(WWWDIR) && rm -f index.php && ln -s advancedpage.php index.php
	$(INSTALLdir) $(WWWETC)
	$(INSTALL) -m 644 etc_apache_phpprintipp \
	  $(WWWETC)/phpprintipp
	$(INSTALLdir) $(sysconfdir)/printipp
	$(INSTALL) -m 644 www/www $(sysconfdir)/printipp/www \

install-banners:
	$(INSTALLdir) $(BANNERDIR)
	for i in $(banners) ; do \
	  if test -f banners/$$i ; then \
	    install -m 644 banners/$$i $(BANNERDIR)/$$i ;\
	  fi;\
	done

mans: documentation/phpprintipp.1

documentation/phpprintipp.1: documentation/phpprintipp-1.xml
	$(XSLTPROC) \
	"http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl" \
	$<

etc_apache_phpprintipp: www/etc_apache_phpprintipp
	sed -e 's,WWWDIR,$(WWWDIR),' www/etc_apache_phpprintipp > \
		etc_apache_phpprintipp
