widl: Pick up the target arch from a prefix on argv[0].

If the executable is named <target>-widl, try to pick up the target
arch implicitly from there.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Martin Storsjo 2021-05-17 00:22:42 +03:00 committed by Alexandre Julliard
parent 4766a01818
commit 57433856b4
1 changed files with 65 additions and 36 deletions

View File

@ -211,6 +211,31 @@ static const struct option long_options[] = {
{ NULL, 0, NULL, 0 }
};
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 },
{ "powerpc", CPU_POWERPC },
{ "powerpc64", CPU_POWERPC64 },
{ "powerpc64le", CPU_POWERPC64 },
{ "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)
@ -274,51 +299,54 @@ 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;
if ((p = strrchr(argv0, '/')) != NULL)
argv0 = p + 1;
if ((p = strrchr(argv0, '\\')) != NULL)
argv0 = p + 1;
name = xstrdup( 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 )
{
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 },
{ "powerpc", CPU_POWERPC },
{ "powerpc64", CPU_POWERPC64 },
{ "powerpc64le", CPU_POWERPC64 },
{ "arm", CPU_ARM },
{ "armv5", CPU_ARM },
{ "armv6", CPU_ARM },
{ "armv7", CPU_ARM },
{ "armv7a", CPU_ARM },
{ "arm64", CPU_ARM64 },
{ "aarch64", CPU_ARM64 },
};
unsigned int i;
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;
for (i = 0; i < ARRAY_SIZE( cpu_names ); i++)
{
if (!strcmp( cpu_names[i].name, spec ))
{
target_cpu = cpu_names[i].cpu;
free( spec );
return;
}
}
error( "Unrecognized CPU '%s'\n", spec );
set_cpu( spec, 1 );
free( spec );
}
/* clean things up when aborting on a signal */
@ -607,6 +635,7 @@ int main(int argc,char *argv[])
signal( SIGHUP, exit_on_signal );
#endif
init_argv0_dir( argv[0] );
init_argv0_target( argv[0] );
now = time(NULL);