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
21 ORDDEF *EntryPoints[MAX_ORDINALS];
22 ORDDEF *Ordinals[MAX_ORDINALS];
23 ORDDEF *Names[MAX_ORDINALS];
25 SPEC_MODE SpecMode = SPEC_MODE_DLL;
26 int Base = MAX_ORDINALS;
31 int nb_entry_points = 0;
33 int nb_debug_channels = 0;
36 /* we only support relay debugging on i386 */
37 #if defined(__i386__) && !defined(NO_TRACE_MSGS)
46 char *init_func = NULL;
47 char **debug_channels = NULL;
48 char **lib_path = NULL;
50 const char *input_file_name;
51 const char *output_file_name;
53 static FILE *input_file;
54 static FILE *output_file;
57 static enum { MODE_NONE, MODE_SPEC, MODE_GLUE, MODE_RELAY } exec_mode = MODE_NONE;
59 /* open the input file */
60 static void open_input( const char *name )
62 input_file_name = name;
63 if (!(input_file = fopen( name, "r" )))
65 fprintf( stderr, "Cannot open input file '%s'\n", name );
70 /* cleanup on program exit */
71 static void cleanup(void)
73 if (output_file_name) unlink( output_file_name );
77 /*******************************************************************
78 * command-line option handling
89 static void do_pic(void);
90 static void do_output( const char *arg );
91 static void do_usage(void);
92 static void do_spec( const char *arg );
93 static void do_glue( const char *arg );
94 static void do_relay(void);
95 static void do_sym( const char *arg );
96 static void do_lib( const char *arg );
98 static const struct option_descr option_table[] =
100 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
101 { "-h", 0, do_usage, "-h Display this help message" },
102 { "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
103 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
104 { "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
105 { "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
106 { "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
107 { "-relay", 0, do_relay, "-relay Build the relay assembly routines" },
108 { NULL, 0, NULL, NULL }
111 static void do_pic(void)
116 static void do_output( const char *arg )
118 if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
120 fprintf ( stderr, "Unable to create output file '%s'\n", arg );
123 if (!(output_file = fopen( arg, "w" )))
125 fprintf( stderr, "Unable to create output file '%s'\n", arg );
128 output_file_name = arg;
129 atexit( cleanup ); /* make sure we remove the output file on exit */
132 static void do_usage(void)
134 const struct option_descr *opt;
135 fprintf( stderr, "Usage: winebuild [options]\n\n" );
136 fprintf( stderr, "Options:\n" );
137 for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
138 fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
142 static void do_spec( const char *arg )
144 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
145 exec_mode = MODE_SPEC;
149 static void do_glue( const char *arg )
151 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
152 exec_mode = MODE_GLUE;
156 static void do_relay(void)
158 if (exec_mode != MODE_NONE) do_usage();
159 exec_mode = MODE_RELAY;
162 static void do_sym( const char *arg )
164 extern void read_undef_symbols( const char *name );
165 read_undef_symbols( arg );
168 static void do_lib( const char *arg )
170 lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
171 lib_path[nb_lib_paths++] = xstrdup( arg );
174 /* parse options from the argv array and remove all the recognized ones */
175 static void parse_options( char *argv[] )
177 const struct option_descr *opt;
179 const char* arg=NULL;
184 for (opt = option_table; opt->name; opt++)
186 if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
188 arg=*ptr+strlen(opt->name);
196 if (!strcmp( *ptr, opt->name ))
205 fprintf( stderr, "Unrecognized option '%s'\n", *ptr );
209 if (opt->has_arg && arg!=NULL) opt->func( arg );
210 else opt->func( "" );
216 /*******************************************************************
219 int main(int argc, char **argv)
221 output_file = stdout;
222 parse_options( argv );
227 switch (ParseTopLevel( input_file ))
230 BuildSpec16File( output_file );
233 BuildSpec32File( output_file );
239 BuildGlue( output_file, input_file );
242 BuildRelays( output_file );
248 if (output_file_name)
250 fclose( output_file );
251 output_file_name = NULL;