]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/headers.c
2 * Copyright 1993, 2000 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
7 * Copyright 2001-2004 David Abrahams.
8 * Distributed under the Boost Software License, Version 1.0.
9 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
13 * headers.c - handle #includes in source files
15 * Using regular expressions provided as the variable $(HDRSCAN), headers()
16 * searches a file for #include files and phonies up a rule invocation:
17 * $(HDRRULE) <target> : <include files> ;
20 * headers() - scan a target for include files and call HDRRULE
23 * headers1() - using regexp, scan a file and build include LIST
40 #ifdef OPT_HEADER_CACHE_EXT
44 #ifndef OPT_HEADER_CACHE_EXT
45 static LIST
* headers1( LIST
*, OBJECT
* file
, int rec
, regexp
* re
[] );
50 * headers() - scan a target for include files and call HDRRULE
55 void headers( TARGET
* t
)
59 #ifndef OPT_HEADER_CACHE_EXT
62 regexp
* re
[ MAXINC
];
67 hdrscan
= var_get( root_module(), constant_HDRSCAN
);
68 if ( list_empty( hdrscan
) )
71 hdrrule
= var_get( root_module(), constant_HDRRULE
);
72 if ( list_empty( hdrrule
) )
76 out_printf( "header scan %s\n", object_str( t
->name
) );
78 /* Compile all regular expressions in HDRSCAN */
79 iter
= list_begin( hdrscan
);
80 end
= list_end( hdrscan
);
81 for ( ; ( rec
< MAXINC
) && iter
!= end
; iter
= list_next( iter
) )
83 re
[ rec
++ ] = regex_compile( list_item( iter
) );
86 /* Doctor up call to HDRRULE rule */
87 /* Call headers1() to get LIST of included files. */
91 lol_add( frame
->args
, list_new( object_copy( t
->name
) ) );
92 #ifdef OPT_HEADER_CACHE_EXT
93 lol_add( frame
->args
, hcache( t
, rec
, re
, hdrscan
) );
95 lol_add( frame
->args
, headers1( headlist
, t
->boundname
, rec
, re
) );
98 if ( lol_get( frame
->args
, 1 ) )
100 OBJECT
* rulename
= list_front( hdrrule
);
101 /* The third argument to HDRRULE is the bound name of $(<). */
102 lol_add( frame
->args
, list_new( object_copy( t
->boundname
) ) );
103 list_free( evaluate_rule( bindrule( rulename
, frame
->module
), rulename
, frame
) );
113 * headers1() - using regexp, scan a file and build include LIST.
116 #ifndef OPT_HEADER_CACHE_EXT
119 LIST
* headers1( LIST
* l
, OBJECT
* file
, int rec
, regexp
* re
[] )
124 static regexp
* re_macros
= 0;
126 #ifdef OPT_IMPROVED_PATIENCE_EXT
127 static int count
= 0;
129 if ( ( ( count
== 100 ) || !( count
% 1000 ) ) && DEBUG_MAKE
)
131 out_printf( "...patience...\n" );
136 /* The following regexp is used to detect cases where a file is included
137 * through a line like "#include MACRO".
139 if ( re_macros
== 0 )
141 OBJECT
* const re_str
= object_new(
142 "#[ \t]*include[ \t]*([A-Za-z][A-Za-z0-9_]*).*$" );
143 re_macros
= regex_compile( re_str
);
144 object_free( re_str
);
147 if ( !( f
= fopen( object_str( file
), "r" ) ) )
150 while ( fgets( buf
, sizeof( buf
), f
) )
152 for ( i
= 0; i
< rec
; ++i
)
153 if ( regexec( re
[ i
], buf
) && re
[ i
]->startp
[ 1 ] )
155 ( (char *)re
[ i
]->endp
[ 1 ] )[ 0 ] = '\0';
157 out_printf( "header found: %s\n", re
[ i
]->startp
[ 1 ] );
158 l
= list_push_back( l
, object_new( re
[ i
]->startp
[ 1 ] ) );
161 /* Special treatment for #include MACRO. */
162 if ( regexec( re_macros
, buf
) && re_macros
->startp
[ 1 ] )
164 OBJECT
* header_filename
;
167 ( (char *)re_macros
->endp
[ 1 ] )[ 0 ] = '\0';
170 out_printf( "macro header found: %s", re_macros
->startp
[ 1 ] );
172 macro_name
= object_new( re_macros
->startp
[ 1 ] );
173 header_filename
= macro_header_get( macro_name
);
174 object_free( macro_name
);
175 if ( header_filename
)
178 out_printf( " resolved to '%s'\n", object_str( header_filename
)
180 l
= list_push_back( l
, object_copy( header_filename
) );
185 out_printf( " ignored !!\n" );
195 void regerror( char const * s
)
197 out_printf( "re error %s\n", s
);