wined3d: Handle stateblock capture for default lights created while recording.
[wine] / tools / winebuild / main.c
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 #include "wine/port.h"
27
28 #include <assert.h>
29 #include <stdio.h>
30 #include <signal.h>
31 #include <errno.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <ctype.h>
35 #ifdef HAVE_GETOPT_H
36 # include <getopt.h>
37 #endif
38
39 #include "build.h"
40
41 int UsePIC = 0;
42 int nb_lib_paths = 0;
43 int nb_errors = 0;
44 int display_warnings = 0;
45 int kill_at = 0;
46 int verbose = 0;
47 int save_temps = 0;
48 int link_ext_symbols = 0;
49 int force_pointer_size = 0;
50
51 #ifdef __i386__
52 enum target_cpu target_cpu = CPU_x86;
53 #elif defined(__x86_64__)
54 enum target_cpu target_cpu = CPU_x86_64;
55 #elif defined(__sparc__)
56 enum target_cpu target_cpu = CPU_SPARC;
57 #elif defined(__ALPHA__)
58 enum target_cpu target_cpu = CPU_ALPHA;
59 #elif defined(__powerpc__)
60 enum target_cpu target_cpu = CPU_POWERPC;
61 #elif defined(__arm__)
62 enum target_cpu target_cpu = CPU_ARM;
63 #else
64 #error Unsupported CPU
65 #endif
66
67 #ifdef __APPLE__
68 enum target_platform target_platform = PLATFORM_APPLE;
69 #elif defined(__FreeBSD__)
70 enum target_platform target_platform = PLATFORM_FREEBSD;
71 #elif defined(__sun)
72 enum target_platform target_platform = PLATFORM_SOLARIS;
73 #elif defined(_WIN32)
74 enum target_platform target_platform = PLATFORM_WINDOWS;
75 #else
76 enum target_platform target_platform = PLATFORM_UNSPECIFIED;
77 #endif
78
79 char *target_alias = NULL;
80 char **lib_path = NULL;
81
82 char *input_file_name = NULL;
83 char *spec_file_name = NULL;
84 FILE *output_file = NULL;
85 const char *output_file_name = NULL;
86 static const char *output_file_source_name;
87 static int fake_module;
88
89 char *as_command = NULL;
90 char *ld_command = NULL;
91 char *nm_command = NULL;
92
93 static int nb_res_files;
94 static char **res_files;
95
96 /* execution mode */
97 enum exec_mode_values
98 {
99     MODE_NONE,
100     MODE_DLL,
101     MODE_EXE,
102     MODE_DEF,
103     MODE_IMPLIB,
104     MODE_RELAY16,
105     MODE_RELAY32,
106     MODE_RESOURCES
107 };
108
109 static enum exec_mode_values exec_mode = MODE_NONE;
110
111 static const struct
112 {
113     const char *name;
114     enum target_platform platform;
115 } platform_names[] =
116 {
117     { "macos",   PLATFORM_APPLE },
118     { "darwin",  PLATFORM_APPLE },
119     { "freebsd", PLATFORM_FREEBSD },
120     { "solaris", PLATFORM_SOLARIS },
121     { "mingw32", PLATFORM_WINDOWS },
122     { "windows", PLATFORM_WINDOWS },
123     { "winnt",   PLATFORM_WINDOWS }
124 };
125
126 /* set the dll file name from the input file name */
127 static void set_dll_file_name( const char *name, DLLSPEC *spec )
128 {
129     char *p;
130
131     if (spec->file_name) return;
132
133     if ((p = strrchr( name, '\\' ))) name = p + 1;
134     if ((p = strrchr( name, '/' ))) name = p + 1;
135     spec->file_name = xmalloc( strlen(name) + 5 );
136     strcpy( spec->file_name, name );
137     if ((p = strrchr( spec->file_name, '.' )))
138     {
139         if (!strcmp( p, ".spec" ) || !strcmp( p, ".def" )) *p = 0;
140     }
141 }
142
143 /* set the dll name from the file name */
144 static void init_dll_name( DLLSPEC *spec )
145 {
146     if (!spec->file_name)
147     {
148         char *p;
149         spec->file_name = xstrdup( output_file_name );
150         if ((p = strrchr( spec->file_name, '.' ))) *p = 0;
151     }
152     if (!spec->dll_name)  /* set default name from file name */
153     {
154         char *p;
155         spec->dll_name = xstrdup( spec->file_name );
156         if ((p = strrchr( spec->dll_name, '.' ))) *p = 0;
157     }
158 }
159
160 /* set the dll subsystem */
161 static void set_subsystem( const char *subsystem, DLLSPEC *spec )
162 {
163     char *major, *minor, *str = xstrdup( subsystem );
164
165     if ((major = strchr( str, ':' ))) *major++ = 0;
166     if (!strcmp( str, "native" )) spec->subsystem = IMAGE_SUBSYSTEM_NATIVE;
167     else if (!strcmp( str, "windows" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
168     else if (!strcmp( str, "console" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
169     else if (!strcmp( str, "win16" )) spec->type = SPEC_WIN16;
170     else fatal_error( "Invalid subsystem name '%s'\n", subsystem );
171     if (major)
172     {
173         if ((minor = strchr( major, '.' )))
174         {
175             *minor++ = 0;
176             spec->subsystem_minor = atoi( minor );
177         }
178         spec->subsystem_major = atoi( major );
179     }
180     free( str );
181 }
182
183 /* set the target CPU and platform */
184 static void set_target( const char *target )
185 {
186     unsigned int i;
187     char *p, *platform, *spec = xstrdup( target );
188
189     /* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
190
191     target_alias = xstrdup( target );
192
193     /* get the CPU part */
194
195     if (!(p = strchr( spec, '-' ))) fatal_error( "Invalid target specification '%s'\n", target );
196     *p++ = 0;
197     if ((target_cpu = get_cpu_from_name( spec )) == -1)
198         fatal_error( "Unrecognized CPU '%s'\n", spec );
199     platform = p;
200     if ((p = strrchr( p, '-' ))) platform = p + 1;
201
202     /* get the OS part */
203
204     target_platform = PLATFORM_UNSPECIFIED;  /* default value */
205     for (i = 0; i < sizeof(platform_names)/sizeof(platform_names[0]); i++)
206     {
207         if (!strncmp( platform_names[i].name, platform, strlen(platform_names[i].name) ))
208         {
209             target_platform = platform_names[i].platform;
210             break;
211         }
212     }
213
214     free( spec );
215 }
216
217 /* cleanup on program exit */
218 static void cleanup(void)
219 {
220     if (output_file_name) unlink( output_file_name );
221 }
222
223 /* clean things up when aborting on a signal */
224 static void exit_on_signal( int sig )
225 {
226     exit(1);  /* this will call atexit functions */
227 }
228
229 /*******************************************************************
230  *         command-line option handling
231  */
232 static const char usage_str[] =
233 "Usage: winebuild [OPTIONS] [FILES]\n\n"
234 "Options:\n"
235 "       --as-cmd=AS           Command to use for assembling (default: as)\n"
236 "   -b, --target=TARGET       Specify target CPU and platform for cross-compiling\n"
237 "   -d, --delay-lib=LIB       Import the specified library in delayed mode\n"
238 "   -D SYM                    Ignored for C flags compatibility\n"
239 "   -e, --entry=FUNC          Set the DLL entry point function (default: DllMain)\n"
240 "   -E, --export=FILE         Export the symbols defined in the .spec or .def file\n"
241 "       --external-symbols    Allow linking to external symbols\n"
242 "   -f FLAGS                  Compiler flags (only -fPIC is supported)\n"
243 "   -F, --filename=DLLFILE    Set the DLL filename (default: from input file name)\n"
244 "       --fake-module         Create a fake binary module\n"
245 "   -h, --help                Display this help message\n"
246 "   -H, --heap=SIZE           Set the heap size for a Win16 dll\n"
247 "   -i, --ignore=SYM[,SYM]    Ignore specified symbols when resolving imports\n"
248 "   -I DIR                    Ignored for C flags compatibility\n"
249 "   -k, --kill-at             Kill stdcall decorations in generated .def files\n"
250 "   -K, FLAGS                 Compiler flags (only -KPIC is supported)\n"
251 "       --large-address-aware Support an address space larger than 2Gb\n"
252 "       --ld-cmd=LD           Command to use for linking (default: ld)\n"
253 "   -l, --library=LIB         Import the specified library\n"
254 "   -L, --library-path=DIR    Look for imports libraries in DIR\n"
255 "   -m32, -m64                Force building 32-bit resp. 64-bit code\n"
256 "   -M, --main-module=MODULE  Set the name of the main module for a Win16 dll\n"
257 "       --nm-cmd=NM           Command to use to get undefined symbols (default: nm)\n"
258 "       --nxcompat=y|n        Set the NX compatibility flag (default: yes)\n"
259 "   -N, --dll-name=DLLNAME    Set the DLL name (default: from input file name)\n"
260 "   -o, --output=NAME         Set the output file name (default: stdout)\n"
261 "   -r, --res=RSRC.RES        Load resources from RSRC.RES\n"
262 "       --save-temps          Do not delete the generated intermediate files\n"
263 "       --subsystem=SUBSYS    Set the subsystem (one of native, windows, console)\n"
264 "   -u, --undefined=SYMBOL    Add an undefined reference to SYMBOL when linking\n"
265 "   -v, --verbose             Display the programs invoked\n"
266 "       --version             Print the version and exit\n"
267 "   -w, --warnings            Turn on warnings\n"
268 "\nMode options:\n"
269 "       --dll                 Build a .c file from a .spec or .def file\n"
270 "       --def                 Build a .def file from a .spec file\n"
271 "       --exe                 Build a .c file for an executable\n"
272 "       --implib              Build an import library\n"
273 "       --relay16             Build the 16-bit relay assembly routines\n"
274 "       --relay32             Build the 32-bit relay assembly routines\n"
275 "       --resources           Build a .o file for the resource files\n\n"
276 "The mode options are mutually exclusive; you must specify one and only one.\n\n";
277
278 enum long_options_values
279 {
280     LONG_OPT_DLL = 1,
281     LONG_OPT_DEF,
282     LONG_OPT_EXE,
283     LONG_OPT_IMPLIB,
284     LONG_OPT_ASCMD,
285     LONG_OPT_EXTERNAL_SYMS,
286     LONG_OPT_FAKE_MODULE,
287     LONG_OPT_LARGE_ADDRESS_AWARE,
288     LONG_OPT_LDCMD,
289     LONG_OPT_NMCMD,
290     LONG_OPT_NXCOMPAT,
291     LONG_OPT_RELAY16,
292     LONG_OPT_RELAY32,
293     LONG_OPT_RESOURCES,
294     LONG_OPT_SAVE_TEMPS,
295     LONG_OPT_SUBSYSTEM,
296     LONG_OPT_VERSION
297 };
298
299 static const char short_options[] = "C:D:E:F:H:I:K:L:M:N:b:d:e:f:hi:kl:m:o:r:u:vw";
300
301 static const struct option long_options[] =
302 {
303     { "dll",           0, 0, LONG_OPT_DLL },
304     { "def",           0, 0, LONG_OPT_DEF },
305     { "exe",           0, 0, LONG_OPT_EXE },
306     { "implib",        0, 0, LONG_OPT_IMPLIB },
307     { "as-cmd",        1, 0, LONG_OPT_ASCMD },
308     { "external-symbols", 0, 0, LONG_OPT_EXTERNAL_SYMS },
309     { "fake-module",   0, 0, LONG_OPT_FAKE_MODULE },
310     { "large-address-aware", 0, 0, LONG_OPT_LARGE_ADDRESS_AWARE },
311     { "ld-cmd",        1, 0, LONG_OPT_LDCMD },
312     { "nm-cmd",        1, 0, LONG_OPT_NMCMD },
313     { "nxcompat",      1, 0, LONG_OPT_NXCOMPAT },
314     { "relay16",       0, 0, LONG_OPT_RELAY16 },
315     { "relay32",       0, 0, LONG_OPT_RELAY32 },
316     { "resources",     0, 0, LONG_OPT_RESOURCES },
317     { "save-temps",    0, 0, LONG_OPT_SAVE_TEMPS },
318     { "subsystem",     1, 0, LONG_OPT_SUBSYSTEM },
319     { "version",       0, 0, LONG_OPT_VERSION },
320     /* aliases for short options */
321     { "target",        1, 0, 'b' },
322     { "delay-lib",     1, 0, 'd' },
323     { "export",        1, 0, 'E' },
324     { "entry",         1, 0, 'e' },
325     { "filename",      1, 0, 'F' },
326     { "help",          0, 0, 'h' },
327     { "heap",          1, 0, 'H' },
328     { "ignore",        1, 0, 'i' },
329     { "kill-at",       0, 0, 'k' },
330     { "library",       1, 0, 'l' },
331     { "library-path",  1, 0, 'L' },
332     { "main-module",   1, 0, 'M' },
333     { "dll-name",      1, 0, 'N' },
334     { "output",        1, 0, 'o' },
335     { "res",           1, 0, 'r' },
336     { "undefined",     1, 0, 'u' },
337     { "verbose",       0, 0, 'v' },
338     { "warnings",      0, 0, 'w' },
339     { NULL,            0, 0, 0 }
340 };
341
342 static void usage( int exit_code )
343 {
344     fprintf( stderr, "%s", usage_str );
345     exit( exit_code );
346 }
347
348 static void set_exec_mode( enum exec_mode_values mode )
349 {
350     if (exec_mode != MODE_NONE) usage(1);
351     exec_mode = mode;
352 }
353
354 /* parse options from the argv array and remove all the recognized ones */
355 static char **parse_options( int argc, char **argv, DLLSPEC *spec )
356 {
357     char *p;
358     int optc;
359
360     while ((optc = getopt_long( argc, argv, short_options, long_options, NULL )) != -1)
361     {
362         switch(optc)
363         {
364         case 'D':
365             /* ignored */
366             break;
367         case 'E':
368             spec_file_name = xstrdup( optarg );
369             set_dll_file_name( optarg, spec );
370             break;
371         case 'F':
372             spec->file_name = xstrdup( optarg );
373             break;
374         case 'H':
375             if (!isdigit(optarg[0]))
376                 fatal_error( "Expected number argument with -H option instead of '%s'\n", optarg );
377             spec->heap_size = atoi(optarg);
378             if (spec->heap_size > 65535)
379                 fatal_error( "Invalid heap size %d, maximum is 65535\n", spec->heap_size );
380             break;
381         case 'I':
382             /* ignored */
383             break;
384         case 'K':
385             /* ignored, because cc generates correct code. */
386             break;
387         case 'L':
388             lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
389             lib_path[nb_lib_paths++] = xstrdup( optarg );
390             break;
391         case 'm':
392             if (strcmp( optarg, "32" ) && strcmp( optarg, "64" ))
393                 fatal_error( "Invalid -m option '%s', expected -m32 or -m64\n", optarg );
394             if (!strcmp( optarg, "32" )) force_pointer_size = 4;
395             else force_pointer_size = 8;
396             break;
397         case 'M':
398             spec->main_module = xstrdup( optarg );
399             break;
400         case 'N':
401             spec->dll_name = xstrdup( optarg );
402             break;
403         case 'b':
404             set_target( optarg );
405             break;
406         case 'd':
407             add_delayed_import( optarg );
408             break;
409         case 'e':
410             spec->init_func = xstrdup( optarg );
411             if ((p = strchr( spec->init_func, '@' ))) *p = 0;  /* kill stdcall decoration */
412             break;
413         case 'f':
414             if (!strcmp( optarg, "PIC") || !strcmp( optarg, "pic")) UsePIC = 1;
415             /* ignore all other flags */
416             break;
417         case 'h':
418             usage(0);
419             break;
420         case 'i':
421             {
422                 char *str = xstrdup( optarg );
423                 char *token = strtok( str, "," );
424                 while (token)
425                 {
426                     add_ignore_symbol( token );
427                     token = strtok( NULL, "," );
428                 }
429                 free( str );
430             }
431             break;
432         case 'k':
433             kill_at = 1;
434             break;
435         case 'l':
436             add_import_dll( optarg, NULL );
437             break;
438         case 'o':
439             {
440                 char *ext = strrchr( optarg, '.' );
441
442                 if (unlink( optarg ) == -1 && errno != ENOENT)
443                     fatal_error( "Unable to create output file '%s'\n", optarg );
444                 if (ext && !strcmp( ext, ".o" ))
445                 {
446                     output_file_source_name = get_temp_file_name( optarg, ".s" );
447                     if (!(output_file = fopen( output_file_source_name, "w" )))
448                         fatal_error( "Unable to create output file '%s'\n", optarg );
449                 }
450                 else
451                 {
452                     if (!(output_file = fopen( optarg, "w" )))
453                         fatal_error( "Unable to create output file '%s'\n", optarg );
454                 }
455                 output_file_name = xstrdup(optarg);
456                 atexit( cleanup );  /* make sure we remove the output file on exit */
457             }
458             break;
459         case 'r':
460             res_files = xrealloc( res_files, (nb_res_files+1) * sizeof(*res_files) );
461             res_files[nb_res_files++] = xstrdup( optarg );
462             break;
463         case 'u':
464             add_extra_ld_symbol( optarg );
465             break;
466         case 'v':
467             verbose++;
468             break;
469         case 'w':
470             display_warnings = 1;
471             break;
472         case LONG_OPT_DLL:
473             set_exec_mode( MODE_DLL );
474             break;
475         case LONG_OPT_DEF:
476             set_exec_mode( MODE_DEF );
477             break;
478         case LONG_OPT_EXE:
479             set_exec_mode( MODE_EXE );
480             if (!spec->subsystem) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
481             break;
482         case LONG_OPT_IMPLIB:
483             set_exec_mode( MODE_IMPLIB );
484             break;
485         case LONG_OPT_ASCMD:
486             as_command = xstrdup( optarg );
487             break;
488         case LONG_OPT_FAKE_MODULE:
489             fake_module = 1;
490             break;
491         case LONG_OPT_EXTERNAL_SYMS:
492             link_ext_symbols = 1;
493             break;
494         case LONG_OPT_LARGE_ADDRESS_AWARE:
495             spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
496             break;
497         case LONG_OPT_LDCMD:
498             ld_command = xstrdup( optarg );
499             break;
500         case LONG_OPT_NMCMD:
501             nm_command = xstrdup( optarg );
502             break;
503         case LONG_OPT_NXCOMPAT:
504             if (optarg[0] == 'n' || optarg[0] == 'N')
505                 spec->dll_characteristics &= ~IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
506             break;
507         case LONG_OPT_RELAY16:
508             set_exec_mode( MODE_RELAY16 );
509             break;
510         case LONG_OPT_RELAY32:
511             set_exec_mode( MODE_RELAY32 );
512             break;
513         case LONG_OPT_RESOURCES:
514             set_exec_mode( MODE_RESOURCES );
515             break;
516         case LONG_OPT_SAVE_TEMPS:
517             save_temps = 1;
518             break;
519         case LONG_OPT_SUBSYSTEM:
520             set_subsystem( optarg, spec );
521             break;
522         case LONG_OPT_VERSION:
523             printf( "winebuild version " PACKAGE_VERSION "\n" );
524             exit(0);
525         case '?':
526             usage(1);
527             break;
528         }
529     }
530
531     if (spec->file_name && !strchr( spec->file_name, '.' ))
532         strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
533     init_dll_name( spec );
534
535     switch (target_cpu)
536     {
537     case CPU_x86:
538         if (force_pointer_size == 8) target_cpu = CPU_x86_64;
539         break;
540     case CPU_x86_64:
541         if (force_pointer_size == 4) target_cpu = CPU_x86;
542         break;
543     default:
544         if (force_pointer_size == 8)
545             fatal_error( "Cannot build 64-bit code for this CPU\n" );
546         break;
547     }
548
549     return &argv[optind];
550 }
551
552
553 /* load all specified resource files */
554 static void load_resources( char *argv[], DLLSPEC *spec )
555 {
556     int i;
557     char **ptr, **last;
558
559     switch (spec->type)
560     {
561     case SPEC_WIN16:
562         for (i = 0; i < nb_res_files; i++) load_res16_file( res_files[i], spec );
563         break;
564
565     case SPEC_WIN32:
566         for (i = 0; i < nb_res_files; i++)
567         {
568             if (!load_res32_file( res_files[i], spec ))
569                 fatal_error( "%s is not a valid Win32 resource file\n", res_files[i] );
570         }
571
572         /* load any resource file found in the remaining arguments */
573         for (ptr = last = argv; *ptr; ptr++)
574         {
575             if (!load_res32_file( *ptr, spec ))
576                 *last++ = *ptr; /* not a resource file, keep it in the list */
577         }
578         *last = NULL;
579         break;
580     }
581 }
582
583 /* add input files that look like import libs to the import list */
584 static void load_import_libs( char *argv[] )
585 {
586     char **ptr, **last;
587
588     for (ptr = last = argv; *ptr; ptr++)
589     {
590         if (strendswith( *ptr, ".def" ))
591             add_import_dll( NULL, *ptr );
592         else
593             *last++ = *ptr; /* not an import dll, keep it in the list */
594     }
595     *last = NULL;
596 }
597
598 static int parse_input_file( DLLSPEC *spec )
599 {
600     FILE *input_file = open_input_file( NULL, spec_file_name );
601     char *extension = strrchr( spec_file_name, '.' );
602     int result;
603
604     spec->src_name = xstrdup( input_file_name );
605     if (extension && !strcmp( extension, ".def" ))
606         result = parse_def_file( input_file, spec );
607     else
608         result = parse_spec_file( input_file, spec );
609     close_input_file( input_file );
610     return result;
611 }
612
613
614 /*******************************************************************
615  *         main
616  */
617 int main(int argc, char **argv)
618 {
619     DLLSPEC *spec = alloc_dll_spec();
620
621 #ifdef SIGHUP
622     signal( SIGHUP, exit_on_signal );
623 #endif
624     signal( SIGTERM, exit_on_signal );
625     signal( SIGINT, exit_on_signal );
626
627     output_file = stdout;
628     argv = parse_options( argc, argv, spec );
629
630     switch(exec_mode)
631     {
632     case MODE_DLL:
633         if (spec->subsystem != IMAGE_SUBSYSTEM_NATIVE)
634             spec->characteristics |= IMAGE_FILE_DLL;
635         if (!spec_file_name) fatal_error( "missing .spec file\n" );
636         /* fall through */
637     case MODE_EXE:
638         load_resources( argv, spec );
639         load_import_libs( argv );
640         if (spec_file_name && !parse_input_file( spec )) break;
641         if (fake_module)
642         {
643             if (spec->type == SPEC_WIN16) output_fake_module16( spec );
644             else output_fake_module( spec );
645             break;
646         }
647         read_undef_symbols( spec, argv );
648         switch (spec->type)
649         {
650             case SPEC_WIN16:
651                 output_spec16_file( spec );
652                 break;
653             case SPEC_WIN32:
654                 BuildSpec32File( spec );
655                 break;
656             default: assert(0);
657         }
658         break;
659     case MODE_DEF:
660         if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
661         if (!spec_file_name) fatal_error( "missing .spec file\n" );
662         if (!parse_input_file( spec )) break;
663         output_def_file( spec, 1 );
664         break;
665     case MODE_IMPLIB:
666         if (!spec_file_name) fatal_error( "missing .spec file\n" );
667         if (!parse_input_file( spec )) break;
668         output_import_lib( spec, argv );
669         break;
670     case MODE_RELAY16:
671         if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
672         BuildRelays16();
673         break;
674     case MODE_RELAY32:
675         if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
676         BuildRelays32();
677         break;
678     case MODE_RESOURCES:
679         load_resources( argv, spec );
680         output_res_o_file( spec );
681         break;
682     default:
683         usage(1);
684         break;
685     }
686     if (nb_errors) exit(1);
687     if (output_file_name)
688     {
689         if (fclose( output_file ) < 0) fatal_perror( "fclose" );
690         if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
691         output_file_name = NULL;
692     }
693     return 0;
694 }