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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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>
|
2004-12-02 19:22:48 +01:00
|
|
|
#include <signal.h>
|
2000-07-15 17:13:09 +02:00
|
|
|
#include <errno.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2004-03-25 01:40:52 +01:00
|
|
|
#include <stdarg.h>
|
2002-09-17 01:58:59 +02:00
|
|
|
#include <ctype.h>
|
2003-03-23 02:12:30 +01:00
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
# include <getopt.h>
|
|
|
|
#endif
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
int UsePIC = 0;
|
2000-11-09 21:31:18 +01:00
|
|
|
int nb_lib_paths = 0;
|
2003-03-18 06:30:54 +01:00
|
|
|
int nb_errors = 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;
|
2005-09-21 12:22:28 +02:00
|
|
|
int verbose = 0;
|
|
|
|
int save_temps = 0;
|
2006-04-18 20:49:29 +02:00
|
|
|
int link_ext_symbols = 0;
|
2009-01-15 21:17:51 +01:00
|
|
|
int force_pointer_size = 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2004-10-20 01:09:02 +02:00
|
|
|
#ifdef __i386__
|
2005-06-27 13:23:24 +02:00
|
|
|
enum target_cpu target_cpu = CPU_x86;
|
2005-09-07 15:31:37 +02:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
enum target_cpu target_cpu = CPU_x86_64;
|
2005-06-27 13:23:24 +02:00
|
|
|
#elif defined(__sparc__)
|
|
|
|
enum target_cpu target_cpu = CPU_SPARC;
|
|
|
|
#elif defined(__ALPHA__)
|
|
|
|
enum target_cpu target_cpu = CPU_ALPHA;
|
|
|
|
#elif defined(__powerpc__)
|
|
|
|
enum target_cpu target_cpu = CPU_POWERPC;
|
2000-11-28 00:48:08 +01:00
|
|
|
#else
|
2005-06-27 13:23:24 +02:00
|
|
|
#error Unsupported CPU
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
enum target_platform target_platform = PLATFORM_APPLE;
|
2008-07-22 13:26:30 +02:00
|
|
|
#elif defined(__sun)
|
|
|
|
enum target_platform target_platform = PLATFORM_SOLARIS;
|
2005-06-27 13:23:24 +02:00
|
|
|
#elif defined(_WINDOWS)
|
|
|
|
enum target_platform target_platform = PLATFORM_WINDOWS;
|
|
|
|
#else
|
|
|
|
enum target_platform target_platform = PLATFORM_UNSPECIFIED;
|
2000-11-28 00:48:08 +01:00
|
|
|
#endif
|
|
|
|
|
2009-02-04 19:31:54 +01:00
|
|
|
char *target_alias = NULL;
|
2000-11-09 21:31:18 +01:00
|
|
|
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;
|
2005-03-15 16:42:32 +01:00
|
|
|
char *spec_file_name = NULL;
|
2006-08-11 20:41:29 +02:00
|
|
|
FILE *output_file = NULL;
|
2002-08-01 20:34:12 +02:00
|
|
|
const char *output_file_name = NULL;
|
2005-09-21 12:22:28 +02:00
|
|
|
static const char *output_file_source_name;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2005-09-19 19:04:43 +02:00
|
|
|
char *as_command = NULL;
|
2005-07-01 18:17:44 +02:00
|
|
|
char *ld_command = NULL;
|
|
|
|
char *nm_command = NULL;
|
2004-10-08 23:11:18 +02:00
|
|
|
|
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 */
|
2003-03-23 02:12:30 +01:00
|
|
|
enum exec_mode_values
|
2002-02-04 19:48:18 +01:00
|
|
|
{
|
|
|
|
MODE_NONE,
|
2004-02-17 21:36:16 +01:00
|
|
|
MODE_DLL,
|
2002-05-12 01:06:32 +02:00
|
|
|
MODE_EXE,
|
2002-02-04 19:48:18 +01:00
|
|
|
MODE_DEF,
|
|
|
|
MODE_RELAY16,
|
2009-05-30 21:39:50 +02:00
|
|
|
MODE_RELAY32,
|
|
|
|
MODE_RESOURCES
|
2003-03-23 02:12:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static enum exec_mode_values exec_mode = MODE_NONE;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2005-07-01 18:17:44 +02:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum target_platform platform;
|
|
|
|
} platform_names[] =
|
|
|
|
{
|
|
|
|
{ "macos", PLATFORM_APPLE },
|
|
|
|
{ "darwin", PLATFORM_APPLE },
|
2008-07-22 13:26:30 +02:00
|
|
|
{ "solaris", PLATFORM_SOLARIS },
|
2005-07-01 18:17:44 +02:00
|
|
|
{ "windows", PLATFORM_WINDOWS },
|
|
|
|
{ "winnt", PLATFORM_WINDOWS }
|
|
|
|
};
|
|
|
|
|
2002-07-28 19:52:01 +02:00
|
|
|
/* set the dll file name from the input file name */
|
2004-02-11 07:41:01 +01:00
|
|
|
static void set_dll_file_name( const char *name, DLLSPEC *spec )
|
2002-07-28 19:52:01 +02:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->file_name) return;
|
2003-01-02 18:48:05 +01:00
|
|
|
|
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;
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->file_name = xmalloc( strlen(name) + 5 );
|
|
|
|
strcpy( spec->file_name, name );
|
2004-02-17 21:36:16 +01:00
|
|
|
if ((p = strrchr( spec->file_name, '.' )))
|
|
|
|
{
|
|
|
|
if (!strcmp( p, ".spec" ) || !strcmp( p, ".def" )) *p = 0;
|
|
|
|
}
|
2002-07-28 19:52:01 +02:00
|
|
|
}
|
|
|
|
|
2004-03-25 01:40:52 +01:00
|
|
|
/* set the dll subsystem */
|
|
|
|
static void set_subsystem( const char *subsystem, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
char *major, *minor, *str = xstrdup( subsystem );
|
|
|
|
|
|
|
|
if ((major = strchr( str, ':' ))) *major++ = 0;
|
|
|
|
if (!strcmp( str, "native" )) spec->subsystem = IMAGE_SUBSYSTEM_NATIVE;
|
|
|
|
else if (!strcmp( str, "windows" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
|
|
|
|
else if (!strcmp( str, "console" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
2009-02-24 18:02:15 +01:00
|
|
|
else if (!strcmp( str, "win16" )) spec->type = SPEC_WIN16;
|
2004-03-25 01:40:52 +01:00
|
|
|
else fatal_error( "Invalid subsystem name '%s'\n", subsystem );
|
|
|
|
if (major)
|
|
|
|
{
|
|
|
|
if ((minor = strchr( major, '.' )))
|
|
|
|
{
|
|
|
|
*minor++ = 0;
|
|
|
|
spec->subsystem_minor = atoi( minor );
|
|
|
|
}
|
|
|
|
spec->subsystem_major = atoi( major );
|
|
|
|
}
|
|
|
|
free( str );
|
|
|
|
}
|
|
|
|
|
2005-07-01 18:17:44 +02:00
|
|
|
/* set the target CPU and platform */
|
|
|
|
static void set_target( const char *target )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
char *p, *platform, *spec = xstrdup( target );
|
|
|
|
|
|
|
|
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
|
|
|
|
|
2009-02-04 19:31:54 +01:00
|
|
|
target_alias = xstrdup( target );
|
|
|
|
|
2005-07-01 18:17:44 +02:00
|
|
|
/* get the CPU part */
|
|
|
|
|
|
|
|
if (!(p = strchr( spec, '-' ))) fatal_error( "Invalid target specification '%s'\n", target );
|
|
|
|
*p++ = 0;
|
2008-12-08 17:07:50 +01:00
|
|
|
if ((target_cpu = get_cpu_from_name( spec )) == -1)
|
|
|
|
fatal_error( "Unrecognized CPU '%s'\n", spec );
|
2005-07-01 18:17:44 +02:00
|
|
|
platform = p;
|
|
|
|
if ((p = strrchr( p, '-' ))) platform = p + 1;
|
|
|
|
|
|
|
|
/* get the OS part */
|
|
|
|
|
|
|
|
target_platform = PLATFORM_UNSPECIFIED; /* default value */
|
|
|
|
for (i = 0; i < sizeof(platform_names)/sizeof(platform_names[0]); i++)
|
|
|
|
{
|
|
|
|
if (!strncmp( platform_names[i].name, platform, strlen(platform_names[i].name) ))
|
|
|
|
{
|
|
|
|
target_platform = platform_names[i].platform;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free( spec );
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* cleanup on program exit */
|
|
|
|
static void cleanup(void)
|
|
|
|
{
|
|
|
|
if (output_file_name) unlink( output_file_name );
|
|
|
|
}
|
|
|
|
|
2004-12-02 19:22:48 +01:00
|
|
|
/* clean things up when aborting on a signal */
|
|
|
|
static void exit_on_signal( int sig )
|
|
|
|
{
|
|
|
|
exit(1); /* this will call atexit functions */
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* command-line option handling
|
|
|
|
*/
|
2003-03-23 02:12:30 +01:00
|
|
|
static const char usage_str[] =
|
|
|
|
"Usage: winebuild [OPTIONS] [FILES]\n\n"
|
|
|
|
"Options:\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" --as-cmd=AS Command to use for assembling (default: as)\n"
|
|
|
|
" -b, --target=TARGET Specify target CPU and platform for cross-compiling\n"
|
|
|
|
" -d, --delay-lib=LIB Import the specified library in delayed mode\n"
|
|
|
|
" -D SYM Ignored for C flags compatibility\n"
|
|
|
|
" -e, --entry=FUNC Set the DLL entry point function (default: DllMain)\n"
|
|
|
|
" -E, --export=FILE Export the symbols defined in the .spec or .def file\n"
|
|
|
|
" --external-symbols Allow linking to external symbols\n"
|
|
|
|
" -f FLAGS Compiler flags (only -fPIC is supported)\n"
|
|
|
|
" -F, --filename=DLLFILE Set the DLL filename (default: from input file name)\n"
|
|
|
|
" -h, --help Display this help message\n"
|
|
|
|
" -H, --heap=SIZE Set the heap size for a Win16 dll\n"
|
|
|
|
" -i, --ignore=SYM[,SYM] Ignore specified symbols when resolving imports\n"
|
|
|
|
" -I DIR Ignored for C flags compatibility\n"
|
|
|
|
" -k, --kill-at Kill stdcall decorations in generated .def files\n"
|
|
|
|
" -K, FLAGS Compiler flags (only -KPIC is supported)\n"
|
|
|
|
" --large-address-aware Support an address space larger than 2Gb\n"
|
|
|
|
" --ld-cmd=LD Command to use for linking (default: ld)\n"
|
|
|
|
" -l, --library=LIB Import the specified library\n"
|
|
|
|
" -L, --library-path=DIR Look for imports libraries in DIR\n"
|
|
|
|
" -m32, -m64 Force building 32-bit resp. 64-bit code\n"
|
|
|
|
" -M, --main-module=MODULE Set the name of the main module for a Win16 dll\n"
|
|
|
|
" --nm-cmd=NM Command to use to get undefined symbols (default: nm)\n"
|
|
|
|
" --nxcompat=y|n Set the NX compatibility flag (default: yes)\n"
|
|
|
|
" -N, --dll-name=DLLNAME Set the DLL name (default: from input file name)\n"
|
|
|
|
" -o, --output=NAME Set the output file name (default: stdout)\n"
|
|
|
|
" -r, --res=RSRC.RES Load resources from RSRC.RES\n"
|
|
|
|
" --save-temps Do not delete the generated intermediate files\n"
|
|
|
|
" --subsystem=SUBSYS Set the subsystem (one of native, windows, console)\n"
|
|
|
|
" -u, --undefined=SYMBOL Add an undefined reference to SYMBOL when linking\n"
|
|
|
|
" -v, --verbose Display the programs invoked\n"
|
|
|
|
" --version Print the version and exit\n"
|
|
|
|
" -w, --warnings Turn on warnings\n"
|
2003-03-23 02:12:30 +01:00
|
|
|
"\nMode options:\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" --dll Build a .c file from a .spec or .def file\n"
|
|
|
|
" --def Build a .def file from a .spec file\n"
|
|
|
|
" --exe Build a .c file for an executable\n"
|
|
|
|
" --relay16 Build the 16-bit relay assembly routines\n"
|
2009-06-22 11:46:33 +02:00
|
|
|
" --relay32 Build the 32-bit relay assembly routines\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" --resources Build a .o file for the resource files\n\n"
|
2003-03-23 02:12:30 +01:00
|
|
|
"The mode options are mutually exclusive; you must specify one and only one.\n\n";
|
|
|
|
|
|
|
|
enum long_options_values
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
LONG_OPT_DLL = 1,
|
2003-03-23 02:12:30 +01:00
|
|
|
LONG_OPT_DEF,
|
|
|
|
LONG_OPT_EXE,
|
2005-09-19 19:04:43 +02:00
|
|
|
LONG_OPT_ASCMD,
|
2006-04-18 20:49:29 +02:00
|
|
|
LONG_OPT_EXTERNAL_SYMS,
|
2009-06-17 16:10:35 +02:00
|
|
|
LONG_OPT_LARGE_ADDRESS_AWARE,
|
2004-10-08 23:11:18 +02:00
|
|
|
LONG_OPT_LDCMD,
|
|
|
|
LONG_OPT_NMCMD,
|
2006-12-07 20:51:49 +01:00
|
|
|
LONG_OPT_NXCOMPAT,
|
2003-03-23 02:12:30 +01:00
|
|
|
LONG_OPT_RELAY16,
|
|
|
|
LONG_OPT_RELAY32,
|
2009-05-30 21:39:50 +02:00
|
|
|
LONG_OPT_RESOURCES,
|
2005-09-21 12:22:28 +02:00
|
|
|
LONG_OPT_SAVE_TEMPS,
|
2004-03-25 01:40:52 +01:00
|
|
|
LONG_OPT_SUBSYSTEM,
|
2003-03-23 02:12:30 +01:00
|
|
|
LONG_OPT_VERSION
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
2009-01-14 12:52:53 +01:00
|
|
|
static const char short_options[] = "C:D:E:F:H:I:K:L:M:N:b:d:e:f:hi:kl:m:o:r:u:vw";
|
2003-03-23 02:12:30 +01:00
|
|
|
|
|
|
|
static const struct option long_options[] =
|
|
|
|
{
|
2006-04-18 20:49:29 +02:00
|
|
|
{ "dll", 0, 0, LONG_OPT_DLL },
|
|
|
|
{ "def", 0, 0, LONG_OPT_DEF },
|
|
|
|
{ "exe", 0, 0, LONG_OPT_EXE },
|
|
|
|
{ "as-cmd", 1, 0, LONG_OPT_ASCMD },
|
|
|
|
{ "external-symbols", 0, 0, LONG_OPT_EXTERNAL_SYMS },
|
2009-06-17 16:10:35 +02:00
|
|
|
{ "large-address-aware", 0, 0, LONG_OPT_LARGE_ADDRESS_AWARE },
|
2006-04-18 20:49:29 +02:00
|
|
|
{ "ld-cmd", 1, 0, LONG_OPT_LDCMD },
|
|
|
|
{ "nm-cmd", 1, 0, LONG_OPT_NMCMD },
|
2006-12-07 20:51:49 +01:00
|
|
|
{ "nxcompat", 1, 0, LONG_OPT_NXCOMPAT },
|
2006-04-18 20:49:29 +02:00
|
|
|
{ "relay16", 0, 0, LONG_OPT_RELAY16 },
|
|
|
|
{ "relay32", 0, 0, LONG_OPT_RELAY32 },
|
2009-05-30 21:39:50 +02:00
|
|
|
{ "resources", 0, 0, LONG_OPT_RESOURCES },
|
2006-04-18 20:49:29 +02:00
|
|
|
{ "save-temps", 0, 0, LONG_OPT_SAVE_TEMPS },
|
|
|
|
{ "subsystem", 1, 0, LONG_OPT_SUBSYSTEM },
|
|
|
|
{ "version", 0, 0, LONG_OPT_VERSION },
|
2003-03-23 02:12:30 +01:00
|
|
|
/* aliases for short options */
|
2009-01-14 12:52:53 +01:00
|
|
|
{ "target", 1, 0, 'b' },
|
2003-03-23 02:12:30 +01:00
|
|
|
{ "delay-lib", 1, 0, 'd' },
|
2005-03-08 17:55:26 +01:00
|
|
|
{ "export", 1, 0, 'E' },
|
2003-03-23 02:12:30 +01:00
|
|
|
{ "entry", 1, 0, 'e' },
|
|
|
|
{ "filename", 1, 0, 'F' },
|
|
|
|
{ "help", 0, 0, 'h' },
|
|
|
|
{ "heap", 1, 0, 'H' },
|
|
|
|
{ "ignore", 1, 0, 'i' },
|
|
|
|
{ "kill-at", 0, 0, 'k' },
|
|
|
|
{ "library", 1, 0, 'l' },
|
|
|
|
{ "library-path", 1, 0, 'L' },
|
|
|
|
{ "main-module", 1, 0, 'M' },
|
|
|
|
{ "dll-name", 1, 0, 'N' },
|
|
|
|
{ "output", 1, 0, 'o' },
|
|
|
|
{ "res", 1, 0, 'r' },
|
2005-08-19 13:28:56 +02:00
|
|
|
{ "undefined", 1, 0, 'u' },
|
2005-09-21 12:22:28 +02:00
|
|
|
{ "verbose", 0, 0, 'v' },
|
2003-03-23 02:12:30 +01:00
|
|
|
{ "warnings", 0, 0, 'w' },
|
|
|
|
{ NULL, 0, 0, 0 }
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
static void usage( int exit_code )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-23 02:12:30 +01:00
|
|
|
fprintf( stderr, "%s", usage_str );
|
|
|
|
exit( exit_code );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
static void set_exec_mode( enum exec_mode_values mode )
|
2002-02-04 19:48:18 +01:00
|
|
|
{
|
2003-03-23 02:12:30 +01:00
|
|
|
if (exec_mode != MODE_NONE) usage(1);
|
|
|
|
exec_mode = mode;
|
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 */
|
2004-02-11 07:41:01 +01:00
|
|
|
static char **parse_options( int argc, char **argv, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-04-01 02:08:32 +02:00
|
|
|
char *p;
|
2003-03-23 02:12:30 +01:00
|
|
|
int optc;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
while ((optc = getopt_long( argc, argv, short_options, long_options, NULL )) != -1)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-23 02:12:30 +01:00
|
|
|
switch(optc)
|
2002-11-06 21:02:59 +01:00
|
|
|
{
|
2003-03-23 02:12:30 +01:00
|
|
|
case 'D':
|
|
|
|
/* ignored */
|
|
|
|
break;
|
2005-03-08 17:55:26 +01:00
|
|
|
case 'E':
|
|
|
|
spec_file_name = xstrdup( optarg );
|
|
|
|
set_dll_file_name( optarg, spec );
|
|
|
|
break;
|
2003-03-23 02:12:30 +01:00
|
|
|
case 'F':
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->file_name = xstrdup( optarg );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
if (!isdigit(optarg[0]))
|
|
|
|
fatal_error( "Expected number argument with -H option instead of '%s'\n", optarg );
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->heap_size = atoi(optarg);
|
|
|
|
if (spec->heap_size > 65535)
|
|
|
|
fatal_error( "Invalid heap size %d, maximum is 65535\n", spec->heap_size );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
/* ignored, because cc generates correct code. */
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
|
|
|
|
lib_path[nb_lib_paths++] = xstrdup( optarg );
|
|
|
|
break;
|
2009-01-15 21:17:51 +01:00
|
|
|
case 'm':
|
|
|
|
if (strcmp( optarg, "32" ) && strcmp( optarg, "64" ))
|
|
|
|
fatal_error( "Invalid -m option '%s', expected -m32 or -m64\n", optarg );
|
|
|
|
if (!strcmp( optarg, "32" )) force_pointer_size = 4;
|
|
|
|
else force_pointer_size = 8;
|
|
|
|
break;
|
2003-03-23 02:12:30 +01:00
|
|
|
case 'M':
|
2009-03-04 14:08:23 +01:00
|
|
|
spec->main_module = xstrdup( optarg );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'N':
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->dll_name = xstrdup( optarg );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
2009-01-14 12:52:53 +01:00
|
|
|
case 'b':
|
|
|
|
set_target( optarg );
|
|
|
|
break;
|
2003-03-23 02:12:30 +01:00
|
|
|
case 'd':
|
2005-05-06 17:54:41 +02:00
|
|
|
add_delayed_import( optarg );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'e':
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->init_func = xstrdup( optarg );
|
|
|
|
if ((p = strchr( spec->init_func, '@' ))) *p = 0; /* kill stdcall decoration */
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
if (!strcmp( optarg, "PIC") || !strcmp( optarg, "pic")) UsePIC = 1;
|
|
|
|
/* ignore all other flags */
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(0);
|
|
|
|
break;
|
|
|
|
case 'i':
|
2000-11-16 00:12:06 +01:00
|
|
|
{
|
2003-03-23 02:12:30 +01:00
|
|
|
char *str = xstrdup( optarg );
|
|
|
|
char *token = strtok( str, "," );
|
|
|
|
while (token)
|
2002-11-06 21:02:59 +01:00
|
|
|
{
|
2003-03-23 02:12:30 +01:00
|
|
|
add_ignore_symbol( token );
|
|
|
|
token = strtok( NULL, "," );
|
2002-11-06 21:02:59 +01:00
|
|
|
}
|
2003-03-23 02:12:30 +01:00
|
|
|
free( str );
|
2000-11-16 00:12:06 +01:00
|
|
|
}
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
kill_at = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2005-05-06 17:54:41 +02:00
|
|
|
add_import_dll( optarg, NULL );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'o':
|
2005-09-21 12:22:28 +02:00
|
|
|
{
|
|
|
|
char *ext = strrchr( optarg, '.' );
|
|
|
|
|
|
|
|
if (unlink( optarg ) == -1 && errno != ENOENT)
|
|
|
|
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
|
|
if (ext && !strcmp( ext, ".o" ))
|
|
|
|
{
|
|
|
|
output_file_source_name = get_temp_file_name( optarg, ".s" );
|
|
|
|
if (!(output_file = fopen( output_file_source_name, "w" )))
|
|
|
|
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(output_file = fopen( optarg, "w" )))
|
|
|
|
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
|
|
}
|
|
|
|
output_file_name = xstrdup(optarg);
|
|
|
|
atexit( cleanup ); /* make sure we remove the output file on exit */
|
|
|
|
}
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
res_files = xrealloc( res_files, (nb_res_files+1) * sizeof(*res_files) );
|
|
|
|
res_files[nb_res_files++] = xstrdup( optarg );
|
|
|
|
break;
|
2005-08-19 13:28:56 +02:00
|
|
|
case 'u':
|
|
|
|
add_extra_ld_symbol( optarg );
|
|
|
|
break;
|
2005-09-21 12:22:28 +02:00
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
2003-03-23 02:12:30 +01:00
|
|
|
case 'w':
|
|
|
|
display_warnings = 1;
|
|
|
|
break;
|
2004-02-17 21:36:16 +01:00
|
|
|
case LONG_OPT_DLL:
|
|
|
|
set_exec_mode( MODE_DLL );
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
|
|
|
case LONG_OPT_DEF:
|
|
|
|
set_exec_mode( MODE_DEF );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_EXE:
|
|
|
|
set_exec_mode( MODE_EXE );
|
2004-03-25 01:40:52 +01:00
|
|
|
if (!spec->subsystem) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
|
2003-03-23 02:12:30 +01:00
|
|
|
break;
|
2005-09-19 19:04:43 +02:00
|
|
|
case LONG_OPT_ASCMD:
|
|
|
|
as_command = xstrdup( optarg );
|
|
|
|
break;
|
2006-04-18 20:49:29 +02:00
|
|
|
case LONG_OPT_EXTERNAL_SYMS:
|
|
|
|
link_ext_symbols = 1;
|
|
|
|
break;
|
2009-06-17 16:10:35 +02:00
|
|
|
case LONG_OPT_LARGE_ADDRESS_AWARE:
|
|
|
|
spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
|
|
|
|
break;
|
2004-10-08 23:11:18 +02:00
|
|
|
case LONG_OPT_LDCMD:
|
|
|
|
ld_command = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_NMCMD:
|
|
|
|
nm_command = xstrdup( optarg );
|
|
|
|
break;
|
2006-12-07 20:51:49 +01:00
|
|
|
case LONG_OPT_NXCOMPAT:
|
|
|
|
if (optarg[0] == 'n' || optarg[0] == 'N')
|
|
|
|
spec->dll_characteristics &= ~IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
|
|
|
|
break;
|
2003-03-23 02:12:30 +01:00
|
|
|
case LONG_OPT_RELAY16:
|
|
|
|
set_exec_mode( MODE_RELAY16 );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_RELAY32:
|
|
|
|
set_exec_mode( MODE_RELAY32 );
|
|
|
|
break;
|
2009-05-30 21:39:50 +02:00
|
|
|
case LONG_OPT_RESOURCES:
|
|
|
|
set_exec_mode( MODE_RESOURCES );
|
|
|
|
break;
|
2005-09-21 12:22:28 +02:00
|
|
|
case LONG_OPT_SAVE_TEMPS:
|
|
|
|
save_temps = 1;
|
|
|
|
break;
|
2004-03-25 01:40:52 +01:00
|
|
|
case LONG_OPT_SUBSYSTEM:
|
|
|
|
set_subsystem( optarg, spec );
|
|
|
|
break;
|
2003-03-23 02:12:30 +01:00
|
|
|
case LONG_OPT_VERSION:
|
|
|
|
printf( "winebuild version " PACKAGE_VERSION "\n" );
|
|
|
|
exit(0);
|
|
|
|
case '?':
|
|
|
|
usage(1);
|
|
|
|
break;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-08 17:55:26 +01:00
|
|
|
|
|
|
|
if (spec->file_name && !strchr( spec->file_name, '.' ))
|
|
|
|
strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
|
|
|
|
|
2009-01-15 21:17:51 +01:00
|
|
|
switch (target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
if (force_pointer_size == 8) target_cpu = CPU_x86_64;
|
|
|
|
break;
|
|
|
|
case CPU_x86_64:
|
|
|
|
if (force_pointer_size == 4) target_cpu = CPU_x86;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (force_pointer_size == 8)
|
|
|
|
fatal_error( "Cannot build 64-bit code for this CPU\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
return &argv[optind];
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-19 00:16:09 +01:00
|
|
|
/* load all specified resource files */
|
2004-02-11 07:41:01 +01:00
|
|
|
static void load_resources( char *argv[], DLLSPEC *spec )
|
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
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
switch (spec->type)
|
2002-11-19 00:16:09 +01:00
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0; i < nb_res_files; i++) load_res16_file( res_files[i], spec );
|
2002-11-19 00:16:09 +01:00
|
|
|
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++)
|
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
if (!load_res32_file( res_files[i], spec ))
|
2002-12-07 00:26:29 +01:00
|
|
|
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++)
|
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
if (!load_res32_file( *ptr, spec ))
|
2002-12-07 00:26:29 +01:00
|
|
|
*last++ = *ptr; /* not a resource file, keep it in the list */
|
|
|
|
}
|
|
|
|
*last = NULL;
|
2002-11-19 00:16:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
/* add input files that look like import libs to the import list */
|
|
|
|
static void load_import_libs( char *argv[] )
|
|
|
|
{
|
|
|
|
char **ptr, **last;
|
|
|
|
|
|
|
|
for (ptr = last = argv; *ptr; ptr++)
|
|
|
|
{
|
|
|
|
if (strendswith( *ptr, ".def" ))
|
|
|
|
add_import_dll( NULL, *ptr );
|
|
|
|
else
|
|
|
|
*last++ = *ptr; /* not an import dll, keep it in the list */
|
|
|
|
}
|
|
|
|
*last = NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_input_file( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
FILE *input_file = open_input_file( NULL, spec_file_name );
|
|
|
|
char *extension = strrchr( spec_file_name, '.' );
|
2005-03-08 17:55:26 +01:00
|
|
|
int result;
|
2004-02-17 21:36:16 +01:00
|
|
|
|
2006-04-18 20:49:29 +02:00
|
|
|
spec->src_name = xstrdup( input_file_name );
|
2004-02-17 21:36:16 +01:00
|
|
|
if (extension && !strcmp( extension, ".def" ))
|
2005-03-08 17:55:26 +01:00
|
|
|
result = parse_def_file( input_file, spec );
|
2004-02-17 21:36:16 +01:00
|
|
|
else
|
2005-03-08 17:55:26 +01:00
|
|
|
result = parse_spec_file( input_file, spec );
|
2004-02-17 21:36:16 +01:00
|
|
|
close_input_file( input_file );
|
2005-03-08 17:55:26 +01:00
|
|
|
return result;
|
2004-02-17 21:36:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* main
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
DLLSPEC *spec = alloc_dll_spec();
|
2004-02-11 07:41:01 +01:00
|
|
|
|
2004-12-07 18:19:54 +01:00
|
|
|
#ifdef SIGHUP
|
2004-12-02 19:22:48 +01:00
|
|
|
signal( SIGHUP, exit_on_signal );
|
2004-12-07 18:19:54 +01:00
|
|
|
#endif
|
2004-12-02 19:22:48 +01:00
|
|
|
signal( SIGTERM, exit_on_signal );
|
|
|
|
signal( SIGINT, exit_on_signal );
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
output_file = stdout;
|
2004-02-17 21:36:16 +01:00
|
|
|
argv = parse_options( argc, argv, spec );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
switch(exec_mode)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
case MODE_DLL:
|
2007-12-11 12:52:26 +01:00
|
|
|
if (spec->subsystem != IMAGE_SUBSYSTEM_NATIVE)
|
|
|
|
spec->characteristics |= IMAGE_FILE_DLL;
|
2008-03-03 15:19:53 +01:00
|
|
|
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
2009-03-04 14:08:23 +01:00
|
|
|
if (spec->type == SPEC_WIN32 && spec->main_module) /* embedded 16-bit module */
|
|
|
|
{
|
|
|
|
spec->type = SPEC_WIN16;
|
|
|
|
load_resources( argv, spec );
|
|
|
|
if (parse_input_file( spec )) BuildSpec16File( spec );
|
|
|
|
break;
|
|
|
|
}
|
2008-03-03 15:19:53 +01:00
|
|
|
/* fall through */
|
|
|
|
case MODE_EXE:
|
2004-02-17 21:36:16 +01:00
|
|
|
load_resources( argv, spec );
|
2005-05-06 17:54:41 +02:00
|
|
|
load_import_libs( argv );
|
2008-03-03 15:19:53 +01:00
|
|
|
if (spec_file_name && !parse_input_file( spec )) break;
|
2009-03-04 14:08:23 +01:00
|
|
|
read_undef_symbols( spec, argv );
|
2004-02-17 21:36:16 +01:00
|
|
|
switch (spec->type)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
2009-03-04 14:08:23 +01:00
|
|
|
output_spec16_file( spec );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case SPEC_WIN32:
|
2006-08-11 20:41:29 +02:00
|
|
|
BuildSpec32File( spec );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
break;
|
2002-02-04 19:48:18 +01:00
|
|
|
case MODE_DEF:
|
2003-03-23 02:12:30 +01:00
|
|
|
if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
|
2004-02-17 21:36:16 +01:00
|
|
|
if (spec->type == SPEC_WIN16) fatal_error( "Cannot yet build .def file for 16-bit dlls\n" );
|
2005-03-08 17:55:26 +01:00
|
|
|
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_input_file( spec )) break;
|
2006-08-11 20:41:29 +02:00
|
|
|
BuildDef32File( spec );
|
2002-02-04 19:48:18 +01:00
|
|
|
break;
|
2001-12-11 01:50:33 +01:00
|
|
|
case MODE_RELAY16:
|
2003-03-23 02:12:30 +01:00
|
|
|
if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
|
2006-08-11 20:41:29 +02:00
|
|
|
BuildRelays16();
|
2001-12-11 01:50:33 +01:00
|
|
|
break;
|
|
|
|
case MODE_RELAY32:
|
2003-03-23 02:12:30 +01:00
|
|
|
if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
|
2006-08-11 20:41:29 +02:00
|
|
|
BuildRelays32();
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
2009-05-30 21:39:50 +02:00
|
|
|
case MODE_RESOURCES:
|
|
|
|
load_resources( argv, spec );
|
|
|
|
output_res_o_file( spec );
|
|
|
|
break;
|
2000-06-23 22:15:35 +02:00
|
|
|
default:
|
2003-03-23 02:12:30 +01:00
|
|
|
usage(1);
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
if (nb_errors) exit(1);
|
2001-05-22 21:55:51 +02:00
|
|
|
if (output_file_name)
|
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
if (fclose( output_file ) < 0) fatal_perror( "fclose" );
|
2005-09-21 12:22:28 +02:00
|
|
|
if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
|
2001-05-22 21:55:51 +02:00
|
|
|
output_file_name = NULL;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|