Unified · Split
| @@ -3,9 +3,44 @@ · 2 unmodified lines | |||
| 3 | #include <signal.h> | 3 | #include <signal.h> |
| 4 | #include <errno.h> | 4 | #include <errno.h> |
| 5 | 5 | ||
| 6 | extern char const cfileContents[]; | 6 | #if defined(_WIN32) |
| 7 | char c[]="/tmp/tcc-XXXXXX.c"; | 7 | #endif |
| 8 | char o[]="/tmp/tcc-XXXXXX.o"; | 8 | |
| 9 | #if __linux__ || __APPLE__ | ||
| 10 | #define SYS_WHICH_NM "which nm >/dev/null 2>&1" | ||
| 11 | #define TCC_COMPILER "../../tcc" | ||
| 12 | #define SYS_AWK | ||
| 13 | |||
| 14 | char c[]="/tmp/tcc-XXXXXX"; char o[]="/tmp/tcc-XXXXXX"; | ||
| 15 | static int mktempfile(char *buf) | ||
| 16 | { | ||
| 17 | return mkstemps(buf,0); | ||
| 18 | } | ||
| 19 | #elif defined(_WIN32) | ||
| 20 | #define SYS_WHICH_NM "which nm >nul 2>&1" | ||
| 21 | |||
| 22 | #if defined(_WIN64) | ||
| 23 | #define TCC_COMPILER "..\\..\\win32\\x86_64-win32-tcc" | ||
| 24 | #else | ||
| 25 | #define TCC_COMPILER "..\\..\\win32\\i386-win32-tcc" | ||
| 26 | #endif | ||
| 27 | |||
| 28 | char c[1024]; char o[1024]; | ||
| 29 | static int mktempfile(char *buf) | ||
| 30 | { | ||
| 31 | /* | ||
| 32 | * WARNING, this simplified 'mktemp' like function | ||
| 33 | * create two temporary Windows files having always | ||
| 34 | * the same name. It is enought for tcc test suite. | ||
| 35 | */ | ||
| 36 | if (buf == c) { | ||
| 37 | sprintf(c, "%s\\tcc-temp1", getenv("LOCALAPPDATA")); | ||
| 38 | } else { | ||
| 39 | sprintf(o, "%s\\tcc-temp2", getenv("LOCALAPPDATA")); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | #endif | ||
| 43 | |||
| 9 | void rmh(int Sig) | 44 | void rmh(int Sig) |
| 10 | { | 45 | { |
| 11 | remove(c); | 46 | remove(c); |
| @@ -24,22 +59,23 @@ int str2file(char const *fnm, char const *str) · 12 unmodified lines | |||
| 24 | int main(int C, char **V) | 59 | int main(int C, char **V) |
| 25 | { | 60 | { |
| 26 | int r=0; | 61 | int r=0; |
| 27 | if (system("which nm >/dev/null 2>&1")){ return 0; } | 62 | if (system(SYS_WHICH_NM)){ return 0; } |
| 28 | signal(SIGINT,SIG_IGN); | 63 | signal(SIGINT,SIG_IGN); |
| 29 | signal(SIGTERM,SIG_IGN); | 64 | signal(SIGTERM,SIG_IGN); |
| 30 | if(0>mkstemps(c,2)) return perror("mkstemps"),1; | 65 | if(0>mktempfile(c)) return perror("mkstemps"),1; |
| 31 | if(0>mkstemps(o,2)){ | 66 | if(0>mktempfile(o)){ |
| 32 | if(0>remove(c)) perror("remove"); | 67 | if(0>remove(c)) perror("remove"); |
| 33 | return perror("mkstemps"),1; | 68 | return perror("mkstemps"),1; |
| 34 | } | 69 | } |
| 35 | signal(SIGINT,rmh); | 70 | signal(SIGINT,rmh); |
| 36 | signal(SIGTERM,rmh); | 71 | signal(SIGTERM,rmh); |
| 72 | extern char const cfileContents[]; | ||
| 37 | if(0>str2file(c, cfileContents)) { perror("write");r=1;goto out;} | 73 | if(0>str2file(c, cfileContents)) { perror("write");r=1;goto out;} |
| 38 | char buf[1024]; | 74 | char buf[1024]; |
| 39 | sprintf(buf, "%s -c %s -o %s", V[1]?V[1]:"../../tcc", c, o); if(0!=system(buf)){ r=1;goto out;} | 75 | sprintf(buf, "%s -c -xc %s -o %s", V[1]?V[1]:TCC_COMPILER, c, o); if(0!=system(buf)){ r=1;goto out;} |
| 40 | sprintf(buf, "nm -Ptx %s > %s", o, c); if(system(buf)) {r=1;goto out;} | 76 | sprintf(buf, "nm -Ptx %s > %s", o, c); if(system(buf)) {r=1;goto out;} |
| 41 | sprintf(buf, "awk '{ if($2 == \"T\") print $1 }' %s > %s", c, o); if(system(buf)) {r=1;goto out;} | 77 | sprintf(buf, "gawk '{ if($2 == \"T\") print $1 }' %s > %s", c, o); if(system(buf)) {r=1;goto out;} |
| 42 | sprintf(buf, "sort %s", o); if(system(buf)) {r=1;goto out;} | 78 | sprintf(buf, "sort %s", o); if(system(buf)) {r=1;goto out;} |
| 43 | out: | 79 | out: |
| 44 | remove(c); | 80 | remove(c); |
| 45 | remove(o); | 81 | remove(o); |
| @@ -175,4 +211,3 @@ char const cfileContents[]= · 129 unmodified lines | |||
| 175 | "}\n" | 211 | "}\n" |
| 176 | "\n" | 212 | "\n" |
| 177 | ; | 213 | ; |
| 178 | |||