Compile with WINE_UNICODE_NATIVE defined, essential for C++.
[wine.git] / tools / winegcc.c
blob72370faf94cb5201ee498b27eadc740cad19a299
1 /*
2 * MinGW wrapper: makes gcc behave like MinGW.
4 * Copyright 2000 Manuel Novoa III
5 * Copyright 2002 Dimitrie O. Paun
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28 #include <string.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
33 #ifndef GCC_BIN
34 #define GCC_BIN "gcc"
35 #endif
37 #ifndef INCLUDEDIR
38 #define INCLUDEDIR "/usr/local/include/wine"
39 #endif
41 void error(const char *s, ...)
43 va_list ap;
45 va_start(ap, s);
46 fprintf(stderr, "Error: ");
47 vfprintf(stderr, s, ap);
48 fprintf(stderr, "\n");
49 va_end(ap);
50 exit(2);
53 int main(int argc, char **argv)
55 char **gcc_argv;
56 int i, j;
57 int linking = 1, verbose = 0, use_static_linking = 0;
58 int use_stdinc = 1, use_stdlib = 1, use_msvcrt = 0, gui_app = 0;
60 for ( i = 1 ; i < argc ; i++ )
62 if (argv[i][0] == '-') /* option */
64 switch (argv[i][1])
66 case 'c': /* compile or assemble */
67 case 'S': /* generate assembler code */
68 case 'E': /* preprocess only */
69 case 'M': /* map file generation */
70 if (argv[i][2] == 0) linking = 0;
71 break;
72 case 'v': /* verbose */
73 if (argv[i][2] == 0) verbose = 1;
74 break;
75 case 'V':
76 printf("winegcc v0.3\n");
77 exit(0);
78 break;
79 case 'm':
80 if (strcmp("-mno-cygwin", argv[i]) == 0)
81 use_msvcrt = 1;
82 else if (strcmp("-mwindows", argv[i]) == 0)
83 gui_app = 1;
84 break;
85 case 'n':
86 if (strcmp("-nostdinc", argv[i]) == 0)
87 use_stdinc = 0;
88 else if (strcmp("-nodefaultlibs", argv[i]) == 0)
89 use_stdlib = 0;
90 else if (strcmp("-nostdlib", argv[i]) == 0)
91 use_stdlib = 0;
92 break;
93 case 's':
94 if (strcmp("-static", argv[i]) == 0) use_static_linking = 1;
95 break;
96 case 'W':
97 if (strncmp("-Wl,", argv[i], 4) == 0)
99 if (strstr(argv[i], "-static"))
100 use_static_linking = 1;
102 break;
103 case '-':
104 if (strcmp("-static", argv[i]+1) == 0)
105 use_static_linking = 1;
106 break;
111 if (use_static_linking) error("Static linking is not supported.");
113 gcc_argv = malloc(sizeof(char*) * (argc + 20));
115 i = 0;
116 if (linking)
118 gcc_argv[i++] = BINDIR "/winewrap";
119 if (gui_app) gcc_argv[i++] = "-mgui";
121 else
123 gcc_argv[i++] = GCC_BIN;
125 gcc_argv[i++] = "-fshort-wchar";
126 gcc_argv[i++] = "-fPIC";
127 if (use_stdinc)
129 if (use_msvcrt) gcc_argv[i++] = "-I" INCLUDEDIR "/msvcrt";
130 gcc_argv[i++] = "-I" INCLUDEDIR "/windows";
132 gcc_argv[i++] = "-DWINE_UNICODE_NATIVE";
133 gcc_argv[i++] = "-D__int8=char";
134 gcc_argv[i++] = "-D__int16=short";
135 gcc_argv[i++] = "-D__int32=int";
136 gcc_argv[i++] = "-D__int64=long long";
139 for ( j = 1 ; j < argc ; j++ )
141 if (strcmp("-mno-cygwin", argv[j]) == 0)
142 ; /* ignore this option */
143 else if (strcmp("-mwindows", argv[j]) == 0)
144 ; /* ignore this option */
145 else if (strcmp("-s", argv[j]) == 0)
146 ; /* ignore this option */
147 else
148 gcc_argv[i++] = argv[j];
151 if (linking)
153 if (use_stdlib && use_msvcrt) gcc_argv[i++] = "-lmsvcrt";
155 gcc_argv[i] = NULL;
157 if (verbose)
159 for (i = 0; gcc_argv[i]; i++) printf("%s ", gcc_argv[i]);
160 printf("\n");
163 execvp(gcc_argv[0], gcc_argv);
165 return 1;