Makefile to turn Docbook-XML into HTML or PDF

From Stack Overflow
Jump to: navigation, search
# Makefile for converting a Docbook-XML file into an HTML or PDF document.
# (C) Copyright 2004, Brian Enigma <enigma@netninja.com>
# Licensed under the Creative Commons Attribution-ShareAlike License
# (http://creativecommons.org/licenses/by-sa/2.0/)

# Change these to reflect your input/output files
INFILE=How_to_make_updates.xml
OUTFILE_HTML=How_to_make_updates.html
TEMP_FO=How_to_make_updates.fo
OUTFILE_PDF=How_to_make_updates.pdf

# You should not need to change these unless you are using a newer version
# of something or have moved the download location
DOWNLOAD_XSL=http://10.1.1.1/docbook-xsl-1.65.1.tar.gz
DOWNLOAD_FOP=http://10.1.1.1/fop-0.20.5-bin.tar.gz

XSL_ARCHIVE=docbook-xsl-1.65.1.tar.gz
FOP_ARCHIVE=fop-0.20.5-bin.tar.gz

XSL_FOLDER=docbook-xsl-1.65.1
FOP_FOLDER=fop-0.20.5

# Build rules

.PHONY: help
help:
	@echo "The supported output formats are:"
	@echo " make html"
	@echo " make pdf"

.PHONY: clean
clean:
	rm -rf $(XSL_FOLDER) $(FOP_FOLDER)
	rm -f $(XSL_ARCHIVE) $(FOP_ARCHIVE) $(OUTFILE_HTML) $(OUTFILE_PDF) $(TEMP_FO)

html: $(OUTFILE_HTML)

$(OUTFILE_HTML): $(INFILE) $(XSL_FOLDER) .checkxsl
	@echo ""
	@echo "#####"
	@echo "# Building HTML document version"
	@echo "#####"
	@echo ""
	xsltproc $(XSL_FOLDER)/html/docbook.xsl $(INFILE) > $(OUTFILE_HTML)

pdf: $(OUTFILE_PDF)

$(OUTFILE_PDF): $(TEMP_FO)
	@echo ""
	@echo "#####"
	@echo "# Building PDF document version"
	@echo "#####"
	@echo ""
	./$(FOP_FOLDER)/fop.sh $(TEMP_FO) $(OUTFILE_PDF)

$(TEMP_FO): $(INFILE) $(XSL_FOLDER) $(FOP_FOLDER) .checkxsl
	@echo ""
	@echo "#####"
	@echo "# Building temporary XML-FO version"
	@echo "#####"
	@echo ""
	xsltproc $(XSL_FOLDER)/fo/docbook.xsl $(INFILE) > $(TEMP_FO)

$(XSL_FOLDER): $(XSL_ARCHIVE)
	@echo ""
	@echo "#####"
	@echo "# Extracting dependency"
	@echo "#####"
	@echo ""
	tar -zxf $(XSL_ARCHIVE)
	touch $(XSL_FOLDER)

$(FOP_FOLDER): $(FOP_ARCHIVE)
	@echo ""
	@echo "#####"
	@echo "# Extracting dependency"
	@echo "#####"
	@echo ""
	tar -zxf $(FOP_ARCHIVE)
	touch $(FOP_FOLDER)

$(XSL_ARCHIVE): .wgetcheck
	@echo ""
	@echo "#####"
	@echo "# Downloading Docbook-XSL dependency"
	@echo "#####"
	@echo ""
	wget -O $(XSL_ARCHIVE) $(DOWNLOAD_XSL)
	touch $(XSL_ARCHIVE)

$(FOP_ARCHIVE): .wgetcheck
	@echo ""
	@echo "#####"
	@echo "# Downloading XSL-FO dependency"
	@echo "#####"
	@echo ""
	wget -O $(FOP_ARCHIVE) $(DOWNLOAD_FOP)
	touch $(FOP_ARCHIVE)

# Dependency check rules

.wgetcheck:
	@CHECKPATH=`which wget`; \
	if [ "$$CHECKPATH" == "" ]; then \
		echo ""; \
		echo ""; \
		echo "You need the 'wget' command installed"; \
		echo "(This is a standard RedHat and Cygwin utility)"; \
		echo ""; \
		exit 1; \
	fi
	@echo "Good.  It looks like you have 'wget' installed"
	@touch .wgetcheck

.checkxsl:
	@CHECKPATH=`which xsltproc`; \
	if [ "$$CHECKPATH" == "" ]; then \
		echo ""; \
		echo ""; \
		echo "You need the 'xsltproc' command installed"; \
		echo "(This is part of libxml and should be a standard RedHat and Cygwin)"; \
		echo ""; \
		exit 1; \
	fi
	@echo "Good.  It looks like you have 'wget' installed"
	@touch .checkxsl

Personal tools