Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / example / generator / soap.jam
1 # Copyright 2006 Vladimir Prus
2 # Distributed under the Boost Software License, Version 1.0.
3 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
4
5 # This is example of a fictional code generator tool.
6 # It accepts a single input of type '.gci' and produces
7 # either one or two outputs of type .cpp, depending
8 # on the value of the feature <server-mode>
9 #
10 # This example is loosely based on gSOAP code generator.
11
12 import type ;
13 import generators ;
14 import feature ;
15 import common ;
16 import "class" : new ;
17
18 type.register GCI : gci ;
19
20 feature.feature server : off on : incidental ;
21
22 class soap-generator : generator
23 {
24     import "class" : new ;
25
26     rule __init__ ( * : * )
27     {
28         generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
29     }
30
31     rule run ( project name ? : property-set : sources * )
32     {
33         if ! $(sources[2])
34         {
35             # Accept only single source.
36             local t = [ $(sources[1]).type ] ;
37             if $(t) = GCI
38             {
39                 # The type is correct.
40
41                 # If no output name is specified, guess it from sources.
42                 if ! $(name)
43                 {
44                     name = [ generator.determine-output-name $(sources) ] ;
45                 }
46
47                 # Produce one output, using just copy.
48                 local a = [ new action $(sources[1])
49                   : common.copy : $(property-set) ] ;
50                 local t = [ new file-target $(name) : CPP : $(project)
51                   : $(a) ] ;
52
53                 # If in server mode, create another output -- an
54                 # empty file. If this were a real SOAP generator, we
55                 # might have created a single action, and two targets
56                 # both using that action.
57         local t2 ;
58         if [ $(property-set).get <server> ] = "on"
59         {
60                     local a = [ new action : soap.touch : $(property-set) ] ;
61                     t2 = [ new file-target $(name)_server : CPP : $(project)
62                       : $(a) ] ;
63                 }
64                 return [ virtual-target.register $(t) ]
65                [ virtual-target.register $(t2) ] ;
66             }
67         }
68     }
69 }
70
71 generators.register [ new soap-generator soap.soap : GCI : CPP ] ;
72
73 TOUCH = [ common.file-touch-command ] ;
74 actions touch
75 {
76     $(TOUCH) $(<)
77 }