Browse Source

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

William Pitcock 1 year ago
parent
commit
8aa662227c
1 changed files with 22 additions and 1 deletions
  1. 22
    1
      cli/main.c

+ 22
- 1
cli/main.c View File

@@ -737,6 +737,27 @@ dump_personality(const pkgconf_cross_personality_t *p)
737 737
 	printf("\n");
738 738
 }
739 739
 
740
+static pkgconf_cross_personality_t *
741
+deduce_personality(char *argv[])
742
+{
743
+	char *workbuf = strdup(argv[0]), *i;
744
+	pkgconf_cross_personality_t *out = pkgconf_cross_personality_default(), *deduced;
745
+
746
+	i = strstr(workbuf, "-pkg");
747
+	if (i == NULL)
748
+		goto finish;
749
+
750
+	*i = 0;
751
+
752
+	deduced = pkgconf_cross_personality_find(workbuf);
753
+	if (deduced != NULL)
754
+		out = deduced;
755
+
756
+finish:
757
+	free(workbuf);
758
+	return out;
759
+}
760
+
740 761
 int
741 762
 main(int argc, char *argv[])
742 763
 {
@@ -834,7 +855,7 @@ main(int argc, char *argv[])
834 855
 		pkgconf_client_set_trace_handler(&pkg_client, error_handler, NULL);
835 856
 	}
836 857
 
837
-	personality = pkgconf_cross_personality_default();
858
+	personality = deduce_personality(argv);
838 859
 
839 860
 	while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1)
840 861
 	{