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." ;
76 # Returns a non-empty string if a cygwin xsltproc binary was specified.
81 return $(.is-cygwin) ;
85 rule .is-cygwin ( xsltproc )
89 local file = [ path.make [ modules.binding $(__name__) ] ] ;
90 local dir = [ path.native [ path.join [ path.parent $(file) ] xsltproc ]
92 if [ os.name ] = CYGWIN
97 "\"$(xsltproc)\" \"$(dir)\\test.xsl\" \"$(dir)\\test.xml\" 2>&1" ;
98 local status = [ SHELL $(command) : no-output : exit-status ] ;
99 if $(status[2]) != "0"
107 rule compute-xslt-flags ( target : properties * )
110 local flags = [ feature.get-values <flags> : $(properties) ] ;
112 # Translate <xsl:param> into command line flags.
113 for local param in [ feature.get-values <xsl:param> : $(properties) ]
115 local namevalue = [ regex.split $(param) "=" ] ;
116 flags += --stringparam $(namevalue[1]) \"$(namevalue[2])\" ;
119 # Translate <xsl:path>.
120 for local path in [ feature.get-values <xsl:path> : $(properties) ]
122 flags += --path \"$(path:G=)\" ;
125 # Take care of implicit dependencies.
127 for local dep in [ feature.get-values <implicit-dependency> : $(properties)
130 other-deps += [ $(dep:G=).creating-subvariant ] ;
133 local implicit-target-directories ;
134 for local dep in [ sequence.unique $(other-deps) ]
136 implicit-target-directories += [ $(dep).all-target-directories ] ;
139 for local dir in $(implicit-target-directories)
141 flags += --path \"$(dir:T)\" ;
148 local rule .xsltproc ( target : source stylesheet : properties * : dirname ? :
152 STYLESHEET on $(target) = $(stylesheet) ;
153 FLAGS on $(target) += [ compute-xslt-flags $(target) : $(properties) ] ;
154 NAME on $(target) = $(.xsltproc) ;
156 for local catalog in [ feature.get-values <catalog> : $(properties) ]
158 CATALOG = [ common.variable-setting-command XML_CATALOG_FILES :
162 if [ os.on-windows ] && ! [ is-cygwin ]
164 action = $(action).windows ;
167 $(action) $(target) : $(source) ;
171 rule xslt ( target : source stylesheet : properties * )
173 return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) : :
178 rule xslt-dir ( target : source stylesheet : properties * : dirname )
180 return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) :
181 $(dirname) : xslt-xsltproc-dir ] ;
184 actions xslt-xsltproc.windows
186 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET:W)" "$(>:W)"
190 actions xslt-xsltproc bind STYLESHEET
192 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET:T)" "$(>:T)"
196 actions xslt-xsltproc-dir.windows bind STYLESHEET
198 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET:W)" "$(>:W)"
202 actions xslt-xsltproc-dir bind STYLESHEET
204 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET:T)" "$(>:T)"