tools: Move target CPU and platform handling to the common tools.h header.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-11-16 21:02:12 +01:00
parent c70ed78a36
commit d969d02e21
13 changed files with 378 additions and 566 deletions

View File

@ -80,6 +80,23 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
struct target
{
enum { CPU_i386, CPU_x86_64, CPU_ARM, CPU_ARM64 } cpu;
enum
{
PLATFORM_UNSPECIFIED,
PLATFORM_APPLE,
PLATFORM_ANDROID,
PLATFORM_LINUX,
PLATFORM_FREEBSD,
PLATFORM_SOLARIS,
PLATFORM_WINDOWS,
PLATFORM_MINGW,
PLATFORM_CYGWIN
} platform;
};
static inline void *xmalloc( size_t size )
{
@ -336,6 +353,217 @@ static inline int make_temp_file( const char *prefix, const char *suffix, char *
}
static inline struct target get_default_target(void)
{
struct target target;
#ifdef __i386__
target.cpu = CPU_i386;
#elif defined(__x86_64__)
target.cpu = CPU_x86_64;
#elif defined(__arm__)
target.cpu = CPU_ARM;
#elif defined(__aarch64__)
target.cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
#ifdef __APPLE__
target.platform = PLATFORM_APPLE;
#elif defined(__ANDROID__)
target.platform = PLATFORM_ANDROID;
#elif defined(__linux__)
target.platform = PLATFORM_LINUX;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
target.platform = PLATFORM_FREEBSD;
#elif defined(__sun)
target.platform = PLATFORM_SOLARIS;
#elif defined(__CYGWIN__)
target.platform = PLATFORM_CYGWIN;
#elif defined(_WIN32)
target.platform = PLATFORM_MINGW;
#else
target.platform = PLATFORM_UNSPECIFIED;
#endif
return target;
}
static inline unsigned int get_target_ptr_size( struct target target )
{
static const unsigned int sizes[] =
{
[CPU_i386] = 4,
[CPU_x86_64] = 8,
[CPU_ARM] = 4,
[CPU_ARM64] = 8,
};
return sizes[target.cpu];
}
static inline void set_target_ptr_size( struct target *target, unsigned int size )
{
switch (target->cpu)
{
case CPU_i386:
if (size == 8) target->cpu = CPU_x86_64;
break;
case CPU_x86_64:
if (size == 4) target->cpu = CPU_i386;
break;
case CPU_ARM:
if (size == 8) target->cpu = CPU_ARM64;
break;
case CPU_ARM64:
if (size == 4) target->cpu = CPU_ARM;
break;
}
}
static inline int get_cpu_from_name( const char *name )
{
static const struct
{
const char *name;
int cpu;
} cpu_names[] =
{
{ "i386", CPU_i386 },
{ "i486", CPU_i386 },
{ "i586", CPU_i386 },
{ "i686", CPU_i386 },
{ "i786", CPU_i386 },
{ "x86_64", CPU_x86_64 },
{ "amd64", CPU_x86_64 },
{ "aarch64", CPU_ARM64 },
{ "arm64", CPU_ARM64 },
{ "arm", CPU_ARM },
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(cpu_names); i++)
if (!strncmp( cpu_names[i].name, name, strlen(cpu_names[i].name) )) return cpu_names[i].cpu;
return -1;
}
static inline int get_platform_from_name( const char *name )
{
static const struct
{
const char *name;
int platform;
} platform_names[] =
{
{ "macos", PLATFORM_APPLE },
{ "darwin", PLATFORM_APPLE },
{ "android", PLATFORM_ANDROID },
{ "linux", PLATFORM_LINUX },
{ "freebsd", PLATFORM_FREEBSD },
{ "solaris", PLATFORM_SOLARIS },
{ "mingw32", PLATFORM_MINGW },
{ "windows-gnu", PLATFORM_MINGW },
{ "winnt", PLATFORM_MINGW },
{ "windows", PLATFORM_WINDOWS },
{ "cygwin", PLATFORM_CYGWIN },
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(platform_names); i++)
if (!strncmp( platform_names[i].name, name, strlen(platform_names[i].name) ))
return platform_names[i].platform;
return -1;
};
static inline const char *get_arch_dir( struct target target )
{
static const char *cpu_names[] =
{
[CPU_i386] = "i386",
[CPU_x86_64] = "x86_64",
[CPU_ARM] = "arm",
[CPU_ARM64] = "aarch64"
};
if (!cpu_names[target.cpu]) return "";
switch (target.platform)
{
case PLATFORM_WINDOWS:
case PLATFORM_CYGWIN:
case PLATFORM_MINGW:
return strmake( "/%s-windows", cpu_names[target.cpu] );
default:
return strmake( "/%s-unix", cpu_names[target.cpu] );
}
}
static inline int parse_target( const char *name, struct target *target )
{
int res;
char *p, *spec = xstrdup( name );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
/* get the CPU part */
if ((p = strchr( spec, '-' )))
{
*p++ = 0;
if ((res = get_cpu_from_name( spec )) == -1)
{
free( spec );
return 0;
}
target->cpu = res;
}
else if (!strcmp( spec, "mingw32" ))
{
target->cpu = CPU_i386;
p = spec;
}
else
{
free( spec );
return 0;
}
/* get the OS part */
target->platform = PLATFORM_UNSPECIFIED; /* default value */
for (;;)
{
if ((res = get_platform_from_name( p )) != -1)
{
target->platform = res;
break;
}
if (!(p = strchr( p, '-' ))) break;
p++;
}
free( spec );
return 1;
}
static inline struct target init_argv0_target( const char *argv0 )
{
char *name = get_basename( argv0 );
struct target target;
if (!strchr( name, '-' ) || !parse_target( name, &target ))
target = get_default_target();
free( name );
return target;
}
/* command-line option parsing */
/* partly based on the Glibc getopt() implementation */

View File

@ -92,17 +92,7 @@ static const char usage[] =
static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
"Copyright 2002 Ove Kaaven\n";
#ifdef __i386__
enum target_cpu target_cpu = CPU_x86;
#elif defined(__x86_64__)
enum target_cpu target_cpu = CPU_x86_64;
#elif defined(__arm__)
enum target_cpu target_cpu = CPU_ARM;
#elif defined(__aarch64__)
enum target_cpu target_cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
static struct target target;
int debuglevel = DEBUGLEVEL_NONE;
int parser_debug, yy_flex_debug;
@ -210,28 +200,6 @@ static const struct long_option long_options[] = {
{ NULL }
};
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 },
{ "amd64", CPU_x86_64 },
{ "x86_64", CPU_x86_64 },
{ "arm", CPU_ARM },
{ "armv5", CPU_ARM },
{ "armv6", CPU_ARM },
{ "armv7", CPU_ARM },
{ "armv7a", CPU_ARM },
{ "arm64", CPU_ARM64 },
{ "aarch64", CPU_ARM64 },
};
static void rm_tempfile(void);
enum stub_mode get_stub_mode(void)
@ -288,50 +256,6 @@ static void add_widl_version_define(void)
wpp_add_cmdline_define(version_str);
}
static void set_cpu( const char *cpu, int error_out )
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE( cpu_names ); i++)
{
if (!strcmp( cpu_names[i].name, cpu ))
{
target_cpu = cpu_names[i].cpu;
return;
}
}
if (error_out)
error( "Unrecognized CPU '%s'\n", cpu );
}
/* Set the target platform based on a potential prefix of the executable name.
* If not found, or not matching a known CPU name, just proceed silently. */
static void init_argv0_target( const char *argv0 )
{
char *p, *name = get_basename( argv0 );
if (!(p = strchr(name, '-')))
{
free( name );
return;
}
*p = 0;
set_cpu( name, 0 );
free( name );
}
/* set the target platform */
static void set_target( const char *target )
{
char *p, *spec = xstrdup( target );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
*p++ = 0;
set_cpu( spec, 1 );
free( spec );
}
/* clean things up when aborting on a signal */
static void exit_on_signal( int sig )
{
@ -648,7 +572,8 @@ static void option_callback( int optc, char *optarg )
/* FIXME: Support robust option */
break;
case 'b':
set_target( optarg );
if (!parse_target( optarg, &target ))
error( "Invalid target specification '%s'\n", optarg );
break;
case 'c':
do_everything = 0;
@ -742,22 +667,11 @@ static void option_callback( int optc, char *optarg )
}
}
static const char *get_pe_dir(void)
{
switch (target_cpu)
{
case CPU_x86: return "/i386-windows";
case CPU_x86_64: return "/x86_64-windows";
case CPU_ARM: return "/arm-windows";
case CPU_ARM64: return "/aarch64-windows";
default: return "";
}
}
int open_typelib( const char *name )
{
static const char *default_dirs[] = { DLLDIR, "/usr/lib/wine", "/usr/local/lib/wine" };
const char *pe_dir = get_pe_dir();
struct target win_target = { target.cpu, PLATFORM_WINDOWS };
const char *pe_dir = get_arch_dir( win_target );
int fd;
unsigned int i;
@ -809,7 +723,7 @@ int main(int argc,char *argv[])
signal( SIGHUP, exit_on_signal );
#endif
init_argv0_dir( argv[0] );
init_argv0_target( argv[0] );
target = init_argv0_target( argv[0] );
now = time(NULL);
@ -832,25 +746,10 @@ int main(int argc,char *argv[])
}
}
switch (target_cpu)
{
case CPU_x86:
if (pointer_size == 8) target_cpu = CPU_x86_64;
else pointer_size = 4;
break;
case CPU_x86_64:
if (pointer_size == 4) target_cpu = CPU_x86;
else pointer_size = 8;
break;
case CPU_ARM:
if (pointer_size == 8) target_cpu = CPU_ARM64;
else pointer_size = 4;
break;
case CPU_ARM64:
if (pointer_size == 4) target_cpu = CPU_ARM;
else pointer_size = 8;
break;
}
if (pointer_size)
set_target_ptr_size( &target, pointer_size );
else
pointer_size = get_target_ptr_size( target );
/* if nothing specified, try to guess output type from the output file name */
if (output_name && do_everything && !do_header && !do_typelib && !do_proxies &&

View File

@ -75,13 +75,6 @@ extern time_t now;
extern int line_number;
extern int char_number;
enum target_cpu
{
CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64
};
extern enum target_cpu target_cpu;
enum stub_mode
{
MODE_Os, /* inline stubs */

View File

@ -135,29 +135,17 @@ typedef struct
struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
} DLLSPEC;
enum target_cpu
{
CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64
};
enum target_platform
{
PLATFORM_UNSPECIFIED,
PLATFORM_APPLE,
PLATFORM_LINUX,
PLATFORM_FREEBSD,
PLATFORM_MINGW,
PLATFORM_SOLARIS,
PLATFORM_WINDOWS
};
extern char *target_alias;
extern enum target_cpu target_cpu;
extern enum target_platform target_platform;
extern struct target target;
static inline unsigned int get_ptr_size(void)
{
return get_target_ptr_size( target );
}
static inline int is_pe(void)
{
return target_platform == PLATFORM_MINGW || target_platform == PLATFORM_WINDOWS;
return target.platform == PLATFORM_MINGW || target.platform == PLATFORM_WINDOWS;
}
/* entry point flags */
@ -178,9 +166,9 @@ static inline int is_pe(void)
#define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
#define FLAG_CPU(cpu) (0x10000 << (cpu))
#define FLAG_CPU_MASK (FLAG_CPU(CPU_LAST + 1) - FLAG_CPU(0))
#define FLAG_CPU_MASK (FLAG_CPU_WIN32 | FLAG_CPU_WIN64)
#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
#define FLAG_CPU_WIN32 (FLAG_CPU_MASK & ~FLAG_CPU_WIN64)
#define FLAG_CPU_WIN32 (FLAG_CPU(CPU_i386) | FLAG_CPU(CPU_ARM))
#define MAX_ORDINALS 65535
@ -258,10 +246,8 @@ extern char *make_c_identifier( const char *str );
extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
extern const char *get_link_name( const ORDDEF *odp );
extern int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) );
extern int get_cpu_from_name( const char *name );
extern unsigned int get_alignment(unsigned int align);
extern unsigned int get_page_size(void);
extern unsigned int get_ptr_size(void);
extern unsigned int get_args_size( const ORDDEF *odp );
extern const char *asm_name( const char *func );
extern const char *func_declaration( const char *func );

View File

@ -757,7 +757,7 @@ int is_undefined( const char *name )
/* output the get_pc thunk if needed */
void output_get_pc_thunk(void)
{
assert( target_cpu == CPU_x86 );
assert( target.cpu == CPU_i386 );
output( "\n\t.text\n" );
output( "\t.align %d\n", get_alignment(4) );
output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
@ -777,9 +777,9 @@ static void output_import_thunk( const char *name, const char *table, int pos )
output( "%s\n", asm_globl(name) );
output_cfi( ".cfi_startproc" );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
if (!UsePIC)
{
output( "\tjmp *(%s+%d)\n", table, pos );
@ -1050,9 +1050,9 @@ static void output_delayed_import_thunks( const DLLSPEC *spec )
output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
output( "%s:\n", asm_name("__wine_delay_load_asm") );
output_cfi( ".cfi_startproc" );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
output( "\tpushl %%ecx\n" );
output_cfi( ".cfi_adjust_cfa_offset 4" );
output( "\tpushl %%edx\n" );
@ -1137,9 +1137,9 @@ static void output_delayed_import_thunks( const DLLSPEC *spec )
if (thumb_mode) output( "\t.thumb_func\n" );
output( "__wine_delay_imp_%s_%s:\n", import->c_name, name );
output_cfi( ".cfi_startproc" );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
case CPU_x86_64:
output( "\tmovl $%d,%%eax\n", (idx << 16) | j );
output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
@ -1244,9 +1244,9 @@ void output_stubs( DLLSPEC *spec )
output( "%s:\n", asm_name(name) );
output_cfi( ".cfi_startproc" );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
/* flesh out the stub a bit to make safedisc happy */
output(" \tnop\n" );
output(" \tnop\n" );
@ -1398,9 +1398,9 @@ void output_syscalls( DLLSPEC *spec )
output( "\t%s\n", func_declaration(name) );
output( "%s\n", asm_globl(name) );
output_cfi( ".cfi_startproc" );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
if (UsePIC)
{
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
@ -1463,9 +1463,9 @@ void output_syscalls( DLLSPEC *spec )
output_function_size( name );
}
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
if (UsePIC) break;
output( "\t.align %d\n", get_alignment(16) );
output( "\t%s\n", func_declaration("__wine_syscall") );
@ -1554,7 +1554,7 @@ static void build_library( const char *output_name, struct strarray files, int c
{
struct strarray args;
if (!create || target_platform != PLATFORM_WINDOWS)
if (!create || target.platform != PLATFORM_WINDOWS)
{
args = find_tool( "ar", NULL );
strarray_add( &args, create ? "rc" : "r" );
@ -1571,7 +1571,7 @@ static void build_library( const char *output_name, struct strarray files, int c
if (create) unlink( output_name );
spawn( args );
if (target_platform != PLATFORM_WINDOWS)
if (target.platform != PLATFORM_WINDOWS)
{
struct strarray ranlib = find_tool( "ranlib", NULL );
strarray_add( &ranlib, output_name );
@ -1596,9 +1596,9 @@ static void build_windows_import_lib( const char *lib_name, DLLSPEC *spec )
strarray_add( &args, "-d" );
strarray_add( &args, def_file );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
strarray_add( &args, "-m" );
strarray_add( &args, "i386" );
strarray_add( &args, "--as-flags=--32" );

View File

@ -47,31 +47,7 @@ int unix_lib = 0;
int safe_seh = 0;
int prefer_native = 0;
#ifdef __i386__
enum target_cpu target_cpu = CPU_x86;
#elif defined(__x86_64__)
enum target_cpu target_cpu = CPU_x86_64;
#elif defined(__arm__)
enum target_cpu target_cpu = CPU_ARM;
#elif defined(__aarch64__)
enum target_cpu target_cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
#ifdef __APPLE__
enum target_platform target_platform = PLATFORM_APPLE;
#elif defined(__linux__)
enum target_platform target_platform = PLATFORM_LINUX;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
enum target_platform target_platform = PLATFORM_FREEBSD;
#elif defined(__sun)
enum target_platform target_platform = PLATFORM_SOLARIS;
#elif defined(_WIN32)
enum target_platform target_platform = PLATFORM_MINGW;
#else
enum target_platform target_platform = PLATFORM_UNSPECIFIED;
#endif
struct target target = { 0 };
char *target_alias = NULL;
@ -123,22 +99,6 @@ enum exec_mode_values
static enum exec_mode_values exec_mode = MODE_NONE;
static const struct
{
const char *name;
enum target_platform platform;
} platform_names[] =
{
{ "macos", PLATFORM_APPLE },
{ "darwin", PLATFORM_APPLE },
{ "linux", PLATFORM_LINUX },
{ "freebsd", PLATFORM_FREEBSD },
{ "solaris", PLATFORM_SOLARIS },
{ "mingw32", PLATFORM_MINGW },
{ "windows-gnu", PLATFORM_MINGW },
{ "windows", PLATFORM_WINDOWS },
{ "winnt", PLATFORM_MINGW }
};
/* set the dll file name from the input file name */
static void set_dll_file_name( const char *name, DLLSPEC *spec )
@ -208,54 +168,12 @@ static void set_syscall_table( const char *id, DLLSPEC *spec )
}
/* set the target CPU and platform */
static void set_target( const char *target )
static void set_target( const char *name )
{
unsigned int i;
char *p, *spec = xstrdup( target );
target_alias = xstrdup( name );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
target_alias = xstrdup( target );
/* get the CPU part */
if ((p = strchr( spec, '-' )))
{
int cpu;
*p++ = 0;
cpu = get_cpu_from_name( spec );
if (cpu == -1) fatal_error( "Unrecognized CPU '%s'\n", spec );
target_cpu = cpu;
}
else if (!strcmp( spec, "mingw32" ))
{
target_cpu = CPU_x86;
p = spec;
}
else
fatal_error( "Invalid target specification '%s'\n", target );
/* get the OS part */
target_platform = PLATFORM_UNSPECIFIED; /* default value */
for (;;)
{
for (i = 0; i < ARRAY_SIZE(platform_names); i++)
{
if (!strncmp( platform_names[i].name, p, strlen(platform_names[i].name) ))
{
target_platform = platform_names[i].platform;
break;
}
}
if (target_platform != PLATFORM_UNSPECIFIED || !(p = strchr( p, '-' ))) break;
p++;
}
free( spec );
if (target_cpu == CPU_ARM && is_pe()) thumb_mode = 1;
if (!parse_target( name, &target )) fatal_error( "Unrecognized target '%s'\n", name );
if (target.cpu == CPU_ARM && is_pe()) thumb_mode = 1;
}
/* cleanup on program exit */
@ -689,6 +607,9 @@ int main(int argc, char **argv)
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
target = init_argv0_target( argv[0] );
if (target.platform == PLATFORM_CYGWIN) target.platform = PLATFORM_MINGW;
files = parse_options( argc, argv, short_options, long_options, 0, option_callback );
atexit( cleanup ); /* make sure we remove the output file on exit */
@ -698,19 +619,7 @@ int main(int argc, char **argv)
strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
init_dll_name( spec );
switch (target_cpu)
{
case CPU_x86:
if (force_pointer_size == 8) target_cpu = CPU_x86_64;
break;
case CPU_x86_64:
if (force_pointer_size == 4) target_cpu = CPU_x86;
break;
default:
if (force_pointer_size == 8)
fatal_error( "Cannot build 64-bit code for this CPU\n" );
break;
}
if (force_pointer_size) set_target_ptr_size( &target, force_pointer_size );
switch(exec_mode)
{

View File

@ -358,7 +358,7 @@ static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec )
if (odp->type == TYPE_VARARGS)
odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */
if (target_cpu != CPU_x86)
if (target.cpu != CPU_i386)
odp->flags &= ~(FLAG_THISCALL | FLAG_FASTCALL);
if (!(token = GetToken(1)))
@ -511,7 +511,7 @@ static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
}
else if (!strcmp( token, "i386" )) /* backwards compatibility */
{
odp->flags |= FLAG_CPU(CPU_x86);
odp->flags |= FLAG_CPU(CPU_i386);
}
else
{
@ -621,7 +621,7 @@ static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
assert( 0 );
}
if ((odp->flags & FLAG_CPU_MASK) && !(odp->flags & FLAG_CPU(target_cpu)))
if ((odp->flags & FLAG_CPU_MASK) && !(odp->flags & FLAG_CPU(target.cpu)))
{
/* ignore this entry point */
spec->nb_entry_points--;

View File

@ -685,9 +685,9 @@ void output_res_o_file( DLLSPEC *spec )
strarray_add( &args, res_file );
strarray_add( &args, "-o" );
strarray_add( &args, output_file_name );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
strarray_add( &args, "-F" );
strarray_add( &args, "pe-i386" );
break;

View File

@ -254,9 +254,9 @@ static void output_relay_debug( DLLSPEC *spec )
if (!needs_relay( odp )) continue;
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
output( "\t.align %d\n", get_alignment(4) );
output( "\t.long 0x90909090,0x90909090\n" );
output( "__wine_spec_relay_entry_point_%d:\n", i );
@ -457,7 +457,7 @@ void output_exports( DLLSPEC *spec )
output( "\t%s .L__wine_spec_forwards+%u\n", func_ptr, fwd_size );
fwd_size += strlen(odp->link_name) + 1;
}
else if ((odp->flags & FLAG_IMPORT) && (target_cpu == CPU_x86 || target_cpu == CPU_x86_64))
else if ((odp->flags & FLAG_IMPORT) && (target.cpu == CPU_i386 || target.cpu == CPU_x86_64))
{
name = odp->name ? odp->name : odp->export_name;
if (name) output( "\t%s %s_%s\n", func_ptr, asm_name("__wine_spec_imp"), name );
@ -585,9 +585,9 @@ void output_exports( DLLSPEC *spec )
else output( "%s_%u:\n", asm_name("__wine_spec_imp"), i );
output_cfi( ".cfi_startproc" );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
output( "\t.byte 0x8b,0xff,0x55,0x8b,0xec,0x5d\n" ); /* hotpatch prolog */
if (UsePIC)
{
@ -623,7 +623,7 @@ void output_module( DLLSPEC *spec )
/* Reserve some space for the PE header */
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
@ -640,9 +640,9 @@ void output_module( DLLSPEC *spec )
output( "\t.skip %u\n", 65536 + page_size );
break;
default:
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
case CPU_x86_64:
output( "\n\t.section \".init\",\"ax\"\n" );
output( "\tjmp 1f\n" );
@ -671,9 +671,9 @@ void output_module( DLLSPEC *spec )
output( ".L__wine_spec_rva_base:\n" );
output( "\t.long 0x4550\n" ); /* Signature */
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
case CPU_i386: machine = IMAGE_FILE_MACHINE_I386; break;
case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
case CPU_ARM: machine = IMAGE_FILE_MACHINE_ARMNT; break;
case CPU_ARM64: machine = IMAGE_FILE_MACHINE_ARM64; break;
@ -739,7 +739,7 @@ void output_module( DLLSPEC *spec )
output_data_directories( data_dirs );
if (target_platform == PLATFORM_APPLE)
if (target.platform == PLATFORM_APPLE)
output( "\t.lcomm %s,4\n", asm_name("_end") );
}
@ -964,9 +964,9 @@ void output_fake_module( DLLSPEC *spec )
put_data( fakedll_signature, sizeof(fakedll_signature) );
put_dword( 0x4550 ); /* Signature */
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86: put_word( IMAGE_FILE_MACHINE_I386 ); break;
case CPU_i386: put_word( IMAGE_FILE_MACHINE_I386 ); break;
case CPU_x86_64: put_word( IMAGE_FILE_MACHINE_AMD64 ); break;
case CPU_ARM: put_word( IMAGE_FILE_MACHINE_ARMNT ); break;
case CPU_ARM64: put_word( IMAGE_FILE_MACHINE_ARM64 ); break;
@ -1105,7 +1105,7 @@ void output_def_file( DLLSPEC *spec, int import_only )
case TYPE_STDCALL:
{
int at_param = get_args_size( odp );
if (!kill_at && target_cpu == CPU_x86) output( "@%d", at_param );
if (!kill_at && target.cpu == CPU_i386) output( "@%d", at_param );
if (import_only) break;
if (odp->flags & FLAG_FORWARD)
output( "=%s", odp->link_name );
@ -1114,7 +1114,7 @@ void output_def_file( DLLSPEC *spec, int import_only )
break;
}
case TYPE_STUB:
if (!kill_at && target_cpu == CPU_x86) output( "@%d", get_args_size( odp ));
if (!kill_at && target.cpu == CPU_i386) output( "@%d", get_args_size( odp ));
is_private = 1;
break;
default:

View File

@ -32,28 +32,6 @@
static struct strarray tmp_files;
static const char *output_file_source_name;
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 },
{ "amd64", CPU_x86_64 },
{ "x86_64", CPU_x86_64 },
{ "arm", CPU_ARM },
{ "armv5", CPU_ARM },
{ "armv6", CPU_ARM },
{ "armv7", CPU_ARM },
{ "armv7a", CPU_ARM },
{ "arm64", CPU_ARM64 },
{ "aarch64", CPU_ARM64 },
};
/* atexit handler to clean tmp files */
void cleanup_tmp_files(void)
{
@ -338,7 +316,7 @@ struct strarray get_as_command(void)
if (force_pointer_size)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
strarray_add( &args, "-arch" );
@ -369,7 +347,7 @@ struct strarray get_ld_command(void)
if (force_pointer_size)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
strarray_add( &args, "-arch" );
@ -391,7 +369,7 @@ struct strarray get_ld_command(void)
}
}
if (target_cpu == CPU_ARM && !is_pe())
if (target.cpu == CPU_ARM && !is_pe())
strarray_add( &args, "--no-wchar-size-warning" );
return args;
@ -696,7 +674,7 @@ int remove_stdcall_decoration( char *name )
{
char *p, *end = strrchr( name, '@' );
if (!end || !end[1] || end == name) return -1;
if (target_cpu != CPU_x86) return -1;
if (target.cpu != CPU_i386) return -1;
/* make sure all the rest is digits */
for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
*end = 0;
@ -822,7 +800,7 @@ const char *get_link_name( const ORDDEF *odp )
static char *buffer;
char *ret;
if (target_cpu != CPU_x86) return odp->link_name;
if (target.cpu != CPU_i386) return odp->link_name;
switch (odp->type)
{
@ -877,16 +855,6 @@ int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const
}
/* parse a cpu name and return the corresponding value */
int get_cpu_from_name( const char *name )
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(cpu_names); i++)
if (!strcmp( cpu_names[i].name, name )) return cpu_names[i].cpu;
return -1;
}
/*****************************************************************
* Function: get_alignment
*
@ -917,11 +885,11 @@ unsigned int get_alignment(unsigned int align)
assert( !(align & (align - 1)) );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
case CPU_x86_64:
if (target_platform != PLATFORM_APPLE) return align;
if (target.platform != PLATFORM_APPLE) return align;
/* fall through */
case CPU_ARM:
case CPU_ARM64:
@ -940,23 +908,6 @@ unsigned int get_page_size(void)
return 0x1000; /* same on all platforms */
}
/* return the size of a pointer on the target CPU */
unsigned int get_ptr_size(void)
{
switch(target_cpu)
{
case CPU_x86:
case CPU_ARM:
return 4;
case CPU_x86_64:
case CPU_ARM64:
return 8;
}
/* unreached */
assert(0);
return 0;
}
/* return the total size in bytes of the arguments on the stack */
unsigned int get_args_size( const ORDDEF *odp )
{
@ -968,12 +919,12 @@ unsigned int get_args_size( const ORDDEF *odp )
{
case ARG_INT64:
case ARG_DOUBLE:
if (target_cpu == CPU_ARM) size = (size + 7) & ~7;
if (target.cpu == CPU_ARM) size = (size + 7) & ~7;
size += 8;
break;
case ARG_INT128:
/* int128 is passed as pointer on x86_64 */
if (target_cpu != CPU_x86_64)
if (target.cpu != CPU_x86_64)
{
size += 16;
break;
@ -992,11 +943,11 @@ const char *asm_name( const char *sym )
{
static char *buffer;
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
if (target_cpu != CPU_x86) return sym;
if (target.cpu != CPU_i386) return sym;
if (sym[0] == '@') return sym; /* fastcall */
/* fall through */
case PLATFORM_APPLE:
@ -1014,7 +965,7 @@ const char *func_declaration( const char *func )
{
static char *buffer;
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
return "";
@ -1026,7 +977,7 @@ const char *func_declaration( const char *func )
break;
default:
free( buffer );
switch(target_cpu)
switch (target.cpu)
{
case CPU_ARM:
buffer = strmake( ".type %s,%%function%s", func,
@ -1047,7 +998,7 @@ const char *func_declaration( const char *func )
/* output a size declaration for an assembly function */
void output_function_size( const char *name )
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
case PLATFORM_MINGW:
@ -1078,7 +1029,7 @@ void output_rva( const char *format, ... )
va_list valist;
va_start( valist, format );
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
@ -1098,14 +1049,14 @@ void output_rva( const char *format, ... )
/* output the GNU note for non-exec stack */
void output_gnu_stack_note(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
case PLATFORM_APPLE:
break;
default:
switch(target_cpu)
switch (target.cpu)
{
case CPU_ARM:
case CPU_ARM64:
@ -1125,15 +1076,15 @@ const char *asm_globl( const char *func )
static char *buffer;
free( buffer );
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
buffer = strmake( "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
break;
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
buffer = strmake( "\t.globl %s%s\n%s%s:", target_cpu == CPU_x86 ? "_" : "", func,
target_cpu == CPU_x86 ? "_" : "", func );
buffer = strmake( "\t.globl %s%s\n%s%s:", target.cpu == CPU_i386 ? "_" : "", func,
target.cpu == CPU_i386 ? "_" : "", func );
break;
default:
buffer = strmake( "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
@ -1155,7 +1106,7 @@ const char *get_asm_ptr_keyword(void)
const char *get_asm_string_keyword(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
return ".asciz";
@ -1166,7 +1117,7 @@ const char *get_asm_string_keyword(void)
const char *get_asm_export_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".data";
case PLATFORM_MINGW:
@ -1177,7 +1128,7 @@ const char *get_asm_export_section(void)
const char *get_asm_rodata_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".const";
default: return ".section .rodata";
@ -1186,7 +1137,7 @@ const char *get_asm_rodata_section(void)
const char *get_asm_rsrc_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".data";
case PLATFORM_MINGW:
@ -1197,7 +1148,7 @@ const char *get_asm_rsrc_section(void)
const char *get_asm_string_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".cstring";
default: return ".section .rodata";
@ -1208,7 +1159,7 @@ const char *arm64_page( const char *sym )
{
static char *buffer;
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
free( buffer );
@ -1224,7 +1175,7 @@ const char *arm64_pageoff( const char *sym )
static char *buffer;
free( buffer );
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
buffer = strmake( "%s@PAGEOFF", sym );

View File

@ -115,10 +115,12 @@ static char* try_lib_path(const char* dir, const char* pre,
return 0;
}
static file_type guess_lib_type(enum target_platform platform, const char* dir,
static file_type guess_lib_type(struct target target, const char* dir,
const char* library, const char *prefix, const char *suffix, char** file)
{
if (platform != PLATFORM_WINDOWS && platform != PLATFORM_MINGW && platform != PLATFORM_CYGWIN)
if (target.platform != PLATFORM_WINDOWS &&
target.platform != PLATFORM_MINGW &&
target.platform != PLATFORM_CYGWIN)
{
/* Unix shared object */
if ((*file = try_lib_path(dir, prefix, library, ".so", file_so)))
@ -140,7 +142,7 @@ static file_type guess_lib_type(enum target_platform platform, const char* dir,
return file_na;
}
file_type get_lib_type(enum target_platform platform, struct strarray path, const char *library,
file_type get_lib_type(struct target target, struct strarray path, const char *library,
const char *prefix, const char *suffix, char** file)
{
unsigned int i;
@ -148,7 +150,7 @@ file_type get_lib_type(enum target_platform platform, struct strarray path, cons
if (!suffix) suffix = ".a";
for (i = 0; i < path.count; i++)
{
file_type type = guess_lib_type(platform, path.str[i], library, prefix, suffix, file);
file_type type = guess_lib_type(target, path.str[i], library, prefix, suffix, file);
if (type != file_na) return type;
}
return file_na;

View File

@ -32,22 +32,6 @@
# endif
#endif
enum target_cpu
{
CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64
};
enum target_platform
{
PLATFORM_UNSPECIFIED,
PLATFORM_APPLE,
PLATFORM_ANDROID,
PLATFORM_SOLARIS,
PLATFORM_WINDOWS,
PLATFORM_MINGW,
PLATFORM_CYGWIN
};
void DECLSPEC_NORETURN error(const char* s, ...);
typedef enum {
@ -57,7 +41,7 @@ typedef enum {
void create_file(const char* name, int mode, const char* fmt, ...);
file_type get_file_type(const char* filename);
file_type get_lib_type(enum target_platform platform, struct strarray path, const char *library,
file_type get_lib_type(struct target target, struct strarray path, const char *library,
const char *prefix, const char *suffix, char** file);
const char *find_binary( struct strarray prefix, const char *name );
int spawn(struct strarray prefix, struct strarray arr, int ignore_errors);

View File

@ -158,51 +158,11 @@ static const char *includedir;
enum processor { proc_cc, proc_cxx, proc_cpp, proc_as };
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 },
{ "amd64", CPU_x86_64 },
{ "x86_64", CPU_x86_64 },
{ "arm", CPU_ARM },
{ "armv5", CPU_ARM },
{ "armv6", CPU_ARM },
{ "armv7", CPU_ARM },
{ "armv7a", CPU_ARM },
{ "arm64", CPU_ARM64 },
{ "aarch64", CPU_ARM64 },
};
static const struct
{
const char *name;
enum target_platform platform;
} platform_names[] =
{
{ "macos", PLATFORM_APPLE },
{ "darwin", PLATFORM_APPLE },
{ "android", PLATFORM_ANDROID },
{ "solaris", PLATFORM_SOLARIS },
{ "cygwin", PLATFORM_CYGWIN },
{ "mingw32", PLATFORM_MINGW },
{ "windows-gnu", PLATFORM_MINGW },
{ "windows", PLATFORM_WINDOWS },
{ "winnt", PLATFORM_MINGW }
};
struct options
{
enum processor processor;
enum target_cpu target_cpu;
enum target_platform target_platform;
const char *target;
struct target target;
const char *target_alias;
const char *version;
int shared;
int use_msvcrt;
@ -246,32 +206,6 @@ struct options
struct strarray delayimports;
};
#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(__arm__)
static const enum target_cpu build_cpu = CPU_ARM;
#elif defined(__aarch64__)
static const enum target_cpu build_cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
#ifdef __APPLE__
static enum target_platform build_platform = PLATFORM_APPLE;
#elif defined(__ANDROID__)
static enum target_platform build_platform = PLATFORM_ANDROID;
#elif defined(__sun)
static enum target_platform build_platform = PLATFORM_SOLARIS;
#elif defined(__CYGWIN__)
static enum target_platform build_platform = PLATFORM_CYGWIN;
#elif defined(_WIN32)
static enum target_platform build_platform = PLATFORM_MINGW;
#else
static enum target_platform build_platform = PLATFORM_UNSPECIFIED;
#endif
static void cleanup_output_files(void)
{
if (output_file_name) unlink( output_file_name );
@ -316,7 +250,7 @@ static char* get_temp_file(const char* prefix, const char* suffix)
static int is_pe_target( const struct options *opts )
{
switch(opts->target_platform)
switch (opts->target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_CYGWIN:
@ -359,13 +293,13 @@ static struct strarray build_tool_name( struct options *opts, enum tool tool )
struct strarray ret = empty_strarray;
char* str;
if (opts->target && opts->version)
if (opts->target_alias && opts->version)
{
str = strmake("%s-%s-%s", opts->target, base, opts->version);
str = strmake("%s-%s-%s", opts->target_alias, base, opts->version);
}
else if (opts->target)
else if (opts->target_alias)
{
str = strmake("%s-%s", opts->target, base);
str = strmake("%s-%s", opts->target_alias, base);
}
else if (opts->version)
{
@ -388,10 +322,10 @@ static struct strarray build_tool_name( struct options *opts, enum tool tool )
ret = strarray_fromstring( path, " " );
if (!strncmp( llvm_base, "clang", 5 ))
{
if (opts->target)
if (opts->target_alias)
{
strarray_add( &ret, "-target" );
strarray_add( &ret, opts->target );
strarray_add( &ret, opts->target_alias );
}
strarray_add( &ret, "-Wno-unused-command-line-argument" );
strarray_add( &ret, "-fuse-ld=lld" );
@ -465,7 +399,7 @@ static struct strarray get_link_args( struct options *opts, const char *output_n
if (verbose > 1) strarray_add( &flags, "-v" );
switch (opts->target_platform)
switch (opts->target.platform)
{
case PLATFORM_APPLE:
strarray_add( &flags, opts->unix_lib ? "-dynamiclib" : "-bundle" );
@ -519,7 +453,7 @@ static struct strarray get_link_args( struct options *opts, const char *output_n
if (opts->image_base) strarray_add( &flags, strmake("-Wl,--image-base,%s", opts->image_base ));
if (opts->large_address_aware && opts->target_cpu == CPU_x86)
if (opts->large_address_aware && opts->target.cpu == CPU_i386)
strarray_add( &flags, "-Wl,--large-address-aware" );
/* make sure we don't need a libgcc_s dll on Windows */
@ -593,7 +527,7 @@ static struct strarray get_link_args( struct options *opts, const char *output_n
strarray_add( &link_args, "-shared" );
strarray_add( &link_args, "-Wl,-Bsymbolic" );
if (!opts->noshortwchar && opts->target_cpu == CPU_ARM)
if (!opts->noshortwchar && opts->target.cpu == CPU_ARM)
strarray_add( &flags, "-Wl,--no-wchar-size-warning" );
if (!try_link( opts->prefix, link_args, "-Wl,-z,defs" ))
strarray_add( &flags, "-Wl,-z,defs" );
@ -602,41 +536,17 @@ static struct strarray get_link_args( struct options *opts, const char *output_n
return link_args;
}
static const char *get_multiarch_dir( enum target_cpu cpu )
static const char *get_multiarch_dir( struct target target )
{
switch(cpu)
switch (target.cpu)
{
case CPU_x86: return "/i386-linux-gnu";
case CPU_i386: return "/i386-linux-gnu";
case CPU_x86_64: return "/x86_64-linux-gnu";
case CPU_ARM: return "/arm-linux-gnueabi";
case CPU_ARM64: return "/aarch64-linux-gnu";
default:
assert(0);
return NULL;
}
}
static const char *get_wine_arch_dir( enum target_cpu target_cpu, enum target_platform target_platform )
{
const char *cpu;
switch (target_cpu)
{
case CPU_x86: cpu = "i386"; break;
case CPU_x86_64: cpu = "x86_64"; break;
case CPU_ARM: cpu = "arm"; break;
case CPU_ARM64: cpu = "aarch64"; break;
default: return "/wine";
}
switch (target_platform)
{
case PLATFORM_WINDOWS:
case PLATFORM_CYGWIN:
case PLATFORM_MINGW:
return strmake( "/wine/%s-windows", cpu );
default:
return strmake( "/wine/%s-unix", cpu );
}
assert(0);
return NULL;
}
static char *get_lib_dir( struct options *opts )
@ -648,11 +558,11 @@ static char *get_lib_dir( struct options *opts )
struct stat st;
size_t build_len, target_len;
bit_suffix = opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 ? "64" : "32";
other_bit_suffix = opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 ? "32" : "64";
winecrt0 = strmake( "%s/libwinecrt0.a", get_wine_arch_dir( opts->target_cpu, opts->target_platform ));
build_multiarch = get_multiarch_dir( build_cpu );
target_multiarch = get_multiarch_dir( opts->target_cpu );
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 );
build_len = strlen( build_multiarch );
target_len = strlen( target_multiarch );
@ -697,7 +607,8 @@ static char *get_lib_dir( struct options *opts )
if (*p != '/') break;
/* try s/$build_cpu/$target_cpu/ on multiarch */
if (build_cpu != opts->target_cpu && !memcmp( p, build_multiarch, build_len ) && p[build_len] == '/')
if (get_default_target().cpu != opts->target.cpu &&
!memcmp( p, build_multiarch, build_len ) && p[build_len] == '/')
{
memmove( p + target_len, p + build_len, strlen( p + build_len ) + 1 );
memcpy( p, target_multiarch, target_len );
@ -791,7 +702,9 @@ static void compile(struct options* opts, const char* lang)
break;
}
if (opts->target_platform == PLATFORM_WINDOWS || opts->target_platform == PLATFORM_CYGWIN || opts->target_platform == PLATFORM_MINGW)
if (opts->target.platform == PLATFORM_WINDOWS ||
opts->target.platform == PLATFORM_CYGWIN ||
opts->target.platform == PLATFORM_MINGW)
goto no_compat_defines;
if (opts->processor != proc_cpp)
@ -808,7 +721,7 @@ static void compile(struct options* opts, const char* lang)
strarray_add(&comp_args, "-fno-PIC");
}
if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64)
if (get_target_ptr_size( opts->target ) == 8)
{
strarray_add(&comp_args, "-DWIN64");
strarray_add(&comp_args, "-D_WIN64");
@ -825,7 +738,7 @@ static void compile(struct options* opts, const char* lang)
if (gcc_defs)
{
switch (opts->target_cpu)
switch (opts->target.cpu)
{
case CPU_x86_64:
case CPU_ARM64:
@ -833,7 +746,7 @@ static void compile(struct options* opts, const char* lang)
strarray_add(&comp_args, "-D__cdecl=__stdcall");
strarray_add(&comp_args, "-D__fastcall=__stdcall");
break;
case CPU_x86:
case CPU_i386:
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__))");
@ -865,7 +778,7 @@ static void compile(struct options* opts, const char* lang)
strarray_add(&comp_args, "-D__int8=char");
strarray_add(&comp_args, "-D__int16=short");
strarray_add(&comp_args, "-D__int32=int");
if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64)
if (get_target_ptr_size( opts->target ) == 8)
strarray_add(&comp_args, "-D__int64=long");
else
strarray_add(&comp_args, "-D__int64=long long");
@ -969,10 +882,10 @@ static struct strarray get_winebuild_args(struct options *opts)
strarray_add( &spec_args, binary );
if (verbose) strarray_add( &spec_args, "-v" );
if (keep_generated) strarray_add( &spec_args, "--save-temps" );
if (opts->target)
if (opts->target_alias)
{
strarray_add( &spec_args, "--target" );
strarray_add( &spec_args, opts->target );
strarray_add( &spec_args, opts->target_alias );
}
for (i = 0; i < opts->prefix.count; i++)
strarray_add( &spec_args, strmake( "-B%s", opts->prefix.str[i] ));
@ -1058,7 +971,7 @@ static void add_library( struct options *opts, struct strarray lib_dirs,
{
char *static_lib, *fullname = 0;
switch(get_lib_type(opts->target_platform, lib_dirs, library, "lib", opts->lib_suffix, &fullname))
switch(get_lib_type(opts->target, lib_dirs, library, "lib", opts->lib_suffix, &fullname))
{
case file_arh:
strarray_add(files, strmake("-a%s", fullname));
@ -1133,7 +1046,7 @@ static const char *build_spec_obj( struct options *opts, const char *spec_file,
if (opts->large_address_aware) strarray_add( &spec_args, "--large-address-aware" );
}
if (opts->target_platform == PLATFORM_WINDOWS) strarray_add(&spec_args, "--safeseh");
if (opts->target.platform == PLATFORM_WINDOWS) strarray_add(&spec_args, "--safeseh");
if (entry_point)
{
@ -1232,8 +1145,7 @@ static void build(struct options* opts)
{
char *lib_dir = get_lib_dir( opts );
strarray_addall( &lib_dirs, opts->lib_dirs );
strarray_add( &lib_dirs, strmake( "%s%s", lib_dir,
get_wine_arch_dir( opts->target_cpu, opts->target_platform )));
strarray_add( &lib_dirs, strmake( "%s/wine%s", lib_dir, get_arch_dir( opts->target )));
strarray_add( &lib_dirs, lib_dir );
}
else
@ -1328,7 +1240,7 @@ static void build(struct options* opts)
if (!opts->entry_point)
{
if (opts->subsystem && !opts->unix_lib && !strcmp( opts->subsystem, "native" ))
entry_point = (is_pe && opts->target_cpu == CPU_x86) ? "DriverEntry@8" : "DriverEntry";
entry_point = (is_pe && opts->target.cpu == CPU_i386) ? "DriverEntry@8" : "DriverEntry";
else if (opts->use_msvcrt && !opts->shared && !opts->win16_app)
entry_point = opts->unicode_app ? "wmainCRTStartup" : "mainCRTStartup";
}
@ -1343,7 +1255,7 @@ static void build(struct options* opts)
/* link everything together now */
link_args = get_link_args( opts, output_name );
if ((opts->nodefaultlibs || opts->use_msvcrt) && opts->target_platform == PLATFORM_MINGW)
if ((opts->nodefaultlibs || opts->use_msvcrt) && opts->target.platform == PLATFORM_MINGW)
{
libgcc = find_libgcc(opts->prefix, link_args);
if (!libgcc) libgcc = "-lgcc";
@ -1356,15 +1268,15 @@ static void build(struct options* opts)
strarray_add(&link_args, strmake("-L%s", lib_dirs.str[j]));
if (is_pe && opts->use_msvcrt && !entry_point && (opts->shared || opts->win16_app))
entry_point = opts->target_cpu == CPU_x86 ? "DllMainCRTStartup@12" : "DllMainCRTStartup";
entry_point = opts->target.cpu == CPU_i386 ? "DllMainCRTStartup@12" : "DllMainCRTStartup";
if (is_pe && entry_point)
{
if (opts->target_platform == PLATFORM_WINDOWS)
if (opts->target.platform == PLATFORM_WINDOWS)
strarray_add(&link_args, strmake("-Wl,-entry:%s", entry_point));
else
strarray_add(&link_args, strmake("-Wl,--entry,%s%s",
is_pe && opts->target_cpu == CPU_x86 ? "_" : "",
is_pe && opts->target.cpu == CPU_i386 ? "_" : "",
entry_point));
}
@ -1374,7 +1286,7 @@ static void build(struct options* opts)
{
for (j = 0; j < opts->delayimports.count; j++)
{
if (opts->target_platform == PLATFORM_WINDOWS)
if (opts->target.platform == PLATFORM_WINDOWS)
strarray_add(&link_args, strmake("-Wl,-delayload:%s", opts->delayimports.str[j]));
else
strarray_add(&link_args, strmake("-Wl,-delayload,%s",opts->delayimports.str[j]));
@ -1491,7 +1403,7 @@ static void build(struct options* opts)
}
/* set the base address with prelink if linker support is not present */
if (opts->prelink && !opts->target)
if (opts->prelink && !opts->target_alias)
{
if (opts->prelink[0] && strcmp(opts->prelink,"false"))
{
@ -1563,54 +1475,8 @@ static int is_linker_arg(const char* arg)
static void parse_target_option( struct options *opts, const char *target )
{
char *p, *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, '-' )))
{
*p++ = 0;
for (i = 0; i < ARRAY_SIZE(cpu_names); i++)
{
if (!strcmp( cpu_names[i].name, spec ))
{
opts->target_cpu = cpu_names[i].cpu;
break;
}
}
if (i == ARRAY_SIZE(cpu_names))
error( "Unrecognized CPU '%s'\n", spec );
}
else if (!strcmp( spec, "mingw32" ))
{
opts->target_cpu = CPU_x86;
p = spec;
}
else
error( "Invalid target specification '%s'\n", target );
/* get the OS part */
opts->target_platform = PLATFORM_UNSPECIFIED; /* default value */
for (;;)
{
for (i = 0; i < ARRAY_SIZE(platform_names); i++)
{
if (!strncmp( platform_names[i].name, p, strlen(platform_names[i].name) ))
{
opts->target_platform = platform_names[i].platform;
break;
}
}
if (opts->target_platform != PLATFORM_UNSPECIFIED || !(p = strchr( p, '-' ))) break;
p++;
}
free( spec );
opts->target = xstrdup( target );
opts->target_alias = xstrdup( target );
if (!parse_target( target, &opts->target )) error( "Invalid target specification '%s'\n", target );
}
static int is_option( struct options *opts, int i, const char *option, const char **option_arg )
@ -1656,8 +1522,7 @@ int main(int argc, char **argv)
/* initialize options */
memset(&opts, 0, sizeof(opts));
opts.target_cpu = build_cpu;
opts.target_platform = build_platform;
opts.target = init_argv0_target( argv[0] );
opts.pic = 1;
/* determine the processor type */
@ -1869,19 +1734,13 @@ int main(int argc, char **argv)
}
else if (strcmp("-m32", opts.args.str[i]) == 0)
{
if (opts.target_cpu == CPU_x86_64)
opts.target_cpu = CPU_x86;
else if (opts.target_cpu == CPU_ARM64)
opts.target_cpu = CPU_ARM;
set_target_ptr_size( &opts.target, 4 );
opts.force_pointer_size = 4;
raw_linker_arg = 1;
}
else if (strcmp("-m64", opts.args.str[i]) == 0)
{
if (opts.target_cpu == CPU_x86)
opts.target_cpu = CPU_x86_64;
else if (opts.target_cpu == CPU_ARM)
opts.target_cpu = CPU_ARM64;
set_target_ptr_size( &opts.target, 8 );
opts.force_pointer_size = 8;
raw_linker_arg = 1;
}
@ -1929,7 +1788,7 @@ int main(int argc, char **argv)
opts.shared = 1;
raw_compiler_arg = raw_linker_arg = 0;
}
else if (strcmp("-s", opts.args.str[i]) == 0 && opts.target_platform == PLATFORM_APPLE)
else if (strcmp("-s", opts.args.str[i]) == 0 && opts.target.platform == PLATFORM_APPLE)
{
/* On Mac, change -s into -Wl,-x. ld's -s switch
* is deprecated, and it doesn't work on Tiger with
@ -2093,6 +1952,7 @@ int main(int argc, char **argv)
}
}
if (opts.force_pointer_size) set_target_ptr_size( &opts.target, opts.force_pointer_size );
if (opts.processor == proc_cpp) linking = 0;
if (linking == -1) error("Static linking is not supported\n");