• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
26import "class" : new ;
27import param ;
28import project ;
29import property-set ;
30import targets ;
31
32
33class alias-target-class : basic-target
34{
35    rule __init__ ( name : project : sources * : requirements *
36        : default-build * : usage-requirements * )
37    {
38        basic-target.__init__ $(name) : $(project) : $(sources) :
39            $(requirements) : $(default-build) : $(usage-requirements) ;
40    }
41
42    rule construct ( name : source-targets * : property-set )
43    {
44        return [ property-set.empty ] $(source-targets) ;
45    }
46
47    rule compute-usage-requirements ( subvariant )
48    {
49        local base = [ basic-target.compute-usage-requirements $(subvariant) ] ;
50        return [ $(base).add [ $(subvariant).sources-usage-requirements ] ] ;
51    }
52}
53
54
55# Declares the 'alias' target. It will process its sources virtual-targets by
56# returning them unaltered as its own constructed virtual-targets.
57#
58rule alias ( name : sources * : requirements * : default-build * :
59    usage-requirements * )
60{
61    param.handle-named-params
62        sources requirements default-build usage-requirements ;
63
64    local project = [ project.current ] ;
65
66    targets.main-target-alternative
67        [ new alias-target-class $(name) : $(project)
68            : [ targets.main-target-sources $(sources) : $(name) : no-renaming ]
69            : [ targets.main-target-requirements $(requirements) : $(project) ]
70            : [ targets.main-target-default-build $(default-build) : $(project)
71                ]
72            : [ targets.main-target-usage-requirements $(usage-requirements) :
73                $(project) ]
74        ] ;
75}
76
77
78IMPORT $(__name__) : alias : : alias ;
79