From 5fb77d1609bb62db11ed640d089a08f34e943998 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 20 Jul 2016 09:03:36 +0200 Subject: Move ar/ranlib to bin.ar sub-module, load in cxx unless shared-only build This way we don't load/configure what we don't need. --- build2/bin/module | 9 +++ build2/bin/module.cxx | 170 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 111 insertions(+), 68 deletions(-) (limited to 'build2/bin') diff --git a/build2/bin/module b/build2/bin/module index 668e4d8..8fb9274 100644 --- a/build2/bin/module +++ b/build2/bin/module @@ -24,6 +24,15 @@ namespace build2 const variable_map&); bool + ar_init (scope&, + scope&, + const location&, + unique_ptr&, + bool, + bool, + const variable_map&); + + bool ld_init (scope&, scope&, const location&, diff --git a/build2/bin/module.cxx b/build2/bin/module.cxx index 194b409..c796c84 100644 --- a/build2/bin/module.cxx +++ b/build2/bin/module.cxx @@ -76,9 +76,6 @@ namespace build2 v.insert ("config.bin.target", true); v.insert ("config.bin.pattern", true); - v.insert ("config.bin.ar", true); - v.insert ("config.bin.ranlib", true); - v.insert ("config.bin.lib", true); v.insert ("config.bin.exe.lib", true); v.insert ("config.bin.liba.lib", true); @@ -277,71 +274,6 @@ namespace build2 dr << '\n' << " pattern " << cast (l); } - - // config.bin.ar - // config.bin.ranlib - // - // For config.bin.ar we have the default (plus the pattern) while - // ranlib should be explicitly specified by the user in order for us - // to use it (all targets that we currently care to support have the - // ar -s option but if that changes we can always force the use of - // ranlib for certain targets). - // - // Another idea is to refuse to use default 'ar' (without the pattern) - // if the host/build targets don't match. On the other hand, a cross- - // toolchain can be target-unprefixed. Also, without canonicalization, - // comparing targets will be unreliable. - // - auto pattern (r["bin.pattern"]); - - // Use the target to decide on the default binutils program names. - // - const string& tsys (cast (r["bin.target.system"])); - const char* ar_d (tsys == "win32-msvc" ? "lib" : "ar"); - - auto p (required (r, "config.bin.ar", path (apply (pattern, ar_d)))); - auto& v (optional (r, "config.bin.ranlib")); - - const path& ar (cast (p.first)); - const path& ranlib (v ? cast (v) : path ()); - - ar_info ari (guess_ar (ar, ranlib)); - - // If this is a new value (e.g., we are configuring), then print the - // report at verbosity level 2 and up (-v). - // - if (verb >= (p.second ? 2 : 3)) - { - //@@ Print project out root or name? See cxx. - - text << "bin.ar\n" - << " exe " << ar << '\n' - << " id " << ari.ar_id << '\n' - << " signature " << ari.ar_signature << '\n' - << " checksum " << ari.ar_checksum; - - if (!ranlib.empty ()) - { - text << "bin.ranlib\n" - << " exe " << ranlib << '\n' - << " id " << ari.ranlib_id << '\n' - << " signature " << ari.ranlib_signature << '\n' - << " checksum " << ari.ranlib_checksum; - } - } - - r.assign ("bin.ar.id") = move (ari.ar_id); - r.assign ("bin.ar.signature") = move (ari.ar_signature); - r.assign ("bin.ar.checksum") = move (ari.ar_checksum); - - if (!ranlib.empty ()) - { - r.assign ("bin.ranlib.id") = move (ari.ranlib_id); - r.assign ("bin.ranlib.signature") = - move (ari.ranlib_signature); - r.assign ("bin.ranlib.checksum") = - move (ari.ranlib_checksum); - } } // Cache some config values we will be needing below. @@ -432,6 +364,108 @@ namespace build2 } bool + ar_init (scope& r, + scope& b, + const location& loc, + unique_ptr&, + bool first, + bool, + const variable_map& config_hints) + { + tracer trace ("bin::ar_init"); + l5 ([&]{trace << "for " << b.out_path ();}); + + // Make sure the bin core is loaded. + // + if (!cast_false (b["bin.loaded"])) + load_module ("bin", r, b, loc, false, config_hints); + + // Enter module variables. + // + if (first) + { + auto& v (var_pool); + + v.insert ("config.bin.ar", true); + v.insert ("config.bin.ranlib", true); + } + + // Configure. + // + if (first) + { + // config.bin.ar + // config.bin.ranlib + // + // For config.bin.ar we have the default (plus the pattern) while + // ranlib should be explicitly specified by the user in order for us + // to use it (all targets that we currently care to support have the + // ar -s option but if that changes we can always force the use of + // ranlib for certain targets). + // + // Another idea is to refuse to use default 'ar' (without the pattern) + // if the host/build targets don't match. On the other hand, a cross- + // toolchain can be target-unprefixed. Also, without canonicalization, + // comparing targets will be unreliable. + // + auto pattern (r["bin.pattern"]); + + // Use the target to decide on the default binutils program names. + // + const string& tsys (cast (r["bin.target.system"])); + const char* ar_d (tsys == "win32-msvc" ? "lib" : "ar"); + + auto p (config::required (r, + "config.bin.ar", + path (apply (pattern, ar_d)))); + auto& v (config::optional (r, "config.bin.ranlib")); + + const path& ar (cast (p.first)); + const path& ranlib (v ? cast (v) : path ()); + + ar_info ari (guess_ar (ar, ranlib)); + + // If this is a new value (e.g., we are configuring), then print the + // report at verbosity level 2 and up (-v). + // + if (verb >= (p.second ? 2 : 3)) + { + //@@ Print project out root or name? See cxx. + + text << "bin.ar\n" + << " exe " << ar << '\n' + << " id " << ari.ar_id << '\n' + << " signature " << ari.ar_signature << '\n' + << " checksum " << ari.ar_checksum; + + if (!ranlib.empty ()) + { + text << "bin.ranlib\n" + << " exe " << ranlib << '\n' + << " id " << ari.ranlib_id << '\n' + << " signature " << ari.ranlib_signature << '\n' + << " checksum " << ari.ranlib_checksum; + } + } + + r.assign ("bin.ar.id") = move (ari.ar_id); + r.assign ("bin.ar.signature") = move (ari.ar_signature); + r.assign ("bin.ar.checksum") = move (ari.ar_checksum); + + if (!ranlib.empty ()) + { + r.assign ("bin.ranlib.id") = move (ari.ranlib_id); + r.assign ("bin.ranlib.signature") = + move (ari.ranlib_signature); + r.assign ("bin.ranlib.checksum") = + move (ari.ranlib_checksum); + } + } + + return true; + } + + bool ld_init (scope& r, scope& b, const location& loc, -- cgit v1.1