2014-05-17 23:15:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* OSXCross Compiler Wrapper *
|
2016-02-27 09:40:10 +01:00
|
|
|
* Copyright (C) 2014-2016 by Thomas Poechtrager *
|
2014-05-17 23:15:15 +02:00
|
|
|
* t.poechtrager@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#include "proginc.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
using namespace tools;
|
|
|
|
using namespace target;
|
|
|
|
|
|
|
|
namespace program {
|
|
|
|
namespace osxcross {
|
|
|
|
|
|
|
|
int env(int argc, char **argv) {
|
|
|
|
char epath[PATH_MAX + 1];
|
|
|
|
char *oldpath = getenv("PATH");
|
|
|
|
|
|
|
|
assert(oldpath);
|
|
|
|
|
|
|
|
if (!getExecutablePath(epath, sizeof(epath)))
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
if (argc <= 1) {
|
|
|
|
const std::string &pname = getParentProcessName();
|
|
|
|
|
|
|
|
if (pname == "csh" || pname == "tcsh") {
|
|
|
|
std::cerr << std::endl << "you are invoking this program from a C shell, "
|
|
|
|
<< std::endl << "please use " << std::endl << std::endl
|
|
|
|
<< "setenv PATH `" << epath << "/osxcross-env -v=PATH`"
|
2015-02-23 21:19:34 +01:00
|
|
|
<< std::endl << std::endl << "instead." << std::endl
|
|
|
|
<< std::endl;
|
2014-05-17 23:15:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 22:28:10 +02:00
|
|
|
std::vector<std::string> path;
|
2014-05-17 23:15:15 +02:00
|
|
|
std::map<std::string, std::string> vars;
|
|
|
|
|
2015-07-19 22:28:10 +02:00
|
|
|
splitPath(oldpath, path);
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-07-19 22:28:10 +02:00
|
|
|
if (!hasPath(path, epath))
|
|
|
|
path.push_back(epath);
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-07-19 22:28:10 +02:00
|
|
|
vars["PATH"] = joinPath(path);
|
2014-05-17 23:15:15 +02:00
|
|
|
|
|
|
|
auto printVariable = [&](const std::string & var)->bool {
|
|
|
|
auto it = vars.find(var);
|
|
|
|
if (it == vars.end()) {
|
|
|
|
std::cerr << "unknown variable '" << var << "'" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::cout << it->second << std::endl;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (argc <= 1) {
|
|
|
|
std::cout << std::endl;
|
|
|
|
for (auto &v : vars) {
|
|
|
|
std::cout << "export " << v.first << "=";
|
|
|
|
if (!printVariable(v.first))
|
|
|
|
return 1;
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strncmp(argv[1], "-v=", 3))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
const char *var = argv[1] + 3;
|
|
|
|
return static_cast<int>(printVariable(var));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace osxcross
|
|
|
|
} // namespace program
|