diff -Nuar binutils-2.11.93.0.2.orig/gas/config/tc-arm.c binutils-2.11.93.0.2/gas/config/tc-arm.c
--- binutils-2.11.93.0.2.orig/gas/config/tc-arm.c	Wed Dec 25 14:55:58 2002
+++ binutils-2.11.93.0.2/gas/config/tc-arm.c	Wed Dec 25 14:56:31 2002
@@ -150,6 +150,8 @@
 static int uses_apcs_float   = false;
 static int pic_code          = false;
 
+extern char * myname;
+
 /* Variables that we set while parsing command-line options.  Once all
    options have been read we re-process these values to set the real
    assembly flags.  */
@@ -10493,7 +10495,7 @@
 find_family_cpu (family_cpu)
 	char **family_cpu;
 {
-  char *p;
+  char *p, *ep, *tmp = 0;
   int len;
 
   p = getenv("CROSS_COMPILE");
@@ -10505,9 +10507,34 @@
       strcpy(*family_cpu, p);
       if ((*family_cpu)[len - 1] == '-')
         (*family_cpu)[len - 1] = '\0';
+    }
+  /* try to determine family_cpu using program name */
+  p = basename(myname);
+  ep = strrchr(p, '-');
+  if (ep && strchr(p, '_')) {
+      len = ep - p;
+      tmp = (char *) xmalloc(len + 1);
+      strncpy(tmp, p, len);
+      tmp[len] = '\0';
+  }
+
+  if (! *family_cpu && !tmp) {
+    /* No way to set family_cpu - error */
+      return 0;
+  }
+  if (tmp) {
+    if (*family_cpu) {
+      if (strcmp(tmp, *family_cpu)) {
+        /* CROSS_COMPILER value is inconsistent with program name */
+        return 0;
+      }
+      free(tmp);
       return 1;
     }
-  return 0;
+    *family_cpu = tmp;
+    setenv("CROSS_COMPILE", tmp, 0);
+    return 1;
+  }
 }
 				
 /* set_default_cpu
@@ -10517,7 +10544,7 @@
 void
 set_default_cpu ()
 {
-  char * family_cpu;
+  char * family_cpu = 0;
   int    i;
   char * cpu;
 
@@ -10529,7 +10556,7 @@
   };
 
   if (! find_family_cpu(&family_cpu))
-    as_fatal (_("The CROSS_COMPILE environment variable is not set"));
+    as_fatal (_("CROSS_COMPILE variable is not set or invalid"));
 
   if (!strncasecmp(family_cpu, "arm_", 4))
     {
diff -Nuar binutils-2.11.93.0.2.orig/gas/config/tc-mips.c binutils-2.11.93.0.2/gas/config/tc-mips.c
--- binutils-2.11.93.0.2.orig/gas/config/tc-mips.c	Wed Dec 25 14:55:58 2002
+++ binutils-2.11.93.0.2/gas/config/tc-mips.c	Wed Dec 25 15:10:39 2002
@@ -44,6 +44,8 @@
 #define DBG(x)
 #endif
 
+extern char * myname;
+
 #ifdef OBJ_MAYBE_ELF
 /* Clean up namespace so we can include obj-elf.h too.  */
 static int mips_output_flavor PARAMS ((void));
@@ -9748,7 +9750,7 @@
 void
 set_default_cpu ()
 {
-  char * family_cpu;
+  char * family_cpu = 0;
   int    i;
   char * cpu;
 
@@ -9760,7 +9762,7 @@
   };
 
   if (! find_family_cpu(&family_cpu))
-    as_fatal (_("The CROSS_COMPILE environment variable is not set"));
+    as_fatal (_("CROSS_COMPILE variable is not set or invalid"));
 
   if (!strncasecmp(family_cpu, "mips_", 5))
     {
@@ -9780,7 +9782,7 @@
 find_family_cpu (family_cpu)
       char **family_cpu;
 {
-  char *p;
+  char *p , *ep, *tmp = 0;
   int len;
 
   p = getenv("CROSS_COMPILE");
@@ -9792,9 +9794,35 @@
       strcpy(*family_cpu, p);
       if ((*family_cpu)[len - 1] == '-')
         (*family_cpu)[len - 1] = '\0';
+    }
+
+  /* try to determine family_cpu using program name */
+  p = basename(myname);
+  ep = strrchr(p, '-');
+  if (ep && strchr(p, '_')) {
+      len = ep - p;
+      tmp = (char *) xmalloc(len + 1);
+      strncpy(tmp, p, len);
+      tmp[len] = '\0';
+  }
+
+  if (! *family_cpu && !tmp) {
+    /* No way to set family_cpu - error */
+      return 0;
+  }
+  if (tmp) {
+    if (*family_cpu) {
+      if (strcmp(tmp, *family_cpu)) {
+        /* CROSS_COMPILER value is inconsistent with program name */
+        return 0;
+      }
+      free(tmp);
       return 1;
     }
-  return 0;
+    *family_cpu = tmp;
+    setenv("CROSS_COMPILE", tmp, 0);
+    return 1;
+  }
 }
 
 int
diff -Nuar binutils-2.11.93.0.2.orig/gas/config/tc-ppc.c binutils-2.11.93.0.2/gas/config/tc-ppc.c
--- binutils-2.11.93.0.2.orig/gas/config/tc-ppc.c	Wed Dec 25 14:55:58 2002
+++ binutils-2.11.93.0.2/gas/config/tc-ppc.c	Wed Dec 25 14:56:31 2002
@@ -44,6 +44,8 @@
 /* Whether or not, we've set target_big_endian.  */
 static int set_target_endian = 0;
 
+extern char *myname;
+
 /* Whether to use user friendly register names.  */
 #ifndef TARGET_REG_NAMES_P
 #ifdef TE_PE
@@ -815,7 +817,7 @@
 void
 set_default_cpu ()
 {
-  char * family_cpu;
+  char * family_cpu = 0;
   int    i;
   char * cpu;
 
@@ -832,7 +834,7 @@
   };
 
   if (! find_family_cpu(&family_cpu))
-    as_fatal (_("The CROSS_COMPILE environment variable is not set"));
+    as_fatal (_("CROSS_COMPILE variable is not set or invalid"));
 
   if (!strncasecmp(family_cpu, "ppc_", 4))
     {
@@ -852,7 +854,7 @@
 find_family_cpu (family_cpu)
       char **family_cpu;
 {
-  char *p;
+  char *p, *ep, *tmp = 0;
   int len;
 
   p = getenv("CROSS_COMPILE");
@@ -864,9 +866,35 @@
       strcpy(*family_cpu, p);
       if ((*family_cpu)[len - 1] == '-')
         (*family_cpu)[len - 1] = '\0';
+    }
+
+  /* try to determine family_cpu using program name */
+  p = basename(myname);
+  ep = strrchr(p, '-');
+  if (ep && strchr(p, '_')) {
+      len = ep - p;
+      tmp = (char *) xmalloc(len + 1);
+      strncpy(tmp, p, len);
+      tmp[len] = '\0';
+  }
+
+  if (! *family_cpu && !tmp) {
+    /* No way to set family_cpu - error */
+      return 0;
+  }
+  if (tmp) {
+    if (*family_cpu) {
+      if (strcmp(tmp, *family_cpu)) {
+        /* CROSS_COMPILER value is inconsistent with program name */
+        return 0;
+      }
+      free(tmp);
       return 1;
     }
-  return 0;
+    *family_cpu = tmp;
+    setenv("CROSS_COMPILE", tmp, 0);
+    return 1;
+  }
 }
 
 int
diff -Nuar binutils-2.11.93.0.2.orig/ld/ldmain.c binutils-2.11.93.0.2/ld/ldmain.c
--- binutils-2.11.93.0.2.orig/ld/ldmain.c	Wed Dec 25 14:55:58 2002
+++ binutils-2.11.93.0.2/ld/ldmain.c	Wed Dec 25 14:56:31 2002
@@ -188,7 +188,7 @@
   xmalloc_set_program_name (program_name);
 
   if (!find_family_cpu(&family_cpu)) {
-    einfo (_("%P%F: the CROSS_COMPILE environment variable is not set\n"));
+    einfo (_("%P%F: CROSS_COMPILE variable is not set or invalid\n"));
   }
   
   START_PROGRESS (program_name, 0);
@@ -1657,7 +1657,7 @@
 static int
 find_family_cpu(char **family_cpu)
 {
-  char *p;
+  char *p, *ep, *tmp = 0;
   int len;
 
   p = getenv("CROSS_COMPILE");
@@ -1669,9 +1669,35 @@
       strcpy(*family_cpu, p);
       if ((*family_cpu)[len - 1] == '-')
         (*family_cpu)[len - 1] = '\0';
+    }
+
+  /* try to determine family_cpu using program name */
+  p = basename(program_name);
+  ep = strrchr(p, '-');
+  if (ep && strchr(p, '_')) {
+      len = ep - p;
+      tmp = (char *) xmalloc(len + 1);
+      strncpy(tmp, p, len);
+      tmp[len] = '\0';
+  }
+
+  if (! *family_cpu && !tmp) {
+    /* No way to set family_cpu - error */
+      return 0;
+  }
+  if (tmp) {
+    if (*family_cpu) {
+      if (strcmp(tmp, *family_cpu)) {
+        /* CROSS_COMPILER value is inconsistent with program name */
+        return 0;
+      }
+      free(tmp);
       return 1;
     }
-  return 0;
+    *family_cpu = tmp;
+    setenv("CROSS_COMPILE", tmp, 0);
+    return 1;
+  }
 }
 
 static void
