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
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 ORDDEF *EntryPoints[MAX_ORDINALS];
35 ORDDEF *Ordinals[MAX_ORDINALS];
36 ORDDEF *Names[MAX_ORDINALS];
38 SPEC_MODE SpecMode = SPEC_MODE_DLL;
39 int Base = MAX_ORDINALS;
44 int nb_entry_points = 0;
46 int nb_debug_channels = 0;
48 int display_warnings = 0;
50 /* we only support relay debugging on i386 */
51 #if defined(__i386__) && !defined(NO_TRACE_MSGS)
60 char *init_func = NULL;
61 char **debug_channels = NULL;
62 char **lib_path = NULL;
64 const char *input_file_name;
65 const char *output_file_name;
67 static FILE *input_file;
68 static FILE *output_file;
79 } exec_mode = MODE_NONE;
81 /* open the input file */
82 static void open_input( const char *name )
84 input_file_name = name;
85 if (!(input_file = fopen( name, "r" )))
87 fprintf( stderr, "Cannot open input file '%s'\n", name );
92 /* cleanup on program exit */
93 static void cleanup(void)
95 if (output_file_name) unlink( output_file_name );
99 /*******************************************************************
100 * command-line option handling
111 static void do_pic(void);
112 static void do_output( const char *arg );
113 static void do_usage(void);
114 static void do_warnings(void);
115 static void do_spec( const char *arg );
116 static void do_def( const char *arg );
117 static void do_glue( const char *arg );
118 static void do_relay16(void);
119 static void do_relay32(void);
120 static void do_sym( const char *arg );
121 static void do_lib( const char *arg );
123 static const struct option_descr option_table[] =
125 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
126 { "-h", 0, do_usage, "-h Display this help message" },
127 { "-w", 0, do_warnings,"-w Turn on warnings" },
128 { "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
129 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
130 { "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
131 { "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
132 { "-def", 1, do_def, "-def file.spec Build a .def file from a spec file" },
133 { "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
134 { "-relay16", 0, do_relay16, "-relay16 Build the 16-bit relay assembly routines" },
135 { "-relay32", 0, do_relay32, "-relay32 Build the 32-bit relay assembly routines" },
136 { NULL, 0, NULL, NULL }
139 static void do_pic(void)
144 static void do_output( const char *arg )
146 if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
148 fprintf ( stderr, "Unable to create output file '%s'\n", arg );
151 if (!(output_file = fopen( arg, "w" )))
153 fprintf( stderr, "Unable to create output file '%s'\n", arg );
156 output_file_name = arg;
157 atexit( cleanup ); /* make sure we remove the output file on exit */
160 static void do_usage(void)
162 const struct option_descr *opt;
163 fprintf( stderr, "Usage: winebuild [options]\n\n" );
164 fprintf( stderr, "Options:\n" );
165 for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
166 fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
170 static void do_warnings(void)
172 display_warnings = 1;
175 static void do_spec( const char *arg )
177 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
178 exec_mode = MODE_SPEC;
182 static void do_def( const char *arg )
184 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
185 exec_mode = MODE_DEF;
189 static void do_glue( const char *arg )
191 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
192 exec_mode = MODE_GLUE;
196 static void do_relay16(void)
198 if (exec_mode != MODE_NONE) do_usage();
199 exec_mode = MODE_RELAY16;
202 static void do_relay32(void)
204 if (exec_mode != MODE_NONE) do_usage();
205 exec_mode = MODE_RELAY32;
208 static void do_sym( const char *arg )
210 extern void read_undef_symbols( const char *name );
211 read_undef_symbols( arg );
214 static void do_lib( const char *arg )
216 lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
217 lib_path[nb_lib_paths++] = xstrdup( arg );
220 /* parse options from the argv array and remove all the recognized ones */
221 static void parse_options( char *argv[] )
223 const struct option_descr *opt;
225 const char* arg=NULL;
230 for (opt = option_table; opt->name; opt++)
232 if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
234 arg=*ptr+strlen(opt->name);
242 if (!strcmp( *ptr, opt->name ))
251 fprintf( stderr, "Unrecognized option '%s'\n", *ptr );
255 if (opt->has_arg && arg!=NULL) opt->func( arg );
256 else opt->func( "" );
262 /*******************************************************************
265 int main(int argc, char **argv)
267 output_file = stdout;
268 parse_options( argv );
273 switch (ParseTopLevel( input_file, 0 ))
276 BuildSpec16File( output_file );
279 BuildSpec32File( output_file );
285 switch (ParseTopLevel( input_file, 1 ))
288 fatal_error( "Cannot yet build .def file for 16-bit dlls\n" );
291 BuildDef32File( output_file );
297 BuildGlue( output_file, input_file );
300 BuildRelays16( output_file );
303 BuildRelays32( output_file );
309 if (output_file_name)
311 fclose( output_file );
312 output_file_name = NULL;