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
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:
47 * -iwithprefixbefore dir
59 * -G num (see NOTES below)
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
73 * object-file-name -llibrary -nostartfiles -nodefaultlibs
74 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
75 * -symbolic -Wl,option -Xlinker option -u symbol --image-base
78 * -Bprefix -Idir -I- -Ldir -specs=file
81 * -b machine -V version
83 * Please note that the Target Options are relevant to everything:
84 * compiler, linker, assembler, preprocessor.
89 #include "wine/port.h"
100 static const char* app_loader_template =
104 "# determine the application directory\n"
108 " # $0 contains a path, use it\n"
109 " appdir=`dirname \"$0\"`\n"
112 " # no directory in $0, search in PATH\n"
118 " if [ -x \"$d/$appname\" ]; then appdir=\"$d\"; break; fi\n"
123 "# figure out the full app path\n"
124 "if [ -n \"$appdir\" ]; then\n"
125 " apppath=\"$appdir/$appname\"\n"
126 " WINEDLLPATH=\"$appdir:$WINEDLLPATH\"\n"
127 " export WINEDLLPATH\n"
129 " apppath=\"$appname\"\n"
132 "# determine the WINELOADER\n"
133 "if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
135 "# and try to start the app\n"
136 "exec \"$WINELOADER\" \"$apppath\" \"$@\"\n"
139 static int keep_generated = 0;
140 static strarray* tmp_files;
142 static sigset_t signal_mask;
147 enum { proc_cc = 0, proc_cxx = 1, proc_cpp = 2} processor;
159 const char* output_name;
160 const char* image_base;
163 strarray* linker_args;
164 strarray* compiler_args;
165 strarray* winebuild_args;
169 static void clean_temp_files(void)
173 if (keep_generated) return;
175 for (i = 0; i < tmp_files->size; i++)
176 unlink(tmp_files->base[i]);
179 /* clean things up when aborting on a signal */
180 static void exit_on_signal( int sig )
182 exit(1); /* this will call the atexit functions */
185 static char* get_temp_file(const char* prefix, const char* suffix)
188 char* tmp = strmake("%s-XXXXXX%s", prefix, suffix);
190 #ifdef HAVE_SIGPROCMASK
192 /* block signals while manipulating the temp files list */
193 sigprocmask( SIG_BLOCK, &signal_mask, &old_set );
195 fd = mkstemps( tmp, strlen(suffix) );
198 /* could not create it in current directory, try in /tmp */
200 tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix);
201 fd = mkstemps( tmp, strlen(suffix) );
202 if (fd == -1) error( "could not create temp file" );
205 strarray_add(tmp_files, tmp);
206 #ifdef HAVE_SIGPROCMASK
207 sigprocmask( SIG_SETMASK, &old_set, NULL );
212 static const strarray* get_translator(struct options* opts)
214 static strarray* cpp = 0;
215 static strarray* cc = 0;
216 static strarray* cxx = 0;
218 switch(opts->processor)
221 if (!cpp) cpp = strarray_fromstring(CPP, " ");
224 if (!cc) cc = strarray_fromstring(CC, " ");
227 if (!cxx) cxx = strarray_fromstring(CXX, " ");
230 error("Unknown processor");
233 static void compile(struct options* opts, const char* lang)
235 strarray* comp_args = strarray_alloc();
238 switch(opts->processor)
240 case proc_cpp: gcc_defs = 1; break;
242 /* Note: if the C compiler is gcc we assume the C++ compiler is too */
243 /* mixing different C and C++ compilers isn't supported in configure anyway */
244 case proc_cc: gcc_defs = 1; break;
245 case proc_cxx: gcc_defs = 1; break;
247 case proc_cc: gcc_defs = 0; break;
248 case proc_cxx: gcc_defs = 0; break;
251 strarray_addall(comp_args, get_translator(opts));
253 if (opts->processor != proc_cpp)
255 #ifdef CC_FLAG_SHORT_WCHAR
256 if (!opts->wine_mode && !opts->noshortwchar)
258 strarray_add(comp_args, CC_FLAG_SHORT_WCHAR);
259 strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
262 strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
265 strarray_add(comp_args, "-DWIN32");
266 strarray_add(comp_args, "-D_WIN32");
267 strarray_add(comp_args, "-D__WIN32");
268 strarray_add(comp_args, "-D__WIN32__");
269 strarray_add(comp_args, "-D__WINNT");
270 strarray_add(comp_args, "-D__WINNT__");
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_stdcall=__attribute__((__stdcall__))");
278 strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
279 strarray_add(comp_args, "-D_fastcall=__attribute__((__fastcall__))");
280 strarray_add(comp_args, "-D__declspec(x)=__declspec_##x");
281 strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
282 strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
283 strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
284 strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
285 strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
286 strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))");
287 strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))");
288 strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
289 strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
290 strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
291 strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))");
292 strarray_add(comp_args, "-D__declspec_thread=__thread");
295 /* Wine specific defines */
296 strarray_add(comp_args, "-D__WINE__");
297 strarray_add(comp_args, "-D__int8=char");
298 strarray_add(comp_args, "-D__int16=short");
299 /* FIXME: what about 64-bit platforms? */
300 strarray_add(comp_args, "-D__int32=int");
301 #ifdef HAVE_LONG_LONG
302 strarray_add(comp_args, "-D__int64=long long");
305 /* options we handle explicitly */
306 if (opts->compile_only)
307 strarray_add(comp_args, "-c");
308 if (opts->output_name)
310 strarray_add(comp_args, "-o");
311 strarray_add(comp_args, opts->output_name);
314 /* the rest of the pass-through parameters */
315 for ( j = 0 ; j < opts->compiler_args->size ; j++ )
316 strarray_add(comp_args, opts->compiler_args->base[j]);
318 /* the language option, if any */
319 if (lang && strcmp(lang, "-xnone"))
320 strarray_add(comp_args, lang);
322 /* last, but not least, the files */
323 for ( j = 0; j < opts->files->size; j++ )
325 if (opts->files->base[j][0] != '-')
326 strarray_add(comp_args, opts->files->base[j]);
329 /* standard includes come last in the include search path */
331 #define SYS_INCLUDE "-isystem"
333 #define SYS_INCLUDE "-I"
335 if (!opts->wine_mode && !opts->nostdinc)
337 if (opts->use_msvcrt)
339 strarray_add(comp_args, SYS_INCLUDE INCLUDEDIR "/msvcrt");
340 strarray_add(comp_args, "-D__MSVCRT__");
342 strarray_add(comp_args, SYS_INCLUDE INCLUDEDIR "/windows");
346 spawn(opts->prefix, comp_args, 0);
349 static const char* compile_to_object(struct options* opts, const char* file, const char* lang)
351 struct options copts;
354 /* make a copy so we don't change any of the initial stuff */
355 /* a shallow copy is exactly what we want in this case */
356 base_name = get_basename(file);
358 copts.output_name = get_temp_file(base_name, ".o");
359 copts.compile_only = 1;
360 copts.files = strarray_alloc();
361 strarray_add(copts.files, file);
362 compile(&copts, lang);
363 strarray_free(copts.files);
366 return copts.output_name;
369 /* check if there is a static lib associated to a given dll */
370 static char *find_static_lib( const char *dll )
372 char *lib = strmake("%s.a", dll);
373 if (get_file_type(lib) == file_arh) return lib;
378 static void build(struct options* opts)
380 static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
381 strarray *lib_dirs, *files;
382 strarray *spec_args, *link_args;
384 const char *spec_c_name, *spec_o_name;
385 const char *output_name, *spec_file, *lang;
386 const char* winebuild = getenv("WINEBUILD");
387 int generate_app_loader = 1;
391 /* NOTE: for the files array we'll use the following convention:
392 * -axxx: xxx is an archive (.a)
393 * -dxxx: xxx is a DLL (.def)
394 * -lxxx: xxx is an unsorted library
395 * -oxxx: xxx is an object (.o)
396 * -rxxx: xxx is a resource (.res)
397 * -sxxx: xxx is a shared lib (.so)
398 * -xlll: lll is the language (c, c++, etc.)
401 if (!winebuild) winebuild = "winebuild";
403 output_file = strdup( opts->output_name ? opts->output_name : "a.out" );
405 /* 'winegcc -o app xxx.exe.so' only creates the load script */
406 if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
408 create_file(output_file, 0755, app_loader_template, opts->files->base[0]);
412 /* generate app loader only for .exe */
413 if (opts->shared || strendswith(output_file, ".exe.so"))
414 generate_app_loader = 0;
416 /* normalize the filename a bit: strip .so, ensure it has proper ext */
417 if (strendswith(output_file, ".so"))
418 output_file[strlen(output_file) - 3] = 0;
421 if ((output_name = strrchr(output_file, '/'))) output_name++;
422 else output_name = output_file;
423 if (!strchr(output_name, '.'))
424 output_file = strmake("%s.dll", output_file);
426 else if (!strendswith(output_file, ".exe"))
427 output_file = strmake("%s.exe", output_file);
429 /* get the filename from the path */
430 if ((output_name = strrchr(output_file, '/'))) output_name++;
431 else output_name = output_file;
433 /* prepare the linking path */
434 lib_dirs = strarray_dup(opts->lib_dirs);
435 if (!opts->wine_mode)
437 for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]); j++ )
438 strarray_add(lib_dirs, stdlibpath[j]);
441 /* mark the files with their appropriate type */
442 spec_file = lang = 0;
443 files = strarray_alloc();
444 for ( j = 0; j < opts->files->size; j++ )
446 const char* file = opts->files->base[j];
449 switch(get_file_type(file))
454 error("Only one spec file can be specified.");
458 /* FIXME: invoke wrc to build it */
459 error("Can't compile .rc file at the moment: %s", file);
462 strarray_add(files, strmake("-r%s", file));
465 strarray_add(files, strmake("-o%s", file));
468 strarray_add(files, strmake("-a%s", file));
471 strarray_add(files, strmake("-s%s", file));
474 error("File does not exist: %s", file);
477 file = compile_to_object(opts, file, lang);
478 strarray_add(files, strmake("-o%s", file));
482 else if (file[1] == 'l')
484 char *static_lib, *fullname = 0;
485 switch(get_lib_type(lib_dirs, file + 2, &fullname))
488 strarray_add(files, strmake("-a%s", fullname));
491 strarray_add(files, strmake("-d%s", file + 2));
492 if ((static_lib = find_static_lib(fullname)))
494 strarray_add(files, strmake("-a%s",static_lib));
499 strarray_add(files, strmake("-s%s", file + 2));
502 /* keep it anyway, the linker may know what to do with it */
503 strarray_add(files, file);
508 else if (file[1] == 'x')
511 if (opts->shared && !spec_file)
512 error("A spec file is currently needed in shared mode");
514 /* add the default libraries, if needed */
517 if (opts->use_msvcrt) strarray_add(files, "-dmsvcrt");
520 if (!opts->wine_mode && !opts->nodefaultlibs)
524 strarray_add(files, "-dshell32");
525 strarray_add(files, "-dcomdlg32");
526 strarray_add(files, "-dgdi32");
528 strarray_add(files, "-dadvapi32");
529 strarray_add(files, "-duser32");
530 strarray_add(files, "-dkernel32");
533 if (!opts->nostartfiles)
535 char *fullname = NULL;
536 if (get_lib_type(lib_dirs, "winecrt0", &fullname) == file_arh)
537 strarray_add(files, strmake("-a%s", fullname));
541 /* run winebuild to generate the .spec.c file */
542 spec_args = strarray_alloc();
543 spec_c_name = get_temp_file(output_name, ".spec.c");
544 strarray_add(spec_args, winebuild);
545 strarray_add(spec_args, "--ld-cmd");
546 strarray_add(spec_args, LD);
547 strarray_addall(spec_args, strarray_fromstring(DLLFLAGS, " "));
548 strarray_add(spec_args, opts->shared ? "--dll" : "--exe");
549 strarray_add(spec_args, "-o");
550 strarray_add(spec_args, spec_c_name);
553 strarray_add(spec_args, "-E");
554 strarray_add(spec_args, spec_file);
559 strarray_add(spec_args, "-F");
560 strarray_add(spec_args, output_name);
561 strarray_add(spec_args, "--subsystem");
562 strarray_add(spec_args, opts->gui_app ? "windows" : "console");
563 if (opts->unicode_app)
565 strarray_add(spec_args, "--entry");
566 strarray_add(spec_args, "__wine_spec_exe_wentry");
570 for ( j = 0; j < lib_dirs->size; j++ )
571 strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
573 for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
574 strarray_add(spec_args, opts->winebuild_args->base[j]);
576 for ( j = 0; j < files->size; j++ )
578 const char* name = files->base[j] + 2;
579 switch(files->base[j][1])
582 strarray_add(spec_args, strmake("-l%s", name));
585 strarray_add(spec_args, files->base[j]);
589 strarray_add(spec_args, name);
594 spawn(opts->prefix, spec_args, 0);
596 /* compile the .spec.c file into a .spec.o file */
597 old_processor = opts->processor;
598 /* Always compile spec.c as c, even if linking with g++ */
599 opts->processor = proc_cc;
600 spec_o_name = compile_to_object(opts, spec_c_name, 0);
601 opts->processor = old_processor;
603 /* link everything together now */
604 link_args = strarray_alloc();
605 strarray_addall(link_args, get_translator(opts));
606 strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
608 strarray_add(link_args, "-o");
609 strarray_add(link_args, strmake("%s.so", output_file));
611 for ( j = 0 ; j < opts->linker_args->size ; j++ )
612 strarray_add(link_args, opts->linker_args->base[j]);
614 for ( j = 0; j < lib_dirs->size; j++ )
615 strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));
617 strarray_add(link_args, spec_o_name);
619 for ( j = 0; j < files->size; j++ )
621 const char* name = files->base[j] + 2;
622 switch(files->base[j][1])
626 strarray_add(link_args, strmake("-l%s", name));
630 strarray_add(link_args, name);
637 strarray_add(link_args, "-lwine");
638 strarray_add(link_args, "-lm");
639 strarray_add(link_args, "-lc");
642 spawn(opts->prefix, link_args, 0);
644 /* set the base address */
645 if (opts->image_base)
647 const char *prelink = PRELINK;
648 if (prelink[0] && strcmp(prelink,"false"))
650 strarray *prelink_args = strarray_alloc();
651 strarray_add(prelink_args, prelink);
652 strarray_add(prelink_args, "--reloc-only");
653 strarray_add(prelink_args, opts->image_base);
654 strarray_add(prelink_args, strmake("%s.so", output_file));
655 spawn(opts->prefix, prelink_args, 1);
656 strarray_free(prelink_args);
660 /* create the loader script */
661 if (generate_app_loader)
663 if (strendswith(output_file, ".exe")) output_file[strlen(output_file) - 4] = 0;
664 create_file(output_file, 0755, app_loader_template, strmake("%s.exe.so", output_name));
669 static void forward(int argc, char **argv, struct options* opts)
671 strarray* args = strarray_alloc();
674 strarray_addall(args, get_translator(opts));
676 for( j = 1; j < argc; j++ )
677 strarray_add(args, argv[j]);
679 spawn(opts->prefix, args, 0);
684 * object-file-name -llibrary -nostartfiles -nodefaultlibs
685 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
686 * -symbolic -Wl,option -Xlinker option -u symbol
689 static int is_linker_arg(const char* arg)
691 static const char* link_switches[] =
693 "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
694 "-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic",
705 if (strncmp("-Wl,", arg, 4) == 0) return 1;
708 if (strcmp("-Xlinker", arg) == 0) return 1;
712 for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
713 if (strcmp(link_switches[j], arg) == 0) return 1;
720 * -b machine -V version
722 static int is_target_arg(const char* arg)
724 return arg[1] == 'b' || arg[2] == 'V';
730 * -Bprefix -Idir -I- -Ldir -specs=file
732 static int is_directory_arg(const char* arg)
734 return arg[1] == 'B' || arg[1] == 'L' || arg[1] == 'I' || strncmp("-specs=", arg, 7) == 0;
739 * -mno-cygwin -mwindows -mconsole -mthreads -municode
741 static int is_mingw_arg(const char* arg)
743 static const char* mingw_switches[] =
745 "-mno-cygwin", "-mwindows", "-mconsole", "-mthreads", "-municode"
749 for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
750 if (strcmp(mingw_switches[j], arg) == 0) return 1;
755 int main(int argc, char **argv)
757 int i, c, next_is_arg = 0, linking = 1;
758 int raw_compiler_arg, raw_linker_arg;
759 const char* option_arg;
765 signal( SIGHUP, exit_on_signal );
767 signal( SIGTERM, exit_on_signal );
768 signal( SIGINT, exit_on_signal );
769 #ifdef HAVE_SIGADDSET
770 sigemptyset( &signal_mask );
771 sigaddset( &signal_mask, SIGHUP );
772 sigaddset( &signal_mask, SIGTERM );
773 sigaddset( &signal_mask, SIGINT );
776 /* setup tmp file removal at exit */
777 tmp_files = strarray_alloc();
778 atexit(clean_temp_files);
780 /* initialize options */
781 memset(&opts, 0, sizeof(opts));
782 opts.lib_dirs = strarray_alloc();
783 opts.files = strarray_alloc();
784 opts.linker_args = strarray_alloc();
785 opts.compiler_args = strarray_alloc();
786 opts.winebuild_args = strarray_alloc();
788 /* determine the processor type */
789 if (strendswith(argv[0], "winecpp")) opts.processor = proc_cpp;
790 else if (strendswith(argv[0], "++")) opts.processor = proc_cxx;
793 for ( i = 1 ; i < argc ; i++ )
795 if (argv[i][0] == '-') /* option */
797 /* determine if tihs switch is followed by a separate argument */
802 case 'x': case 'o': case 'D': case 'U':
803 case 'I': case 'A': case 'l': case 'u':
804 case 'b': case 'V': case 'G': case 'L':
806 if (argv[i][2]) option_arg = &argv[i][2];
807 else next_is_arg = 1;
813 if (strcmp("-aux-info", argv[i]) == 0)
817 if (strcmp("-Xlinker", argv[i]) == 0)
822 if (c == 'F' || c == 'T' || c == 'Q')
824 if (argv[i][3]) option_arg = &argv[i][3];
825 else next_is_arg = 1;
829 if (strcmp("-framework", argv[i]) == 0)
833 if (next_is_arg) option_arg = argv[i+1];
835 /* determine what options go 'as is' to the linker & the compiler */
836 raw_compiler_arg = raw_linker_arg = 0;
837 if (is_linker_arg(argv[i]))
843 if (is_directory_arg(argv[i]) || is_target_arg(argv[i]))
845 raw_compiler_arg = !is_mingw_arg(argv[i]);
848 /* these things we handle explicitly so we don't pass them 'as is' */
849 if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L')
851 if (argv[i][1] == 'c' || argv[i][1] == 'L')
852 raw_compiler_arg = 0;
853 if (argv[i][1] == 'o')
854 raw_compiler_arg = raw_linker_arg = 0;
856 /* do a bit of semantic analysis */
860 str = strdup(option_arg);
861 if (strendswith(str, "/tools/winebuild"))
864 /* don't pass it to the compiler, this generates warnings */
865 raw_compiler_arg = raw_linker_arg = 0;
867 if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
868 if (!opts.prefix) opts.prefix = strarray_alloc();
869 strarray_add(opts.prefix, str);
871 case 'c': /* compile or assemble */
872 if (argv[i][2] == 0) opts.compile_only = 1;
874 case 'S': /* generate assembler code */
875 case 'E': /* preprocess only */
876 if (argv[i][2] == 0) linking = 0;
879 if (strcmp("-fno-short-wchar", argv[i]) == 0)
880 opts.noshortwchar = 1;
883 strarray_add(opts.files, strmake("-l%s", option_arg));
886 strarray_add(opts.lib_dirs, option_arg);
888 case 'M': /* map file generation */
892 if (strcmp("-mno-cygwin", argv[i]) == 0)
894 else if (strcmp("-mwindows", argv[i]) == 0)
896 else if (strcmp("-mconsole", argv[i]) == 0)
898 else if (strcmp("-municode", argv[i]) == 0)
899 opts.unicode_app = 1;
902 if (strcmp("-nostdinc", argv[i]) == 0)
904 else if (strcmp("-nodefaultlibs", argv[i]) == 0)
905 opts.nodefaultlibs = 1;
906 else if (strcmp("-nostdlib", argv[i]) == 0)
908 else if (strcmp("-nostartfiles", argv[i]) == 0)
909 opts.nostartfiles = 1;
912 opts.output_name = option_arg;
915 if (strcmp("-static", argv[i]) == 0)
917 else if(strcmp("-save-temps", argv[i]) == 0)
919 else if(strcmp("-shared", argv[i]) == 0)
922 raw_compiler_arg = raw_linker_arg = 0;
926 if (argv[i][2] == 0) verbose++;
929 if (strncmp("-Wl,", argv[i], 4) == 0)
932 strarray* Wl = strarray_fromstring(argv[i] + 4, ",");
933 for (j = 0; j < Wl->size; j++)
935 if (!strcmp(Wl->base[j], "--image-base") && j < Wl->size - 1)
937 opts.image_base = strdup( Wl->base[++j] );
940 if (!strcmp(Wl->base[j], "-static")) linking = -1;
941 strarray_add(opts.linker_args, strmake("-Wl,%s",Wl->base[j]));
944 raw_compiler_arg = raw_linker_arg = 0;
946 else if (strncmp("-Wb,", argv[i], 4) == 0)
948 strarray* Wb = strarray_fromstring(argv[i] + 4, ",");
949 strarray_addall(opts.winebuild_args, Wb);
951 /* don't pass it to the compiler, it generates errors */
952 raw_compiler_arg = raw_linker_arg = 0;
956 lang = strmake("-x%s", option_arg);
957 strarray_add(opts.files, lang);
958 /* we'll pass these flags ourselves, explicitely */
959 raw_compiler_arg = raw_linker_arg = 0;
962 if (strcmp("-static", argv[i]+1) == 0)
967 /* put the arg into the appropriate bucket */
970 strarray_add(opts.linker_args, argv[i]);
971 if (next_is_arg && (i + 1 < argc))
972 strarray_add(opts.linker_args, argv[i + 1]);
974 if (raw_compiler_arg)
976 strarray_add(opts.compiler_args, argv[i]);
977 if (next_is_arg && (i + 1 < argc))
978 strarray_add(opts.compiler_args, argv[i + 1]);
981 /* skip the next token if it's an argument */
982 if (next_is_arg) i++;
986 strarray_add(opts.files, argv[i]);
990 if (opts.processor == proc_cpp) linking = 0;
991 if (linking == -1) error("Static linking is not supported.");
993 if (opts.files->size == 0) forward(argc, argv, &opts);
994 else if (linking) build(&opts);
995 else compile(&opts, lang);