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;
49 /* we only support relay debugging on i386 */
50 #if defined(__i386__) && !defined(NO_TRACE_MSGS)
59 char *init_func = NULL;
60 char **debug_channels = NULL;
61 char **lib_path = NULL;
63 const char *input_file_name;
64 const char *output_file_name;
66 static FILE *input_file;
67 static FILE *output_file;
78 } exec_mode = MODE_NONE;
80 /* open the input file */
81 static void open_input( const char *name )
83 input_file_name = name;
84 if (!(input_file = fopen( name, "r" )))
86 fprintf( stderr, "Cannot open input file '%s'\n", name );
91 /* cleanup on program exit */
92 static void cleanup(void)
94 if (output_file_name) unlink( output_file_name );
98 /*******************************************************************
99 * command-line option handling
110 static void do_pic(void);
111 static void do_output( const char *arg );
112 static void do_usage(void);
113 static void do_spec( const char *arg );
114 static void do_def( const char *arg );
115 static void do_glue( const char *arg );
116 static void do_relay16(void);
117 static void do_relay32(void);
118 static void do_sym( const char *arg );
119 static void do_lib( const char *arg );
121 static const struct option_descr option_table[] =
123 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
124 { "-h", 0, do_usage, "-h Display this help message" },
125 { "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
126 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
127 { "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
128 { "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
129 { "-def", 1, do_def, "-def file.spec Build a .def file from a spec file" },
130 { "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
131 { "-relay16", 0, do_relay16, "-relay16 Build the 16-bit relay assembly routines" },
132 { "-relay32", 0, do_relay32, "-relay32 Build the 32-bit relay assembly routines" },
133 { NULL, 0, NULL, NULL }
136 static void do_pic(void)
141 static void do_output( const char *arg )
143 if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
145 fprintf ( stderr, "Unable to create output file '%s'\n", arg );
148 if (!(output_file = fopen( arg, "w" )))
150 fprintf( stderr, "Unable to create output file '%s'\n", arg );
153 output_file_name = arg;
154 atexit( cleanup ); /* make sure we remove the output file on exit */
157 static void do_usage(void)
159 const struct option_descr *opt;
160 fprintf( stderr, "Usage: winebuild [options]\n\n" );
161 fprintf( stderr, "Options:\n" );
162 for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
163 fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
167 static void do_spec( const char *arg )
169 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
170 exec_mode = MODE_SPEC;
174 static void do_def( const char *arg )
176 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
177 exec_mode = MODE_DEF;
181 static void do_glue( const char *arg )
183 if (exec_mode != MODE_NONE || !arg[0]) do_usage();
184 exec_mode = MODE_GLUE;
188 static void do_relay16(void)
190 if (exec_mode != MODE_NONE) do_usage();
191 exec_mode = MODE_RELAY16;
194 static void do_relay32(void)
196 if (exec_mode != MODE_NONE) do_usage();
197 exec_mode = MODE_RELAY32;
200 static void do_sym( const char *arg )
202 extern void read_undef_symbols( const char *name );
203 read_undef_symbols( arg );
206 static void do_lib( const char *arg )
208 lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
209 lib_path[nb_lib_paths++] = xstrdup( arg );
212 /* parse options from the argv array and remove all the recognized ones */
213 static void parse_options( char *argv[] )
215 const struct option_descr *opt;
217 const char* arg=NULL;
222 for (opt = option_table; opt->name; opt++)
224 if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
226 arg=*ptr+strlen(opt->name);
234 if (!strcmp( *ptr, opt->name ))
243 fprintf( stderr, "Unrecognized option '%s'\n", *ptr );
247 if (opt->has_arg && arg!=NULL) opt->func( arg );
248 else opt->func( "" );
254 /*******************************************************************
257 int main(int argc, char **argv)
259 output_file = stdout;
260 parse_options( argv );
265 switch (ParseTopLevel( input_file ))
268 BuildSpec16File( output_file );
271 BuildSpec32File( output_file );
277 switch (ParseTopLevel( input_file ))
280 fatal_error( "Cannot yet build .def file for 16-bit dlls\n" );
283 BuildDef32File( output_file );
289 BuildGlue( output_file, input_file );
292 BuildRelays16( output_file );
295 BuildRelays32( output_file );
301 if (output_file_name)
303 fclose( output_file );
304 output_file_name = NULL;