* configure.in: Strip --host and --target options from
[external/binutils.git] / configure
1 #!/bin/sh
2
3 ### WARNING: this file contains embedded tabs.  Do not run untabify on this file.
4
5 # Configuration script
6 # Copyright (C) 1988, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 # This file was originally written by K. Richard Pixley.
23
24 #
25 # Shell script to create proper links to machine-dependent files in
26 # preparation for compilation.
27 #
28 # If configure succeeds, it leaves its status in config.status.
29 # If configure fails after disturbing the status quo, 
30 #       config.status is removed.
31 #
32
33 export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0 $argv; kill $$)
34
35 remove=rm
36 hard_link=ln
37 symbolic_link='ln -s'
38
39 #for Test
40 #remove="echo rm"
41 #hard_link="echo ln"
42 #symbolic_link="echo ln -s"
43
44 # clear some things potentially inherited from environment.
45
46 Makefile=Makefile
47 Makefile_in=Makefile.in
48 arguments=
49 build_alias=
50 cache_file=
51 cache_file_option=
52 configdirs=
53 exec_prefix=
54 exec_prefixoption=
55 fatal=
56 floating_point=default
57 gas=default
58 host_alias=NOHOST
59 host_makefile_frag=
60 moveifchange=
61 norecursion=
62 other_options=
63 package_makefile_frag=
64 prefix=/usr/local
65 progname=
66 program_prefix=
67 program_prefixoption=
68 program_suffix=
69 program_suffixoption=
70 program_transform_name=
71 program_transform_nameoption=
72 redirect=">/dev/null"
73 removing=
74 site=
75 site_makefile_frag=
76 site_option=
77 srcdir=
78 srctrigger=
79 subdirs=
80 target_alias=NOTARGET
81 target_makefile_frag=
82 undefs=NOUNDEFS
83 version="$Revision$"
84 x11=default
85
86 ### we might need to use some other shell than /bin/sh for running subshells
87 #
88 config_shell=${CONFIG_SHELL-/bin/sh}
89
90 NO_EDIT="This file was generated automatically by configure.  Do not edit."
91
92 ## this is a little touchy and won't always work, but...
93 ##
94 ## if the argv[0] starts with a slash then it is an absolute name that can (and
95 ## must) be used as is.
96 ##
97 ## otherwise, if argv[0] has no slash in it, we can assume that it is on the
98 ## path.  Since PATH might include "." we also add `pwd` to the end of PATH.
99 ##
100
101 progname=$0
102 # if PWD already has a value, it is probably wrong.
103 if [ -n "$PWD" ]; then PWD=`pwd`; fi
104
105 case "${progname}" in
106 /*) ;;
107 */*) ;;
108 *)
109         PATH=$PATH:${PWD=`pwd`} ; export PATH
110         ;;
111 esac
112
113 # Loop over all args
114
115 while :
116 do
117
118 # Break out if there are no more args
119         case $# in
120         0)
121                 break
122                 ;;
123         esac
124
125 # Get the first arg, and shuffle
126         option=$1
127         shift
128
129 # Make all options have two hyphens
130         orig_option=$option     # Save original for error messages
131         case $option in
132         --*) ;;
133         -*) option=-$option ;;
134         esac
135                 
136 # Split out the argument for options that take them
137         case $option in
138         --*=*)
139                 optarg=`echo $option | sed -e 's/^[^=]*=//'`
140                 arguments="$arguments $option"
141                 ;;
142 # These options have mandatory values.  Since we didn't find an = sign,
143 # the value must be in the next argument
144         --b* | --cache* | --ex* | --ho* | --pre* | --program-p* | --program-s* | --program-t* | --si* | --sr* | --ta* | --tm* | --x-*)
145                 optarg=$1
146                 shift
147                 arguments="$arguments $option=$optarg"
148                 ;;
149         --*)
150                 arguments="$arguments $option"
151                 ;;
152         esac
153
154 # Now, process the options
155         case $option in
156
157         --build* | --b*)
158                 case "$build_alias" in
159                 "") build_alias=$optarg ;;
160                 *) echo '***' Can only configure for one build machine at a time.  1>&2
161                    fatal=yes
162                    ;;
163                 esac
164                 ;;
165         --cache*)
166                 cache_file=$optarg
167                 ;;
168         --disable-*)
169                 enableopt=`echo ${option} | sed 's:^--disable-:enable_:;s:-:_:g'`
170                 eval $enableopt=no
171                 disableoptions="$disableoptions $option"
172                 ;;
173         --enable-*)
174                 case "$option" in
175                 *=*)    ;;
176                 *)      optarg=yes ;;
177                 esac
178
179                 enableopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
180                 eval $enableopt="$optarg"
181                 enableoptions="$enableoptions $option"
182                 ;;
183         --exec-prefix* | --ex*)
184                 exec_prefix=$optarg
185                 exec_prefixoption="--exec-prefix=$optarg"
186                 ;;
187         --gas | --g*)
188                 gas=yes
189                 ;;
190         --help | --he*)
191                 fatal=yes
192                 ;;
193         --host* | --ho*)
194                 case $host_alias in
195                 NOHOST) host_alias=$optarg ;;
196                 *) echo '***' Can only configure for one host at a time.  1>&2
197                    fatal=yes
198                    ;;
199                 esac
200                 ;;
201         --nfp | --nf*)
202                 floating_point=no
203                 ;;
204         --norecursion | --no*)
205                 norecursion=yes
206                 ;;
207         --prefix* | --pre*)
208                 prefix=$optarg
209                 prefixoption="--prefix=$optarg"
210                 ;;
211         --program-prefix* | --program-p*)
212                 program_prefix=$optarg
213                 program_prefixoption="--program-prefix=$optarg"
214                 ;;
215         --program-suffix* | --program-s*)
216                 program_suffix=$optarg
217                 program_suffixoption="--program-suffix=$optarg"
218                 ;;
219         --program-transform-name* | --program-t*)
220                 # Double any backslashes or dollar signs in the argument
221                 program_transform_name="${program_transform_name} -e `echo ${optarg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`"
222                 program_transform_nameoption="${program_transform_nameoption} --program-transform-name='$optarg'"
223                 ;;
224         --rm)
225                 removing=--rm
226                 ;;
227         --silent | --sil* | --quiet | --q*)
228                 redirect=">/dev/null"
229                 verbose=--silent
230                 ;;
231         --site* | --sit*)
232                 site=$optarg
233                 site_option="--site=$optarg"
234                 ;;
235         --srcdir*/ | --sr*/)
236                 # Remove trailing slashes.  Otherwise, when the file name gets
237                 # bolted into an object file as debug info, it has two slashes
238                 # in it.  Ordinarily this is ok, but emacs takes double slash
239                 # to mean "forget the first part".
240                 srcdir=`echo $optarg | sed -e 's:/$::'`
241                 ;;
242         --srcdir* | --sr*)
243                 srcdir=$optarg
244                 ;;
245         --target* | --ta*)
246                 case $target_alias in
247                 NOTARGET) target_alias=$optarg ;;
248                 *) echo '***' Can only configure for one target at a time.  1>&2
249                    fatal=yes
250                    ;;
251                 esac
252                 ;;
253         --tmpdir* | --tm*)
254                 TMPDIR=$optarg
255                 tmpdiroption="--tmpdir=$optarg"
256                 ;;
257         --verbose | --v | --verb*)
258                 redirect=
259                 verbose=--verbose
260                 ;;
261         --version | --V | --vers*)
262                 echo "This is Cygnus Configure version" `echo ${version} | sed 's/[ $:]//g'`
263                 exit 0
264                 ;;
265         --with-*)
266                 case "$option" in
267                 *=*)    ;;
268                 *)      optarg=yes ;;
269                 esac
270
271                 withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
272                 eval $withopt="$optarg"
273                 withoptions="$withoptions $option"
274                 ;;
275         --without-*)
276                 withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g'`
277                 eval $withopt=no
278                 withoutoptions="$withoutoptions $option"
279                 ;;
280         --x)    with_x=yes
281                 withoptions="$withoptions --with-x"
282                 ;;
283         --x-i* | --x-l*) other_options="$other_options $orig_option"
284                 ;;
285         --*)
286                 echo "configure: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
287                 exit 1
288                 ;;
289         *)
290                 case $undefs in
291                 NOUNDEFS) undefs=$option ;;
292                 *) echo '***' Can only configure for one host and one target at a time.  1>&2
293                    fatal=yes
294                    ;;
295                 esac
296                 ;;
297         esac
298 done
299
300 # process host and target
301
302 # Do some error checking and defaulting for the host and target type.
303 # The inputs are:
304 #    configure --host=HOST --target=TARGET UNDEFS
305 #
306 # The rules are:
307 # 1. You aren't allowed to specify --host, --target, and undefs at the
308 #    same time.
309 # 2. Host defaults to undefs.
310 # 3. If undefs is not specified, then host defaults to the current host,
311 #    as determined by config.guess.
312 # 4. Target defaults to undefs.
313 # 5. If undefs is not specified, then target defaults to host.
314
315 case "${fatal}" in
316 "")
317         # Make sure that host, target & undefs aren't all specified at the
318         # same time.
319         case $host_alias---$target_alias---$undefs in
320         NOHOST---*---* | *---NOTARGET---* | *---*---NOUNDEFS)
321                 ;;
322         *) echo '***' Can only configure for one host and one target at a time.  1>&2
323            fatal=yes
324            break 2
325                 ;;
326         esac
327
328         # Now, do defaulting for host.
329         case $host_alias in
330         NOHOST)
331                 case $undefs in
332                 NOUNDEFS)
333                         # Neither --host option nor undefs were present.
334                         # Call config.guess.
335                         guesssys=`echo ${progname} | sed 's/configure$/config.guess/'`
336                         if host_alias=`${guesssys}`
337                         then
338                                 # If the string we are going to use for
339                                 # the target is a prefix of the string
340                                 # we just guessed for the host, then
341                                 # assume we are running native, and force
342                                 # the same string for both target and host.
343                                 case $target_alias in
344                                 NOTARGET) ;;
345                                 *)
346                                         if expr $host_alias : $target_alias >/dev/null
347                                         then
348                                                 host_alias=$target_alias
349                                         fi
350                                         ;;
351                                 esac
352                                 echo "Configuring for a ${host_alias} host." 1>&2
353                                 arguments="--host=$host_alias $arguments"
354                         else
355                                 echo 'Config.guess failed to determine the host type.  You need to specify one.' 1>&2
356                                 fatal=yes
357                         fi
358                         ;;
359                 *)
360                         host_alias=$undefs
361                         arguments="--host=$host_alias $arguments"
362                         undefs=NOUNDEFS
363                         ;;
364                 esac
365         esac
366
367         # Do defaulting for target.  If --target option isn't present, default
368         # to undefs.  If undefs isn't present, default to host.
369         case $target_alias in
370         NOTARGET)
371                 case $undefs in
372                 NOUNDEFS)
373                         target_alias=$host_alias
374                         ;;
375                 *)
376                         target_alias=$undefs
377                         arguments="--target=$target_alias $arguments"
378                         ;;
379                 esac
380         esac
381         ;;
382 *) ;;
383 esac
384
385 if [ -n "${fatal}" -o "${host_alias}" = "help" ] ; then
386         exec 1>&2
387         echo Usage: configure [OPTIONS] [HOST]
388         echo
389         echo Options: [defaults in brackets]
390         echo ' --prefix=MYDIR            install into MYDIR [/usr/local]'
391         echo ' --exec-prefix=MYDIR       install host-dependent files into MYDIR [/usr/local]'
392         echo ' --help                    print this message [normal config]'
393         echo ' --build=BUILD             configure for building on BUILD [BUILD=HOST]'
394         echo ' --host=HOST               configure for HOST [determined via config.guess]'
395         echo ' --norecursion             configure this directory only [recurse]'
396         echo ' --program-prefix=FOO      prepend FOO to installed program names [""]'
397         echo ' --program-suffix=FOO      append FOO to installed program names [""]'
398         echo ' --program-transform-name=P transform installed names by sed pattern P [""]'
399         echo ' --site=SITE               configure with site-specific makefile for SITE'
400         echo ' --srcdir=DIR              find the sources in DIR [. or ..]'
401         echo ' --target=TARGET   configure for TARGET [TARGET=HOST]'
402         echo ' --tmpdir=TMPDIR   create temporary files in TMPDIR [/tmp]'
403         echo ' --nfp                     configure for software floating point [hard float]'
404         echo ' --with-FOO, --with-FOO=BAR package FOO is available (parameter BAR)'
405         echo ' --without-FOO             package FOO is NOT available'
406         echo ' --enable-FOO, --enable-FOO=BAR include feature FOO (parameter BAR)'
407         echo ' --disable-FOO             do not include feature FOO'
408         echo
409         echo 'Where HOST and TARGET are something like "sparc-sunos", "mips-sgi-irix5", etc.'
410         echo
411         if [ -r config.status ] ; then
412                 cat config.status
413         fi
414
415         exit 1
416 fi
417
418 configsub=`echo ${progname} | sed 's/configure$/config.sub/'`
419 moveifchange=`echo ${progname} | sed 's/configure$/move-if-change/'`
420
421 # this is a hack.  sun4 must always be a valid host alias or this will fail.
422 if ${configsub} sun4 >/dev/null 2>&1 ; then
423         true
424 else
425         echo '***' cannot find config.sub.  1>&2
426         exit 1
427 fi
428
429 touch config.junk
430 if ${moveifchange} config.junk config.trash ; then
431         true
432 else
433         echo '***' cannot find move-if-change.  1>&2
434         exit 1
435 fi
436 rm -f config.junk config.trash
437
438 case "${srcdir}" in
439 "")
440         if [ -r configure.in ] ; then
441                 srcdir=.
442         else
443                 if [ -r ${progname}.in ] ; then
444                         srcdir=`echo ${progname} | sed 's:/configure$::'`
445                 else
446                         echo '***' "Can't find configure.in.  Try using --srcdir=some_dir"  1>&2
447                         exit 1
448                 fi
449         fi
450         ;;
451 *)
452         # Set srcdir to "." if that's what it is.
453         # This is important for multilib support.
454         if [ ! -d ${srcdir} ] ; then
455                 echo "Invalid source directory ${srcdir}" >&2
456                 exit 1
457         fi
458         pwd=`pwd`
459         srcpwd=`cd ${srcdir} ; pwd`
460         if [ "${pwd}" = "${srcpwd}" ] ; then
461                 srcdir=.
462         fi
463 esac
464
465 ### warn about some conflicting configurations.
466
467 case "${srcdir}" in
468 ".") ;;
469 *)
470         if [ -f ${srcdir}/config.status ] ; then
471                 echo '***' Cannot configure here in \"${PWD=`pwd`}\" when \"${srcdir}\" is currently configured. 1>&2
472                 exit 1
473         fi
474 esac
475
476 # default exec_prefix
477 case "${exec_prefixoption}" in
478 "") exec_prefix="\$(prefix)" ;;
479 *) ;;
480 esac
481
482 ### break up ${srcdir}/configure.in.
483 case "`grep '^# per\-host:' ${srcdir}/configure.in`" in
484 "")
485         echo '***' ${srcdir}/configure.in has no \"per-host:\" line. 1>&2
486         # Check for a directory that's been converted to use autoconf since
487         # it was last configured.
488         if grep AC_OUTPUT ${srcdir}/configure.in >/dev/null ; then
489           echo '***' Hmm, looks like this directory has been autoconfiscated. 1>&2
490           if [ -r ${srcdir}/configure ] ; then
491             echo '***' Running the local configure script. 1>&2
492             case "${cache_file}" in
493             "") cache_file_option= ;;
494             *)  cache_file_option="--cache-file=${cache_file}" ;;
495             esac
496             srcdiroption="--srcdir=${srcdir}"
497             case "${build_alias}" in
498             "") buildopt= ;;
499             *)  buildopt="--build=${build_alias}" ;;
500             esac
501             eval exec ${config_shell} ${srcdir}/configure ${verbose} \
502                 ${buildopt} --host=${host_alias} --target=${target_alias} \
503                 ${prefixoption} ${tmpdiroption} ${exec_prefixoption} \
504                 ${srcdiroption} \
505                 ${program_prefixoption} ${program_suffixoption} \
506                 ${program_transform_nameoption} ${site_option} \
507                 ${withoptions} ${withoutoptions} \
508                 ${enableoptions} ${disableoptions} \
509                 ${cache_file_option} ${removing} ${other_options} ${redirect}
510           else
511             echo '***' There is no configure script present though. 1>&2
512           fi
513         fi
514         exit 1
515         ;;
516 *) ;;
517 esac
518
519 case "`grep '^# per\-target:' ${srcdir}/configure.in`" in
520 "")
521         echo '***' ${srcdir}/configure.in has no \"per-target:\" line. 1>&2
522         exit 1
523         ;;
524 *) ;;
525 esac
526
527 case "${TMPDIR}" in
528 "") TMPDIR=/tmp ; export TMPDIR ;;
529 *) ;;
530 esac
531
532 # keep this filename short for &%*%$*# 14 char file names
533 tmpfile=${TMPDIR}/cONf$$
534 # Note that under many versions of sh a trap handler for 0 will *override* any
535 # exit status you explicitly specify!  At this point, the only non-error exit
536 # is at the end of the script; these actions are duplicated there, minus
537 # the "exit 1".  Don't use "exit 0" anywhere after this without resetting the
538 # trap handler, or you'll lose.
539 trap "rm -f Makefile.tem ${tmpfile}.com ${tmpfile}.tgt ${tmpfile}.hst ${tmpfile}.pos; exit 1" 0 1 2 15
540
541 # split ${srcdir}/configure.in into common, per-host, per-target,
542 # and post-target parts.  Post-target is optional.
543 sed -e '/^# per\-host:/,$d' ${srcdir}/configure.in > ${tmpfile}.com
544 sed -e '1,/^# per\-host:/d' -e '/^# per\-target:/,$d' ${srcdir}/configure.in > ${tmpfile}.hst
545 if grep '^# post-target:' ${srcdir}/configure.in >/dev/null ; then
546   sed -e '1,/^# per\-target:/d' -e '/^# post\-target:/,$d' ${srcdir}/configure.in > ${tmpfile}.tgt
547   sed -e '1,/^# post\-target:/d' ${srcdir}/configure.in > ${tmpfile}.pos
548 else
549   sed -e '1,/^# per\-target:/d' ${srcdir}/configure.in > ${tmpfile}.tgt
550   echo >${tmpfile}.pos
551 fi
552
553 ### do common part of configure.in
554
555 . ${tmpfile}.com
556
557 # some sanity checks on configure.in
558 case "${srctrigger}" in
559 "")
560         echo '***' srctrigger not set in ${PWD=`pwd`}/configure.in.  1>&2
561         exit 1
562         ;;
563 *) ;;
564 esac
565
566 case "${build_alias}" in
567 "")
568         if result=`${config_shell} ${configsub} ${host_alias}` ; then
569             build_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
570             build_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
571             build_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
572             build=${build_cpu}-${build_vendor}-${build_os}
573             build_alias=${host_alias}
574         fi
575         ;;
576 *)
577         if result=`${config_shell} ${configsub} ${build_alias}` ; then
578             buildopt="--build=${build_alias}"
579             build_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
580             build_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
581             build_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
582             build=${build_cpu}-${build_vendor}-${build_os}
583         else
584             echo "Unrecognized build system name ${build_alias}." 1>&2
585             exit 1
586         fi
587         ;;
588 esac
589
590 if result=`${config_shell} ${configsub} ${host_alias}` ; then
591     true
592 else
593     echo "Unrecognized host system name ${host_alias}." 1>&2
594     exit 1
595 fi
596 host_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
597 host_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
598 host_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
599 host=${host_cpu}-${host_vendor}-${host_os}
600
601 . ${tmpfile}.hst
602
603 if result=`${config_shell} ${configsub} ${target_alias}` ; then
604     true
605 else
606     echo "Unrecognized target system name ${target_alias}." 1>&2
607     exit 1
608 fi
609 target_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
610 target_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
611 target_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
612 target=${target_cpu}-${target_vendor}-${target_os}
613
614 . ${tmpfile}.tgt
615
616 # Find the source files, if location was not specified.
617 case "${srcdir}" in
618 "")
619         srcdirdefaulted=1
620         srcdir=.
621         if [ ! -r ${srctrigger} ] ; then
622                 srcdir=..
623         fi
624         ;;
625 *) ;;
626 esac
627
628 if [ ! -r ${srcdir}/${srctrigger} ] ; then
629         case "${srcdirdefaulted}" in
630         "") echo '***' "${progname}: Can't find ${srcname} sources in ${PWD=`pwd`}/${srcdir}" 1>&2 ;;
631         *)  echo '***' "${progname}: Can't find ${srcname} sources in ${PWD=`pwd`}/. or ${PWD=`pwd`}/.." 1>&2 ;;
632         esac
633
634         echo '***' \(At least ${srctrigger} is missing.\) 1>&2
635         exit 1
636 fi
637
638 # Some systems (e.g., one of the i386-aix systems the gas testers are
639 # using) don't handle "\$" correctly, so don't use it here.
640 tooldir='$(exec_prefix)'/${target_alias}
641
642 if [ "${host_alias}" != "${target_alias}" ] ; then
643     if [ "${program_prefixoption}" = "" ] ; then
644         if [ "${program_suffixoption}" = "" ] ; then 
645             if [ "${program_transform_nameoption}" = "" ] ; then
646                 program_prefix=${target_alias}- ;
647             fi
648         fi
649     fi
650 fi
651
652 # Merge program_prefix and program_suffix onto program_transform_name.
653 # (program_suffix used to use $, but it's hard to preserve $ through both
654 # make and sh.)
655 if [ "${program_suffix}" != "" ] ; then
656     program_transform_name="-e s,\\\\(.*\\\\),\\\\1${program_suffix}, ${program_transform_name}"
657 fi
658
659 if [ "${program_prefix}" != "" ] ; then
660     program_transform_name="-e s,^,${program_prefix}, ${program_transform_name}"
661 fi
662
663 # If CC and CXX are not set in the environment, and the Makefile
664 # exists, try to extract them from it.  This is to handle running
665 # ./config.status by hand.
666 if [ -z "${CC}" -a -r Makefile ]; then
667   sed -n -e ':loop
668 /\\$/ N
669 /\\$/ b loop
670 s/\\\n//g
671 /^CC[   ]*=/ s/CC[      ]*=[    ]*\(.*\)/\1/p' < Makefile > Makefile.cc
672   CC=`tail -1 Makefile.cc`
673   rm -f Makefile.cc
674 fi
675
676 if [ -z "${CXX}" -a -r Makefile ]; then
677   sed -n -e ':loop
678 /\\$/ N
679 /\\$/ b loop
680 s/\\\n//g
681 /^CXX[  ]*=/ s/CXX[     ]*=[    ]*\(.*\)/\1/p' < Makefile > Makefile.cc
682   CXX=`tail -1 Makefile.cc`
683   rm -f Makefile.cc
684 fi
685
686 if [ "${build}" != "${host}" ]; then
687   # If we are doing a Canadian Cross, in which the host and build systems
688   # are not the same, we set reasonable default values for the tools.
689
690   tools="AR AR_FOR_TARGET AS AS_FOR_TARGET BISON CC_FOR_BUILD"
691   tools="${tools} CC_FOR_TARGET CXX_FOR_TARGET HOST_PREFIX"
692   tools="${tools} HOST_PREFIX_1 LD LD_FOR_TARGET LEX MAKEINFO NM"
693   tools="${tools} NM_FOR_TARGET RANLIB RANLIB_FOR_TARGET"
694
695   for var in ${tools}; do
696     if [ -z "`eval 'echo $'"${var}"`" -a -r Makefile ]; then
697       sed -n -e ':loop
698 /\\$/ N
699 /\\$/ b loop
700 s/\\\n//g
701 /^'"${var}"'[   ]*=/ s/'"${var}"'[      ]*=[    ]*\(.*\)/\1/p' \
702         < Makefile > Makefile.v
703       t=`tail -1 Makefile.v`
704       if [ -n "${t}" ]; then
705         eval "${var}='${t}'"
706       fi
707       rm -f Makefile.v
708     fi
709   done
710
711   AR=${AR-${host_alias}-ar}
712   AR_FOR_TARGET=${AR_FOR_TARGET-${target_alias}-ar}
713   AS=${AS-${host_alias}-as}
714   AS_FOR_TARGET=${AS_FOR_TARGET-${target_alias}-as}
715   CC=${CC-${host_alias}-gcc}
716   CXX=${CXX-${host_alias}-gcc}
717   CC_FOR_BUILD=${CC_FOR_BUILD-gcc}
718   CC_FOR_TARGET=${CC_FOR_TARGET-${target_alias}-gcc}
719   CXX_FOR_TARGET=${CXX_FOR_TARGET-${target_alias}-gcc}
720   HOST_PREFIX=${build_alias}-
721   HOST_PREFIX_1=${build_alias}-
722   LD=${LD-${host_alias}-ld}
723   LD_FOR_TARGET=${LD_FOR_TARGET-${target_alias}-ld}
724   MAKEINFO=${MAKEINFO-makeinfo}
725   NM=${NM-${host_alias}-nm}
726   NM_FOR_TARGET=${NM_FOR_TARGET-${target_alias}-nm}
727   RANLIB=${RANLIB-${host_alias}-ranlib}
728   RANLIB_FOR_TARGET=${RANLIB_FOR_TARGET-${target_alias}-ranlib}
729
730   if [ -z "${BISON}" ]; then
731     IFS="${IFS=         }"; save_ifs="$IFS"; IFS="${IFS}:"
732     for dir in $PATH; do
733       test -z "$dir" && dir=.
734       if test -f $dir/byacc; then
735         BISON=byacc
736         break
737       fi
738       if test -f $dir/bison; then
739         BISON=bison
740         break
741       fi
742       if test -f $dir/yacc; then
743         BISON=yacc
744         break
745       fi
746     done
747     IFS="$save_ifs"
748     BISON=${BISON-bison}
749   fi
750
751   if [ -z "${LEX}" ]; then
752     IFS="${IFS=         }"; save_ifs="$IFS"; IFS="${IFS}:"
753     for dir in $PATH; do
754       test -z "$dir" && dir=.
755       if test -f $dir/flex; then
756         LEX=flex
757         break
758       fi
759       if test -f $dir/lex; then
760         LEX=lex
761         break
762       fi
763     done
764     IFS="$save_ifs"
765     LEX=${LEX-flex}
766   fi
767
768   # Export variables which autoconf might try to set.
769   export AS
770   export AR
771   export CC_FOR_BUILD
772   export LD
773   export NM
774   export RANLIB
775 else
776   # If CC is still not set, try to get gcc.
777   if [ -z "${CC}" ]; then
778     IFS="${IFS=         }"; save_ifs="$IFS"; IFS="${IFS}:"
779     for dir in $PATH; do
780       test -z "$dir" && dir=.
781       if test -f $dir/gcc; then
782         CC="gcc -O2"
783         break
784       fi
785     done
786     IFS="$save_ifs"
787     CC=${CC-cc}
788   fi
789
790   CXX=${CXX-"gcc"}
791 fi
792
793 export CC
794 export CXX
795
796 for subdir in . ${subdirs} ; do
797
798     # ${subdir} is relative path from . to the directory we're currently
799     # configuring.
800     # ${invsubdir} is inverse of ${subdir), *with* trailing /, if needed.
801     invsubdir=`echo ${subdir}/ | sed -e 's|\./||g' -e 's|[^/]*/|../|g'`
802
803     ### figure out what to do with srcdir
804     case "${srcdir}" in
805         ".")  # no -srcdir option.  We're building in place.
806                 makesrcdir=. ;;
807         /*) # absolute path
808                 makesrcdir=`echo ${srcdir}/${subdir} | sed -e 's|/\.$||'`
809                 ;;
810         *) # otherwise relative
811                 case "${subdir}" in
812                 .) makesrcdir=${srcdir} ;;
813                 *) makesrcdir=${invsubdir}${srcdir}/${subdir} ;;
814                 esac
815                 ;;
816     esac
817
818     if [ "${subdir}/" != "./" ] ; then
819         Makefile=${subdir}/Makefile
820     fi
821
822     if [ ! -d ${subdir} ] ; then
823         if mkdir ${subdir} ; then
824                 true
825         else
826                 echo '***' "${progname}: could not make ${PWD=`pwd`}/${subdir}" 1>&2
827                 exit 1
828         fi
829     fi
830
831     case "${removing}" in
832     "")
833         case "${subdir}" in
834         .) ;;
835         *) eval echo Building in ${subdir} ${redirect} ;;
836         esac
837
838         # FIXME Should this be done recursively ??? (Useful for e.g. gdbtest)
839         # Set up the list of links to be made.
840         # ${links} is the list of link names, and ${files} is the list of names to link to.
841
842         # Make the links.
843         configlinks="${links}"
844         if [ -r ${subdir}/config.status ] ; then
845                 mv -f ${subdir}/config.status ${subdir}/config.back
846         fi
847         while [ -n "${files}" ] ; do
848                 # set file to car of files, files to cdr of files
849                 set ${files}; file=$1; shift; files=$*
850                 set ${links}; link=$1; shift; links=$*
851
852                 if [ ! -r ${srcdir}/${file} ] ; then
853                         echo '***' "${progname}: cannot create a link \"${link}\"," 1>&2
854                         echo '***' "since the file \"${srcdir}/${file}\" does not exist." 1>&2
855                         exit 1
856                 fi
857
858                 ${remove} -f ${link}
859                 # Make a symlink if possible, otherwise try a hard link
860                 if ${symbolic_link} ${srcdir}/${file} ${link} >/dev/null 2>&1 ; then
861                         true
862                 else
863                         # We need to re-remove the file because Lynx leaves a 
864                         # very strange directory there when it fails an NFS symlink.
865                         ${remove} -r -f ${link}
866                         ${hard_link} ${srcdir}/${file} ${link}
867                 fi
868                 if [ ! -r ${link} ] ; then
869                         echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
870                         exit 1
871                 fi
872
873                 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
874         done
875
876         # Create a .gdbinit file which runs the one in srcdir
877         # and tells GDB to look there for source files.
878
879         if [ -r ${srcdir}/${subdir}/.gdbinit ] ; then
880                 case ${srcdir} in
881                 .) ;;
882                 *) cat > ${subdir}/.gdbinit <<EOF
883 # ${NO_EDIT}
884 dir ${makesrcdir}
885 dir .
886 source ${makesrcdir}/.gdbinit
887 EOF
888                         ;;
889                 esac
890         fi
891
892         # Install a makefile, and make it set VPATH
893         # if necessary so that the sources are found.
894         # Also change its value of srcdir.
895         # NOTE: Makefile generation constitutes the majority of the time in configure.  Hence, this section has
896         # been somewhat optimized and is perhaps a bit twisty.
897
898         # code is order so as to try to sed the smallest input files we know.
899
900         # the four makefile fragments MUST end up in the resulting Makefile in this order: 
901         # package, target, host, and site.  so do these separately because I don't trust the
902         #  order of sed -e expressions.
903
904         if [ -f ${srcdir}/${subdir}/${Makefile_in} ] ; then
905
906             # Conditionalize for this site from "Makefile.in" (or whatever it's called) into Makefile.tem
907             rm -f ${subdir}/Makefile.tem
908               case "${site}" in
909               "") cp ${srcdir}/${subdir}/${Makefile_in} ${subdir}/Makefile.tem ;;
910               *)
911                       site_makefile_frag=${srcdir}/config/ms-${site}
912
913                       if [ -f ${site_makefile_frag} ] ; then
914                               sed -e "/^####/  r ${site_makefile_frag}" ${srcdir}/${subdir}/${Makefile_in} \
915                                       > ${subdir}/Makefile.tem
916                       else
917                               cp ${srcdir}/${subdir}/${Makefile_in} ${subdir}/Makefile.tem
918                               site_makefile_frag=
919                       fi
920                       ;;
921             esac
922             # working copy now in ${subdir}/Makefile.tem
923
924             # Conditionalize the makefile for this host.
925             rm -f ${Makefile}
926             case "${host_makefile_frag}" in
927               "") mv ${subdir}/Makefile.tem ${Makefile} ;;
928               *)
929                       if [ ! -f ${host_makefile_frag} ] ; then
930                               host_makefile_frag=${srcdir}/${host_makefile_frag}
931                       fi
932                       if [ -f ${host_makefile_frag} ] ; then
933                               sed -e "/^####/  r ${host_makefile_frag}" ${subdir}/Makefile.tem > ${Makefile}
934                       else
935                               echo '***' Expected host makefile fragment \"${host_makefile_frag}\" 1>&2
936                               echo '***' is missing in ${PWD=`pwd`}. 1>&2
937                               mv ${subdir}/Makefile.tem ${Makefile}
938                       fi
939             esac
940             # working copy now in ${Makefile}
941
942             # Conditionalize the makefile for this target.
943             rm -f ${subdir}/Makefile.tem
944             case "${target_makefile_frag}" in
945               "") mv ${Makefile} ${subdir}/Makefile.tem ;;
946               *)
947                       if [ ! -f ${target_makefile_frag} ] ; then
948                               target_makefile_frag=${srcdir}/${target_makefile_frag}
949                       fi
950                       if [ -f ${target_makefile_frag} ] ; then
951                               sed -e "/^####/  r ${target_makefile_frag}" ${Makefile} > ${subdir}/Makefile.tem
952                       else
953                               mv ${Makefile} ${subdir}/Makefile.tem
954                               target_makefile_frag=
955                       fi
956                       ;;
957             esac
958             # real copy now in ${subdir}/Makefile.tem
959
960             # Conditionalize the makefile for this package.
961             rm -f ${Makefile}
962             case "${package_makefile_frag}" in
963               "") mv ${subdir}/Makefile.tem ${Makefile} ;;
964               *)
965                       if [ ! -f ${package_makefile_frag} ] ; then
966                               package_makefile_frag=${srcdir}/${package_makefile_frag}
967                       fi
968                       if [ -f ${package_makefile_frag} ] ; then
969                               sed -e "/^####/  r ${package_makefile_frag}" ${subdir}/Makefile.tem > ${Makefile}
970                               rm -f ${subdir}/Makefile.tem
971                       else
972                               echo '***' Expected package makefile fragment \"${package_makefile_frag}\" 1>&2
973                               echo '***' is missing in ${PWD=`pwd`}. 1>&2
974                               mv ${subdir}/Makefile.tem ${Makefile}
975                       fi
976             esac
977             # working copy now in ${Makefile}
978
979             mv ${Makefile} ${subdir}/Makefile.tem
980
981             # real copy now in ${subdir}/Makefile.tem
982
983             # prepend warning about editting, and a bunch of variables.
984             rm -f ${Makefile}
985             cat > ${Makefile} <<EOF
986 # ${NO_EDIT}
987 VPATH = ${makesrcdir}
988 links = ${configlinks}
989 host_alias = ${host_alias}
990 host_cpu = ${host_cpu}
991 host_vendor = ${host_vendor}
992 host_os = ${host_os}
993 host_canonical = ${host_cpu}-${host_vendor}-${host_os}
994 target_alias = ${target_alias}
995 target_cpu = ${target_cpu}
996 target_vendor = ${target_vendor}
997 target_os = ${target_os}
998 target_canonical = ${target_cpu}-${target_vendor}-${target_os}
999 EOF
1000             case "${build}" in
1001               "") ;;
1002               *)  cat >> ${Makefile} << EOF
1003 build_alias = ${build_alias}
1004 build_cpu = ${build_cpu}
1005 build_vendor = ${build_vendor}
1006 build_os = ${build_os}
1007 build_canonical = ${build_cpu}-${build_vendor}-${build_os}
1008 EOF
1009             esac
1010
1011             case "${package_makefile_frag}" in
1012               "") ;;
1013               /*) echo package_makefile_frag = ${package_makefile_frag} >>${Makefile} ;;
1014               *)  echo package_makefile_frag = ${invsubdir}${package_makefile_frag} >>${Makefile} ;;
1015             esac
1016
1017             case "${target_makefile_frag}" in
1018               "") ;;
1019               /*) echo target_makefile_frag = ${target_makefile_frag} >>${Makefile} ;;
1020               *)  echo target_makefile_frag = ${invsubdir}${target_makefile_frag} >>${Makefile} ;;
1021             esac
1022
1023             case "${host_makefile_frag}" in
1024               "") ;;
1025               /*) echo host_makefile_frag = ${host_makefile_frag} >>${Makefile} ;;
1026               *)  echo host_makefile_frag = ${invsubdir}${host_makefile_frag} >>${Makefile} ;;
1027             esac
1028
1029             if [ "${site_makefile_frag}" != "" ] ; then
1030                 echo site_makefile_frag = ${invsubdir}${site_makefile_frag} >>${Makefile}
1031             fi 
1032
1033             # reset prefix, exec_prefix, srcdir, SUBDIRS, NONSUBDIRS,
1034             # remove any form feeds.
1035             if [ -z "${subdirs}" ]; then
1036                 rm -f ${subdir}/Makefile.tem2
1037                 sed -e "s:^SUBDIRS[     ]*=.*$:SUBDIRS = ${configdirs}:" \
1038                     -e "s:^NONSUBDIRS[  ]*=.*$:NONSUBDIRS = ${noconfigdirs}:" \
1039                     ${subdir}/Makefile.tem > ${subdir}/Makefile.tem2
1040                 rm -f ${subdir}/Makefile.tem
1041                 mv ${subdir}/Makefile.tem2 ${subdir}/Makefile.tem
1042             fi
1043             sed -e "s:^prefix[  ]*=.*$:prefix = ${prefix}:" \
1044                     -e "s:^exec_prefix[         ]*=.*$:exec_prefix = ${exec_prefix}:" \
1045                     -e "/^CC[   ]*=/{
1046                         :loop1
1047                         /\\\\$/ N
1048                         /\\\\$/ b loop1
1049                         s/\\\\\\n//g
1050                         s%^CC[  ]*=.*$%CC = ${CC}%
1051                         }" \
1052                     -e "/^CXX[  ]*=/{
1053                         :loop2
1054                         /\\\\$/ N
1055                         /\\\\$/ b loop2
1056                         s/\\\\\\n//g
1057                         s%^CXX[         ]*=.*$%CXX = ${CXX}%
1058                         }" \
1059                     -e "s:^SHELL[        ]*=.*$:SHELL = ${config_shell}:" \
1060                     -e "s:^srcdir[      ]*=.*$:srcdir = ${makesrcdir}:" \
1061                     -e "s/\f//" \
1062                     -e "s:^program_prefix[      ]*=.*$:program_prefix = ${program_prefix}:" \
1063                     -e "s:^program_suffix[      ]*=.*$:program_suffix = ${program_suffix}:" \
1064                     -e "s:^program_transform_name[      ]*=.*$:program_transform_name = ${program_transform_name}:" \
1065                     -e "s:^tooldir[     ]*=.*$:tooldir = ${tooldir}:" \
1066                     ${subdir}/Makefile.tem >> ${Makefile}
1067
1068             # If this is a Canadian Cross, preset the values of many more
1069             # tools.
1070             if [ "${build}" != "${host}" ]; then
1071                 for var in ${tools}; do
1072                     val=`eval 'echo $'"${var}"`
1073                     sed -e "/^${var}[   ]*=/{
1074                            :loop1
1075                            /\\\\$/ N
1076                            /\\\\$/ b loop1
1077                            s/\\\\\\n//g
1078                            s%^${var}[   ]*=.*$%${var} = ${val}%
1079                            }" ${Makefile} > ${Makefile}.tem
1080                     mv -f ${Makefile}.tem ${Makefile}
1081                 done
1082             fi
1083
1084             # final copy now in ${Makefile}
1085
1086         else
1087            echo "No Makefile.in found in ${srcdir}/${subdir}, unable to configure" 1>&2
1088         fi
1089
1090         rm -f ${subdir}/Makefile.tem
1091
1092         case "${host_makefile_frag}" in
1093         "") using= ;;
1094         *) using="and \"${host_makefile_frag}\"" ;;
1095         esac
1096
1097         case "${target_makefile_frag}" in
1098         "") ;;
1099         *) using="${using} and \"${target_makefile_frag}\"" ;;
1100         esac
1101
1102         case "${site_makefile_frag}" in
1103         "") ;;
1104         *) using="${using} and \"${site_makefile_frag}\"" ;;
1105         esac
1106
1107         newusing=`echo "${using}" | sed 's/and/using/'`
1108         using=${newusing}
1109         echo "Created \"${Makefile}\" in" ${PWD=`pwd`} ${using}
1110
1111         . ${tmpfile}.pos
1112
1113         # describe the chosen configuration in config.status.
1114         # Make that file a shellscript which will reestablish
1115         # the same configuration.  Used in Makefiles to rebuild
1116         # Makefiles.
1117
1118         case "${norecursion}" in
1119         "") arguments="${arguments} --norecursion" ;;
1120         *) ;;
1121         esac
1122
1123         if [ ${subdir} = . ] ; then
1124             echo "#!/bin/sh
1125 # ${NO_EDIT}
1126 # This directory was configured as follows:
1127 ${progname}" ${arguments}  "
1128 # ${using}" > ${subdir}/config.new
1129         else
1130             echo "#!/bin/sh
1131 # ${NO_EDIT}
1132 # This directory was configured as follows:
1133 cd ${invsubdir}
1134 ${progname}" ${arguments}  "
1135 # ${using}" > ${subdir}/config.new
1136         fi
1137         chmod a+x ${subdir}/config.new
1138         if [ -r ${subdir}/config.back ] ; then
1139                 mv -f ${subdir}/config.back ${subdir}/config.status
1140         fi
1141         ${moveifchange} ${subdir}/config.new ${subdir}/config.status
1142         ;;
1143
1144     *)  rm -f ${Makefile} ${subdir}/config.status ${links} ;;
1145     esac
1146 done
1147
1148 # If there are subdirectories, then recur. 
1149 if [ -z "${norecursion}" -a -n "${configdirs}" ] ; then 
1150         for configdir in ${configdirs} ; do
1151
1152                 if [ -d ${srcdir}/${configdir} ] ; then
1153                         eval echo Configuring ${configdir}... ${redirect}
1154                         case "${srcdir}" in
1155                         ".") ;;
1156                         *)
1157                                 if [ ! -d ./${configdir} ] ; then
1158                                         if mkdir ./${configdir} ; then
1159                                                 true
1160                                         else
1161                                                 echo '***' "${progname}: could not make ${PWD=`pwd`}/${configdir}" 1>&2
1162                                                 exit 1
1163                                         fi
1164                                 fi
1165                                 ;;
1166                         esac
1167
1168                         POPDIR=${PWD=`pwd`}
1169                         cd ${configdir} 
1170
1171 ### figure out what to do with srcdir
1172                         case "${srcdir}" in
1173                         ".") newsrcdir=${srcdir} ;; # no -srcdir option.  We're building in place.
1174                         /*) # absolute path
1175                                 newsrcdir=${srcdir}/${configdir}
1176                                 srcdiroption="--srcdir=${newsrcdir}"
1177                                 ;;
1178                         *) # otherwise relative
1179                                 newsrcdir=../${srcdir}/${configdir}
1180                                 srcdiroption="--srcdir=${newsrcdir}"
1181                                 ;;
1182                         esac
1183
1184                         # Handle --cache-file=../XXX
1185                         case "${cache_file}" in
1186                         "") # empty
1187                                 ;;
1188                         /*) # absolute path
1189                                 cache_file_option="--cache-file=${cache_file}"
1190                                 ;;
1191                         *) # relative path
1192                                 cache_file_option="--cache-file=../${cache_file}"
1193                                 ;;
1194                         esac
1195
1196 ### check for guested configure, otherwise fix possibly relative progname
1197                         if [ -f ${newsrcdir}/configure ] ; then
1198                                 recprog=${newsrcdir}/configure
1199                         elif [ -f ${newsrcdir}/configure.in ] ; then
1200                                 case "${progname}" in
1201                                 /*)     recprog=${progname} ;;
1202                                 *)      recprog=../${progname} ;;
1203                                 esac
1204                         else
1205                                 eval echo No configuration information in ${configdir} ${redirect}
1206                                 recprog=
1207                         fi
1208
1209 ### The recursion line is here.
1210                         if [ ! -z "${recprog}" ] ; then
1211                                 if eval ${config_shell} ${recprog} ${verbose} ${buildopt} --host=${host_alias} --target=${target_alias} \
1212                                         ${prefixoption} ${tmpdiroption} ${exec_prefixoption} \
1213                                         ${srcdiroption} ${program_prefixoption} ${program_suffixoption} ${program_transform_nameoption} ${site_option} ${withoptions} ${withoutoptions} ${enableoptions} ${disableoptions} ${cache_file_option} ${removing} ${other_options} ${redirect} ; then
1214                                         true
1215                                 else
1216                                         echo Configure in `pwd` failed, exiting. 1>&2
1217                                         exit 1
1218                                 fi
1219                         fi
1220
1221                         cd ${POPDIR}
1222                 fi
1223         done
1224 fi
1225
1226 # Perform the same cleanup as the trap handler, minus the "exit 1" of course,
1227 # and reset the trap handler.
1228 rm -f ${tmpfile}.com ${tmpfile}.tgt ${tmpfile}.hst ${tmpfile}.pos
1229 trap 0
1230
1231 exit 0
1232
1233 #
1234 # Local Variables:
1235 # fill-column: 131
1236 # End:
1237 #
1238
1239 # end of configure