146283Sdfr# Configure fragment invoked in the post-target section for subdirs
246283Sdfr# wanting multilib support.
346283Sdfr#
4130803Smarcel# Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
5130803Smarcel#   Free Software Foundation, Inc.
6130803Smarcel#
7130803Smarcel# This file is free software; you can redistribute it and/or modify
8130803Smarcel# it under the terms of the GNU General Public License as published by
9130803Smarcel# the Free Software Foundation; either version 2 of the License, or
10130803Smarcel# (at your option) any later version.
11130803Smarcel#
12130803Smarcel# This program is distributed in the hope that it will be useful,
13130803Smarcel# but WITHOUT ANY WARRANTY; without even the implied warranty of
14130803Smarcel# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15130803Smarcel# GNU General Public License for more details.
16130803Smarcel#
17130803Smarcel# You should have received a copy of the GNU General Public License
18130803Smarcel# along with this program; if not, write to the Free Software
19130803Smarcel# Foundation, Inc., 59 Temple Place - Suite 330,
20130803Smarcel# Boston, MA 02111-1307, USA.
21130803Smarcel#
22130803Smarcel# As a special exception to the GNU General Public License, if you
23130803Smarcel# distribute this file as part of a program that contains a
24130803Smarcel# configuration script generated by Autoconf, you may include it under
25130803Smarcel# the same distribution terms that you use for the rest of that program.
26130803Smarcel#
27130803Smarcel# Please report bugs to <gcc-bugs@gnu.org>
28130803Smarcel# and send patches to <gcc-patches@gnu.org>.
29130803Smarcel
3046283Sdfr# It is advisable to support a few --enable/--disable options to let the
3146283Sdfr# user select which libraries s/he really wants.
3246283Sdfr#
3346283Sdfr# Subdirectories wishing to use multilib should put the following lines
3446283Sdfr# in the "post-target" section of configure.in.
3546283Sdfr#
3646283Sdfr# if [ "${srcdir}" = "." ] ; then
3746283Sdfr#   if [ "${with_target_subdir}" != "." ] ; then
3846283Sdfr#     . ${with_multisrctop}../../config-ml.in
3946283Sdfr#   else
4046283Sdfr#     . ${with_multisrctop}../config-ml.in
4146283Sdfr#   fi
4246283Sdfr# else
4346283Sdfr#   . ${srcdir}/../config-ml.in
4446283Sdfr# fi
4546283Sdfr#
4646283Sdfr#
4746283Sdfr# Things are complicated because 6 separate cases must be handled:
4846283Sdfr# 2 (native, cross) x 3 (absolute-path, relative-not-dot, dot) = 6.
4946283Sdfr#
5046283Sdfr# srcdir=. is special.  It must handle make programs that don't handle VPATH.
5146283Sdfr# To implement this, a symlink tree is built for each library and for each
5246283Sdfr# multilib subdir.
5346283Sdfr#
5446283Sdfr# The build tree is layed out as
5546283Sdfr#
5646283Sdfr# ./
5746283Sdfr#   newlib
5846283Sdfr#   m68020/
5946283Sdfr#          newlib
6046283Sdfr#          m68881/
6146283Sdfr#                 newlib
6246283Sdfr#
6346283Sdfr# The nice feature about this arrangement is that inter-library references
6446283Sdfr# in the build tree work without having to care where you are.  Note that
6546283Sdfr# inter-library references also work in the source tree because symlink trees
6646283Sdfr# are built when srcdir=.
6746283Sdfr#
6846283Sdfr# Unfortunately, trying to access the libraries in the build tree requires
6946283Sdfr# the user to manually choose which library to use as GCC won't be able to
7046283Sdfr# find the right one.  This is viewed as the lesser of two evils.
7146283Sdfr#
7246283Sdfr# Configure variables:
7346283Sdfr# ${with_target_subdir} = "." for native, or ${target_alias} for cross.
7446283Sdfr# Set by top level Makefile.
7546283Sdfr# ${with_multisrctop} = how many levels of multilibs there are in the source
7646283Sdfr# tree.  It exists to handle the case of configuring in the source tree:
7746283Sdfr# ${srcdir} is not constant.
7846283Sdfr# ${with_multisubdir} = name of multilib subdirectory (eg: m68020/m68881).
7946283Sdfr#
8046283Sdfr# Makefile variables:
8146283Sdfr# MULTISRCTOP = number of multilib levels in source tree (+1 if cross)
8246283Sdfr# (FIXME: note that this is different than ${with_multisrctop}.  Check out.).
8346283Sdfr# MULTIBUILDTOP = number of multilib levels in build tree
8446283Sdfr# MULTIDIRS = list of multilib subdirs (eg: m68000 m68020 ...)
8546283Sdfr# (only defined in each library's main Makefile).
8646283Sdfr# MULTISUBDIR = installed subdirectory name with leading '/' (eg: /m68000)
8746283Sdfr# (only defined in each multilib subdir).
8846283Sdfr
8946283Sdfr# FIXME: Multilib is currently disabled by default for everything other than
9046283Sdfr# newlib.  It is up to each target to turn on multilib support for the other
9146283Sdfr# libraries as desired.
9246283Sdfr
9346283Sdfr# Autoconf incoming variables:
9498944Sobrien# srcdir, host, ac_configure_args
9546283Sdfr#
9698944Sobrien# We *could* figure srcdir and host out, but we'd have to do work that
9746283Sdfr# our caller has already done to figure them out and requiring these two
9846283Sdfr# seems reasonable.
9998944Sobrien# Note that `host' in this case is GCC's `target'.  Target libraries are
10098944Sobrien# configured for a particular host.
10146283Sdfr
102130803SmarcelMakefile=${ac_file-Makefile}
103130803Smarcelml_config_shell=${CONFIG_SHELL-/bin/sh}
104130803Smarcelml_realsrcdir=${srcdir}
10546283Sdfr
10646283Sdfr# Scan all the arguments and set all the ones we need.
10746283Sdfr
10846283Sdfrml_verbose=--verbose
109130803Smarcelfor option in ${ac_configure_args}
11046283Sdfrdo
11146283Sdfr  case $option in
11246283Sdfr  --*) ;;
11346283Sdfr  -*) option=-$option ;;
11446283Sdfr  esac
11546283Sdfr
11646283Sdfr  case $option in
11746283Sdfr  --*=*)
11846283Sdfr	optarg=`echo $option | sed -e 's/^[^=]*=//'`
11946283Sdfr	;;
12046283Sdfr  esac
12146283Sdfr
12246283Sdfr  case $option in
12346283Sdfr  --disable-*)
12446283Sdfr	enableopt=`echo ${option} | sed 's:^--disable-:enable_:;s:-:_:g'`
12546283Sdfr	eval $enableopt=no
12646283Sdfr	;;
12746283Sdfr  --enable-*)
12846283Sdfr	case "$option" in
12946283Sdfr	*=*)	;;
13046283Sdfr	*)	optarg=yes ;;
13146283Sdfr	esac
13246283Sdfr	enableopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
13346283Sdfr	eval $enableopt="$optarg"
13446283Sdfr	;;
135130803Smarcel  --norecursion | --no-recursion)
13646283Sdfr	ml_norecursion=yes
13746283Sdfr	;;
13846283Sdfr  --silent | --sil* | --quiet | --q*)
13946283Sdfr	ml_verbose=--silent
14046283Sdfr	;;
14146283Sdfr  --verbose | --v | --verb*)
14246283Sdfr	ml_verbose=--verbose
14346283Sdfr	;;
14446283Sdfr  --with-*)
14546283Sdfr	case "$option" in
14646283Sdfr	*=*)	;;
14746283Sdfr	*)	optarg=yes ;;
14846283Sdfr	esac
14946283Sdfr	withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
15046283Sdfr	eval $withopt="$optarg"
15146283Sdfr	;;
15246283Sdfr  --without-*)
15346283Sdfr	withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g'`
15446283Sdfr	eval $withopt=no
15546283Sdfr	;;
15646283Sdfr  esac
15746283Sdfrdone
15846283Sdfr
15946283Sdfr# Only do this if --enable-multilib.
16046283Sdfrif [ "${enable_multilib}" = yes ]; then
16146283Sdfr
16246283Sdfr# Compute whether this is the library's top level directory
163130803Smarcel# (ie: not a multilib subdirectory, and not a subdirectory like newlib/src).
16446283Sdfr# ${with_multisubdir} tells us we're in the right branch, but we could be
16546283Sdfr# in a subdir of that.
16646283Sdfr# ??? The previous version could void this test by separating the process into
16746283Sdfr# two files: one that only the library's toplevel configure.in ran (to
16846283Sdfr# configure the multilib subdirs), and another that all configure.in's ran to
16946283Sdfr# update the Makefile.  It seemed reasonable to collapse all multilib support
17046283Sdfr# into one file, but it does leave us with having to perform this test.
17146283Sdfrml_toplevel_p=no
17246283Sdfrif [ -z "${with_multisubdir}" ]; then
17346283Sdfr  if [ "${srcdir}" = "." ]; then
17446283Sdfr    # Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
17546283Sdfr    # ${with_target_subdir} = "." for native, otherwise target alias.
17646283Sdfr    if [ "${with_target_subdir}" = "." ]; then
17746283Sdfr      if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
17846283Sdfr	ml_toplevel_p=yes
17946283Sdfr      fi
18046283Sdfr    else
18146283Sdfr      if [ -f ${ml_realsrcdir}/../../config-ml.in ]; then
18246283Sdfr	ml_toplevel_p=yes
18346283Sdfr      fi
18446283Sdfr    fi
18546283Sdfr  else
18646283Sdfr    # Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
18746283Sdfr    if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
18846283Sdfr      ml_toplevel_p=yes
18946283Sdfr    fi
19046283Sdfr  fi
19146283Sdfrfi
19246283Sdfr
19346283Sdfr# If this is the library's top level directory, set multidirs to the
19446283Sdfr# multilib subdirs to support.  This lives at the top because we need
19546283Sdfr# `multidirs' set right away.
19646283Sdfr
19746283Sdfrif [ "${ml_toplevel_p}" = yes ]; then
19846283Sdfr
19946283Sdfrmultidirs=
20046283Sdfrfor i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
20146283Sdfr  dir=`echo $i | sed -e 's/;.*$//'`
20246283Sdfr  if [ "${dir}" = "." ]; then
20346283Sdfr    true
20446283Sdfr  else
20546283Sdfr    if [ -z "${multidirs}" ]; then
20646283Sdfr      multidirs="${dir}"
20746283Sdfr    else
20846283Sdfr      multidirs="${multidirs} ${dir}"
20946283Sdfr    fi
21046283Sdfr  fi
21146283Sdfrdone
21246283Sdfr
21398944Sobrien# Target libraries are configured for the host they run on, so we check
21498944Sobrien# $host here, not $target.
21598944Sobrien
21698944Sobriencase "${host}" in
21746283Sdfrarc-*-elf*)
21846283Sdfr	if [ x$enable_biendian != xyes ]
21946283Sdfr	then
22046283Sdfr	  old_multidirs=${multidirs}
22146283Sdfr	  multidirs=""
22246283Sdfr	  for x in ${old_multidirs}; do
22346283Sdfr	    case "${x}" in
22446283Sdfr	      *be*) : ;;
22546283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
22646283Sdfr	    esac
22746283Sdfr	  done
22846283Sdfr	fi
22946283Sdfr	;;
23098944Sobrienarm-*-*)
23198944Sobrien	if [ x"$enable_fpu" = xno ]
23298944Sobrien	then
23398944Sobrien	  old_multidirs=${multidirs}
23498944Sobrien	  multidirs=""
23598944Sobrien	  for x in ${old_multidirs}; do
23698944Sobrien	    case "${x}" in
23798944Sobrien	      *fpu*) : ;;
23898944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
23998944Sobrien	    esac
24098944Sobrien	  done
24198944Sobrien	fi
24298944Sobrien	if [ x"$enable_26bit" = xno ]
24398944Sobrien	then
24498944Sobrien	  old_multidirs=${multidirs}
24598944Sobrien	  multidirs=""
24698944Sobrien	  for x in ${old_multidirs}; do
24798944Sobrien	    case "${x}" in
24898944Sobrien	      *26bit*) : ;;
24998944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
25098944Sobrien	    esac
25198944Sobrien	  done
25298944Sobrien	fi
25398944Sobrien	if [ x"$enable_underscore" = xno ]
25498944Sobrien	then
25598944Sobrien	  old_multidirs=${multidirs}
25698944Sobrien	  multidirs=""
25798944Sobrien	  for x in ${old_multidirs}; do
25898944Sobrien	    case "${x}" in
25998944Sobrien	      *under*) : ;;
26098944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
26198944Sobrien	    esac
26298944Sobrien	  done
26398944Sobrien	fi
26498944Sobrien	if [ x"$enable_interwork" = xno ]
26598944Sobrien	then
26698944Sobrien	  old_multidirs=${multidirs}
26798944Sobrien	  multidirs=""
26898944Sobrien	  for x in ${old_multidirs}; do
26998944Sobrien	    case "${x}" in
27098944Sobrien	      *interwork*) : ;;
27198944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
27298944Sobrien	    esac
27398944Sobrien	  done
27498944Sobrien	fi
27598944Sobrien	if [ x$enable_biendian = xno ]
27698944Sobrien	then
27798944Sobrien	  old_multidirs="${multidirs}"
27898944Sobrien	  multidirs=""
27998944Sobrien	  for x in ${old_multidirs}; do
28098944Sobrien	    case "$x" in
28198944Sobrien	      *le* ) : ;;
28298944Sobrien	      *be* ) : ;;
28398944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
28498944Sobrien	    esac
28598944Sobrien	  done
28698944Sobrien	fi
28798944Sobrien	if [ x"$enable_nofmult" = xno ]
28898944Sobrien	then
28998944Sobrien	  old_multidirs="${multidirs}"
29098944Sobrien	  multidirs=""
29198944Sobrien	  for x in ${old_multidirs}; do
29298944Sobrien	    case "$x" in
29398944Sobrien	      *nofmult* ) : ;;
29498944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
29598944Sobrien	    esac
29698944Sobrien	  done
29798944Sobrien	fi
29898944Sobrien	;;
29946283Sdfrm68*-*-*)
30046283Sdfr	if [ x$enable_softfloat = xno ]
30146283Sdfr	then
30246283Sdfr	  old_multidirs="${multidirs}"
30346283Sdfr	  multidirs=""
30446283Sdfr	  for x in ${old_multidirs}; do
30546283Sdfr	    case "$x" in
30646283Sdfr	      *soft-float* ) : ;;
30746283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
30846283Sdfr	    esac
30946283Sdfr	  done
31046283Sdfr	fi
31146283Sdfr	if [ x$enable_m68881 = xno ]
31246283Sdfr	then
31346283Sdfr	  old_multidirs="${multidirs}"
31446283Sdfr	  multidirs=""
31546283Sdfr	  for x in ${old_multidirs}; do
31646283Sdfr	    case "$x" in
31746283Sdfr	      *m68881* ) : ;;
31846283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
31946283Sdfr	    esac
32046283Sdfr	  done
32146283Sdfr	fi
32246283Sdfr	if [ x$enable_m68000 = xno ]
32346283Sdfr	then
32446283Sdfr	  old_multidirs="${multidirs}"
32546283Sdfr	  multidirs=""
32646283Sdfr	  for x in ${old_multidirs}; do
32746283Sdfr	    case "$x" in
32846283Sdfr	      *m68000* ) : ;;
32946283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
33046283Sdfr	    esac
33146283Sdfr	  done
33246283Sdfr	fi
33346283Sdfr	if [ x$enable_m68020 = xno ]
33446283Sdfr	then
33546283Sdfr	  old_multidirs="${multidirs}"
33646283Sdfr	  multidirs=""
33746283Sdfr	  for x in ${old_multidirs}; do
33846283Sdfr	    case "$x" in
33946283Sdfr	      *m68020* ) : ;;
34046283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
34146283Sdfr	    esac
34246283Sdfr	  done
34346283Sdfr	fi
34446283Sdfr	;;
34546283Sdfrmips*-*-*)
34646283Sdfr	if [ x$enable_single_float = xno ]
34746283Sdfr	then
34846283Sdfr	  old_multidirs="${multidirs}"
34946283Sdfr	  multidirs=""
35046283Sdfr	  for x in ${old_multidirs}; do
35146283Sdfr	    case "$x" in
35246283Sdfr	      *single* ) : ;;
35346283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
35446283Sdfr	    esac
35546283Sdfr	  done
35646283Sdfr	fi
35746283Sdfr	if [ x$enable_biendian = xno ]
35846283Sdfr	then
35946283Sdfr	  old_multidirs="${multidirs}"
36046283Sdfr	  multidirs=""
36146283Sdfr	  for x in ${old_multidirs}; do
36246283Sdfr	    case "$x" in
36346283Sdfr	      *el* ) : ;;
36446283Sdfr	      *eb* ) : ;;
36546283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
36646283Sdfr	    esac
36746283Sdfr	  done
36846283Sdfr	fi
36946283Sdfr	if [ x$enable_softfloat = xno ]
37046283Sdfr	then
37146283Sdfr	  old_multidirs="${multidirs}"
37246283Sdfr	  multidirs=""
37346283Sdfr	  for x in ${old_multidirs}; do
37446283Sdfr	    case "$x" in
37546283Sdfr	      *soft-float* ) : ;;
37646283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
37746283Sdfr	    esac
37846283Sdfr	  done
37946283Sdfr	fi
38098944Sobrien	case " $multidirs " in
38198944Sobrien	*" mabi=64 "*)
38298944Sobrien	  # We will not be able to create libraries with -mabi=64 if
38398944Sobrien	  # we cannot even link a trivial program.  It usually
38498944Sobrien	  # indicates the 64bit libraries are missing.
38598944Sobrien	  if echo 'main() {}' > conftest.c &&
38698944Sobrien	     ${CC-gcc} -mabi=64 conftest.c -o conftest; then
38798944Sobrien	    :
38898944Sobrien	  else
38998944Sobrien	    echo Could not link program with -mabi=64, disabling it.
39098944Sobrien	    old_multidirs="${multidirs}"
39198944Sobrien	    multidirs=""
39298944Sobrien	    for x in ${old_multidirs}; do
39398944Sobrien	      case "$x" in
39498944Sobrien	      *mabi=64* ) : ;;
39598944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
39698944Sobrien	      esac
39798944Sobrien	    done
39898944Sobrien	  fi
39998944Sobrien	  rm -f conftest.c conftest
40098944Sobrien	  ;;
40198944Sobrien	esac
40246283Sdfr	;;
40346283Sdfrpowerpc*-*-* | rs6000*-*-*)
404130803Smarcel	if [ x$enable_aix64 = xno ]
405130803Smarcel	then
406130803Smarcel	  old_multidirs="${multidirs}"
407130803Smarcel	  multidirs=""
408130803Smarcel	  for x in ${old_multidirs}; do
409130803Smarcel	    case "$x" in
410130803Smarcel	      *ppc64* ) : ;;
411130803Smarcel	      *) multidirs="${multidirs} ${x}" ;;
412130803Smarcel	    esac
413130803Smarcel	  done
414130803Smarcel	fi
415130803Smarcel	if [ x$enable_pthread = xno ]
416130803Smarcel	then
417130803Smarcel	  old_multidirs="${multidirs}"
418130803Smarcel	  multidirs=""
419130803Smarcel	  for x in ${old_multidirs}; do
420130803Smarcel	    case "$x" in
421130803Smarcel	      *pthread* ) : ;;
422130803Smarcel	      *) multidirs="${multidirs} ${x}" ;;
423130803Smarcel	    esac
424130803Smarcel	  done
425130803Smarcel	fi
42646283Sdfr	if [ x$enable_softfloat = xno ]
42746283Sdfr	then
42846283Sdfr	  old_multidirs="${multidirs}"
42946283Sdfr	  multidirs=""
43046283Sdfr	  for x in ${old_multidirs}; do
43146283Sdfr	    case "$x" in
43246283Sdfr	      *soft-float* ) : ;;
43346283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
43446283Sdfr	    esac
43546283Sdfr	  done
43646283Sdfr	fi
43746283Sdfr	if [ x$enable_powercpu = xno ]
43846283Sdfr	then
43946283Sdfr	  old_multidirs="${multidirs}"
44046283Sdfr	  multidirs=""
44146283Sdfr	  for x in ${old_multidirs}; do
44246283Sdfr	    case "$x" in
44346283Sdfr	      power | */power | */power/* ) : ;;
44446283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
44546283Sdfr	    esac
44646283Sdfr	  done
44746283Sdfr	fi
44846283Sdfr	if [ x$enable_powerpccpu = xno ]
44946283Sdfr	then
45046283Sdfr	  old_multidirs="${multidirs}"
45146283Sdfr	  multidirs=""
45246283Sdfr	  for x in ${old_multidirs}; do
45346283Sdfr	    case "$x" in
45446283Sdfr	      *powerpc* ) : ;;
45546283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
45646283Sdfr	    esac
45746283Sdfr	  done
45846283Sdfr	fi
45946283Sdfr	if [ x$enable_powerpcos = xno ]
46046283Sdfr	then
46146283Sdfr	  old_multidirs="${multidirs}"
46246283Sdfr	  multidirs=""
46346283Sdfr	  for x in ${old_multidirs}; do
46446283Sdfr	    case "$x" in
46546283Sdfr	      *mcall-linux* | *mcall-solaris* ) : ;;
46646283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
46746283Sdfr	    esac
46846283Sdfr	  done
46946283Sdfr	fi
47046283Sdfr	if [ x$enable_biendian = xno ]
47146283Sdfr	then
47246283Sdfr	  old_multidirs="${multidirs}"
47346283Sdfr	  multidirs=""
47446283Sdfr	  for x in ${old_multidirs}; do
47546283Sdfr	    case "$x" in
47646283Sdfr	      *mlittle* | *mbig* ) : ;;
47746283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
47846283Sdfr	    esac
47946283Sdfr	  done
48046283Sdfr	fi
48146283Sdfr	if [ x$enable_sysv = xno ]
48246283Sdfr	then
48346283Sdfr	  old_multidirs="${multidirs}"
48446283Sdfr	  multidirs=""
48546283Sdfr	  for x in ${old_multidirs}; do
48646283Sdfr	    case "$x" in
48746283Sdfr	      *mcall-sysv* ) : ;;
48846283Sdfr	      *) multidirs="${multidirs} ${x}" ;;
48946283Sdfr	    esac
49046283Sdfr	  done
49146283Sdfr	fi
49246283Sdfr	;;
49398944Sobriensparc*-*-*)
49498944Sobrien	case " $multidirs " in
49598944Sobrien	*" m64 "*)
49698944Sobrien	  # We will not be able to create libraries with -m64 if
49798944Sobrien	  # we cannot even link a trivial program.  It usually
49898944Sobrien	  # indicates the 64bit libraries are missing.
49998944Sobrien	  if echo 'main() {}' > conftest.c &&
50098944Sobrien	     ${CC-gcc} -m64 conftest.c -o conftest; then
50198944Sobrien	    :
50298944Sobrien	  else
50398944Sobrien	    echo Could not link program with -m64, disabling it.
50498944Sobrien	    old_multidirs="${multidirs}"
50598944Sobrien	    multidirs=""
50698944Sobrien	    for x in ${old_multidirs}; do
50798944Sobrien	      case "$x" in
50898944Sobrien	      *m64* ) : ;;
50998944Sobrien	      *) multidirs="${multidirs} ${x}" ;;
51098944Sobrien	      esac
51198944Sobrien	    done
51298944Sobrien	  fi
51398944Sobrien	  rm -f conftest.c conftest
51498944Sobrien	  ;;
51598944Sobrien	esac
51698944Sobrien	;;
51746283Sdfresac
51846283Sdfr
51946283Sdfr# Remove extraneous blanks from multidirs.
52046283Sdfr# Tests like `if [ -n "$multidirs" ]' require it.
52146283Sdfrmultidirs=`echo "$multidirs" | sed -e 's/^[ ][ ]*//' -e 's/[ ][ ]*$//' -e 's/[ ][ ]*/ /g'`
52246283Sdfr
52346283Sdfr# Add code to library's top level makefile to handle building the multilib
52446283Sdfr# subdirs.
52546283Sdfr
52646283Sdfrcat > Multi.tem <<\EOF
52746283Sdfr
528130803SmarcelPWD_COMMAND=$${PWDCMD-pwd}
529130803Smarcel
53046283Sdfr# FIXME: There should be an @-sign in front of the `if'.
53146283Sdfr# Leave out until this is tested a bit more.
53246283Sdfrmulti-do:
53346283Sdfr	if [ -z "$(MULTIDIRS)" ]; then \
53446283Sdfr	  true; \
53546283Sdfr	else \
536130803Smarcel	  rootpre=`${PWD_COMMAND}`/; export rootpre; \
537130803Smarcel	  srcrootpre=`cd $(srcdir); ${PWD_COMMAND}`/; export srcrootpre; \
53846283Sdfr	  lib=`echo $${rootpre} | sed -e 's,^.*/\([^/][^/]*\)/$$,\1,'`; \
53946283Sdfr	  compiler="$(CC)"; \
54046283Sdfr	  for i in `$${compiler} --print-multi-lib 2>/dev/null`; do \
54146283Sdfr	    dir=`echo $$i | sed -e 's/;.*$$//'`; \
54246283Sdfr	    if [ "$${dir}" = "." ]; then \
54346283Sdfr	      true; \
54446283Sdfr	    else \
54546283Sdfr	      if [ -d ../$${dir}/$${lib} ]; then \
54646283Sdfr		flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
54746283Sdfr		if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) \
54846283Sdfr				CFLAGS="$(CFLAGS) $${flags}" \
54998944Sobrien				prefix="$(prefix)" \
55098944Sobrien				exec_prefix="$(exec_prefix)" \
551130803Smarcel				GCJFLAGS="$(GCJFLAGS) $${flags}" \
55246283Sdfr				CXXFLAGS="$(CXXFLAGS) $${flags}" \
55346283Sdfr				LIBCFLAGS="$(LIBCFLAGS) $${flags}" \
55446283Sdfr				LIBCXXFLAGS="$(LIBCXXFLAGS) $${flags}" \
55546283Sdfr				LDFLAGS="$(LDFLAGS) $${flags}" \
556130803Smarcel				MULTIFLAGS="$${flags}" \
557130803Smarcel				DESTDIR="$(DESTDIR)" \
558130803Smarcel				INSTALL="$(INSTALL)" \
559130803Smarcel				INSTALL_DATA="$(INSTALL_DATA)" \
560130803Smarcel				INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
561130803Smarcel				INSTALL_SCRIPT="$(INSTALL_SCRIPT)" \
56246283Sdfr				$(DO)); then \
56346283Sdfr		  true; \
56446283Sdfr		else \
56546283Sdfr		  exit 1; \
56646283Sdfr		fi; \
56746283Sdfr	      else true; \
56846283Sdfr	      fi; \
56946283Sdfr	    fi; \
57046283Sdfr	  done; \
57146283Sdfr	fi
57246283Sdfr
57346283Sdfr# FIXME: There should be an @-sign in front of the `if'.
57446283Sdfr# Leave out until this is tested a bit more.
57546283Sdfrmulti-clean:
57646283Sdfr	if [ -z "$(MULTIDIRS)" ]; then \
57746283Sdfr	  true; \
57846283Sdfr	else \
579130803Smarcel	  lib=`${PWD_COMMAND} | sed -e 's,^.*/\([^/][^/]*\)$$,\1,'`; \
58046283Sdfr	  for dir in Makefile $(MULTIDIRS); do \
58146283Sdfr	    if [ -f ../$${dir}/$${lib}/Makefile ]; then \
58246283Sdfr	      if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) $(DO)); \
58346283Sdfr	      then true; \
58446283Sdfr	      else exit 1; \
58546283Sdfr	      fi; \
58646283Sdfr	    else true; \
58746283Sdfr	    fi; \
58846283Sdfr	  done; \
58946283Sdfr	fi
59046283SdfrEOF
59146283Sdfr
59246283Sdfrcat ${Makefile} Multi.tem > Makefile.tem
59346283Sdfrrm -f ${Makefile} Multi.tem
59446283Sdfrmv Makefile.tem ${Makefile}
59546283Sdfr
59646283Sdfrfi # ${ml_toplevel_p} = yes
59746283Sdfr
59846283Sdfrif [ "${ml_verbose}" = --verbose ]; then
59946283Sdfr  echo "Adding multilib support to Makefile in ${ml_realsrcdir}"
60046283Sdfr  if [ "${ml_toplevel_p}" = yes ]; then
60146283Sdfr    echo "multidirs=${multidirs}"
60246283Sdfr  fi
60346283Sdfr  echo "with_multisubdir=${with_multisubdir}"
60446283Sdfrfi
60546283Sdfr
60646283Sdfrif [ "${srcdir}" = "." ]; then
60746283Sdfr  if [ "${with_target_subdir}" != "." ]; then
60846283Sdfr    ml_srcdotdot="../"
60946283Sdfr  else
61046283Sdfr    ml_srcdotdot=""
61146283Sdfr  fi
61246283Sdfrelse
61346283Sdfr  ml_srcdotdot=""
61446283Sdfrfi
61546283Sdfr
61646283Sdfrif [ -z "${with_multisubdir}" ]; then
61746283Sdfr  ml_subdir=
61846283Sdfr  ml_builddotdot=
61946283Sdfr  : # ml_srcdotdot= # already set
62046283Sdfrelse
62146283Sdfr  ml_subdir="/${with_multisubdir}"
62246283Sdfr  # The '[^/][^/]*' appears that way to work around a SunOS sed bug.
62346283Sdfr  ml_builddotdot=`echo ${with_multisubdir} | sed -e 's:[^/][^/]*:..:g'`/
62446283Sdfr  if [ "$srcdir" = "." ]; then
62546283Sdfr    ml_srcdotdot=${ml_srcdotdot}${ml_builddotdot}
62646283Sdfr  else
62746283Sdfr    : # ml_srcdotdot= # already set
62846283Sdfr  fi
62946283Sdfrfi
63046283Sdfr
63146283Sdfrif [ "${ml_toplevel_p}" = yes ]; then
63246283Sdfr  ml_do='$(MAKE)'
63346283Sdfr  ml_clean='$(MAKE)'
63446283Sdfrelse
63546283Sdfr  ml_do=true
63646283Sdfr  ml_clean=true
63746283Sdfrfi
63846283Sdfr
63946283Sdfr# TOP is used by newlib and should not be used elsewhere for this purpose.
64046283Sdfr# MULTI{SRC,BUILD}TOP are the proper ones to use.  MULTISRCTOP is empty
64146283Sdfr# when srcdir != builddir.  MULTIBUILDTOP is always some number of ../'s.
64246283Sdfr# FIXME: newlib needs to be updated to use MULTI{SRC,BUILD}TOP so we can
64346283Sdfr# delete TOP.  Newlib may wish to continue to use TOP for its own purposes
64446283Sdfr# of course.
64546283Sdfr# MULTIDIRS is non-empty for the cpu top level Makefile (eg: newlib/Makefile)
64646283Sdfr# and lists the subdirectories to recurse into.
64746283Sdfr# MULTISUBDIR is non-empty in each cpu subdirectory's Makefile
64846283Sdfr# (eg: newlib/h8300h/Makefile) and is the installed subdirectory name with
64946283Sdfr# a leading '/'.
65046283Sdfr# MULTIDO is used for targets like all, install, and check where
65146283Sdfr# $(FLAGS_TO_PASS) augmented with the subdir's compiler option is needed.
65246283Sdfr# MULTICLEAN is used for the *clean targets.
65346283Sdfr#
65446283Sdfr# ??? It is possible to merge MULTIDO and MULTICLEAN into one.  They are
65546283Sdfr# currently kept separate because we don't want the *clean targets to require
65646283Sdfr# the existence of the compiler (which MULTIDO currently requires) and
65746283Sdfr# therefore we'd have to record the directory options as well as names
65846283Sdfr# (currently we just record the names and use --print-multi-lib to get the
65946283Sdfr# options).
66046283Sdfr
66146283Sdfrsed -e "s:^TOP[ 	]*=[ 	]*\([./]*\)[ 	]*$:TOP = ${ml_builddotdot}\1:" \
66246283Sdfr    -e "s:^MULTISRCTOP[ 	]*=.*$:MULTISRCTOP = ${ml_srcdotdot}:" \
66346283Sdfr    -e "s:^MULTIBUILDTOP[ 	]*=.*$:MULTIBUILDTOP = ${ml_builddotdot}:" \
66446283Sdfr    -e "s:^MULTIDIRS[ 	]*=.*$:MULTIDIRS = ${multidirs}:" \
66546283Sdfr    -e "s:^MULTISUBDIR[ 	]*=.*$:MULTISUBDIR = ${ml_subdir}:" \
66646283Sdfr    -e "s:^MULTIDO[ 	]*=.*$:MULTIDO = $ml_do:" \
66746283Sdfr    -e "s:^MULTICLEAN[ 	]*=.*$:MULTICLEAN = $ml_clean:" \
66846283Sdfr	${Makefile} > Makefile.tem
66946283Sdfrrm -f ${Makefile}
67046283Sdfrmv Makefile.tem ${Makefile}
67146283Sdfr
67246283Sdfr# If this is the library's top level, configure each multilib subdir.
67346283Sdfr# This is done at the end because this is the loop that runs configure
67446283Sdfr# in each multilib subdir and it seemed reasonable to finish updating the
67546283Sdfr# Makefile before going on to configure the subdirs.
67646283Sdfr
67746283Sdfrif [ "${ml_toplevel_p}" = yes ]; then
67846283Sdfr
67946283Sdfr# We must freshly configure each subdirectory.  This bit of code is
68046283Sdfr# actually partially stolen from the main configure script.  FIXME.
68146283Sdfr
68246283Sdfrif [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
68346283Sdfr
68446283Sdfr  if [ "${ml_verbose}" = --verbose ]; then
68546283Sdfr    echo "Running configure in multilib subdirs ${multidirs}"
686130803Smarcel    echo "pwd: `${PWDCMD-pwd}`"
68746283Sdfr  fi
68846283Sdfr
689130803Smarcel  ml_origdir=`${PWDCMD-pwd}`
69046283Sdfr  ml_libdir=`echo $ml_origdir | sed -e 's,^.*/,,'`
69146283Sdfr  # cd to top-level-build-dir/${with_target_subdir}
69246283Sdfr  cd ..
69346283Sdfr
69446283Sdfr  for ml_dir in ${multidirs}; do
69546283Sdfr
69646283Sdfr    if [ "${ml_verbose}" = --verbose ]; then
69746283Sdfr      echo "Running configure in multilib subdir ${ml_dir}"
698130803Smarcel      echo "pwd: `${PWDCMD-pwd}`"
69946283Sdfr    fi
70046283Sdfr
70198944Sobrien    if [ -d ${ml_dir} ]; then true; else
70298944Sobrien      # ``mkdir -p ${ml_dir}'' See also mkinstalldirs.
70398944Sobrien      pathcomp=""
70498944Sobrien      for d in `echo ":${ml_dir}" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`; do
70598944Sobrien        pathcomp="$pathcomp$d"
70698944Sobrien        case "$pathcomp" in
70798944Sobrien          -* ) pathcomp=./$pathcomp ;;
70898944Sobrien        esac
70998944Sobrien        if test ! -d "$pathcomp"; then
71098944Sobrien           echo "mkdir $pathcomp" 1>&2
71198944Sobrien           mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$?
71298944Sobrien        fi
71398944Sobrien        if test ! -d "$pathcomp"; then
71498944Sobrien	   exit $lasterr
71598944Sobrien        fi
71698944Sobrien        pathcomp="$pathcomp/"
71798944Sobrien      done
71898944Sobrien    fi
71946283Sdfr    if [ -d ${ml_dir}/${ml_libdir} ]; then true; else mkdir ${ml_dir}/${ml_libdir}; fi
72046283Sdfr
72146283Sdfr    # Eg: if ${ml_dir} = m68000/m68881, dotdot = ../../
72246283Sdfr    dotdot=../`echo ${ml_dir} | sed -e 's|[^/]||g' -e 's|/|../|g'`
72346283Sdfr
72446283Sdfr    case ${srcdir} in
72546283Sdfr    ".")
726130803Smarcel      echo Building symlink tree in `${PWDCMD-pwd}`/${ml_dir}/${ml_libdir}
72746283Sdfr      if [ "${with_target_subdir}" != "." ]; then
72846283Sdfr	ml_unsubdir="../"
72946283Sdfr      else
73046283Sdfr	ml_unsubdir=""
73146283Sdfr      fi
73246283Sdfr      (cd ${ml_dir}/${ml_libdir};
73346283Sdfr       ../${dotdot}${ml_unsubdir}symlink-tree ../${dotdot}${ml_unsubdir}${ml_libdir} "")
73446283Sdfr      if [ -f ${ml_dir}/${ml_libdir}/Makefile ]; then
73546283Sdfr	if [ x"${MAKE}" = x ]; then
73646283Sdfr	  (cd ${ml_dir}/${ml_libdir}; make distclean)
73746283Sdfr	else
73846283Sdfr	  (cd ${ml_dir}/${ml_libdir}; ${MAKE} distclean)
73946283Sdfr	fi
74046283Sdfr      fi
74146283Sdfr      ml_newsrcdir="."
74246283Sdfr      ml_srcdiroption=
74346283Sdfr      multisrctop=${dotdot}
74446283Sdfr      ;;
74546283Sdfr    *)
74646283Sdfr      case "${srcdir}" in
747130803Smarcel      /* | [A-Za-z]:[\\/]* ) # absolute path
74846283Sdfr        ml_newsrcdir=${srcdir}
74946283Sdfr        ;;
75046283Sdfr      *) # otherwise relative
75146283Sdfr        ml_newsrcdir=${dotdot}${srcdir}
75246283Sdfr        ;;
75346283Sdfr      esac
75446283Sdfr      ml_srcdiroption="-srcdir=${ml_newsrcdir}"
75546283Sdfr      multisrctop=
75646283Sdfr      ;;
75746283Sdfr    esac
75846283Sdfr
75946283Sdfr    case "${progname}" in
760130803Smarcel    /* | [A-Za-z]:[\\/]* )     ml_recprog=${progname} ;;
76146283Sdfr    *)      ml_recprog=${dotdot}${progname} ;;
76246283Sdfr    esac
76346283Sdfr
76446283Sdfr    # FIXME: POPDIR=${PWD=`pwd`} doesn't work here.
765130803Smarcel    ML_POPDIR=`${PWDCMD-pwd}`
76646283Sdfr    cd ${ml_dir}/${ml_libdir}
76746283Sdfr
76846283Sdfr    if [ -f ${ml_newsrcdir}/configure ]; then
769130803Smarcel      ml_recprog="${ml_newsrcdir}/configure"
77046283Sdfr    fi
77198944Sobrien
77298944Sobrien    # find compiler flag corresponding to ${ml_dir}
773130803Smarcel    for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
77498944Sobrien      dir=`echo $i | sed -e 's/;.*$//'`
77598944Sobrien      if [ "${dir}" = "${ml_dir}" ]; then
77698944Sobrien        flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`
77798944Sobrien        break
77898944Sobrien      fi
77998944Sobrien    done
780130803Smarcel    ml_config_env='CC="${CC_}$flags" CXX="${CXX_}$flags" GCJ="${GCJ_}$flags"'
78198944Sobrien
78298944Sobrien    if [ "${with_target_subdir}" = "." ]; then
78398944Sobrien	CC_=$CC' '
78498944Sobrien	CXX_=$CXX' '
785130803Smarcel	GCJ_=$GCJ' '
78698944Sobrien    else
78798944Sobrien	# Create a regular expression that matches any string as long
78898944Sobrien	# as ML_POPDIR.
78998944Sobrien	popdir_rx=`echo ${ML_POPDIR} | sed 's,.,.,g'`
79098944Sobrien	CC_=
79198944Sobrien	for arg in ${CC}; do
79298944Sobrien	  case $arg in
79398944Sobrien	  -[BIL]"${ML_POPDIR}"/*)
79498944Sobrien	    CC_="${CC_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\1/p"`' ' ;;
79598944Sobrien	  "${ML_POPDIR}"/*)
79698944Sobrien	    CC_="${CC_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
79798944Sobrien	  *)
79898944Sobrien	    CC_="${CC_}${arg} " ;;
79998944Sobrien	  esac
80098944Sobrien	done
80198944Sobrien
80298944Sobrien	CXX_=
80398944Sobrien	for arg in ${CXX}; do
80498944Sobrien	  case $arg in
80598944Sobrien	  -[BIL]"${ML_POPDIR}"/*)
80698944Sobrien	    CXX_="${CXX_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
80798944Sobrien	  "${ML_POPDIR}"/*)
80898944Sobrien	    CXX_="${CXX_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
80998944Sobrien	  *)
81098944Sobrien	    CXX_="${CXX_}${arg} " ;;
81198944Sobrien	  esac
81298944Sobrien	done
81398944Sobrien
814130803Smarcel	GCJ_=
815130803Smarcel	for arg in ${GCJ}; do
816130803Smarcel	  case $arg in
817130803Smarcel	  -[BIL]"${ML_POPDIR}"/*)
818130803Smarcel	    GCJ_="${GCJ_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
819130803Smarcel	  "${ML_POPDIR}"/*)
820130803Smarcel	    GCJ_="${GCJ_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
821130803Smarcel	  *)
822130803Smarcel	    GCJ_="${GCJ_}${arg} " ;;
823130803Smarcel	  esac
824130803Smarcel	done
825130803Smarcel
82698944Sobrien	if test "x${LD_LIBRARY_PATH+set}" = xset; then
82798944Sobrien	  LD_LIBRARY_PATH_=
82898944Sobrien	  for arg in `echo "$LD_LIBRARY_PATH" | tr ':' ' '`; do
82998944Sobrien	    case "$arg" in
83098944Sobrien	    "${ML_POPDIR}"/*)
83198944Sobrien	      arg=`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`
83298944Sobrien	      ;;
83398944Sobrien	    esac
83498944Sobrien	    if test "x$LD_LIBRARY_PATH_" != x; then
83598944Sobrien	      LD_LIBRARY_PATH_=$LD_LIBRARY_PATH_:$arg
83698944Sobrien	    else
83798944Sobrien	      LD_LIBRARY_PATH_=$arg
83898944Sobrien	    fi
83998944Sobrien          done
84098944Sobrien	  ml_config_env="$ml_config_env LD_LIBRARY_PATH=$LD_LIBRARY_PATH_"
84198944Sobrien	fi
84298944Sobrien
84398944Sobrien	if test "x${SHLIB_PATH+set}" = xset; then
84498944Sobrien	  SHLIB_PATH_=
84598944Sobrien	  for arg in `echo "$SHLIB_PATH" | tr ':' ' '`; do
84698944Sobrien	    case "$arg" in
84798944Sobrien	    "${ML_POPDIR}"/*)
84898944Sobrien	      arg=`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`
84998944Sobrien	      ;;
85098944Sobrien	    esac
85198944Sobrien	    if test "x$SHLIB_PATH_" != x; then
85298944Sobrien	      SHLIB_PATH_=$SHLIB_PATH_:$arg
85398944Sobrien	    else
85498944Sobrien	      SHLIB_PATH_=$arg
85598944Sobrien	    fi
85698944Sobrien          done
85798944Sobrien	  ml_config_env="$ml_config_env SHLIB_PATH=$SHLIB_PATH_"
85898944Sobrien	fi
85998944Sobrien    fi
86098944Sobrien
86198944Sobrien    if eval ${ml_config_env} ${ml_config_shell} ${ml_recprog} \
86246283Sdfr	--with-multisubdir=${ml_dir} --with-multisrctop=${multisrctop} \
863130803Smarcel	${ac_configure_args} ${ml_srcdiroption} ; then
86446283Sdfr      true
86546283Sdfr    else
86646283Sdfr      exit 1
86746283Sdfr    fi
86846283Sdfr
86946283Sdfr    cd ${ML_POPDIR}
87046283Sdfr
87146283Sdfr  done
87246283Sdfr
87346283Sdfr  cd ${ml_origdir}
87446283Sdfrfi
87546283Sdfr
87646283Sdfrfi # ${ml_toplevel_p} = yes
87746283Sdfrfi # ${enable_multilib} = yes
878