First cut at handling multiple emulation modes for some MIPS targets.
[binutils-gdb.git] / gas / configure
index e3fac7b15daaa30054a660e81ae5179284ce7a1a..c9d0fa29b8abeb168dc65d177e36112bd99f5221 100755 (executable)
@@ -13,6 +13,8 @@ ac_default_prefix=/usr/local
 # Any additions from configure.in:
 ac_help="$ac_help
     bfd-assembler      use BFD back end for writing object files"
+ac_help="$ac_help
+    targets            alternative target configurations besides the primary"
 
 # Initialize some variables set by options.
 # The variables have the same names as the options, with
@@ -399,7 +401,6 @@ else
   ac_n= ac_c='\c' ac_t=
 fi
 
-bfd_gas=no
 user_bfd_gas=
 # Check whether --enable-bfd-assembler or --disable-bfd-assembler was given.
 enableval="$enable_bfd_assembler"
@@ -410,6 +411,16 @@ if test -n "$enableval"; then
   *)   { echo "configure: error: bad value ${enableval} given for bfd-assembler option" 1>&2; exit 1; } ;;
 esac
 fi
+# Check whether --enable-targets or --disable-targets was given.
+enableval="$enable_targets"
+if test -n "$enableval"; then
+  case "${enableval}" in
+  yes | "") { echo "configure: error: enable-targets option must specify target names or 'all'" 1>&2; exit 1; }
+           ;;
+  no)      enable_targets= ;;
+  *)       enable_targets=$enableval ;;
+esac
+fi
 
 # Generate a header file -- gets more post-processing by Makefile later.
 
@@ -537,7 +548,7 @@ test "$program_suffix" != NONE &&
 test "$program_transform_name" = "" && program_transform_name="s,x,x,"
 
 
-emulation=generic
+te_file=generic
 
 # assign cpu type
 
@@ -551,8 +562,7 @@ case ${target_cpu} in
   m8*)         cpu_type=m88k ;;
   mips*el)     cpu_type=mips endian=little;;
   mips*)       cpu_type=mips endian=big ;;
-  powerpcle*)  cpu_type=ppc endian=little;;
-  powerpc*)    cpu_type=ppc endian=big;;
+  powerpc*)    cpu_type=ppc ;;
   rs6000*)     cpu_type=ppc ;;
   sparc64)     cpu_type=sparc obj_format=elf
                cat >> confdefs.h <<\EOF
@@ -574,166 +584,283 @@ esac
 
 
 gas_target=${cpu_type}
-generic_target=${cpu_type}-${target_vendor}-${target_os}
-dev=no
+this_target=${generic_target}
+
+canon_targets=""
+if test -n "$enable_targets" ; then
+  for t in `echo $enable_targets | sed 's/,/ /g'`; do
+    result=`$ac_config_sub $t 2>/dev/null`
+    if test -n "$result" ; then
+      canon_targets="$canon_targets $result"
+#    else
+#      # Permit "all", etc.  We don't support it yet though.
+#      canon_targets="$canon_targets $t"
+    fi
+  done
+  _gas_uniq_list="$canon_targets"
+_gas_uniq_newlist=""
+for _gas_uniq_i in _gas_uniq_dummy $_gas_uniq_list ; do
+  case $_gas_uniq_i in
+  _gas_uniq_dummy) ;;
+  *) case " $_gas_uniq_newlist " in
+       *" $_gas_uniq_i "*) ;;
+       *) _gas_uniq_newlist="$_gas_uniq_newlist $_gas_uniq_i" ;;
+     esac ;;
+  esac
+done
+canon_targets=$_gas_uniq_newlist
+
+fi
+
+emulations=""
+
+for this_target in $target $canon_targets ; do
+
+    eval `echo $this_target | sed 's/^\(.*\)-\(.*\)-\(.*\)$/cpu=\1 vendor=\2 os=\3/'`
+
+    # check for architecture variants
+    case ${cpu} in
+      hppa*)           cpu_type=hppa ;;
+      i[45]86)         cpu_type=i386 ;;
+      m680[012346]0)   cpu_type=m68k ;;
+      m68008)          cpu_type=m68k ;;
+      m683??)          cpu_type=m68k ;;
+      m8*)             cpu_type=m88k ;;
+      mips*el)         cpu_type=mips endian=little;;
+      mips*)           cpu_type=mips endian=big ;;
+      powerpcle*)      cpu_type=ppc endian=little ;;
+      powerpc*)                cpu_type=ppc endian=big ;;
+      rs6000*)         cpu_type=ppc ;;
+      sparc64)         cpu_type=sparc obj_format=elf want_sparcv9=true ;;
+      sparclite*)      cpu_type=sparc ;;
+      *)               cpu_type=${target_cpu} ;;
+    esac
+
+    if test ${this_target} = $target ; then
+      target_cpu_type=${cpu_type}
+    elif test ${target_cpu_type} != ${cpu_type} ; then
+      continue
+    fi
+
+    targ=${cpu_type}
+    generic_target=${cpu_type}-$vendor-$os
+    dev=no
+    bfd_gas=no
+    em=generic
 
-# assign object format
-case ${generic_target} in
-  a29k-amd-udi)                obj_format=coff gas_target=ebmon29k ;;
-  a29k-amd-ebmon)      obj_format=coff gas_target=ebmon29k ;;
-  a29k-*-vxworks*)      obj_format=coff ;;
+    # assign object format
+    case ${generic_target} in
+      a29k-amd-udi)         fmt=coff targ=ebmon29k ;;
+      a29k-amd-ebmon)       fmt=coff targ=ebmon29k ;;
+      a29k-*-vxworks*)      fmt=coff ;;
 
-  alpha-*-netware*)    obj_format=ecoff ;;
-  alpha-*-osf*)                obj_format=ecoff ;;
+      alpha-*-netware*)     fmt=ecoff ;;
+      alpha-*-osf*)         fmt=ecoff ;;
 
 # start-sanitize-arc
-  arc-*-elf*)          obj_format=elf bfd_gas=yes ;;
+      arc-*-elf*)           fmt=elf bfd_gas=yes ;;
 # end-sanitize-arc
 
-  arm-*-riscix*)       obj_format=aout ;;
-
-  hppa-*-*elf*)                obj_format=elf emulation=hppa ;;
-  hppa-*-lites*)       obj_format=elf emulation=hppa ;;
-  hppa-*-osf*)         obj_format=som emulation=hppa ;;
-  hppa-*-hpux*)                obj_format=som emulation=hppa ;;
-  hppa-*-bsd*)         obj_format=som emulation=hppa ;;
-  hppa-*-hiux*)                obj_format=som emulation=hppa ;;
-
-  h8300-*-coff)                obj_format=coff ;;
-
-  i386-ibm-aix*)       obj_format=coff gas_target=i386coff
-                        emulation=i386aix ;;
-  i386-*-bsd*)         obj_format=aout emulation=386bsd ;;
-  i386-*-netbsd0.8)    obj_format=aout emulation=386bsd ;;
-  i386-*-netbsd*)      obj_format=aout emulation=nbsd bfd_gas=yes;;
-  i386-*-linux*aout*)  obj_format=aout  emulation=linux ;;
-  i386-*-linux*coff*)  obj_format=coff emulation=linux
-                        gas_target=i386coff ;;
-  i386-*-linux*)       obj_format=elf emulation=linux ;;
-  i386-*-lynxos*)      obj_format=coff gas_target=i386coff
-                        emulation=lynx ;;
-  i386-*-sysv4* | i386-*-solaris* | i386-*-elf)
-                       obj_format=elf ;;
-  i386-*-coff | i386-*-sysv* | i386-*-sco* | i386-*-isc*)
-                       obj_format=coff gas_target=i386coff ;;
-  i386-*-vsta)         obj_format=aout ;;
-  i386-*-go32)         obj_format=coff gas_target=i386coff ;;
-  i386-*-gnu*elf*)     obj_format=elf ;;
-  i386-*-mach* | i386-*-gnu*)
-                       obj_format=aout emulation=mach bfd_gas=yes ;;
-  i386-*-msdos*)       obj_format=aout ;;
-
-  i960-*-bout)         obj_format=bout ;;
-  i960-*-coff)         obj_format=coff emulation=ic960 gas_target=ic960coff ;;
-  i960-*-nindy*)       obj_format=bout ;;
-  i960-*-vxworks4*)    obj_format=bout ;;
-  i960-*-vxworks5.0)   obj_format=bout ;;
-  i960-*-vxworks5.*)   obj_format=coff emulation=ic960 gas_target=ic960coff ;;
-  i960-*-vxworks*)     obj_format=bout ;;
-
-  m68k-*-vxworks* | m68k-ericsson-ose | m68k-*-sunos*)
-                       obj_format=aout emulation=sun3 ;;
-  m68k-motorola-sysv)  obj_format=coff gas_target=m68kcoff emulation=delta ;;
-  m68k-bull-sysv3*)    obj_format=coff gas_target=m68kcoff emulation=dpx2 ;;
-  m68k-apollo-*)       obj_format=coff gas_target=apollo emulation=apollo ;;
-  m68k-*-coff | m68k-*-sysv*)
-                       obj_format=coff gas_target=m68kcoff ;;
-  m68k-*-elf)          obj_format=elf ;;
-  m68k-*-hpux*)                obj_format=hp300 emulation=hp300 ;;
-  m68k-*-lynxos*)      obj_format=coff gas_target=m68kcoff
-                        emulation=lynx ;;
-  m68k-*-netbsd*)      obj_format=aout emulation=nbsd bfd_gas=yes ;;
-
-  m88k-*-coff*)                obj_format=coff gas_target=m88kcoff ;;
-
-  # don't change emulation like *-*-bsd does
-  mips-dec-bsd*)       obj_format=aout gas_target=mips-lit ;;
-  mips-sony-bsd*)      obj_format=ecoff gas_target=mips-big ;;
-  mips-*-bsd*)         { echo "configure: error: Unknown vendor for mips-bsd configuration." 1>&2; exit 1; } ;;
-  mips-*-ultrix*)      obj_format=ecoff gas_target=mips-lit ;;
-  mips-*-ecoff*)       obj_format=ecoff 
-                       case "$endian" in
-                       big) gas_target=mips-big ;;
-                       *)   gas_target=mips-lit ;;
-                       esac
-                       ;;
-  mips-*-ecoff*)       obj_format=ecoff gas_target=mips-big ;;
-  mips-*-gnu*)         obj_format=aout
-                       case "$endian" in
-                       big) gas_target=mips-big ;;
-                       *)   gas_target=mips-lit ;;
-                       esac
-                       ;;
-  mips-*-irix5*)       obj_format=elf gas_target=mips-big ;;
-  mips-*-irix*)                obj_format=ecoff gas_target=mips-big ;;
-  mips-*-riscos*)      obj_format=ecoff gas_target=mips-big ;;
-  mips-*-sysv*)                obj_format=ecoff gas_target=mips-big ;;
-  mips-*-elf*)         obj_format=elf 
-                       case "$endian" in
-                       big) gas_target=mips-big ;;
-                       *)   gas_target=mips-lit ;;
-                       esac
-                       ;;
-  ppc-*-aix*)          obj_format=coff ;;
-  ppc-*-elf* | ppc-*-eabi* | ppc-*-sysv4*)
-                       obj_format=elf
-                       case "$endian" in
-                       big) gas_target=ppc-big ;;
-                       *)   gas_target=ppc-lit ;;
-                       esac
-                       ;;
-  ppc-*-netware*)      obj_format=elf emulation=ppcnw ;;
-
-  sh-*-coff)           obj_format=coff ;;
+      arm-*-riscix*)        fmt=aout ;;
+
+      hppa-*-*elf*)         fmt=elf em=hppa ;;
+      hppa-*-lites*)        fmt=elf em=hppa ;;
+      hppa-*-osf*)          fmt=som em=hppa ;;
+      hppa-*-hpux*)         fmt=som em=hppa ;;
+      hppa-*-bsd*)          fmt=som em=hppa ;;
+      hppa-*-hiux*)         fmt=som em=hppa ;;
+
+      h8300-*-coff)         fmt=coff ;;
+
+      i386-ibm-aix*)        fmt=coff targ=i386coff
+                            em=i386aix ;;
+      i386-*-bsd*)          fmt=aout em=386bsd ;;
+      i386-*-netbsd0.8)     fmt=aout em=386bsd ;;
+      i386-*-netbsd*)       fmt=aout em=nbsd bfd_gas=yes;;
+      i386-*-linux*aout*)   fmt=aout  em=linux ;;
+      i386-*-linux*coff*)   fmt=coff em=linux
+                            targ=i386coff ;;
+      i386-*-linux*)        fmt=elf em=linux ;;
+      i386-*-lynxos*)       fmt=coff targ=i386coff
+                            em=lynx ;;
+      i386-*-sysv4* | i386-*-solaris* | i386-*-elf)
+                           fmt=elf ;;
+      i386-*-coff | i386-*-sysv* | i386-*-sco* | i386-*-isc*)
+                           fmt=coff targ=i386coff ;;
+      i386-*-vsta)          fmt=aout ;;
+      i386-*-go32)          fmt=coff targ=i386coff ;;
+      i386-*-gnu*elf*)      fmt=elf ;;
+      i386-*-mach* | i386-*-gnu*)
+                           fmt=aout em=mach bfd_gas=yes ;;
+      i386-*-msdos*)        fmt=aout ;;
+
+      i960-*-bout)          fmt=bout ;;
+      i960-*-coff)          fmt=coff em=ic960 targ=ic960coff ;;
+      i960-*-nindy*)        fmt=bout ;;
+      i960-*-vxworks4*)     fmt=bout ;;
+      i960-*-vxworks5.0)    fmt=bout ;;
+      i960-*-vxworks5.*)    fmt=coff em=ic960 targ=ic960coff ;;
+      i960-*-vxworks*)      fmt=bout ;;
+
+      m68k-*-vxworks* | m68k-ericsson-ose | m68k-*-sunos*)
+                           fmt=aout em=sun3 ;;
+      m68k-motorola-sysv)   fmt=coff targ=m68kcoff em=delta ;;
+      m68k-bull-sysv3*)     fmt=coff targ=m68kcoff em=dpx2 ;;
+      m68k-apollo-*)        fmt=coff targ=apollo em=apollo ;;
+      m68k-*-coff | m68k-*-sysv*)
+                           fmt=coff targ=m68kcoff ;;
+      m68k-*-elf)           fmt=elf ;;
+      m68k-*-hpux*)         fmt=hp300 em=hp300 ;;
+      m68k-*-lynxos*)       fmt=coff targ=m68kcoff
+                            em=lynx ;;
+      m68k-*-netbsd*)       fmt=aout em=nbsd bfd_gas=yes ;;
+
+      m88k-*-coff*)         fmt=coff targ=m88kcoff ;;
+
+      # don't change em like *-*-bsd does
+      mips-dec-bsd*)        fmt=aout targ=mips-lit ;;
+      mips-sony-bsd*)       fmt=ecoff targ=mips-big ;;
+      mips-*-bsd*)          { echo "configure: error: Unknown vendor for mips-bsd configuration." 1>&2; exit 1; } ;;
+      mips-*-ultrix*)       fmt=ecoff targ=mips-lit ;;
+      mips-*-ecoff*)        fmt=ecoff 
+                           case "$endian" in
+                           big) targ=mips-big ;;
+                           *)   targ=mips-lit ;;
+                           esac
+                           ;;
+      mips-*-ecoff*)        fmt=ecoff targ=mips-big ;;
+      mips-*-gnu*)          fmt=aout
+                           case "$endian" in
+                           big) targ=mips-big ;;
+                           *)   targ=mips-lit ;;
+                           esac
+                           ;;
+      mips-*-irix5*)        fmt=elf targ=mips-big ;;
+      mips-*-irix*)         fmt=ecoff targ=mips-big ;;
+      mips-*-riscos*)       fmt=ecoff targ=mips-big ;;
+      mips-*-sysv*)         fmt=ecoff targ=mips-big ;;
+      mips-*-elf*)          fmt=elf 
+                           case "$endian" in
+                           big) targ=mips-big ;;
+                           *)   targ=mips-lit ;;
+                           esac
+                           ;;
+      ppc-*-aix*)           fmt=coff ;;
+      ppc-*-elf* | ppc-*-eabi* | ppc-*-sysv4*)
+                           fmt=elf
+                           case "$endian" in
+                           big)  targ=ppc-big ;;
+                           *)    targ=ppc-lit ;;
+                           esac
+                           ;;
+      ppc-*-netware*)       fmt=elf em=ppcnw ;;
+
+      sh-*-coff)            fmt=coff ;;
 
 # start-sanitize-rce
-  rce-*-aout)          obj_format=aout ;;
+      rce-*-aout)           fmt=aout ;;
 # end-sanitize-rce
 
-  ns32k-pc532-mach*)   obj_format=aout emulation=pc532mach ;;
-  ns32k-pc532-netbsd*) obj_format=aout emulation=nbsd532 ;;
-
-  sparc-*-sunos4*)     obj_format=aout emulation=sun3 ;;
-  sparc-*-aout | sparc*-*-vxworks)
-                       obj_format=aout ;;
-  sparc-*-coff)                obj_format=coff ;;
-  sparc-*-lynxos*)     obj_format=coff emulation=lynx ;;
-  sparc-fujitsu-none)  obj_format=aout ;;
-  sparc-*-elf | sparc*-*-solaris*)
-                       obj_format=elf ;;
-  sparc-*-netbsd*)     obj_format=aout emulation=nbsd bfd_gas=yes ;;
-
-  vax-*-bsd* | vax-*-ultrix*)
-                       obj_format=aout ;;
-  vax-*-vms)           obj_format=vms ;;
-
-  z8k-*-coff | z8k-*-sim)
-                       obj_format=coff ;;
-
-  w65-*-*)             obj_format=coff ;;
-
-  *-*-aout | *-*-scout)
-                       obj_format=aout ;;
-  *-*-nindy*)
-                       obj_format=bout ;;
-  *-*-bsd*)
-                       obj_format=aout emulation=sun3 ;;
-  *-*-generic)         obj_format=generic ;;
-  *-*-xray | *-*-hms)  obj_format=coff ;;
-  *-*-sim)             obj_format=coff ;;
-  *-*-elf | *-*-sysv4* | *-*-solaris*)
-                       echo "configure: warning: GAS support for ELF format is incomplete" 1>&2
-                       obj_format=elf dev=yes ;;
-  *-*-vxworks)         obj_format=aout ;;
-  *-*-netware)         obj_format=elf ;;
-esac
+      ns32k-pc532-mach*)    fmt=aout em=pc532mach ;;
+      ns32k-pc532-netbsd*)  fmt=aout em=nbsd532 ;;
+
+      sparc-*-sunos4*)      fmt=aout em=sun3 ;;
+      sparc-*-aout | sparc*-*-vxworks)
+                           fmt=aout ;;
+      sparc-*-coff)         fmt=coff ;;
+      sparc-*-lynxos*)      fmt=coff em=lynx ;;
+      sparc-fujitsu-none)   fmt=aout ;;
+      sparc-*-elf | sparc*-*-solaris*)
+                           fmt=elf ;;
+      sparc-*-netbsd*)      fmt=aout em=nbsd bfd_gas=yes ;;
+
+      vax-*-bsd* | vax-*-ultrix*)
+                           fmt=aout ;;
+      vax-*-vms)            fmt=vms ;;
+
+      z8k-*-coff | z8k-*-sim)
+                           fmt=coff ;;
+
+      w65-*-*)              fmt=coff ;;
+
+      *-*-aout | *-*-scout)
+                           fmt=aout ;;
+      *-*-nindy*)
+                           fmt=bout ;;
+      *-*-bsd*)
+                           fmt=aout em=sun3 ;;
+      *-*-generic)          fmt=generic ;;
+      *-*-xray | *-*-hms)   fmt=coff ;;
+      *-*-sim)              fmt=coff ;;
+      *-*-elf | *-*-sysv4* | *-*-solaris*)
+                           echo "configure: warning: GAS support for ELF format is incomplete." 1>&2
+                           fmt=elf dev=yes ;;
+      *-*-vxworks)          fmt=aout ;;
+      *-*-netware)          fmt=elf ;;
+    esac
+
+    case ${cpu_type}-${fmt} in
+      arm-*)   bfd_gas=yes ;;
+    # not yet
+    # i386-aout)       bfd_gas=preferred ;;
+      mips-*)  bfd_gas=yes ;;
+      ns32k-*) bfd_gas=yes ;;
+      ppc-*)   bfd_gas=yes ;;
+      sparc-*) bfd_gas=yes ;;
+      *-elf)   bfd_gas=yes ;;
+      *-ecoff) bfd_gas=yes ;;
+      *-som)   bfd_gas=yes ;;
+      *)               ;;
+    esac
+
+# See if we really can support this configuration with the emulation code.
+
+    if test $this_target = $target ; then
+      primary_bfd_gas=$bfd_gas
+      obj_format=$fmt
+      gas_target=$targ
+      te_file=$em
+
+      if test $bfd_gas = no ; then
+       # Can't support other configurations this way.
+       break
+      fi
+    elif test $bfd_gas = no ; then
+      # Can't support this configuration.
+      break
+    fi
+
+# From target name and format, produce a list of supported emulations.
+
+    case ${generic_target}-${fmt} in
+      mips-*-irix5*-*) emulation="mipsbelf mipslelf mipsbecoff mipslecoff" ;;
+      mips-*-*-ecoff)  case "$endian" in
+                       big)    emulation="mipsbecoff mipslecoff" ;;
+                       *)      emulation="mipslecoff mipsbecoff" ;;
+                       esac ;;
+      mips-*-*-elf)    case "$endian" in
+                       big)    emulation="mipsbelf mipslelf" ;;
+                       *)      emulation="mipslelf mipsbelf" ;;
+                       esac ;;
+    esac
+
+    emulations="$emulations $emulation"
+
+# Other random stuff.
+
+    test -n "$want_sparcv9" && cat >> confdefs.h <<\EOF
+#define sparcv9 1
+EOF
+
+
+done
 
 # Assign floating point type.  Most processors with FP support
 # IEEE FP.  On those that don't support FP at all, usually IEEE
 # is emulated.
 case ${target_cpu} in
   vax | tahoe )        atof=${target_cpu} ;;
-  *)                   atof=ieee ;;
+  *)           atof=ieee ;;
 esac
 
 case "${obj_format}" in
@@ -757,21 +884,7 @@ if test ! -r ${target_frag}; then
 fi
 
 
-case ${cpu_type}-${obj_format} in
-  arm-*)       bfd_gas=yes ;;
-# not yet
-# i386-aout)   bfd_gas=preferred ;;
-  mips-*)      bfd_gas=yes ;;
-  ns32k-*)     bfd_gas=yes ;;
-  ppc-*)       bfd_gas=yes ;;
-  sparc-*)     bfd_gas=yes ;;
-  *-elf)       bfd_gas=yes ;;
-  *-ecoff)     bfd_gas=yes ;;
-  *-som)       bfd_gas=yes ;;
-  *)           ;;
-esac
-
-case ${user_bfd_gas}-${bfd_gas} in
+case ${user_bfd_gas}-${primary_bfd_gas} in
   yes-yes | no-no)
     # We didn't override user's choice.
     ;;
@@ -779,20 +892,180 @@ case ${user_bfd_gas}-${bfd_gas} in
     echo "configure: warning: Use of BFD is required for ${target}; overriding config options." 1>&2
     ;;
   no-preferred)
-    bfd_gas=no
+    primary_bfd_gas=no
     ;;
   *-preferred)
-    bfd_gas=yes
+    primary_bfd_gas=yes
     ;;
   yes-*)
-    bfd_gas=yes
+    primary_bfd_gas=yes
     ;;
   -*)
     # User specified nothing.
     ;;
 esac
 
-case ${bfd_gas}-${cpu_type}-${obj_format} in
+# Some COFF configurations want these random other flags set.
+case ${obj_format} in
+  coff)
+    case ${target_cpu_type} in
+      i386) cat >> confdefs.h <<\EOF
+#define I386COFF 1
+EOF
+ ;;
+      m68k) cat >> confdefs.h <<\EOF
+#define M68KCOFF 1
+EOF
+ ;;
+      m88k) cat >> confdefs.h <<\EOF
+#define M88KCOFF 1
+EOF
+ ;;
+    esac
+    ;;
+esac
+
+# Getting this done right is going to be a bitch.  Each configuration specified
+# with --enable-targets=... should be checked for environment, format, cpu, and
+# bfd_gas setting.
+#
+# For each configuration, the necessary object file support code must be linked
+# in.  This might be only one, it might be up to four.  The necessary emulation
+# code needs to be provided, too.
+#
+# And then there's "--enable-targets=all"....
+#
+# For now, just always do it for MIPS ELF or ECOFF configurations.  Sigh.
+
+formats="${obj_format}"
+emfiles=""
+EMULATIONS=""
+_gas_uniq_list="$emulations"
+_gas_uniq_newlist=""
+for _gas_uniq_i in _gas_uniq_dummy $_gas_uniq_list ; do
+  case $_gas_uniq_i in
+  _gas_uniq_dummy) ;;
+  *) case " $_gas_uniq_newlist " in
+       *" $_gas_uniq_i "*) ;;
+       *) _gas_uniq_newlist="$_gas_uniq_newlist $_gas_uniq_i" ;;
+     esac ;;
+  esac
+done
+emulations=$_gas_uniq_newlist
+
+for em in . $emulations ; do
+  case $em in
+    .) continue ;;
+    mipsbelf | mipslelf)
+       fmt=elf   file=mipself ;;
+    mipsbecoff | mipslecoff)
+       fmt=ecoff file=mipsecoff ;;
+  esac
+  formats="$formats $fmt"
+  emfiles="$emfiles e-$file.o"
+  EMULATIONS="$EMULATIONS &$em,"
+done
+_gas_uniq_list="$formats"
+_gas_uniq_newlist=""
+for _gas_uniq_i in _gas_uniq_dummy $_gas_uniq_list ; do
+  case $_gas_uniq_i in
+  _gas_uniq_dummy) ;;
+  *) case " $_gas_uniq_newlist " in
+       *" $_gas_uniq_i "*) ;;
+       *) _gas_uniq_newlist="$_gas_uniq_newlist $_gas_uniq_i" ;;
+     esac ;;
+  esac
+done
+formats=$_gas_uniq_newlist
+
+_gas_uniq_list="$emfiles"
+_gas_uniq_newlist=""
+for _gas_uniq_i in _gas_uniq_dummy $_gas_uniq_list ; do
+  case $_gas_uniq_i in
+  _gas_uniq_dummy) ;;
+  *) case " $_gas_uniq_newlist " in
+       *" $_gas_uniq_i "*) ;;
+       *) _gas_uniq_newlist="$_gas_uniq_newlist $_gas_uniq_i" ;;
+     esac ;;
+  esac
+done
+emfiles=$_gas_uniq_newlist
+
+if test `set . $formats ; shift ; echo $#` -gt 1 ; then
+  for fmt in $formats ; do
+    case $fmt in
+      aout)    cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_AOUT 1
+EOF
+    ;;
+      bout)    cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_BOUT 1
+EOF
+    ;;
+      coff)    cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_COFF 1
+EOF
+    ;;
+      ecoff)   cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_ECOFF 1
+EOF
+   ;;
+      elf)     cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_ELF 1
+EOF
+     ;;
+      generic) cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_GENERIC 1
+EOF
+ ;;
+      hp300)   cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_HP300 1
+EOF
+   ;;
+      ieee)    cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_IEEE 1
+EOF
+    ;;
+      som)     cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_SOM 1
+EOF
+     ;;
+      vms)     cat >> confdefs.h <<\EOF
+#define OBJ_MAYBE_VMS 1
+EOF
+     ;;
+    esac
+    extra_objects="$extra_objects obj-$fmt.o"
+  done
+  obj_format=multi
+fi
+if test `set . $emfiles ; shift ; echo $#` -gt 0 ; then
+  te_file=multi
+  extra_objects="$extra_objects $emfiles"
+  DEFAULT_EMULATION=`set . $emulations ; echo $2`
+  cat >> confdefs.h <<\EOF
+#define USE_EMULATIONS 1
+EOF
+
+fi
+
+cat >> confdefs.h <<EOF
+#define EMULATIONS $EMULATIONS
+EOF
+
+cat >> confdefs.h <<EOF
+#define DEFAULT_EMULATION "$DEFAULT_EMULATION"
+EOF
+
+
+files="config/tc-${cpu_type}.c config/tc-${cpu_type}.h \
+       config/obj-${obj_format}.h config/obj-${obj_format}.c \
+       config/te-${te_file}.h config/atof-${atof}.c \
+       $extra_files"
+links="targ-cpu.c targ-cpu.h obj-format.h obj-format.c targ-env.h atof-targ.c \
+       $extra_links"
+
+case ${primary_bfd_gas}-${cpu_type}-${obj_format} in
   yes-*-coff)  need_bfd=yes ;;
   no-*-coff)   need_bfd=yes
                cat >> confdefs.h <<\EOF
@@ -815,8 +1088,7 @@ esac
 
 
 
-
-case "${bfd_gas}" in
+case "${primary_bfd_gas}" in
   yes) cat >> confdefs.h <<\EOF
 #define BFD_ASSEMBLER 1
 EOF
@@ -940,7 +1212,7 @@ else
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 944 "configure"
+#line 1216 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
@@ -954,7 +1226,7 @@ else
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 958 "configure"
+#line 1230 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
@@ -985,7 +1257,7 @@ if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 989 "configure"
+#line 1261 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
@@ -1037,7 +1309,7 @@ else
   ac_cv_c_cross=yes
 else
 cat > conftest.$ac_ext <<EOF
-#line 1041 "configure"
+#line 1313 "configure"
 #include "confdefs.h"
 main(){return(0);}
 EOF
@@ -1060,7 +1332,7 @@ if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1064 "configure"
+#line 1336 "configure"
 #include "confdefs.h"
 #include <alloca.h>
 int main() { return 0; }
@@ -1091,7 +1363,7 @@ if eval "test \"`echo '$''{'ac_cv_func_alloca'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1095 "configure"
+#line 1367 "configure"
 #include "confdefs.h"
 
 #ifdef __GNUC__
@@ -1149,7 +1421,7 @@ if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1153 "configure"
+#line 1425 "configure"
 #include "confdefs.h"
 #if defined(CRAY) && ! defined(CRAY2)
 webecray
@@ -1177,7 +1449,7 @@ if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1181 "configure"
+#line 1453 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1231,7 +1503,7 @@ else
   ac_cv_c_stack_direction=0
 else
 cat > conftest.$ac_ext <<EOF
-#line 1235 "configure"
+#line 1507 "configure"
 #include "confdefs.h"
 find_stack_direction ()
 {
@@ -1273,7 +1545,7 @@ else
   ac_cv_c_inline=no
 for ac_kw in inline __inline__ __inline; do
   cat > conftest.$ac_ext <<EOF
-#line 1277 "configure"
+#line 1549 "configure"
 #include "confdefs.h"
 
 int main() { return 0; }
@@ -1312,7 +1584,7 @@ if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1316 "configure"
+#line 1588 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1365,7 +1637,7 @@ if eval "test \"`echo '$''{'gas_cv_assert_ok'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1369 "configure"
+#line 1641 "configure"
 #include "confdefs.h"
 #include <assert.h>
 #include <stdio.h>
@@ -1422,7 +1694,7 @@ if eval "test \"`echo '$''{'gas_cv_decl_needed_malloc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1426 "configure"
+#line 1698 "configure"
 #include "confdefs.h"
 $gas_test_headers
 int main() { return 0; }
@@ -1458,7 +1730,7 @@ if eval "test \"`echo '$''{'gas_cv_decl_needed_free'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1462 "configure"
+#line 1734 "configure"
 #include "confdefs.h"
 $gas_test_headers
 int main() { return 0; }
@@ -1497,7 +1769,7 @@ if eval "test \"`echo '$''{'gas_cv_decl_needed_errno'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1501 "configure"
+#line 1773 "configure"
 #include "confdefs.h"
 
 #ifdef HAVE_ERRNO_H
@@ -1656,10 +1928,10 @@ s%@build_os@%$build_os%g
 s%@OPCODES_LIB@%$OPCODES_LIB%g
 /@target_frag@/r $target_frag
 s%@target_frag@%%g
+s%@extra_objects@%$extra_objects%g
 s%@cpu_type@%$cpu_type%g
 s%@obj_format@%$obj_format%g
 s%@atof@%$atof%g
-s%@emulation@%$emulation%g
 s%@BFDLIB@%$BFDLIB%g
 s%@ALL_OBJ_DEPS@%$ALL_OBJ_DEPS%g
 s%@CC@%$CC%g
@@ -1828,10 +2100,8 @@ fi; done
 EOF
 
 cat >> $CONFIG_STATUS <<EOF
-ac_sources="config/tc-${cpu_type}.c    config/tc-${cpu_type}.h \
-       config/obj-${obj_format}.h config/obj-${obj_format}.c \
-       config/te-${emulation}.h config/atof-${atof}.c"
-ac_dests="targ-cpu.c targ-cpu.h obj-format.h obj-format.c targ-env.h atof-targ.c"
+ac_sources="$files"
+ac_dests="$links"
 EOF
 
 cat >> $CONFIG_STATUS <<\EOF