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;
31 int nb_debug_channels = 0;
34 /* we only support relay debugging on i386 */
35 #if defined(__i386__) && !defined(NO_TRACE_MSGS)
44 char *init_func = NULL;
45 char **debug_channels = NULL;
46 char **lib_path = NULL;
48 const char *input_file_name;
49 const char *output_file_name;
51 static FILE *input_file;
52 static FILE *output_file;
55 static enum { MODE_NONE, MODE_SPEC, MODE_GLUE, MODE_RELAY } exec_mode = MODE_NONE;
57 /* open the input file */
58 static void open_input( const char *name )
60 input_file_name = name;
61 if (!(input_file = fopen( name, "r" )))
63 fprintf( stderr, "Cannot open input file '%s'\n", name );
68 /* cleanup on program exit */
69 static void cleanup(void)
71 if (output_file_name) unlink( output_file_name );
75 /*******************************************************************
76 * command-line option handling
87 static void do_pic(void);
88 static void do_output( const char *arg );
89 static void do_usage(void);
90 static void do_spec( const char *arg );
91 static void do_glue( const char *arg );
92 static void do_relay(void);
93 static void do_sym( const char *arg );
94 static void do_lib( const char *arg );
96 static const struct option_descr option_table[] =
98 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
99 { "-h", 0, do_usage, "-h Display this help message" },
100 { "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
101 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
102 { "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
103 { "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
104 { "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
105 { "-relay", 0, do_relay, "-relay Build the relay assembly routines" },
106 { NULL, 0, NULL, NULL }
109 static void do_pic(void)
114 static void do_output( const char *arg )
116 if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
118 fprintf ( stderr, "Unable to create output file '%s'\n", arg );
121 if (!(output_file = fopen( arg, "w" )))
123 fprintf( stderr, "Unable to create output file '%s'\n", arg );
126 output_file_name = arg;
127 atexit( cleanup ); /* make sure we remove the output file on exit */
130 static void do_usage(void)
132 const struct option_descr *opt;
133 fprintf( stderr, "Usage: winebuild [options]\n\n" );
134 fprintf( stderr, "Options:\n" );
135 for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
136 fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
140 static void do_spec( const char *arg )
142 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
143 exec_mode = MODE_SPEC;
147 static void do_glue( const char *arg )
149 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
150 exec_mode = MODE_GLUE;
154 static void do_relay(void)
156 if (exec_mode != MODE_NONE) do_usage();
157 exec_mode = MODE_RELAY;
160 static void do_sym( const char *arg )
162 extern void read_undef_symbols( const char *name );
163 read_undef_symbols( arg );
166 static void do_lib( const char *arg )
168 lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
169 lib_path[nb_lib_paths++] = xstrdup( arg );
172 /* parse options from the argv array and remove all the recognized ones */
173 static void parse_options( char *argv[] )
175 const struct option_descr *opt;
177 const char* arg=NULL;
182 for (opt = option_table; opt->name; opt++)
184 if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
186 arg=*ptr+strlen(opt->name);
194 if (!strcmp( *ptr, opt->name ))
203 fprintf( stderr, "Unrecognized option '%s'\n", *ptr );
207 if (opt->has_arg && arg!=NULL) opt->func( arg );
208 else opt->func( "" );
214 /*******************************************************************
217 int main(int argc, char **argv)
219 output_file = stdout;
220 parse_options( argv );
225 switch (ParseTopLevel( input_file ))
228 BuildSpec16File( output_file );
231 BuildSpec32File( output_file );
237 BuildGlue( output_file, input_file );
240 BuildRelays( output_file );
246 fclose( output_file );
247 output_file_name = NULL;