source: trunk/doc-new/Makefile @ 136298

Last change on this file since 136298 was 120885, checked in by cal@…, 6 years ago

guide: new, more macports-y layout to replace the somewhat oldstyle layout of the guide

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