source: trunk/doc-new/Makefile @ 97454

Last change on this file since 97454 was 97454, checked in by wsiegrist@…, 8 years ago

Add Linux support to guide generation.

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