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
20 ORDDEF EntryPoints[MAX_ORDINALS];
21 ORDDEF *Ordinals[MAX_ORDINALS];
22 ORDDEF *Names[MAX_ORDINALS];
24 SPEC_MODE SpecMode = SPEC_MODE_DLL;
25 int Base = MAX_ORDINALS;
29 int nb_entry_points = 0;
32 int nb_debug_channels = 0;
39 char **debug_channels = NULL;
40 char **lib_path = NULL;
42 const char *input_file_name;
43 const char *output_file_name;
45 static FILE *input_file;
46 static FILE *output_file;
49 static enum { MODE_NONE, MODE_SPEC, MODE_GLUE, MODE_RELAY } exec_mode = MODE_NONE;
51 /* open the input file */
52 static void open_input( const char *name )
54 input_file_name = name;
55 if (!(input_file = fopen( name, "r" )))
57 fprintf( stderr, "Cannot open input file '%s'\n", name );
62 /* cleanup on program exit */
63 static void cleanup(void)
65 if (output_file_name) unlink( output_file_name );
69 /*******************************************************************
70 * command-line option handling
81 static void do_pic(void);
82 static void do_output( const char *arg );
83 static void do_usage(void);
84 static void do_spec( const char *arg );
85 static void do_glue( const char *arg );
86 static void do_relay(void);
87 static void do_sym( const char *arg );
88 static void do_lib( const char *arg );
90 static const struct option option_table[] =
92 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
93 { "-h", 0, do_usage, "-h Display this help message" },
94 { "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
95 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
96 { "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
97 { "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
98 { "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
99 { "-relay", 0, do_relay, "-relay Build the relay assembly routines" },
100 { NULL, 0, NULL, NULL }
103 static void do_pic(void)
108 static void do_output( const char *arg )
110 if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
112 fprintf ( stderr, "Unable to create output file '%s'\n", arg );
115 if (!(output_file = fopen( arg, "w" )))
117 fprintf( stderr, "Unable to create output file '%s'\n", arg );
120 output_file_name = arg;
121 atexit( cleanup ); /* make sure we remove the output file on exit */
124 static void do_usage(void)
126 const struct option *opt;
127 fprintf( stderr, "Usage: winebuild [options]\n\n" );
128 fprintf( stderr, "Options:\n" );
129 for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
130 fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
134 static void do_spec( const char *arg )
136 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
137 exec_mode = MODE_SPEC;
141 static void do_glue( const char *arg )
143 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
144 exec_mode = MODE_GLUE;
148 static void do_relay(void)
150 if (exec_mode != MODE_NONE) do_usage();
151 exec_mode = MODE_RELAY;
154 static void do_sym( const char *arg )
156 extern void read_undef_symbols( const char *name );
157 read_undef_symbols( arg );
160 static void do_lib( const char *arg )
162 lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
163 lib_path[nb_lib_paths++] = xstrdup( arg );
166 /* parse options from the argv array and remove all the recognized ones */
167 static void parse_options( char *argv[] )
169 const struct option *opt;
172 for (i = 1; argv[i]; i++)
174 for (opt = option_table; opt->name; opt++)
175 if (!strcmp( argv[i], opt->name )) break;
179 fprintf( stderr, "Unrecognized option '%s'\n", argv[i] );
183 if (opt->has_arg && argv[i+1]) opt->func( argv[++i] );
184 else opt->func( "" );
189 /*******************************************************************
192 int main(int argc, char **argv)
194 output_file = stdout;
195 parse_options( argv );
200 switch (ParseTopLevel( input_file ))
203 BuildSpec16File( output_file );
206 BuildSpec32File( output_file, !resolve_imports( output_file ) );
212 BuildGlue( output_file, input_file );
215 BuildRelays( output_file );
221 fclose( output_file );
222 output_file_name = NULL;