2002-12-05 20:12:13 +01:00
|
|
|
/*
|
|
|
|
* MinGW wrapper: makes gcc behave like MinGW.
|
|
|
|
*
|
2002-12-15 02:17:10 +01:00
|
|
|
* Copyright 2000 Manuel Novoa III
|
2004-02-24 02:00:53 +01:00
|
|
|
* Copyright 2000 Francois Gouget
|
2002-12-05 20:12:13 +01:00
|
|
|
* Copyright 2002 Dimitrie O. Paun
|
|
|
|
*
|
|
|
|
* 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
|
2004-02-21 05:01:38 +01:00
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
*
|
|
|
|
* all options for gcc start with '-' and are for the most part
|
|
|
|
* single options (no parameters as separate argument).
|
|
|
|
* There are of course exceptions to this rule, so here is an
|
2004-03-02 03:23:26 +01:00
|
|
|
* exhaustive list of options that do take parameters (potentially)
|
2004-02-21 05:01:38 +01:00
|
|
|
* as a separate argument:
|
|
|
|
*
|
|
|
|
* Compiler:
|
|
|
|
* -x language
|
|
|
|
* -o filename
|
|
|
|
* -aux-info filename
|
|
|
|
*
|
|
|
|
* Preprocessor:
|
|
|
|
* -D name
|
|
|
|
* -U name
|
|
|
|
* -I dir
|
|
|
|
* -MF file
|
|
|
|
* -MT target
|
|
|
|
* -MQ target
|
|
|
|
* (all -i.* arg)
|
|
|
|
* -include file
|
|
|
|
* -imacros file
|
|
|
|
* -idirafter dir
|
|
|
|
* -iwithprefix dir
|
|
|
|
* -iwithprefixbefore dir
|
|
|
|
* -isystem dir
|
|
|
|
* -A predicate=answer
|
|
|
|
*
|
|
|
|
* Linking:
|
|
|
|
* -l library
|
|
|
|
* -Xlinker option
|
|
|
|
* -u symbol
|
|
|
|
*
|
|
|
|
* Misc:
|
|
|
|
* -b machine
|
|
|
|
* -V version
|
|
|
|
* -G num (see NOTES below)
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* There is -G option for compatibility with System V that
|
2004-03-02 03:23:26 +01:00
|
|
|
* takes no parameters. This makes "-G num" parsing ambiguous.
|
|
|
|
* This option is synonymous to -shared, and as such we will
|
2004-02-21 05:01:38 +01:00
|
|
|
* not support it for now.
|
|
|
|
*
|
|
|
|
* Special interest options
|
|
|
|
*
|
|
|
|
* Assembler Option
|
|
|
|
* -Wa,option
|
|
|
|
*
|
|
|
|
* Linker Options
|
|
|
|
* object-file-name -llibrary -nostartfiles -nodefaultlibs
|
2018-12-03 16:05:14 +01:00
|
|
|
* -nostdlib -s -static -static-libgcc -static-libstdc++
|
|
|
|
* -shared -shared-libgcc -symbolic -Wl,option
|
2019-11-25 03:13:31 +01:00
|
|
|
* -Xlinker option -u symbol --image-base -fuse-ld
|
2004-02-21 05:01:38 +01:00
|
|
|
*
|
|
|
|
* Directory Options
|
|
|
|
* -Bprefix -Idir -I- -Ldir -specs=file
|
|
|
|
*
|
|
|
|
* Target Options
|
|
|
|
* -b machine -V version
|
|
|
|
*
|
2004-03-02 03:23:26 +01:00
|
|
|
* Please note that the Target Options are relevant to everything:
|
|
|
|
* compiler, linker, assembler, preprocessor.
|
2004-02-21 05:01:38 +01:00
|
|
|
*
|
|
|
|
*/
|
2002-12-05 20:12:13 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
#include <assert.h>
|
2002-12-05 20:12:13 +01:00
|
|
|
#include <stdio.h>
|
2002-12-12 03:17:56 +01:00
|
|
|
#include <stdlib.h>
|
2004-12-02 19:22:48 +01:00
|
|
|
#include <signal.h>
|
2002-12-15 02:17:10 +01:00
|
|
|
#include <stdarg.h>
|
2002-12-05 20:12:13 +01:00
|
|
|
#include <string.h>
|
2003-01-07 20:47:19 +01:00
|
|
|
#include <errno.h>
|
2019-09-23 13:57:57 +02:00
|
|
|
#include <ctype.h>
|
2021-10-23 10:17:45 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_SYSCTL_H
|
|
|
|
# include <sys/sysctl.h>
|
|
|
|
#endif
|
2002-12-05 20:12:13 +01:00
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
#include "utils.h"
|
2003-01-07 20:47:19 +01:00
|
|
|
|
2004-03-09 02:34:00 +01:00
|
|
|
static const char* app_loader_template =
|
2004-02-24 02:00:53 +01:00
|
|
|
"#!/bin/sh\n"
|
|
|
|
"\n"
|
|
|
|
"appname=\"%s\"\n"
|
|
|
|
"# determine the application directory\n"
|
|
|
|
"appdir=''\n"
|
|
|
|
"case \"$0\" in\n"
|
|
|
|
" */*)\n"
|
|
|
|
" # $0 contains a path, use it\n"
|
|
|
|
" appdir=`dirname \"$0\"`\n"
|
|
|
|
" ;;\n"
|
|
|
|
" *)\n"
|
|
|
|
" # no directory in $0, search in PATH\n"
|
|
|
|
" saved_ifs=$IFS\n"
|
|
|
|
" IFS=:\n"
|
|
|
|
" for d in $PATH\n"
|
|
|
|
" do\n"
|
|
|
|
" IFS=$saved_ifs\n"
|
|
|
|
" if [ -x \"$d/$appname\" ]; then appdir=\"$d\"; break; fi\n"
|
|
|
|
" done\n"
|
|
|
|
" ;;\n"
|
|
|
|
"esac\n"
|
|
|
|
"\n"
|
|
|
|
"# figure out the full app path\n"
|
|
|
|
"if [ -n \"$appdir\" ]; then\n"
|
2004-03-03 21:11:20 +01:00
|
|
|
" apppath=\"$appdir/$appname\"\n"
|
2004-02-24 02:00:53 +01:00
|
|
|
" WINEDLLPATH=\"$appdir:$WINEDLLPATH\"\n"
|
|
|
|
" export WINEDLLPATH\n"
|
|
|
|
"else\n"
|
2004-03-03 21:11:20 +01:00
|
|
|
" apppath=\"$appname\"\n"
|
2004-02-24 02:00:53 +01:00
|
|
|
"fi\n"
|
|
|
|
"\n"
|
|
|
|
"# determine the WINELOADER\n"
|
|
|
|
"if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
|
|
|
|
"\n"
|
|
|
|
"# and try to start the app\n"
|
2004-05-07 01:51:43 +02:00
|
|
|
"exec \"$WINELOADER\" \"$apppath\" \"$@\"\n"
|
2004-02-24 02:00:53 +01:00
|
|
|
;
|
|
|
|
|
2020-02-21 13:52:31 +01:00
|
|
|
static const char *output_file_name;
|
2020-05-14 16:39:48 +02:00
|
|
|
static const char *output_debug_file;
|
2020-11-25 20:41:43 +01:00
|
|
|
static const char *output_implib;
|
2003-09-12 00:16:33 +02:00
|
|
|
static int keep_generated = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
static struct strarray tmp_files;
|
2004-12-07 18:19:54 +01:00
|
|
|
#ifdef HAVE_SIGSET_T
|
2004-12-02 19:22:48 +01:00
|
|
|
static sigset_t signal_mask;
|
2004-12-07 18:19:54 +01:00
|
|
|
#endif
|
2003-01-07 20:47:19 +01:00
|
|
|
|
2020-01-30 11:49:49 +01:00
|
|
|
static const char *bindir;
|
|
|
|
static const char *libdir;
|
|
|
|
static const char *includedir;
|
|
|
|
|
2005-09-15 17:01:30 +02:00
|
|
|
enum processor { proc_cc, proc_cxx, proc_cpp, proc_as };
|
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
struct options
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2005-09-15 17:01:30 +02:00
|
|
|
enum processor processor;
|
2021-11-16 21:02:12 +01:00
|
|
|
struct target target;
|
|
|
|
const char *target_alias;
|
2011-03-15 21:17:48 +01:00
|
|
|
const char *version;
|
2004-03-23 01:14:54 +01:00
|
|
|
int shared;
|
2004-02-21 05:01:38 +01:00
|
|
|
int use_msvcrt;
|
|
|
|
int nostdinc;
|
|
|
|
int nostdlib;
|
2005-08-25 13:41:05 +02:00
|
|
|
int nostartfiles;
|
2004-02-21 05:01:38 +01:00
|
|
|
int nodefaultlibs;
|
2004-03-02 03:23:26 +01:00
|
|
|
int noshortwchar;
|
2020-07-01 10:36:42 +02:00
|
|
|
int unix_lib;
|
2004-02-21 05:01:38 +01:00
|
|
|
int gui_app;
|
2005-08-25 21:26:59 +02:00
|
|
|
int unicode_app;
|
2010-07-21 12:44:12 +02:00
|
|
|
int win16_app;
|
2004-02-21 05:01:38 +01:00
|
|
|
int compile_only;
|
2009-02-04 20:10:49 +01:00
|
|
|
int force_pointer_size;
|
2009-06-17 16:10:56 +02:00
|
|
|
int large_address_aware;
|
2019-04-22 11:34:14 +02:00
|
|
|
int wine_builtin;
|
2021-11-18 19:47:40 +01:00
|
|
|
int fake_module;
|
2010-04-11 12:32:01 +02:00
|
|
|
int unwind_tables;
|
2011-10-06 01:07:38 +02:00
|
|
|
int strip;
|
2019-04-29 06:04:54 +02:00
|
|
|
int pic;
|
2006-07-11 21:32:36 +02:00
|
|
|
const char* wine_objdir;
|
2019-09-23 13:43:18 +02:00
|
|
|
const char* winebuild;
|
2004-02-21 05:01:38 +01:00
|
|
|
const char* output_name;
|
2005-08-09 13:12:29 +02:00
|
|
|
const char* image_base;
|
2008-07-22 13:27:07 +02:00
|
|
|
const char* section_align;
|
2020-07-23 20:33:16 +02:00
|
|
|
const char* file_align;
|
2019-09-10 12:07:01 +02:00
|
|
|
const char* sysroot;
|
|
|
|
const char* isysroot;
|
2010-01-23 20:25:14 +01:00
|
|
|
const char* lib_suffix;
|
2018-05-01 12:57:54 +02:00
|
|
|
const char* subsystem;
|
2020-01-21 19:52:05 +01:00
|
|
|
const char* entry_point;
|
2019-03-09 20:42:37 +01:00
|
|
|
const char* prelink;
|
2020-05-14 16:39:48 +02:00
|
|
|
const char* debug_file;
|
2020-11-25 20:41:43 +01:00
|
|
|
const char* out_implib;
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray prefix;
|
|
|
|
struct strarray lib_dirs;
|
|
|
|
struct strarray args;
|
|
|
|
struct strarray linker_args;
|
|
|
|
struct strarray compiler_args;
|
|
|
|
struct strarray winebuild_args;
|
|
|
|
struct strarray files;
|
|
|
|
struct strarray delayimports;
|
2004-02-21 05:01:38 +01:00
|
|
|
};
|
|
|
|
|
2020-02-21 13:52:31 +01:00
|
|
|
static void cleanup_output_files(void)
|
|
|
|
{
|
|
|
|
if (output_file_name) unlink( output_file_name );
|
2020-05-14 16:39:48 +02:00
|
|
|
if (output_debug_file) unlink( output_debug_file );
|
2020-11-25 20:41:43 +01:00
|
|
|
if (output_implib) unlink( output_implib );
|
2020-02-21 13:52:31 +01:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void clean_temp_files(void)
|
2003-01-07 20:47:19 +01:00
|
|
|
{
|
2007-02-10 12:57:25 +01:00
|
|
|
unsigned int i;
|
2004-02-24 02:00:53 +01:00
|
|
|
|
|
|
|
if (keep_generated) return;
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; i < tmp_files.count; i++)
|
|
|
|
unlink(tmp_files.str[i]);
|
2003-01-07 20:47:19 +01:00
|
|
|
}
|
|
|
|
|
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 the atexit functions */
|
|
|
|
}
|
|
|
|
|
2004-12-06 17:44:32 +01:00
|
|
|
static char* get_temp_file(const char* prefix, const char* suffix)
|
2003-01-07 20:47:19 +01:00
|
|
|
{
|
2004-12-02 19:22:48 +01:00
|
|
|
int fd;
|
2021-09-29 09:32:01 +02:00
|
|
|
char *tmp;
|
2004-12-02 19:22:48 +01:00
|
|
|
|
2004-12-07 18:19:54 +01:00
|
|
|
#ifdef HAVE_SIGPROCMASK
|
|
|
|
sigset_t old_set;
|
2004-12-02 19:22:48 +01:00
|
|
|
/* block signals while manipulating the temp files list */
|
|
|
|
sigprocmask( SIG_BLOCK, &signal_mask, &old_set );
|
2004-12-07 18:19:54 +01:00
|
|
|
#endif
|
2021-09-29 09:32:01 +02:00
|
|
|
fd = make_temp_file( prefix, suffix, &tmp );
|
2003-03-20 22:09:06 +01:00
|
|
|
close( fd );
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&tmp_files, tmp);
|
2004-12-07 18:19:54 +01:00
|
|
|
#ifdef HAVE_SIGPROCMASK
|
2004-12-02 19:22:48 +01:00
|
|
|
sigprocmask( SIG_SETMASK, &old_set, NULL );
|
2004-12-07 18:19:54 +01:00
|
|
|
#endif
|
2003-01-07 20:47:19 +01:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2021-05-14 16:53:40 +02:00
|
|
|
static int is_pe_target( const struct options *opts )
|
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
switch (opts->target.platform)
|
2021-05-14 16:53:40 +02:00
|
|
|
{
|
|
|
|
case PLATFORM_MINGW:
|
|
|
|
case PLATFORM_CYGWIN:
|
|
|
|
case PLATFORM_WINDOWS:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:02:18 +01:00
|
|
|
enum tool
|
2011-03-15 21:17:48 +01:00
|
|
|
{
|
2020-03-03 14:02:18 +01:00
|
|
|
TOOL_CC,
|
|
|
|
TOOL_CXX,
|
|
|
|
TOOL_CPP,
|
|
|
|
TOOL_LD,
|
2020-05-14 16:39:48 +02:00
|
|
|
TOOL_OBJCOPY,
|
2020-03-03 14:02:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *base;
|
2020-03-03 14:02:28 +01:00
|
|
|
const char *llvm_base;
|
2020-03-03 14:02:18 +01:00
|
|
|
const char *deflt;
|
|
|
|
} tool_names[] =
|
|
|
|
{
|
2020-05-14 16:39:48 +02:00
|
|
|
{ "gcc", "clang --driver-mode=gcc", CC },
|
|
|
|
{ "g++", "clang --driver-mode=g++", CXX },
|
|
|
|
{ "cpp", "clang --driver-mode=cpp", CPP },
|
|
|
|
{ "ld", "ld.lld", LD },
|
|
|
|
{ "objcopy", "llvm-objcopy" },
|
2020-03-03 14:02:18 +01:00
|
|
|
};
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
static struct strarray build_tool_name( struct options *opts, enum tool tool )
|
2020-03-03 14:02:18 +01:00
|
|
|
{
|
|
|
|
const char *base = tool_names[tool].base;
|
2020-03-03 14:02:28 +01:00
|
|
|
const char *llvm_base = tool_names[tool].llvm_base;
|
2020-03-03 14:02:18 +01:00
|
|
|
const char *deflt = tool_names[tool].deflt;
|
2020-03-03 14:01:59 +01:00
|
|
|
const char *path;
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray ret = empty_strarray;
|
2011-03-15 21:17:48 +01:00
|
|
|
char* str;
|
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target_alias && opts->version)
|
2011-03-15 21:17:48 +01:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
str = strmake("%s-%s-%s", opts->target_alias, base, opts->version);
|
2011-03-15 21:17:48 +01:00
|
|
|
}
|
2021-11-16 21:02:12 +01:00
|
|
|
else if (opts->target_alias)
|
2011-03-15 21:17:48 +01:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
str = strmake("%s-%s", opts->target_alias, base);
|
2011-03-15 21:17:48 +01:00
|
|
|
}
|
|
|
|
else if (opts->version)
|
|
|
|
{
|
|
|
|
str = strmake("%s-%s", base, opts->version);
|
|
|
|
}
|
|
|
|
else
|
2020-05-14 16:39:48 +02:00
|
|
|
str = xstrdup((deflt && *deflt) ? deflt : base);
|
2020-03-03 14:01:59 +01:00
|
|
|
|
2020-03-03 14:02:08 +01:00
|
|
|
if ((path = find_binary( opts->prefix, str ))) return strarray_fromstring( path, " " );
|
2020-03-03 14:02:28 +01:00
|
|
|
|
|
|
|
if (!opts->version) str = xstrdup( llvm_base );
|
|
|
|
else str = strmake( "%s-%s", llvm_base, opts->version );
|
|
|
|
path = find_binary( opts->prefix, str );
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
error( "Could not find %s\n", base );
|
2021-09-23 11:52:15 +02:00
|
|
|
return ret;
|
2020-03-03 14:02:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = strarray_fromstring( path, " " );
|
|
|
|
if (!strncmp( llvm_base, "clang", 5 ))
|
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target_alias)
|
2020-03-03 14:02:28 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &ret, "-target" );
|
2021-11-16 21:02:12 +01:00
|
|
|
strarray_add( &ret, opts->target_alias );
|
2020-03-03 14:02:28 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &ret, "-Wno-unused-command-line-argument" );
|
|
|
|
strarray_add( &ret, "-fuse-ld=lld" );
|
2020-03-03 14:02:28 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2011-03-15 21:17:48 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
static struct strarray get_translator(struct options *opts)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2020-03-03 14:02:18 +01:00
|
|
|
enum tool tool;
|
2004-03-09 01:42:21 +01:00
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
switch(opts->processor)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2009-02-12 11:41:56 +01:00
|
|
|
case proc_cpp:
|
2020-03-03 14:02:18 +01:00
|
|
|
tool = TOOL_CPP;
|
2009-02-12 11:41:56 +01:00
|
|
|
break;
|
|
|
|
case proc_cc:
|
2009-05-30 13:03:20 +02:00
|
|
|
case proc_as:
|
2020-03-03 14:02:18 +01:00
|
|
|
tool = TOOL_CC;
|
2009-02-12 11:41:56 +01:00
|
|
|
break;
|
|
|
|
case proc_cxx:
|
2020-03-03 14:02:18 +01:00
|
|
|
tool = TOOL_CXX;
|
2009-02-12 11:41:56 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
2020-03-03 14:02:18 +01:00
|
|
|
return build_tool_name( opts, tool );
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
static int try_link( struct strarray prefix, struct strarray link_tool, const char *cflags )
|
2013-08-27 11:03:42 +02:00
|
|
|
{
|
|
|
|
const char *in = get_temp_file( "try_link", ".c" );
|
|
|
|
const char *out = get_temp_file( "try_link", ".out" );
|
2013-09-06 14:33:24 +02:00
|
|
|
const char *err = get_temp_file( "try_link", ".err" );
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray link = empty_strarray;
|
2013-09-06 14:33:24 +02:00
|
|
|
int sout = -1, serr = -1;
|
2013-08-27 11:03:42 +02:00
|
|
|
int ret;
|
|
|
|
|
2013-09-06 14:33:17 +02:00
|
|
|
create_file( in, 0644, "int main(void){return 1;}\n" );
|
2013-08-27 11:03:42 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link, link_tool );
|
|
|
|
strarray_add( &link, "-o" );
|
|
|
|
strarray_add( &link, out );
|
|
|
|
strarray_addall( &link, strarray_fromstring( cflags, " " ) );
|
|
|
|
strarray_add( &link, in );
|
2013-08-27 11:03:42 +02:00
|
|
|
|
2013-09-06 14:33:24 +02:00
|
|
|
sout = dup( fileno(stdout) );
|
|
|
|
freopen( err, "w", stdout );
|
|
|
|
serr = dup( fileno(stderr) );
|
|
|
|
freopen( err, "w", stderr );
|
2013-08-27 11:03:42 +02:00
|
|
|
ret = spawn( prefix, link, 1 );
|
2013-09-06 14:33:24 +02:00
|
|
|
if (sout >= 0)
|
|
|
|
{
|
|
|
|
dup2( sout, fileno(stdout) );
|
|
|
|
close( sout );
|
|
|
|
}
|
|
|
|
if (serr >= 0)
|
|
|
|
{
|
|
|
|
dup2( serr, fileno(stderr) );
|
|
|
|
close( serr );
|
|
|
|
}
|
2013-08-27 11:03:42 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
static struct strarray get_link_args( struct options *opts, const char *output_name )
|
2013-08-27 11:03:42 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray link_args = get_translator( opts );
|
|
|
|
struct strarray flags = empty_strarray;
|
2019-03-09 20:42:37 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link_args, opts->linker_args );
|
2019-03-09 20:42:37 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
if (verbose > 1) strarray_add( &flags, "-v" );
|
2019-03-09 20:42:37 +01:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
switch (opts->target.platform)
|
2013-08-27 11:03:42 +02:00
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, opts->unix_lib ? "-dynamiclib" : "-bundle" );
|
|
|
|
strarray_add( &flags, "-multiply_defined" );
|
|
|
|
strarray_add( &flags, "suppress" );
|
2019-03-09 20:42:37 +01:00
|
|
|
if (opts->image_base)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-image_base" );
|
|
|
|
strarray_add( &flags, opts->image_base );
|
2019-03-09 20:42:37 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->strip) strarray_add( &flags, "-Wl,-x" );
|
2021-08-23 08:30:10 +02:00
|
|
|
if (opts->unix_lib)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-install_name" );
|
|
|
|
strarray_add( &flags, strmake( "@loader_path/%s.so", output_name ) );
|
2021-08-23 08:30:10 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link_args, flags );
|
2019-09-23 19:27:09 +02:00
|
|
|
return link_args;
|
2013-08-27 11:03:42 +02:00
|
|
|
|
|
|
|
case PLATFORM_SOLARIS:
|
|
|
|
{
|
2019-03-09 20:42:37 +01:00
|
|
|
char *mapfile = get_temp_file( output_name, ".map" );
|
|
|
|
const char *align = opts->section_align ? opts->section_align : "0x1000";
|
|
|
|
|
|
|
|
create_file( mapfile, 0644, "text = A%s;\ndata = A%s;\n", align, align );
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, strmake("-Wl,-M,%s", mapfile) );
|
|
|
|
strarray_add( &tmp_files, mapfile );
|
2013-08-27 11:03:42 +02:00
|
|
|
}
|
2019-03-09 20:42:37 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLATFORM_ANDROID:
|
|
|
|
/* the Android loader requires a soname for all libraries */
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, strmake( "-Wl,-soname,%s.so", output_name ));
|
2019-03-09 20:42:37 +01:00
|
|
|
break;
|
|
|
|
|
2020-05-04 15:20:26 +02:00
|
|
|
case PLATFORM_MINGW:
|
2019-03-09 20:43:43 +01:00
|
|
|
case PLATFORM_CYGWIN:
|
2019-05-18 09:22:26 +02:00
|
|
|
if (opts->shared || opts->win16_app)
|
2019-03-09 20:43:43 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-shared" );
|
|
|
|
strarray_add( &flags, "-Wl,--kill-at" );
|
2019-03-09 20:43:43 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else strarray_add( &flags, opts->gui_app ? "-mwindows" : "-mconsole" );
|
2019-03-09 20:43:43 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->unicode_app) strarray_add( &flags, "-municode" );
|
|
|
|
if (opts->nodefaultlibs || opts->use_msvcrt) strarray_add( &flags, "-nodefaultlibs" );
|
|
|
|
if (opts->nostartfiles || opts->use_msvcrt) strarray_add( &flags, "-nostartfiles" );
|
|
|
|
if (opts->subsystem) strarray_add( &flags, strmake("-Wl,--subsystem,%s", opts->subsystem ));
|
2019-03-09 20:43:43 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-Wl,--nxcompat" );
|
2019-07-30 18:29:26 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->image_base) strarray_add( &flags, strmake("-Wl,--image-base,%s", opts->image_base ));
|
2019-03-09 20:43:43 +01:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->large_address_aware && opts->target.cpu == CPU_i386)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-Wl,--large-address-aware" );
|
2019-03-09 20:43:43 +01:00
|
|
|
|
2019-05-16 16:04:00 +02:00
|
|
|
/* make sure we don't need a libgcc_s dll on Windows */
|
2021-09-25 02:56:23 +02:00
|
|
|
if (!opts->nodefaultlibs && !opts->use_msvcrt)
|
|
|
|
strarray_add( &flags, "-static-libgcc" );
|
2019-05-16 16:04:00 +02:00
|
|
|
|
2020-05-14 16:39:48 +02:00
|
|
|
if (opts->debug_file && strendswith(opts->debug_file, ".pdb"))
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,-pdb,%s", opts->debug_file));
|
2020-05-14 16:39:48 +02:00
|
|
|
|
2020-11-25 20:41:43 +01:00
|
|
|
if (opts->out_implib)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,--out-implib,%s", opts->out_implib));
|
2020-11-25 20:41:43 +01:00
|
|
|
|
2020-07-13 19:49:22 +02:00
|
|
|
if (!try_link( opts->prefix, link_args, "-Wl,--file-alignment,0x1000" ))
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &link_args, strmake( "-Wl,--file-alignment,%s",
|
2020-07-23 20:33:16 +02:00
|
|
|
opts->file_align ? opts->file_align : "0x1000" ));
|
2020-07-31 16:22:43 +02:00
|
|
|
else if (!try_link( opts->prefix, link_args, "-Wl,-Xlink=-filealign:0x1000" ))
|
|
|
|
/* lld from llvm 10 does not support mingw style --file-alignment,
|
|
|
|
* but it's possible to use msvc syntax */
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &link_args, strmake( "-Wl,-Xlink=-filealign:%s",
|
2020-07-31 16:22:43 +02:00
|
|
|
opts->file_align ? opts->file_align : "0x1000" ));
|
2020-07-13 19:49:22 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link_args, flags );
|
2019-09-23 19:27:09 +02:00
|
|
|
return link_args;
|
2019-03-09 20:43:43 +01:00
|
|
|
|
2020-05-04 15:24:55 +02:00
|
|
|
case PLATFORM_WINDOWS:
|
|
|
|
if (opts->shared || opts->win16_app)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-shared" );
|
|
|
|
strarray_add( &flags, "-Wl,-kill-at" );
|
2020-05-04 15:24:55 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->unicode_app) strarray_add( &flags, "-municode" );
|
|
|
|
if (opts->nodefaultlibs || opts->use_msvcrt) strarray_add( &flags, "-nodefaultlibs" );
|
|
|
|
if (opts->nostartfiles || opts->use_msvcrt) strarray_add( &flags, "-nostartfiles" );
|
|
|
|
if (opts->image_base) strarray_add( &flags, strmake("-Wl,-base:%s", opts->image_base ));
|
2021-09-21 14:42:02 +02:00
|
|
|
if (opts->subsystem)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, strmake("-Wl,-subsystem:%s", opts->subsystem ));
|
2020-05-04 15:24:55 +02:00
|
|
|
else
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, strmake("-Wl,-subsystem:%s", opts->gui_app ? "windows" : "console" ));
|
2020-05-04 15:24:55 +02:00
|
|
|
|
2020-05-14 16:39:48 +02:00
|
|
|
if (opts->debug_file && strendswith(opts->debug_file, ".pdb"))
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, "-Wl,-debug");
|
|
|
|
strarray_add(&link_args, strmake("-Wl,-pdb:%s", opts->debug_file));
|
2020-05-14 16:39:48 +02:00
|
|
|
}
|
2021-02-17 21:36:29 +01:00
|
|
|
else if (!opts->strip)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, "-Wl,-debug:dwarf");
|
2020-11-25 20:41:43 +01:00
|
|
|
|
|
|
|
if (opts->out_implib)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,-implib:%s", opts->out_implib));
|
2020-11-25 20:41:43 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &link_args, strmake( "-Wl,-filealign:%s", opts->file_align ? opts->file_align : "0x1000" ));
|
2020-05-14 16:39:48 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link_args, flags );
|
2020-05-04 15:24:55 +02:00
|
|
|
return link_args;
|
|
|
|
|
2019-03-09 20:42:37 +01:00
|
|
|
default:
|
|
|
|
if (opts->image_base)
|
2013-08-27 11:03:42 +02:00
|
|
|
{
|
2019-09-23 19:27:09 +02:00
|
|
|
if (!try_link( opts->prefix, link_args, strmake("-Wl,-Ttext-segment=%s", opts->image_base)) )
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, strmake("-Wl,-Ttext-segment=%s", opts->image_base) );
|
2019-03-09 20:42:37 +01:00
|
|
|
else
|
|
|
|
opts->prelink = PRELINK;
|
2013-08-27 11:03:42 +02:00
|
|
|
}
|
2019-09-23 19:27:09 +02:00
|
|
|
if (!try_link( opts->prefix, link_args, "-Wl,-z,max-page-size=0x1000"))
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-Wl,-z,max-page-size=0x1000");
|
|
|
|
if (opts->unix_lib) strarray_add( &flags, strmake( "-Wl,-soname,%s.so", output_name ));
|
2013-08-27 11:03:42 +02:00
|
|
|
break;
|
2019-03-09 20:42:37 +01:00
|
|
|
}
|
2013-08-27 11:03:42 +02:00
|
|
|
|
2019-03-09 20:42:37 +01:00
|
|
|
/* generic Unix shared library flags */
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &link_args, "-shared" );
|
|
|
|
strarray_add( &link_args, "-Wl,-Bsymbolic" );
|
2021-11-16 21:02:12 +01:00
|
|
|
if (!opts->noshortwchar && opts->target.cpu == CPU_ARM)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-Wl,--no-wchar-size-warning" );
|
2020-04-15 17:52:04 +02:00
|
|
|
if (!try_link( opts->prefix, link_args, "-Wl,-z,defs" ))
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &flags, "-Wl,-z,defs" );
|
2019-03-09 20:42:37 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link_args, flags );
|
2019-09-23 19:27:09 +02:00
|
|
|
return link_args;
|
2013-08-27 11:03:42 +02:00
|
|
|
}
|
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
static const char *get_multiarch_dir( struct target target )
|
2018-11-21 13:33:52 +01:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
switch (target.cpu)
|
2018-11-21 13:33:52 +01:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
case CPU_i386: return "/i386-linux-gnu";
|
2018-11-21 13:33:52 +01:00
|
|
|
case CPU_x86_64: return "/x86_64-linux-gnu";
|
|
|
|
case CPU_ARM: return "/arm-linux-gnueabi";
|
|
|
|
case CPU_ARM64: return "/aarch64-linux-gnu";
|
|
|
|
}
|
2021-11-16 21:02:12 +01:00
|
|
|
assert(0);
|
|
|
|
return NULL;
|
2021-04-28 11:42:40 +02:00
|
|
|
}
|
|
|
|
|
2010-10-25 20:42:00 +02:00
|
|
|
static char *get_lib_dir( struct options *opts )
|
|
|
|
{
|
2020-01-30 11:49:49 +01:00
|
|
|
const char *stdlibpath[] = { libdir, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
|
2021-04-28 11:42:40 +02:00
|
|
|
const char *bit_suffix, *other_bit_suffix, *build_multiarch, *target_multiarch, *winecrt0;
|
2019-09-10 12:07:01 +02:00
|
|
|
const char *root = opts->sysroot ? opts->sysroot : "";
|
2010-10-25 20:42:00 +02:00
|
|
|
unsigned int i;
|
2021-04-28 11:42:40 +02:00
|
|
|
struct stat st;
|
2018-11-21 13:33:52 +01:00
|
|
|
size_t build_len, target_len;
|
2010-10-25 20:42:00 +02:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
bit_suffix = get_target_ptr_size( opts->target ) == 8 ? "64" : "32";
|
|
|
|
other_bit_suffix = get_target_ptr_size( opts->target ) == 8 ? "32" : "64";
|
|
|
|
winecrt0 = strmake( "/wine%s/libwinecrt0.a", get_arch_dir( opts->target ));
|
|
|
|
build_multiarch = get_multiarch_dir( get_default_target() );
|
|
|
|
target_multiarch = get_multiarch_dir( opts->target );
|
2018-11-21 13:33:52 +01:00
|
|
|
build_len = strlen( build_multiarch );
|
|
|
|
target_len = strlen( target_multiarch );
|
2018-08-17 16:58:15 +02:00
|
|
|
|
2019-09-23 18:53:19 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(stdlibpath); i++)
|
2010-10-25 20:42:00 +02:00
|
|
|
{
|
2020-01-30 11:49:49 +01:00
|
|
|
const char *root = (i && opts->sysroot) ? opts->sysroot : "";
|
|
|
|
char *p, *buffer;
|
|
|
|
|
|
|
|
if (!stdlibpath[i]) continue;
|
|
|
|
buffer = xmalloc( strlen(root) + strlen(stdlibpath[i]) +
|
2021-04-28 11:42:40 +02:00
|
|
|
strlen("/arm-linux-gnueabi") + strlen(winecrt0) + 1 );
|
2019-09-10 12:07:01 +02:00
|
|
|
strcpy( buffer, root );
|
|
|
|
strcat( buffer, stdlibpath[i] );
|
2010-10-25 20:42:00 +02:00
|
|
|
p = buffer + strlen(buffer);
|
|
|
|
while (p > buffer && p[-1] == '/') p--;
|
2021-04-28 11:42:40 +02:00
|
|
|
strcpy( p, winecrt0 );
|
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-07-19 16:50:33 +02:00
|
|
|
if (p > buffer + 2 && (!memcmp( p - 2, "32", 2 ) || !memcmp( p - 2, "64", 2 )))
|
|
|
|
{
|
|
|
|
p -= 2;
|
2021-04-28 11:42:40 +02:00
|
|
|
strcpy( p, winecrt0 );
|
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-07-19 16:50:33 +02:00
|
|
|
}
|
2018-08-17 16:58:15 +02:00
|
|
|
strcpy( p, bit_suffix );
|
2021-04-28 11:42:40 +02:00
|
|
|
strcat( p, winecrt0 );
|
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-11-21 13:33:52 +01:00
|
|
|
strcpy( p, target_multiarch );
|
2021-04-28 11:42:40 +02:00
|
|
|
strcat( p, winecrt0 );
|
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-08-17 16:58:15 +02:00
|
|
|
|
2019-09-10 12:07:01 +02:00
|
|
|
strcpy( buffer, root );
|
|
|
|
strcat( buffer, stdlibpath[i] );
|
2018-08-17 16:58:15 +02:00
|
|
|
p = buffer + strlen(buffer);
|
|
|
|
while (p > buffer && p[-1] == '/') p--;
|
2021-04-28 11:42:40 +02:00
|
|
|
strcpy( p, winecrt0 );
|
2018-08-17 16:58:15 +02:00
|
|
|
|
|
|
|
/* try to fixup each parent dirs named lib, lib32 or lib64 with target bitness suffix */
|
|
|
|
while (p > buffer)
|
|
|
|
{
|
|
|
|
p--;
|
|
|
|
while (p > buffer && *p != '/') p--;
|
|
|
|
if (*p != '/') break;
|
2018-11-21 13:33:52 +01:00
|
|
|
|
|
|
|
/* try s/$build_cpu/$target_cpu/ on multiarch */
|
2021-11-16 21:02:12 +01:00
|
|
|
if (get_default_target().cpu != opts->target.cpu &&
|
|
|
|
!memcmp( p, build_multiarch, build_len ) && p[build_len] == '/')
|
2018-11-21 13:33:52 +01:00
|
|
|
{
|
|
|
|
memmove( p + target_len, p + build_len, strlen( p + build_len ) + 1 );
|
|
|
|
memcpy( p, target_multiarch, target_len );
|
2021-04-28 11:42:40 +02:00
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-11-21 13:33:52 +01:00
|
|
|
memmove( p + build_len, p + target_len, strlen( p + target_len ) + 1 );
|
|
|
|
memcpy( p, build_multiarch, build_len );
|
|
|
|
}
|
|
|
|
|
2018-08-17 16:58:15 +02:00
|
|
|
if (memcmp( p + 1, "lib", 3 )) continue;
|
|
|
|
if (p[4] == '/')
|
|
|
|
{
|
|
|
|
memmove( p + 6, p + 4, strlen( p + 4 ) + 1 );
|
|
|
|
memcpy( p + 4, bit_suffix, 2 );
|
2021-04-28 11:42:40 +02:00
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-08-17 16:58:15 +02:00
|
|
|
memmove( p + 4, p + 6, strlen( p + 6 ) + 1 );
|
|
|
|
}
|
|
|
|
else if (!memcmp( p + 4, other_bit_suffix, 2 ) && p[6] == '/')
|
|
|
|
{
|
|
|
|
memcpy( p + 4, bit_suffix, 2 );
|
2021-04-28 11:42:40 +02:00
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-08-20 13:58:40 +02:00
|
|
|
memmove( p + 4, p + 6, strlen( p + 6 ) + 1 );
|
2021-04-28 11:42:40 +02:00
|
|
|
if (!stat( buffer, &st )) goto found;
|
2018-08-20 13:58:40 +02:00
|
|
|
memmove( p + 6, p + 4, strlen( p + 4 ) + 1 );
|
2018-08-17 16:58:15 +02:00
|
|
|
memcpy( p + 4, other_bit_suffix, 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-25 20:42:00 +02:00
|
|
|
free( buffer );
|
2010-10-28 11:45:05 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
found:
|
2021-04-28 11:42:40 +02:00
|
|
|
buffer[strlen(buffer) - strlen(winecrt0)] = 0;
|
2010-10-28 11:45:05 +02:00
|
|
|
return buffer;
|
2010-10-25 20:42:00 +02:00
|
|
|
}
|
2019-09-10 12:07:01 +02:00
|
|
|
return strmake( "%s%s", root, LIBDIR );
|
2010-10-25 20:42:00 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 11:49:49 +01:00
|
|
|
static void init_argv0_dir( const char *argv0 )
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
2021-09-29 11:13:36 +02:00
|
|
|
char *dir;
|
2020-01-30 11:49:49 +01:00
|
|
|
|
|
|
|
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
|
|
|
|
dir = realpath( "/proc/self/exe", NULL );
|
|
|
|
#elif defined (__FreeBSD__) || defined(__DragonFly__)
|
2021-10-23 10:17:45 +02:00
|
|
|
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
|
|
|
size_t path_size = PATH_MAX;
|
|
|
|
char *path = malloc( path_size );
|
|
|
|
if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
|
|
|
|
dir = realpath( path, NULL );
|
|
|
|
free( path );
|
2020-01-30 11:49:49 +01:00
|
|
|
#else
|
|
|
|
dir = realpath( argv0, NULL );
|
|
|
|
#endif
|
|
|
|
if (!dir) return;
|
2021-09-29 11:13:36 +02:00
|
|
|
bindir = get_dirname( dir );
|
|
|
|
includedir = strmake( "%s/%s", bindir, BIN_TO_INCLUDEDIR );
|
|
|
|
libdir = strmake( "%s/%s", bindir, BIN_TO_LIBDIR );
|
2020-01-30 11:49:49 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-04-17 01:30:32 +02:00
|
|
|
static void compile(struct options* opts, const char* lang)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray comp_args = get_translator(opts);
|
2012-05-10 22:43:26 +02:00
|
|
|
unsigned int i, j;
|
2007-02-10 12:57:25 +01:00
|
|
|
int gcc_defs = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray gcc;
|
|
|
|
struct strarray gpp;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2019-09-23 19:27:09 +02:00
|
|
|
if (opts->force_pointer_size)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &comp_args, strmake("-m%u", 8 * opts->force_pointer_size ) );
|
2004-03-02 03:23:26 +01:00
|
|
|
switch(opts->processor)
|
|
|
|
{
|
2009-02-02 12:19:11 +01:00
|
|
|
case proc_cpp: gcc_defs = 1; break;
|
|
|
|
case proc_as: gcc_defs = 0; break;
|
2004-03-02 03:23:26 +01:00
|
|
|
/* Note: if the C compiler is gcc we assume the C++ compiler is too */
|
|
|
|
/* mixing different C and C++ compilers isn't supported in configure anyway */
|
2009-02-02 12:19:11 +01:00
|
|
|
case proc_cc:
|
|
|
|
case proc_cxx:
|
2020-03-03 14:02:18 +01:00
|
|
|
gcc = build_tool_name(opts, TOOL_CC);
|
|
|
|
gpp = build_tool_name(opts, TOOL_CXX);
|
2021-09-23 11:52:15 +02:00
|
|
|
for ( j = 0; !gcc_defs && j < comp_args.count; j++ )
|
2009-10-09 19:14:52 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
const char *cc = comp_args.str[j];
|
2009-10-09 19:14:52 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; !gcc_defs && i < gcc.count; i++)
|
|
|
|
gcc_defs = gcc.str[i][0] != '-' && strendswith(cc, gcc.str[i]);
|
|
|
|
for (i = 0; !gcc_defs && i < gpp.count; i++)
|
|
|
|
gcc_defs = gpp.str[i][0] != '-' && strendswith(cc, gpp.str[i]);
|
2009-10-09 19:14:52 +02:00
|
|
|
}
|
2009-02-02 12:19:11 +01:00
|
|
|
break;
|
2004-03-02 03:23:26 +01:00
|
|
|
}
|
2009-02-02 12:19:11 +01:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target.platform == PLATFORM_WINDOWS ||
|
|
|
|
opts->target.platform == PLATFORM_CYGWIN ||
|
|
|
|
opts->target.platform == PLATFORM_MINGW)
|
2010-06-14 15:58:07 +02:00
|
|
|
goto no_compat_defines;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2004-03-09 01:42:21 +01:00
|
|
|
if (opts->processor != proc_cpp)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2009-02-02 12:19:11 +01:00
|
|
|
if (gcc_defs && !opts->wine_objdir && !opts->noshortwchar)
|
2004-03-02 03:23:26 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-fshort-wchar");
|
|
|
|
strarray_add(&comp_args, "-DWINE_UNICODE_NATIVE");
|
2004-03-02 03:23:26 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D_REENTRANT");
|
2019-04-29 06:04:54 +02:00
|
|
|
if (opts->pic)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-fPIC");
|
2019-04-29 06:04:54 +02:00
|
|
|
else
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-fno-PIC");
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
2005-03-11 11:25:59 +01:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (get_target_ptr_size( opts->target ) == 8)
|
2009-02-02 12:19:11 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-DWIN64");
|
|
|
|
strarray_add(&comp_args, "-D_WIN64");
|
|
|
|
strarray_add(&comp_args, "-D__WIN64");
|
|
|
|
strarray_add(&comp_args, "-D__WIN64__");
|
2009-02-02 12:19:11 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-DWIN32");
|
|
|
|
strarray_add(&comp_args, "-D_WIN32");
|
|
|
|
strarray_add(&comp_args, "-D__WIN32");
|
|
|
|
strarray_add(&comp_args, "-D__WIN32__");
|
|
|
|
strarray_add(&comp_args, "-D__WINNT");
|
|
|
|
strarray_add(&comp_args, "-D__WINNT__");
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2004-03-02 03:23:26 +01:00
|
|
|
if (gcc_defs)
|
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
switch (opts->target.cpu)
|
2009-02-02 12:19:11 +01:00
|
|
|
{
|
2015-11-16 14:52:41 +01:00
|
|
|
case CPU_x86_64:
|
2019-09-27 12:01:40 +02:00
|
|
|
case CPU_ARM64:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__stdcall=__attribute__((ms_abi))");
|
|
|
|
strarray_add(&comp_args, "-D__cdecl=__stdcall");
|
|
|
|
strarray_add(&comp_args, "-D__fastcall=__stdcall");
|
2015-11-16 14:52:41 +01:00
|
|
|
break;
|
2021-11-16 21:02:12 +01:00
|
|
|
case CPU_i386:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__stdcall=__attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))");
|
|
|
|
strarray_add(&comp_args, "-D__cdecl=__attribute__((__cdecl__)) __attribute__((__force_align_arg_pointer__))");
|
|
|
|
strarray_add(&comp_args, "-D__fastcall=__attribute__((__fastcall__))");
|
2015-11-16 14:52:41 +01:00
|
|
|
break;
|
|
|
|
case CPU_ARM:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__stdcall=__attribute__((pcs(\"aapcs-vfp\")))");
|
|
|
|
strarray_add(&comp_args, "-D__cdecl=__stdcall");
|
|
|
|
strarray_add(&comp_args, "-D__fastcall=__stdcall");
|
2019-09-30 09:35:47 +02:00
|
|
|
break;
|
2010-04-19 22:33:33 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D_stdcall=__stdcall");
|
|
|
|
strarray_add(&comp_args, "-D_cdecl=__cdecl");
|
|
|
|
strarray_add(&comp_args, "-D_fastcall=__fastcall");
|
|
|
|
strarray_add(&comp_args, "-D__declspec(x)=__declspec_##x");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_naked=__attribute__((naked))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_noinline=__attribute__((noinline))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
|
|
|
|
strarray_add(&comp_args, "-D__declspec_selectany=__attribute__((weak))");
|
|
|
|
strarray_add(&comp_args, "-D__declspec_thread=__thread");
|
2004-03-02 03:23:26 +01:00
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__int8=char");
|
|
|
|
strarray_add(&comp_args, "-D__int16=short");
|
|
|
|
strarray_add(&comp_args, "-D__int32=int");
|
2021-11-16 21:02:12 +01:00
|
|
|
if (get_target_ptr_size( opts->target ) == 8)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__int64=long");
|
2009-02-02 12:19:11 +01:00
|
|
|
else
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__int64=long long");
|
2009-02-02 12:19:11 +01:00
|
|
|
|
|
|
|
no_compat_defines:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__WINE__");
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* options we handle explicitly */
|
|
|
|
if (opts->compile_only)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-c");
|
2004-02-21 05:01:38 +01:00
|
|
|
if (opts->output_name)
|
2004-02-26 06:28:35 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-o");
|
|
|
|
strarray_add(&comp_args, opts->output_name);
|
2004-02-26 06:28:35 +01:00
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* the rest of the pass-through parameters */
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall(&comp_args, opts->compiler_args);
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2004-04-17 01:30:32 +02:00
|
|
|
/* the language option, if any */
|
|
|
|
if (lang && strcmp(lang, "-xnone"))
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, lang);
|
2004-04-17 01:30:32 +02:00
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* last, but not least, the files */
|
2021-09-23 11:52:15 +02:00
|
|
|
for ( j = 0; j < opts->files.count; j++ )
|
2004-04-17 01:30:32 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->files.str[j][0] != '-' || !opts->files.str[j][1]) /* not an option or bare '-' (i.e. stdin) */
|
|
|
|
strarray_add(&comp_args, opts->files.str[j]);
|
2004-04-17 01:30:32 +02:00
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2005-03-11 11:25:59 +01:00
|
|
|
/* standard includes come last in the include search path */
|
2006-07-11 21:32:36 +02:00
|
|
|
if (!opts->wine_objdir && !opts->nostdinc)
|
2005-03-11 11:25:59 +01:00
|
|
|
{
|
2019-09-23 15:53:28 +02:00
|
|
|
const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
|
2019-09-10 12:07:01 +02:00
|
|
|
const char *root = opts->isysroot ? opts->isysroot : opts->sysroot ? opts->sysroot : "";
|
2020-01-30 11:49:49 +01:00
|
|
|
const char *isystem = gcc_defs ? "-isystem" : "-I";
|
2021-04-22 18:30:52 +02:00
|
|
|
const char *idirafter = gcc_defs ? "-idirafter" : "-I";
|
2019-09-23 15:53:28 +02:00
|
|
|
|
2005-03-11 11:25:59 +01:00
|
|
|
if (opts->use_msvcrt)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (includedir) strarray_add( &comp_args, strmake( "%s%s/wine/msvcrt", isystem, includedir ));
|
2019-09-23 15:53:28 +02:00
|
|
|
for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
|
|
|
|
{
|
|
|
|
if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, strmake( "%s%s%s/wine/msvcrt", isystem, root, incl_dirs[j] ));
|
2019-09-23 15:53:28 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, "-D__MSVCRT__");
|
2005-03-11 11:25:59 +01:00
|
|
|
}
|
2021-04-22 18:30:52 +02:00
|
|
|
if (includedir)
|
2020-01-30 11:49:49 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &comp_args, strmake( "%s%s/wine/windows", isystem, includedir ));
|
|
|
|
strarray_add( &comp_args, strmake( "%s%s", idirafter, includedir ));
|
2020-01-30 11:49:49 +01:00
|
|
|
}
|
2019-09-23 15:53:28 +02:00
|
|
|
for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
|
|
|
|
{
|
|
|
|
if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, strmake( "%s%s%s/wine/windows", isystem, root, incl_dirs[j] ));
|
|
|
|
strarray_add(&comp_args, strmake( "%s%s%s", idirafter, root, incl_dirs[j] ));
|
2019-09-23 15:53:28 +02:00
|
|
|
}
|
2005-03-11 11:25:59 +01:00
|
|
|
}
|
2009-02-02 12:19:11 +01:00
|
|
|
else if (opts->wine_objdir)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&comp_args, strmake("-I%s/include", opts->wine_objdir) );
|
2005-03-11 11:25:59 +01:00
|
|
|
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, comp_args, 0);
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
2004-04-17 01:30:32 +02:00
|
|
|
static const char* compile_to_object(struct options* opts, const char* file, const char* lang)
|
2004-02-24 02:00:53 +01:00
|
|
|
{
|
|
|
|
struct options copts;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2005-03-08 17:55:26 +01:00
|
|
|
/* make a copy so we don't change any of the initial stuff */
|
2004-02-24 02:00:53 +01:00
|
|
|
/* a shallow copy is exactly what we want in this case */
|
|
|
|
copts = *opts;
|
2021-09-29 11:13:36 +02:00
|
|
|
copts.output_name = get_temp_file(get_basename_noext(file), ".o");
|
2004-02-24 02:00:53 +01:00
|
|
|
copts.compile_only = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
copts.files = empty_strarray;
|
|
|
|
strarray_add(&copts.files, file);
|
2004-04-17 01:30:32 +02:00
|
|
|
compile(&copts, lang);
|
2004-02-24 02:00:53 +01:00
|
|
|
return copts.output_name;
|
|
|
|
}
|
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
/* return the initial set of options needed to run winebuild */
|
2021-09-23 11:52:15 +02:00
|
|
|
static struct strarray get_winebuild_args(struct options *opts)
|
2009-05-30 15:24:07 +02:00
|
|
|
{
|
|
|
|
const char* winebuild = getenv("WINEBUILD");
|
2019-09-23 13:43:18 +02:00
|
|
|
const char *binary = NULL;
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray spec_args = empty_strarray;
|
2019-09-10 17:57:19 +02:00
|
|
|
unsigned int i;
|
2009-05-30 15:24:07 +02:00
|
|
|
|
2019-09-23 13:43:18 +02:00
|
|
|
if (opts->winebuild)
|
|
|
|
binary = opts->winebuild;
|
|
|
|
else if (opts->wine_objdir)
|
|
|
|
binary = strmake( "%s/tools/winebuild/winebuild%s", opts->wine_objdir, EXEEXT );
|
2020-02-06 21:12:25 +01:00
|
|
|
else if (winebuild)
|
|
|
|
binary = find_binary( opts->prefix, winebuild );
|
2020-01-30 11:49:49 +01:00
|
|
|
else if (bindir)
|
|
|
|
binary = strmake( "%s/winebuild%s", bindir, EXEEXT );
|
2019-09-23 13:43:18 +02:00
|
|
|
else
|
2020-02-06 21:12:25 +01:00
|
|
|
binary = find_binary( opts->prefix, "winebuild" );
|
2020-03-03 14:01:59 +01:00
|
|
|
if (!binary) error( "Could not find winebuild\n" );
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &spec_args, binary );
|
|
|
|
if (verbose) strarray_add( &spec_args, "-v" );
|
|
|
|
if (keep_generated) strarray_add( &spec_args, "--save-temps" );
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target_alias)
|
2009-05-30 15:24:07 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &spec_args, "--target" );
|
2021-11-16 21:02:12 +01:00
|
|
|
strarray_add( &spec_args, opts->target_alias );
|
2009-05-30 15:24:07 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; i < opts->prefix.count; i++)
|
|
|
|
strarray_add( &spec_args, strmake( "-B%s", opts->prefix.str[i] ));
|
|
|
|
strarray_addall( &spec_args, opts->winebuild_args );
|
|
|
|
if (opts->unwind_tables) strarray_add( &spec_args, "-fasynchronous-unwind-tables" );
|
|
|
|
else strarray_add( &spec_args, "-fno-asynchronous-unwind-tables" );
|
2009-05-30 15:24:07 +02:00
|
|
|
return spec_args;
|
|
|
|
}
|
|
|
|
|
2020-04-16 12:21:48 +02:00
|
|
|
static void fixup_constructors( struct options *opts, const char *file )
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray args = get_winebuild_args( opts );
|
2020-04-16 12:21:48 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &args, "--fixup-ctors" );
|
|
|
|
strarray_add( &args, file );
|
2020-04-16 12:21:48 +02:00
|
|
|
spawn( opts->prefix, args, 0 );
|
|
|
|
}
|
|
|
|
|
2019-12-18 21:05:44 +01:00
|
|
|
static void make_wine_builtin( struct options *opts, const char *file )
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray args = get_winebuild_args( opts );
|
2019-12-18 21:05:44 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &args, "--builtin" );
|
|
|
|
strarray_add( &args, file );
|
2019-12-18 21:05:44 +01:00
|
|
|
spawn( opts->prefix, args, 0 );
|
|
|
|
}
|
|
|
|
|
2005-05-09 16:38:06 +02:00
|
|
|
/* check if there is a static lib associated to a given dll */
|
|
|
|
static char *find_static_lib( const char *dll )
|
|
|
|
{
|
|
|
|
char *lib = strmake("%s.a", dll);
|
|
|
|
if (get_file_type(lib) == file_arh) return lib;
|
|
|
|
free( lib );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
static const char *find_libgcc(struct strarray prefix, struct strarray link_tool)
|
2019-09-23 13:57:57 +02:00
|
|
|
{
|
|
|
|
const char *out = get_temp_file( "find_libgcc", ".out" );
|
|
|
|
const char *err = get_temp_file( "find_libgcc", ".err" );
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray link = empty_strarray;
|
2019-09-23 13:57:57 +02:00
|
|
|
int sout = -1, serr = -1;
|
|
|
|
char *libgcc, *p;
|
|
|
|
struct stat st;
|
|
|
|
size_t cnt;
|
|
|
|
int ret;
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &link, link_tool );
|
|
|
|
strarray_add( &link, "-print-libgcc-file-name" );
|
2019-09-23 13:57:57 +02:00
|
|
|
|
|
|
|
sout = dup( fileno(stdout) );
|
|
|
|
freopen( out, "w", stdout );
|
|
|
|
serr = dup( fileno(stderr) );
|
|
|
|
freopen( err, "w", stderr );
|
|
|
|
ret = spawn( prefix, link, 1 );
|
|
|
|
if (sout >= 0)
|
|
|
|
{
|
|
|
|
dup2( sout, fileno(stdout) );
|
|
|
|
close( sout );
|
|
|
|
}
|
|
|
|
if (serr >= 0)
|
|
|
|
{
|
|
|
|
dup2( serr, fileno(stderr) );
|
|
|
|
close( serr );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret || stat(out, &st) || !st.st_size) return NULL;
|
|
|
|
|
|
|
|
libgcc = xmalloc(st.st_size + 1);
|
|
|
|
sout = open(out, O_RDONLY);
|
|
|
|
if (sout == -1) return NULL;
|
|
|
|
cnt = read(sout, libgcc, st.st_size);
|
|
|
|
close(sout);
|
|
|
|
libgcc[cnt] = 0;
|
|
|
|
if ((p = strchr(libgcc, '\n'))) *p = 0;
|
|
|
|
return libgcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-16 16:28:04 +01:00
|
|
|
/* add specified library to the list of files */
|
2021-09-23 11:52:15 +02:00
|
|
|
static void add_library( struct options *opts, struct strarray lib_dirs,
|
|
|
|
struct strarray *files, const char *library )
|
2006-03-16 16:28:04 +01:00
|
|
|
{
|
2021-09-21 14:42:02 +02:00
|
|
|
char *static_lib, *fullname = 0;
|
2006-03-16 16:28:04 +01:00
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
switch(get_lib_type(opts->target, lib_dirs, library, "lib", opts->lib_suffix, &fullname))
|
2006-03-16 16:28:04 +01:00
|
|
|
{
|
|
|
|
case file_arh:
|
|
|
|
strarray_add(files, strmake("-a%s", fullname));
|
|
|
|
break;
|
|
|
|
case file_dll:
|
|
|
|
strarray_add(files, strmake("-d%s", fullname));
|
|
|
|
if ((static_lib = find_static_lib(fullname)))
|
|
|
|
{
|
|
|
|
strarray_add(files, strmake("-a%s",static_lib));
|
|
|
|
free(static_lib);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case file_so:
|
|
|
|
default:
|
|
|
|
/* keep it anyway, the linker may know what to do with it */
|
|
|
|
strarray_add(files, strmake("-l%s", library));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(fullname);
|
|
|
|
}
|
|
|
|
|
2021-08-11 11:58:17 +02:00
|
|
|
/* run winebuild to generate the .spec.o file */
|
|
|
|
static const char *build_spec_obj( struct options *opts, const char *spec_file, const char *output_file,
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray files, struct strarray lib_dirs, const char *entry_point )
|
2021-08-11 11:58:17 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int is_pe = is_pe_target( opts );
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray spec_args = get_winebuild_args( opts );
|
|
|
|
struct strarray tool;
|
2021-08-11 11:58:17 +02:00
|
|
|
const char *spec_o_name, *output_name;
|
|
|
|
|
|
|
|
/* get the filename from the path */
|
2021-09-29 11:13:36 +02:00
|
|
|
output_name = get_basename( output_file );
|
2021-08-11 11:58:17 +02:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
tool = build_tool_name( opts, TOOL_CC );
|
|
|
|
strarray_add( &spec_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " )));
|
|
|
|
if (!is_pe)
|
|
|
|
{
|
|
|
|
tool = build_tool_name( opts, TOOL_LD );
|
|
|
|
strarray_add( &spec_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " )));
|
|
|
|
}
|
2021-08-11 11:58:17 +02:00
|
|
|
|
|
|
|
spec_o_name = get_temp_file(output_name, ".spec.o");
|
|
|
|
if (opts->force_pointer_size)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, strmake("-m%u", 8 * opts->force_pointer_size ));
|
|
|
|
if (opts->pic && !is_pe) strarray_add(&spec_args, "-fPIC");
|
|
|
|
strarray_add(&spec_args, opts->shared ? "--dll" : "--exe");
|
2021-11-18 19:47:40 +01:00
|
|
|
if (opts->fake_module)
|
2021-08-11 11:58:17 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "--fake-module");
|
|
|
|
strarray_add(&spec_args, "-o");
|
|
|
|
strarray_add(&spec_args, output_file);
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "-o");
|
|
|
|
strarray_add(&spec_args, spec_o_name);
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
if (spec_file)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "-E");
|
|
|
|
strarray_add(&spec_args, spec_file);
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts->shared)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "-F");
|
|
|
|
strarray_add(&spec_args, output_name);
|
|
|
|
strarray_add(&spec_args, "--subsystem");
|
|
|
|
strarray_add(&spec_args, opts->gui_app ? "windows" : "console");
|
|
|
|
if (opts->large_address_aware) strarray_add( &spec_args, "--large-address-aware" );
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target.platform == PLATFORM_WINDOWS) strarray_add(&spec_args, "--safeseh");
|
2021-08-11 11:58:17 +02:00
|
|
|
|
|
|
|
if (entry_point)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "--entry");
|
|
|
|
strarray_add(&spec_args, entry_point);
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
|
2021-09-21 14:42:02 +02:00
|
|
|
if (opts->subsystem)
|
2021-08-11 11:58:17 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "--subsystem");
|
|
|
|
strarray_add(&spec_args, opts->subsystem);
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; i < lib_dirs.count; i++)
|
|
|
|
strarray_add(&spec_args, strmake("-L%s", lib_dirs.str[i]));
|
2021-08-11 11:58:17 +02:00
|
|
|
|
|
|
|
if (!is_pe)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; i < opts->delayimports.count; i++)
|
|
|
|
strarray_add(&spec_args, strmake("-d%s", opts->delayimports.str[i]));
|
2021-08-11 11:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add resource files */
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; i < files.count; i++)
|
|
|
|
if (files.str[i][1] == 'r') strarray_add(&spec_args, files.str[i]);
|
2021-08-11 11:58:17 +02:00
|
|
|
|
|
|
|
/* add other files */
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, "--");
|
|
|
|
for (i = 0; i < files.count; i++)
|
2021-08-11 11:58:17 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
switch(files.str[i][1])
|
2021-08-11 11:58:17 +02:00
|
|
|
{
|
|
|
|
case 'd':
|
|
|
|
case 'a':
|
|
|
|
case 'o':
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&spec_args, files.str[i] + 2);
|
2021-08-11 11:58:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spawn(opts->prefix, spec_args, 0);
|
|
|
|
return spec_o_name;
|
|
|
|
}
|
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
static void build(struct options* opts)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray lib_dirs = empty_strarray;
|
|
|
|
struct strarray files = empty_strarray;
|
|
|
|
struct strarray link_args;
|
2019-03-12 10:02:50 +01:00
|
|
|
char *output_file, *output_path;
|
2021-08-11 11:59:26 +02:00
|
|
|
const char *spec_o_name = NULL, *libgcc = NULL;
|
2004-04-17 01:30:32 +02:00
|
|
|
const char *output_name, *spec_file, *lang;
|
2004-03-02 06:00:17 +01:00
|
|
|
int generate_app_loader = 1;
|
2020-01-21 19:52:05 +01:00
|
|
|
const char *crt_lib = NULL, *entry_point = NULL;
|
2021-05-14 16:53:40 +02:00
|
|
|
int is_pe = is_pe_target( opts );
|
2007-02-10 12:57:25 +01:00
|
|
|
unsigned int j;
|
2004-03-02 06:00:17 +01:00
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
/* NOTE: for the files array we'll use the following convention:
|
|
|
|
* -axxx: xxx is an archive (.a)
|
|
|
|
* -dxxx: xxx is a DLL (.def)
|
|
|
|
* -lxxx: xxx is an unsorted library
|
|
|
|
* -oxxx: xxx is an object (.o)
|
|
|
|
* -rxxx: xxx is a resource (.res)
|
|
|
|
* -sxxx: xxx is a shared lib (.so)
|
2004-04-17 01:30:32 +02:00
|
|
|
* -xlll: lll is the language (c, c++, etc.)
|
2004-03-04 07:06:06 +01:00
|
|
|
*/
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2004-03-23 01:14:54 +01:00
|
|
|
output_file = strdup( opts->output_name ? opts->output_name : "a.out" );
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2004-03-09 01:42:21 +01:00
|
|
|
/* 'winegcc -o app xxx.exe.so' only creates the load script */
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->files.count == 1 && strendswith(opts->files.str[0], ".exe.so"))
|
2004-03-03 21:11:20 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
create_file(output_file, 0755, app_loader_template, opts->files.str[0]);
|
2004-03-03 21:11:20 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-03-02 07:53:16 +01:00
|
|
|
|
2004-03-23 01:14:54 +01:00
|
|
|
/* generate app loader only for .exe */
|
2019-03-12 10:02:50 +01:00
|
|
|
if (opts->shared || is_pe || strendswith(output_file, ".so"))
|
2004-03-23 01:14:54 +01:00
|
|
|
generate_app_loader = 0;
|
|
|
|
|
2021-11-18 19:47:40 +01:00
|
|
|
if (strendswith(output_file, ".fake")) opts->fake_module = 1;
|
2009-08-18 11:26:43 +02:00
|
|
|
|
2004-03-23 01:14:54 +01:00
|
|
|
/* normalize the filename a bit: strip .so, ensure it has proper ext */
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!strchr(get_basename( output_file ), '.'))
|
2009-02-23 17:18:19 +01:00
|
|
|
output_file = strmake("%s.%s", output_file, opts->shared ? "dll" : "exe");
|
2020-05-14 14:01:24 +02:00
|
|
|
else if (strendswith(output_file, ".so"))
|
|
|
|
output_file[strlen(output_file) - 3] = 0;
|
2019-03-12 10:02:50 +01:00
|
|
|
output_path = is_pe ? output_file : strmake( "%s.so", output_file );
|
2004-03-23 01:14:54 +01:00
|
|
|
|
2004-04-09 21:02:18 +02:00
|
|
|
/* get the filename from the path */
|
2021-09-29 11:13:36 +02:00
|
|
|
output_name = get_basename( output_file );
|
2004-03-23 01:14:54 +01:00
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
/* prepare the linking path */
|
2006-07-11 21:32:36 +02:00
|
|
|
if (!opts->wine_objdir)
|
2004-03-09 05:20:58 +01:00
|
|
|
{
|
2010-10-25 20:42:00 +02:00
|
|
|
char *lib_dir = get_lib_dir( opts );
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &lib_dirs, opts->lib_dirs );
|
2021-11-16 21:02:12 +01:00
|
|
|
strarray_add( &lib_dirs, strmake( "%s/wine%s", lib_dir, get_arch_dir( opts->target )));
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &lib_dirs, lib_dir );
|
2004-03-09 05:20:58 +01:00
|
|
|
}
|
2006-07-11 21:32:36 +02:00
|
|
|
else
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&lib_dirs, strmake("%s/dlls", opts->wine_objdir));
|
|
|
|
strarray_addall(&lib_dirs, opts->lib_dirs);
|
2006-07-11 21:32:36 +02:00
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
/* mark the files with their appropriate type */
|
2004-04-17 01:30:32 +02:00
|
|
|
spec_file = lang = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
for ( j = 0; j < opts->files.count; j++ )
|
2004-02-24 02:00:53 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
const char* file = opts->files.str[j];
|
2004-03-04 07:06:06 +01:00
|
|
|
if (file[0] != '-')
|
2004-02-24 02:00:53 +01:00
|
|
|
{
|
2004-03-04 07:06:06 +01:00
|
|
|
switch(get_file_type(file))
|
|
|
|
{
|
2004-03-23 01:14:54 +01:00
|
|
|
case file_def:
|
|
|
|
case file_spec:
|
|
|
|
if (spec_file)
|
2007-10-18 17:11:47 +02:00
|
|
|
error("Only one spec file can be specified\n");
|
2004-03-23 01:14:54 +01:00
|
|
|
spec_file = file;
|
|
|
|
break;
|
2004-03-04 07:06:06 +01:00
|
|
|
case file_rc:
|
|
|
|
/* FIXME: invoke wrc to build it */
|
2007-10-18 17:11:47 +02:00
|
|
|
error("Can't compile .rc file at the moment: %s\n", file);
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
|
|
|
case file_res:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&files, strmake("-r%s", file));
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
|
|
|
case file_obj:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&files, strmake("-o%s", file));
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
2004-03-31 02:56:14 +02:00
|
|
|
case file_arh:
|
2019-08-06 12:24:19 +02:00
|
|
|
if (opts->use_msvcrt)
|
|
|
|
{
|
2021-09-29 11:13:36 +02:00
|
|
|
char *p = get_basename( file );
|
2019-08-06 12:24:19 +02:00
|
|
|
if (!strncmp(p, "libmsvcr", 8) || !strncmp(p, "libucrt", 7)) crt_lib = file;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&files, strmake("-a%s", file));
|
2019-08-06 12:24:19 +02:00
|
|
|
break;
|
2004-03-31 02:56:14 +02:00
|
|
|
case file_so:
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&files, strmake("-s%s", file));
|
2004-03-31 02:56:14 +02:00
|
|
|
break;
|
2004-03-04 07:06:06 +01:00
|
|
|
case file_na:
|
2007-10-18 17:11:47 +02:00
|
|
|
error("File does not exist: %s\n", file);
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
|
|
|
default:
|
2004-04-17 01:30:32 +02:00
|
|
|
file = compile_to_object(opts, file, lang);
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&files, strmake("-o%s", file));
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (file[1] == 'l')
|
2021-09-23 11:52:15 +02:00
|
|
|
add_library(opts, lib_dirs, &files, file + 2 );
|
2004-04-17 01:30:32 +02:00
|
|
|
else if (file[1] == 'x')
|
|
|
|
lang = file;
|
2020-05-25 20:34:31 +02:00
|
|
|
else if(file[1] == 'W')
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&files, file);
|
2004-02-24 02:00:53 +01:00
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2019-03-12 10:02:50 +01:00
|
|
|
/* add the default libraries, if needed */
|
2009-05-30 18:33:11 +02:00
|
|
|
|
2019-03-12 10:02:50 +01:00
|
|
|
if (!opts->wine_objdir && !opts->nodefaultlibs)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2019-03-12 10:02:50 +01:00
|
|
|
if (opts->gui_app)
|
2004-02-24 02:00:53 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
add_library(opts, lib_dirs, &files, "shell32");
|
|
|
|
add_library(opts, lib_dirs, &files, "comdlg32");
|
|
|
|
add_library(opts, lib_dirs, &files, "gdi32");
|
2004-02-24 02:00:53 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
add_library(opts, lib_dirs, &files, "advapi32");
|
|
|
|
add_library(opts, lib_dirs, &files, "user32");
|
|
|
|
add_library(opts, lib_dirs, &files, "winecrt0");
|
2019-08-06 12:24:19 +02:00
|
|
|
if (opts->use_msvcrt)
|
|
|
|
{
|
2020-11-19 11:35:22 +01:00
|
|
|
if (!crt_lib)
|
|
|
|
{
|
|
|
|
if (strncmp( output_name, "msvcr", 5 ) &&
|
|
|
|
strncmp( output_name, "ucrt", 4 ) &&
|
|
|
|
strcmp( output_name, "crtdll.dll" ))
|
2021-09-23 11:52:15 +02:00
|
|
|
add_library(opts, lib_dirs, &files, "ucrtbase");
|
2020-11-19 11:35:22 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else strarray_add(&files, strmake("-a%s", crt_lib));
|
2019-08-06 12:24:19 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->win16_app) add_library(opts, lib_dirs, &files, "kernel");
|
|
|
|
add_library(opts, lib_dirs, &files, "kernel32");
|
|
|
|
add_library(opts, lib_dirs, &files, "ntdll");
|
2010-07-21 13:03:12 +02:00
|
|
|
}
|
2005-08-25 13:41:05 +02:00
|
|
|
|
2020-01-21 19:52:05 +01:00
|
|
|
/* set default entry point, if needed */
|
|
|
|
if (!opts->entry_point)
|
|
|
|
{
|
2021-05-28 19:02:56 +02:00
|
|
|
if (opts->subsystem && !opts->unix_lib && !strcmp( opts->subsystem, "native" ))
|
2021-11-16 21:02:12 +01:00
|
|
|
entry_point = (is_pe && opts->target.cpu == CPU_i386) ? "DriverEntry@8" : "DriverEntry";
|
2020-04-15 16:06:22 +02:00
|
|
|
else if (opts->use_msvcrt && !opts->shared && !opts->win16_app)
|
2020-05-04 15:19:23 +02:00
|
|
|
entry_point = opts->unicode_app ? "wmainCRTStartup" : "mainCRTStartup";
|
2020-01-21 19:52:05 +01:00
|
|
|
}
|
|
|
|
else entry_point = opts->entry_point;
|
|
|
|
|
2005-09-21 13:00:21 +02:00
|
|
|
/* run winebuild to generate the .spec.o file */
|
2021-09-21 14:42:02 +02:00
|
|
|
if (spec_file || !opts->unix_lib)
|
2021-08-11 11:59:26 +02:00
|
|
|
spec_o_name = build_spec_obj( opts, spec_file, output_file, files, lib_dirs, entry_point );
|
2015-01-14 10:52:48 +01:00
|
|
|
|
2021-11-18 19:47:40 +01:00
|
|
|
if (opts->fake_module) return; /* nothing else to do */
|
2004-02-24 02:00:53 +01:00
|
|
|
|
|
|
|
/* link everything together now */
|
2019-03-09 20:42:37 +01:00
|
|
|
link_args = get_link_args( opts, output_name );
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2022-01-05 00:00:28 +01:00
|
|
|
if (opts->nodefaultlibs || opts->use_msvcrt)
|
2019-09-23 13:57:57 +02:00
|
|
|
{
|
2022-01-05 00:00:28 +01:00
|
|
|
switch (opts->target.platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_MINGW:
|
|
|
|
case PLATFORM_CYGWIN:
|
|
|
|
libgcc = find_libgcc( opts->prefix, link_args );
|
|
|
|
if (!libgcc) libgcc = "-lgcc";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-09-23 13:57:57 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, "-o");
|
|
|
|
strarray_add(&link_args, output_path);
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
for ( j = 0; j < lib_dirs.count; j++ )
|
|
|
|
strarray_add(&link_args, strmake("-L%s", lib_dirs.str[j]));
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2020-05-04 15:19:43 +02:00
|
|
|
if (is_pe && opts->use_msvcrt && !entry_point && (opts->shared || opts->win16_app))
|
2021-11-16 21:02:12 +01:00
|
|
|
entry_point = opts->target.cpu == CPU_i386 ? "DllMainCRTStartup@12" : "DllMainCRTStartup";
|
2020-05-04 15:19:43 +02:00
|
|
|
|
2020-05-04 15:19:23 +02:00
|
|
|
if (is_pe && entry_point)
|
2020-05-04 15:24:55 +02:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target.platform == PLATFORM_WINDOWS)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,-entry:%s", entry_point));
|
2020-05-04 15:24:55 +02:00
|
|
|
else
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,--entry,%s%s",
|
2021-11-16 21:02:12 +01:00
|
|
|
is_pe && opts->target.cpu == CPU_i386 ? "_" : "",
|
2020-05-04 15:24:55 +02:00
|
|
|
entry_point));
|
|
|
|
}
|
2020-01-21 19:52:05 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
if (spec_o_name) strarray_add(&link_args, spec_o_name);
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2019-11-11 19:56:49 +01:00
|
|
|
if (is_pe)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
for (j = 0; j < opts->delayimports.count; j++)
|
2020-05-04 15:24:55 +02:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->target.platform == PLATFORM_WINDOWS)
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,-delayload:%s", opts->delayimports.str[j]));
|
2020-05-04 15:24:55 +02:00
|
|
|
else
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-Wl,-delayload,%s",opts->delayimports.str[j]));
|
2020-05-04 15:24:55 +02:00
|
|
|
}
|
2019-11-11 19:56:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
for ( j = 0; j < files.count; j++ )
|
2004-03-04 07:06:06 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
const char* name = files.str[j] + 2;
|
|
|
|
switch(files.str[j][1])
|
2004-03-04 07:06:06 +01:00
|
|
|
{
|
2004-03-09 05:49:42 +01:00
|
|
|
case 'l':
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, strmake("-l%s", name));
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
2010-04-23 10:55:28 +02:00
|
|
|
case 's':
|
2004-03-04 07:06:06 +01:00
|
|
|
case 'o':
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, name);
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
2019-03-12 10:02:50 +01:00
|
|
|
case 'a':
|
2021-11-17 14:56:38 +01:00
|
|
|
if (!opts->use_msvcrt && !opts->lib_suffix && strchr(name, '/'))
|
2019-03-12 10:02:50 +01:00
|
|
|
{
|
|
|
|
/* turn the path back into -Ldir -lfoo options
|
|
|
|
* this makes sure that we use the specified libs even
|
|
|
|
* when mingw adds its own import libs to the link */
|
2021-09-29 11:13:36 +02:00
|
|
|
const char *p = get_basename( name );
|
2019-03-12 10:02:50 +01:00
|
|
|
|
2021-11-17 14:56:38 +01:00
|
|
|
if (is_pe)
|
2019-03-12 10:02:50 +01:00
|
|
|
{
|
2021-11-17 14:56:38 +01:00
|
|
|
if (!strncmp( p, "lib", 3 ) && strcmp( p, "libmsvcrt.a" ))
|
|
|
|
{
|
|
|
|
strarray_add(&link_args, strmake("-L%s", get_dirname(name) ));
|
|
|
|
strarray_add(&link_args, strmake("-l%s", get_basename_noext( p + 3 )));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* don't link to ntdll or ntoskrnl in non-msvcrt mode
|
|
|
|
* since they export CRT functions */
|
|
|
|
if (!strcmp( p, "libntdll.a" )) break;
|
|
|
|
if (!strcmp( p, "libntoskrnl.a" )) break;
|
2019-03-12 10:02:50 +01:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, name);
|
2019-03-12 10:02:50 +01:00
|
|
|
break;
|
2020-05-25 20:34:31 +02:00
|
|
|
case 'W':
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, files.str[j]);
|
2020-05-25 20:34:31 +02:00
|
|
|
break;
|
2004-03-04 07:06:06 +01:00
|
|
|
}
|
|
|
|
}
|
2004-03-03 23:38:25 +01:00
|
|
|
|
2019-03-12 10:02:50 +01:00
|
|
|
if (!opts->nostdlib && !is_pe)
|
2004-03-04 07:06:06 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&link_args, "-lm");
|
|
|
|
strarray_add(&link_args, "-lc");
|
2004-03-04 07:06:06 +01:00
|
|
|
}
|
2004-03-03 23:38:25 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
if (libgcc) strarray_add(&link_args, libgcc);
|
2019-06-12 22:38:09 +02:00
|
|
|
|
2020-02-21 13:52:31 +01:00
|
|
|
output_file_name = output_path;
|
2020-05-14 16:39:48 +02:00
|
|
|
output_debug_file = opts->debug_file;
|
2020-11-25 20:41:43 +01:00
|
|
|
output_implib = opts->out_implib;
|
2020-02-21 13:52:31 +01:00
|
|
|
atexit( cleanup_output_files );
|
|
|
|
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, link_args, 0);
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2020-05-14 16:39:48 +02:00
|
|
|
if (opts->debug_file && !strendswith(opts->debug_file, ".pdb"))
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray tool, objcopy = build_tool_name(opts, TOOL_OBJCOPY);
|
2020-05-14 16:39:48 +02:00
|
|
|
|
2021-09-24 10:17:40 +02:00
|
|
|
tool = empty_strarray;
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall( &tool, objcopy );
|
|
|
|
strarray_add(&tool, "--only-keep-debug");
|
|
|
|
strarray_add(&tool, output_path);
|
|
|
|
strarray_add(&tool, opts->debug_file);
|
2020-05-14 16:39:48 +02:00
|
|
|
spawn(opts->prefix, tool, 1);
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
tool = empty_strarray;
|
|
|
|
strarray_addall( &tool, objcopy );
|
|
|
|
strarray_add(&tool, "--strip-debug");
|
|
|
|
strarray_add(&tool, output_path);
|
2020-05-14 16:39:48 +02:00
|
|
|
spawn(opts->prefix, tool, 1);
|
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
tool = empty_strarray;
|
|
|
|
strarray_addall( &tool, objcopy );
|
|
|
|
strarray_add(&tool, "--add-gnu-debuglink");
|
|
|
|
strarray_add(&tool, opts->debug_file);
|
|
|
|
strarray_add(&tool, output_path);
|
2020-05-14 16:39:48 +02:00
|
|
|
spawn(opts->prefix, tool, 0);
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:17:36 +02:00
|
|
|
if (opts->unix_lib) return;
|
|
|
|
|
2020-11-25 20:41:43 +01:00
|
|
|
if (opts->out_implib && !is_pe)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray tool, implib_args;
|
|
|
|
|
2020-11-25 20:41:43 +01:00
|
|
|
if (!spec_file)
|
|
|
|
error("--out-implib requires a .spec or .def file\n");
|
|
|
|
|
|
|
|
implib_args = get_winebuild_args( opts );
|
2021-09-23 11:52:15 +02:00
|
|
|
tool = build_tool_name( opts, TOOL_CC );
|
|
|
|
strarray_add( &implib_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " )));
|
|
|
|
tool = build_tool_name( opts, TOOL_LD );
|
|
|
|
strarray_add( &implib_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " )));
|
2020-11-25 20:41:43 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&implib_args, "--implib");
|
|
|
|
strarray_add(&implib_args, "-o");
|
|
|
|
strarray_add(&implib_args, opts->out_implib);
|
|
|
|
strarray_add(&implib_args, "--export");
|
|
|
|
strarray_add(&implib_args, spec_file);
|
2020-11-25 20:41:43 +01:00
|
|
|
|
|
|
|
spawn(opts->prefix, implib_args, 0);
|
|
|
|
}
|
|
|
|
|
2015-10-22 03:54:38 +02:00
|
|
|
/* set the base address with prelink if linker support is not present */
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts->prelink && !opts->target_alias)
|
2005-08-09 13:12:29 +02:00
|
|
|
{
|
2019-03-09 20:42:37 +01:00
|
|
|
if (opts->prelink[0] && strcmp(opts->prelink,"false"))
|
2005-08-09 13:12:29 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray prelink_args = empty_strarray;
|
|
|
|
strarray_add(&prelink_args, opts->prelink);
|
|
|
|
strarray_add(&prelink_args, "--reloc-only");
|
|
|
|
strarray_add(&prelink_args, opts->image_base);
|
|
|
|
strarray_add(&prelink_args, output_path);
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, prelink_args, 1);
|
2005-08-09 13:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 11:27:53 +02:00
|
|
|
if (!is_pe) fixup_constructors( opts, output_path );
|
|
|
|
else if (opts->wine_builtin) make_wine_builtin( opts, output_path );
|
2020-04-16 12:21:48 +02:00
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
/* create the loader script */
|
2004-03-02 06:00:17 +01:00
|
|
|
if (generate_app_loader)
|
2009-02-23 17:18:19 +01:00
|
|
|
create_file(output_file, 0755, app_loader_template, strmake("%s.so", output_name));
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-25 20:33:35 +02:00
|
|
|
static void forward( struct options *opts )
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray args = get_translator(opts);
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_addall(&args, opts->compiler_args);
|
|
|
|
strarray_addall(&args, opts->linker_args);
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, args, 0);
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int is_linker_arg(const char* arg)
|
|
|
|
{
|
|
|
|
static const char* link_switches[] =
|
|
|
|
{
|
2018-12-03 16:05:14 +01:00
|
|
|
"-nostdlib", "-s", "-static", "-static-libgcc", "-static-libstdc++",
|
|
|
|
"-shared", "-shared-libgcc", "-symbolic", "-framework", "--coverage",
|
|
|
|
"-fprofile-generate", "-fprofile-use"
|
2004-02-21 05:01:38 +01:00
|
|
|
};
|
2007-02-10 12:57:25 +01:00
|
|
|
unsigned int j;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
switch (arg[1])
|
|
|
|
{
|
2007-05-05 20:33:58 +02:00
|
|
|
case 'R':
|
|
|
|
case 'z':
|
2004-02-21 05:01:38 +01:00
|
|
|
case 'u':
|
|
|
|
return 1;
|
|
|
|
case 'W':
|
|
|
|
if (strncmp("-Wl,", arg, 4) == 0) return 1;
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
if (strcmp("-Xlinker", arg) == 0) return 1;
|
|
|
|
break;
|
2009-05-02 05:59:25 +02:00
|
|
|
case 'a':
|
|
|
|
if (strcmp("-arch", arg) == 0) return 1;
|
|
|
|
break;
|
2019-11-25 03:13:31 +01:00
|
|
|
case 'f':
|
|
|
|
if (strncmp("-fuse-ld=", arg, 9) == 0) return 1;
|
|
|
|
break;
|
2020-02-21 13:57:52 +01:00
|
|
|
case 'r':
|
|
|
|
if (strncmp("-rtlib=", arg, 7) == 0) return 1;
|
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
2019-09-23 18:53:19 +02:00
|
|
|
for (j = 0; j < ARRAY_SIZE(link_switches); j++)
|
2004-02-21 05:01:38 +01:00
|
|
|
if (strcmp(link_switches[j], arg) == 0) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
static void parse_target_option( struct options *opts, const char *target )
|
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
opts->target_alias = xstrdup( target );
|
|
|
|
if (!parse_target( target, &opts->target )) error( "Invalid target specification '%s'\n", target );
|
2009-02-02 12:25:37 +01:00
|
|
|
}
|
|
|
|
|
2020-05-25 20:33:35 +02:00
|
|
|
static int is_option( struct options *opts, int i, const char *option, const char **option_arg )
|
2019-09-23 13:43:18 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp( opts->args.str[i], option ))
|
2019-09-23 13:43:18 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts->args.count == i) error( "option %s requires an argument\n", opts->args.str[i] );
|
|
|
|
*option_arg = opts->args.str[i + 1];
|
2019-09-23 13:43:18 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strncmp( opts->args.str[i], option, strlen(option) ) && opts->args.str[i][strlen(option)] == '=')
|
2019-09-23 13:43:18 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
*option_arg = opts->args.str[i] + strlen(option) + 1;
|
2019-09-23 13:43:18 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-05 20:12:13 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2004-02-21 05:01:38 +01:00
|
|
|
int i, c, next_is_arg = 0, linking = 1;
|
2021-01-22 13:59:48 +01:00
|
|
|
int raw_compiler_arg, raw_linker_arg, raw_winebuild_arg;
|
2004-02-21 05:01:38 +01:00
|
|
|
const char* option_arg;
|
|
|
|
struct options opts;
|
2004-04-17 01:30:32 +02:00
|
|
|
char* lang = 0;
|
2004-03-09 02:34:00 +01:00
|
|
|
char* str;
|
2002-12-15 02:17:10 +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 );
|
2004-12-07 18:19:54 +01:00
|
|
|
#ifdef HAVE_SIGADDSET
|
2004-12-02 19:22:48 +01:00
|
|
|
sigemptyset( &signal_mask );
|
|
|
|
sigaddset( &signal_mask, SIGHUP );
|
|
|
|
sigaddset( &signal_mask, SIGTERM );
|
|
|
|
sigaddset( &signal_mask, SIGINT );
|
2004-12-07 18:19:54 +01:00
|
|
|
#endif
|
2020-01-30 11:49:49 +01:00
|
|
|
init_argv0_dir( argv[0] );
|
2004-12-02 19:22:48 +01:00
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* setup tmp file removal at exit */
|
2003-01-07 20:47:19 +01:00
|
|
|
atexit(clean_temp_files);
|
2020-01-30 11:49:49 +01:00
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* initialize options */
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
2021-11-16 21:02:12 +01:00
|
|
|
opts.target = init_argv0_target( argv[0] );
|
2019-04-29 06:04:54 +02:00
|
|
|
opts.pic = 1;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* determine the processor type */
|
2004-03-09 01:42:21 +01:00
|
|
|
if (strendswith(argv[0], "winecpp")) opts.processor = proc_cpp;
|
|
|
|
else if (strendswith(argv[0], "++")) opts.processor = proc_cxx;
|
2003-01-07 20:47:19 +01:00
|
|
|
|
2020-05-25 20:33:35 +02:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
2020-05-25 20:34:08 +02:00
|
|
|
char *input_buffer = NULL, *iter, *opt, *out;
|
|
|
|
struct stat st;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (argv[i][0] != '@' || (fd = open( argv[i] + 1, O_RDONLY | O_BINARY )) == -1)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.args, argv[i] );
|
2020-05-25 20:34:08 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-03-02 20:11:53 +01:00
|
|
|
if ((fstat( fd, &st ) == -1)) error( "Cannot stat %s\n", argv[i] + 1 );
|
2020-05-25 20:34:08 +02:00
|
|
|
if (st.st_size)
|
|
|
|
{
|
|
|
|
input_buffer = xmalloc( st.st_size + 1 );
|
|
|
|
if (read( fd, input_buffer, st.st_size ) != st.st_size) error( "Cannot read %s\n", argv[i] + 1 );
|
|
|
|
}
|
|
|
|
close( fd );
|
|
|
|
for (iter = input_buffer; iter < input_buffer + st.st_size; iter++)
|
|
|
|
{
|
|
|
|
char quote = 0;
|
|
|
|
while (iter < input_buffer + st.st_size && isspace(*iter)) iter++;
|
|
|
|
if (iter == input_buffer + st.st_size) break;
|
|
|
|
opt = out = iter;
|
|
|
|
while (iter < input_buffer + st.st_size && (quote || !isspace(*iter)))
|
|
|
|
{
|
|
|
|
if (*iter == quote)
|
|
|
|
{
|
|
|
|
iter++;
|
|
|
|
quote = 0;
|
|
|
|
}
|
|
|
|
else if (*iter == '\'' || *iter == '"') quote = *iter++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*iter == '\\' && iter + 1 < input_buffer + st.st_size) iter++;
|
|
|
|
*out++ = *iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.args, opt );
|
2020-05-25 20:34:08 +02:00
|
|
|
}
|
2020-05-25 20:33:35 +02:00
|
|
|
}
|
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* parse options */
|
2021-09-23 11:52:15 +02:00
|
|
|
for (i = 0; i < opts.args.count; i++)
|
2002-12-15 02:17:10 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts.args.str[i][0] == '-' && opts.args.str[i][1]) /* option, except '-' alone is stdin, which is a file */
|
2002-12-15 02:17:10 +01:00
|
|
|
{
|
2011-07-28 21:51:20 +02:00
|
|
|
/* determine if this switch is followed by a separate argument */
|
2004-02-26 06:28:35 +01:00
|
|
|
next_is_arg = 0;
|
2004-02-21 05:01:38 +01:00
|
|
|
option_arg = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
switch(opts.args.str[i][1])
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
|
|
|
case 'x': case 'o': case 'D': case 'U':
|
|
|
|
case 'I': case 'A': case 'l': case 'u':
|
2004-03-02 06:00:17 +01:00
|
|
|
case 'b': case 'V': case 'G': case 'L':
|
2007-05-05 20:33:58 +02:00
|
|
|
case 'B': case 'R': case 'z':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts.args.str[i][2]) option_arg = &opts.args.str[i][2];
|
2004-02-21 05:01:38 +01:00
|
|
|
else next_is_arg = 1;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
next_is_arg = 1;
|
|
|
|
break;
|
|
|
|
case 'a':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-aux-info", opts.args.str[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
next_is_arg = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-arch", opts.args.str[i]) == 0)
|
2009-05-02 05:59:25 +02:00
|
|
|
next_is_arg = 1;
|
2004-02-21 05:01:38 +01:00
|
|
|
break;
|
|
|
|
case 'X':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-Xlinker", opts.args.str[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
next_is_arg = 1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
2021-09-23 11:52:15 +02:00
|
|
|
c = opts.args.str[i][2];
|
2004-02-21 05:01:38 +01:00
|
|
|
if (c == 'F' || c == 'T' || c == 'Q')
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts.args.str[i][3]) option_arg = &opts.args.str[i][3];
|
2004-02-21 05:01:38 +01:00
|
|
|
else next_is_arg = 1;
|
|
|
|
}
|
|
|
|
break;
|
2004-08-19 03:20:45 +02:00
|
|
|
case 'f':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-framework", opts.args.str[i]) == 0)
|
2004-08-19 03:20:45 +02:00
|
|
|
next_is_arg = 1;
|
|
|
|
break;
|
2020-02-21 13:52:20 +01:00
|
|
|
case 't':
|
2021-09-23 11:52:15 +02:00
|
|
|
next_is_arg = strcmp("-target", opts.args.str[i]) == 0;
|
2020-02-21 13:52:20 +01:00
|
|
|
break;
|
2010-06-15 21:30:01 +02:00
|
|
|
case '-':
|
2021-09-23 11:52:15 +02:00
|
|
|
next_is_arg = (strcmp("--param", opts.args.str[i]) == 0 ||
|
|
|
|
strcmp("--sysroot", opts.args.str[i]) == 0 ||
|
|
|
|
strcmp("--target", opts.args.str[i]) == 0 ||
|
|
|
|
strcmp("--wine-objdir", opts.args.str[i]) == 0 ||
|
|
|
|
strcmp("--winebuild", opts.args.str[i]) == 0 ||
|
|
|
|
strcmp("--lib-suffix", opts.args.str[i]) == 0);
|
2010-06-15 21:30:01 +02:00
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
2011-03-26 12:16:51 +01:00
|
|
|
if (next_is_arg)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (i + 1 >= opts.args.count) error("option -%c requires an argument\n", opts.args.str[i][1]);
|
|
|
|
option_arg = opts.args.str[i+1];
|
2011-03-26 12:16:51 +01:00
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* determine what options go 'as is' to the linker & the compiler */
|
2021-09-23 11:52:15 +02:00
|
|
|
raw_linker_arg = is_linker_arg(opts.args.str[i]);
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = !raw_linker_arg;
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 0;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* do a bit of semantic analysis */
|
2021-09-23 11:52:15 +02:00
|
|
|
switch (opts.args.str[i][1])
|
2002-12-15 02:17:10 +01:00
|
|
|
{
|
2004-03-09 02:34:00 +01:00
|
|
|
case 'B':
|
|
|
|
str = strdup(option_arg);
|
2011-08-22 10:40:10 +02:00
|
|
|
if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&opts.prefix, str);
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_linker_arg = 1;
|
2004-03-09 02:34:00 +01:00
|
|
|
break;
|
2009-02-02 12:25:37 +01:00
|
|
|
case 'b':
|
|
|
|
parse_target_option( &opts, option_arg );
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2009-02-02 12:25:37 +01:00
|
|
|
break;
|
2011-03-15 21:17:48 +01:00
|
|
|
case 'V':
|
|
|
|
opts.version = xstrdup( option_arg );
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2011-03-15 21:17:48 +01:00
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'c': /* compile or assemble */
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts.args.str[i][2] == 0) opts.compile_only = 1;
|
2004-02-21 05:01:38 +01:00
|
|
|
/* fall through */
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'S': /* generate assembler code */
|
|
|
|
case 'E': /* preprocess only */
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts.args.str[i][2] == 0) linking = 0;
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
2004-03-02 03:23:26 +01:00
|
|
|
case 'f':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-fno-short-wchar", opts.args.str[i]) == 0)
|
2004-03-02 03:23:26 +01:00
|
|
|
opts.noshortwchar = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (!strcmp("-fasynchronous-unwind-tables", opts.args.str[i]))
|
2010-04-11 12:32:01 +02:00
|
|
|
opts.unwind_tables = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (!strcmp("-fno-asynchronous-unwind-tables", opts.args.str[i]))
|
2010-04-11 12:32:01 +02:00
|
|
|
opts.unwind_tables = 0;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (!strcmp("-fPIC", opts.args.str[i]) || !strcmp("-fpic", opts.args.str[i]))
|
2019-04-29 06:04:54 +02:00
|
|
|
opts.pic = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (!strcmp("-fno-PIC", opts.args.str[i]) || !strcmp("-fno-pic", opts.args.str[i]))
|
2019-04-29 06:04:54 +02:00
|
|
|
opts.pic = 0;
|
2004-03-02 03:23:26 +01:00
|
|
|
break;
|
2019-09-10 12:07:01 +02:00
|
|
|
case 'i':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp( "-isysroot", opts.args.str[i] )) opts.isysroot = opts.args.str[i + 1];
|
2019-09-10 12:07:01 +02:00
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
case 'l':
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&opts.files, strmake("-l%s", option_arg));
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2004-02-21 05:01:38 +01:00
|
|
|
break;
|
|
|
|
case 'L':
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&opts.lib_dirs, option_arg);
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2004-02-21 05:01:38 +01:00
|
|
|
break;
|
2003-01-03 23:31:56 +01:00
|
|
|
case 'M': /* map file generation */
|
|
|
|
linking = 0;
|
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'm':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-mno-cygwin", opts.args.str[i]) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.use_msvcrt = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-mcygwin", opts.args.str[i]) == 0)
|
2021-09-20 16:58:11 +02:00
|
|
|
{
|
|
|
|
opts.use_msvcrt = 0;
|
|
|
|
raw_compiler_arg = 0;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-mwindows", opts.args.str[i]) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.gui_app = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-mconsole", opts.args.str[i]) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.gui_app = 0;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-municode", opts.args.str[i]) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
2005-08-25 21:26:59 +02:00
|
|
|
opts.unicode_app = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-mthreads", opts.args.str[i]) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
|
|
|
raw_compiler_arg = 0;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-munix", opts.args.str[i]) == 0)
|
2020-07-01 10:36:42 +02:00
|
|
|
{
|
|
|
|
opts.unix_lib = 1;
|
|
|
|
raw_compiler_arg = 0;
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 1;
|
2020-07-01 10:36:42 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-m16", opts.args.str[i]) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
2010-07-21 12:44:12 +02:00
|
|
|
opts.win16_app = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 1;
|
2019-09-27 13:25:59 +02:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-m32", opts.args.str[i]) == 0)
|
2009-02-04 20:10:49 +01:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
set_target_ptr_size( &opts.target, 4 );
|
2009-02-04 20:10:49 +01:00
|
|
|
opts.force_pointer_size = 4;
|
2006-01-25 13:15:34 +01:00
|
|
|
raw_linker_arg = 1;
|
2009-02-04 20:10:49 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-m64", opts.args.str[i]) == 0)
|
2009-02-04 20:10:49 +01:00
|
|
|
{
|
2021-11-16 21:02:12 +01:00
|
|
|
set_target_ptr_size( &opts.target, 8 );
|
2009-02-04 20:10:49 +01:00
|
|
|
opts.force_pointer_size = 8;
|
|
|
|
raw_linker_arg = 1;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (!strcmp("-marm", opts.args.str[i] ) || !strcmp("-mthumb", opts.args.str[i] ))
|
2014-02-12 12:57:48 +01:00
|
|
|
{
|
|
|
|
raw_linker_arg = 1;
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 1;
|
2014-02-12 12:57:48 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (!strncmp("-mcpu=", opts.args.str[i], 6) ||
|
|
|
|
!strncmp("-mfpu=", opts.args.str[i], 6) ||
|
|
|
|
!strncmp("-march=", opts.args.str[i], 7) ||
|
|
|
|
!strncmp("-mfloat-abi=", opts.args.str[i], 12))
|
2021-01-22 13:59:48 +01:00
|
|
|
raw_winebuild_arg = 1;
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
|
|
|
case 'n':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-nostdinc", opts.args.str[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.nostdinc = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-nodefaultlibs", opts.args.str[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.nodefaultlibs = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-nostdlib", opts.args.str[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.nostdlib = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strcmp("-nostartfiles", opts.args.str[i]) == 0)
|
2005-08-25 13:41:05 +02:00
|
|
|
opts.nostartfiles = 1;
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
case 'o':
|
|
|
|
opts.output_name = option_arg;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_compiler_arg = 0;
|
2004-02-21 05:01:38 +01:00
|
|
|
break;
|
2021-07-02 11:47:59 +02:00
|
|
|
case 'p':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-pthread", opts.args.str[i]) == 0)
|
2021-07-02 11:47:59 +02:00
|
|
|
{
|
|
|
|
raw_compiler_arg = 1;
|
|
|
|
raw_linker_arg = 1;
|
|
|
|
}
|
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 's':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-static", opts.args.str[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
linking = -1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if(strcmp("-save-temps", opts.args.str[i]) == 0)
|
2004-02-24 02:00:53 +01:00
|
|
|
keep_generated = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strncmp("-specs=", opts.args.str[i], 7) == 0)
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_linker_arg = 1;
|
2021-09-23 11:52:15 +02:00
|
|
|
else if(strcmp("-shared", opts.args.str[i]) == 0)
|
2004-03-23 01:14:54 +01:00
|
|
|
{
|
|
|
|
opts.shared = 1;
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2021-11-16 21:02:12 +01:00
|
|
|
else if (strcmp("-s", opts.args.str[i]) == 0 && opts.target.platform == PLATFORM_APPLE)
|
2011-10-06 01:07:38 +02:00
|
|
|
{
|
|
|
|
/* On Mac, change -s into -Wl,-x. ld's -s switch
|
|
|
|
* is deprecated, and it doesn't work on Tiger with
|
|
|
|
* MH_BUNDLEs anyway
|
|
|
|
*/
|
|
|
|
opts.strip = 1;
|
|
|
|
raw_linker_arg = 0;
|
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
2020-02-21 13:52:20 +01:00
|
|
|
case 't':
|
2020-05-25 20:33:35 +02:00
|
|
|
if (is_option( &opts, i, "-target", &option_arg ))
|
2020-02-21 13:52:20 +01:00
|
|
|
{
|
|
|
|
parse_target_option( &opts, option_arg );
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
case 'v':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (opts.args.str[i][2] == 0) verbose++;
|
2003-01-03 00:07:52 +01:00
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'W':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strncmp("-Wl,", opts.args.str[i], 4) == 0)
|
2002-12-15 02:17:10 +01:00
|
|
|
{
|
2005-08-09 13:12:29 +02:00
|
|
|
unsigned int j;
|
2021-09-23 11:52:15 +02:00
|
|
|
struct strarray Wl = strarray_fromstring(opts.args.str[i] + 4, ",");
|
|
|
|
for (j = 0; j < Wl.count; j++)
|
2005-08-09 13:12:29 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--image-base") && j < Wl.count - 1)
|
2005-08-09 13:12:29 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.image_base = strdup( Wl.str[++j] );
|
2005-08-09 13:12:29 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--section-alignment") && j < Wl.count - 1)
|
2008-07-22 13:27:07 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.section_align = strdup( Wl.str[++j] );
|
2008-07-22 13:27:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--file-alignment") && j < Wl.count - 1)
|
2020-07-23 20:33:16 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.file_align = strdup( Wl.str[++j] );
|
2020-07-23 20:33:16 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--large-address-aware"))
|
2009-06-17 16:10:56 +02:00
|
|
|
{
|
|
|
|
opts.large_address_aware = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--wine-builtin"))
|
2019-04-22 11:34:14 +02:00
|
|
|
{
|
|
|
|
opts.wine_builtin = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--subsystem") && j < Wl.count - 1)
|
2018-05-01 12:57:54 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.subsystem = strdup( Wl.str[++j] );
|
2018-05-01 12:57:54 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--entry") && j < Wl.count - 1)
|
2020-01-21 19:52:05 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.entry_point = strdup( Wl.str[++j] );
|
2020-01-21 19:52:05 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "-delayload") && j < Wl.count - 1)
|
2019-11-11 19:56:49 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.delayimports, Wl.str[++j] );
|
2019-11-11 19:56:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--debug-file") && j < Wl.count - 1)
|
2020-05-14 16:39:48 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.debug_file = strdup( Wl.str[++j] );
|
2020-05-14 16:39:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--whole-archive") ||
|
|
|
|
!strcmp(Wl.str[j], "--no-whole-archive") ||
|
|
|
|
!strcmp(Wl.str[j], "--start-group") ||
|
|
|
|
!strcmp(Wl.str[j], "--end-group"))
|
2020-05-25 20:34:31 +02:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.files, strmake( "-Wl,%s", Wl.str[j] ));
|
2020-05-25 20:34:31 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "--out-implib"))
|
2020-11-25 20:41:43 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
opts.out_implib = strdup( Wl.str[++j] );
|
2020-11-25 20:41:43 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
if (!strcmp(Wl.str[j], "-static")) linking = -1;
|
|
|
|
strarray_add(&opts.linker_args, strmake("-Wl,%s",Wl.str[j]));
|
2005-08-09 13:12:29 +02:00
|
|
|
}
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
2002-12-15 02:17:10 +01:00
|
|
|
}
|
2021-09-23 11:52:15 +02:00
|
|
|
else if (strncmp("-Wb,", opts.args.str[i], 4) == 0)
|
2004-03-02 07:53:16 +01:00
|
|
|
{
|
2021-11-18 19:47:40 +01:00
|
|
|
unsigned int j;
|
|
|
|
struct strarray Wb = strarray_fromstring(opts.args.str[i] + 4, ",");
|
|
|
|
for (j = 0; j < Wb.count; j++)
|
|
|
|
{
|
|
|
|
if (!strcmp(Wb.str[j], "--fake-module")) opts.fake_module = 1;
|
|
|
|
else strarray_add( &opts.winebuild_args, Wb.str[j] );
|
|
|
|
}
|
2004-03-11 23:42:39 +01:00
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
2004-03-02 07:53:16 +01:00
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
2004-04-17 01:30:32 +02:00
|
|
|
case 'x':
|
|
|
|
lang = strmake("-x%s", option_arg);
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add(&opts.files, lang);
|
2008-01-16 02:28:45 +01:00
|
|
|
/* we'll pass these flags ourselves, explicitly */
|
2004-04-17 01:30:32 +02:00
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case '-':
|
2021-09-23 11:52:15 +02:00
|
|
|
if (strcmp("-static", opts.args.str[i]+1) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
linking = -1;
|
2020-05-25 20:33:35 +02:00
|
|
|
else if (is_option( &opts, i, "--sysroot", &option_arg ))
|
2019-09-27 13:25:59 +02:00
|
|
|
{
|
2019-09-23 13:43:18 +02:00
|
|
|
opts.sysroot = option_arg;
|
2019-09-27 13:25:59 +02:00
|
|
|
raw_linker_arg = 1;
|
|
|
|
}
|
2020-05-25 20:33:35 +02:00
|
|
|
else if (is_option( &opts, i, "--target", &option_arg ))
|
2009-02-02 15:11:13 +01:00
|
|
|
{
|
2019-09-23 13:43:18 +02:00
|
|
|
parse_target_option( &opts, option_arg );
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2020-05-25 20:33:35 +02:00
|
|
|
else if (is_option( &opts, i, "--wine-objdir", &option_arg ))
|
2019-09-23 13:43:18 +02:00
|
|
|
{
|
|
|
|
opts.wine_objdir = option_arg;
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
2009-02-02 15:11:13 +01:00
|
|
|
}
|
2020-05-25 20:33:35 +02:00
|
|
|
else if (is_option( &opts, i, "--winebuild", &option_arg ))
|
2019-09-10 12:14:30 +02:00
|
|
|
{
|
2019-09-23 13:43:18 +02:00
|
|
|
opts.winebuild = option_arg;
|
2019-09-10 12:14:30 +02:00
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2020-05-25 20:33:35 +02:00
|
|
|
else if (is_option( &opts, i, "--lib-suffix", &option_arg ))
|
2010-01-23 20:25:14 +01:00
|
|
|
{
|
2019-09-23 13:43:18 +02:00
|
|
|
opts.lib_suffix = option_arg;
|
2010-01-23 20:25:14 +01:00
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-01-10 02:44:52 +01:00
|
|
|
|
2004-03-09 05:49:42 +01:00
|
|
|
/* put the arg into the appropriate bucket */
|
2021-09-23 11:52:15 +02:00
|
|
|
if (raw_linker_arg)
|
2004-03-09 05:49:42 +01:00
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.linker_args, opts.args.str[i] );
|
|
|
|
if (next_is_arg && (i + 1 < opts.args.count))
|
|
|
|
strarray_add( &opts.linker_args, opts.args.str[i + 1] );
|
2004-03-09 05:49:42 +01:00
|
|
|
}
|
|
|
|
if (raw_compiler_arg)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.compiler_args, opts.args.str[i] );
|
|
|
|
if (next_is_arg && (i + 1 < opts.args.count))
|
|
|
|
strarray_add( &opts.compiler_args, opts.args.str[i + 1] );
|
2004-03-09 05:49:42 +01:00
|
|
|
}
|
2021-01-22 13:59:48 +01:00
|
|
|
if (raw_winebuild_arg)
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.winebuild_args, opts.args.str[i] );
|
|
|
|
if (next_is_arg && (i + 1 < opts.args.count))
|
|
|
|
strarray_add( &opts.winebuild_args, opts.args.str[i + 1] );
|
2021-01-22 13:59:48 +01:00
|
|
|
}
|
2004-03-09 05:49:42 +01:00
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* skip the next token if it's an argument */
|
|
|
|
if (next_is_arg) i++;
|
|
|
|
}
|
2003-09-03 21:23:30 +02:00
|
|
|
else
|
|
|
|
{
|
2021-09-23 11:52:15 +02:00
|
|
|
strarray_add( &opts.files, opts.args.str[i] );
|
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
}
|
|
|
|
|
2021-11-16 21:02:12 +01:00
|
|
|
if (opts.force_pointer_size) set_target_ptr_size( &opts.target, opts.force_pointer_size );
|
2004-03-09 01:42:21 +01:00
|
|
|
if (opts.processor == proc_cpp) linking = 0;
|
2007-10-18 17:11:47 +02:00
|
|
|
if (linking == -1) error("Static linking is not supported\n");
|
2002-12-05 20:12:13 +01:00
|
|
|
|
2021-05-14 16:53:40 +02:00
|
|
|
if (!opts.wine_objdir && is_pe_target( &opts )) opts.use_msvcrt = 1;
|
|
|
|
|
2021-11-18 19:47:40 +01:00
|
|
|
if (opts.files.count == 0 && !opts.fake_module) forward(&opts);
|
2004-02-24 02:00:53 +01:00
|
|
|
else if (linking) build(&opts);
|
2004-04-17 01:30:32 +02:00
|
|
|
else compile(&opts, lang);
|
2002-12-15 02:17:10 +01:00
|
|
|
|
2020-02-21 13:52:31 +01:00
|
|
|
output_file_name = NULL;
|
2020-05-14 16:39:48 +02:00
|
|
|
output_debug_file = NULL;
|
2020-11-25 20:41:43 +01:00
|
|
|
output_implib = NULL;
|
2003-01-07 20:47:19 +01:00
|
|
|
return 0;
|
2002-12-05 20:12:13 +01:00
|
|
|
}
|