Last active
December 18, 2015 20:49
-
-
Save 7shi/5843442 to your computer and use it in GitHub Desktop.
MinGWのmakeにパスを通すためのラッパー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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