• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
12import type ;
13import generators ;
14import feature ;
15import common ;
16import "class" : new ;
17import os ;
18
19type.register GCI : gci ;
20
21feature.feature server : off on : incidental ;
22
23class soap-generator : generator
24{
25    import "class" : new ;
26
27    rule __init__ ( * : * )
28    {
29        generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
30    }
31
32    rule run ( project name ? : property-set : sources * )
33    {
34        if ! $(sources[2])
35        {
36            # Accept only single source.
37            local t = [ $(sources[1]).type ] ;
38            if $(t) = GCI
39            {
40                # The type is correct.
41
42                # If no output name is specified, guess it from sources.
43                if ! $(name)
44                {
45                    name = [ generator.determine-output-name $(sources) ] ;
46                }
47
48                # Produce one output, using just copy.
49                local a = [ new action $(sources[1])
50                  : common.copy : $(property-set) ] ;
51                local t = [ new file-target $(name) : CPP : $(project)
52                  : $(a) ] ;
53
54                # If in server mode, create another output -- an
55                # empty file. If this were a real SOAP generator, we
56                # might have created a single action, and two targets
57                # both using that action.
58        local t2 ;
59        if [ $(property-set).get <server> ] = "on"
60        {
61                    local a = [ new action : soap.touch : $(property-set) ] ;
62                    t2 = [ new file-target $(name)_server : CPP : $(project)
63                      : $(a) ] ;
64                }
65                return [ virtual-target.register $(t) ]
66               [ virtual-target.register $(t2) ] ;
67            }
68        }
69    }
70}
71
72generators.register [ new soap-generator soap.soap : GCI : CPP ] ;
73
74TOUCH = [ common.file-touch-command ] ;
75actions touch
76{
77    $(TOUCH) $(<)
78}
79
80if [ os.name ] = VMS
81{
82    actions touch
83    {
84        $(TOUCH) $(<:W)
85    }
86}
87