From bb7bb37fe2eb47a35edcb4a5d4de62c044aafabf Mon Sep 17 00:00:00 2001 From: Henry Kroll III Date: Mon, 6 Dec 2010 16:17:20 -0800 Subject: [PATCH] tcc: add -m32 option to x86_64 cross compilers --- tcc.c | 35 ++++++++++++++++++++++++++++++++++- tcc.h | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tcc.c b/tcc.c index 817eb683..692d355f 100644 --- a/tcc.c +++ b/tcc.c @@ -212,6 +212,36 @@ static int expand_args(char ***pargv, const char *str) return argc; } +void exec_other_tcc(TCCState *s, int argc,char **argv,int optarg) +{ +#ifdef TCC_TARGET_X86_64 +#define WIN32_CAST + char arg[20]="i386-tcc"; + char sep='/',*tcc; + if (32 == optarg) {/* -m32 launches 32 bit tcc */ +#ifdef TCC_TARGET_PE +#ifdef _WIN32 +#define WIN32_CAST (const char**)(const char *) + strcpy(arg,"tcc.exe"); + sep='\\'; +#else + strcpy(arg,"i386-win32-tcc"); +#endif +#endif + if (!(tcc=strrchr(argv[0],sep))) + tcc=argv[0]; + else tcc++; + if (0verbose) printf("%s->%s\n",tcc,arg); + if (strcmp(tcc,arg)) { + execvp(arg, WIN32_CAST (argv)); + error("cross compiler not found!"); + exit(1); +#undef WIN32_CAST + } else warning("-m32 infinite loop prevented"); + } else warning("usupported option \"-m%s\"",optarg); +#endif +} + static int parse_args(TCCState *s, int argc, char **argv) { int optind; @@ -334,7 +364,10 @@ static int parse_args(TCCState *s, int argc, char **argv) output_type = TCC_OUTPUT_DLL; break; case TCC_OPTION_soname: - s->soname = optarg; + s->soname = optarg; + break; + case TCC_OPTION_m: + exec_other_tcc(s,argc+1,argv-1,atoi(optarg)); break; case TCC_OPTION_o: multiple_files = 1; diff --git a/tcc.h b/tcc.h index 6ab5346e..2cd2043c 100644 --- a/tcc.h +++ b/tcc.h @@ -44,6 +44,7 @@ #ifdef _WIN32 #include +#include #include #include /* open, close etc. */ #include /* getcwd */