dmime: Rename IDirectMusicSegment8Impl method prefix to segment.
[wine.git] / tools / winebuild / main.c
blobc5f5b56c20e01ee333337517bb6f73c64ef969ec
1 /*
2 * Main function
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
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.
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.
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
25 #include "config.h"
27 #include <assert.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <stdarg.h>
32 #include <ctype.h>
34 #include "build.h"
36 int UsePIC = 0;
37 int nb_errors = 0;
38 int display_warnings = 0;
39 int kill_at = 0;
40 int verbose = 0;
41 int link_ext_symbols = 0;
42 int force_pointer_size = 0;
43 int unwind_tables = 0;
44 int use_dlltool = 1;
45 int use_msvcrt = 0;
46 int safe_seh = 0;
47 int prefer_native = 0;
48 int data_only = 0;
50 struct target target = { 0 };
52 char *target_alias = NULL;
54 char *input_file_name = NULL;
55 char *spec_file_name = NULL;
56 FILE *output_file = NULL;
57 const char *output_file_name = NULL;
58 static int save_temps;
59 static int fake_module;
60 static DLLSPEC *main_spec;
62 static const struct strarray empty_strarray;
63 struct strarray lib_path = { 0 };
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 #ifdef __SOFTFP__
73 const char *float_abi_option = "soft";
74 #else
75 const char *float_abi_option = "softfp";
76 #endif
78 #ifdef __thumb__
79 int thumb_mode = 1;
80 #else
81 int thumb_mode = 0;
82 #endif
84 static struct strarray res_files;
86 /* execution mode */
87 enum exec_mode_values
89 MODE_NONE,
90 MODE_DLL,
91 MODE_EXE,
92 MODE_DEF,
93 MODE_IMPLIB,
94 MODE_STATICLIB,
95 MODE_BUILTIN,
96 MODE_FIXUP_CTORS,
97 MODE_RESOURCES
100 static enum exec_mode_values exec_mode = MODE_NONE;
103 /* set the dll file name from the input file name */
104 static void set_dll_file_name( const char *name, DLLSPEC *spec )
106 char *p;
108 if (spec->file_name) return;
110 name = get_basename( name );
111 spec->file_name = xmalloc( strlen(name) + 5 );
112 strcpy( spec->file_name, name );
113 if ((p = strrchr( spec->file_name, '.' )))
115 if (!strcmp( p, ".spec" ) || !strcmp( p, ".def" )) *p = 0;
119 /* set the dll name from the file name */
120 static void init_dll_name( DLLSPEC *spec )
122 if (!spec->file_name && output_file_name)
124 char *p;
125 spec->file_name = xstrdup( output_file_name );
126 if ((p = strrchr( spec->file_name, '.' ))) *p = 0;
128 if (!spec->dll_name && spec->file_name) /* set default name from file name */
130 char *p;
131 spec->dll_name = xstrdup( spec->file_name );
132 if ((p = strrchr( spec->dll_name, '.' ))) *p = 0;
134 if (spec->dll_name) spec->c_name = make_c_identifier( spec->dll_name );
137 /* set the dll subsystem */
138 static void set_subsystem( const char *subsystem, DLLSPEC *spec )
140 char *major, *minor, *str = xstrdup( subsystem );
142 if ((major = strchr( str, ':' ))) *major++ = 0;
143 if (!strcmp( str, "native" )) spec->subsystem = IMAGE_SUBSYSTEM_NATIVE;
144 else if (!strcmp( str, "windows" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
145 else if (!strcmp( str, "console" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
146 else if (!strcmp( str, "wince" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CE_GUI;
147 else if (!strcmp( str, "win16" )) spec->type = SPEC_WIN16;
148 else fatal_error( "Invalid subsystem name '%s'\n", subsystem );
149 if (major)
151 if ((minor = strchr( major, '.' )))
153 *minor++ = 0;
154 spec->subsystem_minor = atoi( minor );
156 spec->subsystem_major = atoi( major );
158 free( str );
161 /* set the syscall table id */
162 static void set_syscall_table( const char *id, DLLSPEC *spec )
164 int val = atoi( id );
166 if (val < 0 || val > 3) fatal_error( "Invalid syscall table id '%s', must be 0-3\n", id );
167 spec->syscall_table = val;
170 /* set the target CPU and platform */
171 static void set_target( const char *name )
173 target_alias = xstrdup( name );
175 if (!parse_target( name, &target )) fatal_error( "Unrecognized target '%s'\n", name );
176 thumb_mode = target.cpu == CPU_ARM && is_pe();
177 if (is_pe()) unwind_tables = 1;
180 /* cleanup on program exit */
181 static void cleanup(void)
183 if (output_file_name) unlink( output_file_name );
184 if (!save_temps) remove_temp_files();
187 /* clean things up when aborting on a signal */
188 static void exit_on_signal( int sig )
190 exit(1); /* this will call atexit functions */
193 /*******************************************************************
194 * command-line option handling
196 static const char usage_str[] =
197 "Usage: winebuild [OPTIONS] [FILES]\n\n"
198 "Options:\n"
199 " --as-cmd=AS Command to use for assembling (default: as)\n"
200 " -b, --target=TARGET Specify target CPU and platform for cross-compiling\n"
201 " -B PREFIX Look for build tools in the PREFIX directory\n"
202 " --cc-cmd=CC C compiler to use for assembling (default: fall back to --as-cmd)\n"
203 " --data-only Generate a data-only dll (i.e. without any executable code)\n"
204 " -d, --delay-lib=LIB Import the specified library in delayed mode\n"
205 " -D SYM Ignored for C flags compatibility\n"
206 " -e, --entry=FUNC Set the DLL entry point function (default: DllMain)\n"
207 " -E, --export=FILE Export the symbols defined in the .spec or .def file\n"
208 " --external-symbols Allow linking to external symbols\n"
209 " -f FLAGS Compiler flags (-fPIC and -fasynchronous-unwind-tables are supported)\n"
210 " -F, --filename=DLLFILE Set the DLL filename (default: from input file name)\n"
211 " --fake-module Create a fake binary module\n"
212 " -h, --help Display this help message\n"
213 " -H, --heap=SIZE Set the heap size for a Win16 dll\n"
214 " -I DIR Ignored for C flags compatibility\n"
215 " -k, --kill-at Kill stdcall decorations in generated .def files\n"
216 " -K, FLAGS Compiler flags (only -KPIC is supported)\n"
217 " --large-address-aware Support an address space larger than 2Gb\n"
218 " --ld-cmd=LD Command to use for linking (default: ld)\n"
219 " -l, --library=LIB Import the specified library\n"
220 " -L, --library-path=DIR Look for imports libraries in DIR\n"
221 " -m16, -m32, -m64 Force building 16-bit, 32-bit resp. 64-bit code\n"
222 " -M, --main-module=MODULE Set the name of the main module for a Win16 dll\n"
223 " --nm-cmd=NM Command to use to get undefined symbols (default: nm)\n"
224 " --nxcompat=y|n Set the NX compatibility flag (default: yes)\n"
225 " -N, --dll-name=DLLNAME Set the DLL name (default: from input file name)\n"
226 " -o, --output=NAME Set the output file name (default: stdout)\n"
227 " --prefer-native Set the flag to prefer loading native at run time\n"
228 " -r, --res=RSRC.RES Load resources from RSRC.RES\n"
229 " --safeseh Mark object files as SEH compatible\n"
230 " --save-temps Do not delete the generated intermediate files\n"
231 " --subsystem=SUBSYS Set the subsystem (one of native, windows, console, wince)\n"
232 " --syscall-table=ID Set the syscall table id (between 0 and 3)\n"
233 " -u, --undefined=SYMBOL Add an undefined reference to SYMBOL when linking\n"
234 " -v, --verbose Display the programs invoked\n"
235 " --version Print the version and exit\n"
236 " -w, --warnings Turn on warnings\n"
237 " --without-dlltool Generate import library without using dlltool\n"
238 "\nMode options:\n"
239 " --dll Build a library from a .spec file and object files\n"
240 " --def Build a .def file from a .spec file\n"
241 " --exe Build an executable from object files\n"
242 " --implib Build an import library\n"
243 " --staticlib Build a static library\n"
244 " --resources Build a .o or .res file for the resource files\n\n"
245 " --builtin Mark a library as a Wine builtin\n"
246 " --fixup-ctors Fixup the constructors data after the module has been built\n"
247 "The mode options are mutually exclusive; you must specify one and only one.\n\n";
249 enum long_options_values
251 LONG_OPT_DLL = 1,
252 LONG_OPT_DEF,
253 LONG_OPT_EXE,
254 LONG_OPT_IMPLIB,
255 LONG_OPT_BUILTIN,
256 LONG_OPT_ASCMD,
257 LONG_OPT_CCCMD,
258 LONG_OPT_DATA_ONLY,
259 LONG_OPT_EXTERNAL_SYMS,
260 LONG_OPT_FAKE_MODULE,
261 LONG_OPT_FIXUP_CTORS,
262 LONG_OPT_LARGE_ADDRESS_AWARE,
263 LONG_OPT_LDCMD,
264 LONG_OPT_NMCMD,
265 LONG_OPT_NXCOMPAT,
266 LONG_OPT_PREFER_NATIVE,
267 LONG_OPT_RESOURCES,
268 LONG_OPT_SAFE_SEH,
269 LONG_OPT_SAVE_TEMPS,
270 LONG_OPT_STATICLIB,
271 LONG_OPT_SUBSYSTEM,
272 LONG_OPT_SYSCALL_TABLE,
273 LONG_OPT_VERSION,
274 LONG_OPT_WITHOUT_DLLTOOL,
277 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";
279 static const struct long_option long_options[] =
281 /* mode options */
282 { "dll", 0, LONG_OPT_DLL },
283 { "def", 0, LONG_OPT_DEF },
284 { "exe", 0, LONG_OPT_EXE },
285 { "implib", 0, LONG_OPT_IMPLIB },
286 { "staticlib", 0, LONG_OPT_STATICLIB },
287 { "builtin", 0, LONG_OPT_BUILTIN },
288 { "resources", 0, LONG_OPT_RESOURCES },
289 { "fixup-ctors", 0, LONG_OPT_FIXUP_CTORS },
290 /* other long options */
291 { "as-cmd", 1, LONG_OPT_ASCMD },
292 { "cc-cmd", 1, LONG_OPT_CCCMD },
293 { "data-only", 0, LONG_OPT_DATA_ONLY },
294 { "external-symbols", 0, LONG_OPT_EXTERNAL_SYMS },
295 { "fake-module", 0, LONG_OPT_FAKE_MODULE },
296 { "large-address-aware", 0, LONG_OPT_LARGE_ADDRESS_AWARE },
297 { "ld-cmd", 1, LONG_OPT_LDCMD },
298 { "nm-cmd", 1, LONG_OPT_NMCMD },
299 { "nxcompat", 1, LONG_OPT_NXCOMPAT },
300 { "prefer-native", 0, LONG_OPT_PREFER_NATIVE },
301 { "safeseh", 0, LONG_OPT_SAFE_SEH },
302 { "save-temps", 0, LONG_OPT_SAVE_TEMPS },
303 { "subsystem", 1, LONG_OPT_SUBSYSTEM },
304 { "syscall-table", 1, LONG_OPT_SYSCALL_TABLE },
305 { "version", 0, LONG_OPT_VERSION },
306 { "without-dlltool", 0, LONG_OPT_WITHOUT_DLLTOOL },
307 /* aliases for short options */
308 { "target", 1, 'b' },
309 { "delay-lib", 1, 'd' },
310 { "export", 1, 'E' },
311 { "entry", 1, 'e' },
312 { "filename", 1, 'F' },
313 { "help", 0, 'h' },
314 { "heap", 1, 'H' },
315 { "kill-at", 0, 'k' },
316 { "library", 1, 'l' },
317 { "library-path", 1, 'L' },
318 { "main-module", 1, 'M' },
319 { "dll-name", 1, 'N' },
320 { "output", 1, 'o' },
321 { "res", 1, 'r' },
322 { "undefined", 1, 'u' },
323 { "verbose", 0, 'v' },
324 { "warnings", 0, 'w' },
325 { NULL }
328 static void usage( int exit_code )
330 fprintf( stderr, "%s", usage_str );
331 exit( exit_code );
334 static void set_exec_mode( enum exec_mode_values mode )
336 if (exec_mode != MODE_NONE) usage(1);
337 exec_mode = mode;
340 /* get the default entry point for a given spec file */
341 static const char *get_default_entry_point( const DLLSPEC *spec )
343 if (spec->characteristics & IMAGE_FILE_DLL)
345 add_spec_extra_ld_symbol("DllMain");
346 return "__wine_spec_dll_entry";
348 if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) return "DriverEntry";
349 if (spec->type == SPEC_WIN16)
351 add_spec_extra_ld_symbol("WinMain16");
352 return "__wine_spec_exe16_entry";
354 else if (spec->unicode_app)
356 /* __wine_spec_exe_wentry always calls wmain */
357 add_spec_extra_ld_symbol("wmain");
358 if (spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
359 add_spec_extra_ld_symbol("wWinMain");
360 return "__wine_spec_exe_wentry";
362 else
364 /* __wine_spec_exe_entry always calls main */
365 add_spec_extra_ld_symbol("main");
366 if (spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
367 add_spec_extra_ld_symbol("WinMain");
368 return "__wine_spec_exe_entry";
372 static void option_callback( int optc, char *optarg )
374 char *p;
376 switch (optc)
378 case 'B':
379 strarray_add( &tools_path, xstrdup( optarg ));
380 break;
381 case 'D':
382 /* ignored */
383 break;
384 case 'E':
385 spec_file_name = xstrdup( optarg );
386 set_dll_file_name( optarg, main_spec );
387 break;
388 case 'F':
389 main_spec->file_name = xstrdup( optarg );
390 break;
391 case 'H':
392 if (!isdigit(optarg[0]))
393 fatal_error( "Expected number argument with -H option instead of '%s'\n", optarg );
394 main_spec->heap_size = atoi(optarg);
395 if (main_spec->heap_size > 65535)
396 fatal_error( "Invalid heap size %d, maximum is 65535\n", main_spec->heap_size );
397 break;
398 case 'I':
399 /* ignored */
400 break;
401 case 'K':
402 /* ignored, because cc generates correct code. */
403 break;
404 case 'L':
405 strarray_add( &lib_path, xstrdup( optarg ));
406 break;
407 case 'm':
408 if (!strcmp( optarg, "16" )) main_spec->type = SPEC_WIN16;
409 else if (!strcmp( optarg, "32" )) force_pointer_size = 4;
410 else if (!strcmp( optarg, "64" )) force_pointer_size = 8;
411 else if (!strcmp( optarg, "arm" )) thumb_mode = 0;
412 else if (!strcmp( optarg, "thumb" )) thumb_mode = 1;
413 else if (!strcmp( optarg, "no-cygwin" )) use_msvcrt = 1;
414 else if (!strcmp( optarg, "unicode" )) main_spec->unicode_app = 1;
415 else if (!strncmp( optarg, "cpu=", 4 )) cpu_option = xstrdup( optarg + 4 );
416 else if (!strncmp( optarg, "fpu=", 4 )) fpu_option = xstrdup( optarg + 4 );
417 else if (!strncmp( optarg, "arch=", 5 )) arch_option = xstrdup( optarg + 5 );
418 else if (!strncmp( optarg, "float-abi=", 10 )) float_abi_option = xstrdup( optarg + 10 );
419 else fatal_error( "Unknown -m option '%s'\n", optarg );
420 break;
421 case 'M':
422 main_spec->main_module = xstrdup( optarg );
423 break;
424 case 'N':
425 main_spec->dll_name = xstrdup( optarg );
426 break;
427 case 'b':
428 set_target( optarg );
429 break;
430 case 'd':
431 add_delayed_import( optarg );
432 break;
433 case 'e':
434 main_spec->init_func = xstrdup( optarg );
435 if ((p = strchr( main_spec->init_func, '@' ))) *p = 0; /* kill stdcall decoration */
436 break;
437 case 'f':
438 if (!strcmp( optarg, "PIC") || !strcmp( optarg, "pic")) UsePIC = 1;
439 else if (!strcmp( optarg, "asynchronous-unwind-tables")) unwind_tables = 1;
440 else if (!strcmp( optarg, "no-asynchronous-unwind-tables")) unwind_tables = 0;
441 /* ignore all other flags */
442 break;
443 case 'h':
444 usage(0);
445 break;
446 case 'k':
447 kill_at = 1;
448 break;
449 case 'l':
450 add_import_dll( optarg, NULL );
451 break;
452 case 'o':
453 if (unlink( optarg ) == -1 && errno != ENOENT)
454 fatal_error( "Unable to create output file '%s'\n", optarg );
455 output_file_name = xstrdup( optarg );
456 break;
457 case 'r':
458 strarray_add( &res_files, xstrdup( optarg ));
459 break;
460 case 'u':
461 add_extra_ld_symbol( optarg );
462 break;
463 case 'v':
464 verbose++;
465 break;
466 case 'w':
467 display_warnings = 1;
468 break;
469 case LONG_OPT_DLL:
470 set_exec_mode( MODE_DLL );
471 break;
472 case LONG_OPT_DEF:
473 set_exec_mode( MODE_DEF );
474 break;
475 case LONG_OPT_EXE:
476 set_exec_mode( MODE_EXE );
477 if (!main_spec->subsystem) main_spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
478 break;
479 case LONG_OPT_IMPLIB:
480 set_exec_mode( MODE_IMPLIB );
481 break;
482 case LONG_OPT_STATICLIB:
483 set_exec_mode( MODE_STATICLIB );
484 break;
485 case LONG_OPT_BUILTIN:
486 set_exec_mode( MODE_BUILTIN );
487 break;
488 case LONG_OPT_FIXUP_CTORS:
489 set_exec_mode( MODE_FIXUP_CTORS );
490 break;
491 case LONG_OPT_ASCMD:
492 as_command = strarray_fromstring( optarg, " " );
493 break;
494 case LONG_OPT_CCCMD:
495 cc_command = strarray_fromstring( optarg, " " );
496 break;
497 case LONG_OPT_DATA_ONLY:
498 data_only = 1;
499 break;
500 case LONG_OPT_FAKE_MODULE:
501 fake_module = 1;
502 break;
503 case LONG_OPT_EXTERNAL_SYMS:
504 link_ext_symbols = 1;
505 break;
506 case LONG_OPT_LARGE_ADDRESS_AWARE:
507 main_spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
508 break;
509 case LONG_OPT_LDCMD:
510 ld_command = strarray_fromstring( optarg, " " );
511 break;
512 case LONG_OPT_NMCMD:
513 nm_command = strarray_fromstring( optarg, " " );
514 break;
515 case LONG_OPT_NXCOMPAT:
516 if (optarg[0] == 'n' || optarg[0] == 'N')
517 main_spec->dll_characteristics &= ~IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
518 break;
519 case LONG_OPT_SAFE_SEH:
520 safe_seh = 1;
521 break;
522 case LONG_OPT_PREFER_NATIVE:
523 prefer_native = 1;
524 main_spec->dll_characteristics |= IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE;
525 break;
526 case LONG_OPT_RESOURCES:
527 set_exec_mode( MODE_RESOURCES );
528 break;
529 case LONG_OPT_SAVE_TEMPS:
530 save_temps = 1;
531 break;
532 case LONG_OPT_SUBSYSTEM:
533 set_subsystem( optarg, main_spec );
534 break;
535 case LONG_OPT_SYSCALL_TABLE:
536 set_syscall_table( optarg, main_spec );
537 break;
538 case LONG_OPT_VERSION:
539 printf( "winebuild version " PACKAGE_VERSION "\n" );
540 exit(0);
541 case LONG_OPT_WITHOUT_DLLTOOL:
542 use_dlltool = 0;
543 break;
544 case '?':
545 fprintf( stderr, "winebuild: %s\n\n", optarg );
546 usage(1);
547 break;
552 /* load all specified resource files */
553 static struct strarray load_resources( struct strarray files, DLLSPEC *spec )
555 struct strarray ret = empty_strarray;
556 int i;
558 switch (spec->type)
560 case SPEC_WIN16:
561 for (i = 0; i < res_files.count; i++) load_res16_file( res_files.str[i], spec );
562 return files;
564 case SPEC_WIN32:
565 for (i = 0; i < res_files.count; i++)
567 if (!load_res32_file( res_files.str[i], spec ))
568 fatal_error( "%s is not a valid Win32 resource file\n", res_files.str[i] );
571 /* load any resource file found in the remaining arguments */
572 for (i = 0; i < files.count; i++)
574 if (!load_res32_file( files.str[i], spec ))
575 strarray_add( &ret, files.str[i] ); /* not a resource file, keep it in the list */
577 break;
579 return ret;
582 /* add input files that look like import libs to the import list */
583 static struct strarray load_import_libs( struct strarray files )
585 struct strarray ret = empty_strarray;
586 int i;
588 for (i = 0; i < files.count; i++)
590 if (strendswith( files.str[i], ".def" ))
591 add_import_dll( NULL, files.str[i] );
592 else
593 strarray_add( &ret, files.str[i] ); /* not an import dll, keep it in the list */
595 return ret;
598 static int parse_input_file( DLLSPEC *spec )
600 FILE *input_file = open_input_file( NULL, spec_file_name );
601 int result;
603 spec->src_name = xstrdup( input_file_name );
604 if (strendswith( spec_file_name, ".def" ))
605 result = parse_def_file( input_file, spec );
606 else
607 result = parse_spec_file( input_file, spec );
608 close_input_file( input_file );
609 return result;
613 /*******************************************************************
614 * main
616 int main(int argc, char **argv)
618 struct strarray files;
619 DLLSPEC *spec = main_spec = alloc_dll_spec();
621 init_signals( exit_on_signal );
622 target = init_argv0_target( argv[0] );
623 if (target.platform == PLATFORM_CYGWIN) target.platform = PLATFORM_MINGW;
624 if (is_pe()) unwind_tables = 1;
626 files = parse_options( argc, argv, short_options, long_options, 0, option_callback );
628 atexit( cleanup ); /* make sure we remove the output file on exit */
630 if (spec->file_name && !strchr( spec->file_name, '.' ))
631 strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
632 init_dll_name( spec );
634 if (force_pointer_size) set_target_ptr_size( &target, force_pointer_size );
636 switch(exec_mode)
638 case MODE_DLL:
639 if (spec->subsystem != IMAGE_SUBSYSTEM_NATIVE)
640 spec->characteristics |= IMAGE_FILE_DLL;
641 /* fall through */
642 case MODE_EXE:
643 if (get_ptr_size() == 4)
644 spec->characteristics |= IMAGE_FILE_32BIT_MACHINE;
645 else
646 spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
648 files = load_resources( files, spec );
649 if (spec_file_name && !parse_input_file( spec )) break;
650 if (!spec->init_func) spec->init_func = xstrdup( get_default_entry_point( spec ));
652 if (fake_module)
654 output_fake_module( spec );
655 break;
657 if (data_only)
659 output_data_module( spec );
660 break;
662 if (!is_pe())
664 files = load_import_libs( files );
665 read_undef_symbols( spec, files );
666 resolve_imports( spec );
668 if (spec->type == SPEC_WIN16) output_spec16_file( spec );
669 else output_spec32_file( spec );
670 break;
671 case MODE_DEF:
672 if (files.count) fatal_error( "file argument '%s' not allowed in this mode\n", files.str[0] );
673 if (!spec_file_name) fatal_error( "missing .spec file\n" );
674 if (!parse_input_file( spec )) break;
675 open_output_file();
676 output_def_file( spec, 0 );
677 close_output_file();
678 break;
679 case MODE_IMPLIB:
680 if (!spec_file_name) fatal_error( "missing .spec file\n" );
681 if (!parse_input_file( spec )) break;
682 output_import_lib( spec, files );
683 break;
684 case MODE_STATICLIB:
685 output_static_lib( output_file_name, files, 1 );
686 break;
687 case MODE_BUILTIN:
688 if (!files.count) fatal_error( "missing file argument for --builtin option\n" );
689 make_builtin_files( files );
690 break;
691 case MODE_FIXUP_CTORS:
692 if (!files.count) fatal_error( "missing file argument for --fixup-ctors option\n" );
693 fixup_constructors( files );
694 break;
695 case MODE_RESOURCES:
696 files = load_resources( files, spec );
697 output_res_o_file( spec );
698 break;
699 default:
700 usage(1);
701 break;
703 if (nb_errors) exit(1);
704 output_file_name = NULL;
705 return 0;