]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/hdrmacro.cpp
2 * Copyright 1993, 2000 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * Copyright 2001-2004 David Abrahams.
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
14 * hdrmacro.c - handle header files that define macros used in #include
17 * we look for lines like "#define MACRO <....>" or '#define MACRO " "' in
18 * the target file. When found, we then phony up a rule invocation like:
20 * $(HDRRULE) <target> : <resolved included files> ;
23 * headers1() - scan a target for "#include MACRO" lines and try to resolve
27 * headers1() - using regexp, scan a file and build include LIST
45 /* this type is used to store a dictionary of file header macros */
46 typedef struct header_macro
49 OBJECT
* filename
; /* we could maybe use a LIST here ?? */
52 static struct hash
* header_macros_hash
= 0;
56 * headers() - scan a target for include files and call HDRRULE
61 void macro_headers( TARGET
* t
)
63 static regexp
* re
= 0;
68 out_printf( "macro header scan for %s\n", object_str( t
->name
) );
70 /* This regexp is used to detect lines of the form
71 * "#define MACRO <....>" or "#define MACRO "....."
72 * in the header macro files.
76 OBJECT
* const re_str
= object_new(
77 "^[ ]*#[ ]*define[ ]*([A-Za-z][A-Za-z0-9_]*)[ ]*"
78 "[<\"]([^\">]*)[\">].*$" );
79 re
= regex_compile( re_str
);
80 object_free( re_str
);
83 if ( !( f
= fopen( object_str( t
->boundname
), "r" ) ) )
86 while ( fgets( buf
, sizeof( buf
), f
) )
89 HEADER_MACRO
* v
= &var
;
91 if ( regexec( re
, buf
) && re
->startp
[ 1 ] )
95 /* we detected a line that looks like "#define MACRO filename */
96 ( (char *)re
->endp
[ 1 ] )[ 0 ] = '\0';
97 ( (char *)re
->endp
[ 2 ] )[ 0 ] = '\0';
100 out_printf( "macro '%s' used to define filename '%s' in '%s'\n",
101 re
->startp
[ 1 ], re
->startp
[ 2 ], object_str( t
->boundname
)
104 /* add macro definition to hash table */
105 if ( !header_macros_hash
)
106 header_macros_hash
= hashinit( sizeof( HEADER_MACRO
),
109 symbol
= object_new( re
->startp
[ 1 ] );
110 v
= (HEADER_MACRO
*)hash_insert( header_macros_hash
, symbol
, &found
115 v
->filename
= object_new( re
->startp
[ 2 ] ); /* never freed */
118 object_free( symbol
);
119 /* XXXX: FOR NOW, WE IGNORE MULTIPLE MACRO DEFINITIONS !! */
120 /* WE MIGHT AS WELL USE A LIST TO STORE THEM.. */
128 OBJECT
* macro_header_get( OBJECT
* macro_name
)
131 if ( header_macros_hash
&& ( v
= (HEADER_MACRO
*)hash_find(
132 header_macros_hash
, macro_name
) ) )
135 out_printf( "### macro '%s' evaluated to '%s'\n", object_str( macro_name
136 ), object_str( v
->filename
) );