source: trunk/doc-new/Makefile @ 114392

Last change on this file since 114392 was 105466, checked in by mk@…, 7 years ago

Guide: revert inadvertedly introduced change to Makefile

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1# $Id: Makefile 105466 2013-04-22 06:57:59Z mk@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)/
67ifeq ($(UNAME), Linux)
68        $(LN) -sfn $(DOCBOOK) $(GUIDE)/resources/xsl
69else
70        $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
71endif
72        $(XSLTPROC) --xinclude \
73            --output $(GUIDE_RESULT)/index.html \
74            $(GUIDE_XSL) $(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.
77ifeq ($(UNAME), Linux)
78        $(SED) -i -r -e \
79            's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
80            $(GUIDE_RESULT)/index.html
81else
82        $(SED) -i "" -E \
83            's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
84            $(GUIDE_RESULT)/index.html
85endif
86
87# Generate the chunked HTML guide with one section per file.
88guide-chunked:
89        $(MKDIR) -p $(GUIDE_RESULT_CHUNK)
90        $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE_RESULT_CHUNK)/$(STYLESHEET)
91        $(CP) $(GUIDE)/resources/images/* $(GUIDE_RESULT_CHUNK)/
92ifeq ($(UNAME), Linux)
93        $(LN) -sfn $(DOCBOOK) $(GUIDE)/resources/xsl
94else
95        $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
96endif
97        $(XSLTPROC) --xinclude \
98            --output $(GUIDE_RESULT_CHUNK)/index.html \
99            $(GUIDE_XSL_CHUNK) $(GUIDE_SRC)/guide.xml
100        # Convert all sections (h1-h9) to a link so it's easy to link to them.
101        # If someone knows a better way to do this please change it.
102ifeq ($(UNAME), Linux)
103        $(SED) -i -r -e \
104            's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
105            $(GUIDE_RESULT_CHUNK)/*.html
106else
107        $(SED) -i "" -E \
108            's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
109            $(GUIDE_RESULT_CHUNK)/*.html
110endif
111        # Add the table of contents to every junked HTML file.
112        # If someone knows a better way to do this please change it.
113        $(TCLSH) toc-for-chunked.tcl $(GUIDE_RESULT_CHUNK)
114
115# Generate the guide as a PDF.
116guide-dblatex: SUFFIX = pdf
117guide-dblatex:
118        $(MKDIR) -p $(GUIDE_RESULT_DBLATEX)
119        $(DBLATEX) \
120                --fig-path="$(GUIDE)/resources/images" \
121                --type="$(SUFFIX)" \
122                --param='toc.section.depth=2' \
123                --param='doc.section.depth=3' \
124                --output="$(GUIDE_RESULT_DBLATEX)/macports-guide.$(SUFFIX)" \
125        $(GUIDE_SRC)/guide.xml
126
127# Generate the man pages using DocBook from the XML source in $(MAN_SRC).
128# The portfile-*.xml and portgroup-*.xml files in $(GUIDE_SRC) are copied to
129# $(MAN_TMP) and modified (section -> refsection) so they can be used as man
130# XML source files and then xincluded in the real man XML files in $(MAN_SRC).
131man: $(MAN_XSL)
132        $(MKDIR) -p $(MAN_RESULT)
133        $(MKDIR) -p $(MAN_TMP)
134        $(CP) $(GUIDE_SRC)/portfile-*.xml $(MAN_TMP)
135        $(CP) $(GUIDE_SRC)/portgroup-*.xml $(MAN_TMP)
136ifeq ($(UNAME), Linux)
137        $(SED) -i -r -e 's|<section|<refsection|g' $(MAN_TMP)/*
138        $(SED) -i -r -e 's|</section>|</refsection>|g' $(MAN_TMP)/*
139else
140        $(SED) -i "" 's|<section|<refsection|g' $(MAN_TMP)/*
141        $(SED) -i "" 's|</section>|</refsection>|g' $(MAN_TMP)/*
142endif
143        $(XSLTPROC) --xinclude --output $(MAN_RESULT) $(MAN_XSL) \
144            $(MAN_SRC)/port.1.xml \
145            $(MAN_SRC)/portfile.7.xml \
146            $(MAN_SRC)/portgroup.7.xml \
147            $(MAN_SRC)/porthier.7.xml
148        $(RM) -r $(MAN_TMP)
149
150# Create XSL from template for man pages.
151$(MAN_XSL):
152ifeq ($(UNAME), Linux)
153        $(SED) -r -e 's:@PREFIX@:$(PREFIX):' $@.in > $@
154else
155        $(SED) 's:@PREFIX@:$(PREFIX):' $@.in > $@
156endif
157
158# Remove all temporary files generated by guide: and man:.
159clean:
160        $(RM) -rf $(GUIDE)/resources/xsl
161        $(RM) -rf $(GUIDE_RESULT)
162        $(RM) -rf $(GUIDE_RESULT_DBLATEX)
163        $(RM) -rf $(MAN_RESULT)
164        $(RM) -rf $(MAN_TMP)
165        $(RM) -rf $(MAN_XSL)
166        $(RM) -f  guide.tmp.xml
167
168# Validate the XML files for the guide.
169validate:
170        $(XMLLINT) --xinclude --loaddtd --postvalid --noout $(GUIDE_SRC)/guide.xml
Note: See TracBrowser for help on using the repository browser.