Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winebuild/main.c
8669 views
1
/*
2
* Main function
3
*
4
* Copyright 1993 Robert J. Amstadt
5
* Copyright 1995 Martin von Loewis
6
* Copyright 1995, 1996, 1997 Alexandre Julliard
7
* Copyright 1997 Eric Youngdale
8
* Copyright 1999 Ulrich Weigand
9
*
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later version.
14
*
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
19
*
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23
*/
24
25
#include "config.h"
26
27
#include <assert.h>
28
#include <stdio.h>
29
#include <errno.h>
30
#include <string.h>
31
#include <stdarg.h>
32
#include <ctype.h>
33
34
#include "build.h"
35
36
int UsePIC = 0;
37
int nb_errors = 0;
38
int display_warnings = 0;
39
int native_arch = -1;
40
int kill_at = 0;
41
int verbose = 0;
42
int link_ext_symbols = 0;
43
int force_pointer_size = 0;
44
int unwind_tables = 0;
45
int use_dlltool = 1;
46
int use_msvcrt = 0;
47
int safe_seh = 0;
48
int prefer_native = 0;
49
int data_only = 0;
50
51
struct target target = { 0 };
52
53
char *target_alias = NULL;
54
55
char *input_file_name = NULL;
56
char *spec_file_name = NULL;
57
FILE *output_file = NULL;
58
const char *output_file_name = NULL;
59
static int save_temps;
60
static int fake_module;
61
static DLLSPEC *main_spec;
62
63
static const struct strarray empty_strarray;
64
struct strarray tools_path = { 0 };
65
struct strarray as_command = { 0 };
66
struct strarray cc_command = { 0 };
67
struct strarray ld_command = { 0 };
68
struct strarray nm_command = { 0 };
69
struct strarray strip_command = { 0 };
70
char *cpu_option = NULL;
71
char *fpu_option = NULL;
72
char *arch_option = NULL;
73
74
static struct strarray res_files;
75
76
/* execution mode */
77
enum exec_mode_values
78
{
79
MODE_NONE,
80
MODE_DLL,
81
MODE_EXE,
82
MODE_DEF,
83
MODE_IMPLIB,
84
MODE_STATICLIB,
85
MODE_BUILTIN,
86
MODE_FIXUP_CTORS,
87
MODE_RESOURCES
88
};
89
90
static enum exec_mode_values exec_mode = MODE_NONE;
91
92
93
/* set the dll file name from the input file name */
94
static void set_dll_file_name( const char *name, DLLSPEC *spec )
95
{
96
char *p;
97
98
if (spec->file_name) return;
99
100
name = get_basename( name );
101
spec->file_name = xmalloc( strlen(name) + 5 );
102
strcpy( spec->file_name, name );
103
if ((p = strrchr( spec->file_name, '.' )))
104
{
105
if (!strcmp( p, ".spec" ) || !strcmp( p, ".def" )) *p = 0;
106
}
107
}
108
109
/* set the dll name from the file name */
110
static void init_dll_name( DLLSPEC *spec )
111
{
112
if (!spec->file_name && output_file_name)
113
{
114
char *p;
115
spec->file_name = xstrdup( output_file_name );
116
if ((p = strrchr( spec->file_name, '.' ))) *p = 0;
117
}
118
if (!spec->dll_name && spec->file_name) /* set default name from file name */
119
{
120
char *p;
121
spec->dll_name = xstrdup( spec->file_name );
122
if ((p = strrchr( spec->dll_name, '.' ))) *p = 0;
123
}
124
if (spec->dll_name) spec->c_name = make_c_identifier( spec->dll_name );
125
}
126
127
/* set the dll subsystem */
128
static void set_subsystem( const char *subsystem, DLLSPEC *spec )
129
{
130
char *major, *minor, *str = xstrdup( subsystem );
131
132
if ((major = strchr( str, ':' ))) *major++ = 0;
133
if (!strcmp( str, "native" )) spec->subsystem = IMAGE_SUBSYSTEM_NATIVE;
134
else if (!strcmp( str, "windows" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
135
else if (!strcmp( str, "console" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
136
else if (!strcmp( str, "wince" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CE_GUI;
137
else if (!strcmp( str, "win16" )) spec->type = SPEC_WIN16;
138
else fatal_error( "Invalid subsystem name '%s'\n", subsystem );
139
if (major)
140
{
141
if ((minor = strchr( major, '.' )))
142
{
143
*minor++ = 0;
144
spec->subsystem_minor = atoi( minor );
145
}
146
spec->subsystem_major = atoi( major );
147
}
148
free( str );
149
}
150
151
/* set the target CPU and platform */
152
static void set_target( const char *name )
153
{
154
target_alias = xstrdup( name );
155
156
if (!parse_target( name, &target )) fatal_error( "Unrecognized target '%s'\n", name );
157
if (is_pe()) unwind_tables = 1;
158
}
159
160
/* cleanup on program exit */
161
static void cleanup(void)
162
{
163
if (output_file_name) unlink( output_file_name );
164
if (!save_temps) remove_temp_files();
165
}
166
167
/* clean things up when aborting on a signal */
168
static void exit_on_signal( int sig )
169
{
170
exit(1); /* this will call atexit functions */
171
}
172
173
/*******************************************************************
174
* command-line option handling
175
*/
176
static const char usage_str[] =
177
"Usage: winebuild [OPTIONS] [FILES]\n\n"
178
"Options:\n"
179
" --as-cmd=AS Command to use for assembling (default: as)\n"
180
" -b, --target=TARGET Specify target CPU and platform for cross-compiling\n"
181
" -B PREFIX Look for build tools in the PREFIX directory\n"
182
" --cc-cmd=CC C compiler to use for assembling (default: fall back to --as-cmd)\n"
183
" --data-only Generate a data-only dll (i.e. without any executable code)\n"
184
" -d, --delay-lib=LIB Import the specified library in delayed mode\n"
185
" -D SYM Ignored for C flags compatibility\n"
186
" --disable-dynamicbase Disable 'ASLR' address space layout randomization (default: ASLR on)\n"
187
" -e, --entry=FUNC Set the DLL entry point function (default: DllMain)\n"
188
" -E, --export=FILE Export the symbols defined in the .spec or .def file\n"
189
" --external-symbols Allow linking to external symbols\n"
190
" -f FLAGS Compiler flags (-fPIC and -fasynchronous-unwind-tables are supported)\n"
191
" -F, --filename=DLLFILE Set the DLL filename (default: from input file name)\n"
192
" --fake-module Create a fake binary module\n"
193
" -h, --help Display this help message\n"
194
" -H, --heap=SIZE Set the heap size for a Win16 dll\n"
195
" -I DIR Ignored for C flags compatibility\n"
196
" -k, --kill-at Kill stdcall decorations in generated .def files\n"
197
" -K, FLAGS Compiler flags (only -KPIC is supported)\n"
198
" --large-address-aware Support an address space larger than 2Gb\n"
199
" --ld-cmd=LD Command to use for linking (default: ld)\n"
200
" -m16, -m32, -m64 Force building 16-bit, 32-bit resp. 64-bit code\n"
201
" -M, --main-module=MODULE Set the name of the main module for a Win16 dll\n"
202
" --nm-cmd=NM Command to use to get undefined symbols (default: nm)\n"
203
" --nxcompat=y|n Set the NX compatibility flag (default: yes)\n"
204
" -N, --dll-name=DLLNAME Set the DLL name (default: from input file name)\n"
205
" -o, --output=NAME Set the output file name (default: stdout)\n"
206
" --prefer-native Set the flag to prefer loading native at run time\n"
207
" -r, --res=RSRC.RES Load resources from RSRC.RES\n"
208
" --safeseh Mark object files as SEH compatible\n"
209
" --save-temps Do not delete the generated intermediate files\n"
210
" --strip-cmd=STRIP Command to use for stripping (default: none)\n"
211
" --subsystem=SUBSYS Set the subsystem (one of native, windows, console, wince)\n"
212
" -u, --undefined=SYMBOL Add an undefined reference to SYMBOL when linking\n"
213
" -v, --verbose Display the programs invoked\n"
214
" --version Print the version and exit\n"
215
" -w, --warnings Turn on warnings\n"
216
" --without-dlltool Generate import library without using dlltool\n"
217
"\nMode options:\n"
218
" --dll Build a library from a .spec file and object files\n"
219
" --def Build a .def file from a .spec file\n"
220
" --exe Build an executable from object files\n"
221
" --implib Build an import library\n"
222
" --staticlib Build a static library\n"
223
" --resources Build a .o or .res file for the resource files\n\n"
224
" --builtin Mark a library as a Wine builtin\n"
225
" --fixup-ctors Fixup the constructors data after the module has been built\n"
226
"The mode options are mutually exclusive; you must specify one and only one.\n\n";
227
228
enum long_options_values
229
{
230
LONG_OPT_DLL = 1,
231
LONG_OPT_DEF,
232
LONG_OPT_EXE,
233
LONG_OPT_IMPLIB,
234
LONG_OPT_BUILTIN,
235
LONG_OPT_ASCMD,
236
LONG_OPT_CCCMD,
237
LONG_OPT_DATA_ONLY,
238
LONG_OPT_DISABLE_DYNAMICBASE,
239
LONG_OPT_EXTERNAL_SYMS,
240
LONG_OPT_FAKE_MODULE,
241
LONG_OPT_FIXUP_CTORS,
242
LONG_OPT_LARGE_ADDRESS_AWARE,
243
LONG_OPT_LDCMD,
244
LONG_OPT_NMCMD,
245
LONG_OPT_NXCOMPAT,
246
LONG_OPT_PREFER_NATIVE,
247
LONG_OPT_RESOURCES,
248
LONG_OPT_SAFE_SEH,
249
LONG_OPT_SAVE_TEMPS,
250
LONG_OPT_STATICLIB,
251
LONG_OPT_STRIPCMD,
252
LONG_OPT_SUBSYSTEM,
253
LONG_OPT_VERSION,
254
LONG_OPT_WITHOUT_DLLTOOL,
255
};
256
257
static const char short_options[] = "B:C:D:E:F:H:I:K:L:M:N:b:d:e:f:hkl:m:o:r:u:vw";
258
259
static const struct long_option long_options[] =
260
{
261
/* mode options */
262
{ "dll", 0, LONG_OPT_DLL },
263
{ "def", 0, LONG_OPT_DEF },
264
{ "exe", 0, LONG_OPT_EXE },
265
{ "implib", 0, LONG_OPT_IMPLIB },
266
{ "staticlib", 0, LONG_OPT_STATICLIB },
267
{ "builtin", 0, LONG_OPT_BUILTIN },
268
{ "resources", 0, LONG_OPT_RESOURCES },
269
{ "fixup-ctors", 0, LONG_OPT_FIXUP_CTORS },
270
/* other long options */
271
{ "as-cmd", 1, LONG_OPT_ASCMD },
272
{ "cc-cmd", 1, LONG_OPT_CCCMD },
273
{ "data-only", 0, LONG_OPT_DATA_ONLY },
274
{ "disable-dynamicbase", 0, LONG_OPT_DISABLE_DYNAMICBASE },
275
{ "external-symbols", 0, LONG_OPT_EXTERNAL_SYMS },
276
{ "fake-module", 0, LONG_OPT_FAKE_MODULE },
277
{ "large-address-aware", 0, LONG_OPT_LARGE_ADDRESS_AWARE },
278
{ "ld-cmd", 1, LONG_OPT_LDCMD },
279
{ "nm-cmd", 1, LONG_OPT_NMCMD },
280
{ "nxcompat", 1, LONG_OPT_NXCOMPAT },
281
{ "prefer-native", 0, LONG_OPT_PREFER_NATIVE },
282
{ "safeseh", 0, LONG_OPT_SAFE_SEH },
283
{ "save-temps", 0, LONG_OPT_SAVE_TEMPS },
284
{ "strip-cmd", 1, LONG_OPT_STRIPCMD },
285
{ "subsystem", 1, LONG_OPT_SUBSYSTEM },
286
{ "version", 0, LONG_OPT_VERSION },
287
{ "without-dlltool", 0, LONG_OPT_WITHOUT_DLLTOOL },
288
/* aliases for short options */
289
{ "target", 1, 'b' },
290
{ "delay-lib", 1, 'd' },
291
{ "export", 1, 'E' },
292
{ "entry", 1, 'e' },
293
{ "filename", 1, 'F' },
294
{ "help", 0, 'h' },
295
{ "heap", 1, 'H' },
296
{ "kill-at", 0, 'k' },
297
{ "main-module", 1, 'M' },
298
{ "dll-name", 1, 'N' },
299
{ "output", 1, 'o' },
300
{ "res", 1, 'r' },
301
{ "undefined", 1, 'u' },
302
{ "verbose", 0, 'v' },
303
{ "warnings", 0, 'w' },
304
{ NULL }
305
};
306
307
static void usage( int exit_code )
308
{
309
fprintf( stderr, "%s", usage_str );
310
exit( exit_code );
311
}
312
313
static void set_exec_mode( enum exec_mode_values mode )
314
{
315
if (exec_mode != MODE_NONE) usage(1);
316
exec_mode = mode;
317
}
318
319
/* get the default entry point for a given spec file */
320
static const char *get_default_entry_point( const DLLSPEC *spec )
321
{
322
if (spec->characteristics & IMAGE_FILE_DLL)
323
{
324
add_spec_extra_ld_symbol("DllMain");
325
return "__wine_spec_dll_entry";
326
}
327
if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) return "DriverEntry";
328
if (spec->type == SPEC_WIN16)
329
{
330
add_spec_extra_ld_symbol("WinMain16");
331
return "__wine_spec_exe16_entry";
332
}
333
else if (spec->unicode_app)
334
{
335
/* __wine_spec_exe_wentry always calls wmain */
336
add_spec_extra_ld_symbol("wmain");
337
if (spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
338
add_spec_extra_ld_symbol("wWinMain");
339
return "__wine_spec_exe_wentry";
340
}
341
else
342
{
343
/* __wine_spec_exe_entry always calls main */
344
add_spec_extra_ld_symbol("main");
345
if (spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
346
add_spec_extra_ld_symbol("WinMain");
347
return "__wine_spec_exe_entry";
348
}
349
}
350
351
static void option_callback( int optc, char *optarg )
352
{
353
char *p;
354
355
switch (optc)
356
{
357
case 'B':
358
strarray_add( &tools_path, xstrdup( optarg ));
359
break;
360
case 'D':
361
/* ignored */
362
break;
363
case 'E':
364
spec_file_name = xstrdup( optarg );
365
set_dll_file_name( optarg, main_spec );
366
break;
367
case 'F':
368
main_spec->file_name = xstrdup( optarg );
369
break;
370
case 'H':
371
if (!isdigit(optarg[0]))
372
fatal_error( "Expected number argument with -H option instead of '%s'\n", optarg );
373
main_spec->heap_size = atoi(optarg);
374
if (main_spec->heap_size > 65535)
375
fatal_error( "Invalid heap size %d, maximum is 65535\n", main_spec->heap_size );
376
break;
377
case 'I':
378
/* ignored */
379
break;
380
case 'K':
381
/* ignored, because cc generates correct code. */
382
break;
383
case 'm':
384
if (!strcmp( optarg, "16" )) main_spec->type = SPEC_WIN16;
385
else if (!strcmp( optarg, "32" )) force_pointer_size = 4;
386
else if (!strcmp( optarg, "64" )) force_pointer_size = 8;
387
else if (!strcmp( optarg, "no-cygwin" )) use_msvcrt = 1;
388
else if (!strcmp( optarg, "unicode" )) main_spec->unicode_app = 1;
389
else if (!strcmp( optarg, "arm64x" )) native_arch = CPU_ARM64;
390
else if (!strncmp( optarg, "cpu=", 4 )) cpu_option = xstrdup( optarg + 4 );
391
else if (!strncmp( optarg, "fpu=", 4 )) fpu_option = xstrdup( optarg + 4 );
392
else if (!strncmp( optarg, "arch=", 5 )) arch_option = xstrdup( optarg + 5 );
393
else fatal_error( "Unknown -m option '%s'\n", optarg );
394
break;
395
case 'M':
396
main_spec->main_module = xstrdup( optarg );
397
break;
398
case 'N':
399
main_spec->dll_name = xstrdup( optarg );
400
break;
401
case 'b':
402
set_target( optarg );
403
break;
404
case 'd':
405
add_delayed_import( optarg );
406
break;
407
case 'e':
408
main_spec->init_func = xstrdup( optarg );
409
if ((p = strchr( main_spec->init_func, '@' ))) *p = 0; /* kill stdcall decoration */
410
break;
411
case 'f':
412
if (!strcmp( optarg, "PIC") || !strcmp( optarg, "pic")) UsePIC = 1;
413
else if (!strcmp( optarg, "asynchronous-unwind-tables")) unwind_tables = 1;
414
else if (!strcmp( optarg, "no-asynchronous-unwind-tables")) unwind_tables = 0;
415
/* ignore all other flags */
416
break;
417
case 'h':
418
usage(0);
419
break;
420
case 'k':
421
kill_at = 1;
422
break;
423
case 'o':
424
if (unlink( optarg ) == -1 && errno != ENOENT)
425
fatal_error( "Unable to create output file '%s'\n", optarg );
426
output_file_name = xstrdup( optarg );
427
break;
428
case 'r':
429
strarray_add( &res_files, xstrdup( optarg ));
430
break;
431
case 'u':
432
add_extra_ld_symbol( optarg );
433
break;
434
case 'v':
435
verbose++;
436
break;
437
case 'w':
438
display_warnings = 1;
439
break;
440
case LONG_OPT_DLL:
441
set_exec_mode( MODE_DLL );
442
break;
443
case LONG_OPT_DEF:
444
set_exec_mode( MODE_DEF );
445
break;
446
case LONG_OPT_DISABLE_DYNAMICBASE:
447
main_spec->dll_characteristics &= ~IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
448
break;
449
case LONG_OPT_EXE:
450
set_exec_mode( MODE_EXE );
451
if (!main_spec->subsystem) main_spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
452
break;
453
case LONG_OPT_IMPLIB:
454
set_exec_mode( MODE_IMPLIB );
455
break;
456
case LONG_OPT_STATICLIB:
457
set_exec_mode( MODE_STATICLIB );
458
break;
459
case LONG_OPT_BUILTIN:
460
set_exec_mode( MODE_BUILTIN );
461
break;
462
case LONG_OPT_FIXUP_CTORS:
463
set_exec_mode( MODE_FIXUP_CTORS );
464
break;
465
case LONG_OPT_ASCMD:
466
as_command = strarray_fromstring( optarg, " " );
467
break;
468
case LONG_OPT_CCCMD:
469
cc_command = strarray_fromstring( optarg, " " );
470
break;
471
case LONG_OPT_DATA_ONLY:
472
data_only = 1;
473
break;
474
case LONG_OPT_FAKE_MODULE:
475
fake_module = 1;
476
break;
477
case LONG_OPT_EXTERNAL_SYMS:
478
link_ext_symbols = 1;
479
break;
480
case LONG_OPT_LARGE_ADDRESS_AWARE:
481
main_spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
482
break;
483
case LONG_OPT_LDCMD:
484
ld_command = strarray_fromstring( optarg, " " );
485
break;
486
case LONG_OPT_NMCMD:
487
nm_command = strarray_fromstring( optarg, " " );
488
break;
489
case LONG_OPT_NXCOMPAT:
490
if (optarg[0] == 'n' || optarg[0] == 'N')
491
main_spec->dll_characteristics &= ~IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
492
break;
493
case LONG_OPT_SAFE_SEH:
494
safe_seh = 1;
495
break;
496
case LONG_OPT_PREFER_NATIVE:
497
prefer_native = 1;
498
main_spec->dll_characteristics |= IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE;
499
break;
500
case LONG_OPT_RESOURCES:
501
set_exec_mode( MODE_RESOURCES );
502
break;
503
case LONG_OPT_SAVE_TEMPS:
504
save_temps = 1;
505
break;
506
case LONG_OPT_STRIPCMD:
507
strip_command = strarray_fromstring( optarg, " " );
508
break;
509
case LONG_OPT_SUBSYSTEM:
510
set_subsystem( optarg, main_spec );
511
break;
512
case LONG_OPT_VERSION:
513
printf( "winebuild version " PACKAGE_VERSION "\n" );
514
exit(0);
515
case LONG_OPT_WITHOUT_DLLTOOL:
516
use_dlltool = 0;
517
break;
518
case '?':
519
fprintf( stderr, "winebuild: %s\n\n", optarg );
520
usage(1);
521
break;
522
}
523
}
524
525
526
/* load all specified resource files */
527
static struct strarray load_resources( struct strarray files, DLLSPEC *spec )
528
{
529
struct strarray ret = empty_strarray;
530
531
switch (spec->type)
532
{
533
case SPEC_WIN16:
534
STRARRAY_FOR_EACH( file, &res_files ) load_res16_file( file, spec );
535
return files;
536
537
case SPEC_WIN32:
538
STRARRAY_FOR_EACH( file, &res_files )
539
if (!load_res32_file( file, spec ))
540
fatal_error( "%s is not a valid Win32 resource file\n", file );
541
542
/* load any resource file found in the remaining arguments */
543
STRARRAY_FOR_EACH( file, &files )
544
if (!load_res32_file( file, spec ))
545
strarray_add( &ret, file ); /* not a resource file, keep it in the list */
546
break;
547
}
548
return ret;
549
}
550
551
static int parse_input_file( DLLSPEC *spec )
552
{
553
FILE *input_file = open_input_file( NULL, spec_file_name );
554
int result;
555
556
spec->src_name = xstrdup( input_file_name );
557
if (strendswith( spec_file_name, ".def" ))
558
result = parse_def_file( input_file, spec );
559
else
560
result = parse_spec_file( input_file, spec );
561
close_input_file( input_file );
562
return result;
563
}
564
565
static void check_target(void)
566
{
567
if (is_pe()) return;
568
if (target.cpu == CPU_i386 || target.cpu == CPU_x86_64) return;
569
fatal_error( "Non-PE builds are not supported on this platform.\n" );
570
}
571
572
/*******************************************************************
573
* main
574
*/
575
int main(int argc, char **argv)
576
{
577
struct strarray files;
578
DLLSPEC *spec = main_spec = alloc_dll_spec();
579
580
init_signals( exit_on_signal );
581
target = init_argv0_target( argv[0] );
582
if (target.platform == PLATFORM_CYGWIN) target.platform = PLATFORM_MINGW;
583
if (is_pe()) unwind_tables = 1;
584
585
files = parse_options( argc, argv, short_options, long_options, 0, option_callback );
586
587
atexit( cleanup ); /* make sure we remove the output file on exit */
588
589
if (spec->file_name && !strchr( spec->file_name, '.' ))
590
strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
591
init_dll_name( spec );
592
593
if (force_pointer_size) set_target_ptr_size( &target, force_pointer_size );
594
595
switch(exec_mode)
596
{
597
case MODE_DLL:
598
if (spec->subsystem != IMAGE_SUBSYSTEM_NATIVE)
599
spec->characteristics |= IMAGE_FILE_DLL;
600
/* fall through */
601
case MODE_EXE:
602
if (get_ptr_size() == 4)
603
{
604
spec->characteristics |= IMAGE_FILE_32BIT_MACHINE;
605
}
606
else
607
{
608
spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
609
if (spec->dll_characteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE)
610
spec->dll_characteristics |= IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA;
611
}
612
613
check_target();
614
files = load_resources( files, spec );
615
if (spec_file_name && !parse_input_file( spec )) break;
616
if (!spec->init_func) spec->init_func = xstrdup( get_default_entry_point( spec ));
617
618
if (fake_module)
619
{
620
output_fake_module( spec );
621
break;
622
}
623
if (data_only)
624
{
625
output_data_module( spec );
626
break;
627
}
628
if (!is_pe())
629
{
630
read_undef_symbols( spec, files );
631
resolve_imports( spec );
632
}
633
if (spec->type == SPEC_WIN16) output_spec16_file( spec );
634
else output_spec32_file( spec );
635
break;
636
case MODE_DEF:
637
if (files.count) fatal_error( "file argument '%s' not allowed in this mode\n", files.str[0] );
638
if (!spec_file_name) fatal_error( "missing .spec file\n" );
639
if (!parse_input_file( spec )) break;
640
open_output_file();
641
output_def_file( spec, &spec->exports, 0 );
642
close_output_file();
643
break;
644
case MODE_IMPLIB:
645
check_target();
646
if (!spec_file_name) fatal_error( "missing .spec file\n" );
647
if (!parse_input_file( spec )) break;
648
output_import_lib( spec, files );
649
break;
650
case MODE_STATICLIB:
651
output_static_lib( output_file_name, files, 1 );
652
break;
653
case MODE_BUILTIN:
654
if (!files.count) fatal_error( "missing file argument for --builtin option\n" );
655
make_builtin_files( files );
656
break;
657
case MODE_FIXUP_CTORS:
658
if (!files.count) fatal_error( "missing file argument for --fixup-ctors option\n" );
659
fixup_constructors( files );
660
break;
661
case MODE_RESOURCES:
662
files = load_resources( files, spec );
663
output_res_o_file( spec );
664
break;
665
default:
666
usage(1);
667
break;
668
}
669
if (nb_errors) exit(1);
670
output_file_name = NULL;
671
return 0;
672
}
673
674