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