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
22 ORDDEF
*EntryPoints
[MAX_ORDINALS
];
23 ORDDEF
*Ordinals
[MAX_ORDINALS
];
24 ORDDEF
*Names
[MAX_ORDINALS
];
26 SPEC_MODE SpecMode
= SPEC_MODE_DLL
;
27 int Base
= MAX_ORDINALS
;
32 int nb_entry_points
= 0;
34 int nb_debug_channels
= 0;
37 /* we only support relay debugging on i386 */
38 #if defined(__i386__) && !defined(NO_TRACE_MSGS)
47 char *init_func
= NULL
;
48 char **debug_channels
= NULL
;
49 char **lib_path
= NULL
;
51 const char *input_file_name
;
52 const char *output_file_name
;
54 static FILE *input_file
;
55 static FILE *output_file
;
66 } exec_mode
= MODE_NONE
;
68 /* open the input file */
69 static void open_input( const char *name
)
71 input_file_name
= name
;
72 if (!(input_file
= fopen( name
, "r" )))
74 fprintf( stderr
, "Cannot open input file '%s'\n", name
);
79 /* cleanup on program exit */
80 static void cleanup(void)
82 if (output_file_name
) unlink( output_file_name
);
86 /*******************************************************************
87 * command-line option handling
98 static void do_pic(void);
99 static void do_output( const char *arg
);
100 static void do_usage(void);
101 static void do_spec( const char *arg
);
102 static void do_def( const char *arg
);
103 static void do_glue( const char *arg
);
104 static void do_relay16(void);
105 static void do_relay32(void);
106 static void do_sym( const char *arg
);
107 static void do_lib( const char *arg
);
109 static const struct option_descr option_table
[] =
111 { "-fPIC", 0, do_pic
, "-fPIC Generate PIC code" },
112 { "-h", 0, do_usage
, "-h Display this help message" },
113 { "-L", 1, do_lib
, "-L directory Look for imports libraries in 'directory'" },
114 { "-o", 1, do_output
, "-o name Set the output file name (default: stdout)" },
115 { "-sym", 1, do_sym
, "-sym file.o Read the list of undefined symbols from 'file.o'" },
116 { "-spec", 1, do_spec
, "-spec file.spec Build a .c file from a spec file" },
117 { "-def", 1, do_def
, "-def file.spec Build a .def file from a spec file" },
118 { "-glue", 1, do_glue
, "-glue file.c Build the 16-bit glue for a .c file" },
119 { "-relay16", 0, do_relay16
, "-relay16 Build the 16-bit relay assembly routines" },
120 { "-relay32", 0, do_relay32
, "-relay32 Build the 32-bit relay assembly routines" },
121 { NULL
, 0, NULL
, NULL
}
124 static void do_pic(void)
129 static void do_output( const char *arg
)
131 if ( ( unlink ( arg
) ) == -1 && ( errno
!= ENOENT
) )
133 fprintf ( stderr
, "Unable to create output file '%s'\n", arg
);
136 if (!(output_file
= fopen( arg
, "w" )))
138 fprintf( stderr
, "Unable to create output file '%s'\n", arg
);
141 output_file_name
= arg
;
142 atexit( cleanup
); /* make sure we remove the output file on exit */
145 static void do_usage(void)
147 const struct option_descr
*opt
;
148 fprintf( stderr
, "Usage: winebuild [options]\n\n" );
149 fprintf( stderr
, "Options:\n" );
150 for (opt
= option_table
; opt
->name
; opt
++) fprintf( stderr
, " %s\n", opt
->usage
);
151 fprintf( stderr
, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
155 static void do_spec( const char *arg
)
157 if (exec_mode
!= MODE_NONE
|| !arg
[0]) do_usage();
158 exec_mode
= MODE_SPEC
;
162 static void do_def( const char *arg
)
164 if (exec_mode
!= MODE_NONE
|| !arg
[0]) do_usage();
165 exec_mode
= MODE_DEF
;
169 static void do_glue( const char *arg
)
171 if (exec_mode
!= MODE_NONE
|| !arg
[0]) do_usage();
172 exec_mode
= MODE_GLUE
;
176 static void do_relay16(void)
178 if (exec_mode
!= MODE_NONE
) do_usage();
179 exec_mode
= MODE_RELAY16
;
182 static void do_relay32(void)
184 if (exec_mode
!= MODE_NONE
) do_usage();
185 exec_mode
= MODE_RELAY32
;
188 static void do_sym( const char *arg
)
190 extern void read_undef_symbols( const char *name
);
191 read_undef_symbols( arg
);
194 static void do_lib( const char *arg
)
196 lib_path
= xrealloc( lib_path
, (nb_lib_paths
+1) * sizeof(*lib_path
) );
197 lib_path
[nb_lib_paths
++] = xstrdup( arg
);
200 /* parse options from the argv array and remove all the recognized ones */
201 static void parse_options( char *argv
[] )
203 const struct option_descr
*opt
;
205 const char* arg
=NULL
;
210 for (opt
= option_table
; opt
->name
; opt
++)
212 if (opt
->has_arg
&& !strncmp( *ptr
, opt
->name
, strlen(opt
->name
) ))
214 arg
=*ptr
+strlen(opt
->name
);
222 if (!strcmp( *ptr
, opt
->name
))
231 fprintf( stderr
, "Unrecognized option '%s'\n", *ptr
);
235 if (opt
->has_arg
&& arg
!=NULL
) opt
->func( arg
);
236 else opt
->func( "" );
242 /*******************************************************************
245 int main(int argc
, char **argv
)
247 output_file
= stdout
;
248 parse_options( argv
);
253 switch (ParseTopLevel( input_file
))
256 BuildSpec16File( output_file
);
259 BuildSpec32File( output_file
);
265 switch (ParseTopLevel( input_file
))
268 fatal_error( "Cannot yet build .def file for 16-bit dlls\n" );
271 BuildDef32File( output_file
);
277 BuildGlue( output_file
, input_file
);
280 BuildRelays16( output_file
);
283 BuildRelays32( output_file
);
289 if (output_file_name
)
291 fclose( output_file
);
292 output_file_name
= NULL
;