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