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