Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winegcc/winegcc.c
4394 views
1
/*
2
* MinGW wrapper: makes gcc behave like MinGW.
3
*
4
* Copyright 2000 Manuel Novoa III
5
* Copyright 2000 Francois Gouget
6
* Copyright 2002 Dimitrie O. Paun
7
*
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.
12
*
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.
17
*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21
*
22
* DESCRIPTION
23
*
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:
29
*
30
* Compiler:
31
* -x language
32
* -o filename
33
* -aux-info filename
34
*
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
50
*
51
* Linking:
52
* -l library
53
* -Xlinker option
54
* -u symbol
55
*
56
* Misc:
57
* -b machine
58
* -V version
59
* -G num (see NOTES below)
60
*
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.
66
*
67
* Special interest options
68
*
69
* Assembler Option
70
* -Wa,option
71
*
72
* Linker Options
73
* object-file-name -llibrary -nostartfiles -nodefaultlibs
74
* -nostdlib -s -static -static-libgcc -static-libstdc++
75
* -shared -shared-libgcc -symbolic -Wl,option
76
* -Xlinker option -u symbol --image-base -fuse-ld
77
*
78
* Directory Options
79
* -Bprefix -Idir -I- -Ldir -specs=file
80
*
81
* Target Options
82
* -b machine -V version
83
*
84
* Please note that the Target Options are relevant to everything:
85
* compiler, linker, assembler, preprocessor.
86
*
87
*/
88
89
#include "config.h"
90
91
#include <assert.h>
92
#include <stdio.h>
93
#include <stdlib.h>
94
#include <stdarg.h>
95
#include <stdbool.h>
96
#include <string.h>
97
#include <errno.h>
98
#include <ctype.h>
99
#include <limits.h>
100
#include <sys/types.h>
101
#include "../tools.h"
102
103
static const char* app_loader_template =
104
"#!/bin/sh\n"
105
"\n"
106
"appname=\"%s\"\n"
107
"# determine the application directory\n"
108
"appdir=''\n"
109
"case \"$0\" in\n"
110
" */*)\n"
111
" # $0 contains a path, use it\n"
112
" appdir=`dirname \"$0\"`\n"
113
" ;;\n"
114
" *)\n"
115
" # no directory in $0, search in PATH\n"
116
" saved_ifs=$IFS\n"
117
" IFS=:\n"
118
" for d in $PATH\n"
119
" do\n"
120
" IFS=$saved_ifs\n"
121
" if [ -x \"$d/$appname\" ]; then appdir=\"$d\"; break; fi\n"
122
" done\n"
123
" ;;\n"
124
"esac\n"
125
"\n"
126
"# figure out the full app path\n"
127
"if [ -n \"$appdir\" ]; then\n"
128
" apppath=\"$appdir/$appname\"\n"
129
" WINEDLLPATH=\"$appdir:$WINEDLLPATH\"\n"
130
" export WINEDLLPATH\n"
131
"else\n"
132
" apppath=\"$appname\"\n"
133
"fi\n"
134
"\n"
135
"# determine the WINELOADER\n"
136
"if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
137
"\n"
138
"# and try to start the app\n"
139
"exec \"$WINELOADER\" \"$apppath\" \"$@\"\n"
140
;
141
142
static const char *output_file_name;
143
static struct strarray output_debug_files;
144
static const char *output_implib;
145
static const char *output;
146
static int keep_generated = 0;
147
static int verbose;
148
const char *temp_dir = NULL;
149
struct strarray temp_files = { 0 };
150
151
static const char *bindir;
152
static const char *libdir;
153
static const char *includedir;
154
static const char *wine_objdir;
155
static const char *winebuild;
156
static const char *lib_suffix;
157
static const char *sysroot;
158
static const char *isysroot;
159
static const char *target_alias;
160
static const char *target_version;
161
static struct target target;
162
static struct strarray prefix_dirs;
163
static struct strarray path_dirs;
164
static struct strarray lib_path_dirs;
165
166
static enum processor { proc_cc, proc_cxx, proc_cpp } processor = proc_cc;
167
168
enum file_type { file_na, file_other, file_obj, file_res, file_rc, file_arh, file_dll, file_so, file_spec };
169
170
static bool is_pe;
171
static bool is_static;
172
static bool is_shared;
173
static bool is_gui_app;
174
static bool is_unicode_app;
175
static bool is_win16_app;
176
static bool is_arm64x;
177
static bool use_msvcrt;
178
static bool use_pic = true;
179
static bool use_build_id;
180
static bool nostdinc;
181
static bool nostdlib;
182
static bool nostartfiles;
183
static bool nodefaultlibs;
184
static bool noshortwchar;
185
static bool data_only;
186
static bool fake_module;
187
static bool large_address_aware;
188
static bool wine_builtin;
189
static bool unwind_tables;
190
static bool strip;
191
static bool compile_only;
192
static bool skip_link;
193
static bool no_default_config;
194
static int force_pointer_size;
195
196
static const char *image_base;
197
static const char *section_align;
198
static const char *file_align;
199
static const char *subsystem;
200
static const char *entry_point;
201
static struct strarray file_args;
202
static struct strarray linker_args;
203
static struct strarray compiler_args;
204
static struct strarray winebuild_args;
205
static struct strarray delayimports;
206
207
208
static void cleanup_output_files(void)
209
{
210
unsigned int i;
211
if (output_file_name) unlink( output_file_name );
212
if (output_implib) unlink( output_implib );
213
for (i = 0; i < output_debug_files.count; i++)
214
unlink( output_debug_files.str[i] );
215
}
216
217
static void clean_temp_files(void)
218
{
219
if (!keep_generated) remove_temp_files();
220
}
221
222
/* clean things up when aborting on a signal */
223
static void exit_on_signal( int sig )
224
{
225
exit(1); /* this will call the atexit functions */
226
}
227
228
static void error(const char* s, ...)
229
{
230
va_list ap;
231
232
va_start(ap, s);
233
fprintf(stderr, "winegcc: ");
234
vfprintf(stderr, s, ap);
235
va_end(ap);
236
exit(2);
237
}
238
239
static void create_file(const char* name, int mode, const char* fmt, ...)
240
{
241
va_list ap;
242
FILE *file;
243
244
if (verbose) printf("Creating file %s\n", name);
245
va_start(ap, fmt);
246
if ( !(file = fopen(name, "w")) )
247
error("Unable to open %s for writing\n", name);
248
vfprintf(file, fmt, ap);
249
va_end(ap);
250
fclose(file);
251
chmod(name, mode);
252
}
253
254
static enum file_type get_file_type(const char* filename)
255
{
256
/* see tools/winebuild/res32.c: check_header for details */
257
static const char res_sig[] = { 0,0,0,0, 32,0,0,0, 0xff,0xff, 0,0, 0xff,0xff, 0,0, 0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0,0,0 };
258
static const char elf_sig[4] = "\177ELF";
259
static const char ar_sig[8] = "!<arch>\n";
260
char buf[sizeof(res_sig)];
261
int fd, cnt;
262
263
fd = open( filename, O_RDONLY );
264
if (fd == -1) return file_na;
265
cnt = read(fd, buf, sizeof(buf));
266
close( fd );
267
if (cnt == -1) return file_na;
268
269
if (cnt == sizeof(res_sig) && !memcmp(buf, res_sig, sizeof(res_sig))) return file_res;
270
if (strendswith(filename, ".o")) return file_obj;
271
if (strendswith(filename, ".obj")) return file_obj;
272
if (strendswith(filename, ".a")) return file_arh;
273
if (strendswith(filename, ".res")) return file_res;
274
if (strendswith(filename, ".so")) return file_so;
275
if (strendswith(filename, ".dylib")) return file_so;
276
if (strendswith(filename, ".def")) return file_spec;
277
if (strendswith(filename, ".spec")) return file_spec;
278
if (strendswith(filename, ".rc")) return file_rc;
279
if (cnt >= sizeof(elf_sig) && !memcmp(buf, elf_sig, sizeof(elf_sig))) return file_so; /* ELF lib */
280
if (cnt >= sizeof(ar_sig) && !memcmp(buf, ar_sig, sizeof(ar_sig))) return file_arh;
281
if (cnt >= sizeof(unsigned int) &&
282
(*(unsigned int *)buf == 0xfeedface || *(unsigned int *)buf == 0xcefaedfe ||
283
*(unsigned int *)buf == 0xfeedfacf || *(unsigned int *)buf == 0xcffaedfe))
284
return file_so; /* Mach-O lib */
285
286
return file_other;
287
}
288
289
static char* try_lib_path(const char *dir, const char *arch_dir, const char* library,
290
const char* ext, enum file_type expected_type)
291
{
292
char *fullname;
293
enum file_type type;
294
295
/* first try a subdir named from the library we are looking for */
296
fullname = strmake("%s/%s%s/lib%s%s", dir, library, arch_dir, library, ext);
297
if (verbose > 1) fprintf(stderr, "Try %s...", fullname);
298
type = get_file_type(fullname);
299
if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n");
300
if (type == expected_type) return fullname;
301
free( fullname );
302
303
fullname = strmake("%s/lib%s%s", dir, library, ext);
304
if (verbose > 1) fprintf(stderr, "Try %s...", fullname);
305
type = get_file_type(fullname);
306
if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n");
307
if (type == expected_type) return fullname;
308
free( fullname );
309
return 0;
310
}
311
312
static enum file_type guess_lib_type(const char* dir, const char* library, char** file)
313
{
314
const char *arch_dir = "";
315
const char *suffix = lib_suffix ? lib_suffix : ".a";
316
317
if (!is_pe)
318
{
319
/* Unix shared object */
320
if ((*file = try_lib_path(dir, "", library, ".so", file_so)))
321
return file_so;
322
323
/* Mach-O (Darwin/Mac OS X) Dynamic Library behaves mostly like .so */
324
if ((*file = try_lib_path(dir, "", library, ".dylib", file_so)))
325
return file_so;
326
}
327
else
328
{
329
arch_dir = get_arch_dir( target );
330
if (!strcmp( suffix, ".a" )) /* try Mingw-style .dll.a import lib */
331
{
332
if ((*file = try_lib_path(dir, arch_dir, library, ".dll.a", file_arh)))
333
return file_arh;
334
}
335
}
336
337
/* static archives */
338
if ((*file = try_lib_path(dir, arch_dir, library, suffix, file_arh)))
339
return file_arh;
340
341
return file_na;
342
}
343
344
static enum file_type get_lib_type(struct strarray path, const char *library, char** file)
345
{
346
unsigned int i;
347
348
for (i = 0; i < path.count; i++)
349
{
350
enum file_type type = guess_lib_type(path.str[i], library, file);
351
if (type != file_na) return type;
352
}
353
return file_na;
354
}
355
356
static const char *find_binary( const char *name )
357
{
358
char *file_name, *args;
359
struct strarray dirs = empty_strarray;
360
unsigned int i;
361
362
if (strchr( name, '/' )) return name;
363
364
file_name = xstrdup( name );
365
if ((args = strchr( file_name, ' ' ))) *args++ = 0;
366
367
strarray_addall( &dirs, prefix_dirs );
368
strarray_addall( &dirs, path_dirs );
369
for (i = 0; i < dirs.count; i++)
370
{
371
struct stat st;
372
char *prog = strmake( "%s/%s%s", dirs.str[i], file_name, EXEEXT );
373
if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111))
374
return args ? strmake( "%s %s", prog, args ) : prog;
375
free( prog );
376
}
377
return NULL;
378
}
379
380
static int spawn(struct strarray args, int ignore_errors)
381
{
382
int status;
383
const char *cmd;
384
385
cmd = args.str[0] = find_binary( args.str[0] );
386
if (verbose) strarray_trace( args );
387
388
if ((status = strarray_spawn( args )) && !ignore_errors)
389
{
390
if (status > 0) error("%s failed\n", cmd);
391
else perror("winegcc");
392
exit(3);
393
}
394
395
return status;
396
}
397
398
399
struct tool_names
400
{
401
const char *base;
402
const char *llvm_base;
403
const char *deflt;
404
};
405
406
static const struct tool_names tool_cc = { "gcc", "clang --driver-mode=gcc", CC };
407
static const struct tool_names tool_cxx = { "g++", "clang --driver-mode=g++", CXX };
408
static const struct tool_names tool_cpp = { "cpp", "clang --driver-mode=cpp", CPP };
409
static const struct tool_names tool_ld = { "ld", "ld.lld", LD };
410
static const struct tool_names tool_objcopy = { "objcopy", "llvm-objcopy" };
411
412
static struct strarray build_tool_name( const char *target_name, struct tool_names tool )
413
{
414
const char *path, *str;
415
struct strarray ret;
416
417
if (target_name && target_version)
418
str = strmake( "%s-%s-%s", target_name, tool.base, target_version );
419
else if (target_name)
420
str = strmake( "%s-%s", target_name, tool.base );
421
else if (target_version)
422
str = strmake("%s-%s", tool.base, target_version);
423
else
424
str = tool.deflt && *tool.deflt ? tool.deflt : tool.base;
425
426
if ((path = find_binary( str ))) return strarray_fromstring( path, " " );
427
428
if (target_version)
429
str = strmake( "%s-%s", tool.llvm_base, target_version );
430
else
431
str = tool.llvm_base;
432
433
if (!(path = find_binary( str ))) error( "Could not find %s\n", tool.base );
434
435
ret = strarray_fromstring( path, " " );
436
if (!strncmp( tool.llvm_base, "clang", 5 ))
437
{
438
if (target_name)
439
{
440
strarray_add( &ret, "-target" );
441
strarray_add( &ret, target_name );
442
}
443
strarray_add( &ret, "-Wno-unused-command-line-argument" );
444
strarray_add( &ret, "-fuse-ld=lld" );
445
if (no_default_config) strarray_add( &ret, "--no-default-config" );
446
}
447
return ret;
448
}
449
450
static struct strarray get_translator(void)
451
{
452
switch(processor)
453
{
454
case proc_cpp:
455
return build_tool_name( target_alias, tool_cpp );
456
case proc_cc:
457
return build_tool_name( target_alias, tool_cc );
458
case proc_cxx:
459
return build_tool_name( target_alias, tool_cxx );
460
}
461
assert(0);
462
return empty_strarray;
463
}
464
465
static int try_link( struct strarray link_tool, const char *cflags )
466
{
467
const char *in = make_temp_file( "try_link", ".c" );
468
const char *out = make_temp_file( "try_link", ".out" );
469
const char *err = make_temp_file( "try_link", ".err" );
470
struct strarray link = empty_strarray;
471
int sout = -1, serr = -1;
472
int ret;
473
474
create_file( in, 0644, "int %s(void){return 1;}\n", is_pe ? "mainCRTStartup" : "main");
475
476
strarray_addall( &link, link_tool );
477
strarray_add( &link, "-o" );
478
strarray_add( &link, out );
479
strarray_addall( &link, strarray_fromstring( cflags, " " ) );
480
strarray_add( &link, in );
481
482
sout = dup( fileno(stdout) );
483
freopen( err, "w", stdout );
484
serr = dup( fileno(stderr) );
485
freopen( err, "w", stderr );
486
ret = spawn( link, 1 );
487
if (sout >= 0)
488
{
489
dup2( sout, fileno(stdout) );
490
close( sout );
491
}
492
if (serr >= 0)
493
{
494
dup2( serr, fileno(stderr) );
495
close( serr );
496
}
497
return ret;
498
}
499
500
static struct strarray get_link_args( const char *output_name )
501
{
502
struct strarray link_args = get_translator();
503
struct strarray flags = empty_strarray;
504
unsigned int i;
505
506
strarray_addall( &link_args, linker_args );
507
508
if (verbose > 1) strarray_add( &flags, "-v" );
509
510
switch (target.platform)
511
{
512
case PLATFORM_APPLE:
513
strarray_add( &flags, "-bundle" );
514
strarray_add( &flags, "-multiply_defined" );
515
strarray_add( &flags, "suppress" );
516
if (image_base)
517
{
518
strarray_add( &flags, "-image_base" );
519
strarray_add( &flags, image_base );
520
}
521
/* On Mac, change -s into -Wl,-x. ld's -s switch is deprecated,
522
* and it doesn't work on Tiger with MH_BUNDLEs anyway */
523
if (strip) strarray_add( &flags, "-Wl,-x" );
524
strarray_addall( &link_args, flags );
525
return link_args;
526
527
case PLATFORM_SOLARIS:
528
{
529
char *mapfile = make_temp_file( output_name, ".map" );
530
create_file( mapfile, 0644, "text = A%s;\ndata = A%s;\n", section_align, section_align );
531
strarray_add( &flags, strmake("-Wl,-M,%s", mapfile) );
532
}
533
break;
534
535
case PLATFORM_ANDROID:
536
/* the Android loader requires a soname for all libraries */
537
strarray_add( &flags, strmake( "-Wl,-soname,%s.so", output_name ));
538
break;
539
540
case PLATFORM_MINGW:
541
case PLATFORM_CYGWIN:
542
strarray_add( &link_args, "-nodefaultlibs" );
543
strarray_add( &link_args, "-nostartfiles" );
544
545
if (is_shared || is_win16_app)
546
{
547
strarray_add( &flags, "-shared" );
548
strarray_add( &flags, "-Wl,--kill-at" );
549
}
550
else strarray_add( &flags, is_gui_app ? "-mwindows" : "-mconsole" );
551
552
if (is_unicode_app) strarray_add( &flags, "-municode" );
553
if (subsystem) strarray_add( &flags, strmake("-Wl,--subsystem,%s", subsystem ));
554
555
strarray_add( &flags, "-Wl,--exclude-all-symbols" );
556
strarray_add( &flags, "-Wl,--nxcompat" );
557
strarray_add( &flags, "-Wl,--dynamicbase" );
558
strarray_add( &flags, "-Wl,--disable-auto-image-base" );
559
560
if (image_base) strarray_add( &flags, strmake("-Wl,--image-base,%s", image_base ));
561
562
if (large_address_aware && target.cpu == CPU_i386)
563
strarray_add( &flags, "-Wl,--large-address-aware" );
564
565
if (entry_point)
566
strarray_add( &flags, strmake( "-Wl,--entry,%s%s", target.cpu == CPU_i386 ? "_" : "", entry_point ));
567
568
for (i = 0; i < output_debug_files.count; i++)
569
{
570
if (!strendswith(output_debug_files.str[i], ".pdb")) continue;
571
strarray_add(&link_args, strmake("-Wl,--pdb=%s", output_debug_files.str[i]));
572
}
573
574
if (use_build_id)
575
strarray_add( &link_args, "-Wl,--build-id");
576
577
if (output_implib)
578
strarray_add(&link_args, strmake("-Wl,--out-implib,%s", output_implib));
579
580
if (strip) strarray_add( &link_args, "-s" );
581
582
if (!try_link( link_args, "-Wl,-Xlink=-filealign:0x1000,-Xlink=-align:0x1000,-Xlink=-driver" ))
583
/* lld from llvm 10 does not support mingw style --file-alignment,
584
* but it's possible to use msvc syntax
585
* the -driver option is needed to silence a warning about using -align */
586
strarray_add( &link_args, strmake( "-Wl,-Xlink=-filealign:%s,-Xlink=-align:%s,-Xlink=-driver",
587
file_align, section_align ));
588
else if (!try_link( link_args, "-Wl,--file-alignment,0x1000,--section-alignment,0x1000" ))
589
strarray_add( &link_args, strmake( "-Wl,--file-alignment,%s,--section-alignment,%s",
590
file_align, section_align ));
591
strarray_addall( &link_args, flags );
592
return link_args;
593
594
case PLATFORM_WINDOWS:
595
strarray_add( &link_args, "-nodefaultlibs" );
596
strarray_add( &link_args, "-nostdlib" );
597
598
if (is_shared || is_win16_app)
599
{
600
strarray_add( &flags, "-shared" );
601
strarray_add( &flags, "-Wl,-kill-at" );
602
}
603
if (is_unicode_app) strarray_add( &flags, "-municode" );
604
if (nostartfiles) strarray_add( &flags, "-nostartfiles" );
605
if (image_base) strarray_add( &flags, strmake("-Wl,-base:%s", image_base ));
606
if (entry_point) strarray_add( &flags, strmake( "-Wl,-entry:%s", entry_point ));
607
608
if (subsystem)
609
strarray_add( &flags, strmake("-Wl,-subsystem:%s", subsystem ));
610
else
611
strarray_add( &flags, strmake("-Wl,-subsystem:%s", is_gui_app ? "windows" : "console" ));
612
613
for (i = 0; i < output_debug_files.count; i++)
614
{
615
if (strendswith(output_debug_files.str[i], ".pdb"))
616
{
617
strarray_add(&link_args, "-Wl,-debug");
618
strarray_add(&link_args, strmake("-Wl,-pdb:%s", output_debug_files.str[i]));
619
}
620
else strarray_add( &link_args, "-Wl,-debug:dwarf" );
621
}
622
623
if (strip)
624
strarray_add( &link_args, "-s" );
625
else if (!output_debug_files.count)
626
strarray_add( &link_args, "-Wl,-debug:dwarf" );
627
628
if (use_build_id)
629
strarray_add( &link_args, "-Wl,-build-id");
630
631
if (output_implib)
632
strarray_add(&link_args, strmake("-Wl,-implib:%s", output_implib));
633
else
634
strarray_add(&link_args, strmake("-Wl,-implib:%s", make_temp_file( output_name, ".lib" )));
635
636
strarray_add( &link_args, strmake( "-Wl,-filealign:%s,-align:%s,-driver", file_align, section_align ));
637
638
strarray_addall( &link_args, flags );
639
return link_args;
640
641
default:
642
if (image_base)
643
{
644
if (!try_link( link_args, strmake("-Wl,-Ttext-segment=%s", image_base)) )
645
strarray_add( &flags, strmake("-Wl,-Ttext-segment=%s", image_base) );
646
}
647
if (!try_link( link_args, "-Wl,-z,max-page-size=0x1000"))
648
strarray_add( &flags, "-Wl,-z,max-page-size=0x1000");
649
break;
650
}
651
652
if (use_build_id)
653
strarray_add( &link_args, "-Wl,--build-id");
654
655
/* generic Unix shared library flags */
656
657
if (strip) strarray_add( &link_args, "-s" );
658
strarray_add( &link_args, "-shared" );
659
strarray_add( &link_args, "-Wl,-Bsymbolic" );
660
if (!noshortwchar && target.cpu == CPU_ARM)
661
strarray_add( &flags, "-Wl,--no-wchar-size-warning" );
662
if (!try_link( link_args, "-Wl,-z,defs" ))
663
strarray_add( &flags, "-Wl,-z,defs" );
664
665
strarray_addall( &link_args, flags );
666
return link_args;
667
}
668
669
static const char *get_multiarch_dir( struct target target )
670
{
671
switch (target.cpu)
672
{
673
case CPU_i386: return "/i386-linux-gnu";
674
case CPU_x86_64: return "/x86_64-linux-gnu";
675
case CPU_ARM: return "/arm-linux-gnueabi";
676
case CPU_ARM64: return "/aarch64-linux-gnu";
677
default:
678
assert(0);
679
}
680
return NULL;
681
}
682
683
static char *get_lib_dir(void)
684
{
685
const char *stdlibpath[] = { libdir, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
686
const char *bit_suffix, *other_bit_suffix, *build_multiarch, *target_multiarch, *winecrt0;
687
const char *root = sysroot ? sysroot : "";
688
unsigned int i;
689
struct stat st;
690
size_t build_len, target_len;
691
692
bit_suffix = get_target_ptr_size( target ) == 8 ? "64" : "32";
693
other_bit_suffix = get_target_ptr_size( target ) == 8 ? "32" : "64";
694
winecrt0 = strmake( "/wine%s/libwinecrt0.a", get_arch_dir( target ));
695
build_multiarch = get_multiarch_dir( get_default_target() );
696
target_multiarch = get_multiarch_dir( target );
697
build_len = strlen( build_multiarch );
698
target_len = strlen( target_multiarch );
699
700
for (i = 0; i < ARRAY_SIZE(stdlibpath); i++)
701
{
702
const char *root = (i && sysroot) ? sysroot : "";
703
char *p, *buffer;
704
705
if (!stdlibpath[i]) continue;
706
buffer = xmalloc( strlen(root) + strlen(stdlibpath[i]) +
707
strlen("/arm-linux-gnueabi") + strlen(winecrt0) + 1 );
708
strcpy( buffer, root );
709
strcat( buffer, stdlibpath[i] );
710
p = buffer + strlen(buffer);
711
while (p > buffer && p[-1] == '/') p--;
712
strcpy( p, winecrt0 );
713
if (!stat( buffer, &st )) goto found;
714
if (p > buffer + 2 && (!memcmp( p - 2, "32", 2 ) || !memcmp( p - 2, "64", 2 )))
715
{
716
p -= 2;
717
strcpy( p, winecrt0 );
718
if (!stat( buffer, &st )) goto found;
719
}
720
strcpy( p, bit_suffix );
721
strcat( p, winecrt0 );
722
if (!stat( buffer, &st )) goto found;
723
strcpy( p, target_multiarch );
724
strcat( p, winecrt0 );
725
if (!stat( buffer, &st )) goto found;
726
727
strcpy( buffer, root );
728
strcat( buffer, stdlibpath[i] );
729
p = buffer + strlen(buffer);
730
while (p > buffer && p[-1] == '/') p--;
731
strcpy( p, winecrt0 );
732
733
/* try to fixup each parent dirs named lib, lib32 or lib64 with target bitness suffix */
734
while (p > buffer)
735
{
736
p--;
737
while (p > buffer && *p != '/') p--;
738
if (*p != '/') break;
739
740
/* try s/$build_cpu/$target_cpu/ on multiarch */
741
if (get_default_target().cpu != target.cpu &&
742
!memcmp( p, build_multiarch, build_len ) && p[build_len] == '/')
743
{
744
memmove( p + target_len, p + build_len, strlen( p + build_len ) + 1 );
745
memcpy( p, target_multiarch, target_len );
746
if (!stat( buffer, &st )) goto found;
747
memmove( p + build_len, p + target_len, strlen( p + target_len ) + 1 );
748
memcpy( p, build_multiarch, build_len );
749
}
750
751
if (memcmp( p + 1, "lib", 3 )) continue;
752
if (p[4] == '/')
753
{
754
memmove( p + 6, p + 4, strlen( p + 4 ) + 1 );
755
memcpy( p + 4, bit_suffix, 2 );
756
if (!stat( buffer, &st )) goto found;
757
memmove( p + 4, p + 6, strlen( p + 6 ) + 1 );
758
}
759
else if (!memcmp( p + 4, other_bit_suffix, 2 ) && p[6] == '/')
760
{
761
memcpy( p + 4, bit_suffix, 2 );
762
if (!stat( buffer, &st )) goto found;
763
memmove( p + 4, p + 6, strlen( p + 6 ) + 1 );
764
if (!stat( buffer, &st )) goto found;
765
memmove( p + 6, p + 4, strlen( p + 4 ) + 1 );
766
memcpy( p + 4, other_bit_suffix, 2 );
767
}
768
}
769
770
free( buffer );
771
continue;
772
773
found:
774
buffer[strlen(buffer) - strlen(winecrt0)] = 0;
775
return buffer;
776
}
777
return strmake( "%s%s", root, LIBDIR );
778
}
779
780
/* add compatibility defines to make non-PE platforms more Windows-like */
781
static struct strarray get_compat_defines( int gcc_defs )
782
{
783
struct strarray args = empty_strarray;
784
785
if (processor != proc_cpp)
786
{
787
if (gcc_defs && !wine_objdir && !noshortwchar)
788
{
789
strarray_add(&args, "-fshort-wchar");
790
strarray_add(&args, "-DWINE_UNICODE_NATIVE");
791
}
792
strarray_add(&args, "-D_REENTRANT");
793
if (use_pic)
794
strarray_add(&args, "-fPIC");
795
else
796
strarray_add(&args, "-fno-PIC");
797
}
798
799
if (get_target_ptr_size( target ) == 8)
800
{
801
strarray_add(&args, "-DWIN64");
802
strarray_add(&args, "-D_WIN64");
803
strarray_add(&args, "-D__WIN64");
804
strarray_add(&args, "-D__WIN64__");
805
}
806
807
strarray_add(&args, "-DWIN32");
808
strarray_add(&args, "-D_WIN32");
809
strarray_add(&args, "-D__WIN32");
810
strarray_add(&args, "-D__WIN32__");
811
strarray_add(&args, "-D__WINNT");
812
strarray_add(&args, "-D__WINNT__");
813
814
if (gcc_defs)
815
{
816
switch (target.cpu)
817
{
818
case CPU_x86_64:
819
case CPU_ARM64:
820
strarray_add(&args, "-D__stdcall=__attribute__((ms_abi))");
821
strarray_add(&args, "-D__cdecl=__stdcall");
822
strarray_add(&args, "-D__fastcall=__stdcall");
823
break;
824
case CPU_i386:
825
strarray_add(&args, "-D__stdcall=__attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))");
826
strarray_add(&args, "-D__cdecl=__attribute__((__cdecl__)) __attribute__((__force_align_arg_pointer__))");
827
strarray_add(&args, "-D__fastcall=__attribute__((__fastcall__))");
828
break;
829
case CPU_ARM:
830
strarray_add(&args, "-D__stdcall=__attribute__((pcs(\"aapcs-vfp\")))");
831
strarray_add(&args, "-D__cdecl=__stdcall");
832
strarray_add(&args, "-D__fastcall=__stdcall");
833
break;
834
case CPU_ARM64EC:
835
break;
836
}
837
strarray_add(&args, "-D_stdcall=__stdcall");
838
strarray_add(&args, "-D_cdecl=__cdecl");
839
strarray_add(&args, "-D_fastcall=__fastcall");
840
strarray_add(&args, "-D__declspec(x)=__declspec_##x");
841
strarray_add(&args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
842
strarray_add(&args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
843
strarray_add(&args, "-D__declspec_deprecated=__attribute__((deprecated))");
844
strarray_add(&args, "-D__declspec_dllimport=__attribute__((dllimport))");
845
strarray_add(&args, "-D__declspec_dllexport=__attribute__((dllexport))");
846
strarray_add(&args, "-D__declspec_naked=__attribute__((naked))");
847
strarray_add(&args, "-D__declspec_noinline=__attribute__((noinline))");
848
strarray_add(&args, "-D__declspec_noreturn=__attribute__((noreturn))");
849
strarray_add(&args, "-D__declspec_nothrow=__attribute__((nothrow))");
850
strarray_add(&args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
851
strarray_add(&args, "-D__declspec_selectany=__attribute__((weak))");
852
strarray_add(&args, "-D__declspec_thread=__thread");
853
}
854
855
strarray_add(&args, "-D__int8=char");
856
strarray_add(&args, "-D__int16=short");
857
strarray_add(&args, "-D__int32=int");
858
if (get_target_ptr_size( target ) == 8)
859
strarray_add(&args, "-D__int64=long");
860
else
861
strarray_add(&args, "-D__int64=long long");
862
863
return args;
864
}
865
866
static void compile( struct strarray files, const char *output_name, int compile_only )
867
{
868
struct strarray comp_args = get_translator();
869
unsigned int i, j;
870
int gcc_defs = 0;
871
struct strarray gcc;
872
struct strarray gpp;
873
874
if (force_pointer_size)
875
strarray_add( &comp_args, strmake("-m%u", 8 * force_pointer_size ) );
876
switch(processor)
877
{
878
case proc_cpp: gcc_defs = 1; break;
879
/* Note: if the C compiler is gcc we assume the C++ compiler is too */
880
/* mixing different C and C++ compilers isn't supported in configure anyway */
881
case proc_cc:
882
case proc_cxx:
883
gcc = build_tool_name( target_alias, tool_cc );
884
gpp = build_tool_name( target_alias, tool_cxx );
885
for ( j = 0; !gcc_defs && j < comp_args.count; j++ )
886
{
887
const char *cc = comp_args.str[j];
888
889
for (i = 0; !gcc_defs && i < gcc.count; i++)
890
gcc_defs = gcc.str[i][0] != '-' && strendswith(cc, gcc.str[i]);
891
for (i = 0; !gcc_defs && i < gpp.count; i++)
892
gcc_defs = gpp.str[i][0] != '-' && strendswith(cc, gpp.str[i]);
893
}
894
break;
895
}
896
897
if (!is_pe) strarray_addall( &comp_args, get_compat_defines( gcc_defs ));
898
899
strarray_add(&comp_args, "-D__WINE__");
900
901
/* options we handle explicitly */
902
if (compile_only)
903
strarray_add(&comp_args, "-c");
904
if (output_name)
905
{
906
strarray_add(&comp_args, "-o");
907
strarray_add(&comp_args, output_name);
908
}
909
910
if (verbose > 1) strarray_add( &comp_args, "-v" );
911
912
/* the rest of the pass-through parameters */
913
strarray_addall(&comp_args, compiler_args);
914
915
/* last, but not least, the files */
916
for ( j = 0; j < files.count; j++ )
917
{
918
if (files.str[j][0] == '-')
919
{
920
/* keep -x and bare '-' (i.e. stdin) options */
921
if (files.str[j][1] && files.str[j][1] != 'x') continue;
922
}
923
strarray_add(&comp_args, files.str[j]);
924
}
925
926
/* standard includes come last in the include search path */
927
if (!wine_objdir && !nostdinc)
928
{
929
const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
930
const char *root = isysroot ? isysroot : sysroot ? sysroot : "";
931
const char *isystem = gcc_defs ? "-isystem" : "-I";
932
const char *idirafter = gcc_defs ? "-idirafter" : "-I";
933
934
if (use_msvcrt)
935
{
936
if (includedir) strarray_add( &comp_args, strmake( "%s%s/wine/msvcrt", isystem, includedir ));
937
for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
938
{
939
if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
940
strarray_add(&comp_args, strmake( "%s%s%s/wine/msvcrt", isystem, root, incl_dirs[j] ));
941
}
942
strarray_add(&comp_args, "-D__MSVCRT__");
943
}
944
if (includedir)
945
{
946
strarray_add( &comp_args, strmake( "%s%s/wine/windows", isystem, includedir ));
947
if (!use_msvcrt) strarray_add( &comp_args, strmake( "%s%s", idirafter, includedir ));
948
}
949
for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
950
{
951
if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
952
strarray_add(&comp_args, strmake( "%s%s%s/wine/windows", isystem, root, incl_dirs[j] ));
953
if (!use_msvcrt) strarray_add(&comp_args, strmake( "%s%s%s", idirafter, root, incl_dirs[j] ));
954
}
955
}
956
else if (wine_objdir)
957
strarray_add(&comp_args, strmake("-I%s/include", wine_objdir) );
958
959
spawn(comp_args, 0);
960
}
961
962
static const char* compile_to_object(const char* file, const char* lang)
963
{
964
char *output_name = make_temp_file(get_basename_noext(file), ".o");
965
struct strarray files = empty_strarray;
966
967
if (lang) strarray_add(&files, lang);
968
strarray_add(&files, file);
969
compile(files, output_name, 1);
970
return output_name;
971
}
972
973
/* return the initial set of options needed to run winebuild */
974
static struct strarray get_winebuild_args( const char *target )
975
{
976
const char *binary;
977
struct strarray spec_args = empty_strarray;
978
unsigned int i;
979
980
if (!(binary = find_binary( winebuild ))) error( "Could not find winebuild\n" );
981
strarray_add( &spec_args, binary );
982
if (verbose) strarray_add( &spec_args, "-v" );
983
if (keep_generated) strarray_add( &spec_args, "--save-temps" );
984
if (target)
985
{
986
strarray_add( &spec_args, "--target" );
987
strarray_add( &spec_args, target );
988
}
989
if (force_pointer_size)
990
strarray_add(&spec_args, strmake("-m%u", 8 * force_pointer_size ));
991
for (i = 0; i < prefix_dirs.count; i++)
992
strarray_add( &spec_args, strmake( "-B%s", prefix_dirs.str[i] ));
993
strarray_addall( &spec_args, winebuild_args );
994
return spec_args;
995
}
996
997
static void fixup_constructors( const char *file )
998
{
999
struct strarray args = get_winebuild_args( target_alias );
1000
1001
strarray_add( &args, "--fixup-ctors" );
1002
strarray_add( &args, file );
1003
spawn( args, 0 );
1004
}
1005
1006
static void make_wine_builtin( const char *file )
1007
{
1008
struct strarray args = get_winebuild_args( target_alias );
1009
1010
strarray_add( &args, "--builtin" );
1011
strarray_add( &args, file );
1012
spawn( args, 0 );
1013
}
1014
1015
/* check if there is a static lib associated to a given dll */
1016
static char *find_static_lib( const char *dll )
1017
{
1018
char *lib = strmake("%s.a", dll);
1019
if (get_file_type(lib) == file_arh) return lib;
1020
free( lib );
1021
return NULL;
1022
}
1023
1024
static const char *find_libgcc(void)
1025
{
1026
const char *out = make_temp_file( "find_libgcc", ".out" );
1027
const char *err = make_temp_file( "find_libgcc", ".err" );
1028
struct strarray link = get_translator();
1029
int sout = -1, serr = -1, i;
1030
char *libgcc, *p;
1031
struct stat st;
1032
size_t cnt;
1033
int ret;
1034
1035
for (i = 0; i < linker_args.count; i++)
1036
if (strcmp(linker_args.str[i], "--no-default-config" ))
1037
strarray_add( &link, linker_args.str[i] );
1038
1039
strarray_add( &link, "-print-libgcc-file-name" );
1040
1041
sout = dup( fileno(stdout) );
1042
freopen( out, "w", stdout );
1043
serr = dup( fileno(stderr) );
1044
freopen( err, "w", stderr );
1045
ret = spawn( link, 1 );
1046
if (sout >= 0)
1047
{
1048
dup2( sout, fileno(stdout) );
1049
close( sout );
1050
}
1051
if (serr >= 0)
1052
{
1053
dup2( serr, fileno(stderr) );
1054
close( serr );
1055
}
1056
1057
if (ret || stat(out, &st) || !st.st_size) return NULL;
1058
1059
libgcc = xmalloc(st.st_size + 1);
1060
sout = open(out, O_RDONLY);
1061
if (sout == -1) return NULL;
1062
cnt = read(sout, libgcc, st.st_size);
1063
close(sout);
1064
libgcc[cnt] = 0;
1065
if ((p = strchr(libgcc, '\n'))) *p = 0;
1066
return libgcc;
1067
}
1068
1069
1070
/* add specified library to the list of files */
1071
static void add_library( struct strarray lib_dirs, struct strarray *files, const char *library )
1072
{
1073
char *static_lib, *fullname = 0;
1074
1075
switch(get_lib_type(lib_dirs, library, &fullname))
1076
{
1077
case file_arh:
1078
strarray_add(files, strmake("-a%s", fullname));
1079
break;
1080
case file_dll:
1081
strarray_add(files, strmake("-d%s", fullname));
1082
if ((static_lib = find_static_lib(fullname)))
1083
{
1084
strarray_add(files, strmake("-a%s",static_lib));
1085
free(static_lib);
1086
}
1087
break;
1088
case file_so:
1089
default:
1090
/* keep it anyway, the linker may know what to do with it */
1091
strarray_add(files, strmake("-l%s", library));
1092
break;
1093
}
1094
free(fullname);
1095
}
1096
1097
/* run winebuild to generate the .spec.o file */
1098
static void build_spec_obj( const char *spec_file, const char *output_file,
1099
const char *target_name, struct strarray files,
1100
struct strarray resources, struct strarray *spec_objs )
1101
{
1102
unsigned int i;
1103
struct strarray spec_args = get_winebuild_args( target_name );
1104
struct strarray tool;
1105
const char *spec_o_name, *output_name;
1106
1107
/* get the filename from the path */
1108
output_name = get_basename( output_file );
1109
1110
tool = build_tool_name( target_name, tool_cc );
1111
strarray_add( &spec_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " )));
1112
if (!is_pe)
1113
{
1114
tool = build_tool_name( target_name, tool_ld );
1115
strarray_add( &spec_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " )));
1116
}
1117
1118
spec_o_name = make_temp_file(output_name, ".spec.o");
1119
if (!is_pe)
1120
{
1121
if (use_pic) strarray_add(&spec_args, "-fPIC");
1122
if (use_msvcrt) strarray_add(&spec_args, "-mno-cygwin");
1123
if (unwind_tables) strarray_add( &spec_args, "-fasynchronous-unwind-tables" );
1124
}
1125
strarray_add(&spec_args, is_shared ? "--dll" : "--exe");
1126
if (fake_module)
1127
{
1128
strarray_add(&spec_args, "--fake-module");
1129
strarray_add(&spec_args, "-o");
1130
strarray_add(&spec_args, output_file);
1131
}
1132
else
1133
{
1134
strarray_add(&spec_args, "-o");
1135
strarray_add(&spec_args, spec_o_name);
1136
}
1137
if (spec_file)
1138
{
1139
strarray_add(&spec_args, "-E");
1140
strarray_add(&spec_args, spec_file);
1141
}
1142
else
1143
{
1144
strarray_add(&spec_args, "-F");
1145
strarray_add(&spec_args, output_name);
1146
}
1147
1148
if (!is_shared)
1149
{
1150
strarray_add(&spec_args, "--subsystem");
1151
strarray_add(&spec_args, is_gui_app ? "windows" : "console");
1152
if (large_address_aware) strarray_add( &spec_args, "--large-address-aware" );
1153
}
1154
1155
if (target.platform == PLATFORM_WINDOWS && target.cpu == CPU_i386)
1156
strarray_add(&spec_args, "--safeseh");
1157
1158
if (entry_point)
1159
{
1160
strarray_add(&spec_args, "--entry");
1161
strarray_add(&spec_args, entry_point);
1162
}
1163
1164
if (subsystem)
1165
{
1166
strarray_add(&spec_args, "--subsystem");
1167
strarray_add(&spec_args, subsystem);
1168
}
1169
1170
if (!is_pe)
1171
{
1172
for (i = 0; i < delayimports.count; i++)
1173
strarray_add(&spec_args, strmake("-d%s", delayimports.str[i]));
1174
}
1175
1176
strarray_addall( &spec_args, resources );
1177
1178
/* add other files */
1179
strarray_add(&spec_args, "--");
1180
for (i = 0; i < files.count; i++)
1181
{
1182
switch(files.str[i][1])
1183
{
1184
case 'd':
1185
case 'a':
1186
case 'o':
1187
strarray_add(&spec_args, files.str[i] + 2);
1188
break;
1189
}
1190
}
1191
1192
spawn(spec_args, 0);
1193
strarray_add( spec_objs, spec_o_name );
1194
}
1195
1196
/* run winebuild to generate a data-only library */
1197
static void build_data_lib( const char *spec_file, const char *output_file, struct strarray files )
1198
{
1199
unsigned int i;
1200
struct strarray spec_args = get_winebuild_args( target_alias );
1201
1202
strarray_add(&spec_args, is_shared ? "--dll" : "--exe");
1203
strarray_add(&spec_args, "-o");
1204
strarray_add(&spec_args, output_file);
1205
if (spec_file)
1206
{
1207
strarray_add(&spec_args, "-E");
1208
strarray_add(&spec_args, spec_file);
1209
}
1210
1211
/* add resource files */
1212
for (i = 0; i < files.count; i++)
1213
if (files.str[i][1] == 'r') strarray_add(&spec_args, files.str[i]);
1214
1215
spawn(spec_args, 0);
1216
}
1217
1218
static void build(struct strarray input_files, const char *output)
1219
{
1220
struct strarray resources = empty_strarray;
1221
struct strarray spec_objs = empty_strarray;
1222
struct strarray lib_dirs = empty_strarray;
1223
struct strarray files = empty_strarray;
1224
struct strarray link_args;
1225
char *output_file;
1226
const char *output_name, *spec_file, *lang;
1227
const char *libgcc = NULL;
1228
int generate_app_loader = 1;
1229
const char *crt_lib = NULL;
1230
unsigned int i, j;
1231
1232
/* NOTE: for the files array we'll use the following convention:
1233
* -axxx: xxx is an archive (.a)
1234
* -dxxx: xxx is a DLL (.def)
1235
* -lxxx: xxx is an unsorted library
1236
* -oxxx: xxx is an object (.o)
1237
* -rxxx: xxx is a resource (.res)
1238
* -sxxx: xxx is a shared lib (.so)
1239
* -xlll: lll is the language (c, c++, etc.)
1240
*/
1241
1242
output_file = xstrdup( output ? output : "a.out" );
1243
1244
/* 'winegcc -o app xxx.exe.so' only creates the load script */
1245
if (input_files.count == 1 && strendswith(input_files.str[0], ".exe.so"))
1246
{
1247
create_file(output_file, 0755, app_loader_template, input_files.str[0]);
1248
return;
1249
}
1250
1251
if (is_static) error("Static linking is not supported\n");
1252
1253
/* generate app loader only for .exe */
1254
if (is_shared || is_pe || strendswith(output_file, ".so"))
1255
generate_app_loader = 0;
1256
1257
/* normalize the filename a bit: strip .so, ensure it has proper ext */
1258
if (!strchr(get_basename( output_file ), '.'))
1259
output_file = strmake("%s.%s", output_file, is_shared ? "dll" : "exe");
1260
else if (strendswith(output_file, ".so"))
1261
output_file[strlen(output_file) - 3] = 0;
1262
output_file_name = is_pe ? output_file : strmake( "%s.so", output_file );
1263
1264
/* get the filename from the path */
1265
output_name = get_basename( output_file );
1266
1267
/* prepare the linking path */
1268
if (!wine_objdir)
1269
{
1270
char *lib_dir = get_lib_dir();
1271
strarray_addall( &lib_dirs, lib_path_dirs );
1272
strarray_add( &lib_dirs, strmake( "%s/wine%s", lib_dir, get_arch_dir( target )));
1273
strarray_add( &lib_dirs, lib_dir );
1274
}
1275
else
1276
{
1277
strarray_add(&lib_dirs, strmake("%s/dlls", wine_objdir));
1278
strarray_addall(&lib_dirs, lib_path_dirs);
1279
}
1280
1281
/* mark the files with their appropriate type */
1282
spec_file = lang = 0;
1283
for ( j = 0; j < input_files.count; j++ )
1284
{
1285
const char* file = input_files.str[j];
1286
if (file[0] != '-')
1287
{
1288
switch(get_file_type(file))
1289
{
1290
case file_spec:
1291
if (spec_file)
1292
error("Only one spec file can be specified\n");
1293
spec_file = file;
1294
break;
1295
case file_rc:
1296
/* FIXME: invoke wrc to build it */
1297
error("Can't compile .rc file at the moment: %s\n", file);
1298
break;
1299
case file_res:
1300
strarray_add(&files, strmake("-r%s", file));
1301
break;
1302
case file_obj:
1303
strarray_add(&files, strmake("-o%s", file));
1304
break;
1305
case file_arh:
1306
if (use_msvcrt)
1307
{
1308
char *p = get_basename( file );
1309
if (!strncmp(p, "libmsvcr", 8) || !strncmp(p, "libucrt", 7)) crt_lib = file;
1310
}
1311
strarray_add(&files, strmake("-a%s", file));
1312
break;
1313
case file_so:
1314
strarray_add(&files, strmake("-s%s", file));
1315
break;
1316
case file_na:
1317
error("File does not exist: %s\n", file);
1318
break;
1319
default:
1320
file = compile_to_object(file, lang);
1321
strarray_add(&files, strmake("-o%s", file));
1322
break;
1323
}
1324
}
1325
else if (file[1] == 'l')
1326
add_library( lib_dirs, &files, file + 2 );
1327
else if (file[1] == 'x')
1328
lang = file;
1329
else if(file[1] == 'W')
1330
strarray_add(&files, file);
1331
}
1332
1333
/* add the default libraries, if needed */
1334
1335
if (!wine_objdir && !nodefaultlibs)
1336
{
1337
if (is_gui_app)
1338
{
1339
add_library(lib_dirs, &files, "shell32");
1340
add_library(lib_dirs, &files, "comdlg32");
1341
add_library(lib_dirs, &files, "gdi32");
1342
}
1343
add_library(lib_dirs, &files, "advapi32");
1344
add_library(lib_dirs, &files, "user32");
1345
add_library(lib_dirs, &files, "winecrt0");
1346
if (target.platform == PLATFORM_WINDOWS)
1347
add_library(lib_dirs, &files, "compiler-rt");
1348
if (use_msvcrt)
1349
{
1350
if (!crt_lib)
1351
{
1352
if (strncmp( output_name, "msvcr", 5 ) &&
1353
strncmp( output_name, "ucrt", 4 ) &&
1354
strcmp( output_name, "crtdll.dll" ))
1355
add_library(lib_dirs, &files, "ucrtbase");
1356
}
1357
else strarray_add(&files, strmake("-a%s", crt_lib));
1358
}
1359
if (is_win16_app) add_library(lib_dirs, &files, "kernel");
1360
add_library(lib_dirs, &files, "kernel32");
1361
add_library(lib_dirs, &files, "ntdll");
1362
}
1363
1364
/* set default entry point, if needed */
1365
if (!entry_point)
1366
{
1367
if (subsystem && !strcmp( subsystem, "native" ))
1368
entry_point = (is_pe && target.cpu == CPU_i386) ? "DriverEntry@8" : "DriverEntry";
1369
else if (use_msvcrt && !is_shared && !is_win16_app)
1370
entry_point = is_unicode_app ? "wmainCRTStartup" : "mainCRTStartup";
1371
}
1372
1373
/* run winebuild to generate the .spec.o file */
1374
if (data_only)
1375
{
1376
build_data_lib( spec_file, output_file, files );
1377
return;
1378
}
1379
1380
for (i = 0; i < files.count; i++)
1381
if (files.str[i][1] == 'r') strarray_add( &resources, files.str[i] );
1382
1383
build_spec_obj( spec_file, output_file, target_alias, files, resources, &spec_objs );
1384
if (is_arm64x)
1385
{
1386
const char *suffix = strchr( target_alias, '-' );
1387
if (!suffix) suffix = "";
1388
build_spec_obj( spec_file, output_file, strmake( "aarch64%s", suffix ),
1389
files, empty_strarray, &spec_objs );
1390
}
1391
1392
if (fake_module) return; /* nothing else to do */
1393
1394
if (is_pe && !entry_point && (is_shared || is_win16_app))
1395
entry_point = target.cpu == CPU_i386 ? "DllMainCRTStartup@12" : "DllMainCRTStartup";
1396
1397
/* link everything together now */
1398
link_args = get_link_args( output_name );
1399
1400
switch (target.platform)
1401
{
1402
case PLATFORM_MINGW:
1403
case PLATFORM_CYGWIN:
1404
libgcc = find_libgcc();
1405
if (!libgcc) libgcc = "-lgcc";
1406
break;
1407
default:
1408
break;
1409
}
1410
1411
strarray_add(&link_args, "-o");
1412
strarray_add(&link_args, output_file_name);
1413
1414
for ( j = 0; j < lib_dirs.count; j++ )
1415
strarray_add(&link_args, strmake("-L%s", lib_dirs.str[j]));
1416
1417
strarray_addall( &link_args, spec_objs );
1418
1419
if (is_pe)
1420
{
1421
for (j = 0; j < delayimports.count; j++)
1422
{
1423
if (target.platform == PLATFORM_WINDOWS)
1424
strarray_add(&link_args, strmake("-Wl,-delayload:%s", delayimports.str[j]));
1425
else
1426
strarray_add(&link_args, strmake("-Wl,-delayload,%s",delayimports.str[j]));
1427
}
1428
}
1429
1430
for ( j = 0; j < files.count; j++ )
1431
{
1432
const char* name = files.str[j] + 2;
1433
switch(files.str[j][1])
1434
{
1435
case 'l':
1436
strarray_add(&link_args, strmake("-l%s", name));
1437
break;
1438
case 's':
1439
case 'o':
1440
strarray_add(&link_args, name);
1441
break;
1442
case 'a':
1443
if (!use_msvcrt && !lib_suffix && strchr(name, '/'))
1444
{
1445
const char *p = get_basename( name );
1446
1447
/* don't link to ntdll or ntoskrnl in non-msvcrt mode
1448
* since they export CRT functions */
1449
if (!strcmp( p, "libntdll.a" )) break;
1450
if (!strcmp( p, "libntoskrnl.a" )) break;
1451
}
1452
strarray_add(&link_args, name);
1453
break;
1454
case 'W':
1455
strarray_add(&link_args, files.str[j]);
1456
break;
1457
}
1458
}
1459
1460
if (!nostdlib && !is_pe)
1461
{
1462
strarray_add(&link_args, "-ldl");
1463
strarray_add(&link_args, "-lm");
1464
strarray_add(&link_args, "-lc");
1465
}
1466
1467
if (libgcc) strarray_add(&link_args, libgcc);
1468
1469
atexit( cleanup_output_files );
1470
1471
spawn(link_args, 0);
1472
1473
for (i = 0; i < output_debug_files.count; i++)
1474
{
1475
struct strarray tool, objcopy;
1476
1477
if (strendswith(output_debug_files.str[i], ".pdb")) continue;
1478
objcopy = build_tool_name(target_alias, tool_objcopy);
1479
1480
tool = empty_strarray;
1481
strarray_addall( &tool, objcopy );
1482
strarray_add(&tool, "--only-keep-debug");
1483
strarray_add(&tool, output_file_name);
1484
strarray_add(&tool, output_debug_files.str[i]);
1485
spawn(tool, 1);
1486
1487
tool = empty_strarray;
1488
strarray_addall( &tool, objcopy );
1489
strarray_add(&tool, "--strip-debug");
1490
strarray_add(&tool, output_file_name);
1491
spawn(tool, 1);
1492
1493
tool = empty_strarray;
1494
strarray_addall( &tool, objcopy );
1495
strarray_add(&tool, "--add-gnu-debuglink");
1496
strarray_add(&tool, output_debug_files.str[i]);
1497
strarray_add(&tool, output_file_name);
1498
spawn(tool, 0);
1499
}
1500
1501
if (output_implib && !is_pe)
1502
{
1503
struct strarray tool, implib_args;
1504
1505
if (!spec_file)
1506
error("--out-implib requires a .spec or .def file\n");
1507
1508
implib_args = get_winebuild_args( target_alias );
1509
tool = build_tool_name( target_alias, tool_cc );
1510
strarray_add( &implib_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " )));
1511
tool = build_tool_name( target_alias, tool_ld );
1512
strarray_add( &implib_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " )));
1513
1514
strarray_add(&implib_args, "--implib");
1515
strarray_add(&implib_args, "-o");
1516
strarray_add(&implib_args, output_implib);
1517
strarray_add(&implib_args, "--export");
1518
strarray_add(&implib_args, spec_file);
1519
1520
spawn(implib_args, 0);
1521
}
1522
1523
if (!is_pe) fixup_constructors( output_file_name );
1524
else if (wine_builtin) make_wine_builtin( output_file_name );
1525
1526
/* create the loader script */
1527
if (generate_app_loader)
1528
create_file(output_file, 0755, app_loader_template, strmake("%s.so", output_name));
1529
}
1530
1531
1532
static void forward(void)
1533
{
1534
struct strarray args = get_translator();
1535
1536
strarray_addall(&args, compiler_args);
1537
strarray_addall(&args, linker_args);
1538
spawn(args, 0);
1539
}
1540
1541
static int is_linker_arg(const char* arg)
1542
{
1543
static const char* link_switches[] =
1544
{
1545
"-nostdlib", "-s", "-static", "-static-libgcc", "-static-libstdc++",
1546
"-shared", "-shared-libgcc", "-symbolic", "-framework", "--coverage",
1547
"-fprofile-generate", "-fprofile-use"
1548
};
1549
unsigned int j;
1550
1551
switch (arg[1])
1552
{
1553
case 'R':
1554
case 'z':
1555
case 'u':
1556
return 1;
1557
case 'W':
1558
if (strncmp("-Wl,", arg, 4) == 0) return 1;
1559
break;
1560
case 'X':
1561
if (strcmp("-Xlinker", arg) == 0) return 1;
1562
break;
1563
case 'a':
1564
if (strcmp("-arch", arg) == 0) return 1;
1565
break;
1566
case 'f':
1567
if (strncmp("-fuse-ld=", arg, 9) == 0) return 1;
1568
break;
1569
case 'r':
1570
if (strncmp("-rtlib=", arg, 7) == 0) return 1;
1571
break;
1572
}
1573
1574
for (j = 0; j < ARRAY_SIZE(link_switches); j++)
1575
if (strcmp(link_switches[j], arg) == 0) return 1;
1576
1577
return 0;
1578
}
1579
1580
static int is_option( struct strarray args, int i, const char *option, const char **option_arg )
1581
{
1582
if (!strcmp( args.str[i], option ))
1583
{
1584
if (args.count == i) error( "option %s requires an argument\n", args.str[i] );
1585
*option_arg = args.str[i + 1];
1586
return 1;
1587
}
1588
if (!strncmp( args.str[i], option, strlen(option) ) && args.str[i][strlen(option)] == '=')
1589
{
1590
*option_arg = args.str[i] + strlen(option) + 1;
1591
return 1;
1592
}
1593
return 0;
1594
}
1595
1596
static struct strarray read_args_from_file( const char *name )
1597
{
1598
struct strarray args = empty_strarray;
1599
char *input_buffer = NULL, *iter, *end, *opt, *out;
1600
struct stat st;
1601
int fd;
1602
1603
if ((fd = open( name, O_RDONLY | O_BINARY )) == -1) error( "Cannot open %s\n", name );
1604
fstat( fd, &st );
1605
if (st.st_size)
1606
{
1607
input_buffer = xmalloc( st.st_size + 1 );
1608
if (read( fd, input_buffer, st.st_size ) != st.st_size) error( "Cannot read %s\n", name );
1609
}
1610
close( fd );
1611
end = input_buffer + st.st_size;
1612
for (iter = input_buffer; iter < end; iter++)
1613
{
1614
char quote = 0;
1615
while (iter < end && isspace(*iter)) iter++;
1616
if (iter == end) break;
1617
opt = out = iter;
1618
while (iter < end && (quote || !isspace(*iter)))
1619
{
1620
if (*iter == quote)
1621
{
1622
iter++;
1623
quote = 0;
1624
}
1625
else if (*iter == '\'' || *iter == '"') quote = *iter++;
1626
else
1627
{
1628
if (*iter == '\\' && iter + 1 < end) iter++;
1629
*out++ = *iter++;
1630
}
1631
}
1632
*out = 0;
1633
strarray_add( &args, opt );
1634
}
1635
return args;
1636
}
1637
1638
int main(int argc, char **argv)
1639
{
1640
int i, c, next_is_arg = 0;
1641
int raw_compiler_arg, raw_linker_arg, raw_winebuild_arg;
1642
struct strarray args = empty_strarray;
1643
const char* option_arg;
1644
char* str;
1645
1646
init_signals( exit_on_signal );
1647
bindir = get_bindir( argv[0] );
1648
libdir = get_libdir( bindir );
1649
includedir = get_includedir( bindir );
1650
target = init_argv0_target( argv[0] );
1651
path_dirs = strarray_frompath( getenv( "PATH" ));
1652
1653
/* setup tmp file removal at exit */
1654
atexit(clean_temp_files);
1655
1656
/* determine the processor type */
1657
if (strendswith(argv[0], "winecpp")) processor = proc_cpp;
1658
else if (strendswith(argv[0], "++")) processor = proc_cxx;
1659
1660
for (i = 1; i < argc; i++)
1661
if (argv[i][0] == '@')
1662
strarray_addall( &args, read_args_from_file( argv[i] + 1 ));
1663
else
1664
strarray_add( &args, argv[i] );
1665
1666
/* parse options */
1667
for (i = 0; i < args.count; i++)
1668
{
1669
if (args.str[i][0] == '-' && args.str[i][1]) /* option, except '-' alone is stdin, which is a file */
1670
{
1671
/* determine if this switch is followed by a separate argument */
1672
next_is_arg = 0;
1673
option_arg = 0;
1674
switch(args.str[i][1])
1675
{
1676
case 'x': case 'o': case 'D': case 'U':
1677
case 'I': case 'A': case 'l': case 'u':
1678
case 'b': case 'V': case 'G': case 'L':
1679
case 'B': case 'R': case 'z':
1680
if (args.str[i][2]) option_arg = &args.str[i][2];
1681
else next_is_arg = 1;
1682
break;
1683
case 'i':
1684
next_is_arg = 1;
1685
break;
1686
case 'a':
1687
if (strcmp("-aux-info", args.str[i]) == 0)
1688
next_is_arg = 1;
1689
if (strcmp("-arch", args.str[i]) == 0)
1690
next_is_arg = 1;
1691
break;
1692
case 'X':
1693
if (strcmp("-Xlinker", args.str[i]) == 0)
1694
next_is_arg = 1;
1695
break;
1696
case 'M':
1697
c = args.str[i][2];
1698
if (c == 'F' || c == 'T' || c == 'Q')
1699
{
1700
if (args.str[i][3]) option_arg = &args.str[i][3];
1701
else next_is_arg = 1;
1702
}
1703
break;
1704
case 'f':
1705
if (strcmp("-framework", args.str[i]) == 0)
1706
next_is_arg = 1;
1707
break;
1708
case 't':
1709
next_is_arg = strcmp("-target", args.str[i]) == 0;
1710
break;
1711
case '-':
1712
next_is_arg = (strcmp("--param", args.str[i]) == 0 ||
1713
strcmp("--sysroot", args.str[i]) == 0 ||
1714
strcmp("--target", args.str[i]) == 0 ||
1715
strcmp("--wine-objdir", args.str[i]) == 0 ||
1716
strcmp("--winebuild", args.str[i]) == 0 ||
1717
strcmp("--lib-suffix", args.str[i]) == 0);
1718
break;
1719
}
1720
if (next_is_arg)
1721
{
1722
if (i + 1 >= args.count) error("option -%c requires an argument\n", args.str[i][1]);
1723
option_arg = args.str[i+1];
1724
}
1725
1726
/* determine what options go 'as is' to the linker & the compiler */
1727
raw_linker_arg = is_linker_arg(args.str[i]);
1728
raw_compiler_arg = !raw_linker_arg;
1729
raw_winebuild_arg = 0;
1730
1731
/* do a bit of semantic analysis */
1732
switch (args.str[i][1])
1733
{
1734
case 'B':
1735
str = xstrdup(option_arg);
1736
if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
1737
strarray_add(&prefix_dirs, str);
1738
raw_linker_arg = 1;
1739
break;
1740
case 'b':
1741
target_alias = option_arg;
1742
raw_compiler_arg = 0;
1743
break;
1744
case 'V':
1745
target_version = option_arg;
1746
raw_compiler_arg = 0;
1747
break;
1748
case 'c': /* compile or assemble */
1749
raw_compiler_arg = 0;
1750
if (args.str[i][2] == 0) compile_only = true;
1751
break;
1752
case 'S': /* generate assembler code */
1753
case 'E': /* preprocess only */
1754
if (args.str[i][2] == 0) skip_link = true;
1755
break;
1756
case 'f':
1757
if (strcmp("-fno-short-wchar", args.str[i]) == 0)
1758
noshortwchar = true;
1759
else if (!strcmp("-fasynchronous-unwind-tables", args.str[i]))
1760
unwind_tables = true;
1761
else if (!strcmp("-fno-asynchronous-unwind-tables", args.str[i]))
1762
unwind_tables = false;
1763
else if (!strcmp("-fms-hotpatch", args.str[i]))
1764
raw_linker_arg = 1;
1765
else if (!strcmp("-fPIC", args.str[i]) || !strcmp("-fpic", args.str[i]))
1766
use_pic = true;
1767
else if (!strcmp("-fno-PIC", args.str[i]) || !strcmp("-fno-pic", args.str[i]))
1768
use_pic = false;
1769
break;
1770
case 'i':
1771
if (!strcmp( "-isysroot", args.str[i] )) isysroot = args.str[i + 1];
1772
break;
1773
case 'l':
1774
strarray_add(&file_args, strmake("-l%s", option_arg));
1775
raw_compiler_arg = 0;
1776
break;
1777
case 'L':
1778
strarray_add(&lib_path_dirs, option_arg);
1779
raw_compiler_arg = 0;
1780
break;
1781
case 'M': /* map file generation */
1782
skip_link = true;
1783
break;
1784
case 'm':
1785
if (strcmp("-mno-cygwin", args.str[i]) == 0)
1786
{
1787
use_msvcrt = true;
1788
raw_compiler_arg = 0;
1789
}
1790
if (strcmp("-mcygwin", args.str[i]) == 0)
1791
{
1792
use_msvcrt = false;
1793
raw_compiler_arg = 0;
1794
}
1795
else if (strcmp("-mwindows", args.str[i]) == 0)
1796
{
1797
is_gui_app = true;
1798
raw_compiler_arg = 0;
1799
}
1800
else if (strcmp("-mconsole", args.str[i]) == 0)
1801
{
1802
is_gui_app = false;
1803
raw_compiler_arg = 0;
1804
}
1805
else if (strcmp("-municode", args.str[i]) == 0)
1806
{
1807
is_unicode_app = true;
1808
raw_compiler_arg = 0;
1809
raw_winebuild_arg = 1;
1810
}
1811
else if (strcmp("-mthreads", args.str[i]) == 0)
1812
{
1813
raw_compiler_arg = 0;
1814
}
1815
else if (strcmp("-m16", args.str[i]) == 0)
1816
{
1817
is_win16_app = true;
1818
raw_compiler_arg = 0;
1819
raw_winebuild_arg = 1;
1820
}
1821
else if (strcmp("-m32", args.str[i]) == 0)
1822
{
1823
force_pointer_size = 4;
1824
raw_linker_arg = 1;
1825
}
1826
else if (strcmp("-m64", args.str[i]) == 0)
1827
{
1828
force_pointer_size = 8;
1829
raw_linker_arg = 1;
1830
}
1831
else if (!strcmp("-marm", args.str[i] ) || !strcmp("-mthumb", args.str[i] ))
1832
{
1833
raw_linker_arg = 1;
1834
}
1835
else if (!strcmp("-marm64x", args.str[i] ))
1836
{
1837
is_arm64x = true;
1838
raw_linker_arg = 1;
1839
}
1840
else if (!strncmp("-mcpu=", args.str[i], 6) ||
1841
!strncmp("-mfpu=", args.str[i], 6) ||
1842
!strncmp("-march=", args.str[i], 7))
1843
raw_winebuild_arg = 1;
1844
break;
1845
case 'n':
1846
if (strcmp("-nostdinc", args.str[i]) == 0)
1847
nostdinc = true;
1848
else if (strcmp("-nodefaultlibs", args.str[i]) == 0)
1849
nodefaultlibs = true;
1850
else if (strcmp("-nostdlib", args.str[i]) == 0)
1851
nostdlib = true;
1852
else if (strcmp("-nostartfiles", args.str[i]) == 0)
1853
nostartfiles = true;
1854
break;
1855
case 'o':
1856
output = option_arg;
1857
raw_compiler_arg = 0;
1858
break;
1859
case 'p':
1860
if (strcmp("-pthread", args.str[i]) == 0)
1861
{
1862
raw_compiler_arg = 1;
1863
raw_linker_arg = 1;
1864
}
1865
break;
1866
case 's':
1867
if (strcmp("-static", args.str[i]) == 0)
1868
is_static = true;
1869
else if(strcmp("-save-temps", args.str[i]) == 0)
1870
keep_generated = 1;
1871
else if (strncmp("-specs=", args.str[i], 7) == 0)
1872
raw_linker_arg = 1;
1873
else if(strcmp("-shared", args.str[i]) == 0)
1874
{
1875
is_shared = true;
1876
raw_compiler_arg = raw_linker_arg = 0;
1877
}
1878
else if (strcmp("-s", args.str[i]) == 0)
1879
{
1880
strip = true;
1881
raw_linker_arg = 0;
1882
}
1883
break;
1884
case 't':
1885
if (is_option( args, i, "-target", &option_arg ))
1886
{
1887
target_alias = option_arg;
1888
raw_compiler_arg = raw_linker_arg = 0;
1889
}
1890
break;
1891
case 'v':
1892
if (args.str[i][2] == 0)
1893
{
1894
verbose++;
1895
raw_compiler_arg = raw_linker_arg = 0;
1896
}
1897
break;
1898
case 'W':
1899
if (strncmp("-Wl,", args.str[i], 4) == 0)
1900
{
1901
unsigned int j;
1902
struct strarray Wl = strarray_fromstring(args.str[i] + 4, ",");
1903
for (j = 0; j < Wl.count; j++)
1904
{
1905
if (!strcmp(Wl.str[j], "--image-base") && j < Wl.count - 1)
1906
{
1907
image_base = xstrdup( Wl.str[++j] );
1908
continue;
1909
}
1910
if (!strcmp(Wl.str[j], "--section-alignment") && j < Wl.count - 1)
1911
{
1912
section_align = xstrdup( Wl.str[++j] );
1913
continue;
1914
}
1915
if (!strcmp(Wl.str[j], "--file-alignment") && j < Wl.count - 1)
1916
{
1917
file_align = xstrdup( Wl.str[++j] );
1918
continue;
1919
}
1920
if (!strcmp(Wl.str[j], "--large-address-aware"))
1921
{
1922
large_address_aware = true;
1923
continue;
1924
}
1925
if (!strcmp(Wl.str[j], "--wine-builtin"))
1926
{
1927
wine_builtin = true;
1928
continue;
1929
}
1930
if (!strcmp(Wl.str[j], "--subsystem") && j < Wl.count - 1)
1931
{
1932
subsystem = xstrdup( Wl.str[++j] );
1933
continue;
1934
}
1935
if (!strcmp(Wl.str[j], "--entry") && j < Wl.count - 1)
1936
{
1937
entry_point = xstrdup( Wl.str[++j] );
1938
continue;
1939
}
1940
if (!strcmp(Wl.str[j], "-delayload") && j < Wl.count - 1)
1941
{
1942
strarray_add( &delayimports, Wl.str[++j] );
1943
continue;
1944
}
1945
if (!strcmp(Wl.str[j], "--debug-file") && j < Wl.count - 1)
1946
{
1947
strarray_add( &output_debug_files, xstrdup( Wl.str[++j] ));
1948
continue;
1949
}
1950
if (!strcmp(Wl.str[j], "--whole-archive") ||
1951
!strcmp(Wl.str[j], "--no-whole-archive") ||
1952
!strcmp(Wl.str[j], "--start-group") ||
1953
!strcmp(Wl.str[j], "--end-group"))
1954
{
1955
strarray_add( &file_args, strmake( "-Wl,%s", Wl.str[j] ));
1956
continue;
1957
}
1958
if (!strcmp(Wl.str[j], "--out-implib"))
1959
{
1960
output_implib = xstrdup( Wl.str[++j] );
1961
continue;
1962
}
1963
if (!strcmp( Wl.str[j], "--build-id" ))
1964
{
1965
use_build_id = true;
1966
continue;
1967
}
1968
if (!strcmp(Wl.str[j], "-static")) is_static = true;
1969
strarray_add(&linker_args, strmake("-Wl,%s",Wl.str[j]));
1970
}
1971
raw_compiler_arg = raw_linker_arg = 0;
1972
}
1973
else if (strncmp("-Wb,", args.str[i], 4) == 0)
1974
{
1975
unsigned int j;
1976
struct strarray Wb = strarray_fromstring(args.str[i] + 4, ",");
1977
for (j = 0; j < Wb.count; j++)
1978
{
1979
if (!strcmp(Wb.str[j], "--data-only")) data_only = true;
1980
if (!strcmp(Wb.str[j], "--fake-module")) fake_module = true;
1981
else strarray_add( &winebuild_args, Wb.str[j] );
1982
}
1983
raw_compiler_arg = raw_linker_arg = 0;
1984
}
1985
break;
1986
case 'x':
1987
strarray_add(&file_args, args.str[i]);
1988
/* we'll pass these flags ourselves, explicitly */
1989
raw_compiler_arg = raw_linker_arg = 0;
1990
break;
1991
case '-':
1992
if (strcmp("-static", args.str[i]+1) == 0)
1993
is_static = true;
1994
else if (!strcmp( "-no-default-config", args.str[i] + 1 ))
1995
{
1996
no_default_config = true;
1997
raw_compiler_arg = raw_linker_arg = 1;
1998
}
1999
else if (is_option( args, i, "--sysroot", &option_arg ))
2000
{
2001
sysroot = option_arg;
2002
raw_linker_arg = 1;
2003
}
2004
else if (is_option( args, i, "--target", &option_arg ))
2005
{
2006
target_alias = option_arg;
2007
raw_compiler_arg = raw_linker_arg = 0;
2008
}
2009
else if (is_option( args, i, "--wine-objdir", &option_arg ))
2010
{
2011
wine_objdir = option_arg;
2012
raw_compiler_arg = raw_linker_arg = 0;
2013
}
2014
else if (is_option( args, i, "--winebuild", &option_arg ))
2015
{
2016
winebuild = option_arg;
2017
raw_compiler_arg = raw_linker_arg = 0;
2018
}
2019
else if (is_option( args, i, "--lib-suffix", &option_arg ))
2020
{
2021
lib_suffix = option_arg;
2022
raw_compiler_arg = raw_linker_arg = 0;
2023
}
2024
break;
2025
}
2026
2027
/* put the arg into the appropriate bucket */
2028
if (raw_linker_arg)
2029
{
2030
strarray_add( &linker_args, args.str[i] );
2031
if (next_is_arg && (i + 1 < args.count))
2032
strarray_add( &linker_args, args.str[i + 1] );
2033
}
2034
if (raw_compiler_arg)
2035
{
2036
strarray_add( &compiler_args, args.str[i] );
2037
if (next_is_arg && (i + 1 < args.count))
2038
strarray_add( &compiler_args, args.str[i + 1] );
2039
}
2040
if (raw_winebuild_arg)
2041
{
2042
strarray_add( &winebuild_args, args.str[i] );
2043
if (next_is_arg && (i + 1 < args.count))
2044
strarray_add( &winebuild_args, args.str[i + 1] );
2045
}
2046
2047
/* skip the next token if it's an argument */
2048
if (next_is_arg) i++;
2049
}
2050
else
2051
{
2052
strarray_add( &file_args, args.str[i] );
2053
}
2054
}
2055
2056
if (target_alias && !parse_target( target_alias, &target ))
2057
error( "Invalid target specification '%s'\n", target_alias );
2058
if (force_pointer_size) set_target_ptr_size( &target, force_pointer_size );
2059
2060
if (processor == proc_cpp) skip_link = true;
2061
2062
is_pe = is_pe_target( target );
2063
if (is_pe) use_msvcrt = true;
2064
if (output && strendswith( output, ".fake" )) fake_module = true;
2065
2066
if (!section_align)
2067
section_align = (target.cpu == CPU_ARM64 || target.cpu == CPU_ARM64EC) ? "0x10000" : "0x1000";
2068
2069
if (!file_align) file_align = section_align;
2070
2071
if (!is_pe && target.cpu != CPU_i386 && target.cpu != CPU_x86_64)
2072
error( "Non-PE builds are not supported on this platform. You need to use something like '--target=%s-windows'.\n",
2073
target.cpu == CPU_ARM ? "arm" : "aarch64" );
2074
2075
if (!winebuild)
2076
{
2077
if (wine_objdir) winebuild = strmake( "%s/tools/winebuild/winebuild%s", wine_objdir, EXEEXT );
2078
else if (!(winebuild = getenv( "WINEBUILD" )))
2079
{
2080
if (bindir) winebuild = strmake( "%s/winebuild%s", bindir, EXEEXT );
2081
else winebuild = "winebuild";
2082
}
2083
}
2084
if (file_args.count == 0 && !fake_module) forward();
2085
else if (!skip_link && !compile_only) build(file_args, output);
2086
else compile(file_args, output, compile_only);
2087
2088
output_file_name = NULL;
2089
output_debug_files.count = 0;
2090
output_implib = NULL;
2091
return 0;
2092
}
2093
2094