aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/cc/link-rule.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-10-07 09:41:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-10-07 09:41:13 +0200
commit4d43fc686427252367576bb1a37724bb45958358 (patch)
treeccc5bef784457788a1ff5c5f93c39f5b9090b107 /libbuild2/cc/link-rule.cxx
parenta90eecb47438303ae3f6409276f8d9bb77c9f6fc (diff)
Pass MSVC system library search paths to linker if LIB envvar is unset
Diffstat (limited to 'libbuild2/cc/link-rule.cxx')
-rw-r--r--libbuild2/cc/link-rule.cxx57
1 files changed, 44 insertions, 13 deletions
diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx
index 5341a2e..cd31058 100644
--- a/libbuild2/cc/link-rule.cxx
+++ b/libbuild2/cc/link-rule.cxx
@@ -2105,11 +2105,22 @@ namespace build2
// kind of a hybrid).
//
cstrings args {nullptr}; // Reserve one for config.bin.ar/config.x.
+ strings sargs; // Argument tail with storage.
- // Storage.
+ // Stored args.
//
string arg1, arg2;
- strings sargs;
+ strings sargs1;
+
+ // Shallow-copy over stored args to args. Note that this must only be
+ // done once we are finished appending to stored args because of
+ // potential reallocations.
+ //
+ auto append_args = [&args] (const strings& sargs)
+ {
+ for (const string& a: sargs)
+ args.push_back (a.c_str ());
+ };
if (lt.static_library ())
{
@@ -2190,14 +2201,36 @@ namespace build2
// Extra system library dirs (last).
//
- // @@ /LIBPATH:<path>, not /LIBPATH <path>
- //
assert (sys_lib_dirs_extra <= sys_lib_dirs.size ());
- append_option_values (
- args,
- cclass == compiler_class::msvc ? "/LIBPATH:" : "-L",
- sys_lib_dirs.begin () + sys_lib_dirs_extra, sys_lib_dirs.end (),
- [] (const dir_path& d) {return d.string ().c_str ();});
+
+ if (tsys == "win32-msvc")
+ {
+ // If we have no LIB environment variable set, then we add all of
+ // them. But we want extras to come first.
+ //
+ auto b (sys_lib_dirs.begin ());
+ auto m (b + sys_lib_dirs_extra);
+ auto e (sys_lib_dirs.end ());
+
+ for (auto i (m); i != e; ++i)
+ sargs1.push_back ("/LIBPATH:" + i->string ());
+
+ if (!getenv ("LIB"))
+ {
+ for (auto i (b); i != m; ++i)
+ sargs1.push_back ("/LIBPATH:" + i->string ());
+ }
+
+ append_args (sargs1);
+ }
+ else
+ {
+ append_option_values (
+ args,
+ "-L",
+ sys_lib_dirs.begin () + sys_lib_dirs_extra, sys_lib_dirs.end (),
+ [] (const dir_path& d) {return d.string ().c_str ();});
+ }
// Handle soname/rpath.
//
@@ -2649,11 +2682,9 @@ namespace build2
if (!manifest.empty () && tsys == "mingw32")
sargs.push_back (relative (manifest).string ());
- // Shallow-copy sargs to args. Why not do it as we go along pushing into
- // sargs? Because of potential reallocations in sargs.
+ // Shallow-copy sargs over to args.
//
- for (const string& a: sargs)
- args.push_back (a.c_str ());
+ append_args (sargs);
if (!lt.static_library ())
{