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 extern WORD __get_cs(void);
21 extern WORD __get_ds(void);
22 __ASM_GLOBAL_FUNC( __get_cs, "movw %cs,%ax\n\tret" );
23 __ASM_GLOBAL_FUNC( __get_ds, "movw %ds,%ax\n\tret" );
25 static inline WORD __get_cs(void) { return 0; }
26 static inline WORD __get_ds(void) { return 0; }
30 ORDDEF EntryPoints[MAX_ORDINALS];
31 ORDDEF *Ordinals[MAX_ORDINALS];
32 ORDDEF *Names[MAX_ORDINALS];
34 SPEC_MODE SpecMode = SPEC_MODE_DLL;
35 int Base = MAX_ORDINALS;
39 int nb_entry_points = 0;
47 char *DLLImports[MAX_IMPORTS];
50 const char *input_file_name;
51 const char *output_file_name;
53 unsigned short code_selector;
54 unsigned short data_selector;
56 static FILE *input_file;
57 static FILE *output_file;
60 static enum { MODE_NONE, MODE_SPEC, MODE_GLUE, MODE_RELAY } exec_mode = MODE_NONE;
62 /* open the input file */
63 static void open_input( const char *name )
65 input_file_name = name;
66 if (!(input_file = fopen( name, "r" )))
68 fprintf( stderr, "Cannot open input file '%s'\n", name );
73 /* cleanup on program exit */
74 static void cleanup(void)
76 if (output_file_name) unlink( output_file_name );
80 /*******************************************************************
81 * command-line option handling
92 static void do_pic(void);
93 static void do_output( const char *arg );
94 static void do_usage(void);
95 static void do_spec( const char *arg );
96 static void do_glue( const char *arg );
97 static void do_relay(void);
99 static const struct option option_table[] =
101 { "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
102 { "-h", 0, do_usage, "-h Display this help message" },
103 { "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
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" },
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 *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;
162 /* parse options from the argv array and remove all the recognized ones */
163 static void parse_options( char *argv[] )
165 const struct option *opt;
168 for (i = 1; argv[i]; i++)
170 for (opt = option_table; opt->name; opt++)
171 if (!strcmp( argv[i], opt->name )) break;
175 fprintf( stderr, "Unrecognized option '%s'\n", argv[i] );
179 if (opt->has_arg && argv[i+1]) opt->func( argv[++i] );
180 else opt->func( "" );
185 /*******************************************************************
188 int main(int argc, char **argv)
190 output_file = stdout;
191 parse_options( argv );
193 /* Retrieve the selector values; this assumes that we are building
194 * the asm files on the platform that will also run them. Probably
195 * a safe assumption to make.
197 code_selector = __get_cs();
198 data_selector = __get_ds();
203 switch (ParseTopLevel( input_file ))
206 BuildSpec16File( output_file );
209 BuildSpec32File( output_file );
215 BuildGlue( output_file, input_file );
218 BuildRelays( output_file );
224 fclose( output_file );
225 output_file_name = NULL;