source: trunk/doc-new/Makefile @ 94363

Last change on this file since 94363 was 94337, checked in by cal@…, 8 years ago

doc-new: Add Makefile rules to generate guide in PDF form using dblatex, closes #31692

I'm also adding guide-dblatex to all, since trunk/base/portmgr/jobs/GuideRegen.sh explicity
specifies "make guide" and "make guide-chunked", so it won't be affected.

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