# Makefile for p4delta (http://p4delta.sourceforge.net)

PACKAGE       = p4delta
VERSION       = 1.3.2
PKG_VER       = ${PACKAGE}-$(VERSION}
DIST_SOURCES  = p4delta.ps p4delta.pdf p4delta.1 p4delta Makefile ChangeLog
INSTALL       = /usr/bin/install -c
PREFIX       ?= /usr

distdir       = ${PACKAGE}-${VERSION}
srcdir        = .

TAR           = gtar
GZIP_ENV      = --best

SOURCE_FILES  = \
Makefile \
bin/rbsto1 \
log.rb \
file.rb \
filetest.rb \
p4delta.rb \
p4deltahelp.rb \
p4deltaopt.rb \
p4deltarun.rb \
p4ignore.rb \
progmet.rb \
regexp.rb

DISTFILES     = $(SOURCE_FILES) p4delta p4delta.1 p4delta.pod Makefile

all: p4delta.1

docs: p4delta.ps p4delta.pdf p4delta.1 p4delta.html

p4delta.ps: p4delta.dvi
	dvips -o $@ $^

p4delta.pdf: p4delta.ps
	ps2pdf $^ $@

p4delta.dvi: p4delta.tex
	latex $^

p4delta.tex: p4delta.pod
	pod2latex -full $^

p4delta.1: p4delta.pod
	pod2man --release "${PACKAGE} ${VERSION}" \
		--center "${PACKAGE} ${VERSION}" \
		$^ > $@

p4delta.html: p4delta.pod
	pod2html $^ > $@

dist: $(distdir)
	-chmod -R a+r $(distdir)
	GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
	-rm -rf $(distdir)

$(distdir): 
	rm -rf $(distdir)
	mkdir $(distdir)
	mkdir $(distdir)/bin
	-chmod 777 $(distdir)
	-chmod 777 $(distdir)/bin
	distdir=`cd $(distdir) && pwd`; \
	cd $(top_srcdir)
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$d/$$file $(distdir)/$$file; \
	  else \
	    test -f $(distdir)/$$file \
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
	  fi; \
	done

install: p4delta.1
	${INSTALL} p4delta $(PREFIX)/bin
	${INSTALL} p4delta.1 $(PREFIX)/man/man1

uninstall: p4delta.1
	rm -f $(PREFIX)/bin/p4delta
	rm -f $(PREFIX)/man/man1/p4delta.1

clean:
	rm -f p4delta.ps p4delta.pdf p4delta.1 p4delta.dvi p4delta.tex

# Builds the real p4delta from its modules. Not for external use.

complete: p4delta p4delta.1

p4delta: $(SOURCE_FILES)
	./bin/rbsto1 p4deltarun.rb > $@
