# Makefile to install pcd2html
PACKAGE=pcd2html
VERSION=0.5.1.1

FILES_TO_SAVE=Makefile \
	      README.pcd2html \
	      COPYING \
	      INSTALL \
	      News \
	      Bugs \
	      Makefile.pcd2html \
	      empty.xpm \
	      home.xpm home.png \
	      pcd2html_create_makefile \
	      pcd2html_create_html \
	      pcd2html_create_index \
	      pcd2html_create_jpg \
	      pcd2html_uti.pm \
	      pcd2html.conf \
	      pcd2html \
	      pcd.css \
	      pcd2html.1 \
	      pcd2html.html \
	      img \
	      examples \
	      ChangeLog

prefix = /usr/local

bindir = ${prefix}/bin
datadir = ${prefix}/share/pcd2html
mandir = ${prefix}/man/man1
sysconfdir = ${prefix}/etc
perllibdir = ${prefix}/share/perl5

preparedir=prepare

INSTALL = /usr/bin/install -p
INSTALL_DATA = ${INSTALL} -m 644
GZIP = --best

all: prepare

dist:
	rm -rf $(PACKAGE)-$(VERSION)
	mkdir $(PACKAGE)-$(VERSION)
	cp -a $(FILES_TO_SAVE) $(PACKAGE)-$(VERSION)
	GZIP=-9 tar -czf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)

prepare:
	mkdir -p $(preparedir)
	@sed "s?\$${datadir}?${datadir}?g" pcd2html > $(preparedir)/pcd2html
	@touch -r pcd2html $(preparedir)/pcd2html
	@sed "s?\$${sysconfdir}?${sysconfdir}?g" pcd2html_create_makefile | sed "s?\$${datadir}?${datadir}?g" > $(preparedir)/pcd2html_create_makefile
	@touch -r pcd2html_create_makefile $(preparedir)/pcd2html_create_makefile
	@sed "s?\$${datadir}?${datadir}?g" pcd2html_create_index > $(preparedir)/pcd2html_create_index
	@touch -r pcd2html_create_index $(preparedir)/pcd2html_create_index
	@sed "s?\$${datadir}?${datadir}?g" pcd2html_create_html > $(preparedir)/pcd2html_create_html
	@touch -r pcd2html_create_html $(preparedir)/pcd2html_create_html
	@sed "s?\$${datadir}?${datadir}?g" pcd2html_create_jpg > $(preparedir)/pcd2html_create_jpg
	@touch -r pcd2html_create_jpg $(preparedir)/pcd2html_create_jpg

install: prepare
	@${INSTALL} -d ${bindir}
	@${INSTALL} $(preparedir)/pcd2html ${bindir}/pcd2html
	@${INSTALL} -d ${datadir}
	@$(INSTALL) $(preparedir)/pcd2html_create_makefile ${datadir}
	@$(INSTALL) $(preparedir)/pcd2html_create_index ${datadir}
	@$(INSTALL) $(preparedir)/pcd2html_create_html ${datadir}
	@$(INSTALL) $(preparedir)/pcd2html_create_jpg ${datadir}
	@$(INSTALL_DATA) empty.xpm ${datadir}
	@$(INSTALL_DATA) img/*.png ${datadir}
	@$(INSTALL_DATA) home.png ${datadir}
	@${INSTALL} -d ${perllibdir}
	${INSTALL_DATA} pcd2html_uti.pm ${perllibdir}
	@${INSTALL_DATA} Makefile.pcd2html ${datadir}/Makefile
	@${INSTALL_DATA} pcd.css ${datadir}
	@${INSTALL} -d ${sysconfdir}
	@${INSTALL_DATA} pcd2html.conf ${sysconfdir}
	@${INSTALL} -d ${mandir}
	@${INSTALL_DATA} pcd2html.1 ${mandir}
	@echo pcd2html successfully installed in ${datadir}

clean:
	@rm -rf *~ core
	@rm -rf $(preparedir)
