# $Id: Makefile 38441 2008-07-20 16:12:27Z raimue@macports.org $
# Makefile to generate the macports html guide and the man pages.
# The ports 'docbook-xsl', 'docbook-xml' and 'libxslt' have to be installed.
# If your macports isn't installed in /opt/local you have to change PREFIX
# here.
# Prefix of the macports installation.
PREFIX = /opt/local
# Command abstraction variables.
MKDIR = /bin/mkdir
CP = /bin/cp
RM = /bin/rm
LN = /bin/ln
SED = /usr/bin/sed
TCLSH = /usr/bin/tclsh
XSLTPROC = $(PREFIX)/bin/xsltproc
XMLLINT = $(PREFIX)/bin/xmllint
# Data directories.
GUIDE = guide
MAN = man
# Source directories.
GUIDE-SRC = $(GUIDE)/xml
MAN-SRC = $(MAN)/xml
# Result directories.
GUIDE-RESULT = $(GUIDE)/html
GUIDE-RESULT-CHUNK = $(GUIDE-RESULT)/chunked
MAN-RESULT = $(MAN)/man/
# Man temporary directory.
MAN-TMP = $(MAN)/tmp
# Path to the docbook xsl files.
DOCBOOK = $(PREFIX)/share/xsl/docbook-xsl
GUIDE-XSL = $(GUIDE)/resources/single-page.xsl
GUIDE-XSL-CHUNK = $(GUIDE)/resources/chunk.xsl
MAN-XSL = $(MAN)/resources/macports.xsl
# Docbook html stylesheet for the guide.
STYLESHEET = docbook.css
.PHONY: all guide man clean validate
all: guide man
# Generate the html guide using DocBook from the xml sources in $(GUIDE-SRC).
guide:
$(MKDIR) -p $(GUIDE-RESULT)
$(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE-RESULT)/$(STYLESHEET)
$(CP) $(GUIDE)/resources/images/* $(GUIDE-RESULT)/
$(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
$(XSLTPROC) --xinclude \
--output $(GUIDE-RESULT)/index.html \
$(GUIDE-XSL) $(GUIDE-SRC)/guide.xml
# Convert all sections (h1-h9) to a link so it's easy to link to them.
# If someone knows a better way to do this please change it.
$(SED) -i "" -E \
's|(]*>)([^<]*)()|\1\3\4|g' \
$(GUIDE-RESULT)/index.html
# Generate the chunked html guide with one section per file.
guide-chunked:
$(MKDIR) -p $(GUIDE-RESULT-CHUNK)
$(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE-RESULT-CHUNK)/$(STYLESHEET)
$(CP) $(GUIDE)/resources/images/* $(GUIDE-RESULT-CHUNK)/
$(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
$(XSLTPROC) --xinclude \
--output $(GUIDE-RESULT-CHUNK)/index.html \
$(GUIDE-XSL-CHUNK) $(GUIDE-SRC)/guide.xml
# Convert all sections (h1-h9) to a link so it's easy to link to them.
# If someone knows a better way to do this please change it.
$(SED) -i "" -E \
's|(]*>)([^<]*)()|\1\3\4|g' \
$(GUIDE-RESULT-CHUNK)/*.html
# Add the table of contents to every junked html file.
# If someone knows a better way to do this please change it.
$(TCLSH) toc-for-chunked.tcl $(GUIDE-RESULT-CHUNK)
# Generate the man pages using DocBook from the xml source in $(MAN-SRC).
# The portfile-*.xml and portgroup-*.xml files in $(GUIDE-SRC) are copied to
# $(MAN-TMP) and modified (section -> refsection) so they can be used as man
# xml source files and then xincluded in the real man xml files in $(MAN-SRC).
man: $(MAN-XSL)
$(MKDIR) -p $(MAN-RESULT)
$(MKDIR) -p $(MAN-TMP)
$(CP) $(GUIDE-SRC)/portfile-*.xml $(MAN-TMP)
$(CP) $(GUIDE-SRC)/portgroup-*.xml $(MAN-TMP)
$(SED) -i "" 's|||g' $(MAN-TMP)/*
$(XSLTPROC) --xinclude --output $(MAN-RESULT) $(MAN-XSL) \
$(MAN-SRC)/port.1.xml \
$(MAN-SRC)/portfile.7.xml \
$(MAN-SRC)/portgroup.7.xml \
$(MAN-SRC)/porthier.7.xml
$(RM) -r $(MAN-TMP)
# Create XSL from template for man pages.
$(MAN-XSL):
$(SED) 's:@PREFIX@:$(PREFIX):' $@.in > $@
# Remove all temporary files generated by guide: and man:.
clean:
$(RM) -rf $(GUIDE)/resources/xsl
$(RM) -rf $(GUIDE-RESULT)
$(RM) -rf $(MAN-RESULT)
$(RM) -rf $(MAN-TMP)
$(RM) -rf $(MAN-XSL)
$(RM) -f guide.tmp.xml
# Validate the xml files for the guide.
# These two steps are necessary as otherwise xmllint complains about missing
# ids.
validate:
$(XMLLINT) --xinclude $(GUIDE-SRC)/guide.xml > guide.tmp.xml
$(XMLLINT) --loaddtd --valid --noout guide.tmp.xml