source: trunk/doc-new/Makefile @ 57849

Last change on this file since 57849 was 48743, checked in by raimue@…, 12 years ago

guide:
Provide a small tab in the upper right corner to switch between the single page
and the chunked version of the guide. Build both versions by default.

  • Property svn:keywords set to Id
File size: 4.0 KB
RevLine 
[29265]1# $Id: Makefile 48743 2009-03-28 02:55:10Z raimue@macports.org $
[32197]2
[40917]3# Makefile to generate the MacPorts HTML guide and the man pages.
[38335]4# The ports 'docbook-xsl', 'docbook-xml' and 'libxslt' have to be installed.
[29265]5
[40917]6# If your MacPorts isn't installed in /opt/local you have to change PREFIX
[38335]7# here.
[29265]8
[38335]9
[40917]10# Prefix of the MacPorts installation.
[32197]11PREFIX = /opt/local
[29265]12
[38335]13# Command abstraction variables.
[32197]14MKDIR    = /bin/mkdir
15CP       = /bin/cp
16RM       = /bin/rm
[40917]17LN       = /bin/ln
[32197]18SED      = /usr/bin/sed
[38342]19TCLSH    = /usr/bin/tclsh
[32166]20XSLTPROC = $(PREFIX)/bin/xsltproc
[32902]21XMLLINT  = $(PREFIX)/bin/xmllint
[32166]22
[38335]23# Data directories.
[32197]24GUIDE = guide
25MAN   = man
[38335]26# Source directories.
[40918]27GUIDE_SRC = $(GUIDE)/xml
28MAN_SRC   = $(MAN)/xml
[38335]29# Result directories.
[40918]30GUIDE_RESULT       = $(GUIDE)/html
31GUIDE_RESULT_CHUNK = $(GUIDE_RESULT)/chunked
32MAN_RESULT         = $(MAN)/man/
[38335]33# Man temporary directory.
[40918]34MAN_TMP = $(MAN)/tmp
[29265]35
[40917]36# Path to the DocBook XSL files.
[38342]37DOCBOOK         = $(PREFIX)/share/xsl/docbook-xsl
[40918]38GUIDE_XSL       = $(GUIDE)/resources/single-page.xsl
39GUIDE_XSL_CHUNK = $(GUIDE)/resources/chunk.xsl
40MAN_XSL         = $(MAN)/resources/macports.xsl
[29265]41
[40917]42# DocBook HTML stylesheet for the guide.
[32197]43STYLESHEET = docbook.css
[29265]44
[48743]45.PHONY: all guide guide-chunked man clean validate
[29265]46
[48743]47all: guide guide-chunked man
[29265]48
[40918]49# Generate the HTML guide using DocBook from the XML sources in $(GUIDE_SRC).
[29265]50guide:
[40918]51        $(MKDIR) -p $(GUIDE_RESULT)
52        $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE_RESULT)/$(STYLESHEET)
53        $(CP) $(GUIDE)/resources/images/* $(GUIDE_RESULT)/
[38441]54        $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
55        $(XSLTPROC) --xinclude \
[40918]56            --output $(GUIDE_RESULT)/index.html \
57            $(GUIDE_XSL) $(GUIDE_SRC)/guide.xml
[35199]58        # Convert all sections (h1-h9) to a link so it's easy to link to them.
59        # If someone knows a better way to do this please change it.
60        $(SED) -i "" -E \
61            's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
[40918]62            $(GUIDE_RESULT)/index.html
[29265]63
[40917]64# Generate the chunked HTML guide with one section per file.
[38342]65guide-chunked:
[40918]66        $(MKDIR) -p $(GUIDE_RESULT_CHUNK)
67        $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE_RESULT_CHUNK)/$(STYLESHEET)
68        $(CP) $(GUIDE)/resources/images/* $(GUIDE_RESULT_CHUNK)/
[38441]69        $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
70        $(XSLTPROC) --xinclude \
[40918]71            --output $(GUIDE_RESULT_CHUNK)/index.html \
72            $(GUIDE_XSL_CHUNK) $(GUIDE_SRC)/guide.xml
[38342]73        # Convert all sections (h1-h9) to a link so it's easy to link to them.
74        # If someone knows a better way to do this please change it.
75        $(SED) -i "" -E \
76            's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
[40918]77            $(GUIDE_RESULT_CHUNK)/*.html
[40917]78        # Add the table of contents to every junked HTML file.
[38342]79        # If someone knows a better way to do this please change it.
[40918]80        $(TCLSH) toc-for-chunked.tcl $(GUIDE_RESULT_CHUNK)
[38342]81
82
[40918]83# Generate the man pages using DocBook from the XML source in $(MAN_SRC).
84# The portfile-*.xml and portgroup-*.xml files in $(GUIDE_SRC) are copied to
85# $(MAN_TMP) and modified (section -> refsection) so they can be used as man
86# XML source files and then xincluded in the real man XML files in $(MAN_SRC).
87man: $(MAN_XSL)
88        $(MKDIR) -p $(MAN_RESULT)
89        $(MKDIR) -p $(MAN_TMP)
90        $(CP) $(GUIDE_SRC)/portfile-*.xml $(MAN_TMP)
91        $(CP) $(GUIDE_SRC)/portgroup-*.xml $(MAN_TMP)
92        $(SED) -i "" 's|<section|<refsection|g' $(MAN_TMP)/*
93        $(SED) -i "" 's|</section>|</refsection>|g' $(MAN_TMP)/*
94        $(XSLTPROC) --xinclude --output $(MAN_RESULT) $(MAN_XSL) \
95            $(MAN_SRC)/port.1.xml \
96            $(MAN_SRC)/portfile.7.xml \
97            $(MAN_SRC)/portgroup.7.xml \
98            $(MAN_SRC)/porthier.7.xml
99        $(RM) -r $(MAN_TMP)
[29265]100
[38335]101# Create XSL from template for man pages.
[40918]102$(MAN_XSL):
[38034]103        $(SED) 's:@PREFIX@:$(PREFIX):' $@.in > $@
104
[32812]105# Remove all temporary files generated by guide: and man:.
[29265]106clean:
[38441]107        $(RM) -rf $(GUIDE)/resources/xsl
[40918]108        $(RM) -rf $(GUIDE_RESULT)
109        $(RM) -rf $(MAN_RESULT)
110        $(RM) -rf $(MAN_TMP)
111        $(RM) -rf $(MAN_XSL)
[32902]112        $(RM) -f  guide.tmp.xml
113
[40917]114# Validate the XML files for the guide.
[32902]115# These two steps are necessary as otherwise xmllint complains about missing
116# ids.
117validate:
[40918]118        $(XMLLINT) --xinclude $(GUIDE_SRC)/guide.xml > guide.tmp.xml
[32902]119        $(XMLLINT) --loaddtd --valid --noout guide.tmp.xml
Note: See TracBrowser for help on using the repository browser.