# Usage:
# Validate and process all the lg*.xml files in the current directory that are newer than the corresponding html
#   make
# Build one file if it needs to be updated (useful if several files need updating but you only want to rebuild this file)
#   make lg180-A.html
# Rebuild one file even if it is already up to date
#   make -B lg180-A.html
# Make a backup of the xml files (backup is a tar.gz file with today's date)
#   make backup
# The default css stylesheet can be changed like this:
#  make css=../gazette.css


# Where docbook.xsl resides on your system (change this variable accordingly).
xsldir=/usr/share/xml/docbook/stylesheet/docbook-xsl/xhtml

# Transformation stylesheet to use to convert the documents.
style=gazette.xsl
#style=$(xsldir)/docbook.xsl
#style=$(xsldir)/changebars.xsl

# CSS to use to render the HTML documents.
css=http://ftp.traduc.org/projets/gazette-linux/outils-docbook/gazette.css




# Collect the xml files to process.
SOURCE=$(wildcard lg*.xml)
TARGET=$(patsubst %.xml,%.html,$(SOURCE))

# First rule is the one taken into account when make is ran without arguments.
# It rebuild all the files listed in $(TARGET).
all: $(TARGET)

#CATALOG=XML_CATALOG_FILES="gazette.xml"
ARGS=--path "$(xsldir)"
ARGS+=--stringparam html.stylesheet $(css)

# Default rule tells how to make a html document out of a xml file.
%.html: %.xml $(style)
	xmllint --nonet --valid --noout $<
	xsltproc $(ARGS) "$(style)" $< > $@

# This example demonstrates how to use a custom build for a specific file. In
# this case, it adds xinclude.
# It is not recommended to use custom build for the sake of the coordinator building the final article.
#lg181-D.html: lg181-D.xml $(style)
#	xmllint --nonet --postvalid -xinclude --noout $<
#	xsltproc $(ARGS) --xinclude "$(style)" $< > $@

# This example disables the table of content
#lg180-B.html: lg180-B.xml $(style)
#	xmllint --nonet --valid --noout $<
#	xsltproc $(ARGS) --stringparam generate.toc nop "$(style)" $< > $@

# Make a backup of all the xml files and support files.
backup:
	tar -jcf lg-$(shell date "+%Y%m%d%H%M").tar.bz2 lg*.xml Makefile gazette.css gazette.xsl

