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
|
|
|
|
* -nostdlib -s -static -static-libgcc -shared -shared-libgcc
|
2005-08-09 13:12:29 +02:00
|
|
|
* -symbolic -Wl,option -Xlinker option -u symbol --image-base
|
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"
|
|
|
|
#include "wine/port.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>
|
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
|
|
|
;
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
static int keep_generated = 0;
|
2004-03-09 02:34:00 +01:00
|
|
|
static 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
|
|
|
|
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
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum target_cpu cpu;
|
|
|
|
} cpu_names[] =
|
|
|
|
{
|
|
|
|
{ "i386", CPU_x86 },
|
|
|
|
{ "i486", CPU_x86 },
|
|
|
|
{ "i586", CPU_x86 },
|
|
|
|
{ "i686", CPU_x86 },
|
|
|
|
{ "i786", CPU_x86 },
|
|
|
|
{ "x86_64", CPU_x86_64 },
|
|
|
|
{ "sparc", CPU_SPARC },
|
|
|
|
{ "alpha", CPU_ALPHA },
|
2009-09-23 20:15:26 +02:00
|
|
|
{ "powerpc", CPU_POWERPC },
|
|
|
|
{ "arm", CPU_ARM }
|
2009-02-02 12:25:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum target_platform platform;
|
|
|
|
} platform_names[] =
|
|
|
|
{
|
|
|
|
{ "macos", PLATFORM_APPLE },
|
|
|
|
{ "darwin", PLATFORM_APPLE },
|
|
|
|
{ "solaris", PLATFORM_SOLARIS },
|
|
|
|
{ "mingw32", PLATFORM_WINDOWS },
|
|
|
|
{ "windows", PLATFORM_WINDOWS },
|
|
|
|
{ "winnt", PLATFORM_WINDOWS }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct options
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2005-09-15 17:01:30 +02:00
|
|
|
enum processor processor;
|
2009-02-02 12:19:11 +01:00
|
|
|
enum target_cpu target_cpu;
|
|
|
|
enum target_platform target_platform;
|
2009-02-02 12:25:37 +01:00
|
|
|
const char *target;
|
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;
|
2004-02-21 05:01:38 +01:00
|
|
|
int gui_app;
|
2005-08-25 21:26:59 +02:00
|
|
|
int unicode_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;
|
2006-07-11 21:32:36 +02:00
|
|
|
const char* wine_objdir;
|
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;
|
2010-01-23 20:25:14 +01:00
|
|
|
const char* lib_suffix;
|
2004-03-09 05:49:42 +01:00
|
|
|
strarray* prefix;
|
2004-02-21 05:01:38 +01:00
|
|
|
strarray* lib_dirs;
|
2004-03-09 02:34:00 +01:00
|
|
|
strarray* linker_args;
|
|
|
|
strarray* compiler_args;
|
2004-03-02 07:53:16 +01:00
|
|
|
strarray* winebuild_args;
|
2004-02-21 05:01:38 +01:00
|
|
|
strarray* files;
|
|
|
|
};
|
|
|
|
|
2009-02-02 12:19:11 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
static const enum target_cpu build_cpu = CPU_x86;
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
static const enum target_cpu build_cpu = CPU_x86_64;
|
|
|
|
#elif defined(__sparc__)
|
|
|
|
static const enum target_cpu build_cpu = CPU_SPARC;
|
|
|
|
#elif defined(__ALPHA__)
|
|
|
|
static const enum target_cpu build_cpu = CPU_ALPHA;
|
|
|
|
#elif defined(__powerpc__)
|
|
|
|
static const enum target_cpu build_cpu = CPU_POWERPC;
|
2009-09-23 20:15:26 +02:00
|
|
|
#elif defined(__arm__)
|
|
|
|
static const enum target_cpu build_cpu = CPU_ARM;
|
2009-02-02 12:19:11 +01:00
|
|
|
#else
|
|
|
|
#error Unsupported CPU
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
static enum target_platform build_platform = PLATFORM_APPLE;
|
|
|
|
#elif defined(__sun)
|
|
|
|
static enum target_platform build_platform = PLATFORM_SOLARIS;
|
2009-08-22 07:57:54 +02:00
|
|
|
#elif defined(_WIN32)
|
2009-02-02 12:19:11 +01:00
|
|
|
static enum target_platform build_platform = PLATFORM_WINDOWS;
|
|
|
|
#else
|
|
|
|
static enum target_platform build_platform = PLATFORM_UNSPECIFIED;
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (i = 0; i < tmp_files->size; i++)
|
|
|
|
unlink(tmp_files->base[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;
|
2004-03-09 02:34:00 +01:00
|
|
|
char* tmp = strmake("%s-XXXXXX%s", prefix, suffix);
|
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
|
2004-12-02 19:22:48 +01:00
|
|
|
fd = mkstemps( tmp, strlen(suffix) );
|
2003-03-20 22:09:06 +01:00
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
/* could not create it in current directory, try in /tmp */
|
|
|
|
free(tmp);
|
2004-02-24 02:00:53 +01:00
|
|
|
tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix);
|
2003-03-20 22:09:06 +01:00
|
|
|
fd = mkstemps( tmp, strlen(suffix) );
|
2007-10-18 17:11:47 +02:00
|
|
|
if (fd == -1) error( "could not create temp file\n" );
|
2003-03-20 22:09:06 +01:00
|
|
|
}
|
|
|
|
close( fd );
|
2003-09-12 00:16:33 +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;
|
|
|
|
}
|
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
static const strarray* get_translator(struct options *opts)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2009-03-13 21:13:13 +01:00
|
|
|
const char *str = NULL;
|
2009-02-12 11:41:56 +01:00
|
|
|
strarray *ret;
|
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:
|
|
|
|
if (opts->target) str = strmake( "%s-cpp", opts->target );
|
|
|
|
else str = CPP;
|
|
|
|
break;
|
|
|
|
case proc_cc:
|
2009-05-30 13:03:20 +02:00
|
|
|
case proc_as:
|
2009-02-12 11:41:56 +01:00
|
|
|
if (opts->target) str = strmake( "%s-gcc", opts->target );
|
|
|
|
else str = CC;
|
|
|
|
break;
|
|
|
|
case proc_cxx:
|
|
|
|
if (opts->target) str = strmake( "%s-g++", opts->target );
|
|
|
|
else str = CXX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
2009-02-12 11:41:56 +01:00
|
|
|
ret = strarray_fromstring( str, " " );
|
|
|
|
if (opts->force_pointer_size)
|
2009-05-30 13:03:20 +02:00
|
|
|
strarray_add( ret, strmake("-m%u", 8 * opts->force_pointer_size ));
|
2009-02-12 11:41:56 +01:00
|
|
|
return ret;
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-03-09 02:34:00 +01:00
|
|
|
strarray* comp_args = strarray_alloc();
|
2007-02-10 12:57:25 +01:00
|
|
|
unsigned int j;
|
|
|
|
int gcc_defs = 0;
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
strarray_addall(comp_args, get_translator(opts));
|
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:
|
2009-10-09 19:14:52 +02:00
|
|
|
for ( j = 0; !gcc_defs && j < comp_args->size; j++ )
|
|
|
|
{
|
|
|
|
const char *cc = comp_args->base[j];
|
|
|
|
|
|
|
|
gcc_defs = strendswith(cc, "gcc") || strendswith(cc, "g++");
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (opts->target_platform == PLATFORM_WINDOWS) 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
|
|
|
{
|
2009-02-02 12:19:11 +01:00
|
|
|
strarray_add(comp_args, "-fshort-wchar");
|
2004-03-02 03:23:26 +01:00
|
|
|
strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
|
|
|
|
}
|
|
|
|
strarray_addall(comp_args, strarray_fromstring(DLLFLAGS, " "));
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
2005-03-11 11:25:59 +01:00
|
|
|
|
2009-02-02 12:19:11 +01:00
|
|
|
if (opts->target_cpu == CPU_x86_64)
|
|
|
|
{
|
|
|
|
strarray_add(comp_args, "-DWIN64");
|
|
|
|
strarray_add(comp_args, "-D_WIN64");
|
|
|
|
strarray_add(comp_args, "-D__WIN64");
|
|
|
|
strarray_add(comp_args, "-D__WIN64__");
|
|
|
|
}
|
|
|
|
|
2004-02-24 02:00:53 +01: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-03-02 03:23:26 +01:00
|
|
|
if (gcc_defs)
|
|
|
|
{
|
2009-02-02 12:19:11 +01:00
|
|
|
if (opts->target_cpu == CPU_x86_64)
|
|
|
|
{
|
|
|
|
strarray_add(comp_args, "-D__stdcall=__attribute__((ms_abi))");
|
|
|
|
strarray_add(comp_args, "-D__cdecl=__attribute__((ms_abi))");
|
|
|
|
strarray_add(comp_args, "-D_stdcall=__attribute__((ms_abi))");
|
|
|
|
strarray_add(comp_args, "-D_cdecl=__attribute__((ms_abi))");
|
|
|
|
strarray_add(comp_args, "-D__fastcall=__attribute__((ms_abi))");
|
|
|
|
strarray_add(comp_args, "-D_fastcall=__attribute__((ms_abi))");
|
|
|
|
}
|
|
|
|
else if (opts->target_platform == PLATFORM_APPLE)
|
|
|
|
{
|
|
|
|
/* Mac OS X uses a 16-byte aligned stack and not a 4-byte one */
|
|
|
|
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_stdcall=__attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))");
|
|
|
|
strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__)) __attribute__((__force_align_arg_pointer__))");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__))");
|
|
|
|
strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__))");
|
|
|
|
strarray_add(comp_args, "-D_stdcall=__attribute__((__stdcall__))");
|
|
|
|
strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
|
|
|
|
}
|
2006-10-07 23:57:25 +02:00
|
|
|
|
|
|
|
strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))");
|
2004-03-02 03:23:26 +01:00
|
|
|
strarray_add(comp_args, "-D_fastcall=__attribute__((__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-02-21 05:01:38 +01:00
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
strarray_add(comp_args, "-D__int8=char");
|
|
|
|
strarray_add(comp_args, "-D__int16=short");
|
|
|
|
strarray_add(comp_args, "-D__int32=int");
|
2009-02-02 12:19:11 +01:00
|
|
|
if (opts->target_cpu == CPU_x86_64)
|
|
|
|
strarray_add(comp_args, "-D__int64=long");
|
|
|
|
else
|
|
|
|
strarray_add(comp_args, "-D__int64=long long");
|
|
|
|
|
|
|
|
no_compat_defines:
|
|
|
|
strarray_add(comp_args, "-D__WINE__");
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* options we handle explicitly */
|
|
|
|
if (opts->compile_only)
|
2004-02-24 02:00:53 +01: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
|
|
|
{
|
|
|
|
strarray_add(comp_args, "-o");
|
|
|
|
strarray_add(comp_args, opts->output_name);
|
|
|
|
}
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
/* the rest of the pass-through parameters */
|
|
|
|
for ( j = 0 ; j < opts->compiler_args->size ; j++ )
|
2004-02-24 02:00:53 +01:00
|
|
|
strarray_add(comp_args, opts->compiler_args->base[j]);
|
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"))
|
|
|
|
strarray_add(comp_args, lang);
|
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* last, but not least, the files */
|
|
|
|
for ( j = 0; j < opts->files->size; j++ )
|
2004-04-17 01:30:32 +02:00
|
|
|
{
|
|
|
|
if (opts->files->base[j][0] != '-')
|
|
|
|
strarray_add(comp_args, opts->files->base[j]);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (opts->use_msvcrt)
|
|
|
|
{
|
2010-03-24 20:16:27 +01:00
|
|
|
strarray_add(comp_args, gcc_defs ? "-isystem" INCLUDEDIR "/msvcrt" : "-I" INCLUDEDIR "/msvcrt" );
|
2005-03-11 11:25:59 +01:00
|
|
|
strarray_add(comp_args, "-D__MSVCRT__");
|
|
|
|
}
|
2009-02-02 12:19:11 +01:00
|
|
|
strarray_add(comp_args, gcc_defs ? "-isystem" INCLUDEDIR "/windows" : "-I" INCLUDEDIR "/windows" );
|
2005-03-11 11:25:59 +01:00
|
|
|
}
|
2009-02-02 12:19:11 +01:00
|
|
|
else if (opts->wine_objdir)
|
|
|
|
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);
|
2009-02-10 19:33:32 +01:00
|
|
|
strarray_free(comp_args);
|
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;
|
|
|
|
char* base_name;
|
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 */
|
|
|
|
base_name = get_basename(file);
|
|
|
|
copts = *opts;
|
|
|
|
copts.output_name = get_temp_file(base_name, ".o");
|
|
|
|
copts.compile_only = 1;
|
|
|
|
copts.files = strarray_alloc();
|
|
|
|
strarray_add(copts.files, file);
|
2004-04-17 01:30:32 +02:00
|
|
|
compile(&copts, lang);
|
2004-02-24 02:00:53 +01:00
|
|
|
strarray_free(copts.files);
|
|
|
|
free(base_name);
|
|
|
|
|
|
|
|
return copts.output_name;
|
|
|
|
}
|
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
/* return the initial set of options needed to run winebuild */
|
|
|
|
static strarray *get_winebuild_args(struct options *opts)
|
|
|
|
{
|
|
|
|
const char* winebuild = getenv("WINEBUILD");
|
|
|
|
strarray *spec_args = strarray_alloc();
|
|
|
|
|
|
|
|
if (!winebuild) winebuild = "winebuild";
|
|
|
|
strarray_add( spec_args, winebuild );
|
|
|
|
if (verbose) strarray_add( spec_args, "-v" );
|
|
|
|
if (keep_generated) strarray_add( spec_args, "--save-temps" );
|
|
|
|
if (opts->target)
|
|
|
|
{
|
|
|
|
strarray_add( spec_args, "--target" );
|
|
|
|
strarray_add( spec_args, opts->target );
|
|
|
|
}
|
|
|
|
return spec_args;
|
|
|
|
}
|
|
|
|
|
2009-05-30 18:33:11 +02:00
|
|
|
static const char* compile_resources_to_object(struct options* opts, const strarray *resources,
|
|
|
|
const char *res_o_name)
|
|
|
|
{
|
|
|
|
strarray *winebuild_args = get_winebuild_args( opts );
|
|
|
|
|
|
|
|
strarray_add( winebuild_args, "--resources" );
|
|
|
|
strarray_add( winebuild_args, "-o" );
|
|
|
|
strarray_add( winebuild_args, res_o_name );
|
|
|
|
strarray_addall( winebuild_args, resources );
|
|
|
|
|
|
|
|
spawn( opts->prefix, winebuild_args, 0 );
|
|
|
|
strarray_free( winebuild_args );
|
|
|
|
return res_o_name;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-03-16 16:28:04 +01:00
|
|
|
/* add specified library to the list of files */
|
2009-05-30 15:24:07 +02:00
|
|
|
static void add_library( struct options *opts, strarray *lib_dirs, strarray *files, const char *library )
|
2006-03-16 16:28:04 +01:00
|
|
|
{
|
|
|
|
char *static_lib, *fullname = 0;
|
|
|
|
|
2010-01-23 20:25:14 +01:00
|
|
|
switch(get_lib_type(opts->target_platform, lib_dirs, library, 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);
|
|
|
|
}
|
|
|
|
|
2009-06-05 14:42:32 +02:00
|
|
|
/* hack a main or WinMain function to work around Mingw's lack of Unicode support */
|
|
|
|
static const char *mingw_unicode_hack( struct options *opts )
|
|
|
|
{
|
|
|
|
char *main_stub = get_temp_file( opts->output_name, ".c" );
|
|
|
|
|
|
|
|
create_file( main_stub, 0644,
|
|
|
|
"#include <stdlib.h>\n"
|
|
|
|
"extern int wmain(int,wchar_t**);\n"
|
|
|
|
"int main( int argc, char *argv[] )\n{\n"
|
|
|
|
" return wmain( argc, __wargv );\n}\n" );
|
|
|
|
return compile_to_object( opts, main_stub, NULL );
|
|
|
|
}
|
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
static void build(struct options* opts)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2004-03-09 05:49:42 +01:00
|
|
|
static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
|
2004-03-04 07:06:06 +01:00
|
|
|
strarray *lib_dirs, *files;
|
2004-04-17 01:30:32 +02:00
|
|
|
strarray *spec_args, *link_args;
|
2004-03-23 01:14:54 +01:00
|
|
|
char *output_file;
|
2005-09-21 13:00:21 +02:00
|
|
|
const char *spec_o_name;
|
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;
|
2009-08-18 11:26:43 +02:00
|
|
|
int fake_module = 0;
|
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 */
|
2004-03-02 07:53:16 +01:00
|
|
|
if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
|
2004-03-03 21:11:20 +01:00
|
|
|
{
|
2004-03-23 01:14:54 +01:00
|
|
|
create_file(output_file, 0755, app_loader_template, opts->files->base[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 */
|
2009-02-23 17:18:19 +01:00
|
|
|
if (opts->shared || strendswith(output_file, ".so"))
|
2004-03-23 01:14:54 +01:00
|
|
|
generate_app_loader = 0;
|
|
|
|
|
2009-08-18 11:26:43 +02:00
|
|
|
if (strendswith(output_file, ".fake")) fake_module = 1;
|
|
|
|
|
2004-03-23 01:14:54 +01:00
|
|
|
/* normalize the filename a bit: strip .so, ensure it has proper ext */
|
|
|
|
if (strendswith(output_file, ".so"))
|
|
|
|
output_file[strlen(output_file) - 3] = 0;
|
2009-02-23 17:18:19 +01:00
|
|
|
if ((output_name = strrchr(output_file, '/'))) output_name++;
|
|
|
|
else output_name = output_file;
|
|
|
|
if (!strchr(output_name, '.'))
|
|
|
|
output_file = strmake("%s.%s", output_file, opts->shared ? "dll" : "exe");
|
2004-03-23 01:14:54 +01:00
|
|
|
|
2004-04-09 21:02:18 +02:00
|
|
|
/* get the filename from the path */
|
2004-03-23 01:14:54 +01:00
|
|
|
if ((output_name = strrchr(output_file, '/'))) output_name++;
|
|
|
|
else output_name = output_file;
|
|
|
|
|
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
|
|
|
{
|
2006-07-17 14:07:11 +02:00
|
|
|
lib_dirs = strarray_dup(opts->lib_dirs);
|
2004-03-23 01:14:54 +01:00
|
|
|
for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]); j++ )
|
2004-03-09 05:20:58 +01:00
|
|
|
strarray_add(lib_dirs, stdlibpath[j]);
|
|
|
|
}
|
2006-07-11 21:32:36 +02:00
|
|
|
else
|
|
|
|
{
|
2006-07-17 14:07:11 +02:00
|
|
|
lib_dirs = strarray_alloc();
|
2006-07-11 21:32:36 +02:00
|
|
|
strarray_add(lib_dirs, strmake("%s/dlls", opts->wine_objdir));
|
|
|
|
strarray_add(lib_dirs, strmake("%s/libs/wine", opts->wine_objdir));
|
2006-07-17 14:07:11 +02:00
|
|
|
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;
|
2004-03-04 07:06:06 +01:00
|
|
|
files = strarray_alloc();
|
2009-05-30 15:24:07 +02:00
|
|
|
link_args = strarray_alloc();
|
2004-03-04 07:06:06 +01:00
|
|
|
for ( j = 0; j < opts->files->size; j++ )
|
2004-02-24 02:00:53 +01:00
|
|
|
{
|
2004-03-04 07:06:06 +01:00
|
|
|
const char* file = opts->files->base[j];
|
|
|
|
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:
|
|
|
|
strarray_add(files, strmake("-r%s", file));
|
|
|
|
break;
|
|
|
|
case file_obj:
|
|
|
|
strarray_add(files, strmake("-o%s", file));
|
|
|
|
break;
|
2004-03-31 02:56:14 +02:00
|
|
|
case file_arh:
|
|
|
|
strarray_add(files, strmake("-a%s", file));
|
|
|
|
break;
|
|
|
|
case file_so:
|
|
|
|
strarray_add(files, strmake("-s%s", file));
|
|
|
|
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);
|
2004-03-04 07:06:06 +01:00
|
|
|
strarray_add(files, strmake("-o%s", file));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (file[1] == 'l')
|
2009-05-30 15:24:07 +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;
|
2004-02-24 02:00:53 +01:00
|
|
|
}
|
2004-03-23 01:14:54 +01:00
|
|
|
if (opts->shared && !spec_file)
|
2007-10-18 17:11:47 +02:00
|
|
|
error("A spec file is currently needed in shared mode\n");
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
/* building for Windows is completely different */
|
|
|
|
|
|
|
|
if (opts->target_platform == PLATFORM_WINDOWS)
|
|
|
|
{
|
2009-05-30 18:33:11 +02:00
|
|
|
strarray *resources = strarray_alloc();
|
|
|
|
char *res_o_name = NULL;
|
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
if (opts->shared)
|
|
|
|
{
|
|
|
|
/* run winebuild to generate the .def file */
|
|
|
|
char *spec_def_name = get_temp_file(output_name, ".spec.def");
|
|
|
|
spec_args = get_winebuild_args( opts );
|
|
|
|
strarray_add(spec_args, "--def");
|
|
|
|
strarray_add(spec_args, "-o");
|
|
|
|
strarray_add(spec_args, spec_def_name);
|
|
|
|
if (spec_file)
|
|
|
|
{
|
|
|
|
strarray_add(spec_args, "--export");
|
|
|
|
strarray_add(spec_args, spec_file);
|
|
|
|
}
|
|
|
|
spawn(opts->prefix, spec_args, 0);
|
|
|
|
strarray_free(spec_args);
|
|
|
|
|
|
|
|
if (opts->target) strarray_add(link_args, strmake("%s-dllwrap", opts->target));
|
|
|
|
else strarray_add(link_args, "dllwrap");
|
|
|
|
if (verbose) strarray_add(link_args, "-v");
|
|
|
|
strarray_add(link_args, "-k");
|
|
|
|
strarray_add(link_args, "--def");
|
|
|
|
strarray_add(link_args, spec_def_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strarray_addall(link_args, get_translator(opts));
|
|
|
|
strarray_add(link_args, opts->gui_app ? "-mwindows" : "-mconsole");
|
|
|
|
if (opts->nodefaultlibs) strarray_add(link_args, "-nodefaultlibs");
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( j = 0 ; j < opts->linker_args->size ; j++ )
|
|
|
|
strarray_add(link_args, opts->linker_args->base[j]);
|
|
|
|
|
|
|
|
strarray_add(link_args, "-o");
|
|
|
|
strarray_add(link_args, output_file);
|
|
|
|
|
|
|
|
if (opts->image_base)
|
|
|
|
strarray_add(link_args, strmake("-Wl,--image-base,%s", opts->image_base));
|
|
|
|
|
2009-06-17 16:10:56 +02:00
|
|
|
if (opts->large_address_aware) strarray_add( link_args, "-Wl,--large-address-aware" );
|
|
|
|
|
2009-06-05 14:42:32 +02:00
|
|
|
if (opts->unicode_app && !opts->shared)
|
|
|
|
strarray_add(link_args, mingw_unicode_hack(opts));
|
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
for ( j = 0; j < lib_dirs->size; j++ )
|
|
|
|
strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));
|
|
|
|
|
2009-06-05 14:42:18 +02:00
|
|
|
if (!opts->nostartfiles) add_library(opts, lib_dirs, files, "winecrt0");
|
2009-05-30 15:24:07 +02:00
|
|
|
if (opts->shared && !opts->nostdlib) add_library(opts, lib_dirs, files, "wine");
|
|
|
|
|
|
|
|
for ( j = 0; j < files->size; j++ )
|
|
|
|
{
|
|
|
|
const char* name = files->base[j] + 2;
|
|
|
|
|
|
|
|
switch(files->base[j][1])
|
|
|
|
{
|
|
|
|
case 'l':
|
|
|
|
case 's':
|
|
|
|
case 'd':
|
|
|
|
strarray_add(link_args, strmake("-l%s", name));
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
strarray_add(link_args, name);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
if (strchr(name, '/'))
|
|
|
|
{
|
|
|
|
/* 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 */
|
|
|
|
char *lib = xstrdup( name );
|
|
|
|
char *p = strrchr( lib, '/' );
|
|
|
|
|
|
|
|
*p++ = 0;
|
|
|
|
if (!strncmp( p, "lib", 3 ))
|
|
|
|
{
|
|
|
|
char *ext = strrchr( p, '.' );
|
|
|
|
|
|
|
|
if (ext) *ext = 0;
|
|
|
|
p += 3;
|
|
|
|
strarray_add(link_args, strmake("-L%s", lib ));
|
|
|
|
strarray_add(link_args, strmake("-l%s", p ));
|
|
|
|
free( lib );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free( lib );
|
|
|
|
}
|
|
|
|
strarray_add(link_args, name);
|
|
|
|
break;
|
2009-05-30 18:33:11 +02:00
|
|
|
case 'r':
|
|
|
|
if (!res_o_name)
|
|
|
|
{
|
|
|
|
res_o_name = get_temp_file( output_name, ".res.o" );
|
|
|
|
strarray_add( link_args, res_o_name );
|
|
|
|
}
|
|
|
|
strarray_add( resources, name );
|
|
|
|
break;
|
2009-05-30 15:24:07 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-19 13:59:54 +01:00
|
|
|
if (!opts->shared && (opts->use_msvcrt || opts->unicode_app)) strarray_add(link_args, "-lmsvcrt");
|
2009-05-30 15:24:07 +02:00
|
|
|
|
2009-05-30 18:33:11 +02:00
|
|
|
if (res_o_name) compile_resources_to_object( opts, resources, res_o_name );
|
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
spawn(opts->prefix, link_args, 0);
|
2009-05-30 18:33:11 +02:00
|
|
|
strarray_free (resources);
|
2009-05-30 15:24:07 +02:00
|
|
|
strarray_free (link_args);
|
2009-06-05 13:31:36 +02:00
|
|
|
strarray_free (lib_dirs);
|
|
|
|
strarray_free (files);
|
2009-05-30 15:24:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
/* add the default libraries, if needed */
|
2009-05-30 15:24:07 +02:00
|
|
|
if (!opts->nostdlib && opts->use_msvcrt) add_library(opts, lib_dirs, files, "msvcrt");
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2006-07-11 21:32:36 +02:00
|
|
|
if (!opts->wine_objdir && !opts->nodefaultlibs)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2004-02-24 02:00:53 +01:00
|
|
|
if (opts->gui_app)
|
|
|
|
{
|
2009-05-30 15:24:07 +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
|
|
|
}
|
2009-05-30 15:24:07 +02:00
|
|
|
add_library(opts, lib_dirs, files, "advapi32");
|
|
|
|
add_library(opts, lib_dirs, files, "user32");
|
|
|
|
add_library(opts, lib_dirs, files, "kernel32");
|
2004-02-24 02:00:53 +01:00
|
|
|
}
|
|
|
|
|
2009-05-30 15:24:07 +02:00
|
|
|
if (!opts->nostartfiles) add_library(opts, lib_dirs, files, "winecrt0");
|
|
|
|
if (!opts->nostdlib) add_library(opts, lib_dirs, files, "wine");
|
2005-08-25 13:41:05 +02:00
|
|
|
|
2005-09-21 13:00:21 +02:00
|
|
|
/* run winebuild to generate the .spec.o file */
|
2009-05-30 15:24:07 +02:00
|
|
|
spec_args = get_winebuild_args( opts );
|
2005-09-21 13:00:21 +02:00
|
|
|
spec_o_name = get_temp_file(output_name, ".spec.o");
|
2009-02-04 20:10:49 +01:00
|
|
|
if (opts->force_pointer_size)
|
|
|
|
strarray_add(spec_args, strmake("-m%u", 8 * opts->force_pointer_size ));
|
2004-11-22 20:48:10 +01:00
|
|
|
strarray_addall(spec_args, strarray_fromstring(DLLFLAGS, " "));
|
2005-03-08 17:55:26 +01:00
|
|
|
strarray_add(spec_args, opts->shared ? "--dll" : "--exe");
|
2009-08-18 11:26:43 +02:00
|
|
|
if (fake_module)
|
|
|
|
{
|
|
|
|
strarray_add(spec_args, "--fake-module");
|
|
|
|
strarray_add(spec_args, "-o");
|
|
|
|
strarray_add(spec_args, output_file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strarray_add(spec_args, "-o");
|
|
|
|
strarray_add(spec_args, spec_o_name);
|
|
|
|
}
|
2005-03-08 17:55:26 +01:00
|
|
|
if (spec_file)
|
2004-03-23 01:14:54 +01:00
|
|
|
{
|
2005-03-08 17:55:26 +01:00
|
|
|
strarray_add(spec_args, "-E");
|
2004-03-23 01:14:54 +01:00
|
|
|
strarray_add(spec_args, spec_file);
|
|
|
|
}
|
2005-03-08 17:55:26 +01:00
|
|
|
|
|
|
|
if (!opts->shared)
|
2004-03-23 01:14:54 +01:00
|
|
|
{
|
2005-03-08 17:55:26 +01:00
|
|
|
strarray_add(spec_args, "-F");
|
2005-05-05 18:44:38 +02:00
|
|
|
strarray_add(spec_args, output_name);
|
2004-03-25 01:40:52 +01:00
|
|
|
strarray_add(spec_args, "--subsystem");
|
|
|
|
strarray_add(spec_args, opts->gui_app ? "windows" : "console");
|
2005-08-25 21:26:59 +02:00
|
|
|
if (opts->unicode_app)
|
|
|
|
{
|
|
|
|
strarray_add(spec_args, "--entry");
|
2005-08-29 16:16:27 +02:00
|
|
|
strarray_add(spec_args, "__wine_spec_exe_wentry");
|
2005-08-25 21:26:59 +02:00
|
|
|
}
|
2009-06-17 16:10:56 +02:00
|
|
|
if (opts->large_address_aware) strarray_add( spec_args, "--large-address-aware" );
|
2004-03-23 01:14:54 +01:00
|
|
|
}
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
for ( j = 0; j < lib_dirs->size; j++ )
|
|
|
|
strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2004-03-02 07:53:16 +01:00
|
|
|
for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
|
|
|
|
strarray_add(spec_args, opts->winebuild_args->base[j]);
|
|
|
|
|
2009-06-29 13:13:25 +02:00
|
|
|
/* add resource files */
|
|
|
|
for ( j = 0; j < files->size; j++ )
|
|
|
|
if (files->base[j][1] == 'r') strarray_add(spec_args, files->base[j]);
|
|
|
|
|
|
|
|
/* add other files */
|
|
|
|
strarray_add(spec_args, "--");
|
2004-03-04 07:06:06 +01:00
|
|
|
for ( j = 0; j < files->size; j++ )
|
|
|
|
{
|
|
|
|
switch(files->base[j][1])
|
|
|
|
{
|
2006-03-16 16:28:04 +01:00
|
|
|
case 'd':
|
2004-03-04 07:06:06 +01:00
|
|
|
case 'a':
|
|
|
|
case 'o':
|
2009-06-29 13:13:25 +02:00
|
|
|
strarray_add(spec_args, files->base[j] + 2);
|
2004-03-04 07:06:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-02 06:00:17 +01:00
|
|
|
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, spec_args, 0);
|
2009-02-10 19:33:32 +01:00
|
|
|
strarray_free (spec_args);
|
2009-08-18 11:26:43 +02:00
|
|
|
if (fake_module) return; /* nothing else to do */
|
2004-02-24 02:00:53 +01:00
|
|
|
|
|
|
|
/* link everything together now */
|
2009-02-02 12:25:37 +01:00
|
|
|
strarray_addall(link_args, get_translator(opts));
|
2004-03-02 03:23:26 +01:00
|
|
|
strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2004-02-26 06:28:35 +01:00
|
|
|
strarray_add(link_args, "-o");
|
2004-03-23 01:14:54 +01:00
|
|
|
strarray_add(link_args, strmake("%s.so", output_file));
|
2004-02-24 02:00:53 +01:00
|
|
|
|
|
|
|
for ( j = 0 ; j < opts->linker_args->size ; j++ )
|
|
|
|
strarray_add(link_args, opts->linker_args->base[j]);
|
|
|
|
|
2009-02-02 12:19:11 +01:00
|
|
|
switch (opts->target_platform)
|
2008-07-22 13:27:07 +02:00
|
|
|
{
|
2009-02-02 12:19:11 +01:00
|
|
|
case PLATFORM_APPLE:
|
|
|
|
if (opts->image_base)
|
|
|
|
{
|
|
|
|
strarray_add(link_args, "-image_base");
|
|
|
|
strarray_add(link_args, opts->image_base);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PLATFORM_SOLARIS:
|
|
|
|
{
|
|
|
|
char *mapfile = get_temp_file( output_name, ".map" );
|
|
|
|
const char *align = opts->section_align ? opts->section_align : "0x1000";
|
2008-07-22 13:27:07 +02:00
|
|
|
|
2009-02-02 12:19:11 +01:00
|
|
|
create_file( mapfile, 0644, "text = A%s;\ndata = A%s;\n", align, align );
|
|
|
|
strarray_add(link_args, strmake("-Wl,-M,%s", mapfile));
|
|
|
|
strarray_add(tmp_files, mapfile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2008-07-22 13:27:07 +02:00
|
|
|
}
|
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
for ( j = 0; j < lib_dirs->size; j++ )
|
|
|
|
strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2004-03-03 23:38:25 +01:00
|
|
|
strarray_add(link_args, spec_o_name);
|
2004-02-24 02:00:53 +01:00
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
for ( j = 0; j < files->size; j++ )
|
|
|
|
{
|
|
|
|
const char* name = files->base[j] + 2;
|
|
|
|
switch(files->base[j][1])
|
|
|
|
{
|
2004-03-09 05:49:42 +01:00
|
|
|
case 'l':
|
2006-04-04 13:45:16 +02:00
|
|
|
case 's':
|
2004-03-04 07:06:06 +01:00
|
|
|
strarray_add(link_args, strmake("-l%s", name));
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
case 'o':
|
|
|
|
strarray_add(link_args, name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-03 23:38:25 +01:00
|
|
|
|
2004-03-04 07:06:06 +01:00
|
|
|
if (!opts->nostdlib)
|
|
|
|
{
|
|
|
|
strarray_add(link_args, "-lm");
|
|
|
|
strarray_add(link_args, "-lc");
|
|
|
|
}
|
2004-03-03 23:38:25 +01:00
|
|
|
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, link_args, 0);
|
2009-02-10 19:33:32 +01:00
|
|
|
strarray_free (link_args);
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2005-08-09 13:12:29 +02:00
|
|
|
/* set the base address */
|
|
|
|
if (opts->image_base)
|
|
|
|
{
|
|
|
|
const char *prelink = PRELINK;
|
|
|
|
if (prelink[0] && strcmp(prelink,"false"))
|
|
|
|
{
|
|
|
|
strarray *prelink_args = strarray_alloc();
|
|
|
|
strarray_add(prelink_args, prelink);
|
|
|
|
strarray_add(prelink_args, "--reloc-only");
|
|
|
|
strarray_add(prelink_args, opts->image_base);
|
|
|
|
strarray_add(prelink_args, strmake("%s.so", output_file));
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, prelink_args, 1);
|
2005-08-09 13:12:29 +02:00
|
|
|
strarray_free(prelink_args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
static void forward(int argc, char **argv, struct options* opts)
|
2004-02-21 05:01:38 +01:00
|
|
|
{
|
2004-03-09 02:34:00 +01:00
|
|
|
strarray* args = strarray_alloc();
|
2004-02-21 05:01:38 +01:00
|
|
|
int j;
|
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
strarray_addall(args, get_translator(opts));
|
2004-02-21 05:01:38 +01:00
|
|
|
|
|
|
|
for( j = 1; j < argc; j++ )
|
2004-02-24 02:00:53 +01:00
|
|
|
strarray_add(args, argv[j]);
|
2004-02-21 05:01:38 +01:00
|
|
|
|
2005-08-09 22:47:18 +02:00
|
|
|
spawn(opts->prefix, args, 0);
|
2009-02-10 19:33:32 +01:00
|
|
|
strarray_free (args);
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Linker Options
|
|
|
|
* object-file-name -llibrary -nostartfiles -nodefaultlibs
|
|
|
|
* -nostdlib -s -static -static-libgcc -shared -shared-libgcc
|
|
|
|
* -symbolic -Wl,option -Xlinker option -u symbol
|
2004-08-19 03:20:45 +02:00
|
|
|
* -framework name
|
2004-02-21 05:01:38 +01:00
|
|
|
*/
|
|
|
|
static int is_linker_arg(const char* arg)
|
|
|
|
{
|
|
|
|
static const char* link_switches[] =
|
|
|
|
{
|
|
|
|
"-nostartfiles", "-nodefaultlibs", "-nostdlib", "-s",
|
2004-08-19 03:20:45 +02:00
|
|
|
"-static", "-static-libgcc", "-shared", "-shared-libgcc", "-symbolic",
|
|
|
|
"-framework"
|
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':
|
|
|
|
case 'l':
|
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;
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
|
|
|
|
if (strcmp(link_switches[j], arg) == 0) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Target Options
|
|
|
|
* -b machine -V version
|
|
|
|
*/
|
|
|
|
static int is_target_arg(const char* arg)
|
|
|
|
{
|
|
|
|
return arg[1] == 'b' || arg[2] == 'V';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Directory Options
|
|
|
|
* -Bprefix -Idir -I- -Ldir -specs=file
|
|
|
|
*/
|
|
|
|
static int is_directory_arg(const char* arg)
|
|
|
|
{
|
|
|
|
return arg[1] == 'B' || arg[1] == 'L' || arg[1] == 'I' || strncmp("-specs=", arg, 7) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MinGW Options
|
2005-08-25 21:26:59 +02:00
|
|
|
* -mno-cygwin -mwindows -mconsole -mthreads -municode
|
2004-02-21 05:01:38 +01:00
|
|
|
*/
|
|
|
|
static int is_mingw_arg(const char* arg)
|
|
|
|
{
|
|
|
|
static const char* mingw_switches[] =
|
|
|
|
{
|
2005-08-25 21:26:59 +02:00
|
|
|
"-mno-cygwin", "-mwindows", "-mconsole", "-mthreads", "-municode"
|
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
|
|
|
|
|
|
|
for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
|
|
|
|
if (strcmp(mingw_switches[j], arg) == 0) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-07 20:47:19 +01:00
|
|
|
|
2009-02-02 12:25:37 +01:00
|
|
|
static void parse_target_option( struct options *opts, const char *target )
|
|
|
|
{
|
|
|
|
char *p, *platform, *spec = xstrdup( target );
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
|
|
|
|
|
|
|
|
/* get the CPU part */
|
|
|
|
|
|
|
|
if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
|
|
|
|
*p++ = 0;
|
|
|
|
for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( cpu_names[i].name, spec ))
|
|
|
|
{
|
|
|
|
opts->target_cpu = cpu_names[i].cpu;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == sizeof(cpu_names)/sizeof(cpu_names[0]))
|
|
|
|
error( "Unrecognized CPU '%s'\n", spec );
|
|
|
|
platform = p;
|
|
|
|
if ((p = strrchr( p, '-' ))) platform = p + 1;
|
|
|
|
|
|
|
|
/* get the OS part */
|
|
|
|
|
|
|
|
opts->target_platform = PLATFORM_UNSPECIFIED; /* default value */
|
|
|
|
for (i = 0; i < sizeof(platform_names)/sizeof(platform_names[0]); i++)
|
|
|
|
{
|
|
|
|
if (!strncmp( platform_names[i].name, platform, strlen(platform_names[i].name) ))
|
|
|
|
{
|
|
|
|
opts->target_platform = platform_names[i].platform;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free( spec );
|
|
|
|
opts->target = xstrdup( target );
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
int raw_compiler_arg, raw_linker_arg;
|
|
|
|
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
|
2004-12-02 19:22:48 +01:00
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* setup tmp file removal at exit */
|
2003-09-12 00:16:33 +02:00
|
|
|
tmp_files = strarray_alloc();
|
2003-01-07 20:47:19 +01:00
|
|
|
atexit(clean_temp_files);
|
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* initialize options */
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
2009-02-02 12:19:11 +01:00
|
|
|
opts.target_cpu = build_cpu;
|
|
|
|
opts.target_platform = build_platform;
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.lib_dirs = strarray_alloc();
|
|
|
|
opts.files = strarray_alloc();
|
|
|
|
opts.linker_args = strarray_alloc();
|
|
|
|
opts.compiler_args = strarray_alloc();
|
2004-03-02 07:53:16 +01:00
|
|
|
opts.winebuild_args = strarray_alloc();
|
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
|
|
|
|
2004-02-21 05:01:38 +01:00
|
|
|
/* parse options */
|
2002-12-15 02:17:10 +01:00
|
|
|
for ( i = 1 ; i < argc ; i++ )
|
|
|
|
{
|
|
|
|
if (argv[i][0] == '-') /* option */
|
|
|
|
{
|
2004-02-21 05:01:38 +01:00
|
|
|
/* determine if tihs 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;
|
|
|
|
switch(argv[i][1])
|
|
|
|
{
|
|
|
|
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':
|
2004-02-26 06:28:35 +01:00
|
|
|
if (argv[i][2]) option_arg = &argv[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':
|
|
|
|
if (strcmp("-aux-info", argv[i]) == 0)
|
|
|
|
next_is_arg = 1;
|
2009-05-02 05:59:25 +02:00
|
|
|
if (strcmp("-arch", argv[i]) == 0)
|
|
|
|
next_is_arg = 1;
|
2004-02-21 05:01:38 +01:00
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
if (strcmp("-Xlinker", argv[i]) == 0)
|
|
|
|
next_is_arg = 1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
c = argv[i][2];
|
|
|
|
if (c == 'F' || c == 'T' || c == 'Q')
|
|
|
|
{
|
2004-02-26 06:28:35 +01:00
|
|
|
if (argv[i][3]) option_arg = &argv[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':
|
|
|
|
if (strcmp("-framework", argv[i]) == 0)
|
|
|
|
next_is_arg = 1;
|
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
}
|
|
|
|
if (next_is_arg) option_arg = argv[i+1];
|
|
|
|
|
|
|
|
/* determine what options go 'as is' to the linker & the compiler */
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
if (is_linker_arg(argv[i]))
|
|
|
|
{
|
|
|
|
raw_linker_arg = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_directory_arg(argv[i]) || is_target_arg(argv[i]))
|
|
|
|
raw_linker_arg = 1;
|
|
|
|
raw_compiler_arg = !is_mingw_arg(argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* these things we handle explicitly so we don't pass them 'as is' */
|
|
|
|
if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L')
|
|
|
|
raw_linker_arg = 0;
|
|
|
|
if (argv[i][1] == 'c' || argv[i][1] == 'L')
|
|
|
|
raw_compiler_arg = 0;
|
2009-02-02 12:25:37 +01:00
|
|
|
if (argv[i][1] == 'o' || argv[i][1] == 'b')
|
2004-02-21 05:01:38 +01:00
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
|
|
|
|
/* do a bit of semantic analysis */
|
2002-12-15 02:17:10 +01:00
|
|
|
switch (argv[i][1])
|
|
|
|
{
|
2004-03-09 02:34:00 +01:00
|
|
|
case 'B':
|
|
|
|
str = strdup(option_arg);
|
2004-03-09 05:49:42 +01:00
|
|
|
if (strendswith(str, "/tools/winebuild"))
|
|
|
|
{
|
2006-07-11 21:32:36 +02:00
|
|
|
char *objdir = strdup(str);
|
|
|
|
objdir[strlen(objdir) - sizeof("/tools/winebuild") + 1] = 0;
|
|
|
|
opts.wine_objdir = objdir;
|
2004-03-09 05:49:42 +01:00
|
|
|
/* don't pass it to the compiler, this generates warnings */
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2004-03-09 02:34:00 +01:00
|
|
|
if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
|
2004-03-09 05:49:42 +01:00
|
|
|
if (!opts.prefix) opts.prefix = strarray_alloc();
|
|
|
|
strarray_add(opts.prefix, str);
|
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 );
|
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'c': /* compile or assemble */
|
2004-02-21 05:01:38 +01:00
|
|
|
if (argv[i][2] == 0) opts.compile_only = 1;
|
|
|
|
/* fall through */
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'S': /* generate assembler code */
|
|
|
|
case 'E': /* preprocess only */
|
|
|
|
if (argv[i][2] == 0) linking = 0;
|
|
|
|
break;
|
2004-03-02 03:23:26 +01:00
|
|
|
case 'f':
|
|
|
|
if (strcmp("-fno-short-wchar", argv[i]) == 0)
|
|
|
|
opts.noshortwchar = 1;
|
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
case 'l':
|
2004-03-04 07:06:06 +01:00
|
|
|
strarray_add(opts.files, strmake("-l%s", option_arg));
|
2004-02-21 05:01:38 +01:00
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
strarray_add(opts.lib_dirs, option_arg);
|
|
|
|
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':
|
|
|
|
if (strcmp("-mno-cygwin", argv[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.use_msvcrt = 1;
|
2002-12-15 02:17:10 +01:00
|
|
|
else if (strcmp("-mwindows", argv[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.gui_app = 1;
|
2003-08-20 06:15:02 +02:00
|
|
|
else if (strcmp("-mconsole", argv[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.gui_app = 0;
|
2005-08-25 21:26:59 +02:00
|
|
|
else if (strcmp("-municode", argv[i]) == 0)
|
|
|
|
opts.unicode_app = 1;
|
2009-02-04 20:10:49 +01:00
|
|
|
else if (strcmp("-m32", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
else if (strcmp("-m64", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
opts.force_pointer_size = 8;
|
|
|
|
raw_linker_arg = 1;
|
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
if (strcmp("-nostdinc", argv[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.nostdinc = 1;
|
2002-12-15 02:17:10 +01:00
|
|
|
else if (strcmp("-nodefaultlibs", argv[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.nodefaultlibs = 1;
|
2002-12-15 02:17:10 +01:00
|
|
|
else if (strcmp("-nostdlib", argv[i]) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
opts.nostdlib = 1;
|
2005-08-25 13:41:05 +02:00
|
|
|
else if (strcmp("-nostartfiles", argv[i]) == 0)
|
|
|
|
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;
|
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 's':
|
2004-02-21 05:01:38 +01:00
|
|
|
if (strcmp("-static", argv[i]) == 0)
|
|
|
|
linking = -1;
|
2004-02-24 02:00:53 +01:00
|
|
|
else if(strcmp("-save-temps", argv[i]) == 0)
|
|
|
|
keep_generated = 1;
|
2004-03-23 01:14:54 +01:00
|
|
|
else if(strcmp("-shared", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
opts.shared = 1;
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
break;
|
2004-02-21 05:01:38 +01:00
|
|
|
case 'v':
|
2004-02-26 06:28:35 +01:00
|
|
|
if (argv[i][2] == 0) verbose++;
|
2003-01-03 00:07:52 +01:00
|
|
|
break;
|
2002-12-15 02:17:10 +01:00
|
|
|
case 'W':
|
|
|
|
if (strncmp("-Wl,", argv[i], 4) == 0)
|
|
|
|
{
|
2005-08-09 13:12:29 +02:00
|
|
|
unsigned int j;
|
|
|
|
strarray* Wl = strarray_fromstring(argv[i] + 4, ",");
|
|
|
|
for (j = 0; j < Wl->size; j++)
|
|
|
|
{
|
|
|
|
if (!strcmp(Wl->base[j], "--image-base") && j < Wl->size - 1)
|
|
|
|
{
|
|
|
|
opts.image_base = strdup( Wl->base[++j] );
|
|
|
|
continue;
|
|
|
|
}
|
2008-07-22 13:27:07 +02:00
|
|
|
if (!strcmp(Wl->base[j], "--section-alignment") && j < Wl->size - 1)
|
|
|
|
{
|
|
|
|
opts.section_align = strdup( Wl->base[++j] );
|
|
|
|
continue;
|
|
|
|
}
|
2009-06-17 16:10:56 +02:00
|
|
|
if (!strcmp(Wl->base[j], "--large-address-aware"))
|
|
|
|
{
|
|
|
|
opts.large_address_aware = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2005-08-09 13:12:29 +02:00
|
|
|
if (!strcmp(Wl->base[j], "-static")) linking = -1;
|
|
|
|
strarray_add(opts.linker_args, strmake("-Wl,%s",Wl->base[j]));
|
|
|
|
}
|
|
|
|
strarray_free(Wl);
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
2002-12-15 02:17:10 +01:00
|
|
|
}
|
2004-03-02 07:53:16 +01:00
|
|
|
else if (strncmp("-Wb,", argv[i], 4) == 0)
|
|
|
|
{
|
|
|
|
strarray* Wb = strarray_fromstring(argv[i] + 4, ",");
|
|
|
|
strarray_addall(opts.winebuild_args, Wb);
|
|
|
|
strarray_free(Wb);
|
2004-03-11 23:42:39 +01:00
|
|
|
/* don't pass it to the compiler, it generates errors */
|
|
|
|
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);
|
|
|
|
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 '-':
|
|
|
|
if (strcmp("-static", argv[i]+1) == 0)
|
2004-02-21 05:01:38 +01:00
|
|
|
linking = -1;
|
2009-02-02 15:11:13 +01:00
|
|
|
else if (!strncmp("--sysroot", argv[i], 9) && opts.wine_objdir)
|
|
|
|
{
|
|
|
|
if (argv[i][9] == '=') opts.wine_objdir = argv[i] + 10;
|
|
|
|
else opts.wine_objdir = argv[++i];
|
|
|
|
raw_compiler_arg = raw_linker_arg = 0;
|
|
|
|
}
|
2010-01-23 20:25:14 +01:00
|
|
|
else if (!strncmp("--lib-suffix", argv[i], 12) && opts.wine_objdir)
|
|
|
|
{
|
|
|
|
if (argv[i][12] == '=') opts.lib_suffix = argv[i] + 13;
|
|
|
|
else opts.lib_suffix = argv[++i];
|
|
|
|
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 */
|
|
|
|
if (raw_linker_arg)
|
|
|
|
{
|
|
|
|
strarray_add(opts.linker_args, argv[i]);
|
|
|
|
if (next_is_arg && (i + 1 < argc))
|
|
|
|
strarray_add(opts.linker_args, argv[i + 1]);
|
|
|
|
}
|
|
|
|
if (raw_compiler_arg)
|
|
|
|
{
|
|
|
|
strarray_add(opts.compiler_args, argv[i]);
|
|
|
|
if (next_is_arg && (i + 1 < argc))
|
|
|
|
strarray_add(opts.compiler_args, argv[i + 1]);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2004-02-21 05:01:38 +01:00
|
|
|
strarray_add(opts.files, argv[i]);
|
|
|
|
}
|
2002-12-15 02:17:10 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2004-02-24 02:00:53 +01:00
|
|
|
if (opts.files->size == 0) forward(argc, argv, &opts);
|
|
|
|
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
|
|
|
|
2003-01-07 20:47:19 +01:00
|
|
|
return 0;
|
2002-12-05 20:12:13 +01:00
|
|
|
}
|