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;
30 int nb_entry_points = 0;
32 int nb_debug_channels = 0;
35 /* we only support relay debugging on i386 */
36 #if defined(__i386__) && !defined(NO_TRACE_MSGS)
45 char *init_func = NULL;
46 char **debug_channels = NULL;
47 char **lib_path = NULL;
49 const char *input_file_name;
50 const char *output_file_name;
52 static FILE *input_file;
53 static FILE *output_file;
56 static enum { MODE_NONE, MODE_SPEC, MODE_GLUE, MODE_RELAY } exec_mode = MODE_NONE;
58 /* open the input file */
59 static void open_input( const char *name )
61 input_file_name = name;
62 if (!(input_file = fopen( name, "r" )))
64 fprintf( stderr, "Cannot open input file '%s'\n", name );
69 /* cleanup on program exit */
70 static void cleanup(void)
72 if (output_file_name) unlink( output_file_name );
76 /*******************************************************************
77 * command-line option handling
88 static void do_pic(void);
89 static void do_output( const char *arg );
90 static void do_usage(void);
91 static void do_spec( const char *arg );
92 static void do_glue( const char *arg );
93 static void do_relay(void);
94 static void do_sym( const char *arg );
95 static void do_lib( const char *arg );
97 static const struct option_descr option_table[] =
99 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
100 { "-h", 0, do_usage, "-h Display this help message" },
101 { "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
102 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
103 { "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
104 { "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
105 { "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
106 { "-relay", 0, do_relay, "-relay Build the relay assembly routines" },
107 { NULL, 0, NULL, NULL }
110 static void do_pic(void)
115 static void do_output( const char *arg )
117 if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
119 fprintf ( stderr, "Unable to create output file '%s'\n", arg );
122 if (!(output_file = fopen( arg, "w" )))
124 fprintf( stderr, "Unable to create output file '%s'\n", arg );
127 output_file_name = arg;
128 atexit( cleanup ); /* make sure we remove the output file on exit */
131 static void do_usage(void)
133 const struct option_descr *opt;
134 fprintf( stderr, "Usage: winebuild [options]\n\n" );
135 fprintf( stderr, "Options:\n" );
136 for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
137 fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
141 static void do_spec( const char *arg )
143 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
144 exec_mode = MODE_SPEC;
148 static void do_glue( const char *arg )
150 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
151 exec_mode = MODE_GLUE;
155 static void do_relay(void)
157 if (exec_mode != MODE_NONE) do_usage();
158 exec_mode = MODE_RELAY;
161 static void do_sym( const char *arg )
163 extern void read_undef_symbols( const char *name );
164 read_undef_symbols( arg );
167 static void do_lib( const char *arg )
169 lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
170 lib_path[nb_lib_paths++] = xstrdup( arg );
173 /* parse options from the argv array and remove all the recognized ones */
174 static void parse_options( char *argv[] )
176 const struct option_descr *opt;
178 const char* arg=NULL;
183 for (opt = option_table; opt->name; opt++)
185 if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
187 arg=*ptr+strlen(opt->name);
195 if (!strcmp( *ptr, opt->name ))
204 fprintf( stderr, "Unrecognized option '%s'\n", *ptr );
208 if (opt->has_arg && arg!=NULL) opt->func( arg );
209 else opt->func( "" );
215 /*******************************************************************
218 int main(int argc, char **argv)
220 output_file = stdout;
221 parse_options( argv );
226 switch (ParseTopLevel( input_file ))
229 BuildSpec16File( output_file );
232 BuildSpec32File( output_file );
238 BuildGlue( output_file, input_file );
241 BuildRelays( output_file );
247 fclose( output_file );
248 output_file_name = NULL;