Loading main.cpp +31 −20 Changes for main.cpp: 31 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -46,6 +46,30 @@ static void setup_defaults(makeplus::Makefile& mf, const char* argv0) { mf.variables[name] = {value, makeplus::VarFlavor::Recursive, false}; } }; // Make-controlled special variables: make always defines these itself, so // they must override any inherited environment value (GNU make ignores an // environment SHELL/CURDIR, and always recomputes CURDIR/MAKE). auto force_set = [&](const std::string& name, const std::string& value) { mf.variables[name] = {value, makeplus::VarFlavor::Simple, false}; }; // Import environment variables FIRST so they are visible as make variables. // GNU make precedence: an environment variable overrides a built-in default // (e.g. the default CC=cc or CFLAGS=), but is itself overridden by a later // makefile assignment. Because set_default() below only fills in a value // when one is absent, importing here lets exported vars from a parent // $(MAKE) (Kbuild exports CFLAGS, srctree, ...) survive into the sub-make. for (char** env = environ; *env; ++env) { std::string entry(*env); size_t eq = entry.find('='); if (eq != std::string::npos) { std::string name = entry.substr(0, eq); std::string value = entry.substr(eq + 1); if (mf.variables.find(name) == mf.variables.end()) { mf.variables[name] = {value, makeplus::VarFlavor::Simple, false}; } } } set_default("CC", "cc"); set_default("CXX", "clang++"); Loading @@ -60,32 +84,19 @@ static void setup_defaults(makeplus::Makefile& mf, const char* argv0) { set_default("LDFLAGS", ""); set_default("LDLIBS", ""); set_default("ARFLAGS", "rv"); set_default("MAKE", argv0); set_default("SHELL", "/bin/sh"); set_default(".SHELLFLAGS", "-c"); set_default("CURDIR", fs::current_path().string()); force_set("MAKE", argv0); force_set("SHELL", "/bin/sh"); force_set(".SHELLFLAGS", "-c"); force_set("CURDIR", fs::current_path().string()); // Advertise GNU-make compatibility so feature-gated build systems (Kbuild) // accept us. MAKE_VERSION must be >= 4.0; .FEATURES lists the capabilities // makeplus implements. set_default("MAKE_VERSION", "4.4"); set_default("MAKE_HOST", "x86_64-pc-linux-gnu"); set_default(".FEATURES", force_set("MAKE_VERSION", "4.4"); force_set("MAKE_HOST", "x86_64-pc-linux-gnu"); force_set(".FEATURES", "target-specific order-only second-expansion else-if " "shortest-stem undefine oneshell archives jobserver " "output-sync check-symlink"); // Import environment variables (lower priority than file variables) for (char** env = environ; *env; ++env) { std::string entry(*env); size_t eq = entry.find('='); if (eq != std::string::npos) { std::string name = entry.substr(0, eq); std::string value = entry.substr(eq + 1); if (mf.variables.find(name) == mf.variables.end()) { mf.variables[name] = {value, makeplus::VarFlavor::Simple, false}; } } } } int main(int argc, char* argv[]) { Loading Loading
main.cpp +31 −20 Changes for main.cpp: 31 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -46,6 +46,30 @@ static void setup_defaults(makeplus::Makefile& mf, const char* argv0) { mf.variables[name] = {value, makeplus::VarFlavor::Recursive, false}; } }; // Make-controlled special variables: make always defines these itself, so // they must override any inherited environment value (GNU make ignores an // environment SHELL/CURDIR, and always recomputes CURDIR/MAKE). auto force_set = [&](const std::string& name, const std::string& value) { mf.variables[name] = {value, makeplus::VarFlavor::Simple, false}; }; // Import environment variables FIRST so they are visible as make variables. // GNU make precedence: an environment variable overrides a built-in default // (e.g. the default CC=cc or CFLAGS=), but is itself overridden by a later // makefile assignment. Because set_default() below only fills in a value // when one is absent, importing here lets exported vars from a parent // $(MAKE) (Kbuild exports CFLAGS, srctree, ...) survive into the sub-make. for (char** env = environ; *env; ++env) { std::string entry(*env); size_t eq = entry.find('='); if (eq != std::string::npos) { std::string name = entry.substr(0, eq); std::string value = entry.substr(eq + 1); if (mf.variables.find(name) == mf.variables.end()) { mf.variables[name] = {value, makeplus::VarFlavor::Simple, false}; } } } set_default("CC", "cc"); set_default("CXX", "clang++"); Loading @@ -60,32 +84,19 @@ static void setup_defaults(makeplus::Makefile& mf, const char* argv0) { set_default("LDFLAGS", ""); set_default("LDLIBS", ""); set_default("ARFLAGS", "rv"); set_default("MAKE", argv0); set_default("SHELL", "/bin/sh"); set_default(".SHELLFLAGS", "-c"); set_default("CURDIR", fs::current_path().string()); force_set("MAKE", argv0); force_set("SHELL", "/bin/sh"); force_set(".SHELLFLAGS", "-c"); force_set("CURDIR", fs::current_path().string()); // Advertise GNU-make compatibility so feature-gated build systems (Kbuild) // accept us. MAKE_VERSION must be >= 4.0; .FEATURES lists the capabilities // makeplus implements. set_default("MAKE_VERSION", "4.4"); set_default("MAKE_HOST", "x86_64-pc-linux-gnu"); set_default(".FEATURES", force_set("MAKE_VERSION", "4.4"); force_set("MAKE_HOST", "x86_64-pc-linux-gnu"); force_set(".FEATURES", "target-specific order-only second-expansion else-if " "shortest-stem undefine oneshell archives jobserver " "output-sync check-symlink"); // Import environment variables (lower priority than file variables) for (char** env = environ; *env; ++env) { std::string entry(*env); size_t eq = entry.find('='); if (eq != std::string::npos) { std::string name = entry.substr(0, eq); std::string value = entry.substr(eq + 1); if (mf.variables.find(name) == mf.variables.end()) { mf.variables[name] = {value, makeplus::VarFlavor::Simple, false}; } } } } int main(int argc, char* argv[]) { Loading