Created
May 5, 2012 17:21
-
-
Save 7shi/2604163 to your computer and use it in GitHub Desktop.
MSYSから.NET関連のコマンドを呼び出すラッパー
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
TARGETS = csc.exe ilasm.exe al.exe gacutil.exe ildasm.exe | |
PREFIX = /usr/local | |
MSYS_CPPFLAGS = -I/include | |
MSYS_LDFLAGS = -nostdlib /lib/crt0.o -L/lib -lgcc -lmsys-1.0.dll -lkernel32 | |
PATH1=C:\\WINDOWS\\Microsoft.NET\\Framework\\v4.0.30319 | |
PATH2=C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\bin\\NETFX 4.0 Tools | |
all: $(TARGETS) | |
csc.exe: wrapper.c | |
gcc '-DCOMMAND="$(PATH1)\\$@"' \ | |
-std=c99 -s -o $@ $^ $(MSYS_CPPFLAGS) $(MSYS_LDFLAGS) | |
ilasm.exe: wrapper.c | |
gcc '-DCOMMAND="$(PATH1)\\$@"' \ | |
-std=c99 -s -o $@ $^ $(MSYS_CPPFLAGS) $(MSYS_LDFLAGS) | |
al.exe: wrapper.c | |
gcc '-DCOMMAND="$(PATH2)\\$@"' \ | |
-std=c99 -s -o $@ $^ $(MSYS_CPPFLAGS) $(MSYS_LDFLAGS) | |
gacutil.exe: wrapper.c | |
gcc '-DCOMMAND="$(PATH2)\\$@"' \ | |
-std=c99 -s -o $@ $^ $(MSYS_CPPFLAGS) $(MSYS_LDFLAGS) | |
ildasm.exe: wrapper.c | |
gcc '-DCOMMAND="$(PATH2)\\$@"' \ | |
-std=c99 -s -o $@ $^ $(MSYS_CPPFLAGS) $(MSYS_LDFLAGS) | |
install: all | |
cp $(TARGETS) $(PREFIX)/bin | |
clean: | |
rm -f $(TARGETS) |
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 <stdbool.h> | |
#include <string.h> | |
#include <windows.h> | |
const char *cmd = COMMAND; | |
int main(int argc, char *argv[]) { | |
int len = strlen(cmd); | |
for (int i = 1; i < argc; i++) { | |
len += 1 + strlen(argv[i]); | |
if (strchr(argv[i], ' ')) len += 2; | |
} | |
TCHAR args[len + 1]; | |
strcpy(args, cmd); | |
for (int i = 1; i < argc; i++) { | |
strcat(args, " "); | |
bool spc = strchr(argv[i], ' '); | |
if (spc) strcat(args, "\""); | |
strcat(args, argv[i]); | |
if (spc) strcat(args, "\""); | |
} | |
PROCESS_INFORMATION pi; | |
STARTUPINFO si; | |
ZeroMemory(&si, sizeof(si)); | |
si.cb = sizeof(si); | |
CreateProcess( | |
NULL, args, NULL, NULL, FALSE, | |
PROCESS_QUERY_INFORMATION, | |
NULL, NULL, &si, &pi); | |
WaitForSingleObject(pi.hProcess, INFINITE); | |
DWORD ret; | |
GetExitCodeProcess(pi.hProcess, &ret); | |
CloseHandle(pi.hProcess); | |
CloseHandle(pi.hThread); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment