1# Configure fragment invoked in the post-target section for subdirs
2# wanting multilib support.
3#
4# Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
5#   Free Software Foundation, Inc.
6#
7# This file is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place - Suite 330,
20# Boston, MA 02111-1307, USA.
21#
22# As a special exception to the GNU General Public License, if you
23# distribute this file as part of a program that contains a
24# configuration script generated by Autoconf, you may include it under
25# the same distribution terms that you use for the rest of that program.
26#
27# Please report bugs to <gcc-bugs@gnu.org>
28# and send patches to <gcc-patches@gnu.org>.
29
30# It is advisable to support a few --enable/--disable options to let the
31# user select which libraries s/he really wants.
32#
33# Subdirectories wishing to use multilib should put the following lines
34# in the "post-target" section of configure.in.
35#
36# if [ "${srcdir}" = "." ] ; then
37#   if [ "${with_target_subdir}" != "." ] ; then
38#     . ${with_multisrctop}../../config-ml.in
39#   else
40#     . ${with_multisrctop}../config-ml.in
41#   fi
42# else
43#   . ${srcdir}/../config-ml.in
44# fi
45#
46#
47# Things are complicated because 6 separate cases must be handled:
48# 2 (native, cross) x 3 (absolute-path, relative-not-dot, dot) = 6.
49#
50# srcdir=. is special.  It must handle make programs that don't handle VPATH.
51# To implement this, a symlink tree is built for each library and for each
52# multilib subdir.
53#
54# The build tree is layed out as
55#
56# ./
57#   newlib
58#   m68020/
59#          newlib
60#          m68881/
61#                 newlib
62#
63# The nice feature about this arrangement is that inter-library references
64# in the build tree work without having to care where you are.  Note that
65# inter-library references also work in the source tree because symlink trees
66# are built when srcdir=.
67#
68# Unfortunately, trying to access the libraries in the build tree requires
69# the user to manually choose which library to use as GCC won't be able to
70# find the right one.  This is viewed as the lesser of two evils.
71#
72# Configure variables:
73# ${with_target_subdir} = "." for native, or ${target_alias} for cross.
74# Set by top level Makefile.
75# ${with_multisrctop} = how many levels of multilibs there are in the source
76# tree.  It exists to handle the case of configuring in the source tree:
77# ${srcdir} is not constant.
78# ${with_multisubdir} = name of multilib subdirectory (eg: m68020/m68881).
79#
80# Makefile variables:
81# MULTISRCTOP = number of multilib levels in source tree (+1 if cross)
82# (FIXME: note that this is different than ${with_multisrctop}.  Check out.).
83# MULTIBUILDTOP = number of multilib levels in build tree
84# MULTIDIRS = list of multilib subdirs (eg: m68000 m68020 ...)
85# (only defined in each library's main Makefile).
86# MULTISUBDIR = installed subdirectory name with leading '/' (eg: /m68000)
87# (only defined in each multilib subdir).
88
89# FIXME: Multilib is currently disabled by default for everything other than
90# newlib.  It is up to each target to turn on multilib support for the other
91# libraries as desired.
92
93# Autoconf incoming variables:
94# srcdir, host, ac_configure_args
95#
96# We *could* figure srcdir and host out, but we'd have to do work that
97# our caller has already done to figure them out and requiring these two
98# seems reasonable.
99# Note that `host' in this case is GCC's `target'.  Target libraries are
100# configured for a particular host.
101
102Makefile=${ac_file-Makefile}
103ml_config_shell=${CONFIG_SHELL-/bin/sh}
104ml_realsrcdir=${srcdir}
105
106# Scan all the arguments and set all the ones we need.
107
108ml_verbose=--verbose
109for option in ${ac_configure_args}
110do
111  case $option in
112  --*) ;;
113  -*) option=-$option ;;
114  esac
115
116  case $option in
117  --*=*)
118	optarg=`echo $option | sed -e 's/^[^=]*=//'`
119	;;
120  esac
121
122  case $option in
123  --disable-*)
124	enableopt=`echo ${option} | sed 's:^--disable-:enable_:;s:-:_:g'`
125	eval $enableopt=no
126	;;
127  --enable-*)
128	case "$option" in
129	*=*)	;;
130	*)	optarg=yes ;;
131	esac
132	enableopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
133	eval $enableopt="$optarg"
134	;;
135  --norecursion | --no-recursion)
136	ml_norecursion=yes
137	;;
138  --silent | --sil* | --quiet | --q*)
139	ml_verbose=--silent
140	;;
141  --verbose | --v | --verb*)
142	ml_verbose=--verbose
143	;;
144  --with-*)
145	case "$option" in
146	*=*)	;;
147	*)	optarg=yes ;;
148	esac
149	withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
150	eval $withopt="$optarg"
151	;;
152  --without-*)
153	withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g'`
154	eval $withopt=no
155	;;
156  esac
157done
158
159# Only do this if --enable-multilib.
160if [ "${enable_multilib}" = yes ]; then
161
162# Compute whether this is the library's top level directory
163# (ie: not a multilib subdirectory, and not a subdirectory like newlib/src).
164# ${with_multisubdir} tells us we're in the right branch, but we could be
165# in a subdir of that.
166# ??? The previous version could void this test by separating the process into
167# two files: one that only the library's toplevel configure.in ran (to
168# configure the multilib subdirs), and another that all configure.in's ran to
169# update the Makefile.  It seemed reasonable to collapse all multilib support
170# into one file, but it does leave us with having to perform this test.
171ml_toplevel_p=no
172if [ -z "${with_multisubdir}" ]; then
173  if [ "${srcdir}" = "." ]; then
174    # Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
175    # ${with_target_subdir} = "." for native, otherwise target alias.
176    if [ "${with_target_subdir}" = "." ]; then
177      if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
178	ml_toplevel_p=yes
179      fi
180    else
181      if [ -f ${ml_realsrcdir}/../../config-ml.in ]; then
182	ml_toplevel_p=yes
183      fi
184    fi
185  else
186    # Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
187    if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
188      ml_toplevel_p=yes
189    fi
190  fi
191fi
192
193# If this is the library's top level directory, set multidirs to the
194# multilib subdirs to support.  This lives at the top because we need
195# `multidirs' set right away.
196
197if [ "${ml_toplevel_p}" = yes ]; then
198
199multidirs=
200for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
201  dir=`echo $i | sed -e 's/;.*$//'`
202  if [ "${dir}" = "." ]; then
203    true
204  else
205    if [ -z "${multidirs}" ]; then
206      multidirs="${dir}"
207    else
208      multidirs="${multidirs} ${dir}"
209    fi
210  fi
211done
212
213# Target libraries are configured for the host they run on, so we check
214# $host here, not $target.
215
216case "${host}" in
217arc-*-elf*)
218	if [ x$enable_biendian != xyes ]
219	then
220	  old_multidirs=${multidirs}
221	  multidirs=""
222	  for x in ${old_multidirs}; do
223	    case "${x}" in
224	      *be*) : ;;
225	      *) multidirs="${multidirs} ${x}" ;;
226	    esac
227	  done
228	fi
229	;;
230arm-*-*)
231	if [ x"$enable_fpu" = xno ]
232	then
233	  old_multidirs=${multidirs}
234	  multidirs=""
235	  for x in ${old_multidirs}; do
236	    case "${x}" in
237	      *fpu*) : ;;
238	      *) multidirs="${multidirs} ${x}" ;;
239	    esac
240	  done
241	fi
242	if [ x"$enable_26bit" = xno ]
243	then
244	  old_multidirs=${multidirs}
245	  multidirs=""
246	  for x in ${old_multidirs}; do
247	    case "${x}" in
248	      *26bit*) : ;;
249	      *) multidirs="${multidirs} ${x}" ;;
250	    esac
251	  done
252	fi
253	if [ x"$enable_underscore" = xno ]
254	then
255	  old_multidirs=${multidirs}
256	  multidirs=""
257	  for x in ${old_multidirs}; do
258	    case "${x}" in
259	      *under*) : ;;
260	      *) multidirs="${multidirs} ${x}" ;;
261	    esac
262	  done
263	fi
264	if [ x"$enable_interwork" = xno ]
265	then
266	  old_multidirs=${multidirs}
267	  multidirs=""
268	  for x in ${old_multidirs}; do
269	    case "${x}" in
270	      *interwork*) : ;;
271	      *) multidirs="${multidirs} ${x}" ;;
272	    esac
273	  done
274	fi
275	if [ x$enable_biendian = xno ]
276	then
277	  old_multidirs="${multidirs}"
278	  multidirs=""
279	  for x in ${old_multidirs}; do
280	    case "$x" in
281	      *le* ) : ;;
282	      *be* ) : ;;
283	      *) multidirs="${multidirs} ${x}" ;;
284	    esac
285	  done
286	fi
287	if [ x"$enable_nofmult" = xno ]
288	then
289	  old_multidirs="${multidirs}"
290	  multidirs=""
291	  for x in ${old_multidirs}; do
292	    case "$x" in
293	      *nofmult* ) : ;;
294	      *) multidirs="${multidirs} ${x}" ;;
295	    esac
296	  done
297	fi
298	;;
299m68*-*-*)
300	if [ x$enable_softfloat = xno ]
301	then
302	  old_multidirs="${multidirs}"
303	  multidirs=""
304	  for x in ${old_multidirs}; do
305	    case "$x" in
306	      *soft-float* ) : ;;
307	      *) multidirs="${multidirs} ${x}" ;;
308	    esac
309	  done
310	fi
311	if [ x$enable_m68881 = xno ]
312	then
313	  old_multidirs="${multidirs}"
314	  multidirs=""
315	  for x in ${old_multidirs}; do
316	    case "$x" in
317	      *m68881* ) : ;;
318	      *) multidirs="${multidirs} ${x}" ;;
319	    esac
320	  done
321	fi
322	if [ x$enable_m68000 = xno ]
323	then
324	  old_multidirs="${multidirs}"
325	  multidirs=""
326	  for x in ${old_multidirs}; do
327	    case "$x" in
328	      *m68000* ) : ;;
329	      *) multidirs="${multidirs} ${x}" ;;
330	    esac
331	  done
332	fi
333	if [ x$enable_m68020 = xno ]
334	then
335	  old_multidirs="${multidirs}"
336	  multidirs=""
337	  for x in ${old_multidirs}; do
338	    case "$x" in
339	      *m68020* ) : ;;
340	      *) multidirs="${multidirs} ${x}" ;;
341	    esac
342	  done
343	fi
344	;;
345mips*-*-*)
346	if [ x$enable_single_float = xno ]
347	then
348	  old_multidirs="${multidirs}"
349	  multidirs=""
350	  for x in ${old_multidirs}; do
351	    case "$x" in
352	      *single* ) : ;;
353	      *) multidirs="${multidirs} ${x}" ;;
354	    esac
355	  done
356	fi
357	if [ x$enable_biendian = xno ]
358	then
359	  old_multidirs="${multidirs}"
360	  multidirs=""
361	  for x in ${old_multidirs}; do
362	    case "$x" in
363	      *el* ) : ;;
364	      *eb* ) : ;;
365	      *) multidirs="${multidirs} ${x}" ;;
366	    esac
367	  done
368	fi
369	if [ x$enable_softfloat = xno ]
370	then
371	  old_multidirs="${multidirs}"
372	  multidirs=""
373	  for x in ${old_multidirs}; do
374	    case "$x" in
375	      *soft-float* ) : ;;
376	      *) multidirs="${multidirs} ${x}" ;;
377	    esac
378	  done
379	fi
380	case " $multidirs " in
381	*" mabi=64 "*)
382	  # We will not be able to create libraries with -mabi=64 if
383	  # we cannot even link a trivial program.  It usually
384	  # indicates the 64bit libraries are missing.
385	  if echo 'main() {}' > conftest.c &&
386	     ${CC-gcc} -mabi=64 conftest.c -o conftest; then
387	    :
388	  else
389	    echo Could not link program with -mabi=64, disabling it.
390	    old_multidirs="${multidirs}"
391	    multidirs=""
392	    for x in ${old_multidirs}; do
393	      case "$x" in
394	      *mabi=64* ) : ;;
395	      *) multidirs="${multidirs} ${x}" ;;
396	      esac
397	    done
398	  fi
399	  rm -f conftest.c conftest
400	  ;;
401	esac
402	;;
403powerpc*-*-* | rs6000*-*-*)
404	if [ x$enable_aix64 = xno ]
405	then
406	  old_multidirs="${multidirs}"
407	  multidirs=""
408	  for x in ${old_multidirs}; do
409	    case "$x" in
410	      *ppc64* ) : ;;
411	      *) multidirs="${multidirs} ${x}" ;;
412	    esac
413	  done
414	fi
415	if [ x$enable_pthread = xno ]
416	then
417	  old_multidirs="${multidirs}"
418	  multidirs=""
419	  for x in ${old_multidirs}; do
420	    case "$x" in
421	      *pthread* ) : ;;
422	      *) multidirs="${multidirs} ${x}" ;;
423	    esac
424	  done
425	fi
426	if [ x$enable_softfloat = xno ]
427	then
428	  old_multidirs="${multidirs}"
429	  multidirs=""
430	  for x in ${old_multidirs}; do
431	    case "$x" in
432	      *soft-float* ) : ;;
433	      *) multidirs="${multidirs} ${x}" ;;
434	    esac
435	  done
436	fi
437	if [ x$enable_powercpu = xno ]
438	then
439	  old_multidirs="${multidirs}"
440	  multidirs=""
441	  for x in ${old_multidirs}; do
442	    case "$x" in
443	      power | */power | */power/* ) : ;;
444	      *) multidirs="${multidirs} ${x}" ;;
445	    esac
446	  done
447	fi
448	if [ x$enable_powerpccpu = xno ]
449	then
450	  old_multidirs="${multidirs}"
451	  multidirs=""
452	  for x in ${old_multidirs}; do
453	    case "$x" in
454	      *powerpc* ) : ;;
455	      *) multidirs="${multidirs} ${x}" ;;
456	    esac
457	  done
458	fi
459	if [ x$enable_powerpcos = xno ]
460	then
461	  old_multidirs="${multidirs}"
462	  multidirs=""
463	  for x in ${old_multidirs}; do
464	    case "$x" in
465	      *mcall-linux* | *mcall-solaris* ) : ;;
466	      *) multidirs="${multidirs} ${x}" ;;
467	    esac
468	  done
469	fi
470	if [ x$enable_biendian = xno ]
471	then
472	  old_multidirs="${multidirs}"
473	  multidirs=""
474	  for x in ${old_multidirs}; do
475	    case "$x" in
476	      *mlittle* | *mbig* ) : ;;
477	      *) multidirs="${multidirs} ${x}" ;;
478	    esac
479	  done
480	fi
481	if [ x$enable_sysv = xno ]
482	then
483	  old_multidirs="${multidirs}"
484	  multidirs=""
485	  for x in ${old_multidirs}; do
486	    case "$x" in
487	      *mcall-sysv* ) : ;;
488	      *) multidirs="${multidirs} ${x}" ;;
489	    esac
490	  done
491	fi
492	;;
493sparc*-*-*)
494	case " $multidirs " in
495	*" m64 "*)
496	  # We will not be able to create libraries with -m64 if
497	  # we cannot even link a trivial program.  It usually
498	  # indicates the 64bit libraries are missing.
499	  if echo 'main() {}' > conftest.c &&
500	     ${CC-gcc} -m64 conftest.c -o conftest; then
501	    :
502	  else
503	    echo Could not link program with -m64, disabling it.
504	    old_multidirs="${multidirs}"
505	    multidirs=""
506	    for x in ${old_multidirs}; do
507	      case "$x" in
508	      *m64* ) : ;;
509	      *) multidirs="${multidirs} ${x}" ;;
510	      esac
511	    done
512	  fi
513	  rm -f conftest.c conftest
514	  ;;
515	esac
516	;;
517esac
518
519# Remove extraneous blanks from multidirs.
520# Tests like `if [ -n "$multidirs" ]' require it.
521multidirs=`echo "$multidirs" | sed -e 's/^[ ][ ]*//' -e 's/[ ][ ]*$//' -e 's/[ ][ ]*/ /g'`
522
523# Add code to library's top level makefile to handle building the multilib
524# subdirs.
525
526cat > Multi.tem <<\EOF
527
528PWD_COMMAND=$${PWDCMD-pwd}
529
530# FIXME: There should be an @-sign in front of the `if'.
531# Leave out until this is tested a bit more.
532multi-do:
533	if [ -z "$(MULTIDIRS)" ]; then \
534	  true; \
535	else \
536	  rootpre=`${PWD_COMMAND}`/; export rootpre; \
537	  srcrootpre=`cd $(srcdir); ${PWD_COMMAND}`/; export srcrootpre; \
538	  lib=`echo $${rootpre} | sed -e 's,^.*/\([^/][^/]*\)/$$,\1,'`; \
539	  compiler="$(CC)"; \
540	  for i in `$${compiler} --print-multi-lib 2>/dev/null`; do \
541	    dir=`echo $$i | sed -e 's/;.*$$//'`; \
542	    if [ "$${dir}" = "." ]; then \
543	      true; \
544	    else \
545	      if [ -d ../$${dir}/$${lib} ]; then \
546		flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
547		if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) \
548				CFLAGS="$(CFLAGS) $${flags}" \
549				prefix="$(prefix)" \
550				exec_prefix="$(exec_prefix)" \
551				GCJFLAGS="$(GCJFLAGS) $${flags}" \
552				CXXFLAGS="$(CXXFLAGS) $${flags}" \
553				LIBCFLAGS="$(LIBCFLAGS) $${flags}" \
554				LIBCXXFLAGS="$(LIBCXXFLAGS) $${flags}" \
555				LDFLAGS="$(LDFLAGS) $${flags}" \
556				MULTIFLAGS="$${flags}" \
557				DESTDIR="$(DESTDIR)" \
558				INSTALL="$(INSTALL)" \
559				INSTALL_DATA="$(INSTALL_DATA)" \
560				INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
561				INSTALL_SCRIPT="$(INSTALL_SCRIPT)" \
562				$(DO)); then \
563		  true; \
564		else \
565		  exit 1; \
566		fi; \
567	      else true; \
568	      fi; \
569	    fi; \
570	  done; \
571	fi
572
573# FIXME: There should be an @-sign in front of the `if'.
574# Leave out until this is tested a bit more.
575multi-clean:
576	if [ -z "$(MULTIDIRS)" ]; then \
577	  true; \
578	else \
579	  lib=`${PWD_COMMAND} | sed -e 's,^.*/\([^/][^/]*\)$$,\1,'`; \
580	  for dir in Makefile $(MULTIDIRS); do \
581	    if [ -f ../$${dir}/$${lib}/Makefile ]; then \
582	      if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) $(DO)); \
583	      then true; \
584	      else exit 1; \
585	      fi; \
586	    else true; \
587	    fi; \
588	  done; \
589	fi
590EOF
591
592cat ${Makefile} Multi.tem > Makefile.tem
593rm -f ${Makefile} Multi.tem
594mv Makefile.tem ${Makefile}
595
596fi # ${ml_toplevel_p} = yes
597
598if [ "${ml_verbose}" = --verbose ]; then
599  echo "Adding multilib support to Makefile in ${ml_realsrcdir}"
600  if [ "${ml_toplevel_p}" = yes ]; then
601    echo "multidirs=${multidirs}"
602  fi
603  echo "with_multisubdir=${with_multisubdir}"
604fi
605
606if [ "${srcdir}" = "." ]; then
607  if [ "${with_target_subdir}" != "." ]; then
608    ml_srcdotdot="../"
609  else
610    ml_srcdotdot=""
611  fi
612else
613  ml_srcdotdot=""
614fi
615
616if [ -z "${with_multisubdir}" ]; then
617  ml_subdir=
618  ml_builddotdot=
619  : # ml_srcdotdot= # already set
620else
621  ml_subdir="/${with_multisubdir}"
622  # The '[^/][^/]*' appears that way to work around a SunOS sed bug.
623  ml_builddotdot=`echo ${with_multisubdir} | sed -e 's:[^/][^/]*:..:g'`/
624  if [ "$srcdir" = "." ]; then
625    ml_srcdotdot=${ml_srcdotdot}${ml_builddotdot}
626  else
627    : # ml_srcdotdot= # already set
628  fi
629fi
630
631if [ "${ml_toplevel_p}" = yes ]; then
632  ml_do='$(MAKE)'
633  ml_clean='$(MAKE)'
634else
635  ml_do=true
636  ml_clean=true
637fi
638
639# TOP is used by newlib and should not be used elsewhere for this purpose.
640# MULTI{SRC,BUILD}TOP are the proper ones to use.  MULTISRCTOP is empty
641# when srcdir != builddir.  MULTIBUILDTOP is always some number of ../'s.
642# FIXME: newlib needs to be updated to use MULTI{SRC,BUILD}TOP so we can
643# delete TOP.  Newlib may wish to continue to use TOP for its own purposes
644# of course.
645# MULTIDIRS is non-empty for the cpu top level Makefile (eg: newlib/Makefile)
646# and lists the subdirectories to recurse into.
647# MULTISUBDIR is non-empty in each cpu subdirectory's Makefile
648# (eg: newlib/h8300h/Makefile) and is the installed subdirectory name with
649# a leading '/'.
650# MULTIDO is used for targets like all, install, and check where
651# $(FLAGS_TO_PASS) augmented with the subdir's compiler option is needed.
652# MULTICLEAN is used for the *clean targets.
653#
654# ??? It is possible to merge MULTIDO and MULTICLEAN into one.  They are
655# currently kept separate because we don't want the *clean targets to require
656# the existence of the compiler (which MULTIDO currently requires) and
657# therefore we'd have to record the directory options as well as names
658# (currently we just record the names and use --print-multi-lib to get the
659# options).
660
661sed -e "s:^TOP[ 	]*=[ 	]*\([./]*\)[ 	]*$:TOP = ${ml_builddotdot}\1:" \
662    -e "s:^MULTISRCTOP[ 	]*=.*$:MULTISRCTOP = ${ml_srcdotdot}:" \
663    -e "s:^MULTIBUILDTOP[ 	]*=.*$:MULTIBUILDTOP = ${ml_builddotdot}:" \
664    -e "s:^MULTIDIRS[ 	]*=.*$:MULTIDIRS = ${multidirs}:" \
665    -e "s:^MULTISUBDIR[ 	]*=.*$:MULTISUBDIR = ${ml_subdir}:" \
666    -e "s:^MULTIDO[ 	]*=.*$:MULTIDO = $ml_do:" \
667    -e "s:^MULTICLEAN[ 	]*=.*$:MULTICLEAN = $ml_clean:" \
668	${Makefile} > Makefile.tem
669rm -f ${Makefile}
670mv Makefile.tem ${Makefile}
671
672# If this is the library's top level, configure each multilib subdir.
673# This is done at the end because this is the loop that runs configure
674# in each multilib subdir and it seemed reasonable to finish updating the
675# Makefile before going on to configure the subdirs.
676
677if [ "${ml_toplevel_p}" = yes ]; then
678
679# We must freshly configure each subdirectory.  This bit of code is
680# actually partially stolen from the main configure script.  FIXME.
681
682if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
683
684  if [ "${ml_verbose}" = --verbose ]; then
685    echo "Running configure in multilib subdirs ${multidirs}"
686    echo "pwd: `${PWDCMD-pwd}`"
687  fi
688
689  ml_origdir=`${PWDCMD-pwd}`
690  ml_libdir=`echo $ml_origdir | sed -e 's,^.*/,,'`
691  # cd to top-level-build-dir/${with_target_subdir}
692  cd ..
693
694  for ml_dir in ${multidirs}; do
695
696    if [ "${ml_verbose}" = --verbose ]; then
697      echo "Running configure in multilib subdir ${ml_dir}"
698      echo "pwd: `${PWDCMD-pwd}`"
699    fi
700
701    if [ -d ${ml_dir} ]; then true; else
702      # ``mkdir -p ${ml_dir}'' See also mkinstalldirs.
703      pathcomp=""
704      for d in `echo ":${ml_dir}" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`; do
705        pathcomp="$pathcomp$d"
706        case "$pathcomp" in
707          -* ) pathcomp=./$pathcomp ;;
708        esac
709        if test ! -d "$pathcomp"; then
710           echo "mkdir $pathcomp" 1>&2
711           mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$?
712        fi
713        if test ! -d "$pathcomp"; then
714	   exit $lasterr
715        fi
716        pathcomp="$pathcomp/"
717      done
718    fi
719    if [ -d ${ml_dir}/${ml_libdir} ]; then true; else mkdir ${ml_dir}/${ml_libdir}; fi
720
721    # Eg: if ${ml_dir} = m68000/m68881, dotdot = ../../
722    dotdot=../`echo ${ml_dir} | sed -e 's|[^/]||g' -e 's|/|../|g'`
723
724    case ${srcdir} in
725    ".")
726      echo Building symlink tree in `${PWDCMD-pwd}`/${ml_dir}/${ml_libdir}
727      if [ "${with_target_subdir}" != "." ]; then
728	ml_unsubdir="../"
729      else
730	ml_unsubdir=""
731      fi
732      (cd ${ml_dir}/${ml_libdir};
733       ../${dotdot}${ml_unsubdir}symlink-tree ../${dotdot}${ml_unsubdir}${ml_libdir} "")
734      if [ -f ${ml_dir}/${ml_libdir}/Makefile ]; then
735	if [ x"${MAKE}" = x ]; then
736	  (cd ${ml_dir}/${ml_libdir}; make distclean)
737	else
738	  (cd ${ml_dir}/${ml_libdir}; ${MAKE} distclean)
739	fi
740      fi
741      ml_newsrcdir="."
742      ml_srcdiroption=
743      multisrctop=${dotdot}
744      ;;
745    *)
746      case "${srcdir}" in
747      /* | [A-Za-z]:[\\/]* ) # absolute path
748        ml_newsrcdir=${srcdir}
749        ;;
750      *) # otherwise relative
751        ml_newsrcdir=${dotdot}${srcdir}
752        ;;
753      esac
754      ml_srcdiroption="-srcdir=${ml_newsrcdir}"
755      multisrctop=
756      ;;
757    esac
758
759    case "${progname}" in
760    /* | [A-Za-z]:[\\/]* )     ml_recprog=${progname} ;;
761    *)      ml_recprog=${dotdot}${progname} ;;
762    esac
763
764    # FIXME: POPDIR=${PWD=`pwd`} doesn't work here.
765    ML_POPDIR=`${PWDCMD-pwd}`
766    cd ${ml_dir}/${ml_libdir}
767
768    if [ -f ${ml_newsrcdir}/configure ]; then
769      ml_recprog="${ml_newsrcdir}/configure"
770    fi
771
772    # find compiler flag corresponding to ${ml_dir}
773    for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
774      dir=`echo $i | sed -e 's/;.*$//'`
775      if [ "${dir}" = "${ml_dir}" ]; then
776        flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`
777        break
778      fi
779    done
780    ml_config_env='CC="${CC_}$flags" CXX="${CXX_}$flags" GCJ="${GCJ_}$flags"'
781
782    if [ "${with_target_subdir}" = "." ]; then
783	CC_=$CC' '
784	CXX_=$CXX' '
785	GCJ_=$GCJ' '
786    else
787	# Create a regular expression that matches any string as long
788	# as ML_POPDIR.
789	popdir_rx=`echo ${ML_POPDIR} | sed 's,.,.,g'`
790	CC_=
791	for arg in ${CC}; do
792	  case $arg in
793	  -[BIL]"${ML_POPDIR}"/*)
794	    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"`' ' ;;
795	  "${ML_POPDIR}"/*)
796	    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"`' ' ;;
797	  *)
798	    CC_="${CC_}${arg} " ;;
799	  esac
800	done
801
802	CXX_=
803	for arg in ${CXX}; do
804	  case $arg in
805	  -[BIL]"${ML_POPDIR}"/*)
806	    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"`' ' ;;
807	  "${ML_POPDIR}"/*)
808	    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"`' ' ;;
809	  *)
810	    CXX_="${CXX_}${arg} " ;;
811	  esac
812	done
813
814	GCJ_=
815	for arg in ${GCJ}; do
816	  case $arg in
817	  -[BIL]"${ML_POPDIR}"/*)
818	    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"`' ' ;;
819	  "${ML_POPDIR}"/*)
820	    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"`' ' ;;
821	  *)
822	    GCJ_="${GCJ_}${arg} " ;;
823	  esac
824	done
825
826	if test "x${LD_LIBRARY_PATH+set}" = xset; then
827	  LD_LIBRARY_PATH_=
828	  for arg in `echo "$LD_LIBRARY_PATH" | tr ':' ' '`; do
829	    case "$arg" in
830	    "${ML_POPDIR}"/*)
831	      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"`
832	      ;;
833	    esac
834	    if test "x$LD_LIBRARY_PATH_" != x; then
835	      LD_LIBRARY_PATH_=$LD_LIBRARY_PATH_:$arg
836	    else
837	      LD_LIBRARY_PATH_=$arg
838	    fi
839          done
840	  ml_config_env="$ml_config_env LD_LIBRARY_PATH=$LD_LIBRARY_PATH_"
841	fi
842
843	if test "x${SHLIB_PATH+set}" = xset; then
844	  SHLIB_PATH_=
845	  for arg in `echo "$SHLIB_PATH" | tr ':' ' '`; do
846	    case "$arg" in
847	    "${ML_POPDIR}"/*)
848	      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"`
849	      ;;
850	    esac
851	    if test "x$SHLIB_PATH_" != x; then
852	      SHLIB_PATH_=$SHLIB_PATH_:$arg
853	    else
854	      SHLIB_PATH_=$arg
855	    fi
856          done
857	  ml_config_env="$ml_config_env SHLIB_PATH=$SHLIB_PATH_"
858	fi
859    fi
860
861    if eval ${ml_config_env} ${ml_config_shell} ${ml_recprog} \
862	--with-multisubdir=${ml_dir} --with-multisrctop=${multisrctop} \
863	${ac_configure_args} ${ml_srcdiroption} ; then
864      true
865    else
866      exit 1
867    fi
868
869    cd ${ML_POPDIR}
870
871  done
872
873  cd ${ml_origdir}
874fi
875
876fi # ${ml_toplevel_p} = yes
877fi # ${enable_multilib} = yes
878