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)
9 class c-scanner : scanner
15 import virtual-target ;
17 rule __init__ ( includes * )
21 for local i in $(includes)
23 self.includes += [ sequence.transform path.native
24 : [ regex.split $(i:G=) "&&" ] ] ;
30 return "#[ \t]*include[ ]*(<(.*)>|\"(.*)\")" ;
33 rule process ( target : matches * : binding )
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) ] ;
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) ] ;
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) ;
52 angle = $(angle:G=$(g)) ;
53 quoted = $(quoted:G=$(g2)) ;
55 local all = $(angle) $(quoted) ;
57 INCLUDES $(target) : $(all) ;
59 SEARCH on $(angle) = $(self.includes:G=) ;
60 SEARCH on $(quoted) = $(b) $(self.includes:G=) ;
62 # Just propagate the current scanner to includes in hope that includes
63 # do not change scanners.
64 scanner.propagate $(__name__) : $(angle) $(quoted) : $(target) ;
66 ISFILE $(angle) $(quoted) ;
70 scanner.register c-scanner : include ;
72 type.register CPP : cpp cxx cc ;
74 type.register HPP : hpp : H ;
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
85 type.set-scanner H : c-scanner ;
86 type.set-scanner HPP : c-scanner ;