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
;
145 enum processor
{ proc_cc
, proc_cxx
, proc_cpp
, proc_as
};
149 enum processor processor
;
161 const char* output_name
;
162 const char* image_base
;
165 strarray
* linker_args
;
166 strarray
* compiler_args
;
167 strarray
* winebuild_args
;
171 static void clean_temp_files(void)
175 if (keep_generated
) return;
177 for (i
= 0; i
< tmp_files
->size
; i
++)
178 unlink(tmp_files
->base
[i
]);
181 /* clean things up when aborting on a signal */
182 static void exit_on_signal( int sig
)
184 exit(1); /* this will call the atexit functions */
187 static char* get_temp_file(const char* prefix
, const char* suffix
)
190 char* tmp
= strmake("%s-XXXXXX%s", prefix
, suffix
);
192 #ifdef HAVE_SIGPROCMASK
194 /* block signals while manipulating the temp files list */
195 sigprocmask( SIG_BLOCK
, &signal_mask
, &old_set
);
197 fd
= mkstemps( tmp
, strlen(suffix
) );
200 /* could not create it in current directory, try in /tmp */
202 tmp
= strmake("/tmp/%s-XXXXXX%s", prefix
, suffix
);
203 fd
= mkstemps( tmp
, strlen(suffix
) );
204 if (fd
== -1) error( "could not create temp file" );
207 strarray_add(tmp_files
, tmp
);
208 #ifdef HAVE_SIGPROCMASK
209 sigprocmask( SIG_SETMASK
, &old_set
, NULL
);
214 static const strarray
* get_translator(enum processor processor
)
216 static strarray
* cpp
= 0;
217 static strarray
* as
= 0;
218 static strarray
* cc
= 0;
219 static strarray
* cxx
= 0;
224 if (!cpp
) cpp
= strarray_fromstring(CPP
, " ");
227 if (!cc
) cc
= strarray_fromstring(CC
, " ");
230 if (!cxx
) cxx
= strarray_fromstring(CXX
, " ");
233 if (!as
) as
= strarray_fromstring(AS
, " ");
236 error("Unknown processor");
239 static void compile(struct options
* opts
, const char* lang
)
241 strarray
* comp_args
= strarray_alloc();
244 switch(opts
->processor
)
246 case proc_cpp
: gcc_defs
= 1; break;
248 /* Note: if the C compiler is gcc we assume the C++ compiler is too */
249 /* mixing different C and C++ compilers isn't supported in configure anyway */
250 case proc_cc
: gcc_defs
= 1; break;
251 case proc_cxx
: gcc_defs
= 1; break;
253 case proc_cc
: gcc_defs
= 0; break;
254 case proc_cxx
: gcc_defs
= 0; break;
256 case proc_as
: gcc_defs
= 0; break;
258 strarray_addall(comp_args
, get_translator(opts
->processor
));
260 if (opts
->processor
!= proc_cpp
)
262 #ifdef CC_FLAG_SHORT_WCHAR
263 if (!opts
->wine_mode
&& !opts
->noshortwchar
)
265 strarray_add(comp_args
, CC_FLAG_SHORT_WCHAR
);
266 strarray_add(comp_args
, "-DWINE_UNICODE_NATIVE");
269 strarray_addall(comp_args
, strarray_fromstring(DLLFLAGS
, " "));
272 strarray_add(comp_args
, "-DWIN32");
273 strarray_add(comp_args
, "-D_WIN32");
274 strarray_add(comp_args
, "-D__WIN32");
275 strarray_add(comp_args
, "-D__WIN32__");
276 strarray_add(comp_args
, "-D__WINNT");
277 strarray_add(comp_args
, "-D__WINNT__");
281 strarray_add(comp_args
, "-D__stdcall=__attribute__((__stdcall__))");
282 strarray_add(comp_args
, "-D__cdecl=__attribute__((__cdecl__))");
283 strarray_add(comp_args
, "-D__fastcall=__attribute__((__fastcall__))");
284 strarray_add(comp_args
, "-D_stdcall=__attribute__((__stdcall__))");
285 strarray_add(comp_args
, "-D_cdecl=__attribute__((__cdecl__))");
286 strarray_add(comp_args
, "-D_fastcall=__attribute__((__fastcall__))");
287 strarray_add(comp_args
, "-D__declspec(x)=__declspec_##x");
288 strarray_add(comp_args
, "-D__declspec_align(x)=__attribute__((aligned(x)))");
289 strarray_add(comp_args
, "-D__declspec_allocate(x)=__attribute__((section(x)))");
290 strarray_add(comp_args
, "-D__declspec_deprecated=__attribute__((deprecated))");
291 strarray_add(comp_args
, "-D__declspec_dllimport=__attribute__((dllimport))");
292 strarray_add(comp_args
, "-D__declspec_dllexport=__attribute__((dllexport))");
293 strarray_add(comp_args
, "-D__declspec_naked=__attribute__((naked))");
294 strarray_add(comp_args
, "-D__declspec_noinline=__attribute__((noinline))");
295 strarray_add(comp_args
, "-D__declspec_noreturn=__attribute__((noreturn))");
296 strarray_add(comp_args
, "-D__declspec_nothrow=__attribute__((nothrow))");
297 strarray_add(comp_args
, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
298 strarray_add(comp_args
, "-D__declspec_selectany=__attribute__((weak))");
299 strarray_add(comp_args
, "-D__declspec_thread=__thread");
302 /* Wine specific defines */
303 strarray_add(comp_args
, "-D__WINE__");
304 strarray_add(comp_args
, "-D__int8=char");
305 strarray_add(comp_args
, "-D__int16=short");
306 /* FIXME: what about 64-bit platforms? */
307 strarray_add(comp_args
, "-D__int32=int");
308 #ifdef HAVE_LONG_LONG
309 strarray_add(comp_args
, "-D__int64=long long");
312 /* options we handle explicitly */
313 if (opts
->compile_only
)
314 strarray_add(comp_args
, "-c");
315 if (opts
->output_name
)
317 strarray_add(comp_args
, "-o");
318 strarray_add(comp_args
, opts
->output_name
);
321 /* the rest of the pass-through parameters */
322 for ( j
= 0 ; j
< opts
->compiler_args
->size
; j
++ )
323 strarray_add(comp_args
, opts
->compiler_args
->base
[j
]);
325 /* the language option, if any */
326 if (lang
&& strcmp(lang
, "-xnone"))
327 strarray_add(comp_args
, lang
);
329 /* last, but not least, the files */
330 for ( j
= 0; j
< opts
->files
->size
; j
++ )
332 if (opts
->files
->base
[j
][0] != '-')
333 strarray_add(comp_args
, opts
->files
->base
[j
]);
336 /* standard includes come last in the include search path */
338 #define SYS_INCLUDE "-isystem"
340 #define SYS_INCLUDE "-I"
342 if (!opts
->wine_mode
&& !opts
->nostdinc
)
344 if (opts
->use_msvcrt
)
346 strarray_add(comp_args
, SYS_INCLUDE INCLUDEDIR
"/msvcrt");
347 strarray_add(comp_args
, "-D__MSVCRT__");
349 strarray_add(comp_args
, SYS_INCLUDE INCLUDEDIR
"/windows");
353 spawn(opts
->prefix
, comp_args
, 0);
356 static const char* compile_to_object(struct options
* opts
, const char* file
, const char* lang
)
358 struct options copts
;
361 /* make a copy so we don't change any of the initial stuff */
362 /* a shallow copy is exactly what we want in this case */
363 base_name
= get_basename(file
);
365 copts
.output_name
= get_temp_file(base_name
, ".o");
366 copts
.compile_only
= 1;
367 copts
.files
= strarray_alloc();
368 strarray_add(copts
.files
, file
);
369 compile(&copts
, lang
);
370 strarray_free(copts
.files
);
373 return copts
.output_name
;
376 /* check if there is a static lib associated to a given dll */
377 static char *find_static_lib( const char *dll
)
379 char *lib
= strmake("%s.a", dll
);
380 if (get_file_type(lib
) == file_arh
) return lib
;
385 /* add specified library to the list of files */
386 static void add_library( strarray
*lib_dirs
, strarray
*files
, const char *library
)
388 char *static_lib
, *fullname
= 0;
390 switch(get_lib_type(lib_dirs
, library
, &fullname
))
393 strarray_add(files
, strmake("-a%s", fullname
));
396 strarray_add(files
, strmake("-d%s", fullname
));
397 if ((static_lib
= find_static_lib(fullname
)))
399 strarray_add(files
, strmake("-a%s",static_lib
));
404 strarray_add(files
, strmake("-s%s", fullname
));
407 /* keep it anyway, the linker may know what to do with it */
408 strarray_add(files
, strmake("-l%s", library
));
414 static void build(struct options
* opts
)
416 static const char *stdlibpath
[] = { DLLDIR
, LIBDIR
, "/usr/lib", "/usr/local/lib", "/lib" };
417 strarray
*lib_dirs
, *files
;
418 strarray
*spec_args
, *link_args
;
420 const char *spec_o_name
;
421 const char *output_name
, *spec_file
, *lang
;
422 const char* winebuild
= getenv("WINEBUILD");
423 int generate_app_loader
= 1;
426 /* NOTE: for the files array we'll use the following convention:
427 * -axxx: xxx is an archive (.a)
428 * -dxxx: xxx is a DLL (.def)
429 * -lxxx: xxx is an unsorted library
430 * -oxxx: xxx is an object (.o)
431 * -rxxx: xxx is a resource (.res)
432 * -sxxx: xxx is a shared lib (.so)
433 * -xlll: lll is the language (c, c++, etc.)
436 if (!winebuild
) winebuild
= "winebuild";
438 output_file
= strdup( opts
->output_name
? opts
->output_name
: "a.out" );
440 /* 'winegcc -o app xxx.exe.so' only creates the load script */
441 if (opts
->files
->size
== 1 && strendswith(opts
->files
->base
[0], ".exe.so"))
443 create_file(output_file
, 0755, app_loader_template
, opts
->files
->base
[0]);
447 /* generate app loader only for .exe */
448 if (opts
->shared
|| strendswith(output_file
, ".exe.so"))
449 generate_app_loader
= 0;
451 /* normalize the filename a bit: strip .so, ensure it has proper ext */
452 if (strendswith(output_file
, ".so"))
453 output_file
[strlen(output_file
) - 3] = 0;
456 if ((output_name
= strrchr(output_file
, '/'))) output_name
++;
457 else output_name
= output_file
;
458 if (!strchr(output_name
, '.'))
459 output_file
= strmake("%s.dll", output_file
);
461 else if (!strendswith(output_file
, ".exe"))
462 output_file
= strmake("%s.exe", output_file
);
464 /* get the filename from the path */
465 if ((output_name
= strrchr(output_file
, '/'))) output_name
++;
466 else output_name
= output_file
;
468 /* prepare the linking path */
469 lib_dirs
= strarray_dup(opts
->lib_dirs
);
470 if (!opts
->wine_mode
)
472 for ( j
= 0; j
< sizeof(stdlibpath
)/sizeof(stdlibpath
[0]); j
++ )
473 strarray_add(lib_dirs
, stdlibpath
[j
]);
476 /* mark the files with their appropriate type */
477 spec_file
= lang
= 0;
478 files
= strarray_alloc();
479 for ( j
= 0; j
< opts
->files
->size
; j
++ )
481 const char* file
= opts
->files
->base
[j
];
484 switch(get_file_type(file
))
489 error("Only one spec file can be specified.");
493 /* FIXME: invoke wrc to build it */
494 error("Can't compile .rc file at the moment: %s", file
);
497 strarray_add(files
, strmake("-r%s", file
));
500 strarray_add(files
, strmake("-o%s", file
));
503 strarray_add(files
, strmake("-a%s", file
));
506 strarray_add(files
, strmake("-s%s", file
));
509 error("File does not exist: %s", file
);
512 file
= compile_to_object(opts
, file
, lang
);
513 strarray_add(files
, strmake("-o%s", file
));
517 else if (file
[1] == 'l')
518 add_library( lib_dirs
, files
, file
+ 2 );
519 else if (file
[1] == 'x')
522 if (opts
->shared
&& !spec_file
)
523 error("A spec file is currently needed in shared mode");
525 /* add the default libraries, if needed */
526 if (!opts
->nostdlib
&& opts
->use_msvcrt
) add_library(lib_dirs
, files
, "msvcrt");
528 if (!opts
->wine_mode
&& !opts
->nodefaultlibs
)
532 add_library(lib_dirs
, files
, "shell32");
533 add_library(lib_dirs
, files
, "comdlg32");
534 add_library(lib_dirs
, files
, "gdi32");
536 add_library(lib_dirs
, files
, "advapi32");
537 add_library(lib_dirs
, files
, "user32");
538 add_library(lib_dirs
, files
, "kernel32");
541 if (!opts
->nostartfiles
) add_library(lib_dirs
, files
, "winecrt0");
542 if (!opts
->nostdlib
) add_library(lib_dirs
, files
, "wine");
544 /* run winebuild to generate the .spec.o file */
545 spec_args
= strarray_alloc();
546 spec_o_name
= get_temp_file(output_name
, ".spec.o");
547 strarray_add(spec_args
, winebuild
);
548 if (verbose
) strarray_add(spec_args
, "-v");
549 if (keep_generated
) strarray_add(spec_args
, "--save-temps");
550 strarray_add(spec_args
, "--as-cmd");
551 strarray_add(spec_args
, AS
);
552 strarray_add(spec_args
, "--ld-cmd");
553 strarray_add(spec_args
, LD
);
554 strarray_addall(spec_args
, strarray_fromstring(DLLFLAGS
, " "));
555 strarray_add(spec_args
, opts
->shared
? "--dll" : "--exe");
556 strarray_add(spec_args
, "-o");
557 strarray_add(spec_args
, spec_o_name
);
560 strarray_add(spec_args
, "-E");
561 strarray_add(spec_args
, spec_file
);
566 strarray_add(spec_args
, "-F");
567 strarray_add(spec_args
, output_name
);
568 strarray_add(spec_args
, "--subsystem");
569 strarray_add(spec_args
, opts
->gui_app
? "windows" : "console");
570 if (opts
->unicode_app
)
572 strarray_add(spec_args
, "--entry");
573 strarray_add(spec_args
, "__wine_spec_exe_wentry");
577 for ( j
= 0; j
< lib_dirs
->size
; j
++ )
578 strarray_add(spec_args
, strmake("-L%s", lib_dirs
->base
[j
]));
580 for ( j
= 0 ; j
< opts
->winebuild_args
->size
; j
++ )
581 strarray_add(spec_args
, opts
->winebuild_args
->base
[j
]);
583 for ( j
= 0; j
< files
->size
; j
++ )
585 const char* name
= files
->base
[j
] + 2;
586 switch(files
->base
[j
][1])
589 strarray_add(spec_args
, files
->base
[j
]);
594 strarray_add(spec_args
, name
);
599 spawn(opts
->prefix
, spec_args
, 0);
601 /* link everything together now */
602 link_args
= strarray_alloc();
603 strarray_addall(link_args
, get_translator(opts
->processor
));
604 strarray_addall(link_args
, strarray_fromstring(LDDLLFLAGS
, " "));
606 strarray_add(link_args
, "-o");
607 strarray_add(link_args
, strmake("%s.so", output_file
));
609 for ( j
= 0 ; j
< opts
->linker_args
->size
; j
++ )
610 strarray_add(link_args
, opts
->linker_args
->base
[j
]);
613 if (opts
->image_base
)
615 strarray_add(link_args
, "-image_base");
616 strarray_add(link_args
, opts
->image_base
);
620 for ( j
= 0; j
< lib_dirs
->size
; j
++ )
621 strarray_add(link_args
, strmake("-L%s", lib_dirs
->base
[j
]));
623 strarray_add(link_args
, spec_o_name
);
625 for ( j
= 0; j
< files
->size
; j
++ )
627 const char* name
= files
->base
[j
] + 2;
628 switch(files
->base
[j
][1])
631 strarray_add(link_args
, strmake("-l%s", name
));
636 strarray_add(link_args
, name
);
643 strarray_add(link_args
, "-lm");
644 strarray_add(link_args
, "-lc");
647 spawn(opts
->prefix
, link_args
, 0);
649 /* set the base address */
650 if (opts
->image_base
)
652 const char *prelink
= PRELINK
;
653 if (prelink
[0] && strcmp(prelink
,"false"))
655 strarray
*prelink_args
= strarray_alloc();
656 strarray_add(prelink_args
, prelink
);
657 strarray_add(prelink_args
, "--reloc-only");
658 strarray_add(prelink_args
, opts
->image_base
);
659 strarray_add(prelink_args
, strmake("%s.so", output_file
));
660 spawn(opts
->prefix
, prelink_args
, 1);
661 strarray_free(prelink_args
);
665 /* create the loader script */
666 if (generate_app_loader
)
668 if (strendswith(output_file
, ".exe")) output_file
[strlen(output_file
) - 4] = 0;
669 create_file(output_file
, 0755, app_loader_template
, strmake("%s.exe.so", output_name
));
674 static void forward(int argc
, char **argv
, struct options
* opts
)
676 strarray
* args
= strarray_alloc();
679 strarray_addall(args
, get_translator(opts
->processor
));
681 for( j
= 1; j
< argc
; j
++ )
682 strarray_add(args
, argv
[j
]);
684 spawn(opts
->prefix
, args
, 0);
689 * object-file-name -llibrary -nostartfiles -nodefaultlibs
690 * -nostdlib -s -static -static-libgcc -shared -shared-libgcc
691 * -symbolic -Wl,option -Xlinker option -u symbol
694 static int is_linker_arg(const char* arg
)
696 static const char* link_switches
[] =
698 "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
699 "-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic",
710 if (strncmp("-Wl,", arg
, 4) == 0) return 1;
713 if (strcmp("-Xlinker", arg
) == 0) return 1;
717 for (j
= 0; j
< sizeof(link_switches
)/sizeof(link_switches
[0]); j
++)
718 if (strcmp(link_switches
[j
], arg
) == 0) return 1;
725 * -b machine -V version
727 static int is_target_arg(const char* arg
)
729 return arg
[1] == 'b' || arg
[2] == 'V';
735 * -Bprefix -Idir -I- -Ldir -specs=file
737 static int is_directory_arg(const char* arg
)
739 return arg
[1] == 'B' || arg
[1] == 'L' || arg
[1] == 'I' || strncmp("-specs=", arg
, 7) == 0;
744 * -mno-cygwin -mwindows -mconsole -mthreads -municode
746 static int is_mingw_arg(const char* arg
)
748 static const char* mingw_switches
[] =
750 "-mno-cygwin", "-mwindows", "-mconsole", "-mthreads", "-municode"
754 for (j
= 0; j
< sizeof(mingw_switches
)/sizeof(mingw_switches
[0]); j
++)
755 if (strcmp(mingw_switches
[j
], arg
) == 0) return 1;
760 int main(int argc
, char **argv
)
762 int i
, c
, next_is_arg
= 0, linking
= 1;
763 int raw_compiler_arg
, raw_linker_arg
;
764 const char* option_arg
;
770 signal( SIGHUP
, exit_on_signal
);
772 signal( SIGTERM
, exit_on_signal
);
773 signal( SIGINT
, exit_on_signal
);
774 #ifdef HAVE_SIGADDSET
775 sigemptyset( &signal_mask
);
776 sigaddset( &signal_mask
, SIGHUP
);
777 sigaddset( &signal_mask
, SIGTERM
);
778 sigaddset( &signal_mask
, SIGINT
);
781 /* setup tmp file removal at exit */
782 tmp_files
= strarray_alloc();
783 atexit(clean_temp_files
);
785 /* initialize options */
786 memset(&opts
, 0, sizeof(opts
));
787 opts
.lib_dirs
= strarray_alloc();
788 opts
.files
= strarray_alloc();
789 opts
.linker_args
= strarray_alloc();
790 opts
.compiler_args
= strarray_alloc();
791 opts
.winebuild_args
= strarray_alloc();
793 /* determine the processor type */
794 if (strendswith(argv
[0], "winecpp")) opts
.processor
= proc_cpp
;
795 else if (strendswith(argv
[0], "++")) opts
.processor
= proc_cxx
;
798 for ( i
= 1 ; i
< argc
; i
++ )
800 if (argv
[i
][0] == '-') /* option */
802 /* determine if tihs switch is followed by a separate argument */
807 case 'x': case 'o': case 'D': case 'U':
808 case 'I': case 'A': case 'l': case 'u':
809 case 'b': case 'V': case 'G': case 'L':
811 if (argv
[i
][2]) option_arg
= &argv
[i
][2];
812 else next_is_arg
= 1;
818 if (strcmp("-aux-info", argv
[i
]) == 0)
822 if (strcmp("-Xlinker", argv
[i
]) == 0)
827 if (c
== 'F' || c
== 'T' || c
== 'Q')
829 if (argv
[i
][3]) option_arg
= &argv
[i
][3];
830 else next_is_arg
= 1;
834 if (strcmp("-framework", argv
[i
]) == 0)
838 if (next_is_arg
) option_arg
= argv
[i
+1];
840 /* determine what options go 'as is' to the linker & the compiler */
841 raw_compiler_arg
= raw_linker_arg
= 0;
842 if (is_linker_arg(argv
[i
]))
848 if (is_directory_arg(argv
[i
]) || is_target_arg(argv
[i
]))
850 raw_compiler_arg
= !is_mingw_arg(argv
[i
]);
853 /* these things we handle explicitly so we don't pass them 'as is' */
854 if (argv
[i
][1] == 'l' || argv
[i
][1] == 'I' || argv
[i
][1] == 'L')
856 if (argv
[i
][1] == 'c' || argv
[i
][1] == 'L')
857 raw_compiler_arg
= 0;
858 if (argv
[i
][1] == 'o')
859 raw_compiler_arg
= raw_linker_arg
= 0;
861 /* do a bit of semantic analysis */
865 str
= strdup(option_arg
);
866 if (strendswith(str
, "/tools/winebuild"))
869 /* don't pass it to the compiler, this generates warnings */
870 raw_compiler_arg
= raw_linker_arg
= 0;
872 if (strendswith(str
, "/")) str
[strlen(str
) - 1] = 0;
873 if (!opts
.prefix
) opts
.prefix
= strarray_alloc();
874 strarray_add(opts
.prefix
, str
);
876 case 'c': /* compile or assemble */
877 if (argv
[i
][2] == 0) opts
.compile_only
= 1;
879 case 'S': /* generate assembler code */
880 case 'E': /* preprocess only */
881 if (argv
[i
][2] == 0) linking
= 0;
884 if (strcmp("-fno-short-wchar", argv
[i
]) == 0)
885 opts
.noshortwchar
= 1;
888 strarray_add(opts
.files
, strmake("-l%s", option_arg
));
891 strarray_add(opts
.lib_dirs
, option_arg
);
893 case 'M': /* map file generation */
897 if (strcmp("-mno-cygwin", argv
[i
]) == 0)
899 else if (strcmp("-mwindows", argv
[i
]) == 0)
901 else if (strcmp("-mconsole", argv
[i
]) == 0)
903 else if (strcmp("-municode", argv
[i
]) == 0)
904 opts
.unicode_app
= 1;
905 else if (strcmp("-m32", argv
[i
]) == 0 || strcmp("-m64", argv
[i
]) == 0)
909 if (strcmp("-nostdinc", argv
[i
]) == 0)
911 else if (strcmp("-nodefaultlibs", argv
[i
]) == 0)
912 opts
.nodefaultlibs
= 1;
913 else if (strcmp("-nostdlib", argv
[i
]) == 0)
915 else if (strcmp("-nostartfiles", argv
[i
]) == 0)
916 opts
.nostartfiles
= 1;
919 opts
.output_name
= option_arg
;
922 if (strcmp("-static", argv
[i
]) == 0)
924 else if(strcmp("-save-temps", argv
[i
]) == 0)
926 else if(strcmp("-shared", argv
[i
]) == 0)
929 raw_compiler_arg
= raw_linker_arg
= 0;
933 if (argv
[i
][2] == 0) verbose
++;
936 if (strncmp("-Wl,", argv
[i
], 4) == 0)
939 strarray
* Wl
= strarray_fromstring(argv
[i
] + 4, ",");
940 for (j
= 0; j
< Wl
->size
; j
++)
942 if (!strcmp(Wl
->base
[j
], "--image-base") && j
< Wl
->size
- 1)
944 opts
.image_base
= strdup( Wl
->base
[++j
] );
947 if (!strcmp(Wl
->base
[j
], "-static")) linking
= -1;
948 strarray_add(opts
.linker_args
, strmake("-Wl,%s",Wl
->base
[j
]));
951 raw_compiler_arg
= raw_linker_arg
= 0;
953 else if (strncmp("-Wb,", argv
[i
], 4) == 0)
955 strarray
* Wb
= strarray_fromstring(argv
[i
] + 4, ",");
956 strarray_addall(opts
.winebuild_args
, Wb
);
958 /* don't pass it to the compiler, it generates errors */
959 raw_compiler_arg
= raw_linker_arg
= 0;
963 lang
= strmake("-x%s", option_arg
);
964 strarray_add(opts
.files
, lang
);
965 /* we'll pass these flags ourselves, explicitely */
966 raw_compiler_arg
= raw_linker_arg
= 0;
969 if (strcmp("-static", argv
[i
]+1) == 0)
974 /* put the arg into the appropriate bucket */
977 strarray_add(opts
.linker_args
, argv
[i
]);
978 if (next_is_arg
&& (i
+ 1 < argc
))
979 strarray_add(opts
.linker_args
, argv
[i
+ 1]);
981 if (raw_compiler_arg
)
983 strarray_add(opts
.compiler_args
, argv
[i
]);
984 if (next_is_arg
&& (i
+ 1 < argc
))
985 strarray_add(opts
.compiler_args
, argv
[i
+ 1]);
988 /* skip the next token if it's an argument */
989 if (next_is_arg
) i
++;
993 strarray_add(opts
.files
, argv
[i
]);
997 if (opts
.processor
== proc_cpp
) linking
= 0;
998 if (linking
== -1) error("Static linking is not supported.");
1000 if (opts
.files
->size
== 0) forward(argc
, argv
, &opts
);
1001 else if (linking
) build(&opts
);
1002 else compile(&opts
, lang
);