Don't tie the script name to the .exe.so name.
[wine/multimedia.git] / tools / winegcc / winegcc.c
blob1c710f7fbc28d453e7cc92a767a55b6dac2d28a5
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_cpp = 1, proc_pp = 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 const char* output_name;
164 strarray* lib_names;
165 strarray* lib_dirs;
166 strarray *linker_args;
167 strarray *compiler_args;
168 strarray* winebuild_args;
169 strarray* files;
172 static void clean_temp_files()
174 int i;
176 if (keep_generated) return;
178 for (i = 0; i < tmp_files->size; i++)
179 unlink(tmp_files->base[i]);
182 char* get_temp_file(const char* prefix, const char* suffix)
184 char *tmp = strmake("%s-XXXXXX%s", prefix, suffix);
185 int fd = mkstemps( tmp, strlen(suffix) );
186 if (fd == -1)
188 /* could not create it in current directory, try in /tmp */
189 free(tmp);
190 tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix);
191 fd = mkstemps( tmp, strlen(suffix) );
192 if (fd == -1) error( "could not create temp file" );
194 close( fd );
195 strarray_add(tmp_files, tmp);
197 return tmp;
200 static const char* get_translator(struct options* opts)
202 switch(opts->processor)
204 case proc_pp: return CPP;
205 case proc_cc: return CC;
206 case proc_cpp: return CXX;
208 error("Unknown processor");
211 static void compile(struct options* opts)
213 strarray *comp_args = strarray_alloc();
214 int j, gcc_defs = 0;
216 switch(opts->processor)
218 case proc_pp: 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_cpp: gcc_defs = 1; break;
224 #else
225 case proc_cc: gcc_defs = 0; break;
226 case proc_cpp: gcc_defs = 0; break;
227 #endif
229 strarray_add(comp_args, get_translator(opts));
231 if (opts->processor != proc_pp)
233 #ifdef CC_FLAG_SHORT_WCHAR
234 if (!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->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 /* last, but not least, the files */
305 for ( j = 0; j < opts->files->size; j++ )
306 strarray_add(comp_args, opts->files->base[j]);
308 spawn(comp_args);
311 static const char* compile_to_object(struct options* opts, const char* file)
313 struct options copts;
314 char* base_name;
316 /* make a copy we so don't change any of the initial stuff */
317 /* a shallow copy is exactly what we want in this case */
318 base_name = get_basename(file);
319 copts = *opts;
320 copts.processor = proc_cc;
321 copts.output_name = get_temp_file(base_name, ".o");
322 copts.compile_only = 1;
323 copts.files = strarray_alloc();
324 strarray_add(copts.files, file);
325 compile(&copts);
326 strarray_free(copts.files);
327 free(base_name);
329 return copts.output_name;
332 static void build(struct options* opts)
334 static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib" };
335 strarray *so_libs, *arh_libs, *dll_libs, *lib_paths, *lib_dirs;
336 strarray *res_files, *obj_files, *spec_args, *comp_args, *link_args;
337 char *spec_c_name, *spec_o_name, *base_file, *base_name;
338 const char* output_name;
339 const char *winebuild = getenv("WINEBUILD");
340 int generate_app_loader = 1;
341 int j;
343 if (!winebuild) winebuild = "winebuild";
345 so_libs = strarray_alloc();
346 arh_libs = strarray_alloc();
347 dll_libs = strarray_alloc();
348 obj_files = strarray_alloc();
349 res_files = strarray_alloc();
350 lib_paths = strarray_alloc();
352 output_name = opts->output_name ? opts->output_name : "a.out";
354 /* get base filename by removing the .exe extension, if present */
355 base_file = strdup(output_name);
356 if (strendswith(base_file, ".exe.so"))
358 base_file[strlen(base_file) - 7] = 0;
359 generate_app_loader = 0;
361 else if (strendswith(base_file, ".exe")) base_file[strlen(base_file) - 4] = 0;
362 if ((base_name = strrchr(base_file, '/'))) base_name++;
363 else base_name = base_file;
365 if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
367 create_file(base_file, 0755, app_loader_template, opts->files->base[0]);
368 return;
371 /* prepare the linking path */
372 lib_dirs = strarray_dup(opts->lib_dirs);
373 for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]);j++ )
374 strarray_add(lib_dirs, stdlibpath[j]);
376 for ( j = 0; j < lib_dirs->size; j++ )
377 strarray_add(lib_paths, strmake("-L%s", lib_dirs->base[j]));
379 /* prepare the libraries */
380 for ( j = 0; j < opts->lib_names->size; j++ )
382 const char* name = opts->lib_names->base[j];
383 char* fullname;
384 switch(get_lib_type(lib_dirs, name, &fullname))
386 case file_arh:
387 strarray_add(arh_libs, strdup(fullname));
388 break;
389 case file_dll:
390 strarray_add(dll_libs, strmake("-l%s", name));
391 break;
392 case file_so:
393 strarray_add(so_libs, strmake("-l%s", name));
394 break;
395 default:
396 fprintf(stderr, "Can't find library '%s', ignoring\n", name);
398 free(fullname);
401 if (!opts->nostdlib)
403 if (opts->use_msvcrt) strarray_add(dll_libs, "-lmsvcrt");
406 if (!opts->nodefaultlibs)
408 if (opts->gui_app)
410 strarray_add(dll_libs, "-lshell32");
411 strarray_add(dll_libs, "-lcomdlg32");
412 strarray_add(dll_libs, "-lgdi32");
414 strarray_add(dll_libs, "-ladvapi32");
415 strarray_add(dll_libs, "-luser32");
416 strarray_add(dll_libs, "-lkernel32");
419 /* sort object file */
420 for ( j = 0; j < opts->files->size; j++ )
422 const char* file = opts->files->base[j];
423 switch(get_file_type(file))
425 case file_rc:
426 /* FIXME: invoke wrc to build it */
427 break;
428 case file_res:
429 strarray_add(res_files, file);
430 break;
431 case file_obj:
432 strarray_add(obj_files, file);
433 break;
434 case file_na:
435 error("File does not exist: %s", file);
436 break;
437 default:
438 file = compile_to_object(opts, file);
439 strarray_add(obj_files, file);
440 break;
444 /* run winebuild to generate the .spec.c file */
445 spec_args = strarray_alloc();
446 spec_c_name = get_temp_file(base_name, ".spec.c");
447 strarray_add(spec_args, winebuild);
448 strarray_add(spec_args, "-o");
449 strarray_add(spec_args, spec_c_name);
450 strarray_add(spec_args, "--exe");
451 strarray_add(spec_args, strmake("%s.exe", base_name));
452 strarray_add(spec_args, opts->gui_app ? "-mgui" : "-mcui");
454 for ( j = 0; j < lib_paths->size; j++ )
455 strarray_add(spec_args, lib_paths->base[j]);
457 for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
458 strarray_add(spec_args, opts->winebuild_args->base[j]);
460 for ( j = 0; j < dll_libs->size; j++ )
461 strarray_add(spec_args, dll_libs->base[j]);
463 for ( j = 0; j < res_files->size; j++ )
464 strarray_add(spec_args, res_files->base[j]);
466 for ( j = 0; j < obj_files->size; j++ )
467 strarray_add(spec_args, obj_files->base[j]);
469 for ( j = 0; j < arh_libs->size; j++)
470 strarray_add(spec_args, arh_libs->base[j]);
472 spawn(spec_args);
474 /* compile the .spec.c file into a .spec.o file */
475 comp_args = strarray_alloc();
476 spec_o_name = get_temp_file(base_name, ".spec.o");
477 strarray_add(comp_args, CC);
478 strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
479 strarray_add(comp_args, "-o");
480 strarray_add(comp_args, spec_o_name);
481 strarray_add(comp_args, "-c");
482 strarray_add(comp_args, spec_c_name);
484 spawn(comp_args);
486 /* link everything together now */
487 link_args = strarray_alloc();
488 strarray_add(link_args, get_translator(opts));
489 strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
491 strarray_add(link_args, "-o");
492 strarray_add(link_args, strmake("%s.exe.so", base_file));
494 for ( j = 0 ; j < opts->linker_args->size ; j++ )
495 strarray_add(link_args, opts->linker_args->base[j]);
497 for ( j = 0; j < lib_paths->size; j++ )
498 strarray_add(link_args, lib_paths->base[j]);
500 strarray_add(link_args, "-lwine");
501 strarray_add(link_args, "-lm");
503 for ( j = 0; j < so_libs->size; j++ )
504 strarray_add(link_args, so_libs->base[j]);
506 for ( j = 0; j < obj_files->size; j++ )
507 strarray_add(link_args, obj_files->base[j]);
509 strarray_add(link_args, spec_o_name);
511 for ( j = 0; j < arh_libs->size; j++ )
512 strarray_add(link_args, arh_libs->base[j]);
514 spawn(link_args);
516 /* create the loader script */
517 if (generate_app_loader)
518 create_file(base_file, 0755, app_loader_template, strmake("%s.exe.so", base_name));
522 static void forward(int argc, char **argv, struct options* opts)
524 strarray *args = strarray_alloc();
525 int j;
527 strarray_add(args, get_translator(opts));
529 for( j = 1; j < argc; j++ )
530 strarray_add(args, argv[j]);
532 spawn(args);
536 * Linker Options
537 * object-file-name -llibrary -nostartfiles -nodefaultlibs
538 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
539 * -symbolic -Wl,option -Xlinker option -u symbol
541 static int is_linker_arg(const char* arg)
543 static const char* link_switches[] =
545 "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
546 "-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic"
548 int j;
550 switch (arg[1])
552 case 'l':
553 case 'u':
554 return 1;
555 case 'W':
556 if (strncmp("-Wl,", arg, 4) == 0) return 1;
557 break;
558 case 'X':
559 if (strcmp("-Xlinker", arg) == 0) return 1;
560 break;
563 for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
564 if (strcmp(link_switches[j], arg) == 0) return 1;
566 return 0;
570 * Target Options
571 * -b machine -V version
573 static int is_target_arg(const char* arg)
575 return arg[1] == 'b' || arg[2] == 'V';
580 * Directory Options
581 * -Bprefix -Idir -I- -Ldir -specs=file
583 static int is_directory_arg(const char* arg)
585 return arg[1] == 'B' || arg[1] == 'L' || arg[1] == 'I' || strncmp("-specs=", arg, 7) == 0;
589 * MinGW Options
590 * -mno-cygwin -mwindows -mconsole -mthreads
592 static int is_mingw_arg(const char* arg)
594 static const char* mingw_switches[] =
596 "-mno-cygwin", "-mwindows", "-mconsole", "-mthreads"
598 int j;
600 for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
601 if (strcmp(mingw_switches[j], arg) == 0) return 1;
603 return 0;
606 int main(int argc, char **argv)
608 int i, c, next_is_arg = 0, linking = 1;
609 int raw_compiler_arg, raw_linker_arg;
610 const char* option_arg;
611 struct options opts;
613 /* setup tmp file removal at exit */
614 tmp_files = strarray_alloc();
615 atexit(clean_temp_files);
617 /* initialize options */
618 memset(&opts, 0, sizeof(opts));
619 opts.lib_names = strarray_alloc();
620 opts.lib_dirs = strarray_alloc();
621 opts.files = strarray_alloc();
622 opts.linker_args = strarray_alloc();
623 opts.compiler_args = strarray_alloc();
624 opts.winebuild_args = strarray_alloc();
626 /* determine the processor type */
627 if (strendswith(argv[0], "winecpp")) opts.processor = proc_pp;
628 else if (strendswith(argv[0], "++")) opts.processor = proc_cpp;
630 /* parse options */
631 for ( i = 1 ; i < argc ; i++ )
633 if (argv[i][0] == '-') /* option */
635 /* determine if tihs switch is followed by a separate argument */
636 next_is_arg = 0;
637 option_arg = 0;
638 switch(argv[i][1])
640 case 'x': case 'o': case 'D': case 'U':
641 case 'I': case 'A': case 'l': case 'u':
642 case 'b': case 'V': case 'G': case 'L':
643 if (argv[i][2]) option_arg = &argv[i][2];
644 else next_is_arg = 1;
645 break;
646 case 'i':
647 next_is_arg = 1;
648 break;
649 case 'a':
650 if (strcmp("-aux-info", argv[i]) == 0)
651 next_is_arg = 1;
652 break;
653 case 'X':
654 if (strcmp("-Xlinker", argv[i]) == 0)
655 next_is_arg = 1;
656 break;
657 case 'M':
658 c = argv[i][2];
659 if (c == 'F' || c == 'T' || c == 'Q')
661 if (argv[i][3]) option_arg = &argv[i][3];
662 else next_is_arg = 1;
664 break;
666 if (next_is_arg) option_arg = argv[i+1];
668 /* determine what options go 'as is' to the linker & the compiler */
669 raw_compiler_arg = raw_linker_arg = 0;
670 if (is_linker_arg(argv[i]))
672 raw_linker_arg = 1;
674 else
676 if (is_directory_arg(argv[i]) || is_target_arg(argv[i]))
677 raw_linker_arg = 1;
678 raw_compiler_arg = !is_mingw_arg(argv[i]);
681 /* these things we handle explicitly so we don't pass them 'as is' */
682 if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L')
683 raw_linker_arg = 0;
684 if (argv[i][1] == 'c' || argv[i][1] == 'L')
685 raw_compiler_arg = 0;
686 if (argv[i][1] == 'o')
687 raw_compiler_arg = raw_linker_arg = 0;
689 /* put the arg into the appropriate bucket */
690 if (raw_linker_arg)
692 strarray_add(opts.linker_args, argv[i]);
693 if (next_is_arg && (i + 1 < argc))
694 strarray_add(opts.linker_args, argv[i + 1]);
696 if (raw_compiler_arg)
698 strarray_add(opts.compiler_args, argv[i]);
699 if (next_is_arg && (i + 1 < argc))
700 strarray_add(opts.compiler_args, argv[i + 1]);
703 /* do a bit of semantic analysis */
704 switch (argv[i][1])
706 case 'c': /* compile or assemble */
707 if (argv[i][2] == 0) opts.compile_only = 1;
708 /* fall through */
709 case 'S': /* generate assembler code */
710 case 'E': /* preprocess only */
711 if (argv[i][2] == 0) linking = 0;
712 break;
713 case 'f':
714 if (strcmp("-fno-short-wchar", argv[i]) == 0)
715 opts.noshortwchar = 1;
716 break;
717 case 'l':
718 strarray_add(opts.lib_names, option_arg);
719 break;
720 case 'L':
721 strarray_add(opts.lib_dirs, option_arg);
722 break;
723 case 'M': /* map file generation */
724 linking = 0;
725 break;
726 case 'm':
727 if (strcmp("-mno-cygwin", argv[i]) == 0)
728 opts.use_msvcrt = 1;
729 else if (strcmp("-mwindows", argv[i]) == 0)
730 opts.gui_app = 1;
731 else if (strcmp("-mconsole", argv[i]) == 0)
732 opts.gui_app = 0;
733 break;
734 case 'n':
735 if (strcmp("-nostdinc", argv[i]) == 0)
736 opts.nostdinc = 1;
737 else if (strcmp("-nodefaultlibs", argv[i]) == 0)
738 opts.nodefaultlibs = 1;
739 else if (strcmp("-nostdlib", argv[i]) == 0)
740 opts.nostdlib = 1;
741 break;
742 case 'o':
743 opts.output_name = option_arg;
744 break;
745 case 's':
746 if (strcmp("-static", argv[i]) == 0)
747 linking = -1;
748 else if(strcmp("-save-temps", argv[i]) == 0)
749 keep_generated = 1;
750 break;
751 case 'v':
752 if (argv[i][2] == 0) verbose++;
753 break;
754 case 'W':
755 if (strncmp("-Wl,", argv[i], 4) == 0)
757 if (strstr(argv[i], "-static"))
758 linking = -1;
760 else if (strncmp("-Wb,", argv[i], 4) == 0)
762 strarray* Wb = strarray_fromstring(argv[i] + 4, ",");
763 strarray_addall(opts.winebuild_args, Wb);
764 strarray_free(Wb);
766 break;
767 case '-':
768 if (strcmp("-static", argv[i]+1) == 0)
769 linking = -1;
770 break;
773 /* skip the next token if it's an argument */
774 if (next_is_arg) i++;
776 else
778 strarray_add(opts.files, argv[i]);
782 if (opts.processor == proc_pp) linking = 0;
783 if (linking == -1) error("Static linking is not supported.");
785 if (opts.files->size == 0) forward(argc, argv, &opts);
786 else if (linking) build(&opts);
787 else compile(&opts);
789 return 0;