public
Description: Git mirror of the MacPorts svn repo
Homepage: http://www.macports.org
Clone URL: git://github.com/kballard/macports.git
macports / doc-new / Makefile
100644 120 lines (102 sloc) 4.067 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# $Id$
 
# Makefile to generate the macports html guide and the man pages.
# The ports 'docbook-xsl', 'docbook-xml' and 'libxslt' have to be installed.
 
# If your macports isn't installed in /opt/local you have to change PREFIX
# here.
 
 
# Prefix of the macports installation.
PREFIX = /opt/local
 
# Command abstraction variables.
MKDIR = /bin/mkdir
CP = /bin/cp
RM = /bin/rm
LN   = /bin/ln
SED = /usr/bin/sed
TCLSH = /usr/bin/tclsh
XSLTPROC = $(PREFIX)/bin/xsltproc
XMLLINT = $(PREFIX)/bin/xmllint
 
# Data directories.
GUIDE = guide
MAN = man
# Source directories.
GUIDE-SRC = $(GUIDE)/xml
MAN-SRC = $(MAN)/xml
# Result directories.
GUIDE-RESULT = $(GUIDE)/html
GUIDE-RESULT-CHUNK = $(GUIDE-RESULT)/chunked
MAN-RESULT = $(MAN)/man/
# Man temporary directory.
MAN-TMP = $(MAN)/tmp
 
# Path to the docbook xsl files.
DOCBOOK = $(PREFIX)/share/xsl/docbook-xsl
GUIDE-XSL = $(GUIDE)/resources/single-page.xsl
GUIDE-XSL-CHUNK = $(GUIDE)/resources/chunk.xsl
MAN-XSL = $(MAN)/resources/macports.xsl
 
# Docbook html stylesheet for the guide.
STYLESHEET = docbook.css
 
.PHONY: all guide man clean validate
 
all: guide man
 
# Generate the html guide using DocBook from the xml sources in $(GUIDE-SRC).
guide:
  $(MKDIR) -p $(GUIDE-RESULT)
  $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE-RESULT)/$(STYLESHEET)
  $(CP) $(GUIDE)/resources/images/* $(GUIDE-RESULT)/
  $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
  $(XSLTPROC) --xinclude \
   --output $(GUIDE-RESULT)/index.html \
   $(GUIDE-XSL) $(GUIDE-SRC)/guide.xml
  # Convert all sections (h1-h9) to a link so it's easy to link to them.
  # If someone knows a better way to do this please change it.
  $(SED) -i "" -E \
   's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
   $(GUIDE-RESULT)/index.html
 
# Generate the chunked html guide with one section per file.
guide-chunked:
  $(MKDIR) -p $(GUIDE-RESULT-CHUNK)
  $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE-RESULT-CHUNK)/$(STYLESHEET)
  $(CP) $(GUIDE)/resources/images/* $(GUIDE-RESULT-CHUNK)/
  $(LN) -sfh $(DOCBOOK) $(GUIDE)/resources/xsl
  $(XSLTPROC) --xinclude \
   --output $(GUIDE-RESULT-CHUNK)/index.html \
   $(GUIDE-XSL-CHUNK) $(GUIDE-SRC)/guide.xml
  # Convert all sections (h1-h9) to a link so it's easy to link to them.
  # If someone knows a better way to do this please change it.
  $(SED) -i "" -E \
   's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
   $(GUIDE-RESULT-CHUNK)/*.html
  # Add the table of contents to every junked html file.
  # If someone knows a better way to do this please change it.
  $(TCLSH) toc-for-chunked.tcl $(GUIDE-RESULT-CHUNK)
 
 
# Generate the man pages using DocBook from the xml source in $(MAN-SRC).
# The portfile-*.xml and portgroup-*.xml files in $(GUIDE-SRC) are copied to
# $(MAN-TMP) and modified (section -> refsection) so they can be used as man
# xml source files and then xincluded in the real man xml files in $(MAN-SRC).
man: $(MAN-XSL)
  $(MKDIR) -p $(MAN-RESULT)
  $(MKDIR) -p $(MAN-TMP)
  $(CP) $(GUIDE-SRC)/portfile-*.xml $(MAN-TMP)
  $(CP) $(GUIDE-SRC)/portgroup-*.xml $(MAN-TMP)
  $(SED) -i "" 's|<section|<refsection|g' $(MAN-TMP)/*
  $(SED) -i "" 's|</section>|</refsection>|g' $(MAN-TMP)/*
  $(XSLTPROC) --xinclude --output $(MAN-RESULT) $(MAN-XSL) \
   $(MAN-SRC)/port.1.xml \
   $(MAN-SRC)/portfile.7.xml \
   $(MAN-SRC)/portgroup.7.xml \
   $(MAN-SRC)/porthier.7.xml
  $(RM) -r $(MAN-TMP)
 
# Create XSL from template for man pages.
$(MAN-XSL):
  $(SED) 's:@PREFIX@:$(PREFIX):' $@.in > $@
 
# Remove all temporary files generated by guide: and man:.
clean:
  $(RM) -rf $(GUIDE)/resources/xsl
  $(RM) -rf $(GUIDE-RESULT)
  $(RM) -rf $(MAN-RESULT)
  $(RM) -rf $(MAN-TMP)
  $(RM) -rf $(MAN-XSL)
  $(RM) -f guide.tmp.xml
 
# Validate the xml files for the guide.
# These two steps are necessary as otherwise xmllint complains about missing
# ids.
validate:
  $(XMLLINT) --xinclude $(GUIDE-SRC)/guide.xml > guide.tmp.xml
  $(XMLLINT) --loaddtd --valid --noout guide.tmp.xml