• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright (c) 2003 Dr John Maddock
4  * Use, modification and distribution is subject to the
5  * Boost Software License, Version 1.0. (See accompanying file
6  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  *
8  * This file implements the following:
9  *    void bcp_implementation::add_path(const fs::path& p)
10  *    void bcp_implementation::add_directory(const fs::path& p)
11  *    void bcp_implementation::add_file(const fs::path& p)
12  *    void bcp_implementation::add_dependent_lib(const std::string& libname, const fs::path& p, const fileview& view)
13  */
14 
15 #include "bcp_imp.hpp"
16 #include "fileview.hpp"
17 #include <boost/regex.hpp>
18 #include <boost/filesystem/operations.hpp>
19 #include <boost/filesystem/exception.hpp>
20 #include <iostream>
21 
22 
add_path(const fs::path & p)23 void bcp_implementation::add_path(const fs::path& p)
24 {
25    fs::path normalized_path = p;
26     normalized_path.normalize();
27    if(fs::exists(m_boost_path / normalized_path))
28    {
29       if(fs::is_directory(m_boost_path / normalized_path))
30          add_directory(normalized_path);
31       else
32          add_file(normalized_path);
33    }
34    else
35    {
36       std::cerr << "CAUTION: dependent file " << p.string() << " does not exist." << std::endl;
37       std::cerr << "   Found while scanning file " << m_dependencies[p].string() << std::endl;
38    }
39 }
40 
add_directory(const fs::path & p)41 void bcp_implementation::add_directory(const fs::path& p)
42 {
43    //
44    // Don't add files created by build system:
45    //
46    if((p.leaf() == "bin") || (p.leaf() == "bin-stage"))
47       return;
48    //
49    // Don't add version control directories:
50    //
51    if((p.leaf() == "CVS") || (p.leaf() == ".svn"))
52       return;
53    //
54    // don't add directories not under version control:
55    //
56    if(m_cvs_mode && !fs::exists(m_boost_path / p / "CVS/Entries"))
57       return;
58    if(m_svn_mode && !fs::exists(m_boost_path / p / ".svn/entries"))
59       return;
60    //
61    // enermerate files and directories:
62    //
63    fs::directory_iterator i(m_boost_path / p);
64    fs::directory_iterator j;
65    while(i != j)
66    {
67       //
68       // we need to convert *i back into
69       // a relative path, what follows is a hack:
70       //
71       std::string s(i->path().string());
72       if(m_boost_path.string().size())
73          s.erase(0, m_boost_path.string().size() + 1);
74       fs::path np = s;
75       if(!m_dependencies.count(np))
76       {
77          m_dependencies[np] = p; // set up dependency tree
78          add_pending_path(np);
79       }
80       ++i;
81    }
82 }
83 
add_file(const fs::path & p)84 void bcp_implementation::add_file(const fs::path& p)
85 {
86    //
87    // if the file does not exist in cvs then don't do anything with it:
88    //
89    if((m_cvs_mode || m_svn_mode) && (m_cvs_paths.find(p) == m_cvs_paths.end()))
90       return;
91    //
92    // if we've already seen the file return:
93    //
94    if(m_copy_paths.find(p) != m_copy_paths.end())
95       return;
96    //
97    // add the file to our list:
98    //
99    m_copy_paths.insert(p);
100    //
101    // if this is a source file, scan for dependencies:
102    //
103    if(is_source_file(p))
104    {
105       add_file_dependencies(p, false);
106    }
107    if(is_jam_file(p) && m_namespace_name.size() && ((std::distance(p.begin(), p.end()) < 3) || (*p.begin() != "tools") || (*++p.begin() != "build")))
108    {
109       //
110       // We're doing a rename of namespaces and library names
111       // so scan for names of libraries:
112       //
113       static const boost::regex e(
114          "\\<lib\\s+(boost\\w+)\\s+[:;]"
115          );
116 
117       fileview view(m_boost_path / p);
118       boost::regex_token_iterator<const char*> i(view.begin(), view.end(), e, 1);
119       boost::regex_token_iterator<const char*> j;
120       while(i != j)
121       {
122          m_lib_names.insert(*i);
123          ++i;
124       }
125       static const std::pair<fs::path, std::string> specials_library_names[] = {
126             std::pair<fs::path, std::string>("libs/python/build/Jamfile.v2", "boost_python"),
127             std::pair<fs::path, std::string>("libs/python/build/Jamfile.v2", "boost_python3"),
128       };
129 
130       for(unsigned int n = 0; n < (sizeof(specials_library_names)/sizeof(specials_library_names[0])); ++n)
131       {
132          if(0 == compare_paths(specials_library_names[n].first, p))
133          {
134             m_lib_names.insert(specials_library_names[n].second);
135          }
136       }
137    }
138    //
139    // if this is a html file, scan for dependencies:
140    //
141    if(is_html_file(p))
142    {
143       static const boost::regex e(
144          "<(?:img[^>]*src=|link[^>]*href=)(\"[^\"]+\"|\\w+)[^>]*>"
145          );
146 
147       fileview view(m_boost_path / p);
148       boost::regex_token_iterator<const char*> i(view.begin(), view.end(), e, 1);
149       boost::regex_token_iterator<const char*> j;
150       while(i != j)
151       {
152          //
153          // extract the dependent name:
154          //
155          std::string s(*i);
156          if(s[0] == '\"')
157          {
158             // remove quotes:
159             assert(s.size() > 2);
160             s.erase(0, 1);
161             s.erase(s.size() - 1);
162          }
163          //
164          // Remove any target suffix:
165          //
166          std::string::size_type n = s.find('#');
167          if(n != std::string::npos)
168          {
169             s.erase(n);
170          }
171          //
172          // if the name starts with ./ remove it
173          // or we'll get an error:
174          if(s.compare(0, 2, "./") == 0)
175             s.erase(0, 2);
176          if(s.find(':') == std::string::npos)
177          {
178             // only concatonate if it's a relative path
179             // rather than a URL:
180             fs::path dep(p.branch_path() / s);
181             if(!m_dependencies.count(dep))
182             {
183                m_dependencies[dep] = p; // set up dependency tree
184                add_pending_path(dep);
185             }
186          }
187          ++i;
188       }
189    }
190    //
191    // now scan for "special" dependencies:
192    // anything that we can't automatically detect...
193    //
194 static const std::pair<fs::path, fs::path>
195    specials[] = {
196       std::pair<fs::path, fs::path>("tools/build/src/kernel/modules.jam", "libs/predef/check"),
197       std::pair<fs::path, fs::path>("tools/build/src/kernel/modules.jam", "libs/predef/tools"),
198       std::pair<fs::path, fs::path>("tools/build/src/kernel/modules.jam", "tools/boost_install/boost-install.jam"),
199       std::pair<fs::path, fs::path>("tools/build/src/kernel/modules.jam", "tools/boost_install/boost-install-dirs.jam"),
200       std::pair<fs::path, fs::path>("tools/build/src/kernel/modules.jam", "tools/boost_install/Jamfile"),
201       std::pair<fs::path, fs::path>("tools/build/src/kernel/modules.jam", "libs/headers"),
202       std::pair<fs::path, fs::path>("libs/test/build/Jamfile.v2", "libs/timer/src"),
203       std::pair<fs::path, fs::path>("libs/test/build/Jamfile.v2", "libs/timer/build"),
204       std::pair<fs::path, fs::path>("boost/atomic/capabilities.hpp", "boost/atomic/detail"),
205       std::pair<fs::path, fs::path>("boost/chrono/chrono.hpp", "libs/chrono/src"),
206       std::pair<fs::path, fs::path>("boost/chrono/chrono.hpp", "libs/chrono/build"),
207       std::pair<fs::path, fs::path>("boost/context/execution_context.hpp", "libs/context/src"),
208       std::pair<fs::path, fs::path>("boost/context/execution_context.hpp", "libs/context/build"),
209       std::pair<fs::path, fs::path>("boost/context/fcontext.hpp", "libs/context/src"),
210       std::pair<fs::path, fs::path>("boost/context/fcontext.hpp", "libs/context/build"),
211       std::pair<fs::path, fs::path>("boost/context/fixedsize_stack.hpp", "libs/context/src"),
212       std::pair<fs::path, fs::path>("boost/context/fixedsize_stack.hpp", "libs/context/build"),
213       std::pair<fs::path, fs::path>("boost/context/protected_fixedsize_stack.hpp", "libs/context/src"),
214       std::pair<fs::path, fs::path>("boost/context/protected_fixedsize_stack.hpp", "libs/context/build"),
215       std::pair<fs::path, fs::path>("boost/context/segmented_stack.hpp", "libs/context/src"),
216       std::pair<fs::path, fs::path>("boost/context/segmented_stack.hpp", "libs/context/build"),
217       std::pair<fs::path, fs::path>("boost/context/stack_context.hpp", "libs/context/src"),
218       std::pair<fs::path, fs::path>("boost/context/stack_context.hpp", "libs/context/build"),
219       std::pair<fs::path, fs::path>("boost/context/stack_traits.hpp", "libs/context/src"),
220       std::pair<fs::path, fs::path>("boost/context/stack_traits.hpp", "libs/context/build"),
221       std::pair<fs::path, fs::path>("boost/cerrno.hpp", "libs/system/build"),
222       std::pair<fs::path, fs::path>("boost/cerrno.hpp", "libs/system/src"),
223       std::pair<fs::path, fs::path>("libs/thread/build", "boost/system"),
224       std::pair<fs::path, fs::path>("libs/thread/build", "boost/cerrno.hpp"),
225       std::pair<fs::path, fs::path>("libs/thread/build", "boost/chrono"),
226       std::pair<fs::path, fs::path>("boost/filesystem/convenience.hpp", "boost/filesystem.hpp"),
227       std::pair<fs::path, fs::path>("boost/filesystem/exception.hpp", "boost/filesystem.hpp"),
228       std::pair<fs::path, fs::path>("boost/filesystem/fstream.hpp", "boost/filesystem.hpp"),
229       std::pair<fs::path, fs::path>("boost/filesystem/operations.hpp", "boost/filesystem.hpp"),
230       std::pair<fs::path, fs::path>("boost/filesystem/path.hpp", "boost/filesystem.hpp"),
231       std::pair<fs::path, fs::path>("boost/filesystem.hpp", "libs/filesystem/build"),
232       std::pair<fs::path, fs::path>("boost/filesystem.hpp", "libs/filesystem/v2"),
233       std::pair<fs::path, fs::path>("boost/filesystem.hpp", "libs/filesystem/v3"),
234       std::pair<fs::path, fs::path>("boost/config.hpp", "boost/config"),
235       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "libs/config/checks"),
236       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "libs/config/test"),
237       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "libs/headers/build"),
238       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "tools/boost_install/BoostConfig.cmake"),
239       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "tools/boost_install/BoostDetectToolset.cmake"),
240       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "tools/boost_install/boost-install.jam"),
241       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "tools/boost_install/boost-install-dirs.jam"),
242       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "boost-build.jam"),
243       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "boostcpp.jam"),
244       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "bootstrap.bat"),
245       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "bootstrap.sh"),
246       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "Jamroot"),
247       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "INSTALL"),
248       std::pair<fs::path, fs::path>("tools/build/boost-build.jam", "LICENSE_1_0.txt"),
249       std::pair<fs::path, fs::path>("boost/preprocessor/iterate.hpp", "boost/preprocessor/iteration"),
250       std::pair<fs::path, fs::path>("boost/preprocessor/slot/slot.hpp", "boost/preprocessor/slot/detail"),
251       std::pair<fs::path, fs::path>("boost/function.hpp", "boost/function/detail"),
252       std::pair<fs::path, fs::path>("boost/regex/config.hpp", "boost/regex/user.hpp"),
253       std::pair<fs::path, fs::path>("boost/signals/signal_template.hpp", "boost/function"),
254       std::pair<fs::path, fs::path>("boost/mpl/list.hpp", "boost/mpl/list"),
255       std::pair<fs::path, fs::path>("boost/mpl/list_c.hpp", "boost/mpl/list"),
256       std::pair<fs::path, fs::path>("boost/mpl/vector.hpp", "boost/mpl/vector"),
257       std::pair<fs::path, fs::path>("boost/mpl/deque.hpp", "boost/mpl/vector"),
258       std::pair<fs::path, fs::path>("boost/mpl/vector_c.hpp", "boost/mpl/vector"),
259       std::pair<fs::path, fs::path>("boost/mpl/map.hpp", "boost/mpl/map"),
260       std::pair<fs::path, fs::path>("boost/mpl/set.hpp", "boost/mpl/set"),
261       std::pair<fs::path, fs::path>("boost/mpl/set_c.hpp", "boost/mpl/set"),
262       std::pair<fs::path, fs::path>("boost/mpl/aux_/include_preprocessed.hpp", "boost/mpl/aux_/preprocessed"),
263       std::pair<fs::path, fs::path>("boost/mpl/vector/aux_/include_preprocessed.hpp", "boost/mpl/vector/aux_/preprocessed"),
264       std::pair<fs::path, fs::path>("boost/mpl/set/aux_/include_preprocessed.hpp", "boost/mpl/set/aux_/preprocessed"),
265       std::pair<fs::path, fs::path>("boost/mpl/map/aux_/include_preprocessed.hpp", "boost/mpl/map/aux_/preprocessed"),
266       std::pair<fs::path, fs::path>("boost/mpl/list/aux_/include_preprocessed.hpp", "boost/mpl/list/aux_/preprocessed"),
267       std::pair<fs::path, fs::path>("libs/graph/src/python/visitor.hpp", "libs/graph/src/python"),
268       std::pair<fs::path, fs::path>("boost/test/detail/config.hpp", "libs/test/src"),
269       std::pair<fs::path, fs::path>("boost/test/detail/config.hpp", "libs/test/build"),
270       std::pair<fs::path, fs::path>("boost/test/detail/config.hpp", "libs/predef/build.jam"),
271       std::pair<fs::path, fs::path>("boost/test/detail/config.hpp", "libs/predef/check"),
272       std::pair<fs::path, fs::path>("boost/typeof.hpp", "boost/typeof/incr_registration_group.hpp"),
273       std::pair<fs::path, fs::path>("boost/function_types/detail/pp_loop.hpp", "boost/function_types/detail/pp_cc_loop"),
274       std::pair<fs::path, fs::path>("boost/function_types/components.hpp", "boost/function_types/detail/components_impl"),
275       std::pair<fs::path, fs::path>("boost/function_types/detail/pp_loop.hpp", "boost/function_types/detail"),
276       std::pair<fs::path, fs::path>("boost/math/tools/rational.hpp", "boost/math/tools/detail"),
277       std::pair<fs::path, fs::path>("boost/proto/repeat.hpp", "boost/proto/detail/local.hpp"),
278       std::pair<fs::path, fs::path>("boost/signals/signal_template.hpp", "boost/function"),
279       std::pair<fs::path, fs::path>("boost/preprocessor/slot/counter.hpp", "boost/preprocessor/slot/detail/counter.hpp"),
280       std::pair<fs::path, fs::path>("boost/graph/distributed/detail/tag_allocator.hpp", "libs/graph_parallel"),
281       std::pair<fs::path, fs::path>("boost/graph/distributed/mpi_process_group.hpp", "libs/graph_parallel"),
282       std::pair<fs::path, fs::path>("libs/coroutine/build/Jamfile.v2", "libs/context/src"),
283       std::pair<fs::path, fs::path>("libs/coroutine/build/Jamfile.v2", "libs/context/build"),
284       std::pair<fs::path, fs::path>("libs/fiber/build/Jamfile.v2", "libs/context/src"),
285       std::pair<fs::path, fs::path>("libs/fiber/build/Jamfile.v2", "libs/context/build"),
286    };
287 
288    for(unsigned int n = 0; n < (sizeof(specials)/sizeof(specials[0])); ++n)
289    {
290       if(0 == compare_paths(specials[n].first, p))
291       {
292          if(!m_dependencies.count(specials[n].second))
293          {
294             m_dependencies[specials[n].second] = p; // set up dependency tree
295             add_pending_path(specials[n].second);
296          }
297       }
298    }
299 
300 }
301 
add_file_dependencies(const fs::path & p,bool scanfile)302 void bcp_implementation::add_file_dependencies(const fs::path& p, bool scanfile)
303 {
304    static const boost::regex e(
305       "^[[:blank:]]*(?://@bcp[[:blank:]]+([^\\n]*)\n)?#[[:blank:]]*include[[:blank:]]*[\"<]([^\">]+)[\">]"
306       );
307 
308    if(!m_dependencies.count(p))
309       m_dependencies[p] = p; // set terminal dependency
310 
311    fileview view;
312    if(scanfile)
313       view.open(p);
314    else
315       view.open(m_boost_path / p);
316    if(m_license_mode && !scanfile)
317       scan_license(p, view);
318    const int subs[] = { 1, 2 };
319    boost::regex_token_iterator<const char*> i(view.begin(), view.end(), e, subs);
320    boost::regex_token_iterator<const char*> j;
321    while(i != j)
322    {
323       //
324       // *i contains the name of the include file,
325       // check first for a file of that name in the
326       // same directory as the file we are scanning,
327       // and if that fails, then check the boost-root:
328       //
329       fs::path include_file;
330       try{
331          std::string discart_message = *i;
332          ++i;
333          if(discart_message.size())
334          {
335             // The include is optional and should be discarded:
336             std::cout << "Optional functionality won't be copied: " << discart_message << std::endl;
337             std::cout << "Add the file " << *i << " to the list of dependencies to extract to copy this functionality." << std::endl;
338             ++i;
339             continue;
340          }
341          include_file = i->str();
342          fs::path test_file(m_boost_path / p.branch_path() / include_file);
343          if(fs::exists(test_file) && !fs::is_directory(test_file) && (p.branch_path().string() != "boost"))
344          {
345             if(!m_dependencies.count(p.branch_path() / include_file))
346             {
347                m_dependencies[p.branch_path() / include_file] = p;
348                add_pending_path(p.branch_path() / include_file);
349             }
350          }
351          else if(fs::exists(m_boost_path / include_file))
352          {
353             if(!m_dependencies.count(include_file))
354             {
355                m_dependencies[include_file] = p;
356                add_pending_path(include_file);
357             }
358          }
359          ++i;
360       }
361       catch(const fs::filesystem_error&)
362       {
363          std::cerr << "Can't parse filename " << *i << " included by file " << p.string() << std::endl;
364          ++i;
365          continue;
366       }
367    }
368    //
369    // Now we need to scan for Boost.Preprocessor includes that
370    // are included via preprocessor iteration:
371    //
372    static const boost::regex ppfiles("^[[:blank:]]*#[[:blank:]]*define[[:blank:]]+(?:BOOST_PP_FILENAME|BOOST_PP_ITERATION_PARAMS|BOOST_PP_INDIRECT_SELF)(?:[^\\n]|\\\\\\n)+?[\"<]([^\">]+)[\">]");
373    i = boost::regex_token_iterator<const char*>(view.begin(), view.end(), ppfiles, 1);
374    while(i != j)
375    {
376       //
377       // *i contains the name of the include file,
378       // check first for a file of that name in the
379       // same directory as the file we are scanning,
380       // and if that fails, then check the boost-root:
381       //
382       fs::path include_file;
383       try{
384          include_file = i->str();
385       }
386       catch(const fs::filesystem_error&)
387       {
388          std::cerr << "Can't parse filename " << *i << " included by file " << p.string() << std::endl;
389          ++i;
390          continue;
391       }
392       fs::path test_file(m_boost_path / p.branch_path() / include_file);
393       if(fs::exists(test_file) && !fs::is_directory(test_file) && (p.branch_path().string() != "boost"))
394       {
395          if(!m_dependencies.count(p.branch_path() / include_file))
396          {
397             m_dependencies[p.branch_path() / include_file] = p;
398             add_pending_path(p.branch_path() / include_file);
399          }
400       }
401       else if(fs::exists(m_boost_path / include_file))
402       {
403          if(!m_dependencies.count(include_file))
404          {
405             m_dependencies[include_file] = p;
406             add_pending_path(include_file);
407          }
408       }
409       else
410       {
411          std::cerr << "CAUTION: Boost.Preprocessor iterated file " << include_file.string() << " does not exist." << std::endl;
412       }
413       ++i;
414    }
415 
416    //
417    // Scan for any #include MACRO includes that we don't recognise.
418    //
419    // Begin by declaring all of the macros that get #included that
420    // we know about and are correctly handled as special cases:
421    //
422    static const std::string known_macros[] = {
423       "AUX778076_INCLUDE_STRING",
424       "BOOST_PP_STRINGIZE(boost/mpl/aux_/preprocessed/AUX778076_PREPROCESSED_HEADER)",
425       "BOOST_USER_CONFIG",
426       "BOOST_COMPILER_CONFIG",
427       "BOOST_STDLIB_CONFIG",
428       "BOOST_PLATFORM_CONFIG",
429       "BOOST_PP_FILENAME_1",
430       "BOOST_PP_ITERATION_PARAMS_1",
431       "BOOST_PP_FILENAME_2",
432       "BOOST_PP_ITERATION_PARAMS_2",
433       "BOOST_PP_FILENAME_3",
434       "BOOST_PP_ITERATION_PARAMS_3",
435       "BOOST_PP_FILENAME_4",
436       "BOOST_PP_ITERATION_PARAMS_4",
437       "BOOST_PP_FILENAME_5",
438       "BOOST_PP_ITERATION_PARAMS_5",
439       "BOOST_PP_INDIRECT_SELF",
440       "BOOST_PP_INCLUDE_SELF()",
441       "BOOST_PP_ITERATE",
442       "BOOST_PP_LOCAL_ITERATE",
443       "BOOST_PP_ITERATE()",
444       "BOOST_PP_LOCAL_ITERATE()",
445       "BOOST_PP_ASSIGN_SLOT(1)",
446       "BOOST_PP_ASSIGN_SLOT(2)",
447       "BOOST_PP_ASSIGN_SLOT(3)",
448       "BOOST_PP_ASSIGN_SLOT(4)",
449       "BOOST_PP_ASSIGN_SLOT(5)",
450       "BOOST_ABI_PREFIX",
451       "BOOST_ABI_SUFFIX",
452       "BOOST_PP_STRINGIZE(boost/mpl/aux_/preprocessed/AUX_PREPROCESSED_HEADER)",
453       "BOOST_PP_STRINGIZE(boost/mpl/list/AUX778076_HEADER)",
454       "BOOST_PP_STRINGIZE(boost/mpl/list/AUX778076_LIST_C_HEADER)",
455       "BOOST_PP_STRINGIZE(boost/mpl/list/AUX778076_LIST_HEADER)",
456       "BOOST_PP_STRINGIZE(boost/mpl/map/aux_/preprocessed/AUX778076_HEADER)",
457       "BOOST_PP_STRINGIZE(boost/mpl/map/AUX778076_MAP_HEADER)",
458       "BOOST_PP_STRINGIZE(boost/mpl/set/aux_/preprocessed/AUX778076_HEADER)",
459       "BOOST_PP_STRINGIZE(boost/mpl/set/AUX778076_SET_HEADER)",
460       "BOOST_PP_STRINGIZE(boost/mpl/set/AUX778076_SET_C_HEADER)",
461       "BOOST_PP_STRINGIZE(boost/mpl/vector/AUX778076_VECTOR_HEADER)",
462       "BOOST_PP_STRINGIZE(boost/mpl/vector/aux_/preprocessed/AUX778076_HEADER)",
463       "BOOST_PP_STRINGIZE(boost/mpl/vector/AUX778076_DEQUE_HEADER)",
464       "BOOST_PP_STRINGIZE(boost/mpl/vector/AUX778076_VECTOR_C_HEADER)",
465       "BOOST_REGEX_USER_CONFIG",
466       "BGL_PYTHON_EVENTS_HEADER",
467       "B1",
468       "B2",
469       "BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()",
470       "BOOST_SLIST_HEADER",
471       "BOOST_HASH_SET_HEADER",
472       "BOOST_HASH_MAP_HEADER",
473       "BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE",
474       "BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE",
475       "BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE",
476       "BOOST_FT_loop",
477       "BOOST_FT_AL_PREPROCESSED",
478       "BOOST_FT_AL_INCLUDE_FILE",
479       "__FILE__",
480       "BOOST_FT_cc_file",
481       "BOOST_FT_variate_file",
482       "BOOST_USER_CONFIG",
483       "BOOST_HEADER()",
484       "BOOST_TR1_STD_HEADER(utility)",
485       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(tuple))",
486       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(random))",
487       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(array))",
488       "BOOST_TR1_HEADER(cmath)",
489       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex))",
490       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(functional))",
491       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(memory))",
492       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(regex))",
493       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(type_traits))",
494       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(unordered_map))",
495       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(unordered_set))",
496       "BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(utility))",
497       "BOOST_PROTO_LOCAL_ITERATE()",
498       "BOOST_SIGNAL_FUNCTION_N_HEADER",
499       "BOOST_PP_UPDATE_COUNTER()",
500   };
501 
502    static const boost::regex indirect_includes("^[[:blank:]]*#[[:blank:]]*include[[:blank:]]+([^\"<][^\n]*?)[[:blank:]]*$");
503    i = boost::regex_token_iterator<const char*>(view.begin(), view.end(), indirect_includes, 1);
504    while(i != j)
505    {
506       const std::string* known_macros_end = known_macros + sizeof(known_macros)/sizeof(known_macros[0]);
507       if(known_macros_end == std::find(known_macros, known_macros_end, i->str()))
508       {
509          std::cerr << "CAUTION: don't know how to trace depenencies through macro: \"" << *i << "\" in file: " << p.string() << std::endl;
510       }
511       ++i;
512    }
513    //
514    // if the file contains a cpp_main / unit_test_main / test_main
515    // it is dependent upon Boost.test even if it doesn't
516    // include any of the Boost.test headers directly.
517    //
518    static const boost::regex m("^\\s*int\\s+(?:cpp_main|test_main|unit_test_main)");
519    boost::cmatch what;
520    if(boost::regex_search(view.begin(), view.end(), what, m))
521    {
522       add_dependent_lib("test", p, view);
523    }
524    if(!scanfile)
525    {
526       //
527       // grab the name of the library to which the header belongs,
528       // and if that library has source then add the source to our
529       // list:
530       //
531       // this regex catches boost/libname.hpp or boost/libname/whatever:
532       //
533       static const boost::regex lib1("boost/([^\\./]+)(?!detail).*");
534       boost::smatch swhat;
535       std::string gs(p.generic_string());
536       if(boost::regex_match(gs, swhat, lib1))
537       {
538          add_dependent_lib(swhat.str(1), p, view);
539       }
540       //
541       // and this one catches boost/x/y/whatever (for example numeric/ublas):
542       //
543       static const boost::regex lib2("boost/([^/]+/[^/]+)/(?!detail).*");
544       gs = p.generic_string();
545       if(boost::regex_match(gs, swhat, lib2))
546       {
547          add_dependent_lib(swhat.str(1), p, view);
548       }
549    }
550    if(m_list_namespaces)
551    {
552       //
553       // scan for top level namespaces and add to our list:
554       //
555       static const boost::regex namespace_scanner(
556          "^(?<!\\\\\\n)[[:blank:]]*+namespace\\s++(\\w++)\\s++(\\{[^{}]*(?:(?2)[^{}]*)*\\})"
557          );
558       i = boost::regex_token_iterator<const char*>(view.begin(), view.end(), namespace_scanner, 1);
559       while(i != j)
560       {
561          if(m_top_namespaces.count(*i) == 0)
562          {
563             //std::cout << *i << " (Found in " << p << ")" << std::endl;
564             m_top_namespaces[*i] = p;
565          }
566          ++i;
567       }
568    }
569 }
570