Skip to content

Instantly share code, notes, and snippets.

@7shi
Last active December 18, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/5843442 to your computer and use it in GitHub Desktop.
Save 7shi/5843442 to your computer and use it in GitHub Desktop.
MinGWのmakeにパスを通すためのラッパー
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <vector>
#define MINGW "C:\\MinGW"
#define USR MINGW"\\msys\\1.0"
std::string lower(const std::string &s) {
std::string ret;
for (int i = 0; i < s.size(); i++) {
char ch = s[i];
if ('A' <= ch && ch <= 'Z') ch += 32;
ret += ch;
}
return ret;
}
int main(int argc, const char *argv[], const char *envp[]) {
const char *make = USR"\\bin\\make.exe";
argv[0] = make;
std::vector<const char *> envs;
std::string path;
for (int i = 0; envp[i]; i++) {
std::string e = envp[i];
std::string e5 = lower(e.substr(0, 5));
if (e5 == "path=") {
path = "PATH="USR"\\local\\bin;"USR"\\bin;"MINGW"\\bin;" + e.substr(5);
envs.push_back(path.c_str());
} else if (e5 != "lang=") {
envs.push_back(envp[i]);
}
}
envs.push_back("LANG=C");
envs.push_back(NULL);
return execve(make, argv, &envs[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment