[PATCH Libgpg-error 1/2] syscfg: Add support for versioned darwin triplets

Marvin Scholz epirat07 at gmail.com
Fri Jan 21 20:12:26 CET 2022


* src/mkheader.c (deversion_darwin_triplet): New.
(canon_host_triplet): Remove version from triplet before alias lookup
--

Darwin triples can have a version number in the os part, which would
previously just fail the build even though the triplet is supported.
---
 src/mkheader.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/mkheader.c b/src/mkheader.c
index 1d2ea20..f95e030 100644
--- a/src/mkheader.c
+++ b/src/mkheader.c
@@ -77,6 +77,45 @@ xstrdup (const char *string)
   return p;
 }
 
+/* Darwin host triplets can have the darwin version at the
+ * end, which is inconvenient for the header triplet and alias
+ * resolving as it would mean adding a huge amount of different
+ * triplets where only the version number varies and having to
+ * update the list whenever a new darwin version emerges,
+ * so instead this function returns a new triplet with the version
+ * number removed, if it's a darwin triplet. Else it returns NULL.
+ */
+static char *
+deversion_darwin_triplet (const char *triplet)
+{
+  size_t res_len;
+  char *res;
+  char *last_seq;
+
+  last_seq = strrchr (triplet, '-');
+  if (last_seq == NULL)
+    return NULL;
+
+  // Advance past the dash
+  last_seq++;
+  if (strncmp ("darwin", last_seq, 6) != 0)
+    return NULL;
+
+  // We have a darwin triplet, check if something version-like follows
+  last_seq += 6;
+  if (last_seq == NULL)
+    return NULL;
+  if (!(last_seq[0] >= '0' && last_seq[0] <= '9'))
+    return NULL;
+
+  // Finally, strip the version
+  res_len = last_seq - triplet;
+  res = xmalloc (res_len + 1);
+  memcpy (res, triplet, res_len);
+  res[res_len] = '\0';
+
+  return res;
+}
 
 /* Return a malloced string with TRIPLET.  If TRIPLET has an alias
  * return that instead.  In general build-aux/config.sub should do the
@@ -123,6 +162,11 @@ canon_host_triplet (const char *triplet, int no_vendor_hack, char **r_os)
   const char *s;
   char *p;
   char *result;
+  char *deversioned_triplet;
+
+  deversioned_triplet = deversion_darwin_triplet(triplet);
+  if (deversioned_triplet)
+    triplet = deversioned_triplet;
 
   for (i=0; tbl[i].name; i++)
     {
@@ -178,6 +222,7 @@ canon_host_triplet (const char *triplet, int no_vendor_hack, char **r_os)
             break;
           }
     }
+  xfree(deversioned_triplet);
 
   return result;
 }
-- 
2.34.1




More information about the Gnupg-devel mailing list