1 # Copyright (C) 2003 Doug Gregor. Permission to copy, use, modify, sell and
2 # distribute this software is granted provided this copyright notice appears in
3 # all copies. This software is provided "as is" without express or implied
4 # warranty, and with no claim as to its suitability for any purpose.
6 # This module defines rules to apply an XSLT stylesheet to an XML file using the
7 # xsltproc driver, part of libxslt.
18 feature.feature xsl:param : : free ;
19 feature.feature xsl:path : : free ;
20 feature.feature catalog : : free ;
23 # Initialize xsltproc support. The parameters are:
24 # xsltproc: The xsltproc executable
26 rule init ( xsltproc ? )
31 .xsltproc = $(xsltproc) ;
37 rule freeze-config ( )
39 if ! $(.config-frozen)
41 .config-frozen = true ;
42 .xsltproc ?= [ modules.peek : XSLTPROC ] ;
43 .xsltproc ?= xsltproc ;
45 .is-cygwin = [ .is-cygwin $(.xsltproc) ] ;
50 rule modify-config ( )
56 "xsltproc: Cannot change xsltproc command after it has been used." ;
61 rule check-xsltproc ( )
65 local status = [ SHELL "\"$(.xsltproc)\" -V" : no-output : exit-status ]
70 errors.user-error "xsltproc: Could not run \"$(.xsltproc)\" -V." ;
81 # Returns a non-empty string if a cygwin xsltproc binary was specified.
86 return $(.is-cygwin) ;
90 rule .is-cygwin ( xsltproc )
94 local file = [ path.make [ modules.binding $(__name__) ] ] ;
95 local dir = [ path.native [ path.join [ path.parent $(file) ] xsltproc ]
97 if [ os.name ] = CYGWIN
102 "\"$(xsltproc)\" \"$(dir)\\test.xsl\" \"$(dir)\\test.xml\" 2>&1" ;
103 local status = [ SHELL $(command) : no-output : exit-status ] ;
104 if $(status[2]) != "0"
112 rule compute-xslt-flags ( target : properties * )
115 local flags = [ feature.get-values <flags> : $(properties) ] ;
117 # Translate <xsl:param> into command line flags.
118 for local param in [ feature.get-values <xsl:param> : $(properties) ]
120 local namevalue = [ regex.split $(param) "=" ] ;
121 flags += --stringparam $(namevalue[1]) \"$(namevalue[2])\" ;
124 # Translate <xsl:path>.
125 for local path in [ feature.get-values <xsl:path> : $(properties) ]
127 flags += --path \"$(path:G=)\" ;
130 # Take care of implicit dependencies.
132 for local dep in [ feature.get-values <implicit-dependency> : $(properties)
135 other-deps += [ $(dep:G=).creating-subvariant ] ;
138 local implicit-target-directories ;
139 for local dep in [ sequence.unique $(other-deps) ]
141 implicit-target-directories += [ $(dep).all-target-directories ] ;
144 for local dir in $(implicit-target-directories)
146 flags += --path \"$(dir:T)\" ;
153 local rule .xsltproc ( target : source stylesheet : properties * : dirname ? :
157 STYLESHEET on $(target) = $(stylesheet) ;
158 FLAGS on $(target) += [ compute-xslt-flags $(target) : $(properties) ] ;
159 NAME on $(target) = $(.xsltproc) ;
161 for local catalog in [ feature.get-values <catalog> : $(properties) ]
163 CATALOG = [ common.variable-setting-command XML_CATALOG_FILES :
167 if [ os.on-windows ] && ! [ is-cygwin ]
169 action = $(action).windows ;
172 $(action) $(target) : $(source) ;
176 rule xslt ( target : source stylesheet : properties * )
178 return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) : :
183 rule xslt-dir ( target : source stylesheet : properties * : dirname )
185 return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) :
186 $(dirname) : xslt-xsltproc-dir ] ;
189 actions xslt-xsltproc.windows
191 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET:W)" "$(>:W)"
195 actions xslt-xsltproc bind STYLESHEET
197 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET:T)" "$(>:T)"
201 actions xslt-xsltproc-dir.windows bind STYLESHEET
203 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET:W)" "$(>:W)"
207 actions xslt-xsltproc-dir bind STYLESHEET
209 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET:T)" "$(>:T)"