From db3534da1bcbf286df7ac4c8736f5c5157399ced Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 17 Jul 2016 08:18:45 +0200 Subject: Redesign obj to exe/lib mapping Specifically: * objso{} and libso{} target types have been renamed to objs{} and libs{} * obje{} has been added (so now we have obje{}, obja{}, and objs{}) * obje{} is now used for building exe{} * object file extensions have been changed to use "hierarchical extensions" that reflect the extension of the corresponding exe/lib target (instead of the -so suffix we used), specifically: obje{}: foo.o, (UNIX), foo.exe.o (MinGW), foo.exe.obj (Windows) obja{}: foo.a.o (UNIX, MinGW), foo.lib.obj (Windows) objs{}: foo.so.o (UNIX), foo.dylib.o (Darwin), foo.dll.o (MinGW), foo.dll.obj (Windows) --- build2/cxx/compile.cxx | 80 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 17 deletions(-) (limited to 'build2/cxx/compile.cxx') diff --git a/build2/cxx/compile.cxx b/build2/cxx/compile.cxx index 504df7f..645e818 100644 --- a/build2/cxx/compile.cxx +++ b/build2/cxx/compile.cxx @@ -21,6 +21,7 @@ #include #include +#include #include @@ -69,15 +70,57 @@ namespace build2 path_target& t (static_cast (xt)); scope& rs (t.root_scope ()); + const string& cid (cast (rs["cxx.id"])); + const string& tsys (cast (rs["cxx.target.system"])); const string& tclass (cast (rs["cxx.target.class"])); + otype ct (compile_type (t)); + // Derive file name from target name. // if (t.path ().empty ()) { - const char* ext (cid == "msvc" ? "obj" : "o"); - t.derive_path (ext, nullptr, (t.is_a () ? "-so" : nullptr)); + const char* e (nullptr); + + if (tsys == "win32-msvc") + { + switch (ct) + { + case otype::e: e = "exe.obj"; break; + case otype::a: e = "lib.obj"; break; + case otype::s: e = "dll.obj"; break; + } + } + else if (tsys == "mingw32") + { + switch (ct) + { + case otype::e: e = "exe.o"; break; + case otype::a: e = "a.o"; break; + case otype::s: e = "dll.o"; break; + } + } + else if (tsys == "darwin") + { + switch (ct) + { + case otype::e: e = "o"; break; + case otype::a: e = "a.o"; break; + case otype::s: e = "dylib.o"; break; + } + } + else + { + switch (ct) + { + case otype::e: e = "o"; break; + case otype::a: e = "a.o"; break; + case otype::s: e = "so.o"; break; + } + } + + t.derive_path (e); } // Inject dependency on the output directory. @@ -102,7 +145,7 @@ namespace build2 // meta-information protocol". See also append_lib_options() // above. // - if (p.is_a () || p.is_a () || p.is_a ()) + if (p.is_a () || p.is_a () || p.is_a ()) { if (a.operation () == update_id) { @@ -184,7 +227,7 @@ namespace build2 { target& pt (*p.target); // Already searched and matched. - if (pt.is_a () || pt.is_a () || pt.is_a ()) + if (pt.is_a () || pt.is_a () || pt.is_a ()) hash_lib_options (cs, pt, "cxx.export.poptions"); } @@ -192,7 +235,7 @@ namespace build2 hash_options (cs, t, "cxx.coptions"); hash_std (cs, rs, cid, t); - if (t.is_a ()) + if (ct == otype::s) { // On Darwin, Win32 -fPIC is the default. // @@ -369,7 +412,7 @@ namespace build2 if (t == nullptr) continue; - if (t->is_a () || t->is_a () || t->is_a ()) + if (t->is_a () || t->is_a () || t->is_a ()) append_lib_prefixes (m, *t); } @@ -389,7 +432,7 @@ namespace build2 { target& pt (*p.target); // Already searched and matched. - if (pt.is_a () || pt.is_a () || pt.is_a ()) + if (pt.is_a () || pt.is_a () || pt.is_a ()) append_lib_prefixes (m, pt); } @@ -617,7 +660,7 @@ namespace build2 { target& pt (*p.target); // Already searched and matched. - if (pt.is_a () || pt.is_a () || pt.is_a ()) + if (pt.is_a () || pt.is_a () || pt.is_a ()) append_lib_options (args, pt, "cxx.export.poptions"); } @@ -628,7 +671,7 @@ namespace build2 append_options (args, t, "cxx.coptions"); append_std (args, rs, cid, t, cxx_std); - if (t.is_a ()) + if (t.is_a ()) { // On Darwin, Win32 -fPIC is the default. // @@ -1181,19 +1224,22 @@ namespace build2 if (s == nullptr) return target_state::unchanged; - // Translate paths to relative (to working directory) ones. This - // results in easier to read diagnostics. - // - path relo (relative (t.path ())); - path rels (relative (s->path ())); - scope& rs (t.root_scope ()); + const path& cxx (cast (rs["config.cxx"])); const string& cid (cast (rs["cxx.id"])); const string& tclass (cast (rs["cxx.target.class"])); + otype ct (compile_type (t)); + cstrings args {cxx.string ().c_str ()}; + // Translate paths to relative (to working directory) ones. This + // results in easier to read diagnostics. + // + path relo (relative (t.path ())); + path rels (relative (s->path ())); + // Add cxx.export.poptions from prerequisite libraries. Note that // here we don't need to see group members (see apply()). // @@ -1201,7 +1247,7 @@ namespace build2 { target& pt (*p.target); // Already searched and matched. - if (pt.is_a () || pt.is_a () || pt.is_a ()) + if (pt.is_a () || pt.is_a () || pt.is_a ()) append_lib_options (args, pt, "cxx.export.poptions"); } @@ -1268,7 +1314,7 @@ namespace build2 } else { - if (t.is_a ()) + if (ct == otype::s) { // On Darwin, Win32 -fPIC is the default. // -- cgit v1.1