Replaced the --mode winebuild option by a --subsystem option for
[wine/multimedia.git] / tools / winegcc / winegcc.c
blobee675fb1927049914eacdb1c68ef8afdf9469e71
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 shared;
157 int use_msvcrt;
158 int nostdinc;
159 int nostdlib;
160 int nodefaultlibs;
161 int noshortwchar;
162 int gui_app;
163 int compile_only;
164 int wine_mode;
165 const char* output_name;
166 strarray* prefix;
167 strarray* lib_dirs;
168 strarray* linker_args;
169 strarray* compiler_args;
170 strarray* winebuild_args;
171 strarray* files;
174 static void clean_temp_files()
176 int i;
178 if (keep_generated) return;
180 for (i = 0; i < tmp_files->size; i++)
181 unlink(tmp_files->base[i]);
184 char* get_temp_file(const char* prefix, const char* suffix)
186 char* tmp = strmake("%s-XXXXXX%s", prefix, suffix);
187 int fd = mkstemps( tmp, strlen(suffix) );
188 if (fd == -1)
190 /* could not create it in current directory, try in /tmp */
191 free(tmp);
192 tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix);
193 fd = mkstemps( tmp, strlen(suffix) );
194 if (fd == -1) error( "could not create temp file" );
196 close( fd );
197 strarray_add(tmp_files, tmp);
199 return tmp;
202 static const strarray* get_translator(struct options* opts)
204 static strarray* cpp = 0;
205 static strarray* cc = 0;
206 static strarray* cxx = 0;
208 switch(opts->processor)
210 case proc_cpp:
211 if (!cpp) cpp = strarray_fromstring(CPP, " ");
212 return cpp;
213 case proc_cc:
214 if (!cc) cc = strarray_fromstring(CC, " ");
215 return cc;
216 case proc_cxx:
217 if (!cxx) cxx = strarray_fromstring(CXX, " ");
218 return cxx;
220 error("Unknown processor");
223 static void compile(struct options* opts)
225 strarray* comp_args = strarray_alloc();
226 int j, gcc_defs = 0;
228 switch(opts->processor)
230 case proc_cpp: gcc_defs = 1; break;
231 #ifdef __GNUC__
232 /* Note: if the C compiler is gcc we assume the C++ compiler is too */
233 /* mixing different C and C++ compilers isn't supported in configure anyway */
234 case proc_cc: gcc_defs = 1; break;
235 case proc_cxx: gcc_defs = 1; break;
236 #else
237 case proc_cc: gcc_defs = 0; break;
238 case proc_cxx: gcc_defs = 0; break;
239 #endif
241 strarray_addall(comp_args, get_translator(opts));
243 if (opts->processor != proc_cpp)
245 #ifdef CC_FLAG_SHORT_WCHAR
246 if (!opts->wine_mode && !opts->noshortwchar)
248 strarray_add(comp_args, CC_FLAG_SHORT_WCHAR);
249 strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
251 #endif
252 strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
254 if (!opts->wine_mode && !opts->nostdinc)
256 if (opts->use_msvcrt)
258 strarray_add(comp_args, "-I" INCLUDEDIR "/msvcrt");
259 strarray_add(comp_args, "-D__MSVCRT__");
261 strarray_add(comp_args, "-I" INCLUDEDIR "/windows");
263 strarray_add(comp_args, "-DWIN32");
264 strarray_add(comp_args, "-D_WIN32");
265 strarray_add(comp_args, "-D__WIN32");
266 strarray_add(comp_args, "-D__WIN32__");
267 strarray_add(comp_args, "-D__WINNT");
268 strarray_add(comp_args, "-D__WINNT__");
270 if (gcc_defs)
272 strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__))");
273 strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__))");
274 strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))");
275 strarray_add(comp_args, "-D_stdcall=__attribute__((__stdcall__))");
276 strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
277 strarray_add(comp_args, "-D_fastcall=__attribute__((__fastcall__))");
278 strarray_add(comp_args, "-D__declspec(x)=__declspec_##x");
279 strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
280 strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
281 strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
282 strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
283 strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
284 strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))");
285 strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))");
286 strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
287 strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
288 strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
289 strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))");
290 strarray_add(comp_args, "-D__declspec_thread=__thread");
293 /* Wine specific defines */
294 strarray_add(comp_args, "-D__WINE__");
295 strarray_add(comp_args, "-D__int8=char");
296 strarray_add(comp_args, "-D__int16=short");
297 /* FIXME: what about 64-bit platforms? */
298 strarray_add(comp_args, "-D__int32=int");
299 #ifdef HAVE_LONG_LONG
300 strarray_add(comp_args, "-D__int64=long long");
301 #endif
303 /* options we handle explicitly */
304 if (opts->compile_only)
305 strarray_add(comp_args, "-c");
306 if (opts->output_name)
308 strarray_add(comp_args, "-o");
309 strarray_add(comp_args, opts->output_name);
312 /* the rest of the pass-through parameters */
313 for ( j = 0 ; j < opts->compiler_args->size ; j++ )
314 strarray_add(comp_args, opts->compiler_args->base[j]);
316 /* last, but not least, the files */
317 for ( j = 0; j < opts->files->size; j++ )
318 strarray_add(comp_args, opts->files->base[j]);
320 spawn(opts->prefix, comp_args);
323 static const char* compile_to_object(struct options* opts, const char* file)
325 struct options copts;
326 char* base_name;
328 /* make a copy we so don't change any of the initial stuff */
329 /* a shallow copy is exactly what we want in this case */
330 base_name = get_basename(file);
331 copts = *opts;
332 copts.processor = proc_cc;
333 copts.output_name = get_temp_file(base_name, ".o");
334 copts.compile_only = 1;
335 copts.files = strarray_alloc();
336 strarray_add(copts.files, file);
337 compile(&copts);
338 strarray_free(copts.files);
339 free(base_name);
341 return copts.output_name;
344 static void build(struct options* opts)
346 static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
347 strarray *lib_dirs, *files;
348 strarray *spec_args, *comp_args, *link_args;
349 char *output_file;
350 const char *spec_c_name, *spec_o_name;
351 const char *output_name, *spec_file;
352 const char* winebuild = getenv("WINEBUILD");
353 int generate_app_loader = 1;
354 int j;
356 /* NOTE: for the files array we'll use the following convention:
357 * -axxx: xxx is an archive (.a)
358 * -dxxx: xxx is a DLL (.def)
359 * -lxxx: xxx is an unsorted library
360 * -oxxx: xxx is an object (.o)
361 * -rxxx: xxx is a resource (.res)
362 * -sxxx: xxx is a shared lib (.so)
365 if (!winebuild) winebuild = "winebuild";
367 output_file = strdup( opts->output_name ? opts->output_name : "a.out" );
369 /* 'winegcc -o app xxx.exe.so' only creates the load script */
370 if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
372 create_file(output_file, 0755, app_loader_template, opts->files->base[0]);
373 return;
376 /* generate app loader only for .exe */
377 if (opts->shared || strendswith(output_file, ".exe.so"))
378 generate_app_loader = 0;
380 /* normalize the filename a bit: strip .so, ensure it has proper ext */
381 if (strendswith(output_file, ".so"))
382 output_file[strlen(output_file) - 3] = 0;
383 if (opts->shared)
385 if ((output_name = strrchr(output_file, '/'))) output_name++;
386 else output_name = output_file;
387 if (!strchr(output_name, '.'))
388 output_file = strmake("%s.dll", output_file);
390 else if (!strendswith(output_file, ".exe"))
391 output_file = strmake("%s.exe", output_file);
393 /* get the filename by the path, if present */
394 if ((output_name = strrchr(output_file, '/'))) output_name++;
395 else output_name = output_file;
397 /* prepare the linking path */
398 lib_dirs = strarray_dup(opts->lib_dirs);
399 if (!opts->wine_mode)
401 for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]); j++ )
402 strarray_add(lib_dirs, stdlibpath[j]);
405 /* mark the files with their appropriate type */
406 spec_file = 0;
407 files = strarray_alloc();
408 for ( j = 0; j < opts->files->size; j++ )
410 const char* file = opts->files->base[j];
411 if (file[0] != '-')
413 switch(get_file_type(file))
415 case file_def:
416 case file_spec:
417 if (!opts->shared)
418 error("Spec file %s not supported in non-shared mode", file);
419 if (spec_file)
420 error("Only one spec file can be specified in shared mode");
421 spec_file = file;
422 break;
423 case file_rc:
424 /* FIXME: invoke wrc to build it */
425 error("Can't compile .rc file at the moment: %s", file);
426 break;
427 case file_res:
428 strarray_add(files, strmake("-r%s", file));
429 break;
430 case file_obj:
431 strarray_add(files, strmake("-o%s", file));
432 break;
433 case file_na:
434 error("File does not exist: %s", file);
435 break;
436 default:
437 file = compile_to_object(opts, file);
438 strarray_add(files, strmake("-o%s", file));
439 break;
442 else if (file[1] == 'l')
444 char* fullname = 0;
445 switch(get_lib_type(lib_dirs, file + 2, &fullname))
447 case file_arh:
448 strarray_add(files, strmake("-a%s", fullname));
449 break;
450 case file_dll:
451 strarray_add(files, strmake("-d%s", file + 2));
452 break;
453 case file_so:
454 strarray_add(files, strmake("-s%s", file + 2));
455 break;
456 default:
457 /* keep it anyway, the linker may know what to do with it */
458 strarray_add(files, file);
459 break;
461 free(fullname);
464 if (opts->shared && !spec_file)
465 error("A spec file is currently needed in shared mode");
467 /* add the default libraries, if needed */
468 if (!opts->nostdlib)
470 if (opts->use_msvcrt) strarray_add(files, "-dmsvcrt");
473 if (!opts->wine_mode && !opts->nodefaultlibs)
475 if (opts->gui_app)
477 strarray_add(files, "-dshell32");
478 strarray_add(files, "-dcomdlg32");
479 strarray_add(files, "-dgdi32");
481 strarray_add(files, "-dadvapi32");
482 strarray_add(files, "-duser32");
483 strarray_add(files, "-dkernel32");
486 /* run winebuild to generate the .spec.c file */
487 spec_args = strarray_alloc();
488 spec_c_name = get_temp_file(output_name, ".spec.c");
489 strarray_add(spec_args, winebuild);
490 strarray_add(spec_args, "-o");
491 strarray_add(spec_args, spec_c_name);
492 if (opts->shared)
494 strarray_add(spec_args, "--dll");
495 strarray_add(spec_args, spec_file);
497 else
499 strarray_add(spec_args, "--exe");
500 strarray_add(spec_args, output_name);
501 strarray_add(spec_args, "--subsystem");
502 strarray_add(spec_args, opts->gui_app ? "windows" : "console");
505 for ( j = 0; j < lib_dirs->size; j++ )
506 strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
508 for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
509 strarray_add(spec_args, opts->winebuild_args->base[j]);
511 for ( j = 0; j < files->size; j++ )
513 const char* name = files->base[j] + 2;
514 switch(files->base[j][1])
516 case 'd':
517 strarray_add(spec_args, strmake("-l%s", name));
518 break;
519 case 'r':
520 strarray_add(spec_args, files->base[j]);
521 break;
522 case 'a':
523 case 'o':
524 strarray_add(spec_args, name);
525 break;
529 spawn(opts->prefix, spec_args);
531 /* compile the .spec.c file into a .spec.o file */
532 comp_args = strarray_alloc();
533 spec_o_name = compile_to_object(opts, spec_c_name);
535 /* link everything together now */
536 link_args = strarray_alloc();
537 strarray_addall(link_args, get_translator(opts));
538 strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
540 strarray_add(link_args, "-o");
541 strarray_add(link_args, strmake("%s.so", output_file));
543 for ( j = 0 ; j < opts->linker_args->size ; j++ )
544 strarray_add(link_args, opts->linker_args->base[j]);
546 for ( j = 0; j < lib_dirs->size; j++ )
547 strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));
549 strarray_add(link_args, spec_o_name);
551 for ( j = 0; j < files->size; j++ )
553 const char* name = files->base[j] + 2;
554 switch(files->base[j][1])
556 case 'l':
557 case 's':
558 strarray_add(link_args, strmake("-l%s", name));
559 break;
560 case 'a':
561 case 'o':
562 strarray_add(link_args, name);
563 break;
567 if (!opts->nostdlib)
569 strarray_add(link_args, "-lwine");
570 strarray_add(link_args, "-lm");
571 strarray_add(link_args, "-lc");
574 spawn(opts->prefix, link_args);
576 /* create the loader script */
577 if (generate_app_loader)
579 if (strendswith(output_file, ".exe")) output_file[strlen(output_file) - 4] = 0;
580 create_file(output_file, 0755, app_loader_template, strmake("%s.so", output_name));
585 static void forward(int argc, char **argv, struct options* opts)
587 strarray* args = strarray_alloc();
588 int j;
590 strarray_addall(args, get_translator(opts));
592 for( j = 1; j < argc; j++ )
593 strarray_add(args, argv[j]);
595 spawn(opts->prefix, args);
599 * Linker Options
600 * object-file-name -llibrary -nostartfiles -nodefaultlibs
601 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
602 * -symbolic -Wl,option -Xlinker option -u symbol
604 static int is_linker_arg(const char* arg)
606 static const char* link_switches[] =
608 "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
609 "-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic"
611 int j;
613 switch (arg[1])
615 case 'l':
616 case 'u':
617 return 1;
618 case 'W':
619 if (strncmp("-Wl,", arg, 4) == 0) return 1;
620 break;
621 case 'X':
622 if (strcmp("-Xlinker", arg) == 0) return 1;
623 break;
626 for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
627 if (strcmp(link_switches[j], arg) == 0) return 1;
629 return 0;
633 * Target Options
634 * -b machine -V version
636 static int is_target_arg(const char* arg)
638 return arg[1] == 'b' || arg[2] == 'V';
643 * Directory Options
644 * -Bprefix -Idir -I- -Ldir -specs=file
646 static int is_directory_arg(const char* arg)
648 return arg[1] == 'B' || arg[1] == 'L' || arg[1] == 'I' || strncmp("-specs=", arg, 7) == 0;
652 * MinGW Options
653 * -mno-cygwin -mwindows -mconsole -mthreads
655 static int is_mingw_arg(const char* arg)
657 static const char* mingw_switches[] =
659 "-mno-cygwin", "-mwindows", "-mconsole", "-mthreads"
661 int j;
663 for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
664 if (strcmp(mingw_switches[j], arg) == 0) return 1;
666 return 0;
669 int main(int argc, char **argv)
671 int i, c, next_is_arg = 0, linking = 1;
672 int raw_compiler_arg, raw_linker_arg;
673 const char* option_arg;
674 struct options opts;
675 char* str;
677 /* setup tmp file removal at exit */
678 tmp_files = strarray_alloc();
679 atexit(clean_temp_files);
681 /* initialize options */
682 memset(&opts, 0, sizeof(opts));
683 opts.lib_dirs = strarray_alloc();
684 opts.files = strarray_alloc();
685 opts.linker_args = strarray_alloc();
686 opts.compiler_args = strarray_alloc();
687 opts.winebuild_args = strarray_alloc();
689 /* determine the processor type */
690 if (strendswith(argv[0], "winecpp")) opts.processor = proc_cpp;
691 else if (strendswith(argv[0], "++")) opts.processor = proc_cxx;
693 /* parse options */
694 for ( i = 1 ; i < argc ; i++ )
696 if (argv[i][0] == '-') /* option */
698 /* determine if tihs switch is followed by a separate argument */
699 next_is_arg = 0;
700 option_arg = 0;
701 switch(argv[i][1])
703 case 'x': case 'o': case 'D': case 'U':
704 case 'I': case 'A': case 'l': case 'u':
705 case 'b': case 'V': case 'G': case 'L':
706 case 'B':
707 if (argv[i][2]) option_arg = &argv[i][2];
708 else next_is_arg = 1;
709 break;
710 case 'i':
711 next_is_arg = 1;
712 break;
713 case 'a':
714 if (strcmp("-aux-info", argv[i]) == 0)
715 next_is_arg = 1;
716 break;
717 case 'X':
718 if (strcmp("-Xlinker", argv[i]) == 0)
719 next_is_arg = 1;
720 break;
721 case 'M':
722 c = argv[i][2];
723 if (c == 'F' || c == 'T' || c == 'Q')
725 if (argv[i][3]) option_arg = &argv[i][3];
726 else next_is_arg = 1;
728 break;
730 if (next_is_arg) option_arg = argv[i+1];
732 /* determine what options go 'as is' to the linker & the compiler */
733 raw_compiler_arg = raw_linker_arg = 0;
734 if (is_linker_arg(argv[i]))
736 raw_linker_arg = 1;
738 else
740 if (is_directory_arg(argv[i]) || is_target_arg(argv[i]))
741 raw_linker_arg = 1;
742 raw_compiler_arg = !is_mingw_arg(argv[i]);
745 /* these things we handle explicitly so we don't pass them 'as is' */
746 if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L')
747 raw_linker_arg = 0;
748 if (argv[i][1] == 'c' || argv[i][1] == 'L')
749 raw_compiler_arg = 0;
750 if (argv[i][1] == 'o')
751 raw_compiler_arg = raw_linker_arg = 0;
753 /* do a bit of semantic analysis */
754 switch (argv[i][1])
756 case 'B':
757 str = strdup(option_arg);
758 if (strendswith(str, "/tools/winebuild"))
760 opts.wine_mode = 1;
761 /* don't pass it to the compiler, this generates warnings */
762 raw_compiler_arg = raw_linker_arg = 0;
764 if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
765 if (!opts.prefix) opts.prefix = strarray_alloc();
766 strarray_add(opts.prefix, str);
767 break;
768 case 'c': /* compile or assemble */
769 if (argv[i][2] == 0) opts.compile_only = 1;
770 /* fall through */
771 case 'S': /* generate assembler code */
772 case 'E': /* preprocess only */
773 if (argv[i][2] == 0) linking = 0;
774 break;
775 case 'f':
776 if (strcmp("-fno-short-wchar", argv[i]) == 0)
777 opts.noshortwchar = 1;
778 break;
779 case 'l':
780 strarray_add(opts.files, strmake("-l%s", option_arg));
781 break;
782 case 'L':
783 strarray_add(opts.lib_dirs, option_arg);
784 break;
785 case 'M': /* map file generation */
786 linking = 0;
787 break;
788 case 'm':
789 if (strcmp("-mno-cygwin", argv[i]) == 0)
790 opts.use_msvcrt = 1;
791 else if (strcmp("-mwindows", argv[i]) == 0)
792 opts.gui_app = 1;
793 else if (strcmp("-mconsole", argv[i]) == 0)
794 opts.gui_app = 0;
795 break;
796 case 'n':
797 if (strcmp("-nostdinc", argv[i]) == 0)
798 opts.nostdinc = 1;
799 else if (strcmp("-nodefaultlibs", argv[i]) == 0)
800 opts.nodefaultlibs = 1;
801 else if (strcmp("-nostdlib", argv[i]) == 0)
802 opts.nostdlib = 1;
803 break;
804 case 'o':
805 opts.output_name = option_arg;
806 break;
807 case 's':
808 if (strcmp("-static", argv[i]) == 0)
809 linking = -1;
810 else if(strcmp("-save-temps", argv[i]) == 0)
811 keep_generated = 1;
812 else if(strcmp("-shared", argv[i]) == 0)
814 opts.shared = 1;
815 raw_compiler_arg = raw_linker_arg = 0;
817 break;
818 case 'v':
819 if (argv[i][2] == 0) verbose++;
820 break;
821 case 'W':
822 if (strncmp("-Wl,", argv[i], 4) == 0)
824 if (strstr(argv[i], "-static"))
825 linking = -1;
827 else if (strncmp("-Wb,", argv[i], 4) == 0)
829 strarray* Wb = strarray_fromstring(argv[i] + 4, ",");
830 strarray_addall(opts.winebuild_args, Wb);
831 strarray_free(Wb);
832 /* don't pass it to the compiler, it generates errors */
833 raw_compiler_arg = raw_linker_arg = 0;
835 break;
836 case '-':
837 if (strcmp("-static", argv[i]+1) == 0)
838 linking = -1;
839 break;
842 /* put the arg into the appropriate bucket */
843 if (raw_linker_arg)
845 strarray_add(opts.linker_args, argv[i]);
846 if (next_is_arg && (i + 1 < argc))
847 strarray_add(opts.linker_args, argv[i + 1]);
849 if (raw_compiler_arg)
851 strarray_add(opts.compiler_args, argv[i]);
852 if (next_is_arg && (i + 1 < argc))
853 strarray_add(opts.compiler_args, argv[i + 1]);
856 /* skip the next token if it's an argument */
857 if (next_is_arg) i++;
859 else
861 strarray_add(opts.files, argv[i]);
865 if (opts.processor == proc_cpp) linking = 0;
866 if (linking == -1) error("Static linking is not supported.");
868 if (opts.files->size == 0) forward(argc, argv, &opts);
869 else if (linking) build(&opts);
870 else compile(&opts);
872 return 0;