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 --- tools/widl/widl.c | 99 ++++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 35 deletions(-)
diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 8da887ea636..9b140a47497 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -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); }
-/* set the target platform */ -static void set_target( const char *target ) +static void set_cpu( const char *cpu, int error_out ) { - static const struct + unsigned int i; + for (i = 0; i < ARRAY_SIZE( cpu_names ); i++) { - const char *name; - enum target_cpu cpu; - } cpu_names[] = + 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 om 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, '-'))) { - { "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 }, - }; + free( name ); + return; + } + *p = 0; + set_cpu( name, 0 ); + free( name ); +}
- unsigned int i; +/* 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; - 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);