# This file is a shell script that supplies the information necessary
# to tailor a template configure script into the configure script
# appropriate for this directory.  For more information, check any
# existing configure script.

configdirs="doc"
srctrigger=libbfd.c
srcname="BFD"
target_dependent=true
host64=false
target64=false
want64=false

# per-host:

. ${srcdir}/configure.host

# Set up to make a link between the host's include file and "sysdep.h".
files="hosts/${my_host}.h"
links="sysdep.h"

if [ ! -f ${srcdir}/${files} ] ; then
	files=../bfd/hosts/std-host.h
	echo "[${srcname} has no specific support for host ${host} -- using std-host]"
fi

host_makefile_frag=
if [ -f ${srcdir}/config/${my_host}.mh ] ; then
	host_makefile_frag=config/${my_host}.mh
fi

# per-target:

# Canonicalize the secondary target names.
if [ -n "$with_targets" ]; then
    for targ in `echo $with_targets | sed 's/,/ /g'`
    do
	result=`$configsub $targ 2>/dev/null`
	if [ -n "$result" ]; then
	    canon_targets="$canon_targets $result"
	else
	    # Allow targets that config.sub doesn't recognize, like "all".
	    canon_targets="$canon_targets $targ"
	fi
    done
fi

all_targets=false

for targ in $target $canon_targets
do
    bfd_target=`$srcdir/config.bfd $targ`

    if [ "x$bfd_target" = "xall" ]; then
        all_targets=true
    else
	if [ ! -f ${srcdir}/config/${bfd_target}.mt ] ; then
	    echo '***' No file ${srcdir}/config/${bfd_target}.mt 1>&2
	    echo '***' BFD does not support target ${bfd_target} 1>&2
	    echo '***' Look in bfd/config.bfd for supported targets 1>&2
	    exit 1
	fi

	if [ "x$targ" = "x$target" ]; then
	    target_makefile_frag=${srcdir}/config/${bfd_target}.mt
	else
	    target_extra_frags="$target_extra_frags ${srcdir}/config/${bfd_target}.mt"
	fi
    fi
done

# We don't do any links based on the target system, just makefile config.

# post-target:

rm -f Makefile.tmp Makefile.2
mv Makefile Makefile.tmp

case ${with_64_bit_bfd} in
  yes)		want64=true  ;;
  no | "")	want64=false ;;
  *)
    echo "*** bad value \"${with_64_bit_bfd}\" for 64-bit-bfd flag; ignored" 1>&2
    ;;
esac

# This processing still needs to be done if we're to decide properly whether
# 64-bit support needs to be compiled in.  Currently, it will be included if
# the default or any other explicitly requested target requires it; it
# will not be included on a 32-bit host if no 64-bit target is requested, and
# no "--with-64-bit-bfd" option is given, even if "--with-targets=all" is
# used.

# The default vector in the primary target.
DEFAULT_VECTOR=`sed -n '
s/DEFAULT_VECTOR[ 	]*=[ 	]*\([^ 	]*\)/\1/p
' $target_makefile_frag`

allfrags="$target_makefile_frag $target_extra_frags"

# The default and selected vectors in all the configured targets.
SELECT_VECS=`sed -n '
s/DEFAULT_VECTOR[ 	]*=[ 	]*\([^ 	]*\)/\1/p
s/SELECT_VECS[ 	]*=[ 	]*\([^ 	]*\)/\1/p
' $allfrags`
# uniq the list.
f=""
for i in $SELECT_VECS ; do
    case " $f " in
    *" $i "*) ;;
    *) f="$f $i" ;;
    esac
done
SELECT_VECS="$f"

# The architectures in all the configured targets.
SELECT_ARCHITECTURES=`sed -n '
s/SELECT_ARCHITECTURES[ 	]*=[ 	]*//p
' $allfrags`
# uniq the list.
f=""
for i in $SELECT_ARCHITECTURES ; do
    case " $f " in
    *" $i "*) ;;
    *) f="$f $i" ;;
    esac
done
SELECT_ARCHITECTURES="$f"

# Target backend .o files.
tb=

for vec in $SELECT_VECS
do
    case "$vec" in
    # This list is alphabetized to make it easy to compare
    # with the two vector lists in targets.c.
    a29kcoff_big_vec)		tb="$tb coff-a29k.o" ;;
    a_out_adobe_vec)		tb="$tb aout-adobe.o aout32.o stab-syms.o" ;;
    aout_mips_big_vec)		tb="$tb mipsbsd.o aout32.o stab-syms.o" ;;
    aout_mips_little_vec)	tb="$tb mipsbsd.o aout32.o stab-syms.o" ;;
    apollocoff_vec)		tb="$tb coff-apollo.o" ;;
    b_out_vec_big_host)		tb="$tb bout.o aout32.o stab-syms.o" ;;
    b_out_vec_little_host)	tb="$tb bout.o aout32.o stab-syms.o" ;;
    bfd_elf32_big_generic_vec) 	tb="$tb elf32-gen.o elf32.o elf.o" ;;
    bfd_elf32_bigmips_vec) 	tb="$tb elf32-mips.o elf32.o elf.o" ;;
    bfd_elf32_hppa_vec)		tb="$tb elf32-hppa.o elf32.o elf.o" ;;
    bfd_elf32_i386_vec)		tb="$tb elf32-i386.o elf32.o elf.o" ;;
    bfd_elf32_i860_vec)		tb="$tb elf32-i860.o elf32.o elf.o" ;;
    bfd_elf32_little_generic_vec) tb="$tb elf32-gen.o elf32.o elf.o" ;;
    bfd_elf32_littlemips_vec) 	tb="$tb elf32-mips.o elf32.o elf.o" ;;
    bfd_elf32_m68k_vec)		tb="$tb elf32-m68k.o elf32.o elf.o" ;;
    bfd_elf32_m88k_vec)		tb="$tb elf32-m88k.o elf32.o elf.o" ;;
    bfd_elf32_sparc_vec)	tb="$tb elf32-sparc.o elf32.o elf.o" ;;
    bfd_elf64_big_generic_vec) 	tb="$tb elf64-gen.o elf64.o elf.o"
				target64=true ;;
    bfd_elf64_little_generic_vec) tb="$tb elf64-gen.o elf64.o elf.o"
				target64=true ;;
    demo_64_vec)		tb="$tb demo64.o aout64.o stab-syms.o"
				target64=true ;;
    ecoff_big_vec)		tb="$tb coff-mips.o" ;;
    ecoff_little_vec)		tb="$tb coff-mips.o" ;;
    ecoffalpha_little_vec)	tb="$tb coff-alpha.o"
				target64=true ;;
    h8300coff_vec)		tb="$tb coff-h8300.o reloc16.o" ;;
    h8500coff_vec)		tb="$tb coff-h8500.o reloc16.o" ;;
    host_aout_vec)		tb="$tb host-aout.o aout32.o stab-syms.o" ;;
    hp300bsd_vec)		tb="$tb hp300bsd.o aout32.o stab-syms.o" ;;
    hp300hpux_vec)		tb="$tb hp300hpux.o aout32.o stab-syms.o" ;;
    som_vec)			tb="$tb som.o" ;;
    i386aout_vec)		tb="$tb i386aout.o aout32.o stab-syms.o" ;;
    i386bsd_vec)		tb="$tb i386bsd.o aout32.o stab-syms.o" ;;
    netbsd386_vec)		tb="$tb netbsd386.o aout32.o stab-syms.o" ;;
    i386coff_vec)		tb="$tb coff-i386.o" ;;
    i386linux_vec)		tb="$tb i386linux.o aout32.o stab-syms.o" ;;
    i386lynx_aout_vec)		tb="$tb i386lynx.o lynx-core.o aout32.o stab-syms.o" ;;
    i386lynx_coff_vec)		tb="$tb cf-i386lynx.o lynx-core.o stab-syms.o" ;;
    i386mach3_vec)		tb="$tb i386mach3.o aout32.o stab-syms.o" ;;
    icoff_big_vec)		tb="$tb coff-i960.o" ;;
    icoff_little_vec)		tb="$tb coff-i960.o" ;;
    ieee_vec)			tb="$tb ieee.o" ;;
    m68kcoff_vec)		tb="$tb coff-m68k.o" ;;
    m68kcoffun_vec)		tb="$tb coff-u68k.o coff-m68k.o" ;;
    m68klynx_aout_vec)		tb="$tb m68klynx.o lynx-core.o aout32.o stab-syms.o" ;;
    m68klynx_coff_vec)		tb="$tb cf-m68klynx.o coff-m68k.o lynx-core.o stab-syms.o" ;;
    m88kbcs_vec)		tb="$tb coff-m88k.o" ;;
    newsos3_vec)		tb="$tb newsos3.o aout32.o stab-syms.o" ;;
    nlm32_i386_vec)		tb="$tb nlm32-i386.o nlm32.o nlm.o" ;;
    nlm32_sparc_vec)		tb="$tb nlm32-sparc.o nlm32.o nlm.o" ;;
    nlm32_alpha_vec)		tb="$tb nlm32-alpha.o nlm32.o nlm.o"
				target64=true ;;
    rs6000coff_vec)		tb="$tb coff-rs6000.o" ;;
    shcoff_vec)			tb="$tb coff-sh.o reloc16.o" ;;
    sparclynx_aout_vec)		tb="$tb sparclynx.o lynx-core.o aout32.o stab-syms.o" ;;
    sparclynx_coff_vec)		tb="$tb cf-sparclynx.o lynx-core.o stab-syms.o" ;;
    sparccoff_vec)		tb="$tb coff-sparc.o" ;;
    sunos_big_vec)		tb="$tb sunos.o aout32.o stab-syms.o" ;;
    tekhex_vec)			tb="$tb tekhex.o" ;;
    we32kcoff_vec)		tb="$tb coff-we32k.o" ;;
    z8kcoff_vec)		tb="$tb coff-z8k.o reloc16.o" ;;

    srec_vec)			tb="$tb srec.o" ;;
    symbolsrec_vec)		tb="$tb srec.o" ;;

    "")			;;
    *) echo "*** unknown target vector $vec" 1>&2; exit 1 ;;
    esac
done

# Target architecture .o files.
ta=`echo $SELECT_ARCHITECTURES | sed -e s/bfd_/cpu-/g -e s/_arch/.o/g`

# Weed out duplicate .o files.
f=""
for i in $tb ; do
    case " $f " in
    *" $i "*) ;;
    *) f="$f $i" ;;
    esac
done
tb="$f"

f=""
for i in $ta ; do
    case " $f " in
    *" $i "*) ;;
    *) f="$f $i" ;;
    esac
done
ta="$f"

bfd_backends="$tb"
bfd_machines="$ta"

if [ x${all_targets} = xtrue ]; then
  bfd_backends="${bfd_backends}"' $(ALL_BACKENDS)'
  bfd_machines="${bfd_machines}"' $(ALL_MACHINES)'
else	# all_targets is true
  # Only set these if they will be nonempty, for the clever echo.
  test -n "$SELECT_VECS" &&
    selvecs=`echo $SELECT_VECS | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
  test -n "SELECT_ARCHITECTURES" &&
    selarchs=`echo $SELECT_ARCHITECTURES | sed -e 's/ \(.\)/,\1/g'`
fi	# all_targets is true

case ${host64}-${target64}-${want64} in
  *true*)
    wordsize=64
    all_backends='$(BFD64_BACKENDS) $(BFD32_BACKENDS)'
    ;;
  false-false-false)
    wordsize=32
    all_backends='$(BFD32_BACKENDS)'
    ;;
esac

echo WORDSIZE=${wordsize}		>> Makefile.2
echo ALL_BACKENDS=${all_backends}	>> Makefile.2
echo BFD_BACKENDS=${bfd_backends}	>> Makefile.2
echo BFD_MACHINES=${bfd_machines}	>> Makefile.2

test -n "$DEFAULT_VECTOR" && defvec="$DEFAULT_VECTOR"

echo "TDEFAULTS = \
${defvec+-DDEFAULT_VECTOR=$defvec} \
${selvecs+-DSELECT_VECS='$selvecs'} \
${selarchs+-DSELECT_ARCHITECTURES='$selarchs'}" \
  >> Makefile.2

cat Makefile.tmp >> Makefile.2
rm -f Makefile.tmp
mv Makefile.2 Makefile
