source: trunk/doc-new/Makefile @ 41271

Last change on this file since 41271 was 40918, checked in by simon@…, 11 years ago

doc-new: Removed hyphens from variable names as they are not recommended.

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1# $Id: Makefile 40918 2008-10-18 12:59:23Z simon@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
22
23# Data directories.
24GUIDE = guide
25MAN   = man
26# Source directories.
27GUIDE_SRC = $(GUIDE)/xml
28MAN_SRC   = $(MAN)/xml
29# Result directories.
30GUIDE_RESULT       = $(GUIDE)/html
31GUIDE_RESULT_CHUNK = $(GUIDE_RESULT)/chunked
32MAN_RESULT         = $(MAN)/man/
33# Man temporary directory.
34MAN_TMP = $(MAN)/tmp
35
36# Path to the DocBook XSL files.
37DOCBOOK         = $(PREFIX)/share/xsl/docbook-xsl
38GUIDE_XSL       = $(GUIDE)/resources/single-page.xsl
39GUIDE_XSL_CHUNK = $(GUIDE)/resources/chunk.xsl
40MAN_XSL         = $(MAN)/resources/macports.xsl
41
42# DocBook HTML stylesheet for the guide.
43STYLESHEET = docbook.css
44
45.PHONY: all guide man clean validate
46
47all: guide man
48
49# Generate the HTML guide using DocBook from the XML sources in $(GUIDE_SRC).
50guide:
51        $(MKDIR) -p $(GUIDE_RESULT)
52        $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE_RESULT)/$(STYLESHEET)
53        $(CP) $(GUIDE)/resources/images/* $(GUIDE_RESULT)/
54        $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
55        $(XSLTPROC) --xinclude \
56            --output $(GUIDE_RESULT)/index.html \
57            $(GUIDE_XSL) $(GUIDE_SRC)/guide.xml
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' \
62            $(GUIDE_RESULT)/index.html
63
64# Generate the chunked HTML guide with one section per file.
65guide-chunked:
66        $(MKDIR) -p $(GUIDE_RESULT_CHUNK)
67        $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE_RESULT_CHUNK)/$(STYLESHEET)
68        $(CP) $(GUIDE)/resources/images/* $(GUIDE_RESULT_CHUNK)/
69        $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
70        $(XSLTPROC) --xinclude \
71            --output $(GUIDE_RESULT_CHUNK)/index.html \
72            $(GUIDE_XSL_CHUNK) $(GUIDE_SRC)/guide.xml
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' \
77            $(GUIDE_RESULT_CHUNK)/*.html
78        # Add the table of contents to every junked HTML file.
79        # If someone knows a better way to do this please change it.
80        $(TCLSH) toc-for-chunked.tcl $(GUIDE_RESULT_CHUNK)
81
82
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)
100
101# Create XSL from template for man pages.
102$(MAN_XSL):
103        $(SED) 's:@PREFIX@:$(PREFIX):' $@.in > $@
104
105# Remove all temporary files generated by guide: and man:.
106clean:
107        $(RM) -rf $(GUIDE)/resources/xsl
108        $(RM) -rf $(GUIDE_RESULT)
109        $(RM) -rf $(MAN_RESULT)
110        $(RM) -rf $(MAN_TMP)
111        $(RM) -rf $(MAN_XSL)
112        $(RM) -f  guide.tmp.xml
113
114# Validate the XML files for the guide.
115# These two steps are necessary as otherwise xmllint complains about missing
116# ids.
117validate:
118        $(XMLLINT) --xinclude $(GUIDE_SRC)/guide.xml > guide.tmp.xml
119        $(XMLLINT) --loaddtd --valid --noout guide.tmp.xml
Note: See TracBrowser for help on using the repository browser.