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/bin/module.cxx | 51 ++++++++++++------------ build2/bin/rule.cxx | 61 ++++++++++++++--------------- build2/bin/target | 19 +++++++-- build2/bin/target.cxx | 105 +++++++++++++++++++++++++++++++++----------------- 4 files changed, 141 insertions(+), 95 deletions(-) (limited to 'build2/bin') diff --git a/build2/bin/module.cxx b/build2/bin/module.cxx index 306d8de..334384a 100644 --- a/build2/bin/module.cxx +++ b/build2/bin/module.cxx @@ -31,7 +31,7 @@ namespace build2 // static const strings exe_lib {"shared", "static"}; static const strings liba_lib {"static"}; - static const strings libso_lib {"shared"}; + static const strings libs_lib {"shared"}; // Apply the specified stem to the config.bin.pattern. If there is no // pattern, then return the stem itself. Assume the pattern is valid, @@ -73,22 +73,22 @@ namespace build2 // Note: some overridable, some not. // - v.insert ("config.bin.target", true); - v.insert ("config.bin.pattern", true); + 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.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); - v.insert ("config.bin.libso.lib", true); - v.insert ("config.bin.rpath", true); + v.insert ("config.bin.lib", true); + v.insert ("config.bin.exe.lib", true); + v.insert ("config.bin.liba.lib", true); + v.insert ("config.bin.libs.lib", true); + v.insert ("config.bin.rpath", true); v.insert ("bin.lib"); v.insert ("bin.exe.lib"); v.insert ("bin.liba.lib"); - v.insert ("bin.libso.lib"); + v.insert ("bin.libs.lib"); v.insert ("bin.rpath"); v.insert ("bin.libprefix", true); @@ -133,12 +133,12 @@ namespace build2 v = required (r, "config.bin.liba.lib", liba_lib).first; } - // config.bin.libso.lib + // config.bin.libs.lib // { - value& v (b.assign ("bin.libso.lib")); + value& v (b.assign ("bin.libs.lib")); if (!v) - v = required (r, "config.bin.libso.lib", libso_lib).first; + v = required (r, "config.bin.libs.lib", libs_lib).first; } // config.bin.rpath @@ -353,13 +353,14 @@ namespace build2 { auto& t (b.target_types); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); - t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); } // Register rules. @@ -407,15 +408,15 @@ namespace build2 // And a library that wants to override any such overrides (e.g., // because it does have main()) can do: // - // libso{foo}: install.mode=755 + // libs{foo}: install.mode=755 // // Everyone is happy then? Not Windows users. When targeting Windows - // libso{} is an import library and shouldn't be exec. + // libs{} is an import library and shouldn't be exec. // - install_path (b, dir_path ("lib")); // Install into install.lib. + install_path (b, dir_path ("lib")); // Install into install.lib. if (tclass == "windows") - install_mode (b, "644"); + install_mode (b, "644"); install_path (b, dir_path ("lib")); // Install into install.lib. install_mode (b, "644"); diff --git a/build2/bin/rule.cxx b/build2/bin/rule.cxx index 072e931..7710a53 100644 --- a/build2/bin/rule.cxx +++ b/build2/bin/rule.cxx @@ -23,7 +23,7 @@ namespace build2 match (action a, target& t, const string&) const { fail << diag_doing (a, t) << " target group" << - info << "explicitly select either obja{} or objso{} member"; + info << "explicitly select obje{}, obja{}, or objs{} member"; return nullptr; } @@ -33,25 +33,25 @@ namespace build2 // lib // - // The whole logic is pretty much as if we had our two group - // members as our prerequisites. + // The whole logic is pretty much as if we had our two group members as + // our prerequisites. // match_result lib_rule:: - match (action a, target& xt, const string&) const + match (action act, target& xt, const string&) const { lib& t (static_cast (xt)); // @@ We have to re-query it on each match_only()! // Get the library type to build. If not set for a target, this - // should be configured at the project scope by init_lib(). + // should be configured at the project scope by init(). // const string& type (cast (t["bin.lib"])); - bool ar (type == "static" || type == "both"); - bool so (type == "shared" || type == "both"); + bool a (type == "static" || type == "both"); + bool s (type == "shared" || type == "both"); - if (!ar && !so) + if (!a && !s) fail << "unknown library type: " << type << info << "'static', 'shared', or 'both' expected"; @@ -63,20 +63,20 @@ namespace build2 // meta-information about the library, such as the options to use // when linking it, etc. // - if (ar) + if (a) { if (t.a == nullptr) t.a = &search (t.dir, t.out, t.name, nullptr, nullptr); - match_only (a, *t.a); + match_only (act, *t.a); } - if (so) + if (s) { - if (t.so == nullptr) - t.so = &search (t.dir, t.out, t.name, nullptr, nullptr); + if (t.s == nullptr) + t.s = &search (t.dir, t.out, t.name, nullptr, nullptr); - match_only (a, *t.so); + match_only (act, *t.s); } match_result mr (t, &type); @@ -84,35 +84,35 @@ namespace build2 // If there is an outer operation, indicate that we match // unconditionally so that we don't override ourselves. // - if (a.outer_operation () != 0) - mr.recipe_action = action (a.meta_operation (), a.operation ()); + if (act.outer_operation () != 0) + mr.recipe_action = action (act.meta_operation (), act.operation ()); return mr; } recipe lib_rule:: - apply (action a, target& xt, const match_result& mr) const + apply (action act, target& xt, const match_result& mr) const { lib& t (static_cast (xt)); const string& type (*static_cast (mr.cpvalue)); - bool ar (type == "static" || type == "both"); - bool so (type == "shared" || type == "both"); + bool a (type == "static" || type == "both"); + bool s (type == "shared" || type == "both"); // Now we do full match. // - if (ar) - build2::match (a, *t.a); + if (a) + build2::match (act, *t.a); - if (so) - build2::match (a, *t.so); + if (s) + build2::match (act, *t.s); return &perform; } target_state lib_rule:: - perform (action a, target& xt) + perform (action act, target& xt) { lib& t (static_cast (xt)); @@ -122,11 +122,12 @@ namespace build2 // // const string& type (cast (t["bin.lib"])); - bool ar (type == "static" || type == "both"); - bool so (type == "shared" || type == "both"); - target* m1 (ar ? t.a : nullptr); - target* m2 (so ? t.so : nullptr); + bool a (type == "static" || type == "both"); + bool s (type == "shared" || type == "both"); + + target* m1 (a ? t.a : nullptr); + target* m2 (s ? t.s : nullptr); if (current_mode == execution_mode::last) swap (m1, m2); @@ -134,10 +135,10 @@ namespace build2 target_state r (target_state::unchanged); if (m1 != nullptr) - r |= execute (a, *m1); + r |= execute (act, *m1); if (m2 != nullptr) - r |= execute (a, *m2); + r |= execute (act, *m2); return r; } diff --git a/build2/bin/target b/build2/bin/target index f386592..8c32e84 100644 --- a/build2/bin/target +++ b/build2/bin/target @@ -16,6 +16,16 @@ namespace build2 { // The obj{} target group. // + class obje: public file + { + public: + using file::file; + + public: + static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} + }; + class obja: public file { public: @@ -26,7 +36,7 @@ namespace build2 virtual const target_type& dynamic_type () const {return static_type;} }; - class objso: public file + class objs: public file { public: using file::file; @@ -41,8 +51,9 @@ namespace build2 public: using target::target; + obje* e {nullptr}; obja* a {nullptr}; - objso* so {nullptr}; + objs* s {nullptr}; public: static const target_type static_type; @@ -71,7 +82,7 @@ namespace build2 virtual const target_type& dynamic_type () const {return static_type;} }; - class libso: public file + class libs: public file { public: using file::file; @@ -87,7 +98,7 @@ namespace build2 using target::target; liba* a {nullptr}; - libso* so {nullptr}; + libs* s {nullptr}; virtual void reset (action_type); diff --git a/build2/bin/target.cxx b/build2/bin/target.cxx index f141d97..3f16467 100644 --- a/build2/bin/target.cxx +++ b/build2/bin/target.cxx @@ -13,14 +13,41 @@ namespace build2 extern const char ext_var[] = "extension"; // VC 19 rejects constexpr. static target* + obje_factory (const target_type&, + dir_path dir, + dir_path out, + string n, + const string* ext) + { + obj* o (targets.find (dir, out, n)); + obje* e (new obje (move (dir), move (out), move (n), ext)); + + if ((e->group = o)) + o->e = e; + + return e; + } + + const target_type obje::static_type + { + "obje", + &file::static_type, + &obje_factory, + &target_extension_var, + nullptr, + &search_target, // Note: not _file(); don't look for an existing file. + false + }; + + static target* obja_factory (const target_type&, dir_path dir, dir_path out, string n, - const string* e) + const string* ext) { obj* o (targets.find (dir, out, n)); - obja* a (new obja (move (dir), move (out), move (n), e)); + obja* a (new obja (move (dir), move (out), move (n), ext)); if ((a->group = o)) o->a = a; @@ -40,26 +67,26 @@ namespace build2 }; static target* - objso_factory (const target_type&, + objs_factory (const target_type&, dir_path dir, dir_path out, string n, - const string* e) + const string* ext) { obj* o (targets.find (dir, out, n)); - objso* so (new objso (move (dir), move (out), move (n), e)); + objs* s (new objs (move (dir), move (out), move (n), ext)); - if ((so->group = o)) - o->so = so; + if ((s->group = o)) + o->s = s; - return so; + return s; } - const target_type objso::static_type + const target_type objs::static_type { - "objso", + "objs", &file::static_type, - &objso_factory, + &objs_factory, &target_extension_var, nullptr, &search_target, // Note: not _file(); don't look for an existing file. @@ -71,17 +98,22 @@ namespace build2 dir_path dir, dir_path out, string n, - const string* e) + const string* ext) { + obje* e (targets.find (dir, out, n)); obja* a (targets.find (dir, out, n)); - objso* so (targets.find (dir, out, n)); - obj* o (new obj (move (dir), move (out), move (n), e)); + objs* s (targets.find (dir, out, n)); + + obj* o (new obj (move (dir), move (out), move (n), ext)); + + if ((o->e = e)) + e->group = o; if ((o->a = a)) a->group = o; - if ((o->so = so)) - so->group = o; + if ((o->s = s)) + s->group = o; return o; } @@ -124,12 +156,12 @@ namespace build2 dir_path d, dir_path o, string n, - const string* e) + const string* ext) { // Only link-up to the group if the types match exactly. // lib* l (t == liba::static_type ? targets.find (d, o, n) : nullptr); - liba* a (new liba (move (d), move (o), move (n), e)); + liba* a (new liba (move (d), move (o), move (n), ext)); if ((a->group = l)) l->a = a; @@ -161,28 +193,28 @@ namespace build2 }; static target* - libso_factory (const target_type& t, - dir_path d, - dir_path o, - string n, - const string* e) + libs_factory (const target_type& t, + dir_path d, + dir_path o, + string n, + const string* ext) { // Only link-up to the group if the types match exactly. // - lib* l (t == libso::static_type ? targets.find (d, o, n) : nullptr); - libso* so (new libso (move (d), move (o), move (n), e)); + lib* l (t == libs::static_type ? targets.find (d, o, n) : nullptr); + libs* s (new libs (move (d), move (o), move (n), ext)); - if ((so->group = l)) - l->so = so; + if ((s->group = l)) + l->s = s; - return so; + return s; } - const target_type libso::static_type + const target_type libs::static_type { - "libso", + "libs", &file::static_type, - &libso_factory, + &libs_factory, &target_extension_var, nullptr, &search_file, @@ -203,17 +235,18 @@ namespace build2 dir_path d, dir_path o, string n, - const string* e) + const string* ext) { liba* a (targets.find (d, o, n)); - libso* so (targets.find (d, o, n)); - lib* l (new lib (move (d), move (o), move (n), e)); + libs* s (targets.find (d, o, n)); + + lib* l (new lib (move (d), move (o), move (n), ext)); if ((l->a = a)) a->group = l; - if ((l->so = so)) - so->group = l; + if ((l->s = s)) + s->group = l; return l; } -- cgit v1.1