main: deduce the cross-compilation triplet based on program name

feature/tap-sh
William Pitcock 2018-05-10 13:37:40 -05:00
parent db7845b4c7
commit 8aa662227c
1 changed files with 22 additions and 1 deletions

View File

@ -737,6 +737,27 @@ dump_personality(const pkgconf_cross_personality_t *p)
printf("\n"); printf("\n");
} }
static pkgconf_cross_personality_t *
deduce_personality(char *argv[])
{
char *workbuf = strdup(argv[0]), *i;
pkgconf_cross_personality_t *out = pkgconf_cross_personality_default(), *deduced;
i = strstr(workbuf, "-pkg");
if (i == NULL)
goto finish;
*i = 0;
deduced = pkgconf_cross_personality_find(workbuf);
if (deduced != NULL)
out = deduced;
finish:
free(workbuf);
return out;
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -834,7 +855,7 @@ main(int argc, char *argv[])
pkgconf_client_set_trace_handler(&pkg_client, error_handler, NULL); pkgconf_client_set_trace_handler(&pkg_client, error_handler, NULL);
} }
personality = pkgconf_cross_personality_default(); personality = deduce_personality(argv);
while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1) while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1)
{ {