Moved code specific to CPGenKey, CPDeriveKey or CPImportKey from
[wine.git] / tools / winegcc / winegcc.c
blob40f749f33e6dc2de1aedbb7437812f4c11400726
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 "# figure out the full app path\n"
123 "if [ -n \"$appdir\" ]; then\n"
124 " apppath=\"$appdir/$appname\"\n"
125 " WINEDLLPATH=\"$appdir:$WINEDLLPATH\"\n"
126 " export WINEDLLPATH\n"
127 "else\n"
128 " apppath=\"$appname\"\n"
129 "fi\n"
130 "\n"
131 "# determine the WINELOADER\n"
132 "if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
133 "\n"
134 "# and try to start the app\n"
135 "exec \"$WINELOADER\" \"$apppath\" \"$@\"\n"
138 static int keep_generated = 0;
139 static strarray* tmp_files;
141 struct options
143 enum { proc_cc = 0, proc_cxx = 1, proc_cpp = 2} processor;
144 int shared;
145 int use_msvcrt;
146 int nostdinc;
147 int nostdlib;
148 int nodefaultlibs;
149 int noshortwchar;
150 int gui_app;
151 int compile_only;
152 int wine_mode;
153 const char* output_name;
154 strarray* prefix;
155 strarray* lib_dirs;
156 strarray* linker_args;
157 strarray* compiler_args;
158 strarray* winebuild_args;
159 strarray* files;
162 static void clean_temp_files()
164 int i;
166 if (keep_generated) return;
168 for (i = 0; i < tmp_files->size; i++)
169 unlink(tmp_files->base[i]);
172 char* get_temp_file(const char* prefix, const char* suffix)
174 char* tmp = strmake("%s-XXXXXX%s", prefix, suffix);
175 int fd = mkstemps( tmp, strlen(suffix) );
176 if (fd == -1)
178 /* could not create it in current directory, try in /tmp */
179 free(tmp);
180 tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix);
181 fd = mkstemps( tmp, strlen(suffix) );
182 if (fd == -1) error( "could not create temp file" );
184 close( fd );
185 strarray_add(tmp_files, tmp);
187 return tmp;
190 static const strarray* get_translator(struct options* opts)
192 static strarray* cpp = 0;
193 static strarray* cc = 0;
194 static strarray* cxx = 0;
196 switch(opts->processor)
198 case proc_cpp:
199 if (!cpp) cpp = strarray_fromstring(CPP, " ");
200 return cpp;
201 case proc_cc:
202 if (!cc) cc = strarray_fromstring(CC, " ");
203 return cc;
204 case proc_cxx:
205 if (!cxx) cxx = strarray_fromstring(CXX, " ");
206 return cxx;
208 error("Unknown processor");
211 static void compile(struct options* opts, const char* lang)
213 strarray* comp_args = strarray_alloc();
214 int j, gcc_defs = 0;
216 switch(opts->processor)
218 case proc_cpp: gcc_defs = 1; break;
219 #ifdef __GNUC__
220 /* Note: if the C compiler is gcc we assume the C++ compiler is too */
221 /* mixing different C and C++ compilers isn't supported in configure anyway */
222 case proc_cc: gcc_defs = 1; break;
223 case proc_cxx: gcc_defs = 1; break;
224 #else
225 case proc_cc: gcc_defs = 0; break;
226 case proc_cxx: gcc_defs = 0; break;
227 #endif
229 strarray_addall(comp_args, get_translator(opts));
231 if (opts->processor != proc_cpp)
233 #ifdef CC_FLAG_SHORT_WCHAR
234 if (!opts->wine_mode && !opts->noshortwchar)
236 strarray_add(comp_args, CC_FLAG_SHORT_WCHAR);
237 strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
239 #endif
240 strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
242 if (!opts->wine_mode && !opts->nostdinc)
244 if (opts->use_msvcrt)
246 strarray_add(comp_args, "-I" INCLUDEDIR "/msvcrt");
247 strarray_add(comp_args, "-D__MSVCRT__");
249 strarray_add(comp_args, "-I" INCLUDEDIR "/windows");
251 strarray_add(comp_args, "-DWIN32");
252 strarray_add(comp_args, "-D_WIN32");
253 strarray_add(comp_args, "-D__WIN32");
254 strarray_add(comp_args, "-D__WIN32__");
255 strarray_add(comp_args, "-D__WINNT");
256 strarray_add(comp_args, "-D__WINNT__");
258 if (gcc_defs)
260 strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__))");
261 strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__))");
262 strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))");
263 strarray_add(comp_args, "-D_stdcall=__attribute__((__stdcall__))");
264 strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
265 strarray_add(comp_args, "-D_fastcall=__attribute__((__fastcall__))");
266 strarray_add(comp_args, "-D__declspec(x)=__declspec_##x");
267 strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
268 strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
269 strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
270 strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
271 strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
272 strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))");
273 strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))");
274 strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
275 strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
276 strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
277 strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))");
278 strarray_add(comp_args, "-D__declspec_thread=__thread");
281 /* Wine specific defines */
282 strarray_add(comp_args, "-D__WINE__");
283 strarray_add(comp_args, "-D__int8=char");
284 strarray_add(comp_args, "-D__int16=short");
285 /* FIXME: what about 64-bit platforms? */
286 strarray_add(comp_args, "-D__int32=int");
287 #ifdef HAVE_LONG_LONG
288 strarray_add(comp_args, "-D__int64=long long");
289 #endif
291 /* options we handle explicitly */
292 if (opts->compile_only)
293 strarray_add(comp_args, "-c");
294 if (opts->output_name)
296 strarray_add(comp_args, "-o");
297 strarray_add(comp_args, opts->output_name);
300 /* the rest of the pass-through parameters */
301 for ( j = 0 ; j < opts->compiler_args->size ; j++ )
302 strarray_add(comp_args, opts->compiler_args->base[j]);
304 /* the language option, if any */
305 if (lang && strcmp(lang, "-xnone"))
306 strarray_add(comp_args, lang);
308 /* last, but not least, the files */
309 for ( j = 0; j < opts->files->size; j++ )
311 if (opts->files->base[j][0] != '-')
312 strarray_add(comp_args, opts->files->base[j]);
315 spawn(opts->prefix, comp_args);
318 static const char* compile_to_object(struct options* opts, const char* file, const char* lang)
320 struct options copts;
321 char* base_name;
323 /* make a copy we so don't change any of the initial stuff */
324 /* a shallow copy is exactly what we want in this case */
325 base_name = get_basename(file);
326 copts = *opts;
327 copts.output_name = get_temp_file(base_name, ".o");
328 copts.compile_only = 1;
329 copts.files = strarray_alloc();
330 strarray_add(copts.files, file);
331 compile(&copts, lang);
332 strarray_free(copts.files);
333 free(base_name);
335 return copts.output_name;
338 static void build(struct options* opts)
340 static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
341 strarray *lib_dirs, *files;
342 strarray *spec_args, *link_args;
343 char *output_file;
344 const char *spec_c_name, *spec_o_name;
345 const char *output_name, *spec_file, *lang;
346 const char* winebuild = getenv("WINEBUILD");
347 int generate_app_loader = 1;
348 int old_processor;
349 int j;
351 /* NOTE: for the files array we'll use the following convention:
352 * -axxx: xxx is an archive (.a)
353 * -dxxx: xxx is a DLL (.def)
354 * -lxxx: xxx is an unsorted library
355 * -oxxx: xxx is an object (.o)
356 * -rxxx: xxx is a resource (.res)
357 * -sxxx: xxx is a shared lib (.so)
358 * -xlll: lll is the language (c, c++, etc.)
361 if (!winebuild) winebuild = "winebuild";
363 output_file = strdup( opts->output_name ? opts->output_name : "a.out" );
365 /* 'winegcc -o app xxx.exe.so' only creates the load script */
366 if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
368 create_file(output_file, 0755, app_loader_template, opts->files->base[0]);
369 return;
372 /* generate app loader only for .exe */
373 if (opts->shared || strendswith(output_file, ".exe.so"))
374 generate_app_loader = 0;
376 /* normalize the filename a bit: strip .so, ensure it has proper ext */
377 if (strendswith(output_file, ".so"))
378 output_file[strlen(output_file) - 3] = 0;
379 if (opts->shared)
381 if ((output_name = strrchr(output_file, '/'))) output_name++;
382 else output_name = output_file;
383 if (!strchr(output_name, '.'))
384 output_file = strmake("%s.dll", output_file);
386 else if (!strendswith(output_file, ".exe"))
387 output_file = strmake("%s.exe", output_file);
389 /* get the filename from the path */
390 if ((output_name = strrchr(output_file, '/'))) output_name++;
391 else output_name = output_file;
393 /* prepare the linking path */
394 lib_dirs = strarray_dup(opts->lib_dirs);
395 if (!opts->wine_mode)
397 for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]); j++ )
398 strarray_add(lib_dirs, stdlibpath[j]);
401 /* mark the files with their appropriate type */
402 spec_file = lang = 0;
403 files = strarray_alloc();
404 for ( j = 0; j < opts->files->size; j++ )
406 const char* file = opts->files->base[j];
407 if (file[0] != '-')
409 switch(get_file_type(file))
411 case file_def:
412 case file_spec:
413 if (!opts->shared)
414 error("Spec file %s not supported in non-shared mode", file);
415 if (spec_file)
416 error("Only one spec file can be specified in shared mode");
417 spec_file = file;
418 break;
419 case file_rc:
420 /* FIXME: invoke wrc to build it */
421 error("Can't compile .rc file at the moment: %s", file);
422 break;
423 case file_res:
424 strarray_add(files, strmake("-r%s", file));
425 break;
426 case file_obj:
427 strarray_add(files, strmake("-o%s", file));
428 break;
429 case file_arh:
430 strarray_add(files, strmake("-a%s", file));
431 break;
432 case file_so:
433 strarray_add(files, strmake("-s%s", file));
434 break;
435 case file_na:
436 error("File does not exist: %s", file);
437 break;
438 default:
439 file = compile_to_object(opts, file, lang);
440 strarray_add(files, strmake("-o%s", file));
441 break;
444 else if (file[1] == 'l')
446 char* fullname = 0;
447 switch(get_lib_type(lib_dirs, file + 2, &fullname))
449 case file_arh:
450 strarray_add(files, strmake("-a%s", fullname));
451 break;
452 case file_dll:
453 strarray_add(files, strmake("-d%s", file + 2));
454 break;
455 case file_so:
456 strarray_add(files, strmake("-s%s", file + 2));
457 break;
458 default:
459 /* keep it anyway, the linker may know what to do with it */
460 strarray_add(files, file);
461 break;
463 free(fullname);
465 else if (file[1] == 'x')
466 lang = file;
468 if (opts->shared && !spec_file)
469 error("A spec file is currently needed in shared mode");
471 /* add the default libraries, if needed */
472 if (!opts->nostdlib)
474 if (opts->use_msvcrt) strarray_add(files, "-dmsvcrt");
477 if (!opts->wine_mode && !opts->nodefaultlibs)
479 if (opts->gui_app)
481 strarray_add(files, "-dshell32");
482 strarray_add(files, "-dcomdlg32");
483 strarray_add(files, "-dgdi32");
485 strarray_add(files, "-dadvapi32");
486 strarray_add(files, "-duser32");
487 strarray_add(files, "-dkernel32");
490 /* run winebuild to generate the .spec.c file */
491 spec_args = strarray_alloc();
492 spec_c_name = get_temp_file(output_name, ".spec.c");
493 strarray_add(spec_args, winebuild);
494 strarray_add(spec_args, "--ld-cmd");
495 strarray_add(spec_args, LD);
496 strarray_addall(spec_args, strarray_fromstring(DLLFLAGS, " "));
497 strarray_add(spec_args, "-o");
498 strarray_add(spec_args, spec_c_name);
499 if (opts->shared)
501 strarray_add(spec_args, "--dll");
502 strarray_add(spec_args, spec_file);
504 else
506 strarray_add(spec_args, "--exe");
507 strarray_add(spec_args, output_name);
508 strarray_add(spec_args, "--subsystem");
509 strarray_add(spec_args, opts->gui_app ? "windows" : "console");
512 for ( j = 0; j < lib_dirs->size; j++ )
513 strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
515 for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
516 strarray_add(spec_args, opts->winebuild_args->base[j]);
518 for ( j = 0; j < files->size; j++ )
520 const char* name = files->base[j] + 2;
521 switch(files->base[j][1])
523 case 'd':
524 strarray_add(spec_args, strmake("-l%s", name));
525 break;
526 case 'r':
527 strarray_add(spec_args, files->base[j]);
528 break;
529 case 'a':
530 case 'o':
531 strarray_add(spec_args, name);
532 break;
536 spawn(opts->prefix, spec_args);
538 /* compile the .spec.c file into a .spec.o file */
539 old_processor = opts->processor;
540 /* Always compile spec.c as c, even if linking with g++ */
541 opts->processor = proc_cc;
542 spec_o_name = compile_to_object(opts, spec_c_name, 0);
543 opts->processor = old_processor;
545 /* link everything together now */
546 link_args = strarray_alloc();
547 strarray_addall(link_args, get_translator(opts));
548 strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
550 strarray_add(link_args, "-o");
551 strarray_add(link_args, strmake("%s.so", output_file));
553 for ( j = 0 ; j < opts->linker_args->size ; j++ )
554 strarray_add(link_args, opts->linker_args->base[j]);
556 for ( j = 0; j < lib_dirs->size; j++ )
557 strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));
559 strarray_add(link_args, spec_o_name);
561 for ( j = 0; j < files->size; j++ )
563 const char* name = files->base[j] + 2;
564 switch(files->base[j][1])
566 case 'l':
567 case 's':
568 strarray_add(link_args, strmake("-l%s", name));
569 break;
570 case 'a':
571 case 'o':
572 strarray_add(link_args, name);
573 break;
577 if (!opts->nostdlib)
579 strarray_add(link_args, "-lwine");
580 strarray_add(link_args, "-lm");
581 strarray_add(link_args, "-lc");
584 spawn(opts->prefix, link_args);
586 /* create the loader script */
587 if (generate_app_loader)
589 if (strendswith(output_file, ".exe")) output_file[strlen(output_file) - 4] = 0;
590 create_file(output_file, 0755, app_loader_template, strmake("%s.exe.so", output_name));
595 static void forward(int argc, char **argv, struct options* opts)
597 strarray* args = strarray_alloc();
598 int j;
600 strarray_addall(args, get_translator(opts));
602 for( j = 1; j < argc; j++ )
603 strarray_add(args, argv[j]);
605 spawn(opts->prefix, args);
609 * Linker Options
610 * object-file-name -llibrary -nostartfiles -nodefaultlibs
611 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
612 * -symbolic -Wl,option -Xlinker option -u symbol
613 * -framework name
615 static int is_linker_arg(const char* arg)
617 static const char* link_switches[] =
619 "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
620 "-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic",
621 "-framework"
623 int j;
625 switch (arg[1])
627 case 'l':
628 case 'u':
629 return 1;
630 case 'W':
631 if (strncmp("-Wl,", arg, 4) == 0) return 1;
632 break;
633 case 'X':
634 if (strcmp("-Xlinker", arg) == 0) return 1;
635 break;
638 for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
639 if (strcmp(link_switches[j], arg) == 0) return 1;
641 return 0;
645 * Target Options
646 * -b machine -V version
648 static int is_target_arg(const char* arg)
650 return arg[1] == 'b' || arg[2] == 'V';
655 * Directory Options
656 * -Bprefix -Idir -I- -Ldir -specs=file
658 static int is_directory_arg(const char* arg)
660 return arg[1] == 'B' || arg[1] == 'L' || arg[1] == 'I' || strncmp("-specs=", arg, 7) == 0;
664 * MinGW Options
665 * -mno-cygwin -mwindows -mconsole -mthreads
667 static int is_mingw_arg(const char* arg)
669 static const char* mingw_switches[] =
671 "-mno-cygwin", "-mwindows", "-mconsole", "-mthreads"
673 int j;
675 for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
676 if (strcmp(mingw_switches[j], arg) == 0) return 1;
678 return 0;
681 int main(int argc, char **argv)
683 int i, c, next_is_arg = 0, linking = 1;
684 int raw_compiler_arg, raw_linker_arg;
685 const char* option_arg;
686 struct options opts;
687 char* lang = 0;
688 char* str;
690 /* setup tmp file removal at exit */
691 tmp_files = strarray_alloc();
692 atexit(clean_temp_files);
694 /* initialize options */
695 memset(&opts, 0, sizeof(opts));
696 opts.lib_dirs = strarray_alloc();
697 opts.files = strarray_alloc();
698 opts.linker_args = strarray_alloc();
699 opts.compiler_args = strarray_alloc();
700 opts.winebuild_args = strarray_alloc();
702 /* determine the processor type */
703 if (strendswith(argv[0], "winecpp")) opts.processor = proc_cpp;
704 else if (strendswith(argv[0], "++")) opts.processor = proc_cxx;
706 /* parse options */
707 for ( i = 1 ; i < argc ; i++ )
709 if (argv[i][0] == '-') /* option */
711 /* determine if tihs switch is followed by a separate argument */
712 next_is_arg = 0;
713 option_arg = 0;
714 switch(argv[i][1])
716 case 'x': case 'o': case 'D': case 'U':
717 case 'I': case 'A': case 'l': case 'u':
718 case 'b': case 'V': case 'G': case 'L':
719 case 'B':
720 if (argv[i][2]) option_arg = &argv[i][2];
721 else next_is_arg = 1;
722 break;
723 case 'i':
724 next_is_arg = 1;
725 break;
726 case 'a':
727 if (strcmp("-aux-info", argv[i]) == 0)
728 next_is_arg = 1;
729 break;
730 case 'X':
731 if (strcmp("-Xlinker", argv[i]) == 0)
732 next_is_arg = 1;
733 break;
734 case 'M':
735 c = argv[i][2];
736 if (c == 'F' || c == 'T' || c == 'Q')
738 if (argv[i][3]) option_arg = &argv[i][3];
739 else next_is_arg = 1;
741 break;
742 case 'f':
743 if (strcmp("-framework", argv[i]) == 0)
744 next_is_arg = 1;
745 break;
747 if (next_is_arg) option_arg = argv[i+1];
749 /* determine what options go 'as is' to the linker & the compiler */
750 raw_compiler_arg = raw_linker_arg = 0;
751 if (is_linker_arg(argv[i]))
753 raw_linker_arg = 1;
755 else
757 if (is_directory_arg(argv[i]) || is_target_arg(argv[i]))
758 raw_linker_arg = 1;
759 raw_compiler_arg = !is_mingw_arg(argv[i]);
762 /* these things we handle explicitly so we don't pass them 'as is' */
763 if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L')
764 raw_linker_arg = 0;
765 if (argv[i][1] == 'c' || argv[i][1] == 'L')
766 raw_compiler_arg = 0;
767 if (argv[i][1] == 'o')
768 raw_compiler_arg = raw_linker_arg = 0;
770 /* do a bit of semantic analysis */
771 switch (argv[i][1])
773 case 'B':
774 str = strdup(option_arg);
775 if (strendswith(str, "/tools/winebuild"))
777 opts.wine_mode = 1;
778 /* don't pass it to the compiler, this generates warnings */
779 raw_compiler_arg = raw_linker_arg = 0;
781 if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
782 if (!opts.prefix) opts.prefix = strarray_alloc();
783 strarray_add(opts.prefix, str);
784 break;
785 case 'c': /* compile or assemble */
786 if (argv[i][2] == 0) opts.compile_only = 1;
787 /* fall through */
788 case 'S': /* generate assembler code */
789 case 'E': /* preprocess only */
790 if (argv[i][2] == 0) linking = 0;
791 break;
792 case 'f':
793 if (strcmp("-fno-short-wchar", argv[i]) == 0)
794 opts.noshortwchar = 1;
795 break;
796 case 'l':
797 strarray_add(opts.files, strmake("-l%s", option_arg));
798 break;
799 case 'L':
800 strarray_add(opts.lib_dirs, option_arg);
801 break;
802 case 'M': /* map file generation */
803 linking = 0;
804 break;
805 case 'm':
806 if (strcmp("-mno-cygwin", argv[i]) == 0)
807 opts.use_msvcrt = 1;
808 else if (strcmp("-mwindows", argv[i]) == 0)
809 opts.gui_app = 1;
810 else if (strcmp("-mconsole", argv[i]) == 0)
811 opts.gui_app = 0;
812 break;
813 case 'n':
814 if (strcmp("-nostdinc", argv[i]) == 0)
815 opts.nostdinc = 1;
816 else if (strcmp("-nodefaultlibs", argv[i]) == 0)
817 opts.nodefaultlibs = 1;
818 else if (strcmp("-nostdlib", argv[i]) == 0)
819 opts.nostdlib = 1;
820 break;
821 case 'o':
822 opts.output_name = option_arg;
823 break;
824 case 's':
825 if (strcmp("-static", argv[i]) == 0)
826 linking = -1;
827 else if(strcmp("-save-temps", argv[i]) == 0)
828 keep_generated = 1;
829 else if(strcmp("-shared", argv[i]) == 0)
831 opts.shared = 1;
832 raw_compiler_arg = raw_linker_arg = 0;
834 break;
835 case 'v':
836 if (argv[i][2] == 0) verbose++;
837 break;
838 case 'W':
839 if (strncmp("-Wl,", argv[i], 4) == 0)
841 if (strstr(argv[i], "-static"))
842 linking = -1;
844 else if (strncmp("-Wb,", argv[i], 4) == 0)
846 strarray* Wb = strarray_fromstring(argv[i] + 4, ",");
847 strarray_addall(opts.winebuild_args, Wb);
848 strarray_free(Wb);
849 /* don't pass it to the compiler, it generates errors */
850 raw_compiler_arg = raw_linker_arg = 0;
852 break;
853 case 'x':
854 lang = strmake("-x%s", option_arg);
855 strarray_add(opts.files, lang);
856 /* we'll pass these flags ourselves, explicitely */
857 raw_compiler_arg = raw_linker_arg = 0;
858 break;
859 case '-':
860 if (strcmp("-static", argv[i]+1) == 0)
861 linking = -1;
862 break;
865 /* put the arg into the appropriate bucket */
866 if (raw_linker_arg)
868 strarray_add(opts.linker_args, argv[i]);
869 if (next_is_arg && (i + 1 < argc))
870 strarray_add(opts.linker_args, argv[i + 1]);
872 if (raw_compiler_arg)
874 strarray_add(opts.compiler_args, argv[i]);
875 if (next_is_arg && (i + 1 < argc))
876 strarray_add(opts.compiler_args, argv[i + 1]);
879 /* skip the next token if it's an argument */
880 if (next_is_arg) i++;
882 else
884 strarray_add(opts.files, argv[i]);
888 if (opts.processor == proc_cpp) linking = 0;
889 if (linking == -1) error("Static linking is not supported.");
891 if (opts.files->size == 0) forward(argc, argv, &opts);
892 else if (linking) build(&opts);
893 else compile(&opts, lang);
895 return 0;