chmod is more portable than fchmod.
[wine.git] / tools / winegcc / winegcc.c
blobd456f1cdd08f3e986895f82e603218f77723a385
1 /*
2 * MinGW wrapper: makes gcc behave like MinGW.
4 * Copyright 2000 Manuel Novoa III
5 * Copyright 2000 Francois Gouget
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * DESCRIPTION
24 * all options for gcc start with '-' and are for the most part
25 * single options (no parameters as separate argument).
26 * There are of course exceptions to this rule, so here is an
27 * exhaustive list of options that do take parameters (potentially)
28 * as a separate argument:
30 * Compiler:
31 * -x language
32 * -o filename
33 * -aux-info filename
35 * Preprocessor:
36 * -D name
37 * -U name
38 * -I dir
39 * -MF file
40 * -MT target
41 * -MQ target
42 * (all -i.* arg)
43 * -include file
44 * -imacros file
45 * -idirafter dir
46 * -iwithprefix dir
47 * -iwithprefixbefore dir
48 * -isystem dir
49 * -A predicate=answer
51 * Linking:
52 * -l library
53 * -Xlinker option
54 * -u symbol
56 * Misc:
57 * -b machine
58 * -V version
59 * -G num (see NOTES below)
61 * NOTES
62 * There is -G option for compatibility with System V that
63 * takes no parameters. This makes "-G num" parsing ambiguous.
64 * This option is synonymous to -shared, and as such we will
65 * not support it for now.
67 * Special interest options
69 * Assembler Option
70 * -Wa,option
72 * Linker Options
73 * object-file-name -llibrary -nostartfiles -nodefaultlibs
74 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
75 * -symbolic -Wl,option -Xlinker option -u symbol
77 * Directory Options
78 * -Bprefix -Idir -I- -Ldir -specs=file
80 * Target Options
81 * -b machine -V version
83 * Please note that the Target Options are relevant to everything:
84 * compiler, linker, assembler, preprocessor.
86 */
88 #include "config.h"
89 #include "wine/port.h"
91 #include <stdio.h>
92 #include <stdlib.h>
93 #include <stdarg.h>
94 #include <string.h>
95 #include <errno.h>
97 #include "utils.h"
99 static const char* app_loader_template =
100 "#!/bin/sh\n"
101 "\n"
102 "appname=\"%s\"\n"
103 "# determine the application directory\n"
104 "appdir=''\n"
105 "case \"$0\" in\n"
106 " */*)\n"
107 " # $0 contains a path, use it\n"
108 " appdir=`dirname \"$0\"`\n"
109 " ;;\n"
110 " *)\n"
111 " # no directory in $0, search in PATH\n"
112 " saved_ifs=$IFS\n"
113 " IFS=:\n"
114 " for d in $PATH\n"
115 " do\n"
116 " IFS=$saved_ifs\n"
117 " if [ -x \"$d/$appname\" ]; then appdir=\"$d\"; break; fi\n"
118 " done\n"
119 " ;;\n"
120 "esac\n"
121 "\n"
122 "while true; do\n"
123 " case \"$1\" in\n"
124 " --debugmsg)\n"
125 " debugmsg=\"$1 $2\"\n"
126 " shift; shift;\n"
127 " ;;\n"
128 " *)\n"
129 " break\n"
130 " ;;\n"
131 " esac\n"
132 "done\n"
133 "\n"
134 "# figure out the full app path\n"
135 "if [ -n \"$appdir\" ]; then\n"
136 " apppath=\"$appdir/$appname\"\n"
137 " WINEDLLPATH=\"$appdir:$WINEDLLPATH\"\n"
138 " export WINEDLLPATH\n"
139 "else\n"
140 " apppath=\"$appname\"\n"
141 "fi\n"
142 "\n"
143 "# determine the WINELOADER\n"
144 "if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
145 "\n"
146 "# and try to start the app\n"
147 "exec \"$WINELOADER\" $debugmsg -- \"$apppath\" \"$@\"\n"
150 static int keep_generated = 0;
151 static strarray* tmp_files;
153 struct options
155 enum { proc_cc = 0, proc_cxx = 1, proc_cpp = 2} processor;
156 int use_msvcrt;
157 int nostdinc;
158 int nostdlib;
159 int nodefaultlibs;
160 int noshortwchar;
161 int gui_app;
162 int compile_only;
163 int wine_mode;
164 const char* output_name;
165 strarray* prefix;
166 strarray* lib_dirs;
167 strarray* linker_args;
168 strarray* compiler_args;
169 strarray* winebuild_args;
170 strarray* files;
173 static void clean_temp_files()
175 int i;
177 if (keep_generated) return;
179 for (i = 0; i < tmp_files->size; i++)
180 unlink(tmp_files->base[i]);
183 char* get_temp_file(const char* prefix, const char* suffix)
185 char* tmp = strmake("%s-XXXXXX%s", prefix, suffix);
186 int fd = mkstemps( tmp, strlen(suffix) );
187 if (fd == -1)
189 /* could not create it in current directory, try in /tmp */
190 free(tmp);
191 tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix);
192 fd = mkstemps( tmp, strlen(suffix) );
193 if (fd == -1) error( "could not create temp file" );
195 close( fd );
196 strarray_add(tmp_files, tmp);
198 return tmp;
201 static const strarray* get_translator(struct options* opts)
203 static strarray* cpp = 0;
204 static strarray* cc = 0;
205 static strarray* cxx = 0;
207 switch(opts->processor)
209 case proc_cpp:
210 if (!cpp) cpp = strarray_fromstring(CPP, " ");
211 return cpp;
212 case proc_cc:
213 if (!cc) cc = strarray_fromstring(CC, " ");
214 return cc;
215 case proc_cxx:
216 if (!cxx) cxx = strarray_fromstring(CXX, " ");
217 return cxx;
219 error("Unknown processor");
222 static void compile(struct options* opts)
224 strarray* comp_args = strarray_alloc();
225 int j, gcc_defs = 0;
227 switch(opts->processor)
229 case proc_cpp: gcc_defs = 1; break;
230 #ifdef __GNUC__
231 /* Note: if the C compiler is gcc we assume the C++ compiler is too */
232 /* mixing different C and C++ compilers isn't supported in configure anyway */
233 case proc_cc: gcc_defs = 1; break;
234 case proc_cxx: gcc_defs = 1; break;
235 #else
236 case proc_cc: gcc_defs = 0; break;
237 case proc_cxx: gcc_defs = 0; break;
238 #endif
240 strarray_addall(comp_args, get_translator(opts));
242 if (opts->processor != proc_cpp)
244 #ifdef CC_FLAG_SHORT_WCHAR
245 if (!opts->wine_mode && !opts->noshortwchar)
247 strarray_add(comp_args, CC_FLAG_SHORT_WCHAR);
248 strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
250 #endif
251 strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
253 if (!opts->wine_mode && !opts->nostdinc)
255 if (opts->use_msvcrt)
257 strarray_add(comp_args, "-I" INCLUDEDIR "/msvcrt");
258 strarray_add(comp_args, "-D__MSVCRT__");
260 strarray_add(comp_args, "-I" INCLUDEDIR "/windows");
262 strarray_add(comp_args, "-DWIN32");
263 strarray_add(comp_args, "-D_WIN32");
264 strarray_add(comp_args, "-D__WIN32");
265 strarray_add(comp_args, "-D__WIN32__");
266 strarray_add(comp_args, "-D__WINNT");
267 strarray_add(comp_args, "-D__WINNT__");
269 if (gcc_defs)
271 strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__))");
272 strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__))");
273 strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))");
274 strarray_add(comp_args, "-D_stdcall=__attribute__((__stdcall__))");
275 strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
276 strarray_add(comp_args, "-D_fastcall=__attribute__((__fastcall__))");
277 strarray_add(comp_args, "-D__declspec(x)=__declspec_##x");
278 strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
279 strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
280 strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
281 strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
282 strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
283 strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))");
284 strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))");
285 strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
286 strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
287 strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
288 strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))");
289 strarray_add(comp_args, "-D__declspec_thread=__thread");
292 /* Wine specific defines */
293 strarray_add(comp_args, "-D__WINE__");
294 strarray_add(comp_args, "-D__int8=char");
295 strarray_add(comp_args, "-D__int16=short");
296 /* FIXME: what about 64-bit platforms? */
297 strarray_add(comp_args, "-D__int32=int");
298 #ifdef HAVE_LONG_LONG
299 strarray_add(comp_args, "-D__int64=long long");
300 #endif
302 /* options we handle explicitly */
303 if (opts->compile_only)
304 strarray_add(comp_args, "-c");
305 if (opts->output_name)
307 strarray_add(comp_args, "-o");
308 strarray_add(comp_args, opts->output_name);
311 /* the rest of the pass-through parameters */
312 for ( j = 0 ; j < opts->compiler_args->size ; j++ )
313 strarray_add(comp_args, opts->compiler_args->base[j]);
315 /* last, but not least, the files */
316 for ( j = 0; j < opts->files->size; j++ )
317 strarray_add(comp_args, opts->files->base[j]);
319 spawn(opts->prefix, comp_args);
322 static const char* compile_to_object(struct options* opts, const char* file)
324 struct options copts;
325 char* base_name;
327 /* make a copy we so don't change any of the initial stuff */
328 /* a shallow copy is exactly what we want in this case */
329 base_name = get_basename(file);
330 copts = *opts;
331 copts.processor = proc_cc;
332 copts.output_name = get_temp_file(base_name, ".o");
333 copts.compile_only = 1;
334 copts.files = strarray_alloc();
335 strarray_add(copts.files, file);
336 compile(&copts);
337 strarray_free(copts.files);
338 free(base_name);
340 return copts.output_name;
343 static void build(struct options* opts)
345 static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
346 strarray *lib_dirs, *files;
347 strarray *spec_args, *comp_args, *link_args;
348 char *spec_c_name, *spec_o_name, *base_file, *base_name;
349 const char* output_name;
350 const char* winebuild = getenv("WINEBUILD");
351 int generate_app_loader = 1;
352 int j;
354 /* NOTE: for the files array we'll use the following convention:
355 * -axxx: xxx is an archive (.a)
356 * -dxxx: xxx is a DLL (.def)
357 * -lxxx: xxx is an unsorted library
358 * -oxxx: xxx is an object (.o)
359 * -rxxx: xxx is a resource (.res)
360 * -sxxx: xxx is a shared lib (.so)
363 if (!winebuild) winebuild = "winebuild";
365 output_name = opts->output_name ? opts->output_name : "a.out";
367 /* get base filename by removing the .exe extension, if present */
368 base_file = strdup(output_name);
369 if (strendswith(base_file, ".exe.so"))
371 base_file[strlen(base_file) - 7] = 0;
372 generate_app_loader = 0;
374 else if (strendswith(base_file, ".exe")) base_file[strlen(base_file) - 4] = 0;
375 if ((base_name = strrchr(base_file, '/'))) base_name++;
376 else base_name = base_file;
378 /* 'winegcc -o app xxx.exe.so' only creates the load script */
379 if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
381 create_file(base_file, 0755, app_loader_template, opts->files->base[0]);
382 return;
385 /* prepare the linking path */
386 lib_dirs = strarray_dup(opts->lib_dirs);
387 if (!opts->wine_mode)
389 for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]);j++ )
390 strarray_add(lib_dirs, stdlibpath[j]);
393 /* mark the files with their appropriate type */
394 files = strarray_alloc();
395 for ( j = 0; j < opts->files->size; j++ )
397 const char* file = opts->files->base[j];
398 if (file[0] != '-')
400 switch(get_file_type(file))
402 case file_rc:
403 /* FIXME: invoke wrc to build it */
404 error("Can't compile .rc file at the moment: %s", file);
405 break;
406 case file_res:
407 strarray_add(files, strmake("-r%s", file));
408 break;
409 case file_obj:
410 strarray_add(files, strmake("-o%s", file));
411 break;
412 case file_na:
413 error("File does not exist: %s", file);
414 break;
415 default:
416 file = compile_to_object(opts, file);
417 strarray_add(files, strmake("-o%s", file));
418 break;
421 else if (file[1] == 'l')
423 char* fullname = 0;
424 switch(get_lib_type(lib_dirs, file + 2, &fullname))
426 case file_arh:
427 strarray_add(files, strmake("-a%s", fullname));
428 break;
429 case file_dll:
430 strarray_add(files, strmake("-d%s", file + 2));
431 break;
432 case file_so:
433 strarray_add(files, strmake("-s%s", file + 2));
434 break;
435 default:
436 /* keep it anyway, the linker may know what to do with it */
437 strarray_add(files, file);
438 break;
440 free(fullname);
444 /* add the default libraries, if needed */
445 if (!opts->nostdlib)
447 if (opts->use_msvcrt) strarray_add(files, "-dmsvcrt");
450 if (!opts->wine_mode && !opts->nodefaultlibs)
452 if (opts->gui_app)
454 strarray_add(files, "-dshell32");
455 strarray_add(files, "-dcomdlg32");
456 strarray_add(files, "-dgdi32");
458 strarray_add(files, "-dadvapi32");
459 strarray_add(files, "-duser32");
460 strarray_add(files, "-dkernel32");
463 /* run winebuild to generate the .spec.c file */
464 spec_args = strarray_alloc();
465 spec_c_name = get_temp_file(base_name, ".spec.c");
466 strarray_add(spec_args, winebuild);
467 strarray_add(spec_args, "-o");
468 strarray_add(spec_args, spec_c_name);
469 strarray_add(spec_args, "--exe");
470 strarray_add(spec_args, strmake("%s.exe", base_name));
471 strarray_add(spec_args, opts->gui_app ? "-mgui" : "-mcui");
473 for ( j = 0; j < lib_dirs->size; j++ )
474 strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
476 for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
477 strarray_add(spec_args, opts->winebuild_args->base[j]);
479 for ( j = 0; j < files->size; j++ )
481 const char* name = files->base[j] + 2;
482 switch(files->base[j][1])
484 case 'd':
485 strarray_add(spec_args, strmake("-l%s", name));
486 break;
487 case 'r':
488 strarray_add(spec_args, files->base[j]);
489 break;
490 case 'a':
491 case 'o':
492 strarray_add(spec_args, name);
493 break;
497 spawn(opts->prefix, spec_args);
499 /* compile the .spec.c file into a .spec.o file */
500 comp_args = strarray_alloc();
501 spec_o_name = get_temp_file(base_name, ".spec.o");
502 strarray_add(comp_args, CC);
503 strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
504 strarray_add(comp_args, "-o");
505 strarray_add(comp_args, spec_o_name);
506 strarray_add(comp_args, "-c");
507 strarray_add(comp_args, spec_c_name);
509 spawn(opts->prefix, comp_args);
511 /* link everything together now */
512 link_args = strarray_alloc();
513 strarray_addall(link_args, get_translator(opts));
514 strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
516 strarray_add(link_args, "-o");
517 strarray_add(link_args, strmake("%s.exe.so", base_file));
519 for ( j = 0 ; j < opts->linker_args->size ; j++ )
520 strarray_add(link_args, opts->linker_args->base[j]);
522 for ( j = 0; j < lib_dirs->size; j++ )
523 strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));
525 strarray_add(link_args, spec_o_name);
527 for ( j = 0; j < files->size; j++ )
529 const char* name = files->base[j] + 2;
530 switch(files->base[j][1])
532 case 'l':
533 case 's':
534 strarray_add(link_args, strmake("-l%s", name));
535 break;
536 case 'a':
537 case 'o':
538 strarray_add(link_args, name);
539 break;
543 if (!opts->nostdlib)
545 strarray_add(link_args, "-lwine");
546 strarray_add(link_args, "-lm");
547 strarray_add(link_args, "-lc");
550 spawn(opts->prefix, link_args);
552 /* create the loader script */
553 if (generate_app_loader)
554 create_file(base_file, 0755, app_loader_template, strmake("%s.exe.so", base_name));
558 static void forward(int argc, char **argv, struct options* opts)
560 strarray* args = strarray_alloc();
561 int j;
563 strarray_addall(args, get_translator(opts));
565 for( j = 1; j < argc; j++ )
566 strarray_add(args, argv[j]);
568 spawn(opts->prefix, args);
572 * Linker Options
573 * object-file-name -llibrary -nostartfiles -nodefaultlibs
574 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
575 * -symbolic -Wl,option -Xlinker option -u symbol
577 static int is_linker_arg(const char* arg)
579 static const char* link_switches[] =
581 "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
582 "-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic"
584 int j;
586 switch (arg[1])
588 case 'l':
589 case 'u':
590 return 1;
591 case 'W':
592 if (strncmp("-Wl,", arg, 4) == 0) return 1;
593 break;
594 case 'X':
595 if (strcmp("-Xlinker", arg) == 0) return 1;
596 break;
599 for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
600 if (strcmp(link_switches[j], arg) == 0) return 1;
602 return 0;
606 * Target Options
607 * -b machine -V version
609 static int is_target_arg(const char* arg)
611 return arg[1] == 'b' || arg[2] == 'V';
616 * Directory Options
617 * -Bprefix -Idir -I- -Ldir -specs=file
619 static int is_directory_arg(const char* arg)
621 return arg[1] == 'B' || arg[1] == 'L' || arg[1] == 'I' || strncmp("-specs=", arg, 7) == 0;
625 * MinGW Options
626 * -mno-cygwin -mwindows -mconsole -mthreads
628 static int is_mingw_arg(const char* arg)
630 static const char* mingw_switches[] =
632 "-mno-cygwin", "-mwindows", "-mconsole", "-mthreads"
634 int j;
636 for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
637 if (strcmp(mingw_switches[j], arg) == 0) return 1;
639 return 0;
642 int main(int argc, char **argv)
644 int i, c, next_is_arg = 0, linking = 1;
645 int raw_compiler_arg, raw_linker_arg;
646 const char* option_arg;
647 struct options opts;
648 char* str;
650 /* setup tmp file removal at exit */
651 tmp_files = strarray_alloc();
652 atexit(clean_temp_files);
654 /* initialize options */
655 memset(&opts, 0, sizeof(opts));
656 opts.lib_dirs = strarray_alloc();
657 opts.files = strarray_alloc();
658 opts.linker_args = strarray_alloc();
659 opts.compiler_args = strarray_alloc();
660 opts.winebuild_args = strarray_alloc();
662 /* determine the processor type */
663 if (strendswith(argv[0], "winecpp")) opts.processor = proc_cpp;
664 else if (strendswith(argv[0], "++")) opts.processor = proc_cxx;
666 /* parse options */
667 for ( i = 1 ; i < argc ; i++ )
669 if (argv[i][0] == '-') /* option */
671 /* determine if tihs switch is followed by a separate argument */
672 next_is_arg = 0;
673 option_arg = 0;
674 switch(argv[i][1])
676 case 'x': case 'o': case 'D': case 'U':
677 case 'I': case 'A': case 'l': case 'u':
678 case 'b': case 'V': case 'G': case 'L':
679 case 'B':
680 if (argv[i][2]) option_arg = &argv[i][2];
681 else next_is_arg = 1;
682 break;
683 case 'i':
684 next_is_arg = 1;
685 break;
686 case 'a':
687 if (strcmp("-aux-info", argv[i]) == 0)
688 next_is_arg = 1;
689 break;
690 case 'X':
691 if (strcmp("-Xlinker", argv[i]) == 0)
692 next_is_arg = 1;
693 break;
694 case 'M':
695 c = argv[i][2];
696 if (c == 'F' || c == 'T' || c == 'Q')
698 if (argv[i][3]) option_arg = &argv[i][3];
699 else next_is_arg = 1;
701 break;
703 if (next_is_arg) option_arg = argv[i+1];
705 /* determine what options go 'as is' to the linker & the compiler */
706 raw_compiler_arg = raw_linker_arg = 0;
707 if (is_linker_arg(argv[i]))
709 raw_linker_arg = 1;
711 else
713 if (is_directory_arg(argv[i]) || is_target_arg(argv[i]))
714 raw_linker_arg = 1;
715 raw_compiler_arg = !is_mingw_arg(argv[i]);
718 /* these things we handle explicitly so we don't pass them 'as is' */
719 if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L')
720 raw_linker_arg = 0;
721 if (argv[i][1] == 'c' || argv[i][1] == 'L')
722 raw_compiler_arg = 0;
723 if (argv[i][1] == 'o')
724 raw_compiler_arg = raw_linker_arg = 0;
726 /* do a bit of semantic analysis */
727 switch (argv[i][1])
729 case 'B':
730 str = strdup(option_arg);
731 if (strendswith(str, "/tools/winebuild"))
733 opts.wine_mode = 1;
734 /* don't pass it to the compiler, this generates warnings */
735 raw_compiler_arg = raw_linker_arg = 0;
737 if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
738 if (!opts.prefix) opts.prefix = strarray_alloc();
739 strarray_add(opts.prefix, str);
740 break;
741 case 'c': /* compile or assemble */
742 if (argv[i][2] == 0) opts.compile_only = 1;
743 /* fall through */
744 case 'S': /* generate assembler code */
745 case 'E': /* preprocess only */
746 if (argv[i][2] == 0) linking = 0;
747 break;
748 case 'f':
749 if (strcmp("-fno-short-wchar", argv[i]) == 0)
750 opts.noshortwchar = 1;
751 break;
752 case 'l':
753 strarray_add(opts.files, strmake("-l%s", option_arg));
754 break;
755 case 'L':
756 strarray_add(opts.lib_dirs, option_arg);
757 break;
758 case 'M': /* map file generation */
759 linking = 0;
760 break;
761 case 'm':
762 if (strcmp("-mno-cygwin", argv[i]) == 0)
763 opts.use_msvcrt = 1;
764 else if (strcmp("-mwindows", argv[i]) == 0)
765 opts.gui_app = 1;
766 else if (strcmp("-mconsole", argv[i]) == 0)
767 opts.gui_app = 0;
768 break;
769 case 'n':
770 if (strcmp("-nostdinc", argv[i]) == 0)
771 opts.nostdinc = 1;
772 else if (strcmp("-nodefaultlibs", argv[i]) == 0)
773 opts.nodefaultlibs = 1;
774 else if (strcmp("-nostdlib", argv[i]) == 0)
775 opts.nostdlib = 1;
776 break;
777 case 'o':
778 opts.output_name = option_arg;
779 break;
780 case 's':
781 if (strcmp("-static", argv[i]) == 0)
782 linking = -1;
783 else if(strcmp("-save-temps", argv[i]) == 0)
784 keep_generated = 1;
785 break;
786 case 'v':
787 if (argv[i][2] == 0) verbose++;
788 break;
789 case 'W':
790 if (strncmp("-Wl,", argv[i], 4) == 0)
792 if (strstr(argv[i], "-static"))
793 linking = -1;
795 else if (strncmp("-Wb,", argv[i], 4) == 0)
797 strarray* Wb = strarray_fromstring(argv[i] + 4, ",");
798 strarray_addall(opts.winebuild_args, Wb);
799 strarray_free(Wb);
801 break;
802 case '-':
803 if (strcmp("-static", argv[i]+1) == 0)
804 linking = -1;
805 break;
808 /* put the arg into the appropriate bucket */
809 if (raw_linker_arg)
811 strarray_add(opts.linker_args, argv[i]);
812 if (next_is_arg && (i + 1 < argc))
813 strarray_add(opts.linker_args, argv[i + 1]);
815 if (raw_compiler_arg)
817 strarray_add(opts.compiler_args, argv[i]);
818 if (next_is_arg && (i + 1 < argc))
819 strarray_add(opts.compiler_args, argv[i + 1]);
822 /* skip the next token if it's an argument */
823 if (next_is_arg) i++;
825 else
827 strarray_add(opts.files, argv[i]);
831 if (opts.processor == proc_cpp) linking = 0;
832 if (linking == -1) error("Static linking is not supported.");
834 if (opts.files->size == 0) forward(argc, argv, &opts);
835 else if (linking) build(&opts);
836 else compile(&opts);
838 return 0;