1 # Copyright 2003 Dave Abrahams
2 # Copyright 2003 Vladimir Prus
3 # Distributed under the Boost Software License, Version 1.0.
4 # (See accompanying file LICENSE_1_0.txt or copy at
5 # http://www.boost.org/LICENSE_1_0.txt)
11 # The pattern that indirect rules must match: module%rule
12 .pattern = ^([^%]*)%([^%]+)$ ;
16 # Type checking rules.
18 local rule indirect-rule ( x )
20 if ! [ MATCH $(.pattern) : $(x) ]
22 return "expected a string of the form module%rule, but got \""$(x)"\" for argument" ;
27 # Make an indirect rule which calls the given rule. If context is supplied it is
28 # expected to be the module in which to invoke the rule by the 'call' rule
29 # below. Otherwise, the rule will be invoked in the module of this rule's
32 rule make ( rulename bound-args * : context ? )
34 context ?= [ CALLER_MODULE ] ;
36 return $(context)%$(rulename) $(bound-args) ;
40 # Make an indirect rule which calls the given rule. 'rulename' may be a
41 # qualified rule; if so it is returned unchanged. Otherwise, if frames is not
42 # supplied, the result will be invoked (by 'call', below) in the module of the
43 # caller. Otherwise, frames > 1 specifies additional call frames to back up in
44 # order to find the module context.
46 rule make-qualified ( rulename bound-args * : frames ? )
48 if [ MATCH $(.pattern) : $(rulename) ]
50 return $(rulename) $(bound-args) ;
55 # If the rule name includes a Jamfile module, grab it.
56 local module-context = [ MATCH ^(Jamfile<[^>]*>)\\..* : $(rulename) ] ;
58 if ! $(module-context)
60 # Take the first dot-separated element as module name. This disallows
61 # module names with dots, but allows rule names with dots.
62 module-context = [ MATCH ^([^.]*)\\..* : $(rulename) ] ;
64 module-context ?= [ CALLER_MODULE $(frames) ] ;
65 return [ make $(rulename) $(bound-args) : $(module-context) ] ;
70 # Returns the module name in which the given indirect rule will be invoked.
72 rule get-module ( [indirect-rule] x )
74 local m = [ MATCH $(.pattern) : $(x) ] ;
83 # Returns the rulename that will be called when x is invoked.
85 rule get-rule ( [indirect-rule] x )
87 local m = [ MATCH $(.pattern) : $(x) ] ;
92 # Invoke the given indirect-rule.
94 rule call ( [indirect-rule] r args * : * )
96 return [ modules.call-in [ get-module $(r) ] : [ get-rule $(r) ] $(args) :
97 $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) : $(10) : $(11) :
98 $(12) : $(13) : $(14) : $(15) : $(16) : $(17) : $(18) : $(19) ] ;
108 assert.equal $(x) : x ;
111 assert.equal [ get-rule [ make foo-barr! ] ] : foo-barr! ;
112 assert.equal [ get-module [ make foo-barr! ] ] : [ CALLER_MODULE ] ;
114 call [ make foo-barr! ] x ;
115 call [ make foo-barr! x ] ;
116 call [ make foo-barr! : [ CALLER_MODULE ] ] x ;