# Generates online and print versions of SGML source file.

BASENAME=oppgave
WEB_FOLDER=/home/niklas/public_html/hovedfag

# Inpnut files
XML_DEPENDENCIES=introduction.xml methods.xml diskusjon.xml konklusjon.xml references.xml 
XML_FILE=$(BASENAME).xml

# Dependencies
JAVA=/usr/local/linux-jdk1.4.0/bin/java
XSL_ROOT=/usr/local/share/xsl

CLASS=com.jclark.xsl.sax.Driver
FO_CLASS=org.apache.fop.apps.Fop

XSLPROC=/usr/local/bin/xsltproc
FOPARAMS=generate.toc \'book/chapter\ nop\'
HTMLPARAMS=\
--param section.autolabel 1 \
--param chapter.autolabel 1 \
--param toc.section.depth 2 \
--param section.label.includes.component.label 1 
#--param generate.toc \'chapter\ nop\' 


CUSTOM_HTML_XSL=custom.xsl
HTML_XSL=$(XSL_ROOT)/docbook/xhtml/docbook.xsl
FO_XSL=$(XSL_ROOT)/docbook/fo/docbook.xsl

CP=cp

INDENT=/usr/local/bin/xmlindent

# Generated files.
HTML_FILE=index.html
HTM_FILE=$(BASENAME).htm
PDF_FILE=$(BASENAME).pdf
PS_FILE=$(BASENAME).ps
FO_FILE=$(BASENAME).fo

# Override default values
#.include "make.conf"

# Build rules.

all: validate html htm pdf ps

html: $(HTML_FILE)

htm: $(HTM_FILE)

pdf: $(PDF_FILE)

ps: $(PS_FILE)

clean:
	rm -f $(BASENAME).{htm,pdf,fo,ps}
	rm -f *.html

publish: publish_html publish_pdf publish_ps

publish_html: html 
	$(CP) $(HTML_FILE) $(WEB_FOLDER)/thesis.html
	$(CP) $(HTML_FILE) $(WEB_FOLDER)/thesis-utf8.html
	$(CP) figures/*.png $(WEB_FOLDER)/figures
	$(CP) figures/*.gif $(WEB_FOLDER)/figures
	chmod a+w $(WEB_FOLDER)/thesis.html
	lynx -dump http://niklas.saers.com/hovedfag/wrap.php?file=thesis.html > /dev/null
	chmod og-w $(WEB_FOLDER)/thesis.html
	tar cvfz $(WEB_FOLDER)/xml.tar.gz *.xml Makefile

publish_pdf: pdf
	$(CP) $(PDF_FILE) $(WEB_FOLDER)

publish_ps: ps
	$(CP) $(PS_FILE) $(WEB_FOLDER)

distclean: clean
	rm -f $(BASENAME).tgz

package: all
	rm -f $(BASENAME).tgz
	tar -C .. -czf /tmp/$(BASENAME).tgz $(BASENAME)
	mv /tmp/$(BASENAME).tgz .

validate: $(XML_DEPENDENCIES)
	export SGML_CATALOG_FILES=/usr/local/share/sgml/catalog:/usr/local/share/xml/catalog
	xmllint --noout $(BASENAME).xml

dist: clean package

distall: all package


# Compile rules.

$(XML_FILE): validate

$(HTML_FILE): $(XML_FILE)
	$(XSLPROC) --catalogs $(CUSTOM_HTML_XSL) $(XML_FILE) >  $(HTML_FILE)

$(HTM_FILE): $(XML_FILE)
	$(XSLPROC) --catalogs $(CUSTOM_HTML_XSL) $(XML_FILE) >  $(HTM_FILE)

$(FO_FILE): $(XML_FILE)
	$(XSLPROC) --param $(FOPARAMS) --catalogs $(FO_XSL) $(XML_FILE) >  $(FO_FILE)

$(PDF_FILE): $(FO_FILE)
	$(JAVA) $(FO_CLASS) $(FO_FILE) -pdf $(PDF_FILE)

$(PS_FILE): $(FO_FILE)
	$(JAVA) $(FO_CLASS) $(FO_FILE) -ps $(PS_FILE)

metodikk: validate
	$(XSLPROC) $(HTMLPARAMS) --catalogs $(HTML_XSL) metodikk.xml >  freebsd-model.html
	$(CP) freebsd-model.html $(WEB_FOLDER)
	chmod a+w $(WEB_FOLDER)/freebsd-model.html
	lynx -dump http://niklas.saers.com/hovedfag/wrap.php?file=freebsd-model.html > /dev/null
	chmod og-w $(WEB_FOLDER)/freebsd-model.html
	mv $(WEB_FOLDER)/freebsd-model.html $(WEB_FOLDER)/../freebsd-model/freebsd-model.html
	cp model.xml $(WEB_FOLDER)/../freebsd-model/
	cp metodikk.xml $(WEB_FOLDER)/../freebsd-model/
	cp modelrefs.xml $(WEB_FOLDER)/../freebsd-model/

sense: 
	echo "The semantics are up for you to do your work."

indent: validate
	$(INDENT) -i 2 -w administrative.xml
	$(INDENT) -i 2 -w appendix.xml
	$(INDENT) -i 2 -w development_model.xml
	$(INDENT) -i 2 -w diskusjon.xml
	$(INDENT) -i 2 -w introduction.xml
	$(INDENT) -i 2 -w konklusjon.xml
	$(INDENT) -i 2 -w methods.xml
	$(INDENT) -i 2 -w metodikk.xml
	$(INDENT) -i 2 -w model.xml
	$(INDENT) -i 2 -w modelrefs.xml
	$(INDENT) -i 2 -w oppgave.xml
	$(INDENT) -i 2 -w org_structure.xml
	$(INDENT) -i 2 -w references.xml
	$(INDENT) -i 2 -w theory.xml
