Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / src / build / alias.jam
1 # Copyright 2003, 2004, 2006 Vladimir Prus
2 # Distributed under the Boost Software License, Version 1.0.
3 # (See accompanying file LICENSE_1_0.txt or copy at
4 # http://www.boost.org/LICENSE_1_0.txt)
5
6 # This module defines the 'alias' rule and the associated target class.
7 #
8 # Alias is just a main target which returns its source targets without any
9 # processing. For example:
10 #
11 #   alias bin : hello test_hello ;
12 #   alias lib : helpers xml_parser ;
13 #
14 # Another important use of 'alias' is to conveniently group source files:
15 #
16 #   alias platform-src : win.cpp : <os>NT ;
17 #   alias platform-src : linux.cpp : <os>LINUX ;
18 #   exe main : main.cpp platform-src ;
19 #
20 # Lastly, it is possible to create a local alias for some target, with different
21 # properties:
22 #
23 #   alias big_lib : : @/external_project/big_lib/<link>static ;
24 #
25
26 import "class" : new ;
27 import project ;
28 import property-set ;
29 import targets ;
30
31
32 class alias-target-class : basic-target
33 {
34     rule __init__ ( name : project : sources * : requirements *
35         : default-build * : usage-requirements * )
36     {
37         basic-target.__init__ $(name) : $(project) : $(sources) :
38             $(requirements) : $(default-build) : $(usage-requirements) ;
39     }
40
41     rule construct ( name : source-targets * : property-set )
42     {
43         return [ property-set.empty ] $(source-targets) ;
44     }
45
46     rule compute-usage-requirements ( subvariant )
47     {
48         local base = [ basic-target.compute-usage-requirements $(subvariant) ] ;
49         return [ $(base).add [ $(subvariant).sources-usage-requirements ] ] ;
50     }
51 }
52
53
54 # Declares the 'alias' target. It will process its sources virtual-targets by
55 # returning them unaltered as its own constructed virtual-targets.
56 #
57 rule alias ( name : sources * : requirements * : default-build * :
58     usage-requirements * )
59 {
60     local project = [ project.current ] ;
61
62     targets.main-target-alternative
63         [ new alias-target-class $(name) : $(project)
64             : [ targets.main-target-sources $(sources) : $(name) : no-renaming ]
65             : [ targets.main-target-requirements $(requirements) : $(project) ]
66             : [ targets.main-target-default-build $(default-build) : $(project)
67                 ]
68             : [ targets.main-target-usage-requirements $(usage-requirements) :
69                 $(project) ]
70         ] ;
71 }
72
73
74 IMPORT $(__name__) : alias : : alias ;