Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / tools / types / cpp.jam
1 # Copyright David Abrahams 2004.
2 # Copyright 2002, 2003, 2004, 2005, 2006 Vladimir Prus
3 # Copyright 2010 Rene Rivera
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6 import type ;
7 import scanner ;
8
9 class c-scanner : scanner
10 {
11     import path ;
12     import regex ;
13     import scanner ;
14     import sequence ;
15     import virtual-target ;
16
17     rule __init__ ( includes * )
18     {
19         scanner.__init__ ;
20
21         for local i in $(includes)
22         {
23             self.includes += [ sequence.transform path.native
24                                 : [ regex.split $(i:G=) "&&" ] ] ;
25         }
26     }
27
28     rule pattern ( )
29     {
30         return "#[ \t]*include[ ]*(<(.*)>|\"(.*)\")" ;
31     }
32
33     rule process ( target : matches * : binding )
34     {
35         local angle  = [ regex.transform $(matches) : "<(.*)>"   ] ;
36         angle = [ sequence.transform path.native : $(angle) ] ;
37         local quoted = [ regex.transform $(matches) : "\"(.*)\"" ] ;
38         quoted = [ sequence.transform path.native : $(quoted) ] ;
39
40         # CONSIDER: the new scoping rule seem to defeat "on target" variables.
41         local g = [ on $(target) return $(HDRGRIST) ] ;
42         local b = [ NORMALIZE_PATH $(binding:D) ] ;
43
44         # Attach binding of including file to included targets. When a target is
45         # directly created from virtual target this extra information is
46         # unnecessary. But in other cases, it allows us to distinguish between
47         # two headers of the same name included from different places. We do not
48         # need this extra information for angle includes, since they should not
49         # depend on including file (we can not get literal "." in include path).
50         local g2 = $(g)"#"$(b) ;
51
52         angle = $(angle:G=$(g)) ;
53         quoted = $(quoted:G=$(g2)) ;
54
55         local all = $(angle) $(quoted) ;
56
57         INCLUDES $(target) : $(all) ;
58         NOCARE $(all) ;
59         SEARCH on $(angle) = $(self.includes:G=) ;
60         SEARCH on $(quoted) = $(b) $(self.includes:G=) ;
61
62         # Just propagate the current scanner to includes in hope that includes
63         # do not change scanners.
64         scanner.propagate $(__name__) : $(angle) $(quoted) : $(target) ;
65
66         ISFILE $(angle) $(quoted) ;
67     }
68 }
69
70 scanner.register c-scanner : include ;
71
72 type.register CPP : cpp cxx cc ;
73 type.register H   : h ;
74 type.register HPP : hpp : H ;
75 type.register C   : c ;
76
77 # It most cases where a CPP file or a H file is a source of some action, we
78 # should rebuild the result if any of files included by CPP/H are changed. One
79 # case when this is not needed is installation, which is handled specifically.
80 type.set-scanner CPP : c-scanner ;
81 type.set-scanner C   : c-scanner ;
82 # One case where scanning of H/HPP files is necessary is PCH generation -- if
83 # any header included by HPP being precompiled changes, we need to recompile the
84 # header.
85 type.set-scanner H   : c-scanner ;
86 type.set-scanner HPP : c-scanner ;