2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* Main function
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Martin von Loewis
|
|
|
|
* Copyright 1995, 1996, 1997 Alexandre Julliard
|
|
|
|
* Copyright 1997 Eric Youngdale
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2000-07-15 17:13:09 +02:00
|
|
|
#include <errno.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-10-28 02:32:08 +02:00
|
|
|
#include "config.h"
|
2000-06-23 22:15:35 +02:00
|
|
|
#include "winnt.h"
|
|
|
|
#include "build.h"
|
|
|
|
|
2000-12-16 00:04:40 +01:00
|
|
|
ORDDEF *EntryPoints[MAX_ORDINALS];
|
2000-06-23 22:15:35 +02:00
|
|
|
ORDDEF *Ordinals[MAX_ORDINALS];
|
|
|
|
ORDDEF *Names[MAX_ORDINALS];
|
|
|
|
|
|
|
|
SPEC_MODE SpecMode = SPEC_MODE_DLL;
|
|
|
|
int Base = MAX_ORDINALS;
|
|
|
|
int Limit = 0;
|
|
|
|
int DLLHeapSize = 0;
|
|
|
|
int UsePIC = 0;
|
2001-06-08 00:29:03 +02:00
|
|
|
int stack_size = 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
int nb_entry_points = 0;
|
|
|
|
int nb_names = 0;
|
2000-11-05 05:49:13 +01:00
|
|
|
int nb_debug_channels = 0;
|
2000-11-09 21:31:18 +01:00
|
|
|
int nb_lib_paths = 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-11-28 00:48:08 +01:00
|
|
|
/* we only support relay debugging on i386 */
|
|
|
|
#if defined(__i386__) && !defined(NO_TRACE_MSGS)
|
|
|
|
int debugging = 1;
|
|
|
|
#else
|
|
|
|
int debugging = 0;
|
|
|
|
#endif
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
char DLLName[80];
|
|
|
|
char DLLFileName[80];
|
2000-07-28 02:07:18 +02:00
|
|
|
char owner_name[80];
|
2000-12-16 00:04:40 +01:00
|
|
|
char *init_func = NULL;
|
2000-11-09 21:31:18 +01:00
|
|
|
char **debug_channels = NULL;
|
|
|
|
char **lib_path = NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
const char *input_file_name;
|
|
|
|
const char *output_file_name;
|
|
|
|
|
|
|
|
static FILE *input_file;
|
|
|
|
static FILE *output_file;
|
|
|
|
|
|
|
|
/* execution mode */
|
|
|
|
static enum { MODE_NONE, MODE_SPEC, MODE_GLUE, MODE_RELAY } exec_mode = MODE_NONE;
|
|
|
|
|
|
|
|
/* open the input file */
|
|
|
|
static void open_input( const char *name )
|
|
|
|
{
|
|
|
|
input_file_name = name;
|
|
|
|
if (!(input_file = fopen( name, "r" )))
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Cannot open input file '%s'\n", name );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup on program exit */
|
|
|
|
static void cleanup(void)
|
|
|
|
{
|
|
|
|
if (output_file_name) unlink( output_file_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* command-line option handling
|
|
|
|
*/
|
|
|
|
|
2001-01-11 23:31:04 +01:00
|
|
|
struct option_descr
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int has_arg;
|
|
|
|
void (*func)();
|
|
|
|
const char *usage;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void do_pic(void);
|
|
|
|
static void do_output( const char *arg );
|
|
|
|
static void do_usage(void);
|
|
|
|
static void do_spec( const char *arg );
|
|
|
|
static void do_glue( const char *arg );
|
|
|
|
static void do_relay(void);
|
2000-11-09 21:31:18 +01:00
|
|
|
static void do_sym( const char *arg );
|
|
|
|
static void do_lib( const char *arg );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2001-01-11 23:31:04 +01:00
|
|
|
static const struct option_descr option_table[] =
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
{ "-fPIC", 0, do_pic, "-fPIC Generate PIC code" },
|
|
|
|
{ "-h", 0, do_usage, "-h Display this help message" },
|
2000-11-09 21:31:18 +01:00
|
|
|
{ "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
|
2000-06-23 22:15:35 +02:00
|
|
|
{ "-o", 1, do_output, "-o name Set the output file name (default: stdout)" },
|
2000-11-09 21:31:18 +01:00
|
|
|
{ "-sym", 1, do_sym, "-sym file.o Read the list of undefined symbols from 'file.o'" },
|
2000-06-23 22:15:35 +02:00
|
|
|
{ "-spec", 1, do_spec, "-spec file.spec Build a .c file from a spec file" },
|
|
|
|
{ "-glue", 1, do_glue, "-glue file.c Build the 16-bit glue for a .c file" },
|
|
|
|
{ "-relay", 0, do_relay, "-relay Build the relay assembly routines" },
|
2000-10-23 01:56:32 +02:00
|
|
|
{ NULL, 0, NULL, NULL }
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void do_pic(void)
|
|
|
|
{
|
|
|
|
UsePIC = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_output( const char *arg )
|
|
|
|
{
|
2000-07-15 17:13:09 +02:00
|
|
|
if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
|
|
|
|
{
|
|
|
|
fprintf ( stderr, "Unable to create output file '%s'\n", arg );
|
|
|
|
exit (1);
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
if (!(output_file = fopen( arg, "w" )))
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Unable to create output file '%s'\n", arg );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
output_file_name = arg;
|
|
|
|
atexit( cleanup ); /* make sure we remove the output file on exit */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_usage(void)
|
|
|
|
{
|
2001-01-11 23:31:04 +01:00
|
|
|
const struct option_descr *opt;
|
2000-06-23 22:15:35 +02:00
|
|
|
fprintf( stderr, "Usage: winebuild [options]\n\n" );
|
|
|
|
fprintf( stderr, "Options:\n" );
|
|
|
|
for (opt = option_table; opt->name; opt++) fprintf( stderr, " %s\n", opt->usage );
|
|
|
|
fprintf( stderr, "\nExactly one of -spec, -glue or -relay must be specified.\n\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_spec( const char *arg )
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE || !arg[0]) do_usage();
|
|
|
|
exec_mode = MODE_SPEC;
|
|
|
|
open_input( arg );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_glue( const char *arg )
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE || !arg[0]) do_usage();
|
|
|
|
exec_mode = MODE_GLUE;
|
|
|
|
open_input( arg );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_relay(void)
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE) do_usage();
|
|
|
|
exec_mode = MODE_RELAY;
|
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
static void do_sym( const char *arg )
|
|
|
|
{
|
|
|
|
extern void read_undef_symbols( const char *name );
|
|
|
|
read_undef_symbols( arg );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_lib( const char *arg )
|
|
|
|
{
|
|
|
|
lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
|
|
|
|
lib_path[nb_lib_paths++] = xstrdup( arg );
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* parse options from the argv array and remove all the recognized ones */
|
|
|
|
static void parse_options( char *argv[] )
|
|
|
|
{
|
2001-01-11 23:31:04 +01:00
|
|
|
const struct option_descr *opt;
|
2000-11-16 00:12:06 +01:00
|
|
|
char * const * ptr;
|
|
|
|
const char* arg=NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-11-16 00:12:06 +01:00
|
|
|
ptr=argv+1;
|
|
|
|
while (*ptr != NULL)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
for (opt = option_table; opt->name; opt++)
|
2000-11-16 00:12:06 +01:00
|
|
|
{
|
|
|
|
if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
|
|
|
|
{
|
|
|
|
arg=*ptr+strlen(opt->name);
|
|
|
|
if (*arg=='\0')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
arg=*ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!strcmp( *ptr, opt->name ))
|
|
|
|
{
|
|
|
|
arg=NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
if (!opt->name)
|
|
|
|
{
|
2000-11-16 00:12:06 +01:00
|
|
|
fprintf( stderr, "Unrecognized option '%s'\n", *ptr );
|
2000-06-23 22:15:35 +02:00
|
|
|
do_usage();
|
|
|
|
}
|
|
|
|
|
2000-11-16 00:12:06 +01:00
|
|
|
if (opt->has_arg && arg!=NULL) opt->func( arg );
|
2000-06-23 22:15:35 +02:00
|
|
|
else opt->func( "" );
|
2000-11-16 00:12:06 +01:00
|
|
|
ptr++;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* main
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
output_file = stdout;
|
|
|
|
parse_options( argv );
|
|
|
|
|
|
|
|
switch(exec_mode)
|
|
|
|
{
|
|
|
|
case MODE_SPEC:
|
|
|
|
switch (ParseTopLevel( input_file ))
|
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
|
|
|
BuildSpec16File( output_file );
|
|
|
|
break;
|
|
|
|
case SPEC_WIN32:
|
2000-11-13 05:46:34 +01:00
|
|
|
BuildSpec32File( output_file );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_GLUE:
|
|
|
|
BuildGlue( output_file, input_file );
|
|
|
|
break;
|
|
|
|
case MODE_RELAY:
|
|
|
|
BuildRelays( output_file );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
do_usage();
|
|
|
|
break;
|
|
|
|
}
|
2001-05-22 21:55:51 +02:00
|
|
|
if (output_file_name)
|
|
|
|
{
|
|
|
|
fclose( output_file );
|
|
|
|
output_file_name = NULL;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|