# @configure_input@

# info about where we are
buildir=@builddir@
abs_builddir=@abs_builddir@
top_builddir=@top_builddir@
srcdir=@srcdir@
abs_srcdir=@abs_srcdir@
top_srcdir=@top_srcdir@
abs_top_srcdir=@abs_top_srcdir@
datarootdir=@datarootdir@

# install stuff
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
datadir=@datadir@
mandir=@mandir@
includedir=@includedir@
infodir=@infodir@
libdir=@libdir@
libexecdir=@libexecdir@
localstatedir=@localstatedir@
oldincludedir=@oldincludedir@
sbindir=@sbindir@
sharedstatedir=@sharedstatedir@
sysconfdir=@sysconfdir@

PDF_CMD=@PDF_CMD@
XMLTO_CMD=@XMLTO_CMD@
PDF_CMD_OPTS=-P latex.class.options=letterpaper,11pt,twoside,openright
XMLTO_CMD_OPTS=
INSTALL=@INSTALL@
INSTALL_DATA=$(INSTALL) -D -m 0644
INSTALL_DIR=$(INSTALL) -d

# for pkgwrite
DESTDIR=
MANDIR=@mandir@
DATADIR=@datadir@

##########
# Targets
##########
MANUALS=LTSPManual
MANPAGES=lts.conf

##########
# Sources
##########
LTSPManual_SRC=LTSPManual.xml
MAN5=lts.conf.5 # config files - refsects in docbook
MAN8= # system commands

# man pages aren't working yet
all: pdfs html man

#########################################
# Do Not Edit Below This Line:
# (unless you know what you're doing...)
#########################################
.SECONDEXPANSION:

pdfs: $(addsuffix .pdf, $(MANUALS))
html: $(addsuffix .html, $(MANUALS))
# txt: $(addsuffix .txt, $(MANUALS))

# man pages
man: $(MAN5) $(MAN8)

%.pdf: $$($$*_SRC)
	@echo "building $@...."
	@$(PDF_CMD) $(PDF_CMD_OPTS) ${@:.pdf=.xml}

%.html: $$($$*_SRC)
	@echo "Building $@...."
	@$(XMLTO_CMD) html-nochunks $(XML_CMD_OPTS) $(@:.html=.xml)

$(MAN5) $(MAN8): $(MAN5:.5=.xml) $(MAN8:.8=.xml)
	@echo "building man pages"
	@echo "$(addsuffix .xml, $(MANPAGES))" | xargs -n1 $(XMLTO_CMD) man $(DOC_CMD_OPTS)

# %.txt: $$($$*_SRC)
# 	@echo "building $@...."
# 	@$(XMLTO_CMD) txt $(XMLTO_CMD_OPTS) $(@:.txt=.xml)

none:

install: all
	$(INSTALL_DIR) $(DESTDIR)$(MANDIR)/man5
	$(INSTALL_DATA) $(MAN5) $(DESTDIR)$(MANDIR)/man5/
	$(INSTALL_DIR)	$(DESTDIR)$(datadir)/doc/ltsp
	$(INSTALL_DATA) *.pdf $(DESTDIR)$(datadir)/doc/ltsp/.
	$(INSTALL_DATA) *.html $(DESTDIR)$(datadir)/doc/ltsp/
	$(INSTALL_DIR)	$(DESTDIR)$(datadir)/gnome/help/ltsp/C
	$(INSTALL_DATA) *.xml $(DESTDIR)$(datadir)/gnome/help/ltsp/C/
	$(INSTALL_DIR)	$(DESTDIR)$(datadir)/omf/ltsp
	$(INSTALL_DATA) *.omf $(DESTDIR)$(datadir)/omf/ltsp/

clean:
	@bash -c "rm -f *.{5,8,html,doc,pdf,txt,rtf,links,refs,tex,aux}"
	#@bash -c "rm -f ../*.{5,8,html,doc,pdf,txt,rtf}"
	@bash -c "rm -f ../*.pdf"
	@bash -c "rm -rf $(MANUALS)"
	@bash -c "rm -f config.log config.status"

yelp:
	@bash -c "yelp file:///`pwd`/LTSPManual.xml"

distclean: clean
	@bash -c "rm -rf autom4te.cache Makefile config.status config.log"
