# you may set this to empty in order to install the files
# non-locally.
LOCAL=local

USRDIR=/usr/$(LOCAL)

# directory for tbents.txt
TBLIBDIR= $(USRDIR)/share/xml/tbook

# directory for Info files
INFODIR= $(USRDIR)/share/info

# directory for MakeIndex style texi2latex.ist
MAKEINDEXDIR= $(USRDIR)/share/texmf/makeindex

# directory for the stylesheets
XSLTDIR= $(USRDIR)/share/xml/texi2latex

# destination directory for executables
DESTDIR= $(USRDIR)/bin

# Options for the C++ compiler
CXXFLAGS = -O2

# The standard file permissions for installed 
# non-executables
PERMS= a+r,u+w

# No changes should be necessary below this line 
# -----------------------------------------------------

CP= cp

.PHONY : all tbrplent clean install distri info

all : tbrplent texi2latex info

texi2latex : texi2latex.raw
	test -e $(DTDPATH)
	sed -e "s%DTD_PATH=/usr/share/texinfo%DTD_PATH=$(XSLTDIR)%; \
	        s%XSLT_PATH=/usr/local/share/xml/texi2latex/%XSLT_PATH=$(XSLTDIR)%" \
	  $< > $@

tbrplent info :
	$(MAKE) --directory=$@ ROOT=$(ROOT) INFODIR=$(INFODIR) \
	  PERMS=$(PERMS) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) \
	  TBLIBDIR=$(TBLIBDIR) XSLTDIR=$(XSLTDIR) \
	  CXXFLAGS=$(CXXFLAGS)

install : all
	install -d $(ROOT)$(DESTDIR)
	install texi2latex $(ROOT)$(DESTDIR)
	install -d $(ROOT)$(MAKEINDEXDIR)
	install --mode=$(PERMS) texi2latex.ist $(ROOT)$(MAKEINDEXDIR)
	$(MAKE) --directory=tbrplent install ROOT=$(ROOT) INFODIR=$(INFODIR) \
	  PERMS=$(PERMS) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) \
	  TBLIBDIR=$(TBLIBDIR) XSLTDIR=$(XSLTDIR) \
	  CXXFLAGS=$(CXXFLAGS)
	$(MAKE) --directory=info install ROOT=$(ROOT) INFODIR=$(INFODIR) \
	  PERMS=$(PERMS) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) \
	  TBLIBDIR=$(TBLIBDIR) XSLTDIR=$(XSLTDIR) \
	  CXXFLAGS=$(CXXFLAGS)
	$(MAKE) --directory=xslt install ROOT=$(ROOT) INFODIR=$(INFODIR) \
	  PERMS=$(PERMS) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) \
	  TBLIBDIR=$(TBLIBDIR) XSLTDIR=$(XSLTDIR) \
	  CXXFLAGS=$(CXXFLAGS)

clean :
	$(MAKE) --directory=tbrplent clean
	$(MAKE) --directory=info clean
	rm -f texi2latex

DISTRIBASENAME= texi2latex-0.9.4
DISTRINAME= $(DISTRIBASENAME)

distri :
	rm -Rf $(DISTRINAME)
	install -d $(DISTRINAME)/
	install -d $(DISTRINAME)/xslt/
	install -d $(DISTRINAME)/tbrplent/
	install -d $(DISTRINAME)/info/
	$(CP) -up Makefile TODO README COPYING texi2latex.ist texi2latex.raw \
	  $(DISTRINAME)/
	$(CP) -up xslt/{*.xsl,*.xml,*.dtd,Makefile} $(DISTRINAME)/xslt/
	$(CP) -up tbrplent/{*.w,*.cc,Makefile,tbents.txt} $(DISTRINAME)/tbrplent/
	$(CP) -up info/{texi2latex.texi,fdl.txt,Makefile} $(DISTRINAME)/info/
	tar -cjf $(DISTRINAME).tar.bz2 $(DISTRINAME)
