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"
|
|
|
|
|
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>
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
int UsePIC = 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;
|
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;
|
2010-04-11 12:07:44 +02:00
|
|
|
int unwind_tables = 0;
|
2020-07-01 10:36:30 +02:00
|
|
|
int use_msvcrt = 0;
|
2019-06-17 09:24:25 +02:00
|
|
|
int unix_lib = 0;
|
2020-05-06 16:18:31 +02:00
|
|
|
int safe_seh = 0;
|
2021-02-18 11:06:06 +01:00
|
|
|
int prefer_native = 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
struct target target = { 0 };
|
2000-11-28 00:48:08 +01:00
|
|
|
|
2009-02-04 19:31:54 +01:00
|
|
|
char *target_alias = 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;
|
2021-10-05 11:52:49 +02:00
|
|
|
static int save_temps;
|
2009-08-14 14:16:38 +02:00
|
|
|
static int fake_module;
|
2021-10-05 11:52:49 +02:00
|
|
|
static DLLSPEC *main_spec;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2021-09-23 12:23:25 +02:00
|
|
|
static const struct strarray empty_strarray;
|
2016-03-19 05:22:30 +01:00
|
|
|
struct strarray lib_path = { 0 };
|
2019-09-10 17:53:19 +02:00
|
|
|
struct strarray tools_path = { 0 };
|
2016-03-19 05:10:09 +01:00
|
|
|
struct strarray as_command = { 0 };
|
|
|
|
struct strarray cc_command = { 0 };
|
|
|
|
struct strarray ld_command = { 0 };
|
|
|
|
struct strarray nm_command = { 0 };
|
2011-04-27 19:45:11 +02:00
|
|
|
char *cpu_option = NULL;
|
2018-11-05 20:20:25 +01:00
|
|
|
char *fpu_option = NULL;
|
2015-12-13 21:01:19 +01:00
|
|
|
char *arch_option = NULL;
|
2017-12-08 11:55:30 +01:00
|
|
|
#ifdef __SOFTFP__
|
|
|
|
const char *float_abi_option = "soft";
|
|
|
|
#else
|
|
|
|
const char *float_abi_option = "softfp";
|
|
|
|
#endif
|
2004-10-08 23:11:18 +02:00
|
|
|
|
2014-02-12 12:57:27 +01:00
|
|
|
#ifdef __thumb__
|
|
|
|
int thumb_mode = 1;
|
|
|
|
#else
|
|
|
|
int thumb_mode = 0;
|
|
|
|
#endif
|
|
|
|
|
2016-03-19 05:22:30 +01:00
|
|
|
static struct strarray 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,
|
2009-12-30 11:51:19 +01:00
|
|
|
MODE_IMPLIB,
|
2020-03-04 17:15:34 +01:00
|
|
|
MODE_STATICLIB,
|
2019-12-18 21:05:27 +01:00
|
|
|
MODE_BUILTIN,
|
2020-04-16 12:21:23 +02:00
|
|
|
MODE_FIXUP_CTORS,
|
2009-05-30 21:39:50 +02:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
name = get_basename( name );
|
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
|
|
|
}
|
|
|
|
|
2009-12-30 12:12:13 +01:00
|
|
|
/* set the dll name from the file name */
|
|
|
|
static void init_dll_name( DLLSPEC *spec )
|
|
|
|
{
|
2010-09-07 16:36:55 +02:00
|
|
|
if (!spec->file_name && output_file_name)
|
2009-12-30 12:12:13 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
spec->file_name = xstrdup( output_file_name );
|
|
|
|
if ((p = strrchr( spec->file_name, '.' ))) *p = 0;
|
|
|
|
}
|
2010-09-07 16:36:55 +02:00
|
|
|
if (!spec->dll_name && spec->file_name) /* set default name from file name */
|
2009-12-30 12:12:13 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
spec->dll_name = xstrdup( spec->file_name );
|
|
|
|
if ((p = strrchr( spec->dll_name, '.' ))) *p = 0;
|
|
|
|
}
|
2019-01-12 23:01:08 +01:00
|
|
|
if (spec->dll_name) spec->c_name = make_c_identifier( spec->dll_name );
|
2009-12-30 12:12:13 +01: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;
|
2010-11-08 18:52:12 +01:00
|
|
|
else if (!strcmp( str, "wince" )) spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CE_GUI;
|
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 );
|
|
|
|
}
|
|
|
|
|
2021-08-30 11:46:51 +02:00
|
|
|
/* set the syscall table id */
|
|
|
|
static void set_syscall_table( const char *id, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int val = atoi( id );
|
|
|
|
|
|
|
|
if (val < 0 || val > 3) fatal_error( "Invalid syscall table id '%s', must be 0-3\n", id );
|
|
|
|
spec->syscall_table = val;
|
|
|
|
}
|
|
|
|
|
2005-07-01 18:17:44 +02:00
|
|
|
/* set the target CPU and platform */
|
2021-11-16 21:02:12 +01:00
|
|
|
static void set_target( const char *name )
|
2005-07-01 18:17:44 +02:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
target_alias = xstrdup( name );
|
2005-07-01 18:17:44 +02:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (!parse_target( name, &target )) fatal_error( "Unrecognized target '%s'\n", name );
|
|
|
|
if (target.cpu == CPU_ARM && is_pe()) thumb_mode = 1;
|
2005-07-01 18:17:44 +02:00
|
|
|
}
|
|
|
|
|
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"
|
2019-09-10 17:53:19 +02:00
|
|
|
" -B PREFIX Look for build tools in the PREFIX directory\n"
|
2013-06-10 13:19:29 +02:00
|
|
|
" --cc-cmd=CC C compiler to use for assembling (default: fall back to --as-cmd)\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" -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"
|
2010-04-11 12:07:44 +02:00
|
|
|
" -f FLAGS Compiler flags (-fPIC and -fasynchronous-unwind-tables are supported)\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" -F, --filename=DLLFILE Set the DLL filename (default: from input file name)\n"
|
2009-08-14 14:16:38 +02:00
|
|
|
" --fake-module Create a fake binary module\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" -h, --help Display this help message\n"
|
|
|
|
" -H, --heap=SIZE Set the heap size for a Win16 dll\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"
|
2010-07-21 12:43:53 +02:00
|
|
|
" -m16, -m32, -m64 Force building 16-bit, 32-bit resp. 64-bit code\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" -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"
|
2021-02-18 11:06:06 +01:00
|
|
|
" --prefer-native Set the flag to prefer loading native at run time\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" -r, --res=RSRC.RES Load resources from RSRC.RES\n"
|
2020-05-06 16:18:31 +02:00
|
|
|
" --safeseh Mark object files as SEH compatible\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" --save-temps Do not delete the generated intermediate files\n"
|
2010-11-08 18:52:12 +01:00
|
|
|
" --subsystem=SUBSYS Set the subsystem (one of native, windows, console, wince)\n"
|
2021-08-30 11:46:51 +02:00
|
|
|
" --syscall-table=ID Set the syscall table id (between 0 and 3)\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" -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"
|
2019-12-18 21:05:27 +01:00
|
|
|
" --dll Build a library from a .spec file and object files\n"
|
2009-06-17 16:10:35 +02:00
|
|
|
" --def Build a .def file from a .spec file\n"
|
2019-12-18 21:05:27 +01:00
|
|
|
" --exe Build an executable from object files\n"
|
2009-12-30 11:51:19 +01:00
|
|
|
" --implib Build an import library\n"
|
2020-03-04 17:15:34 +01:00
|
|
|
" --staticlib Build a static library\n"
|
2019-12-18 21:05:27 +01:00
|
|
|
" --resources Build a .o or .res file for the resource files\n\n"
|
2020-04-16 12:21:23 +02:00
|
|
|
" --builtin Mark a library as a Wine builtin\n"
|
|
|
|
" --fixup-ctors Fixup the constructors data after the module has been built\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,
|
2009-12-30 11:51:19 +01:00
|
|
|
LONG_OPT_IMPLIB,
|
2019-12-18 21:05:27 +01:00
|
|
|
LONG_OPT_BUILTIN,
|
2005-09-19 19:04:43 +02:00
|
|
|
LONG_OPT_ASCMD,
|
2013-06-10 13:19:29 +02:00
|
|
|
LONG_OPT_CCCMD,
|
2006-04-18 20:49:29 +02:00
|
|
|
LONG_OPT_EXTERNAL_SYMS,
|
2009-08-14 14:16:38 +02:00
|
|
|
LONG_OPT_FAKE_MODULE,
|
2020-04-16 12:21:23 +02:00
|
|
|
LONG_OPT_FIXUP_CTORS,
|
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,
|
2021-02-18 11:06:06 +01:00
|
|
|
LONG_OPT_PREFER_NATIVE,
|
2009-05-30 21:39:50 +02:00
|
|
|
LONG_OPT_RESOURCES,
|
2020-05-06 16:18:31 +02:00
|
|
|
LONG_OPT_SAFE_SEH,
|
2005-09-21 12:22:28 +02:00
|
|
|
LONG_OPT_SAVE_TEMPS,
|
2020-03-04 17:15:34 +01:00
|
|
|
LONG_OPT_STATICLIB,
|
2004-03-25 01:40:52 +01:00
|
|
|
LONG_OPT_SUBSYSTEM,
|
2021-08-30 11:46:51 +02:00
|
|
|
LONG_OPT_SYSCALL_TABLE,
|
2003-03-23 02:12:30 +01:00
|
|
|
LONG_OPT_VERSION
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
2019-09-10 17:53:19 +02:00
|
|
|
static const char short_options[] = "B:C:D:E:F:H:I:K:L:M:N:b:d:e:f:hkl:m:o:r:u:vw";
|
2003-03-23 02:12:30 +01:00
|
|
|
|
2021-10-05 11:52:49 +02:00
|
|
|
static const struct long_option long_options[] =
|
2003-03-23 02:12:30 +01:00
|
|
|
{
|
2021-10-05 11:52:49 +02:00
|
|
|
/* mode options */
|
|
|
|
{ "dll", 0, LONG_OPT_DLL },
|
|
|
|
{ "def", 0, LONG_OPT_DEF },
|
|
|
|
{ "exe", 0, LONG_OPT_EXE },
|
|
|
|
{ "implib", 0, LONG_OPT_IMPLIB },
|
|
|
|
{ "staticlib", 0, LONG_OPT_STATICLIB },
|
|
|
|
{ "builtin", 0, LONG_OPT_BUILTIN },
|
|
|
|
{ "resources", 0, LONG_OPT_RESOURCES },
|
|
|
|
{ "fixup-ctors", 0, LONG_OPT_FIXUP_CTORS },
|
|
|
|
/* other long options */
|
|
|
|
{ "as-cmd", 1, LONG_OPT_ASCMD },
|
|
|
|
{ "cc-cmd", 1, LONG_OPT_CCCMD },
|
|
|
|
{ "external-symbols", 0, LONG_OPT_EXTERNAL_SYMS },
|
|
|
|
{ "fake-module", 0, LONG_OPT_FAKE_MODULE },
|
|
|
|
{ "large-address-aware", 0, LONG_OPT_LARGE_ADDRESS_AWARE },
|
|
|
|
{ "ld-cmd", 1, LONG_OPT_LDCMD },
|
|
|
|
{ "nm-cmd", 1, LONG_OPT_NMCMD },
|
|
|
|
{ "nxcompat", 1, LONG_OPT_NXCOMPAT },
|
|
|
|
{ "prefer-native", 0, LONG_OPT_PREFER_NATIVE },
|
|
|
|
{ "safeseh", 0, LONG_OPT_SAFE_SEH },
|
|
|
|
{ "save-temps", 0, LONG_OPT_SAVE_TEMPS },
|
|
|
|
{ "subsystem", 1, LONG_OPT_SUBSYSTEM },
|
|
|
|
{ "syscall-table", 1, LONG_OPT_SYSCALL_TABLE },
|
|
|
|
{ "version", 0, LONG_OPT_VERSION },
|
2003-03-23 02:12:30 +01:00
|
|
|
/* aliases for short options */
|
2021-10-05 11:52:49 +02:00
|
|
|
{ "target", 1, 'b' },
|
|
|
|
{ "delay-lib", 1, 'd' },
|
|
|
|
{ "export", 1, 'E' },
|
|
|
|
{ "entry", 1, 'e' },
|
|
|
|
{ "filename", 1, 'F' },
|
|
|
|
{ "help", 0, 'h' },
|
|
|
|
{ "heap", 1, 'H' },
|
|
|
|
{ "kill-at", 0, 'k' },
|
|
|
|
{ "library", 1, 'l' },
|
|
|
|
{ "library-path", 1, 'L' },
|
|
|
|
{ "main-module", 1, 'M' },
|
|
|
|
{ "dll-name", 1, 'N' },
|
|
|
|
{ "output", 1, 'o' },
|
|
|
|
{ "res", 1, 'r' },
|
|
|
|
{ "undefined", 1, 'u' },
|
|
|
|
{ "verbose", 0, 'v' },
|
|
|
|
{ "warnings", 0, 'w' },
|
|
|
|
{ NULL }
|
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
|
|
|
}
|
|
|
|
|
2019-06-25 17:36:44 +02:00
|
|
|
/* get the default entry point for a given spec file */
|
|
|
|
static const char *get_default_entry_point( const DLLSPEC *spec )
|
|
|
|
{
|
2020-04-21 11:27:33 +02:00
|
|
|
if (spec->characteristics & IMAGE_FILE_DLL) return "DllMain";
|
2020-04-15 17:49:09 +02:00
|
|
|
if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) return "DriverEntry";
|
2020-11-25 20:00:26 +01:00
|
|
|
if (spec->type == SPEC_WIN16)
|
2020-11-25 20:00:27 +01:00
|
|
|
{
|
|
|
|
add_spec_extra_ld_symbol("WinMain16");
|
2020-11-25 20:00:26 +01:00
|
|
|
return "__wine_spec_exe16_entry";
|
2020-11-25 20:00:27 +01:00
|
|
|
}
|
2020-11-25 20:00:26 +01:00
|
|
|
else if (spec->unicode_app)
|
2020-11-25 20:00:27 +01:00
|
|
|
{
|
|
|
|
/* __wine_spec_exe_wentry always calls wmain */
|
|
|
|
add_spec_extra_ld_symbol("wmain");
|
2020-11-25 20:00:28 +01:00
|
|
|
if (spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
|
|
|
|
add_spec_extra_ld_symbol("wWinMain");
|
2020-11-25 20:00:26 +01:00
|
|
|
return "__wine_spec_exe_wentry";
|
2020-11-25 20:00:27 +01:00
|
|
|
}
|
2020-11-25 20:00:26 +01:00
|
|
|
else
|
2020-11-25 20:00:27 +01:00
|
|
|
{
|
|
|
|
/* __wine_spec_exe_entry always calls main */
|
|
|
|
add_spec_extra_ld_symbol("main");
|
2020-11-25 20:00:28 +01:00
|
|
|
if (spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
|
|
|
|
add_spec_extra_ld_symbol("WinMain");
|
2020-11-25 20:00:26 +01:00
|
|
|
return "__wine_spec_exe_entry";
|
2020-11-25 20:00:27 +01:00
|
|
|
}
|
2019-06-25 17:36:44 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 11:52:49 +02:00
|
|
|
static void option_callback( int optc, char *optarg )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-04-01 02:08:32 +02:00
|
|
|
char *p;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2021-10-05 11:52:49 +02:00
|
|
|
switch (optc)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2021-10-05 11:52:49 +02:00
|
|
|
case 'B':
|
|
|
|
strarray_add( &tools_path, xstrdup( optarg ));
|
2009-01-15 21:17:51 +01:00
|
|
|
break;
|
2021-10-05 11:52:49 +02:00
|
|
|
case 'D':
|
|
|
|
/* ignored */
|
2009-01-15 21:17:51 +01:00
|
|
|
break;
|
2021-10-05 11:52:49 +02:00
|
|
|
case 'E':
|
|
|
|
spec_file_name = xstrdup( optarg );
|
|
|
|
set_dll_file_name( optarg, main_spec );
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
main_spec->file_name = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
if (!isdigit(optarg[0]))
|
|
|
|
fatal_error( "Expected number argument with -H option instead of '%s'\n", optarg );
|
|
|
|
main_spec->heap_size = atoi(optarg);
|
|
|
|
if (main_spec->heap_size > 65535)
|
|
|
|
fatal_error( "Invalid heap size %d, maximum is 65535\n", main_spec->heap_size );
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
/* ignored, because cc generates correct code. */
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
strarray_add( &lib_path, xstrdup( optarg ));
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (!strcmp( optarg, "16" )) main_spec->type = SPEC_WIN16;
|
|
|
|
else if (!strcmp( optarg, "32" )) force_pointer_size = 4;
|
|
|
|
else if (!strcmp( optarg, "64" )) force_pointer_size = 8;
|
|
|
|
else if (!strcmp( optarg, "arm" )) thumb_mode = 0;
|
|
|
|
else if (!strcmp( optarg, "thumb" )) thumb_mode = 1;
|
|
|
|
else if (!strcmp( optarg, "no-cygwin" )) use_msvcrt = 1;
|
|
|
|
else if (!strcmp( optarg, "unix" )) unix_lib = 1;
|
|
|
|
else if (!strcmp( optarg, "unicode" )) main_spec->unicode_app = 1;
|
|
|
|
else if (!strncmp( optarg, "cpu=", 4 )) cpu_option = xstrdup( optarg + 4 );
|
|
|
|
else if (!strncmp( optarg, "fpu=", 4 )) fpu_option = xstrdup( optarg + 4 );
|
|
|
|
else if (!strncmp( optarg, "arch=", 5 )) arch_option = xstrdup( optarg + 5 );
|
|
|
|
else if (!strncmp( optarg, "float-abi=", 10 )) float_abi_option = xstrdup( optarg + 10 );
|
|
|
|
else fatal_error( "Unknown -m option '%s'\n", optarg );
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
main_spec->main_module = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
main_spec->dll_name = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
set_target( optarg );
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
add_delayed_import( optarg );
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
main_spec->init_func = xstrdup( optarg );
|
|
|
|
if ((p = strchr( main_spec->init_func, '@' ))) *p = 0; /* kill stdcall decoration */
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
if (!strcmp( optarg, "PIC") || !strcmp( optarg, "pic")) UsePIC = 1;
|
|
|
|
else if (!strcmp( optarg, "asynchronous-unwind-tables")) unwind_tables = 1;
|
|
|
|
else if (!strcmp( optarg, "no-asynchronous-unwind-tables")) unwind_tables = 0;
|
|
|
|
/* ignore all other flags */
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(0);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
kill_at = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
add_import_dll( optarg, NULL );
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (unlink( optarg ) == -1 && errno != ENOENT)
|
|
|
|
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
|
|
output_file_name = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
strarray_add( &res_files, xstrdup( optarg ));
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
add_extra_ld_symbol( optarg );
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
display_warnings = 1;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_DLL:
|
|
|
|
set_exec_mode( MODE_DLL );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_DEF:
|
|
|
|
set_exec_mode( MODE_DEF );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_EXE:
|
|
|
|
set_exec_mode( MODE_EXE );
|
|
|
|
if (!main_spec->subsystem) main_spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_IMPLIB:
|
|
|
|
set_exec_mode( MODE_IMPLIB );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_STATICLIB:
|
|
|
|
set_exec_mode( MODE_STATICLIB );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_BUILTIN:
|
|
|
|
set_exec_mode( MODE_BUILTIN );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_FIXUP_CTORS:
|
|
|
|
set_exec_mode( MODE_FIXUP_CTORS );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_ASCMD:
|
|
|
|
as_command = strarray_fromstring( optarg, " " );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_CCCMD:
|
|
|
|
cc_command = strarray_fromstring( optarg, " " );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_FAKE_MODULE:
|
|
|
|
fake_module = 1;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_EXTERNAL_SYMS:
|
|
|
|
link_ext_symbols = 1;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_LARGE_ADDRESS_AWARE:
|
|
|
|
main_spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_LDCMD:
|
|
|
|
ld_command = strarray_fromstring( optarg, " " );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_NMCMD:
|
|
|
|
nm_command = strarray_fromstring( optarg, " " );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_NXCOMPAT:
|
|
|
|
if (optarg[0] == 'n' || optarg[0] == 'N')
|
|
|
|
main_spec->dll_characteristics &= ~IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_SAFE_SEH:
|
|
|
|
safe_seh = 1;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_PREFER_NATIVE:
|
|
|
|
prefer_native = 1;
|
|
|
|
main_spec->dll_characteristics |= IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_RESOURCES:
|
|
|
|
set_exec_mode( MODE_RESOURCES );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_SAVE_TEMPS:
|
|
|
|
save_temps = 1;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_SUBSYSTEM:
|
|
|
|
set_subsystem( optarg, main_spec );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_SYSCALL_TABLE:
|
|
|
|
set_syscall_table( optarg, main_spec );
|
|
|
|
break;
|
|
|
|
case LONG_OPT_VERSION:
|
|
|
|
printf( "winebuild version " PACKAGE_VERSION "\n" );
|
|
|
|
exit(0);
|
|
|
|
case '?':
|
|
|
|
fprintf( stderr, "winebuild: %s\n\n", optarg );
|
|
|
|
usage(1);
|
2009-01-15 21:17:51 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-19 00:16:09 +01:00
|
|
|
/* load all specified resource files */
|
2021-09-23 12:23:25 +02:00
|
|
|
static struct strarray load_resources( struct strarray files, DLLSPEC *spec )
|
2002-11-19 00:16:09 +01:00
|
|
|
{
|
2021-09-23 12:23:25 +02:00
|
|
|
struct strarray ret = empty_strarray;
|
2002-11-19 00:16:09 +01:00
|
|
|
int i;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
switch (spec->type)
|
2002-11-19 00:16:09 +01:00
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
2016-03-19 05:22:30 +01:00
|
|
|
for (i = 0; i < res_files.count; i++) load_res16_file( res_files.str[i], spec );
|
2021-09-23 12:23:25 +02:00
|
|
|
return files;
|
2002-12-07 00:26:29 +01:00
|
|
|
|
2002-11-19 00:16:09 +01:00
|
|
|
case SPEC_WIN32:
|
2016-03-19 05:22:30 +01:00
|
|
|
for (i = 0; i < res_files.count; i++)
|
2002-12-07 00:26:29 +01:00
|
|
|
{
|
2016-03-19 05:22:30 +01:00
|
|
|
if (!load_res32_file( res_files.str[i], spec ))
|
|
|
|
fatal_error( "%s is not a valid Win32 resource file\n", res_files.str[i] );
|
2002-12-07 00:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load any resource file found in the remaining arguments */
|
2021-09-23 12:23:25 +02:00
|
|
|
for (i = 0; i < files.count; i++)
|
2002-12-07 00:26:29 +01:00
|
|
|
{
|
2021-09-23 12:23:25 +02:00
|
|
|
if (!load_res32_file( files.str[i], spec ))
|
|
|
|
strarray_add( &ret, files.str[i] ); /* not a resource file, keep it in the list */
|
2002-12-07 00:26:29 +01:00
|
|
|
}
|
2002-11-19 00:16:09 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-09-23 12:23:25 +02:00
|
|
|
return ret;
|
2002-11-19 00:16:09 +01:00
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
/* add input files that look like import libs to the import list */
|
2021-09-23 12:23:25 +02:00
|
|
|
static struct strarray load_import_libs( struct strarray files )
|
2005-05-06 17:54:41 +02:00
|
|
|
{
|
2021-09-23 12:23:25 +02:00
|
|
|
struct strarray ret = empty_strarray;
|
|
|
|
int i;
|
2005-05-06 17:54:41 +02:00
|
|
|
|
2021-09-23 12:23:25 +02:00
|
|
|
for (i = 0; i < files.count; i++)
|
2005-05-06 17:54:41 +02:00
|
|
|
{
|
2021-09-23 12:23:25 +02:00
|
|
|
if (strendswith( files.str[i], ".def" ))
|
|
|
|
add_import_dll( NULL, files.str[i] );
|
2005-05-06 17:54:41 +02:00
|
|
|
else
|
2021-09-23 12:23:25 +02:00
|
|
|
strarray_add( &ret, files.str[i] ); /* not an import dll, keep it in the list */
|
2005-05-06 17:54:41 +02:00
|
|
|
}
|
2021-09-23 12:23:25 +02:00
|
|
|
return ret;
|
2005-05-06 17:54:41 +02:00
|
|
|
}
|
|
|
|
|
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 );
|
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 );
|
2021-09-29 11:13:36 +02:00
|
|
|
if (strendswith( spec_file_name, ".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)
|
|
|
|
{
|
2021-09-23 12:23:25 +02:00
|
|
|
struct strarray files;
|
2021-10-05 11:52:49 +02:00
|
|
|
DLLSPEC *spec = main_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 );
|
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
target = init_argv0_target( argv[0] );
|
|
|
|
if (target.platform == PLATFORM_CYGWIN) target.platform = PLATFORM_MINGW;
|
|
|
|
|
2021-10-05 11:52:49 +02:00
|
|
|
files = parse_options( argc, argv, short_options, long_options, 0, option_callback );
|
|
|
|
|
2019-03-04 14:31:48 +01:00
|
|
|
atexit( cleanup ); /* make sure we remove the output file on exit */
|
2021-10-05 11:52:49 +02:00
|
|
|
if (!save_temps) atexit( cleanup_tmp_files );
|
|
|
|
|
|
|
|
if (spec->file_name && !strchr( spec->file_name, '.' ))
|
|
|
|
strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
|
|
|
|
init_dll_name( spec );
|
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (force_pointer_size) set_target_ptr_size( &target, force_pointer_size );
|
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
|
|
|
/* fall through */
|
|
|
|
case MODE_EXE:
|
2021-09-23 12:23:25 +02:00
|
|
|
files = load_resources( files, spec );
|
2008-03-03 15:19:53 +01:00
|
|
|
if (spec_file_name && !parse_input_file( spec )) break;
|
2020-07-01 10:36:55 +02:00
|
|
|
if (!spec->init_func && !unix_lib) spec->init_func = xstrdup( get_default_entry_point( spec ));
|
2019-06-04 12:38:43 +02:00
|
|
|
|
2009-08-14 14:16:38 +02:00
|
|
|
if (fake_module)
|
|
|
|
{
|
2021-10-21 12:50:13 +02:00
|
|
|
output_fake_module( spec );
|
2009-08-14 14:16:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-01-25 15:24:23 +01:00
|
|
|
if (!is_pe())
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2021-09-23 12:23:25 +02:00
|
|
|
files = load_import_libs( files );
|
|
|
|
read_undef_symbols( spec, files );
|
2019-06-04 12:38:43 +02:00
|
|
|
resolve_imports( spec );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2019-06-04 12:38:43 +02:00
|
|
|
if (spec->type == SPEC_WIN16) output_spec16_file( spec );
|
|
|
|
else output_spec32_file( spec );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
2002-02-04 19:48:18 +01:00
|
|
|
case MODE_DEF:
|
2021-09-23 12:23:25 +02:00
|
|
|
if (files.count) fatal_error( "file argument '%s' not allowed in this mode\n", files.str[0] );
|
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;
|
2019-03-04 14:31:48 +01:00
|
|
|
open_output_file();
|
2019-08-25 18:49:23 +02:00
|
|
|
output_def_file( spec, 0 );
|
2019-03-04 14:31:48 +01:00
|
|
|
close_output_file();
|
2002-02-04 19:48:18 +01:00
|
|
|
break;
|
2009-12-30 11:51:19 +01:00
|
|
|
case MODE_IMPLIB:
|
|
|
|
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
|
|
|
if (!parse_input_file( spec )) break;
|
2021-09-23 12:23:25 +02:00
|
|
|
output_static_lib( spec, files );
|
2020-03-04 17:15:34 +01:00
|
|
|
break;
|
|
|
|
case MODE_STATICLIB:
|
2021-09-23 12:23:25 +02:00
|
|
|
output_static_lib( NULL, files );
|
2009-12-30 11:51:19 +01:00
|
|
|
break;
|
2019-12-18 21:05:27 +01:00
|
|
|
case MODE_BUILTIN:
|
2021-09-23 12:23:25 +02:00
|
|
|
if (!files.count) fatal_error( "missing file argument for --builtin option\n" );
|
|
|
|
make_builtin_files( files );
|
2019-12-18 21:05:27 +01:00
|
|
|
break;
|
2020-04-16 12:21:23 +02:00
|
|
|
case MODE_FIXUP_CTORS:
|
2021-09-23 12:23:25 +02:00
|
|
|
if (!files.count) fatal_error( "missing file argument for --fixup-ctors option\n" );
|
|
|
|
fixup_constructors( files );
|
2020-04-16 12:21:23 +02:00
|
|
|
break;
|
2009-05-30 21:39:50 +02:00
|
|
|
case MODE_RESOURCES:
|
2021-09-23 12:23:25 +02:00
|
|
|
files = load_resources( files, spec );
|
2009-05-30 21:39:50 +02:00
|
|
|
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);
|
2019-03-04 14:31:48 +01:00
|
|
|
output_file_name = NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|