* configure: Search current dir first in .gdbinit.
[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., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 # Please email any bugs, comments, and/or additions to this file to:
23 # configure@cygnus.com
24
25 # This file was written by K. Richard Pixley.
26
27 #
28 # Shell script to create proper links to machine-dependent files in
29 # preparation for compilation.
30 #
31 # If configure succeeds, it leaves its status in config.status.
32 # If configure fails after disturbing the status quo, 
33 #       config.status is removed.
34 #
35
36 export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0 $argv; kill $$)
37
38 remove=rm
39 hard_link=ln
40 symbolic_link='ln -s'
41
42 #for Test
43 #remove="echo rm"
44 #hard_link="echo ln"
45 #symbolic_link="echo ln -s"
46
47 # clear some things potentially inherited from environment.
48
49 Makefile=Makefile
50 Makefile_in=Makefile.in
51 arguments=$*
52 build_alias=
53 configdirs=
54 exec_prefix=
55 exec_prefixoption=
56 fatal=
57 floating_point=default
58 gas=default
59 host_alias=NOHOST
60 host_makefile_frag=
61 moveifchange=
62 norecursion=
63 other_options=
64 package_makefile_frag=
65 prefix=/usr/local
66 progname=
67 program_prefix=
68 program_prefixoption=
69 program_suffix=
70 program_suffixoption=
71 program_transform_name=
72 program_transform_nameoption=
73 redirect=">/dev/null"
74 removing=
75 site=
76 site_makefile_frag=
77 site_option=
78 srcdir=
79 srctrigger=
80 subdirs=
81 target_alias=NOTARGET
82 target_makefile_frag=
83 undefs=NOUNDEFS
84 version="$Revision$"
85 x11=default
86
87 ### we might need to use some other shell than /bin/sh for running subshells
88 #
89 config_shell=${CONFIG_SHELL-/bin/sh}
90
91 NO_EDIT="This file was generated automatically by configure.  Do not edit."
92
93 ## this is a little touchy and won't always work, but...
94 ##
95 ## if the argv[0] starts with a slash then it is an absolute name that can (and
96 ## must) be used as is.
97 ##
98 ## otherwise, if argv[0] has no slash in it, we can assume that it is on the
99 ## path.  Since PATH might include "." we also add `pwd` to the end of PATH.
100 ##
101
102 progname=$0
103 # if PWD already has a value, it is probably wrong.
104 if [ -n "$PWD" ]; then PWD=`pwd`; fi
105
106 case "${progname}" in
107 /*) ;;
108 */*) ;;
109 *)
110         PATH=$PATH:${PWD=`pwd`} ; export PATH
111         ;;
112 esac
113
114 # Loop over all args
115
116 while :
117 do
118
119 # Break out if there are no more args
120         case $# in
121         0)
122                 break
123                 ;;
124         esac
125
126 # Get the first arg, and shuffle
127         option=$1
128         shift
129
130 # Make all options have two hyphens
131         orig_option=$option     # Save original for error messages
132         case $option in
133         --*) ;;
134         -*) option=-$option ;;
135         esac
136                 
137 # Split out the argument for options that take them
138         case $option in
139         --*=*)
140                 optarg=`echo $option | sed -e 's/^[^=]*=//'`
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* | --ex* | --ho* | --pre* | --program-p* | --program-s* | --program-t* | --si* | --sr* | --ta* | --tm* | --x-*)
145                 optarg=$1
146                 shift
147                 ;;
148         esac
149
150 # Now, process the options
151         case $option in
152
153         --build* | --b*)
154                 case "$build_alias" in
155                 "") build_alias=$optarg ;;
156                 *) echo '***' Can only configure for one build machine at a time.  1>&2
157                    fatal=yes
158                    ;;
159                 esac
160                 ;;
161         --disable-*)
162                 enableopt=`echo ${option} | sed 's:^--disable-:enable_:;s:-:_:g'`
163                 eval $enableopt=no
164                 disableoptions="$disableoptions $option"
165                 ;;
166         --enable-*)
167                 case "$option" in
168                 *=*)    ;;
169                 *)      optarg=yes ;;
170                 esac
171
172                 enableopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
173                 eval $enableopt="$optarg"
174                 enableoptions="$enableoptions $option"
175                 ;;
176         --exec-prefix* | --ex*)
177                 exec_prefix=$optarg
178                 exec_prefixoption="--exec-prefix=$optarg"
179                 ;;
180         --gas | --g*)
181                 gas=yes
182                 ;;
183         --help | --he*)
184                 fatal=yes
185                 ;;
186         --host* | --ho*)
187                 case $host_alias in
188                 NOHOST) host_alias=$optarg ;;
189                 *) echo '***' Can only configure for one host at a time.  1>&2
190                    fatal=yes
191                    ;;
192                 esac
193                 ;;
194         --nfp | --nf*)
195                 floating_point=no
196                 ;;
197         --norecursion | --no*)
198                 norecursion=yes
199                 ;;
200         --prefix* | --pre*)
201                 prefix=$optarg
202                 prefixoption="--prefix=$optarg"
203                 ;;
204         --program-prefix* | --program-p*)
205                 program_prefix=$optarg
206                 program_prefixoption="--program-prefix=$optarg"
207                 ;;
208         --program-suffix* | --program-s*)
209                 program_suffix=$optarg
210                 program_suffixoption="--program-suffix=$optarg"
211                 ;;
212         --program-transform-name* | --program-t*)
213                 # Double any backslashes or dollar signs in the argument
214                 program_transform_name="${program_transform_name} -e `echo ${optarg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`"
215                 program_transform_nameoption="${program_transform_nameoption} --program-transform-name='$optarg'"
216                 ;;
217         --rm)
218                 removing=--rm
219                 ;;
220         --silent | --sil* | --quiet | --q*)
221                 redirect=">/dev/null"
222                 verbose=--silent
223                 ;;
224         --site* | --sit*)
225                 site=$optarg
226                 site_option="--site=$optarg"
227                 ;;
228         --srcdir*/ | --sr*/)
229                 # Remove trailing slashes.  Otherwise, when the file name gets
230                 # bolted into an object file as debug info, it has two slashes
231                 # in it.  Ordinarily this is ok, but emacs takes double slash
232                 # to mean "forget the first part".
233                 srcdir=`echo $optarg | sed -e 's:/$::'`
234                 ;;
235         --srcdir* | --sr*)
236                 srcdir=$optarg
237                 ;;
238         --target* | --ta*)
239                 case $target_alias in
240                 NOTARGET) target_alias=$optarg ;;
241                 *) echo '***' Can only configure for one target at a time.  1>&2
242                    fatal=yes
243                    ;;
244                 esac
245                 ;;
246         --tmpdir* | --tm*)
247                 TMPDIR=$optarg
248                 tmpdiroption="--tmpdir=$optarg"
249                 ;;
250         --verbose | --v | --verb*)
251                 redirect=
252                 verbose=--verbose
253                 ;;
254         --version | --V | --vers*)
255                 echo "This is Cygnus Configure version" `echo ${version} | sed 's/[ $:]//g'`
256                 exit 0
257                 ;;
258         --with-*)
259                 case "$option" in
260                 *=*)    ;;
261                 *)      optarg=yes ;;
262                 esac
263
264                 withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
265                 eval $withopt="$optarg"
266                 withoptions="$withoptions $option"
267                 ;;
268         --without-*)
269                 withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g'`
270                 eval $withopt=no
271                 withoutoptions="$withoutoptions $option"
272                 ;;
273         --x)    with_x=yes
274                 withoptions="$withoptions --with-x"
275                 ;;
276         --x-i* | --x-l*) other_options="$other_options $orig_option"
277                 ;;
278         --*)
279                 echo "configure: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
280                 exit 1
281                 ;;
282         *)
283                 case $undefs in
284                 NOUNDEFS) undefs=$option ;;
285                 *) echo '***' Can only configure for one host and one target at a time.  1>&2
286                    fatal=yes
287                    ;;
288                 esac
289                 ;;
290         esac
291 done
292
293 # process host and target
294
295 # Do some error checking and defaulting for the host and target type.
296 # The inputs are:
297 #    configure --host=HOST --target=TARGET UNDEFS
298 #
299 # The rules are:
300 # 1. You aren't allowed to specify --host, --target, and undefs at the
301 #    same time.
302 # 2. Host defaults to undefs.
303 # 3. If undefs is not specified, then host defaults to the current host,
304 #    as determined by config.guess.
305 # 4. Target defaults to undefs.
306 # 5. If undefs is not specified, then target defaults to host.
307
308 case "${fatal}" in
309 "")
310         # Make sure that host, target & undefs aren't all specified at the
311         # same time.
312         case $host_alias---$target_alias---$undefs in
313         NOHOST---*---* | *---NOTARGET---* | *---*---NOUNDEFS)
314                 ;;
315         *) echo '***' Can only configure for one host and one target at a time.  1>&2
316            fatal=yes
317            break 2
318                 ;;
319         esac
320
321         # Now, do defaulting for host.
322         case $host_alias in
323         NOHOST)
324                 case $undefs in
325                 NOUNDEFS)
326                         # Neither --host option nor undefs were present.
327                         # Call config.guess.
328                         guesssys=`echo ${progname} | sed 's/configure$/config.guess/'`
329                         if host_alias=`${guesssys}`
330                         then
331                                 # If the string we are going to use for
332                                 # the target is a prefix of the string
333                                 # we just guessed for the host, then
334                                 # assume we are running native, and force
335                                 # the same string for both target and host.
336                                 case $target_alias in
337                                 NOTARGET)
338                                         case $undefs in
339                                         NOUNDEFS) ;;
340                                         *)
341                                             if expr $host_alias : $undefs >/dev/null
342                                             then
343                                                 host_alias=$undefs
344                                             fi
345                                             ;;
346                                         esac
347                                         ;;
348                                 *)
349                                         if expr $host_alias : $target_alias >/dev/null
350                                         then
351                                                 host_alias=$target_alias
352                                         fi
353                                         ;;
354                                 esac
355                                 echo "Configuring for a ${host_alias} host." 1>&2
356                                 arguments="--host=$host_alias $arguments"
357                         else
358                                 echo 'Config.guess failed to determine the host type.  You need to specify one.' 1>&2
359                                 fatal=yes
360                         fi
361                         ;;
362                 *)
363                         host_alias=$undefs
364                         ;;
365                 esac
366         esac
367
368         # Do defaulting for target.  If --target option isn't present, default
369         # to undefs.  If undefs isn't present, default to host.
370         case $target_alias in
371         NOTARGET)
372                 case $undefs in
373                 NOUNDEFS)
374                         target_alias=$host_alias
375                         ;;
376                 *)
377                         target_alias=$undefs
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            configure for installation of host independent files into MYDIR. ["/usr/local"]'
391         echo ' --exec-prefix=MYDIR       configure for installation of 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      install programs with FOO prepended to their names. [ "" ]'
397         echo ' --program-suffix=FOO      install programs with FOO appended to their names. [ "" ]'
398         echo ' --program-transform-name=FOO install programs with names transformed by sed pattern FOO. [ "" ]'
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.  [ TMPDIR = "/tmp" ]'
403         echo ' --nfp                     configure the compilers default to soft 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 "sun4", "decstation", "encore", 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 esac
453
454 ### warn about some conflicting configurations.
455
456 case "${srcdir}" in
457 ".") ;;
458 *)
459         if [ -f ${srcdir}/config.status ] ; then
460                 echo '***' Cannot configure here in \"${PWD=`pwd`}\" when \"${srcdir}\" is currently configured. 1>&2
461                 exit 1
462         fi
463 esac
464
465 # default exec_prefix
466 case "${exec_prefixoption}" in
467 "") exec_prefix="\$(prefix)" ;;
468 *) ;;
469 esac
470
471 ### break up ${srcdir}/configure.in.
472 case "`grep '^# per\-host:' ${srcdir}/configure.in`" in
473 "")
474         echo '***' ${srcdir}/configure.in has no \"per-host:\" line. 1>&2
475         exit 1
476         ;;
477 *) ;;
478 esac
479
480 case "`grep '^# per\-target:' ${srcdir}/configure.in`" in
481 "")
482         echo '***' ${srcdir}/configure.in has no \"per-target:\" line. 1>&2
483         exit 1
484         ;;
485 *) ;;
486 esac
487
488 case "${TMPDIR}" in
489 "") TMPDIR=/tmp ; export TMPDIR ;;
490 *) ;;
491 esac
492
493 # keep this filename short for &%*%$*# 14 char file names
494 tmpfile=${TMPDIR}/cONf$$
495 trap "rm -f ${tmpfile}.com ${tmpfile}.tgt ${tmpfile}.hst ${tmpfile}.pos; exit 1" 1 2 15
496 trap "rm -f ${tmpfile}.com ${tmpfile}.tgt ${tmpfile}.hst ${tmpfile}.pos" 0
497
498 # split ${srcdir}/configure.in into common, per-host, per-target,
499 # and post-target parts.  Post-target is optional.
500 sed -e '/^# per\-host:/,$d' ${srcdir}/configure.in > ${tmpfile}.com
501 sed -e '1,/^# per\-host:/d' -e '/^# per\-target:/,$d' ${srcdir}/configure.in > ${tmpfile}.hst
502 if grep '^# post-target:' ${srcdir}/configure.in >/dev/null ; then
503   sed -e '1,/^# per\-target:/d' -e '/^# post\-target:/,$d' ${srcdir}/configure.in > ${tmpfile}.tgt
504   sed -e '1,/^# post\-target:/d' ${srcdir}/configure.in > ${tmpfile}.pos
505 else
506   sed -e '1,/^# per\-target:/d' ${srcdir}/configure.in > ${tmpfile}.tgt
507   echo >${tmpfile}.pos
508 fi
509
510 ### do common part of configure.in
511
512 . ${tmpfile}.com
513
514 # some sanity checks on configure.in
515 case "${srctrigger}" in
516 "")
517         echo '***' srctrigger not set in ${PWD=`pwd`}/configure.in.  1>&2
518         exit 1
519         ;;
520 *) ;;
521 esac
522
523 case "${build_alias}" in
524 "")     ;;
525 *)
526         result=`${configsub} ${build_alias}`
527         buildopt="--build=${build_alias}"
528         build_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
529         build_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
530         build_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
531         build=${build_cpu}-${build_vendor}-${build_os}
532         ;;
533 esac
534
535 result=`${configsub} ${host_alias}`
536 host_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
537 host_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
538 host_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
539 host=${host_cpu}-${host_vendor}-${host_os}
540
541 . ${tmpfile}.hst
542
543 result=`${configsub} ${target_alias}`
544 target_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
545 target_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
546 target_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
547 target=${target_cpu}-${target_vendor}-${target_os}
548
549 . ${tmpfile}.tgt
550
551 # Find the source files, if location was not specified.
552 case "${srcdir}" in
553 "")
554         srcdirdefaulted=1
555         srcdir=.
556         if [ ! -r ${srctrigger} ] ; then
557                 srcdir=..
558         fi
559         ;;
560 *) ;;
561 esac
562
563 if [ ! -r ${srcdir}/${srctrigger} ] ; then
564         case "${srcdirdefaulted}" in
565         "") echo '***' "${progname}: Can't find ${srcname} sources in ${PWD=`pwd`}/${srcdir}" 1>&2 ;;
566         *)  echo '***' "${progname}: Can't find ${srcname} sources in ${PWD=`pwd`}/. or ${PWD=`pwd`}/.." 1>&2 ;;
567         esac
568
569         echo '***' \(At least ${srctrigger} is missing.\) 1>&2
570         exit 1
571 fi
572
573 # Some systems (e.g., one of the i386-aix systems the gas testers are
574 # using) don't handle "\$" correctly, so don't use it here.
575 tooldir='$(exec_prefix)'/${target_alias}
576
577 if [ "${host_alias}" != "${target_alias}" ] ; then
578     if [ "${program_prefixoption}" = "" ] ; then
579         if [ "${program_suffixoption}" = "" ] ; then 
580             if [ "${program_transform_nameoption}" = "" ] ; then
581                 program_prefix=${target_alias}- ;
582             fi
583         fi
584     fi
585 fi
586
587 # Merge program_prefix and program_suffix onto program_transform_name
588 # Use a double $ so that make ignores it
589 if [ "${program_suffix}" != "" ] ; then
590     program_transform_name="-e s,\$\$,${program_suffix}, ${program_transform_name}"
591 fi
592
593 if [ "${program_prefix}" != "" ] ; then
594     program_transform_name="-e s,^,${program_prefix}, ${program_transform_name}"
595 fi
596
597 for subdir in . ${subdirs} ; do
598
599     # ${subdir} is relative path from . to the directory we're currently
600     # configuring.
601     # ${invsubdir} is inverse of ${subdir), *with* trailing /, if needed.
602     invsubdir=`echo ${subdir}/ | sed -e 's|\./||g' -e 's|[^/]*/|../|g'`
603
604     ### figure out what to do with srcdir
605     case "${srcdir}" in
606         ".")  # no -srcdir option.  We're building in place.
607                 makesrcdir=. ;;
608         /*) # absolute path
609                 makesrcdir=`echo ${srcdir}/${subdir} | sed -e 's|/\.$||'`
610                 ;;
611         *) # otherwise relative
612                 case "${subdir}" in
613                 .) makesrcdir=${srcdir} ;;
614                 *) makesrcdir=${invsubdir}${srcdir}/${subdir} ;;
615                 esac
616                 ;;
617     esac
618
619     if [ "${subdir}/" != "./" ] ; then
620         Makefile=${subdir}/Makefile
621     fi
622
623     if [ ! -d ${subdir} ] ; then
624         if mkdir ${subdir} ; then
625                 true
626         else
627                 echo '***' "${progname}: could not make ${PWD=`pwd`}/${subdir}" 1>&2
628                 exit 1
629         fi
630     fi
631
632     case "${removing}" in
633     "")
634         case "${subdir}" in
635         .) ;;
636         *) eval echo Building in ${subdir} ${redirect} ;;
637         esac
638
639         # FIXME Should this be done recursively ??? (Useful for e.g. gdbtest)
640         # Set up the list of links to be made.
641         # ${links} is the list of link names, and ${files} is the list of names to link to.
642
643         # Make the links.
644         configlinks="${links}"
645         if [ -r ${subdir}/config.status ] ; then
646                 mv -f ${subdir}/config.status ${subdir}/config.back
647         fi
648         while [ -n "${files}" ] ; do
649                 # set file to car of files, files to cdr of files
650                 set ${files}; file=$1; shift; files=$*
651                 set ${links}; link=$1; shift; links=$*
652
653                 if [ ! -r ${srcdir}/${file} ] ; then
654                         echo '***' "${progname}: cannot create a link \"${link}\"," 1>&2
655                         echo '***' "since the file \"${srcdir}/${file}\" does not exist." 1>&2
656                         exit 1
657                 fi
658
659                 ${remove} -f ${link}
660                 # Make a symlink if possible, otherwise try a hard link
661                 if ${symbolic_link} ${srcdir}/${file} ${link} >/dev/null 2>&1 ; then
662                         true
663                 else
664                         # We need to re-remove the file because Lynx leaves a 
665                         # very strange directory there when it fails an NFS symlink.
666                         ${remove} -r -f ${link}
667                         ${hard_link} ${srcdir}/${file} ${link}
668                 fi
669                 if [ ! -r ${link} ] ; then
670                         echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
671                         exit 1
672                 fi
673
674                 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
675         done
676
677         # Create a .gdbinit file which runs the one in srcdir
678         # and tells GDB to look there for source files.
679
680         if [ -r ${srcdir}/${subdir}/.gdbinit ] ; then
681                 case ${srcdir} in
682                 .) ;;
683                 *) cat > ${subdir}/.gdbinit <<EOF
684 # ${NO_EDIT}
685 dir ${makesrcdir}
686 dir .
687 source ${makesrcdir}/.gdbinit
688 EOF
689                         ;;
690                 esac
691         fi
692
693         # Install a makefile, and make it set VPATH
694         # if necessary so that the sources are found.
695         # Also change its value of srcdir.
696         # NOTE: Makefile generation constitutes the majority of the time in configure.  Hence, this section has
697         # been somewhat optimized and is perhaps a bit twisty.
698
699         # code is order so as to try to sed the smallest input files we know.
700
701         # the four makefile fragments MUST end up in the resulting Makefile in this order: 
702         # package, target, host, and site.  so do these separately because I don't trust the
703         #  order of sed -e expressions.
704
705         if [ -f ${srcdir}/${subdir}/${Makefile_in} ] ; then
706
707             # Conditionalize for this site from "Makefile.in" (or whatever it's called) into Makefile.tem
708             rm -f ${subdir}/Makefile.tem
709               case "${site}" in
710               "") cp ${srcdir}/${subdir}/${Makefile_in} ${subdir}/Makefile.tem ;;
711               *)
712                       site_makefile_frag=${srcdir}/config/ms-${site}
713
714                       if [ -f ${site_makefile_frag} ] ; then
715                               sed -e "/^####/  r ${site_makefile_frag}" ${srcdir}/${subdir}/${Makefile_in} \
716                                       > ${subdir}/Makefile.tem
717                       else
718                               cp ${srcdir}/${subdir}/${Makefile_in} ${subdir}/Makefile.tem
719                               site_makefile_frag=
720                       fi
721                       ;;
722             esac
723             # working copy now in ${subdir}/Makefile.tem
724
725             # Conditionalize the makefile for this host.
726             rm -f ${Makefile}
727             case "${host_makefile_frag}" in
728               "") mv ${subdir}/Makefile.tem ${Makefile} ;;
729               *)
730                       if [ ! -f ${host_makefile_frag} ] ; then
731                               host_makefile_frag=${srcdir}/${host_makefile_frag}
732                       fi
733                       if [ -f ${host_makefile_frag} ] ; then
734                               sed -e "/^####/  r ${host_makefile_frag}" ${subdir}/Makefile.tem > ${Makefile}
735                       else
736                               echo '***' Expected host makefile fragment \"${host_makefile_frag}\" 1>&2
737                               echo '***' is missing in ${PWD=`pwd`}. 1>&2
738                               mv ${subdir}/Makefile.tem ${Makefile}
739                       fi
740             esac
741             # working copy now in ${Makefile}
742
743             # Conditionalize the makefile for this target.
744             rm -f ${subdir}/Makefile.tem
745             case "${target_makefile_frag}" in
746               "") mv ${Makefile} ${subdir}/Makefile.tem ;;
747               *)
748                       if [ ! -f ${target_makefile_frag} ] ; then
749                               target_makefile_frag=${srcdir}/${target_makefile_frag}
750                       fi
751                       if [ -f ${target_makefile_frag} ] ; then
752                               sed -e "/^####/  r ${target_makefile_frag}" ${Makefile} > ${subdir}/Makefile.tem
753                       else
754                               mv ${Makefile} ${subdir}/Makefile.tem
755                               target_makefile_frag=
756                       fi
757                       ;;
758             esac
759             # real copy now in ${subdir}/Makefile.tem
760
761             # Conditionalize the makefile for this package.
762             rm -f ${Makefile}
763             case "${package_makefile_frag}" in
764               "") mv ${subdir}/Makefile.tem ${Makefile} ;;
765               *)
766                       if [ ! -f ${package_makefile_frag} ] ; then
767                               package_makefile_frag=${srcdir}/${package_makefile_frag}
768                       fi
769                       if [ -f ${package_makefile_frag} ] ; then
770                               sed -e "/^####/  r ${package_makefile_frag}" ${subdir}/Makefile.tem > ${Makefile}
771                               rm -f ${subdir}/Makefile.tem
772                       else
773                               echo '***' Expected package makefile fragment \"${package_makefile_frag}\" 1>&2
774                               echo '***' is missing in ${PWD=`pwd`}. 1>&2
775                               mv ${subdir}/Makefile.tem ${Makefile}
776                       fi
777             esac
778             # working copy now in ${Makefile}
779
780             mv ${Makefile} ${subdir}/Makefile.tem
781
782             # real copy now in ${subdir}/Makefile.tem
783
784             # prepend warning about editting, and a bunch of variables.
785             rm -f ${Makefile}
786             cat > ${Makefile} <<EOF
787 # ${NO_EDIT}
788 VPATH = ${makesrcdir}
789 links = ${configlinks}
790 host_alias = ${host_alias}
791 host_cpu = ${host_cpu}
792 host_vendor = ${host_vendor}
793 host_os = ${host_os}
794 host_canonical = ${host_cpu}-${host_vendor}-${host_os}
795 target_alias = ${target_alias}
796 target_cpu = ${target_cpu}
797 target_vendor = ${target_vendor}
798 target_os = ${target_os}
799 target_canonical = ${target_cpu}-${target_vendor}-${target_os}
800 EOF
801             case "${build}" in
802               "") ;;
803               *)  cat >> ${Makefile} << EOF
804 build_alias = ${build_alias}
805 build_cpu = ${build_cpu}
806 build_vendor = ${build_vendor}
807 build_os = ${build_os}
808 build_canonical = ${build_cpu}-${build_vendor}-${build_os}
809 EOF
810             esac
811
812             case "${package_makefile_frag}" in
813               "") ;;
814               /*) echo package_makefile_frag = ${package_makefile_frag} >>${Makefile} ;;
815               *)  echo package_makefile_frag = ${invsubdir}${package_makefile_frag} >>${Makefile} ;;
816             esac
817
818             case "${target_makefile_frag}" in
819               "") ;;
820               /*) echo target_makefile_frag = ${target_makefile_frag} >>${Makefile} ;;
821               *)  echo target_makefile_frag = ${invsubdir}${target_makefile_frag} >>${Makefile} ;;
822             esac
823
824             case "${host_makefile_frag}" in
825               "") ;;
826               /*) echo host_makefile_frag = ${host_makefile_frag} >>${Makefile} ;;
827               *)  echo host_makefile_frag = ${invsubdir}${host_makefile_frag} >>${Makefile} ;;
828             esac
829
830             if [ "${site_makefile_frag}" != "" ] ; then
831                 echo site_makefile_frag = ${invsubdir}${site_makefile_frag} >>${Makefile}
832             fi 
833
834             # make sure that some sort of reasonable default exists for these 
835             # two variables
836             CXX=${CXX-"g++ -O"}
837             CC=${CC-cc}
838
839             # reset prefix, exec_prefix, srcdir, SUBDIRS, NONSUBDIRS,
840             # remove any form feeds.
841             if [ -z "${subdirs}" ]; then
842                 rm -f ${subdir}/Makefile.tem2
843                 sed -e "s:^SUBDIRS[     ]*=.*$:SUBDIRS = ${configdirs}:" \
844                     -e "s:^NONSUBDIRS[  ]*=.*$:NONSUBDIRS = ${noconfigdirs}:" \
845                     ${subdir}/Makefile.tem > ${subdir}/Makefile.tem2
846                 rm -f ${subdir}/Makefile.tem
847                 mv ${subdir}/Makefile.tem2 ${subdir}/Makefile.tem
848             fi
849             sed -e "s:^prefix[  ]*=.*$:prefix = ${prefix}:" \
850                     -e "s:^exec_prefix[         ]*=.*$:exec_prefix = ${exec_prefix}:" \
851                     -e "s:^SHELL[        ]*=.*$:SHELL = ${config_shell}:" \
852                     -e "s:^srcdir[      ]*=.*$:srcdir = ${makesrcdir}:" \
853                     -e "s/\f//" \
854                     -e "s:^program_prefix[      ]*=.*$:program_prefix = ${program_prefix}:" \
855                     -e "s:^program_suffix[      ]*=.*$:program_suffix = ${program_suffix}:" \
856                     -e "s:^program_transform_name[      ]*=.*$:program_transform_name = ${program_transform_name}:" \
857                     -e "s:^tooldir[     ]*=.*$:tooldir = ${tooldir}:" \
858                     ${subdir}/Makefile.tem >> ${Makefile}
859             # final copy now in ${Makefile}
860
861         else
862            echo "No Makefile.in found in ${srcdir}/${subdir}, unable to configure" 1>&2
863         fi
864
865         rm -f ${subdir}/Makefile.tem
866
867         case "${host_makefile_frag}" in
868         "") using= ;;
869         *) using="and \"${host_makefile_frag}\"" ;;
870         esac
871
872         case "${target_makefile_frag}" in
873         "") ;;
874         *) using="${using} and \"${target_makefile_frag}\"" ;;
875         esac
876
877         case "${site_makefile_frag}" in
878         "") ;;
879         *) using="${using} and \"${site_makefile_frag}\"" ;;
880         esac
881
882         newusing=`echo "${using}" | sed 's/and/using/'`
883         using=${newusing}
884         echo "Created \"${Makefile}\" in" ${PWD=`pwd`} ${using}
885
886         . ${tmpfile}.pos
887
888         # describe the chosen configuration in config.status.
889         # Make that file a shellscript which will reestablish
890         # the same configuration.  Used in Makefiles to rebuild
891         # Makefiles.
892
893         case "${norecursion}" in
894         "") arguments="${arguments} --norecursion" ;;
895         *) ;;
896         esac
897
898         if [ ${subdir} = . ] ; then
899             echo "#!/bin/sh
900 # ${NO_EDIT}
901 # This directory was configured as follows:
902 ${progname}" ${arguments}  "
903 # ${using}" > ${subdir}/config.new
904         else
905             echo "#!/bin/sh
906 # ${NO_EDIT}
907 # This directory was configured as follows:
908 cd ${invsubdir}
909 ${progname}" ${arguments}  "
910 # ${using}" > ${subdir}/config.new
911         fi
912         chmod a+x ${subdir}/config.new
913         if [ -r ${subdir}/config.back ] ; then
914                 mv -f ${subdir}/config.back ${subdir}/config.status
915         fi
916         ${moveifchange} ${subdir}/config.new ${subdir}/config.status
917         ;;
918
919     *)  rm -f ${Makefile} ${subdir}/config.status ${links} ;;
920     esac
921 done
922
923 # If there are subdirectories, then recur. 
924 if [ -z "${norecursion}" -a -n "${configdirs}" ] ; then 
925         for configdir in ${configdirs} ; do
926
927                 if [ -d ${srcdir}/${configdir} ] ; then
928                         eval echo Configuring ${configdir}... ${redirect}
929                         case "${srcdir}" in
930                         ".") ;;
931                         *)
932                                 if [ ! -d ./${configdir} ] ; then
933                                         if mkdir ./${configdir} ; then
934                                                 true
935                                         else
936                                                 echo '***' "${progname}: could not make ${PWD=`pwd`}/${configdir}" 1>&2
937                                                 exit 1
938                                         fi
939                                 fi
940                                 ;;
941                         esac
942
943                         POPDIR=${PWD=`pwd`}
944                         cd ${configdir} 
945
946 ### figure out what to do with srcdir
947                         case "${srcdir}" in
948                         ".") newsrcdir=${srcdir} ;; # no -srcdir option.  We're building in place.
949                         /*) # absolute path
950                                 newsrcdir=${srcdir}/${configdir}
951                                 srcdiroption="--srcdir=${newsrcdir}"
952                                 ;;
953                         *) # otherwise relative
954                                 newsrcdir=../${srcdir}/${configdir}
955                                 srcdiroption="--srcdir=${newsrcdir}"
956                                 ;;
957                         esac
958
959 ### check for guested configure, otherwise fix possibly relative progname
960                         if [ -f ${newsrcdir}/configure ] ; then
961                                 recprog=${newsrcdir}/configure
962                         elif [ -f ${newsrcdir}/configure.in ] ; then
963                                 case "${progname}" in
964                                 /*)     recprog=${progname} ;;
965                                 *)      recprog=../${progname} ;;
966                                 esac
967                         else
968                                 eval echo No configuration information in ${configdir} ${redirect}
969                                 recprog=
970                         fi
971
972 ### The recursion line is here.
973                         if [ ! -z "${recprog}" ] ; then
974                                 if eval ${config_shell} ${recprog} ${verbose} ${buildopt} --host=${host_alias} --target=${target_alias} \
975                                         ${prefixoption} ${tmpdiroption} ${exec_prefixoption} \
976                                         ${srcdiroption} ${program_prefixoption} ${program_suffixoption} ${program_transform_nameoption} ${site_option} ${withoptions} ${withoutoptions} ${enableoptions} ${disableoptions} ${removing} ${other_options} ${redirect} ; then
977                                         true
978                                 else
979                                         echo Configure in `pwd` failed, exiting. 1>&2
980                                         exit 1
981                                 fi
982                         fi
983
984                         cd ${POPDIR}
985                 fi
986         done
987 fi
988
989 exit 0
990
991 #
992 # Local Variables:
993 # fill-column: 131
994 # End:
995 #
996
997 # end of configure