History

tcc: add -m32 option to x86_64 cross compilers

Henry Kroll III committed 15 years ago

Commit bb7bb371 parent 33f86ad2 files · +35 −1Browse files

Unified · Split

2 files
  1. tcc.c +34 −1
  2. tcc.h +1 −0
tcc.c+34−1
@@ -212,6 +212,36 @@ static int expand_args(char ***pargv, const char *str) · 211 unmodified lines
212212 return argc;
213213 }
214214
215+void exec_other_tcc(TCCState *s, int argc,char **argv,int optarg)
216+{
217+#ifdef TCC_TARGET_X86_64
218+#define WIN32_CAST
219+ char arg[20]="i386-tcc";
220+ char sep='/',*tcc;
221+ if (32 == optarg) {/* -m32 launches 32 bit tcc */
222+#ifdef TCC_TARGET_PE
223+#ifdef _WIN32
224+#define WIN32_CAST (const char**)(const char *)
225+ strcpy(arg,"tcc.exe");
226+ sep='\\';
227+#else
228+ strcpy(arg,"i386-win32-tcc");
229+#endif
230+#endif
231+ if (!(tcc=strrchr(argv[0],sep)))
232+ tcc=argv[0];
233+ else tcc++;
234+ if (0<s->verbose) printf("%s->%s\n",tcc,arg);
235+ if (strcmp(tcc,arg)) {
236+ execvp(arg, WIN32_CAST (argv));
237+ error("cross compiler not found!");
238+ exit(1);
239+#undef WIN32_CAST
240+ } else warning("-m32 infinite loop prevented");
241+ } else warning("usupported option \"-m%s\"",optarg);
242+#endif
243+}
244+
215245 static int parse_args(TCCState *s, int argc, char **argv)
216246 {
217247 int optind;
@@ -334,7 +364,10 @@ static int parse_args(TCCState *s, int argc, char **argv) · 116 unmodified lines
334364 output_type = TCC_OUTPUT_DLL;
335365 break;
336366 case TCC_OPTION_soname:
337− s->soname = optarg;
367+ s->soname = optarg;
368+ break;
369+ case TCC_OPTION_m:
370+ exec_other_tcc(s,argc+1,argv-1,atoi(optarg));
338371 break;
339372 case TCC_OPTION_o:
340373 multiple_files = 1;
tcc.h+1−0
@@ -44,6 +44,7 @@ · 43 unmodified lines
4444
4545 #ifdef _WIN32
4646 #include <windows.h>
47+#include <process.h>
4748 #include <sys/timeb.h>
4849 #include <io.h> /* open, close etc. */
4950 #include <direct.h> /* getcwd */