Tue Nov 5 10:21:02 1996 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/binutils-gdb.git] / config-ml.in
CommitLineData
d747cac4
DE
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
953fbd65 12# . ${with_multisrctop}../../config-ml.in
d747cac4 13# else
953fbd65 14# . ${with_multisrctop}../config-ml.in
d747cac4
DE
15# fi
16# else
17# . ${srcdir}/../config-ml.in
18# fi
19#
20# See librx/configure.in in the libg++ distribution for an example of how
21# to handle autoconf'd libraries.
22#
23# Things are complicated because 6 separate cases must be handled:
24# 2 (native, cross) x 3 (absolute-path, relative-not-dot, dot) = 6.
25#
26# srcdir=. is special. It must handle make programs that don't handle VPATH.
27# To implement this, a symlink tree is built for each library and for each
28# multilib subdir.
29#
30# The build tree is layed out as
31#
32# ./
33# libg++
34# newlib
35# m68020/
36# libg++
37# newlib
38# m68881/
39# libg++
40# newlib
41#
42# The nice feature about this arrangement is that inter-library references
43# in the build tree work without having to care where you are. Note that
44# inter-library references also work in the source tree because symlink trees
45# are built when srcdir=.
46#
953fbd65
DE
47# Unfortunately, trying to access the libraries in the build tree requires
48# the user to manually choose which library to use as GCC won't be able to
49# find the right one. This is viewed as the lesser of two evils.
50#
d747cac4
DE
51# Configure variables:
52# ${with_target_subdir} = "." for native, or ${target_alias} for cross.
53# Set by top level Makefile.
54# ${with_multisrctop} = how many levels of multilibs there are in the source
55# tree. It exists to handle the case of configuring in the source tree:
56# ${srcdir} is not constant.
57# ${with_multisubdir} = name of multilib subdirectory (eg: m68020/m68881).
58#
59# Makefile variables:
60# MULTISRCTOP = number of multilib levels in source tree (+1 if cross)
953fbd65
DE
61# (FIXME: note that this is different than ${with_multisrctop}. Check out.).
62# MULTIBUILDTOP = number of multilib levels in build tree
d747cac4
DE
63# MULTIDIRS = list of multilib subdirs (eg: m68000 m68020 ...)
64# (only defined in each library's main Makefile).
65# MULTISUBDIR = installed subdirectory name with leading '/' (eg: /m68000)
66# (only defined in each multilib subdir).
67
68# FIXME: Multilib is currently disabled by default for everything other than
69# newlib. It is up to each target to turn on multilib support for the other
70# libraries as desired.
71
72# We have to handle being invoked by both Cygnus configure and Autoconf.
953fbd65
DE
73#
74# Cygnus configure incoming variables:
75# srcdir, subdir, target, arguments
76#
77# Autoconf incoming variables:
78# srcdir, target, ac_configure_args
79#
80# We *could* figure srcdir and target out, but we'd have to do work that
81# our caller has already done to figure them out and requiring these two
82# seems reasonable.
d747cac4
DE
83
84if [ -n "${ac_configure_args}" ]; then
85 Makefile=${ac_file-Makefile}
2a59259c
DE
86 ml_config_shell=${CONFIG_SHELL-/bin/sh}
87 ml_arguments="${ac_configure_args}"
953fbd65 88 ml_realsrcdir=${srcdir}
d747cac4
DE
89else
90 Makefile=${Makefile-Makefile}
2a59259c
DE
91 ml_config_shell=${config_shell-/bin/sh}
92 ml_arguments="${arguments}"
953fbd65
DE
93 if [ -n "${subdir}" -a "${subdir}" != "." ] ; then
94 ml_realsrcdir=${srcdir}/${subdir}
95 else
96 ml_realsrcdir=${srcdir}
97 fi
d747cac4
DE
98fi
99
100# Scan all the arguments and set all the ones we need.
101
2a59259c 102for option in ${ml_arguments}
d747cac4
DE
103do
104 case $option in
105 --*) ;;
106 -*) option=-$option ;;
107 esac
108
109 case $option in
110 --*=*)
111 optarg=`echo $option | sed -e 's/^[^=]*=//'`
112 ;;
113 esac
114
115 case $option in
116 --disable-*)
117 enableopt=`echo ${option} | sed 's:^--disable-:enable_:;s:-:_:g'`
118 eval $enableopt=no
119 ;;
120 --enable-*)
121 case "$option" in
122 *=*) ;;
123 *) optarg=yes ;;
124 esac
125 enableopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
126 eval $enableopt="$optarg"
127 ;;
128 --norecursion | --no*)
2a59259c 129 ml_norecursion=yes
d747cac4
DE
130 ;;
131 --verbose | --v | --verb*)
2a59259c 132 ml_verbose=--verbose
d747cac4
DE
133 ;;
134 --with-*)
135 case "$option" in
136 *=*) ;;
137 *) optarg=yes ;;
138 esac
139 withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
140 eval $withopt="$optarg"
141 ;;
142 --without-*)
143 withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g'`
144 eval $withopt=no
145 ;;
146 esac
147done
148
149# Only do this if --enable-multilib.
150if [ "${enable_multilib}" = yes ]; then
151
152# Compute whether this is the library's top level directory
153# (ie: not a multilib subdirectory, and not a subdirectory like libg++/src).
154# ${with_multisubdir} tells us we're in the right branch, but we could be
155# in a subdir of that.
156# ??? The previous version could void this test by separating the process into
157# two files: one that only the library's toplevel configure.in ran (to
158# configure the multilib subdirs), and another that all configure.in's ran to
159# update the Makefile. It seemed reasonable to collapse all multilib support
160# into one file, but it does leave us with having to perform this test.
161ml_toplevel_p=no
162if [ -z "${with_multisubdir}" ]; then
163 if [ "${srcdir}" = "." ]; then
953fbd65 164 # Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
d747cac4
DE
165 # ${with_target_subdir} = "." for native, otherwise target alias.
166 if [ "${with_target_subdir}" = "." ]; then
953fbd65 167 if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
d747cac4
DE
168 ml_toplevel_p=yes
169 fi
170 else
953fbd65 171 if [ -f ${ml_realsrcdir}/../../config-ml.in ]; then
d747cac4
DE
172 ml_toplevel_p=yes
173 fi
174 fi
175 else
953fbd65
DE
176 # Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
177 if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
d747cac4
DE
178 ml_toplevel_p=yes
179 fi
180 fi
181fi
182
183# If this is the library's top level directory, set multidirs to the
184# multilib subdirs to support. This lives at the top because we need
d1265690 185# `multidirs' set right away.
d747cac4
DE
186
187if [ "${ml_toplevel_p}" = yes ]; then
188
d1265690
MM
189multidirs=
190for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
191 dir=`echo $i | sed -e 's/;.*$//'`
192 if [ "${dir}" = "." ]; then
193 true
194 else
195 if [ -z "${multidirs}" ]; then
196 multidirs="${dir}"
197 else
198 multidirs="${multidirs} ${dir}"
199 fi
200 fi
201done
202
d747cac4
DE
203case "${target}" in
204# start-sanitize-arc
205arc-sbp-elf*)
d1265690 206 if [ x$enable_biendian != xyes ]
d747cac4 207 then
d1265690
MM
208 old_multidirs=${multidirs}
209 multidirs=
d747cac4 210 for x in ${old_multidirs}; do
d1265690
MM
211 case "${x}" in
212 *be*) ;;
213 *) if [ x"$multidirs" = x ]; then
214 multidirs="$x";
215 else
216 multidirs="${multidirs} ${x}";
217 fi
218 ;;
d747cac4
DE
219 esac
220 done
221 fi
d1265690
MM
222 ;;
223# end-sanitize-arc
224mips*-*-*)
225 if [ x$enable_single_float = xno ]
d747cac4
DE
226 then
227 old_multidirs="${multidirs}"
228 multidirs=""
229 for x in ${old_multidirs}; do
230 case "$x" in
d1265690 231 *single* ) : ;;
d747cac4
DE
232 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
233 esac
234 done
235 fi
d1265690 236 if [ x$enable_biendian = xno ]
d747cac4
DE
237 then
238 old_multidirs="${multidirs}"
239 multidirs=""
240 for x in ${old_multidirs}; do
241 case "$x" in
d1265690
MM
242 *el* ) : ;;
243 *eb* ) : ;;
d747cac4
DE
244 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
245 esac
246 done
247 fi
d1265690 248 if [ x$enable_softfloat = xno ]
d747cac4
DE
249 then
250 old_multidirs="${multidirs}"
251 multidirs=""
252 for x in ${old_multidirs}; do
253 case "$x" in
d1265690 254 *soft-float* ) : ;;
d747cac4
DE
255 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
256 esac
257 done
258 fi
259 ;;
d1265690 260powerpc*-*-* | rs6000*-*-*)
d747cac4
DE
261 if [ x$enable_softfloat = xno ]
262 then
263 old_multidirs="${multidirs}"
264 multidirs=""
265 for x in ${old_multidirs}; do
266 case "$x" in
267 *soft-float* ) : ;;
268 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
269 esac
270 done
271 fi
272 if [ x$enable_commoncpu = xno ]
273 then
274 old_multidirs="${multidirs}"
275 multidirs=""
276 for x in ${old_multidirs}; do
277 case "$x" in
278 *common* ) : ;;
279 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
280 esac
281 done
282 fi
d1265690 283 if [ x$enable_powercpu = xno ]
d747cac4
DE
284 then
285 old_multidirs="${multidirs}"
286 multidirs=""
287 for x in ${old_multidirs}; do
288 case "$x" in
d1265690 289 power | */power | */power/* ) : ;;
d747cac4
DE
290 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
291 esac
292 done
293 fi
d1265690 294 if [ x$enable_power2cpu = xno ]
d747cac4
DE
295 then
296 old_multidirs="${multidirs}"
297 multidirs=""
298 for x in ${old_multidirs}; do
299 case "$x" in
d1265690 300 *power2* ) : ;;
d747cac4
DE
301 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
302 esac
303 done
304 fi
d1265690 305 if [ x$enable_powerpccpu = xno ]
d747cac4
DE
306 then
307 old_multidirs="${multidirs}"
308 multidirs=""
309 for x in ${old_multidirs}; do
310 case "$x" in
d1265690 311 *powerpc* ) : ;;
d747cac4
DE
312 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
313 esac
314 done
315 fi
d1265690 316 if [ x$enable_601cpu = xno ]
d747cac4
DE
317 then
318 old_multidirs="${multidirs}"
319 multidirs=""
320 for x in ${old_multidirs}; do
321 case "$x" in
d1265690 322 *601* ) : ;;
d747cac4
DE
323 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
324 esac
325 done
326 fi
d747cac4
DE
327 if [ x$enable_biendian = xno ]
328 then
329 old_multidirs="${multidirs}"
330 multidirs=""
331 for x in ${old_multidirs}; do
332 case "$x" in
333 *endian* ) : ;;
334 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
335 esac
336 done
337 fi
d747cac4
DE
338 if [ x$enable_relocatable = xno ]
339 then
340 old_multidirs="${multidirs}"
341 multidirs=""
342 for x in ${old_multidirs}; do
343 case "$x" in
344 *relocatable* ) : ;;
345 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
346 esac
347 done
348 fi
d1265690 349 if [ x$enable_sysv = xno ]
d747cac4
DE
350 then
351 old_multidirs="${multidirs}"
352 multidirs=""
353 for x in ${old_multidirs}; do
354 case "$x" in
d1265690 355 *sysv* ) : ;;
d747cac4
DE
356 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
357 esac
358 done
359 fi
360 if [ x$enable_aix = xno ]
361 then
362 old_multidirs="${multidirs}"
363 multidirs=""
364 for x in ${old_multidirs}; do
365 case "$x" in
366 *aix* ) : ;;
367 *) if [ x"$multidirs" = x ]; then multidirs="$x"; else multidirs="${multidirs} ${x}"; fi ;;
368 esac
369 done
370 fi
371 ;;
d747cac4
DE
372esac
373
374# Add code to library's top level makefile to handle building the multilib
375# subdirs.
376
377cat > Multi.tem <<\EOF
378
379# FIXME: There should be an @-sign in front of the `if'.
380# Leave out until this is tested a bit more.
381multi-do:
382 if [ -z "$(MULTIDIRS)" ]; then \
383 true; \
384 else \
385 rootpre=`pwd`/; export rootpre; \
386 srcrootpre=`cd $(srcdir); pwd`/; export srcrootpre; \
387 lib=`echo $${rootpre} | sed -e 's,^.*/\([^/][^/]*\)/$$,\1,'`; \
388 compiler="$(CC)"; \
389 for i in `$${compiler} --print-multi-lib 2>/dev/null`; do \
390 dir=`echo $$i | sed -e 's/;.*$$//'`; \
391 if [ "$${dir}" = "." ]; then \
392 true; \
393 else \
394 if [ -d ../$${dir}/$${lib} ]; then \
395 flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
396 if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) \
397 CFLAGS="$(CFLAGS) $${flags}" \
398 CXXFLAGS="$(CXXFLAGS) $${flags}" \
399 LIBCFLAGS="$(LIBCFLAGS) $${flags}" \
400 LIBCXXFLAGS="$(LIBCXXFLAGS) $${flags}" \
401 $(DO)); then \
402 true; \
403 else \
404 exit 1; \
405 fi; \
406 else true; \
407 fi; \
408 fi; \
409 done; \
410 fi
411
412# FIXME: There should be an @-sign in front of the `if'.
413# Leave out until this is tested a bit more.
414multi-clean:
415 if [ -z "$(MULTIDIRS)" ]; then \
416 true; \
417 else \
d1265690 418 lib=`pwd | sed -e 's,^.*/\([^/][^/]*\)$$,\1,'`; \
d747cac4
DE
419 for dir in Makefile $(MULTIDIRS); do \
420 if [ -f ../$${dir}/$${lib}/Makefile ]; then \
421 if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) $(DO)); \
422 then true; \
423 else exit 1; \
424 fi; \
425 else true; \
426 fi; \
427 done; \
428 fi
429EOF
430
431cat ${Makefile} Multi.tem > Makefile.tem
432rm -f ${Makefile} Multi.tem
433mv Makefile.tem ${Makefile}
434
435fi # ${ml_toplevel_p} = yes
436
2a59259c 437if [ "${ml_verbose}" = --verbose ]; then
953fbd65 438 echo "Adding multilib support to Makefile in ${ml_realsrcdir}"
d747cac4
DE
439 if [ "${ml_toplevel_p}" = yes ]; then
440 echo "multidirs=${multidirs}"
441 fi
442 echo "with_multisubdir=${with_multisubdir}"
443fi
444
445if [ "${srcdir}" = "." ]; then
446 if [ "${with_target_subdir}" != "." ]; then
447 ml_srcdotdot="../"
448 else
449 ml_srcdotdot=""
450 fi
451else
452 ml_srcdotdot=""
453fi
454
455if [ -z "${with_multisubdir}" ]; then
456 ml_subdir=
457 ml_builddotdot=
458 : # ml_srcdotdot= # already set
459else
460 ml_subdir="/${with_multisubdir}"
461 # The '[^/][^/]*' appears that way to work around a SunOS sed bug.
462 ml_builddotdot=`echo ${with_multisubdir} | sed -e 's:[^/][^/]*:..:g'`/
463 if [ "$srcdir" = "." ]; then
464 ml_srcdotdot=${ml_srcdotdot}${ml_builddotdot}
465 else
466 : # ml_srcdotdot= # already set
467 fi
468fi
469
470if [ "${ml_toplevel_p}" = yes ]; then
471 ml_do='$(MAKE)'
472 ml_clean='$(MAKE)'
473else
474 ml_do=true
475 ml_clean=true
476fi
477
478# TOP is used by newlib and should not be used elsewhere for this purpose.
479# MULTI{SRC,BUILD}TOP are the proper ones to use. MULTISRCTOP is empty
480# when srcdir != builddir. MULTIBUILDTOP is always some number of ../'s.
481# FIXME: newlib needs to be updated to use MULTI{SRC,BUILD}TOP so we can
482# delete TOP. Newlib may wish to continue to use TOP for its own purposes
483# of course.
484# MULTIDIRS is non-empty for the cpu top level Makefile (eg: newlib/Makefile)
485# and lists the subdirectories to recurse into.
486# MULTISUBDIR is non-empty in each cpu subdirectory's Makefile
487# (eg: newlib/h8300h/Makefile) and is the installed subdirectory name with
488# a leading '/'.
489# MULTIDO is used for targets like all, install, and check where
490# $(FLAGS_TO_PASS) augmented with the subdir's compiler option is needed.
491# MULTICLEAN is used for the *clean targets.
492#
493# ??? It is possible to merge MULTIDO and MULTICLEAN into one. They are
494# currently kept separate because we don't want the *clean targets to require
495# the existence of the compiler (which MULTIDO currently requires) and
496# therefore we'd have to record the directory options as well as names
497# (currently we just record the names and use --print-multi-lib to get the
498# options).
499
500sed -e "s:^TOP[ ]*=[ ]*\([./]*\)[ ]*$:TOP = ${ml_builddotdot}\1:" \
501 -e "s:^MULTISRCTOP[ ]*=.*$:MULTISRCTOP = ${ml_srcdotdot}:" \
502 -e "s:^MULTIBUILDTOP[ ]*=.*$:MULTIBUILDTOP = ${ml_builddotdot}:" \
503 -e "s:^MULTIDIRS[ ]*=.*$:MULTIDIRS = ${multidirs}:" \
504 -e "s:^MULTISUBDIR[ ]*=.*$:MULTISUBDIR = ${ml_subdir}:" \
505 -e "s:^MULTIDO[ ]*=.*$:MULTIDO = $ml_do:" \
506 -e "s:^MULTICLEAN[ ]*=.*$:MULTICLEAN = $ml_clean:" \
507 ${Makefile} > Makefile.tem
508rm -f ${Makefile}
509mv Makefile.tem ${Makefile}
510
511# If this is the library's top level, configure each multilib subdir.
512# This is done at the end because this is the loop that runs configure
513# in each multilib subdir and it seemed reasonable to finish updating the
514# Makefile before going on to configure the subdirs.
515
516if [ "${ml_toplevel_p}" = yes ]; then
517
518# We must freshly configure each subdirectory. This bit of code is
519# actually partially stolen from the main configure script. FIXME.
520
2a59259c 521if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
d747cac4 522
2a59259c 523 if [ "${ml_verbose}" = --verbose ]; then
d747cac4
DE
524 echo "Running configure in multilib subdirs ${multidirs}"
525 echo "pwd: `pwd`"
526 fi
527
528 ml_origdir=`pwd`
529 ml_libdir=`echo $ml_origdir | sed -e 's,^.*/,,'`
530 # cd to top-level-build-dir/${with_target_subdir}
531 cd ..
532
2a59259c 533 for ml_dir in ${multidirs}; do
d747cac4 534
2a59259c
DE
535 if [ "${ml_verbose}" = --verbose ]; then
536 echo "Running configure in multilib subdir ${ml_dir}"
d747cac4
DE
537 echo "pwd: `pwd`"
538 fi
539
2a59259c
DE
540 if [ -d ${ml_dir} ]; then true; else mkdir ${ml_dir}; fi
541 if [ -d ${ml_dir}/${ml_libdir} ]; then true; else mkdir ${ml_dir}/${ml_libdir}; fi
d747cac4 542
2a59259c
DE
543 # Eg: if ${ml_dir} = m68000/m68881, dotdot = ../../
544 dotdot=../`echo ${ml_dir} | sed -e 's|[^/]||g' -e 's|/|../|g'`
d747cac4
DE
545
546 case ${srcdir} in
547 ".")
2a59259c 548 echo Building symlink tree in `pwd`/${ml_dir}/${ml_libdir}
d747cac4
DE
549 if [ "${with_target_subdir}" != "." ]; then
550 ml_unsubdir="../"
551 else
552 ml_unsubdir=""
553 fi
2a59259c 554 (cd ${ml_dir}/${ml_libdir};
d747cac4 555 ../${dotdot}${ml_unsubdir}symlink-tree ../${dotdot}${ml_unsubdir}${ml_libdir} "")
2a59259c
DE
556 ml_newsrcdir="."
557 ml_srcdiroption=
d747cac4
DE
558 multisrctop=${dotdot}
559 ;;
560 *)
561 case "${srcdir}" in
562 /*) # absolute path
2a59259c 563 ml_newsrcdir=${srcdir}
d747cac4
DE
564 ;;
565 *) # otherwise relative
2a59259c 566 ml_newsrcdir=${dotdot}${srcdir}
d747cac4
DE
567 ;;
568 esac
2a59259c 569 ml_srcdiroption="-srcdir=${ml_newsrcdir}"
d747cac4
DE
570 multisrctop=
571 ;;
572 esac
573
574 case "${progname}" in
2a59259c
DE
575 /*) ml_recprog=${progname} ;;
576 *) ml_recprog=${dotdot}${progname} ;;
d747cac4
DE
577 esac
578
579 # FIXME: POPDIR=${PWD=`pwd`} doesn't work here.
580 ML_POPDIR=`pwd`
2a59259c 581 cd ${ml_dir}/${ml_libdir}
d747cac4 582
2a59259c
DE
583 if [ -f ${ml_newsrcdir}/configure ]; then
584 ml_recprog=${ml_newsrcdir}/configure
d747cac4 585 fi
2a59259c
DE
586 if eval ${ml_config_shell} ${ml_recprog} \
587 --with-multisubdir=${ml_dir} --with-multisrctop=${multisrctop} \
588 ${ml_arguments} ${ml_srcdiroption} ; then
d747cac4
DE
589 true
590 else
591 exit 1
592 fi
593
594 cd ${ML_POPDIR}
595
596 done
597
598 cd ${ml_origdir}
599fi
600
601fi # ${ml_toplevel_p} = yes
602fi # ${enable_multilib} = yes
This page took 0.073452 seconds and 4 git commands to generate.