From 1195f9307c425ed28075a17671c13676b65f4a43 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Feb 2020 14:51:43 +0200 Subject: Add header/library search paths from compiler mode to sys_*_dirs --- libbuild2/cc/gcc.cxx | 78 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'libbuild2/cc/gcc.cxx') diff --git a/libbuild2/cc/gcc.cxx b/libbuild2/cc/gcc.cxx index 91a04f6..5d84f85 100644 --- a/libbuild2/cc/gcc.cxx +++ b/libbuild2/cc/gcc.cxx @@ -23,17 +23,61 @@ namespace build2 { using namespace bin; + void + gcc_extract_library_search_dirs (const strings& v, dir_paths& r) + { + for (auto i (v.begin ()), e (v.end ()); i != e; ++i) + { + const string& o (*i); + + dir_path d; + try + { + // -L can either be in the "-L" or "-L " form. + // + if (o == "-L") + { + if (++i == e) + break; // Let the compiler complain. + + d = dir_path (*i); + } + else if (o.compare (0, 2, "-L") == 0) + d = dir_path (o, 2, string::npos); + else + continue; + } + catch (const invalid_path& e) + { + fail << "invalid directory '" << e.path << "'" << " in option '" + << o << "'"; + } + + // Ignore relative paths. Or maybe we should warn? + // + if (!d.relative ()) + r.push_back (move (d)); + } + } + // Extract system header search paths from GCC (gcc/g++) or compatible - // (Clang, Intel) using the -v -E config_module:: + gcc_header_search_dirs (const process_path& xc, scope& rs) const { dir_paths r; + // Note also that any -I and similar that we may specify on the command + // line are factored into the output. + // cstrings args {xc.recall_string ()}; - append_options (args, rs, c_coptions); - append_options (args, rs, x_coptions); append_options (args, tstd); append_options (args, rs, x_mode); @@ -154,14 +198,14 @@ namespace build2 fail << "unable to extract " << x_lang << " compiler system header " << "search paths"; - return r; + return make_pair (move (r), size_t (0)); } // Extract system library search paths from GCC (gcc/g++) or compatible // (Clang, Intel) using the -print-search-dirs option. // - dir_paths config_module:: - gcc_library_search_paths (const process_path& xc, scope& rs) const + pair config_module:: + gcc_library_search_dirs (const process_path& xc, scope& rs) const { // The output of -print-search-dirs are a bunch of lines that start with // ": =" where name can be "install", "programs", or "libraries". @@ -176,16 +220,20 @@ namespace build2 // Maybe it's time we stop playing these games and start running // everything with LC_ALL=C? One drawback of this approach is that the // command that we print isn't exactly how we run. Maybe print it with - // the environment variables in front? + // the environment variables in front? Also there is MinGW GCC. + // + // Note also that any -L that we may specify on the command line are not + // factored into the output (unlike for headers above). // dir_paths r; + // Extract -L paths from the compiler mode. + // + gcc_extract_library_search_dirs (cast (rs[x_mode]), r); + size_t rn (r.size ()); + cstrings args {xc.recall_string ()}; - append_options (args, rs, c_coptions); - append_options (args, rs, x_coptions); append_options (args, tstd); - append_options (args, rs, x_loptions); - append_options (args, rs, c_loptions); append_options (args, rs, x_mode); args.push_back ("-print-search-dirs"); args.push_back (nullptr); @@ -267,7 +315,9 @@ namespace build2 break; } - return r; + return make_pair (move (r), rn); } + + } } -- cgit v1.1