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
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2000-07-15 17:13:09 +02:00
|
|
|
#include <errno.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2002-09-17 01:58:59 +02:00
|
|
|
#include <ctype.h>
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
#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;
|
2002-11-19 00:16:09 +01:00
|
|
|
SPEC_TYPE SpecType = SPEC_WIN32;
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
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;
|
2002-03-21 02:38:53 +01:00
|
|
|
int display_warnings = 0;
|
2002-12-12 05:06:28 +01:00
|
|
|
int kill_at = 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
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
char *input_file_name = NULL;
|
|
|
|
const char *output_file_name = NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
static FILE *input_file;
|
|
|
|
static FILE *output_file;
|
2002-05-14 22:54:58 +02:00
|
|
|
static const char *current_src_dir;
|
2002-11-19 00:16:09 +01:00
|
|
|
static int nb_res_files;
|
|
|
|
static char **res_files;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* execution mode */
|
2002-02-04 19:48:18 +01:00
|
|
|
static enum
|
|
|
|
{
|
|
|
|
MODE_NONE,
|
|
|
|
MODE_SPEC,
|
2002-05-12 01:06:32 +02:00
|
|
|
MODE_EXE,
|
2002-02-04 19:48:18 +01:00
|
|
|
MODE_GLUE,
|
|
|
|
MODE_DEF,
|
2002-05-14 22:54:58 +02:00
|
|
|
MODE_DEBUG,
|
2002-02-04 19:48:18 +01:00
|
|
|
MODE_RELAY16,
|
|
|
|
MODE_RELAY32
|
|
|
|
} exec_mode = MODE_NONE;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2002-07-28 19:52:01 +02:00
|
|
|
/* set the dll file name from the input file name */
|
|
|
|
static void set_dll_file_name( const char *name )
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
2003-01-02 18:48:05 +01:00
|
|
|
if (*DLLFileName) return;
|
|
|
|
|
2002-08-31 21:04:14 +02:00
|
|
|
if ((p = strrchr( name, '\\' ))) name = p + 1;
|
2002-07-28 19:52:01 +02:00
|
|
|
if ((p = strrchr( name, '/' ))) name = p + 1;
|
|
|
|
strcpy( DLLFileName, name );
|
|
|
|
if ((p = strrchr( DLLFileName, '.' )) && !strcmp( p, ".spec" )) *p = 0;
|
|
|
|
if (!strchr( DLLFileName, '.' )) strcat( DLLFileName, ".dll" );
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* 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_output( const char *arg );
|
|
|
|
static void do_usage(void);
|
2002-03-21 02:38:53 +01:00
|
|
|
static void do_warnings(void);
|
2002-05-14 22:54:58 +02:00
|
|
|
static void do_f_flags( const char *arg );
|
|
|
|
static void do_define( const char *arg );
|
|
|
|
static void do_include( const char *arg );
|
2002-07-05 02:20:42 +02:00
|
|
|
static void do_k_flags( const char *arg );
|
2002-12-08 00:54:12 +01:00
|
|
|
static void do_ignore( const char *arg );
|
2002-12-12 05:06:28 +01:00
|
|
|
static void do_kill_at(void);
|
2002-05-12 01:06:32 +02:00
|
|
|
static void do_exe_mode( const char *arg );
|
2002-06-21 21:15:45 +02:00
|
|
|
static void do_module( const char *arg );
|
2002-09-13 00:51:20 +02:00
|
|
|
static void do_heap( const char *arg );
|
2002-09-12 19:23:25 +02:00
|
|
|
static void do_name( const char *arg );
|
2003-01-02 18:48:05 +01:00
|
|
|
static void do_file( const char *arg );
|
2002-11-06 21:02:59 +01:00
|
|
|
static void do_entry( const char *arg );
|
2000-06-23 22:15:35 +02:00
|
|
|
static void do_spec( const char *arg );
|
2002-02-04 19:48:18 +01:00
|
|
|
static void do_def( const char *arg );
|
2002-05-12 01:06:32 +02:00
|
|
|
static void do_exe( const char *arg );
|
2002-08-01 20:34:12 +02:00
|
|
|
static void do_glue(void);
|
2001-12-11 01:50:33 +01:00
|
|
|
static void do_relay16(void);
|
|
|
|
static void do_relay32(void);
|
2002-05-14 22:54:58 +02:00
|
|
|
static void do_debug(void);
|
|
|
|
static void do_chdir( const char *arg );
|
2000-11-09 21:31:18 +01:00
|
|
|
static void do_lib( const char *arg );
|
2002-05-09 02:05:48 +02:00
|
|
|
static void do_import( const char *arg );
|
|
|
|
static void do_dimport( const char *arg );
|
2002-05-12 01:06:32 +02:00
|
|
|
static void do_rsrc( 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
|
|
|
{
|
2002-11-06 21:02:59 +01:00
|
|
|
{ "-h", 0, do_usage, "-h Display this help message" },
|
|
|
|
{ "-w", 0, do_warnings,"-w Turn on warnings" },
|
|
|
|
{ "-C", 1, do_chdir, "-C dir Change directory to <dir> before opening source files" },
|
|
|
|
{ "-f", 1, do_f_flags, "-f flags Compiler flags (only -fPIC is supported)" },
|
|
|
|
{ "-D", 1, do_define, "-D sym Ignored for C flags compatibility" },
|
|
|
|
{ "-I", 1, do_include, "-I dir Ignored for C flags compatibility" },
|
|
|
|
{ "-K", 1, do_k_flags, "-K flags Compiler flags (only -KPIC is supported)" },
|
2002-12-08 00:54:12 +01:00
|
|
|
{ "-i", 1, do_ignore, "-i sym[,sym] Ignore specified symbols when resolving imports" },
|
2002-12-12 05:06:28 +01:00
|
|
|
{ "-k", 0, do_kill_at, "-k Kill stdcall decorations in generated .def files" },
|
2002-11-06 21:02:59 +01:00
|
|
|
{ "-m", 1, do_exe_mode,"-m mode Set the executable mode (cui|gui|cuiw|guiw)" },
|
|
|
|
{ "-M", 1, do_module, "-M module Set the name of the main (Win32) module for a Win16 dll" },
|
|
|
|
{ "-L", 1, do_lib, "-L directory Look for imports libraries in 'directory'" },
|
|
|
|
{ "-l", 1, do_import, "-l lib.dll Import the specified library" },
|
|
|
|
{ "-d", 1, do_dimport, "-d lib.dll Delay-import the specified library" },
|
|
|
|
{ "-H", 1, do_heap, "-H size Set the heap size for a Win16 dll" },
|
|
|
|
{ "-N", 1, do_name, "-N dllname Set the DLL name (default: set from input file name)" },
|
2003-01-02 18:48:05 +01:00
|
|
|
{ "-F", 1, do_file, "-F dllfile Set the DLL filename (default: set from input file name)" },
|
2002-11-06 21:02:59 +01:00
|
|
|
{ "-e", 1, do_entry, "-e function Set the DLL entry point function (default: DllMain)" },
|
|
|
|
{ "-r", 1, do_rsrc, "-r rsrc.res Load resources from rsrc.res" },
|
|
|
|
{ "-res", 1, do_rsrc, NULL }, /* for backwards compatibility, will disappear */
|
|
|
|
{ "-o", 1, do_output, "-o name Set the output file name (default: stdout)\n" },
|
|
|
|
{ "--spec", 1, do_spec, "--spec file.spec Build a .c file from a spec file" },
|
|
|
|
{ "--def", 1, do_def, "--def file.spec Build a .def file from a spec file" },
|
|
|
|
{ "--exe", 1, do_exe, "--exe name Build a .c file for the named executable" },
|
|
|
|
{ "--debug", 0, do_debug, "--debug [files] Build a .c file containing debug channels declarations" },
|
|
|
|
{ "--glue", 0, do_glue, "--glue [files] Build the 16-bit glue for the source files" },
|
|
|
|
{ "--relay16", 0, do_relay16, "--relay16 Build the 16-bit relay assembly routines" },
|
|
|
|
{ "--relay32", 0, do_relay32, "--relay32 Build the 32-bit relay assembly routines" },
|
2001-12-11 01:50:33 +01:00
|
|
|
{ NULL, 0, NULL, NULL }
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void do_output( const char *arg )
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if ( ( unlink ( arg ) ) == -1 && ( errno != ENOENT ) )
|
2000-07-15 17:13:09 +02:00
|
|
|
{
|
|
|
|
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" );
|
2002-08-01 20:34:12 +02:00
|
|
|
for (opt = option_table; opt->name; opt++)
|
|
|
|
if (opt->usage) fprintf( stderr, " %s\n", opt->usage );
|
|
|
|
|
2002-11-06 21:02:59 +01:00
|
|
|
fprintf( stderr, "\nExactly one of --spec, --def, --exe, --debug, --glue, --relay16 or --relay32 must be specified.\n\n" );
|
2000-06-23 22:15:35 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-03-21 02:38:53 +01:00
|
|
|
static void do_warnings(void)
|
|
|
|
{
|
|
|
|
display_warnings = 1;
|
|
|
|
}
|
|
|
|
|
2002-05-14 22:54:58 +02:00
|
|
|
static void do_f_flags( const char *arg )
|
|
|
|
{
|
|
|
|
if (!strcmp( arg, "PIC" )) UsePIC = 1;
|
|
|
|
/* ignore all other flags */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_define( const char *arg )
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_include( const char *arg )
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
2002-07-05 02:20:42 +02:00
|
|
|
static void do_k_flags( const char *arg )
|
|
|
|
{
|
|
|
|
/* Ignored, because cc generates correct code. */
|
|
|
|
/* if (!strcmp( arg, "PIC" )) UsePIC = 1; */
|
|
|
|
/* ignore all other flags */
|
|
|
|
}
|
|
|
|
|
2002-12-08 00:54:12 +01:00
|
|
|
static void do_ignore( const char *arg )
|
|
|
|
{
|
|
|
|
char *str = xstrdup( arg );
|
|
|
|
char *token = strtok( str, "," );
|
|
|
|
while (token)
|
|
|
|
{
|
|
|
|
add_ignore_symbol( token );
|
|
|
|
token = strtok( NULL, "," );
|
|
|
|
}
|
|
|
|
free( str );
|
|
|
|
}
|
|
|
|
|
2002-12-12 05:06:28 +01:00
|
|
|
static void do_kill_at(void)
|
|
|
|
{
|
|
|
|
kill_at = 1;
|
|
|
|
}
|
|
|
|
|
2002-09-13 00:51:20 +02:00
|
|
|
static void do_heap( const char *arg )
|
|
|
|
{
|
|
|
|
if (!isdigit(arg[0]))
|
|
|
|
fatal_error( "Expected number argument with -H option instead of '%s'\n", arg );
|
|
|
|
DLLHeapSize = atoi(arg);
|
|
|
|
if (DLLHeapSize > 65535) fatal_error( "Invalid heap size %d, maximum is 65535\n", DLLHeapSize );
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:23:25 +02:00
|
|
|
static void do_name( const char *arg )
|
|
|
|
{
|
|
|
|
strncpy( DLLName, arg, sizeof(DLLName) );
|
|
|
|
DLLName[sizeof(DLLName) - 1] = 0;
|
|
|
|
}
|
|
|
|
|
2003-01-02 18:48:05 +01:00
|
|
|
static void do_file( const char *arg )
|
|
|
|
{
|
|
|
|
strncpy( DLLFileName, arg, sizeof(DLLFileName) );
|
|
|
|
DLLFileName[sizeof(DLLFileName) - 1] = 0;
|
|
|
|
}
|
|
|
|
|
2002-11-06 21:02:59 +01:00
|
|
|
static void do_entry( const char *arg )
|
|
|
|
{
|
|
|
|
init_func = xstrdup( arg );
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
static void do_spec( const char *arg )
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE || !arg[0]) do_usage();
|
|
|
|
exec_mode = MODE_SPEC;
|
2002-08-01 20:34:12 +02:00
|
|
|
input_file = open_input_file( NULL, arg );
|
2002-07-28 19:52:01 +02:00
|
|
|
set_dll_file_name( arg );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
2002-02-04 19:48:18 +01:00
|
|
|
static void do_def( const char *arg )
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE || !arg[0]) do_usage();
|
|
|
|
exec_mode = MODE_DEF;
|
2002-08-01 20:34:12 +02:00
|
|
|
input_file = open_input_file( NULL, arg );
|
2002-07-28 19:52:01 +02:00
|
|
|
set_dll_file_name( arg );
|
2002-02-04 19:48:18 +01:00
|
|
|
}
|
|
|
|
|
2002-05-12 01:06:32 +02:00
|
|
|
static void do_exe( const char *arg )
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (exec_mode != MODE_NONE || !arg[0]) do_usage();
|
|
|
|
exec_mode = MODE_EXE;
|
|
|
|
if ((p = strrchr( arg, '/' ))) p++;
|
|
|
|
else p = arg;
|
|
|
|
strcpy( DLLFileName, p );
|
|
|
|
if (!strchr( DLLFileName, '.' )) strcat( DLLFileName, ".exe" );
|
|
|
|
if (SpecMode == SPEC_MODE_DLL) SpecMode = SPEC_MODE_GUIEXE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_exe_mode( const char *arg )
|
|
|
|
{
|
|
|
|
if (!strcmp( arg, "gui" )) SpecMode = SPEC_MODE_GUIEXE;
|
|
|
|
else if (!strcmp( arg, "cui" )) SpecMode = SPEC_MODE_CUIEXE;
|
|
|
|
else if (!strcmp( arg, "guiw" )) SpecMode = SPEC_MODE_GUIEXE_UNICODE;
|
|
|
|
else if (!strcmp( arg, "cuiw" )) SpecMode = SPEC_MODE_CUIEXE_UNICODE;
|
|
|
|
else do_usage();
|
|
|
|
}
|
|
|
|
|
2002-06-21 21:15:45 +02:00
|
|
|
static void do_module( const char *arg )
|
|
|
|
{
|
|
|
|
strcpy( owner_name, arg );
|
2002-11-19 00:16:09 +01:00
|
|
|
SpecType = SPEC_WIN16;
|
2002-06-21 21:15:45 +02:00
|
|
|
}
|
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
static void do_glue(void)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2002-08-01 20:34:12 +02:00
|
|
|
if (exec_mode != MODE_NONE) do_usage();
|
2000-06-23 22:15:35 +02:00
|
|
|
exec_mode = MODE_GLUE;
|
|
|
|
}
|
|
|
|
|
2002-05-14 22:54:58 +02:00
|
|
|
static void do_debug(void)
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE) do_usage();
|
|
|
|
exec_mode = MODE_DEBUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_chdir( const char *arg )
|
|
|
|
{
|
|
|
|
current_src_dir = arg;
|
|
|
|
}
|
|
|
|
|
2001-12-11 01:50:33 +01:00
|
|
|
static void do_relay16(void)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE) do_usage();
|
2001-12-11 01:50:33 +01:00
|
|
|
exec_mode = MODE_RELAY16;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_relay32(void)
|
|
|
|
{
|
|
|
|
if (exec_mode != MODE_NONE) do_usage();
|
|
|
|
exec_mode = MODE_RELAY32;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
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
|
|
|
|
2002-05-09 02:05:48 +02:00
|
|
|
static void do_import( const char *arg )
|
|
|
|
{
|
|
|
|
add_import_dll( arg, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_dimport( const char *arg )
|
|
|
|
{
|
|
|
|
add_import_dll( arg, 1 );
|
|
|
|
}
|
|
|
|
|
2002-05-12 01:06:32 +02:00
|
|
|
static void do_rsrc( const char *arg )
|
|
|
|
{
|
2002-11-19 00:16:09 +01:00
|
|
|
res_files = xrealloc( res_files, (nb_res_files+1) * sizeof(*res_files) );
|
|
|
|
res_files[nb_res_files++] = xstrdup( arg );
|
2002-05-12 01:06:32 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2002-08-01 20:34:12 +02:00
|
|
|
char **ptr, **last;
|
2000-11-16 00:12:06 +01:00
|
|
|
const char* arg=NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2002-12-07 00:26:29 +01:00
|
|
|
for (ptr = last = argv; *ptr; ptr++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2002-11-06 21:02:59 +01:00
|
|
|
/* first check the exact option name */
|
2000-06-23 22:15:35 +02:00
|
|
|
for (opt = option_table; opt->name; opt++)
|
2000-11-16 00:12:06 +01:00
|
|
|
{
|
2002-11-06 21:02:59 +01:00
|
|
|
if (!strcmp( *ptr, opt->name ) ||
|
|
|
|
/* for long option check without the first dash too */
|
|
|
|
(opt->name[1] == '-' && !strcmp( *ptr, opt->name+1 )))
|
2000-11-16 00:12:06 +01:00
|
|
|
{
|
2002-11-06 21:02:59 +01:00
|
|
|
if (opt->has_arg) arg = *(++ptr);
|
|
|
|
else arg = NULL;
|
2000-11-16 00:12:06 +01:00
|
|
|
break;
|
|
|
|
}
|
2002-11-06 21:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now check for option name concatenated with argument */
|
|
|
|
if (!opt->name)
|
|
|
|
{
|
|
|
|
for (opt = option_table; opt->name; opt++)
|
2000-11-16 00:12:06 +01:00
|
|
|
{
|
2002-11-06 21:02:59 +01:00
|
|
|
if (opt->has_arg && !strncmp( *ptr, opt->name, strlen(opt->name) ))
|
|
|
|
{
|
|
|
|
arg = *ptr + strlen(opt->name);
|
|
|
|
break;
|
|
|
|
}
|
2000-11-16 00:12:06 +01:00
|
|
|
}
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
if (opt->name)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2002-08-01 20:34:12 +02:00
|
|
|
if (opt->has_arg && arg != NULL) opt->func( arg );
|
|
|
|
else opt->func( "" );
|
|
|
|
}
|
|
|
|
else /* keep this argument */
|
|
|
|
{
|
|
|
|
if (last != ptr) *last = *ptr;
|
|
|
|
last++;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
2002-08-01 20:34:12 +02:00
|
|
|
*last = NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-19 00:16:09 +01:00
|
|
|
/* load all specified resource files */
|
2002-12-07 00:26:29 +01:00
|
|
|
static void load_resources( char *argv[] )
|
2002-11-19 00:16:09 +01:00
|
|
|
{
|
|
|
|
int i;
|
2002-12-07 00:26:29 +01:00
|
|
|
char **ptr, **last;
|
2002-11-19 00:16:09 +01:00
|
|
|
|
|
|
|
switch (SpecType)
|
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
|
|
|
for (i = 0; i < nb_res_files; i++) load_res16_file( res_files[i] );
|
|
|
|
break;
|
2002-12-07 00:26:29 +01:00
|
|
|
|
2002-11-19 00:16:09 +01:00
|
|
|
case SPEC_WIN32:
|
2002-12-07 00:26:29 +01:00
|
|
|
for (i = 0; i < nb_res_files; i++)
|
|
|
|
{
|
|
|
|
if (!load_res32_file( res_files[i] ))
|
|
|
|
fatal_error( "%s is not a valid Win32 resource file\n", res_files[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load any resource file found in the remaining arguments */
|
|
|
|
for (ptr = last = argv; *ptr; ptr++)
|
|
|
|
{
|
|
|
|
if (!load_res32_file( *ptr ))
|
|
|
|
*last++ = *ptr; /* not a resource file, keep it in the list */
|
|
|
|
}
|
|
|
|
*last = NULL;
|
2002-11-19 00:16:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* main
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
output_file = stdout;
|
2002-12-07 00:26:29 +01:00
|
|
|
parse_options( argv + 1 );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
switch(exec_mode)
|
|
|
|
{
|
|
|
|
case MODE_SPEC:
|
2002-12-07 00:26:29 +01:00
|
|
|
load_resources( argv + 1 );
|
2002-11-19 00:16:09 +01:00
|
|
|
ParseTopLevel( input_file );
|
|
|
|
switch (SpecType)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
2002-08-01 20:34:12 +02:00
|
|
|
if (argv[1])
|
|
|
|
fatal_error( "file argument '%s' not allowed in this mode\n", argv[1] );
|
2000-06-23 22:15:35 +02:00
|
|
|
BuildSpec16File( output_file );
|
|
|
|
break;
|
|
|
|
case SPEC_WIN32:
|
2002-08-01 20:34:12 +02:00
|
|
|
read_undef_symbols( argv + 1 );
|
2000-11-13 05:46:34 +01:00
|
|
|
BuildSpec32File( output_file );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
break;
|
2002-05-12 01:06:32 +02:00
|
|
|
case MODE_EXE:
|
2002-11-19 00:16:09 +01:00
|
|
|
if (SpecType == SPEC_WIN16) fatal_error( "Cannot build 16-bit exe files\n" );
|
2002-12-07 00:26:29 +01:00
|
|
|
load_resources( argv + 1 );
|
2002-08-01 20:34:12 +02:00
|
|
|
read_undef_symbols( argv + 1 );
|
2002-05-12 01:06:32 +02:00
|
|
|
BuildSpec32File( output_file );
|
|
|
|
break;
|
2002-02-04 19:48:18 +01:00
|
|
|
case MODE_DEF:
|
2002-08-01 20:34:12 +02:00
|
|
|
if (argv[1]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[1] );
|
2002-11-19 00:16:09 +01:00
|
|
|
if (SpecType == SPEC_WIN16) fatal_error( "Cannot yet build .def file for 16-bit dlls\n" );
|
|
|
|
ParseTopLevel( input_file );
|
|
|
|
BuildDef32File( output_file );
|
2002-02-04 19:48:18 +01:00
|
|
|
break;
|
2002-05-14 22:54:58 +02:00
|
|
|
case MODE_DEBUG:
|
2002-08-01 20:34:12 +02:00
|
|
|
BuildDebugFile( output_file, current_src_dir, argv + 1 );
|
2002-05-14 22:54:58 +02:00
|
|
|
break;
|
2000-06-23 22:15:35 +02:00
|
|
|
case MODE_GLUE:
|
2002-08-01 20:34:12 +02:00
|
|
|
BuildGlue( output_file, current_src_dir, argv + 1 );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
2001-12-11 01:50:33 +01:00
|
|
|
case MODE_RELAY16:
|
2002-08-01 20:34:12 +02:00
|
|
|
if (argv[1]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[1] );
|
2001-12-11 01:50:33 +01:00
|
|
|
BuildRelays16( output_file );
|
|
|
|
break;
|
|
|
|
case MODE_RELAY32:
|
2002-08-01 20:34:12 +02:00
|
|
|
if (argv[1]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[1] );
|
2001-12-11 01:50:33 +01:00
|
|
|
BuildRelays32( output_file );
|
2000-06-23 22:15:35 +02:00
|
|
|
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;
|
|
|
|
}
|