Makefile.combine 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # $Source$
  2. # $Author: xmldoc $
  3. # $Date: 2007-03-05 06:28:18 +0000 (Mon, 05 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. # What file extension do you use for DocBook source files?
  27. DOCBOOK_FILE_EXTENSION = .xml
  28. SOURCE_FILES_DBK = $(wildcard *$(DOCBOOK_FILE_EXTENSION))
  29. MAKEFILE_DOCBOOK = Makefile.DocBook
  30. XSLTPROC=xsltproc
  31. XSLTPROC_FLAGS=
  32. SED=sed
  33. SED_FLAGS=-i
  34. CHUNKSIZE ?= 20
  35. WRAPPER_ELEMENT = reference
  36. WRAPPER_TITLE=Combined contents
  37. COMBINE_XSL = <?xml version="1.0"?> \
  38. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
  39. xmlns:exsl="http://exslt.org/common" \
  40. xmlns:xi="http://www.w3.org/2001/XInclude" \
  41. exclude-result-prefixes="exsl xi" \
  42. extension-element-prefixes="exsl" \
  43. version="1.0"> \
  44. <xsl:param name="files"/> \
  45. <xsl:param name="chunk.size"/> \
  46. <xsl:template match="/"> \
  47. <xsl:call-template name="make.file"/> \
  48. </xsl:template> \
  49. \
  50. <xsl:template name="make.file"> \
  51. <xsl:param name="count" select="1"/> \
  52. <xsl:param name="current.files" select="concat(normalize-space($$files), ^^ ^^)"/> \
  53. <xsl:param name="more.files" \
  54. select="concat(normalize-space(substring-after($$current.files, ^^ ^^)),^^ ^^)"/> \
  55. <xsl:param name="file.number" select="1"/> \
  56. <xsl:param name="filename" select="concat(^^./build/^^,$$file.number,^^.xml^^)"/> \
  57. \
  58. <xsl:choose> \
  59. <xsl:when test="$$more.files = ^^ ^^"/> \
  60. <xsl:when test="$$count mod $$chunk.size = 0"> \
  61. <xsl:variable name="fileset" select="concat($$current.files, ^^ ^^, \
  62. substring-before($$more.files, ^^ ^^))"/> \
  63. <exsl:document href="{$$filename}" \
  64. method="xml" \
  65. encoding="UTF-8" \
  66. indent="yes" \
  67. omit-xml-declaration="yes" \
  68. media-type="" \
  69. standalone="no"> \
  70. <$(WRAPPER_ELEMENT)> \
  71. <title>$(WRAPPER_TITLE)</title> \
  72. <xsl:call-template name="make.xinclude"> \
  73. <xsl:with-param name="file"> \
  74. <xsl:choose> \
  75. <xsl:when test="contains($$fileset, ^^ ^^)"> \
  76. <xsl:value-of \
  77. select="normalize-space(substring-before($$fileset, ^^ ^^))"/> \
  78. </xsl:when> \
  79. <xsl:otherwise> \
  80. <xsl:value-of select="$$fileset"/> \
  81. </xsl:otherwise> \
  82. </xsl:choose> \
  83. </xsl:with-param> \
  84. <xsl:with-param \
  85. name="remaining.files" \
  86. select="concat(normalize-space(substring-after($$fileset, ^^ ^^)),^^ ^^)"/> \
  87. </xsl:call-template> \
  88. </$(WRAPPER_ELEMENT)> \
  89. </exsl:document> \
  90. <xsl:call-template name="make.file"> \
  91. <xsl:with-param name="count" select="1"/> \
  92. <xsl:with-param name="current.files" \
  93. select="$$more.files"/> \
  94. <xsl:with-param name="file.number" select="number($$file.number) + 1"/> \
  95. <xsl:with-param name="filename" select="concat(^^./build/^^,$$file.number,^^.xml^^)"/> \
  96. </xsl:call-template> \
  97. </xsl:when> \
  98. <xsl:otherwise> \
  99. <xsl:call-template name="make.file"> \
  100. <xsl:with-param name="count" select="$$count + 1"/> \
  101. <xsl:with-param name="current.files"> \
  102. <xsl:choose> \
  103. <xsl:when test="$$count = 1 and $$file.number = 1"> \
  104. <xsl:value-of \
  105. select="concat(substring-before($$current.files, ^^ ^^), \
  106. ^^ ^^, \
  107. substring-before($$more.files, ^^ ^^))"/> \
  108. </xsl:when> \
  109. <xsl:when test="$$count = 1"> \
  110. <xsl:value-of \
  111. select="substring-before($$more.files, ^^ ^^)"/> \
  112. </xsl:when> \
  113. <xsl:otherwise> \
  114. <xsl:value-of \
  115. select="concat($$current.files, ^^ ^^, \
  116. substring-before($$more.files, ^^ ^^))"/> \
  117. </xsl:otherwise> \
  118. </xsl:choose> \
  119. </xsl:with-param> \
  120. <xsl:with-param name="more.files" \
  121. select="substring-after($$more.files, ^^ ^^)"/> \
  122. <xsl:with-param name="file.number" select="$$file.number"/> \
  123. </xsl:call-template> \
  124. </xsl:otherwise> \
  125. </xsl:choose> \
  126. </xsl:template> \
  127. \
  128. <xsl:template name="make.xinclude"> \
  129. <xsl:param name="file"/> \
  130. <xsl:param name="remaining.files"/> \
  131. <xsl:param name="count" select="1"/> \
  132. <xsl:if test="not($$file = ^^^^)"> \
  133. <xi:include href="../{$$file}"/> \
  134. <xsl:call-template name="make.xinclude"> \
  135. <xsl:with-param \
  136. name="file" \
  137. select="substring-before($$remaining.files, ^^ ^^)"/> \
  138. <xsl:with-param \
  139. name="remaining.files" \
  140. select="substring-after($$remaining.files, ^^ ^^)"/> \
  141. <xsl:with-param name="count" select="$$count + 1"/> \
  142. </xsl:call-template> \
  143. </xsl:if> \
  144. </xsl:template> \
  145. \
  146. </xsl:stylesheet>
  147. all: man
  148. man: build/man
  149. build/Makefile:
  150. if [ ! -d build ]; then mkdir build; fi
  151. cp $(MAKEFILE_DOCBOOK) $@
  152. combine.xsl: Makefile
  153. @echo '$(COMBINE_XSL)' > $@
  154. $(SED) $(SED_FLAGS) "s/\^\^/'/g" $@
  155. build/1.xml: combine.xsl
  156. $(XSLTPROC) $(XSLTPROC_FLAGS) \
  157. --stringparam files "$(SOURCE_FILES_DBK)" \
  158. --stringparam chunk.size $(CHUNKSIZE) \
  159. $< $<
  160. build/man: build/Makefile build/1.xml
  161. time $(MAKE) -C build man \
  162. MAN_PARAMS="--stringparam man.output.quietly 1 \
  163. --stringparam refentry.meta.get.quietly 1 \
  164. --stringparam man.charmap.enabled 0"
  165. debug:
  166. clean:
  167. $(RM) -r build