diff --git a/tools/windres.c b/tools/windres.c new file mode 100644 index 0000000..5171ad3 --- /dev/null +++ b/tools/windres.c @@ -0,0 +1,558 @@ +/** + * PROJECT: XTchain + * LICENSE: See COPYING.md in the top level directory + * FILE: tools/windres.c + * DESCRIPTION: WINDRES compatible interface to LLVM + * DEVELOPERS: Josh de Kock + * Martin Storsjo + * Rafal Kupiec + */ + +#include "xtchain.h" + +#define WINDRES_VERSION "1.0" + +#ifndef DEFAULT_TARGET +#define DEFAULT_TARGET "x86_64-w64-mingw32" +#endif + +#include + +#define _tspawnvp_escape _spawnvp + +#include +#include + +#define _P_WAIT 0 + +static +int +_spawnvp(int mode, + const char *filename, + const char * const *argv) +{ + pid_t pid; + + if(!(pid = fork())) + { + execvp(filename, (char **) argv); + perror(filename); + exit(1); + } + + int stat = 0; + + if(waitpid(pid, &stat, 0) == -1) + { + return -1; + } + + if(WIFEXITED(stat)) + { + return WEXITSTATUS(stat); + } + errno = EIO; + + return -1; +} + +static +const +char *unescape_cpp(const char *str) +{ + char *out = strdup(str); + int len = strlen(str); + int i, outpos = 0; + + for(i = 0; i < len - 1; i++) + { + if(str[i] == '\\' && str[i + 1] == '"') + { + continue; + } + out[outpos++] = str[i]; + } + + while(i < len) + { + out[outpos++] = str[i++]; + } + + out[outpos++] = '\0'; + + return out; +} + +static +void print_version(void) +{ + printf("XTchain windres (GNU windres compatible) %s\n", WINDRES_VERSION); + exit(-1); +} + +static +void print_help(void) +{ + printf( + "usage: llvm-windres