]> git.stg.codes - stg.git/blob - doc/xslt/tools/make/Makefile.combine
Fixed stupid bug in case conversion functions.
[stg.git] / doc / xslt / tools / make / Makefile.combine
1 # $Source$
2 # $Author: xmldoc $
3 # $Date: 2007-03-04 22:28:18 -0800 (Sun, 04 Mar 2007) $
4 # $Revision: 6666 $
5 # vim: number
6 #
7 # -----------------------------------------------------------------
8 #  ** Makefile.combine -- combine source files **
9 # -----------------------------------------------------------------
10 #
11 #   This file is part of the DocBook Project XSL Stylesheet
12 #   distribution.
13 #
14 #   See http://docbook.sourceforge.net/release/xsl/current/
15 #   for copyright and other information.
16 #
17 # This makefile creates "wrapper" files that combine sets of
18 # individual DocBook source files. The purpose of combining the
19 # files is to speed up processing time. By default it puts 20
20 # files into each wrapper. Use CHUNKSIZE to configure the number
21 # of files per wrapper.
22 #
23 # Currently, this makefile has only a "man" target and is mainly
24 # intended to speed up processing of large numbers of individual
25 # refentry instances.
26
27 # What file extension do you use for DocBook source files?
28 DOCBOOK_FILE_EXTENSION = .xml
29 SOURCE_FILES_DBK = $(wildcard *$(DOCBOOK_FILE_EXTENSION))
30
31 MAKEFILE_DOCBOOK = Makefile.DocBook
32
33 XSLTPROC=xsltproc
34 XSLTPROC_FLAGS=
35
36 SED=sed
37 SED_FLAGS=-i
38
39 CHUNKSIZE ?= 20
40
41 WRAPPER_ELEMENT = reference
42 WRAPPER_TITLE=Combined contents
43
44 COMBINE_XSL = <?xml version="1.0"?> \
45 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
46                 xmlns:exsl="http://exslt.org/common" \
47                 xmlns:xi="http://www.w3.org/2001/XInclude" \
48                 exclude-result-prefixes="exsl xi" \
49                 extension-element-prefixes="exsl" \
50                 version="1.0"> \
51   <xsl:param name="files"/> \
52   <xsl:param name="chunk.size"/> \
53   <xsl:template match="/"> \
54     <xsl:call-template name="make.file"/> \
55   </xsl:template> \
56  \
57   <xsl:template name="make.file"> \
58     <xsl:param name="count" select="1"/> \
59     <xsl:param name="current.files" select="concat(normalize-space($$files), ^^ ^^)"/> \
60     <xsl:param name="more.files" \
61                select="concat(normalize-space(substring-after($$current.files, ^^ ^^)),^^ ^^)"/> \
62     <xsl:param name="file.number" select="1"/> \
63     <xsl:param name="filename" select="concat(^^./build/^^,$$file.number,^^.xml^^)"/> \
64  \
65     <xsl:choose> \
66       <xsl:when test="$$more.files = ^^ ^^"/> \
67       <xsl:when test="$$count mod $$chunk.size = 0"> \
68         <xsl:variable name="fileset" select="concat($$current.files, ^^ ^^, \
69           substring-before($$more.files, ^^ ^^))"/> \
70         <exsl:document href="{$$filename}" \
71                        method="xml" \
72                        encoding="UTF-8" \
73                        indent="yes" \
74                        omit-xml-declaration="yes" \
75                        media-type="" \
76                        standalone="no"> \
77           <$(WRAPPER_ELEMENT)> \
78             <title>$(WRAPPER_TITLE)</title> \
79             <xsl:call-template name="make.xinclude"> \
80               <xsl:with-param name="file"> \
81                 <xsl:choose> \
82                   <xsl:when test="contains($$fileset, ^^ ^^)"> \
83                     <xsl:value-of \
84                         select="normalize-space(substring-before($$fileset, ^^ ^^))"/> \
85                   </xsl:when> \
86                   <xsl:otherwise> \
87                     <xsl:value-of select="$$fileset"/> \
88                   </xsl:otherwise> \
89                 </xsl:choose> \
90               </xsl:with-param> \
91               <xsl:with-param \
92                   name="remaining.files" \
93                   select="concat(normalize-space(substring-after($$fileset, ^^ ^^)),^^ ^^)"/> \
94             </xsl:call-template> \
95           </$(WRAPPER_ELEMENT)> \
96         </exsl:document> \
97         <xsl:call-template name="make.file"> \
98           <xsl:with-param name="count" select="1"/> \
99           <xsl:with-param name="current.files"  \
100                           select="$$more.files"/> \
101           <xsl:with-param name="file.number" select="number($$file.number) + 1"/> \
102           <xsl:with-param name="filename" select="concat(^^./build/^^,$$file.number,^^.xml^^)"/> \
103         </xsl:call-template> \
104       </xsl:when> \
105       <xsl:otherwise> \
106         <xsl:call-template name="make.file"> \
107           <xsl:with-param name="count" select="$$count + 1"/> \
108           <xsl:with-param name="current.files"> \
109             <xsl:choose> \
110               <xsl:when test="$$count = 1 and $$file.number = 1"> \
111                 <xsl:value-of  \
112                     select="concat(substring-before($$current.files, ^^ ^^), \
113                             ^^ ^^, \
114                             substring-before($$more.files, ^^ ^^))"/> \
115               </xsl:when> \
116               <xsl:when test="$$count = 1"> \
117                 <xsl:value-of  \
118                     select="substring-before($$more.files, ^^ ^^)"/> \
119               </xsl:when> \
120               <xsl:otherwise> \
121                 <xsl:value-of  \
122                     select="concat($$current.files, ^^ ^^, \
123                             substring-before($$more.files, ^^ ^^))"/> \
124               </xsl:otherwise> \
125             </xsl:choose> \
126           </xsl:with-param> \
127           <xsl:with-param name="more.files" \
128                           select="substring-after($$more.files, ^^ ^^)"/> \
129           <xsl:with-param name="file.number" select="$$file.number"/> \
130         </xsl:call-template> \
131       </xsl:otherwise> \
132     </xsl:choose> \
133   </xsl:template> \
134  \
135   <xsl:template name="make.xinclude"> \
136     <xsl:param name="file"/> \
137     <xsl:param name="remaining.files"/> \
138     <xsl:param name="count" select="1"/> \
139     <xsl:if test="not($$file = ^^^^)"> \
140       <xi:include href="../{$$file}"/> \
141       <xsl:call-template name="make.xinclude"> \
142         <xsl:with-param \
143             name="file" \
144             select="substring-before($$remaining.files, ^^ ^^)"/> \
145         <xsl:with-param \
146             name="remaining.files" \
147             select="substring-after($$remaining.files, ^^ ^^)"/> \
148         <xsl:with-param name="count" select="$$count + 1"/> \
149       </xsl:call-template> \
150     </xsl:if> \
151   </xsl:template> \
152  \
153 </xsl:stylesheet>
154
155 all: man
156
157 man: build/man
158
159 build/Makefile:
160         if [ ! -d build ]; then mkdir build; fi
161         cp $(MAKEFILE_DOCBOOK) $@
162
163 combine.xsl: Makefile
164         @echo '$(COMBINE_XSL)' > $@
165         $(SED) $(SED_FLAGS) "s/\^\^/'/g" $@
166
167 build/1.xml: combine.xsl
168         $(XSLTPROC) $(XSLTPROC_FLAGS) \
169         --stringparam files "$(SOURCE_FILES_DBK)" \
170         --stringparam chunk.size $(CHUNKSIZE) \
171         $< $<
172
173 build/man: build/Makefile build/1.xml
174         time $(MAKE) -C build man \
175                 MAN_PARAMS="--stringparam man.output.quietly 1 \
176                    --stringparam refentry.meta.get.quietly 1 \
177                    --stringparam man.charmap.enabled 0"
178
179 debug:
180
181 clean:
182         $(RM) -r build