diff options
Diffstat (limited to 'src/mkheader.c')
-rw-r--r-- | src/mkheader.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/mkheader.c b/src/mkheader.c index 9fe0695..3481771 100644 --- a/src/mkheader.c +++ b/src/mkheader.c @@ -23,7 +23,7 @@ #define LINESIZE 1024 static const char *host_os; -static const char *host_triplet; +static char *host_triplet; static char *srcdir; static const char *hdr_version; static const char *hdr_version_number; @@ -63,6 +63,40 @@ xstrdup (const char *string) } +/* 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. */ +static char * +canon_host_triplet (const char *triplet) +{ + struct { + const char *name; + const char *alias; + } tbl[] = { + {"i486-pc-linux-gnu", "i686-pc-linux-gnu" }, + {"i586-pc-linux-gnu" }, + + { NULL } + }; + int i; + const char *lastalias = NULL; + + for (i=0; tbl[i].name; 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); + } + } + return xstrdup (triplet); +} + + /* Parse the supplied config.h file and extract required info. Returns 0 on success. */ static int @@ -481,6 +515,7 @@ main (int argc, char **argv) const char *fname, *s; char *p1, *p2; const char *config_h; + const char *host_triplet_raw; if (argc) { @@ -496,12 +531,14 @@ main (int argc, char **argv) return 1; } host_os = argv[0]; - host_triplet = argv[1]; + host_triplet_raw = argv[1]; fname = argv[2]; config_h = argv[3]; hdr_version = argv[4]; hdr_version_number = argv[5]; + host_triplet = canon_host_triplet (host_triplet_raw); + srcdir = malloc (strlen (fname) + 2 + 1); if (!srcdir) { @@ -554,8 +591,12 @@ main (int argc, char **argv) if (!strcmp (p1, "configure_input")) { s = strrchr (fname, '/'); - printf ("Do not edit. Generated from %s for %s.", - s? s+1 : fname, host_triplet); + printf ("Do not edit. Generated from %s for:\n%*s", + s? s+1 : fname, (int)(p1 - line) + 13, ""); + if (!strcmp (host_triplet, host_triplet_raw)) + printf ("%s", host_triplet); + else + printf ("%s (%s)", host_triplet, host_triplet_raw); fputs (p2, stdout); } else if (!write_special (fname, lnr, p1)) @@ -593,5 +634,6 @@ main (int argc, char **argv) fclose (fp); + xfree (host_triplet); return 0; } |