--- libgpg-error-1.22/src/mkheader.c.old 2016-04-22 03:05:37.000000000 -0400 +++ libgpg-error-1.22/src/mkheader.c 2016-05-26 01:12:24.938041016 -0400 @@ -17,6 +17,7 @@ #include #include #include +#include #define PGM "mkheader" @@ -64,46 +65,64 @@ } -/* Return a malloced string with TRIPLET. If TRIPLET has an alias - return that instead. In general build-aux/config.sub should do the - aliasing but some returned triplets are anyway identical and thus we - use this function to map it to the canonical form. */ +/* Return a malloced string with TRIPLET. The TRIPLET should conform + * to the hostnames in the header file names in src/syscfg. Assume + * build-aux/config.sub correctly validates the names and try to map it + * to a header hostname. */ static char * canon_host_triplet (const char *triplet) { struct { - const char *name; - const char *alias; + const char *pattern; + const char *host; } tbl[] = { - {"i486-pc-linux-gnu", "i686-pc-linux-gnu" }, - {"i586-pc-linux-gnu" }, - {"i486-pc-gnu", "i686-pc-gnu"}, - {"i586-pc-gnu"}, - {"i486-pc-kfreebsd-gnu", "i686-pc-kfreebsd-gnu"}, - {"i586-pc-kfreebsd-gnu"}, - {"x86_64-pc-linux-gnuhardened1", "x86_64-pc-linux-gnu" }, - {"powerpc-unknown-linux-gnuspe", "powerpc-unknown-linux-gnu" }, + {"^aarch64.*apple.*", "aarch64-apple-darwin"}, + {"^aarch64.*", "aarch64-apple-darwin"}, + {"^alpha.*", "alpha-unknown-linux-gnu"}, + {"^arm.*apple.*", "arm-apple-darwin"}, + {"^arm.*android.*", "arm-unknown-linux-androideabi"}, + {"^arm.*gnueabihf.*", "arm-unknown-linux-gnueabihf"}, + {"^armv6.*musl.*", "armv6-unknown-linux-musleabihf"}, + {"^arm.*musl.*", "armv5-unknown-linux-musleabi"}, + {"^arm.*", "arm-unknown-linux-gnueabi"}, + {"^hppa.*", "hppa-unknown-linux-gnu"}, + {"^i[3-6]86.*freebsd.*", "i686-pc-kfreebsd-gnu"}, + {"^i[3-6]86.*linux.*", "i686-pc-linux-gnu"}, + {"^i[3-6]86.*", "i686-pc-gnu"}, + {"^m68.*", "m68k-unknown-linux-gnu"}, + {"^mingw.*", "mingw32"}, + {"^mips64el.*", "mips64el-unknown-linux-gnuabi64"}, + {"^mipsel.*", "mipsel-unknown-linux-gnu"}, + {"^mips.*", "mips-unknown-linux-gnu"}, + {"^nios2.*", "nios2-unknown-linux-gnu"}, + {"^or1k.*", "or1k-unknown-linux-gnu"}, + {"^powerpc64le.*", "powerpc64le-unknown-linux-gnu"}, + {"^powerpc64.*", "powerpc64-unknown-linux-gnu"}, + {"^powerpc.*", "powerpc-unknown-linux-gnu"}, + {"^s390.*", "s390x-ibm-linux-gnu"}, + {"^sh.*", "sh4-unknown-linux-gnu"}, + {"^sparc64.*", "sparc64-unknown-linux-gnu"}, + {"^sparc.*", "sparc-unknown-linux-gnu"}, + {"^x86_64.*freebsd.*", "x86_64-pc-kfreebsd-gnu"}, + {"^x86_64.*musl.*", "x86_64-pc-linux-musl"}, + {"^x86_64.*x32.*", "x86_64-pc-linux-gnux32"}, + {"^x86_64.*", "x86_64-pc-linux-gnu"}, { NULL } }; - int i; - const char *lastalias = NULL; + regex_t regtest; + const char *lasthost = NULL; - for (i=0; tbl[i].name; i++) + for (int i=0; tbl[i].pattern; i++) { - if (tbl[i].alias) - lastalias = tbl[i].alias; - if (!strcmp (tbl[i].name, triplet)) - { - if (!lastalias) - break; /* Ooops: first entry has no alias. */ - return xstrdup (lastalias); - } + lasthost = tbl[i].host; + if (regcomp(®test, tbl[i].pattern, REG_NOSUB) == 0) + if (regexec(®test, triplet, 0, NULL, 0) == 0) + return xstrdup (lasthost); } return xstrdup (triplet); } - /* Parse the supplied config.h file and extract required info. Returns 0 on success. */ static int