void Include::Clear() { files.clear(); ignoredFiles.clear(); Variable *v = VariableContainer::Instance()->Lookup("MAKEFILE_LIST"); if (v) v->SetValue(""); }
void MakeMain::SetVariable(const std::string &name, const std::string &value, Variable::Origin origin, bool toExport) { Variable *v = VariableContainer::Instance()->Lookup(name); if (v) { v->SetValue(value); } else { v = new Variable(name, value, Variable::f_recursive, origin); *VariableContainer::Instance() += v; } if (toExport) v->SetExport(true); }
bool Maker::CreateDependencyTree() { if (goals.size() == 0) { Variable *dg = VariableContainer::Instance()->Lookup(".DEFAULT_GOAL"); std::string value; if (dg && dg->GetValue().size() != 0) { value = dg->GetValue(); if (dg->GetFlavor() == Variable::f_recursive) { Eval r(value, false); value = r.Evaluate(); } } else { value = firstGoal; } if (value.size() == 0) return true; // nothing to do AddGoal(value); } EnterSuffixTerminals(); std::string intermediate; Variable *v = VariableContainer::Instance()->Lookup(".INTERMEDIATE"); if (v) { intermediate = v->GetValue(); } for (std::deque<std::string>::iterator it = goals.begin(); it != goals.end(); ++it) { Time tv1, tv2; Depends *t = Dependencies(*it, "", tv1); if (t || OnList(*it,".PHONY")) { depends.push_back(t); } else if (t) delete t; } v = VariableContainer::Instance()->Lookup(".INTERMEDIATE"); if (v) { v->SetValue(intermediate); } return !missingTarget; }
bool Include::AddFileList(const std::string &name, bool ignoreOk, bool MakeFile) { Eval e(name, false); std::string iname = e.Evaluate(); bool rv = true; CmdFiles cmdFiles; std::string seps(" "); seps += CmdFiles::PATH_SEP; std::string includeDirs; Variable *id = VariableContainer::Instance()->Lookup(".INCLUDE_DIRS"); if (id) { includeDirs = id->GetValue(); if (id->GetFlavor() == Variable::f_recursive) { Eval r(includeDirs, false); includeDirs = r.Evaluate(); } } while (iname.size()) { std::string current = Eval::ExtractFirst(iname, seps); cmdFiles.AddFromPath(current, includeDirs); } for (CmdFiles::FileNameIterator it = cmdFiles.FileNameBegin(); rv && it != cmdFiles.FileNameEnd(); ++it) { Variable *v = VariableContainer::Instance()->Lookup("MAKEFILE_LIST"); if (!v) { v = new Variable(std::string("MAKEFILE_LIST"), *(*it), Variable::f_simple, Variable::o_file); *VariableContainer::Instance() += v; } else { v->SetValue(v->GetValue() +" " + *(*it)); } files.push_back(*(*it)); rv &= Parse(*(*it), ignoreOk | MakeFile, MakeFile); } return rv; }
/** * Creates and caches a simplified version of the linear programming problem, * where redundant rows, columns and constraints are removed, * if it has not been created before. * Then, the simplified problem is solved. * * @return the result of the solving attempt */ ResultType LPSolveInterface::_Presolve(const VariableList& variables) { if (fLpPresolved == NULL) { fLpPresolved = copy_lp(fLP); set_presolve(fLpPresolved, PRESOLVE_ROWS | PRESOLVE_COLS | PRESOLVE_LINDEP, get_presolveloops(fLpPresolved)); } ResultType result = (ResultType)solve(fLpPresolved); if (result == OPTIMAL) { int32 size = variables.CountItems(); for (int32 i = 0; i < size; i++) { Variable* current = variables.ItemAt(i); current->SetValue(get_var_primalresult(fLpPresolved, get_Norig_rows(fLpPresolved) + current->GlobalIndex() + 1)); } } return result; }
int MakeMain::Run(int argc, char **argv, char **env) { char *p = getenv("MAKEFLAGS"); if (p) { Variable *v = new Variable("MAKEFLAGS", p, Variable::f_recursive, Variable::o_environ); *VariableContainer::Instance() += v; p = getenv("MAKEOVERRIDES"); if (p) { Variable *v = new Variable("MAKEOVERRIDES", p, Variable::f_recursive, Variable::o_environ); *VariableContainer::Instance() += v; } Eval r(v->GetValue(), false); std::string cmdLine = r.Evaluate(); Dispatch(cmdLine.c_str()); } if (!switchParser.Parse(&argc, argv) || help.GetValue() || help2.GetValue()) { Utils::banner(argv[0]); Utils::usage(argv[0], usageText); } if (dir.GetValue().size()) { cwd = OS::GetWorkingDir(); if (!OS::SetWorkingDir(dir.GetValue())) { std::cout << "Cannot set working dir to: " << dir.GetValue() << std::endl; return 2; } } if (printDir.GetValue()) { std::cout << OS::GetWorkingDir() << std::endl; } if (cancelKeep.GetValue()) { cancelKeep.SetValue(false); keepGoing.SetValue(false); } bool done = false; Eval::Init(); Eval::SetWarnings(warnUndef.GetValue()); while (!done && !Eval::GetErrCount()) { VariableContainer::Instance()->Clear(); RuleContainer::Instance()->Clear(); Include::Instance()->Clear(); Maker::ClearFirstGoal(); LoadEnvironment(env); LoadCmdDefines(); SetVariable("MAKE", argv[0], Variable::o_environ, false); Variable *v = VariableContainer::Instance()->Lookup("SHELL"); if (!v) { v = VariableContainer::Instance()->Lookup("COMSPEC"); if (!v) v = VariableContainer::Instance()->Lookup("ComSpec"); if (v) { std::string val = v->GetValue(); SetVariable("SHELL", val, Variable::o_environ, true); } } std::string goals; for (int i=1; i < argc; i++) { if (goals.size()) goals += " "; goals += argv[i]; } SetVariable("MAKECMDGOALS", goals, Variable::o_command_line, false); SetMakeFlags(); if (restarts) { std::strstream str; std::string temp; str << restarts; str >> temp; SetVariable("MAKE_RESTARTS", temp, Variable::o_command_line, false); } v = VariableContainer::Instance()->Lookup("MAKE_LEVEL"); if (!v) { SetVariable("MAKE_LEVEL", "0", Variable::o_environ, true); } else { std::strstream str; std::string temp; str << v->GetValue(); int n; str >> n; n++; str << n; str >> temp; v->SetValue(temp); } SetVariable(".FEATURES","second-expansion order-only target-specific", Variable::o_environ, false); SetVariable(".DEFAULT_GOAL","", Variable::o_environ, false); SetVariable(".INCLUDE_DIRS",includes.GetValue(), Variable::o_command_line, false); SetVariable("VPATH",includes.GetValue(), Variable::o_environ, false); SetInternalVars(); v = VariableContainer::Instance()->Lookup("MAKEFILES"); if (v) { v->SetExport(true); Include::Instance()->AddFileList(v->GetValue(), true, true); } Rule *rule = new Rule(".SUFFIXES", ".c .o .cpp .nas .asm", "", new Command("", 0), "", 0, false); RuleList *ruleList = new RuleList(".SUFFIXES"); ruleList->Add(rule, false); *RuleContainer::Instance() += ruleList; std::string files = specifiedFiles.GetValue(); if (!files.size()) files = "makefile"; Include::Instance()->AddFileList(files, false, false); SetupImplicit(); RuleContainer::Instance()->SecondaryEval(); done = !Include::Instance()->MakeMakefiles(silent.GetValue()); if (!done) restarts++; } if (showDatabase.GetValue()) ShowDatabase(); int rv = 0; if (Eval::GetErrCount()) { rv = 2; } else { bool xsilent = silent.GetValue(); bool xignore = ignoreErrors.GetValue(); bool xdontrun = displayOnly.GetValue(); bool xtouch = touch.GetValue(); xdontrun |= xtouch || query.GetValue(); xsilent |= xtouch || query.GetValue(); Maker maker(xsilent, xdontrun, xignore, xtouch, rebuild.GetValue(), newFiles.GetValue(), oldFiles.GetValue()); for (int i = 1; i < argc; i++) { maker.AddGoal(argv[i]); } if (maker.CreateDependencyTree()) { rv = maker.RunCommands(keepGoing.GetValue()); if (query.GetValue() && rv == 0) rv = maker.HasCommands() ? 1 : 0; } else { rv = 2; } } if (dir.GetValue().size()) { OS::SetWorkingDir(cwd); } if (printDir.GetValue()) { std::cout << OS::GetWorkingDir() << std::endl; } return rv; }