summaryrefslogtreecommitdiffstats
blob: 28a5e18466983c10ffd4e9d59be7f765a56bcd11 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# $Source$
# $Author: xmldoc $
# $Date: 2007-03-04 22:28:18 -0800 (Sun, 04 Mar 2007) $
# $Revision: 6666 $
# vim: number
#
# -----------------------------------------------------------------
#  ** Makefile.combine -- combine source files **
# -----------------------------------------------------------------
#
#   This file is part of the DocBook Project XSL Stylesheet
#   distribution.
#
#   See http://docbook.sourceforge.net/release/xsl/current/
#   for copyright and other information.
#
# This makefile creates "wrapper" files that combine sets of
# individual DocBook source files. The purpose of combining the
# files is to speed up processing time. By default it puts 20
# files into each wrapper. Use CHUNKSIZE to configure the number
# of files per wrapper.
#
# Currently, this makefile has only a "man" target and is mainly
# intended to speed up processing of large numbers of individual
# refentry instances.

# What file extension do you use for DocBook source files?
DOCBOOK_FILE_EXTENSION = .xml
SOURCE_FILES_DBK = $(wildcard *$(DOCBOOK_FILE_EXTENSION))

MAKEFILE_DOCBOOK = Makefile.DocBook

XSLTPROC=xsltproc
XSLTPROC_FLAGS=

SED=sed
SED_FLAGS=-i

CHUNKSIZE ?= 20

WRAPPER_ELEMENT = reference
WRAPPER_TITLE=Combined contents

COMBINE_XSL = <?xml version="1.0"?> \
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                xmlns:exsl="http://exslt.org/common" \
                xmlns:xi="http://www.w3.org/2001/XInclude" \
                exclude-result-prefixes="exsl xi" \
                extension-element-prefixes="exsl" \
                version="1.0"> \
  <xsl:param name="files"/> \
  <xsl:param name="chunk.size"/> \
  <xsl:template match="/"> \
    <xsl:call-template name="make.file"/> \
  </xsl:template> \
 \
  <xsl:template name="make.file"> \
    <xsl:param name="count" select="1"/> \
    <xsl:param name="current.files" select="concat(normalize-space($$files), ^^ ^^)"/> \
    <xsl:param name="more.files" \
               select="concat(normalize-space(substring-after($$current.files, ^^ ^^)),^^ ^^)"/> \
    <xsl:param name="file.number" select="1"/> \
    <xsl:param name="filename" select="concat(^^./build/^^,$$file.number,^^.xml^^)"/> \
 \
    <xsl:choose> \
      <xsl:when test="$$more.files = ^^ ^^"/> \
      <xsl:when test="$$count mod $$chunk.size = 0"> \
        <xsl:variable name="fileset" select="concat($$current.files, ^^ ^^, \
          substring-before($$more.files, ^^ ^^))"/> \
        <exsl:document href="{$$filename}" \
                       method="xml" \
                       encoding="UTF-8" \
                       indent="yes" \
                       omit-xml-declaration="yes" \
                       media-type="" \
                       standalone="no"> \
          <$(WRAPPER_ELEMENT)> \
            <title>$(WRAPPER_TITLE)</title> \
            <xsl:call-template name="make.xinclude"> \
              <xsl:with-param name="file"> \
                <xsl:choose> \
                  <xsl:when test="contains($$fileset, ^^ ^^)"> \
                    <xsl:value-of \
                        select="normalize-space(substring-before($$fileset, ^^ ^^))"/> \
                  </xsl:when> \
                  <xsl:otherwise> \
                    <xsl:value-of select="$$fileset"/> \
                  </xsl:otherwise> \
                </xsl:choose> \
              </xsl:with-param> \
              <xsl:with-param \
                  name="remaining.files" \
                  select="concat(normalize-space(substring-after($$fileset, ^^ ^^)),^^ ^^)"/> \
            </xsl:call-template> \
          </$(WRAPPER_ELEMENT)> \
        </exsl:document> \
        <xsl:call-template name="make.file"> \
          <xsl:with-param name="count" select="1"/> \
          <xsl:with-param name="current.files"  \
                          select="$$more.files"/> \
          <xsl:with-param name="file.number" select="number($$file.number) + 1"/> \
          <xsl:with-param name="filename" select="concat(^^./build/^^,$$file.number,^^.xml^^)"/> \
        </xsl:call-template> \
      </xsl:when> \
      <xsl:otherwise> \
        <xsl:call-template name="make.file"> \
          <xsl:with-param name="count" select="$$count + 1"/> \
          <xsl:with-param name="current.files"> \
            <xsl:choose> \
              <xsl:when test="$$count = 1 and $$file.number = 1"> \
                <xsl:value-of  \
                    select="concat(substring-before($$current.files, ^^ ^^), \
                            ^^ ^^, \
                            substring-before($$more.files, ^^ ^^))"/> \
              </xsl:when> \
              <xsl:when test="$$count = 1"> \
                <xsl:value-of  \
                    select="substring-before($$more.files, ^^ ^^)"/> \
              </xsl:when> \
              <xsl:otherwise> \
                <xsl:value-of  \
                    select="concat($$current.files, ^^ ^^, \
                            substring-before($$more.files, ^^ ^^))"/> \
              </xsl:otherwise> \
            </xsl:choose> \
          </xsl:with-param> \
          <xsl:with-param name="more.files" \
                          select="substring-after($$more.files, ^^ ^^)"/> \
          <xsl:with-param name="file.number" select="$$file.number"/> \
        </xsl:call-template> \
      </xsl:otherwise> \
    </xsl:choose> \
  </xsl:template> \
 \
  <xsl:template name="make.xinclude"> \
    <xsl:param name="file"/> \
    <xsl:param name="remaining.files"/> \
    <xsl:param name="count" select="1"/> \
    <xsl:if test="not($$file = ^^^^)"> \
      <xi:include href="../{$$file}"/> \
      <xsl:call-template name="make.xinclude"> \
        <xsl:with-param \
            name="file" \
            select="substring-before($$remaining.files, ^^ ^^)"/> \
        <xsl:with-param \
            name="remaining.files" \
            select="substring-after($$remaining.files, ^^ ^^)"/> \
        <xsl:with-param name="count" select="$$count + 1"/> \
      </xsl:call-template> \
    </xsl:if> \
  </xsl:template> \
 \
</xsl:stylesheet>

all: man

man: build/man

build/Makefile:
	if [ ! -d build ]; then mkdir build; fi
	cp $(MAKEFILE_DOCBOOK) $@

combine.xsl: Makefile
	@echo '$(COMBINE_XSL)' > $@
	$(SED) $(SED_FLAGS) "s/\^\^/'/g" $@

build/1.xml: combine.xsl
	$(XSLTPROC) $(XSLTPROC_FLAGS) \
	--stringparam files "$(SOURCE_FILES_DBK)" \
	--stringparam chunk.size $(CHUNKSIZE) \
	$< $<

build/man: build/Makefile build/1.xml
	time $(MAKE) -C build man \
		MAN_PARAMS="--stringparam man.output.quietly 1 \
		   --stringparam refentry.meta.get.quietly 1 \
		   --stringparam man.charmap.enabled 0"

debug:

clean:
	$(RM) -r build