from p3. Some shells leave PWD in the environment (old tcsh, ksh at least)
[external/binutils.git] / configure
1 #!/bin/sh
2
3 # Configuration script
4 #   Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 # Please email any bugs, comments, and/or additions to this file to:
21 # configure@cygnus.com
22
23 # This file was written by K. Richard Pixley.
24
25 #
26 # Shell script to create proper links to machine-dependent files in
27 # preparation for compilation.
28 #
29 # If configure succeeds, it leaves its status in config.status.
30 # If configure fails after disturbing the status quo, 
31 #       config.status is removed.
32 #
33
34 export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0 $argv; kill $$)
35
36 remove=rm
37 hard_link=ln
38 symbolic_link='ln -s'
39
40 #for Test
41 #remove="echo rm"
42 #hard_link="echo ln"
43 #symbolic_link="echo ln -s"
44
45 # clear some things potentially inherited from environment.
46
47 Makefile=Makefile
48 Makefile_in=Makefile.in
49 arguments=$*
50 configdirs=
51 exec_prefix=
52 exec_prefixoption=
53 fatal=
54 floating_point=default
55 gas=default
56 host_alias=
57 host_makefile_frag=
58 moveifchange=
59 next_host=
60 next_prefix=
61 next_site=
62 next_srcdir=
63 next_target=
64 next_tmpdir=
65 norecursion=
66 prefix=/usr/local
67 progname=
68 program_prefix=
69 program_prefixoption=
70 program_suffix=
71 program_suffixoption=
72 program_transform_name=
73 program_transform_nameoption=
74 redirect=">/dev/null"
75 removing=
76 site=
77 site_makefile_frag=
78 site_option=
79 srcdir=
80 srctrigger=
81 subdirs=
82 target_alias=
83 target_makefile_frag=
84 undefinedargs=
85 version="$Revision$"
86 x11=default
87
88 NO_EDIT="This file was generated automatically by configure.  Do not edit."
89
90 ## this is a little touchy and won't always work, but...
91 ##
92 ## if the argv[0] starts with a slash then it is an absolute name that can (and
93 ## must) be used as is.
94 ##
95 ## otherwise, if argv[0] has no slash in it, we can assume that it is on the
96 ## path.  Since PATH might include "." we also add `pwd` to the end of PATH.
97 ##
98
99 progname=$0
100 PWD=`pwd`
101
102 case "${progname}" in
103 /*) ;;
104 */*) ;;
105 *)
106         PATH=$PATH:${PWD=`pwd`} ; export PATH
107         ;;
108 esac
109
110 for arg in $*;
111 do
112         # handle things that might have args following as separate words
113         if [ -n "${next_prefix}" ] ; then prefix=${arg} ; prefixoption="-prefix=${prefix}" ; next_prefix=
114         elif [ -n "${next_exec_prefix}" ] ; then
115                 exec_prefix=${arg}
116                 exec_prefixoption="-exec_prefix=${exec_prefix}"
117                 next_exec_prefix=
118         elif [ -n "${next_site}" ] ; then site=${arg} ; site_option=-site=${site} ; next_site=
119         # remove any possible trailing slash from srcdir.  See note below.
120         elif [ -n "${next_srcdir}" ] ; then srcdir=`echo ${arg} | sed -e 's:/$::'` ; next_srcdir=
121         elif [ -n "${next_program_prefix}" ] ; then
122                 program_prefix=${arg}
123                 program_prefixoption="-program_prefix=${program_prefix}"
124                 next_program_prefix=
125         elif [ -n "${next_program_suffix}" ] ; then
126                 program_suffix=${arg}
127                 program_suffixoption="-program_suffix=${program_suffix}"
128                 next_program_suffix=
129         elif [ -n "${next_program_transform_name}" ] ; then
130                 # Double any backslashes or dollar signs in the argument
131                 program_transform_name="${program_transform_name} -e `echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`"
132                 program_transform_nameoption="${program_transform_nameoption} -program_transform_name='${arg}'"
133                 next_program_transform_name=
134         elif [ -n "${next_target}" ] ; then
135                 next_target=
136                 case "${target_alias}" in
137                 "")
138                         target_alias="${arg}"
139                         ;;
140                 *)
141                         echo '***' Can only configure for one target at a time.  1>&2
142                         fatal=yes
143                         ;;
144                 esac
145         elif [ -n "${next_tmpdir}" ] ; then
146                 next_tmpdir=
147                 tmpdiroption="--tmpdir=${arg}"
148                 TMPDIR=${arg}
149
150         else
151                 case ${arg} in
152                 -exec_prefix=* | --exec_prefix=* | --exec_prefi=* | --exec_pref=* | --exec_pre=* | --exec_pr=* | --exec_p=* | --exec_=* | --exec=* | --exe=* | --ex=* | --e=*)
153                         exec_prefix=`echo ${arg} | sed 's/^[-a-z_]*=//'`
154                         exec_prefixoption=${arg}
155                         ;;
156                 -exec_prefix | --exec_prefix | --exec_prefi | --exec_pref | --exec_pre | --exec_pr | --exec_p | --exec_ | --exec | --exe | --ex | --e)
157                         next_exec_prefix=yes
158                         ;;
159                 -gas | --g*)
160                         gas=yes
161                         ;;
162                 -help | --he*)
163                         fatal=true
164                         ;;
165                 -host=* | --host=* | --hos=* | --ho=*)
166                         case "${host_alias}" in
167                         "")
168                                 host_alias="`echo ${arg} | sed 's/^[-a-z]*=//'`"
169                                 ;;
170                         *)
171                                 echo '***' Can only configure for one host at a time.  1>&2
172                                 fatal=yes
173                                 ;;
174                         esac
175                         ;;
176                 -nfp | --nf*)
177                         floating_point=no
178                         ;;
179                 -norecursion | --no*)
180                         norecursion=true
181                         ;;
182                 -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=*)
183                         prefix=`echo ${arg} | sed 's/^[-a-z]*=//'`
184                         prefixoption=${arg}
185                         ;;
186                 -prefix | --prefix | --prefi | --pref | --pre)
187                         next_prefix=yes
188                         ;;
189                 -rm | --rm) removing=${arg} ;;
190                 -program_prefix=* | --program_prefix=* | --program_prefi=* | --program_pref=* | --program_pre=* | --program_pr=* | --program_p=*)
191                         program_prefix=`echo ${arg} | sed 's/^[-a-z_]*=//'`
192                         program_prefixoption=${arg}
193                         ;;
194                 -program_prefix | --program_prefix | --program_prefi | --program_pref | --program_pre | --program_pr | --program_p)
195                         next_program_prefix=yes
196                         ;;
197                 -program_suffix=* | --program_suffix=* | --program_suffi=* | --program_suff=* | --program_suf=* | --program_su=* | --program_s=*)
198                         program_suffix=`echo ${arg} | sed 's/^[-a-z_]*=//'`
199                         program_suffixoption=${arg}
200                         ;;
201                 -program_suffix | --program_suffix | --program_suffi | --program_suff | --program_suf | --program_su | --program_s )
202                         next_program_suffix=yes
203                         ;;
204                 -program_transform_name=* | --program_transform_name=* | --program_transform_nam=* | --program_transform_na=* | --program_transform_n=* | --program_transform_=* | --program_transform=* | --program_transfor=* | --program_transfo=* | --program_transf=* | --program_trans=* | --program_tran=* | --program_tra=* | --program_tr=* | --program_t=*)
205                         # Double any \ or $ in the argument
206                         program_transform_name="${program_transform_name} -e `echo ${arg} | sed -e 's/^[-a-z_]*=//' -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`"
207                         program_transform_nameoption="${program_transform_nameoption} -program_transform_name='`echo ${arg} | sed 's/^[-a-z_]*=//'`'"
208                         ;;
209                 -program_transform_name | --program_transform_name | --program_transform_nam | --program_transform_na | --program_transform_n | --program_transform_ | --program_transform | --program_transfor | --program_transfo | --program_transf | --program_trans | --program_tran | --program_tra | --program_tr | --program_t)
210                         next_program_transform_name=yes
211                         ;;
212                 -site=* | --site=* | --sit=* | --si=*)
213                         site_option=${arg}
214                         site=`echo ${arg} | sed 's/^[-a-z]*=//'`
215                         ;;
216                 -site | --site | --sit)
217                         next_site=yes
218                         ;;
219                 # remove trailing slashes.  Otherwise, when the file name gets
220                 # bolted into an object file as debug info, it has two slashes in
221                 # it.  Ordinarily this is ok, but emacs takes double slash to
222                 # mean "forget the first part".
223                 -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
224                         srcdir=`echo ${arg} | sed 's/^[-a-z]*=//' | sed -e 's:/$::'`
225                         ;;
226                 -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
227                         next_srcdir=yes
228                         ;;
229                 -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=*)
230                         case "${target_alias}" in
231                         "") target_alias="`echo ${arg} | sed 's/^[-a-z]*=//'`" ;;
232                         *)
233                                 echo '***' Can only configure for one target at a time.  1>&2
234                                 fatal=yes
235                                 ;;
236                         esac
237                         ;;
238                 -target | --target | --targe | --targ | --tar | --ta)
239                         next_target=yes
240                         ;;
241                 -tmpdir=* | --tmpdir=* | --tmpdi=* | --tmpd=* | --tmp=* | --tm=*)
242                         tmpdiroption=${arg}
243                         TMPDIR=`echo ${arg} | sed 's/^[-a-z]*=//'`
244                         ;;
245                 -tmpdir | --tmpdir | --tmpdi | --tmpd | --tmp | --tm)
246                         next_tmpdir=yes
247                         ;;
248                 -v | -verbose | --v)
249                         redirect=
250                         verbose=-v
251                         ;;
252                 -version | -V | --version | --V)
253                         echo "This is Cygnus Configure version" `echo ${version} | sed 's/[ $:]//g'`
254                         exit 0
255                         ;;
256                 -x | --x) ;;
257                 -* | --*)
258                         (echo ;
259                         echo "Unrecognized option: \"${arg}\"". ;
260                         echo) 1>&2
261                         fatal=true
262                         ;;
263                 *)
264                         case "${undefs}" in
265                         "")
266                                 undefs="${arg}"
267                                 ;;
268                         *)
269                                 echo '***' Can only configure for one host and one target at a time.  1>&2
270                                 fatal=yes
271                                 ;;
272                         esac
273                         ;;
274                 esac
275         fi
276 done
277
278 # process host and target
279 case "${fatal}" in
280 "")
281 #       # Complain if an arg is missing
282 #       if [ -z "${host_alias}" ] ; then
283 #               (echo ;
284 #               echo "configure: No HOST specified." ;
285 #               echo) 1>&2
286 #               fatal=true
287 #       fi
288
289 ### This is a bit twisted.
290 ### * if all three are specified, this is an error.
291 ### * if we have neither hosts, nor unadorned args, this is an error.
292 ### * if no hosts are specified, then the unadorned args are hosts, but if
293 ### there were none, this is an error.
294 ### * if no targets are specified, then the unadorned args are targets, but if
295 ### there were no unadorned args, then the hosts are also targets.
296
297         if [ -n "${host_alias}" -a -n "${target_alias}" -a -n "${undefs}" ] ; then
298                 echo '***' Can only configure for one host and one target at a time.  1>&2
299                 fatal=yes
300         elif [ -z "${host_alias}" -a -z "${undefs}" ] ; then
301                 echo '***' You must tell me for which host you want to configure.  1>&2
302                 fatal=yes
303         else
304                 case "${host_alias}" in
305                 "") host_alias=${undefs} ;;
306                 *) ;;
307                 esac
308
309                 case "${target_alias}" in
310                 "")
311                         case "${undefs}" in
312                         "")     target_alias=${host_alias} ;;
313                         *)      target_alias=${undefs} ;;
314                         esac
315                         ;;
316                 *) ;;
317                 esac
318         fi
319         ;;
320 *) ;;
321 esac
322
323 if [ -n "${fatal}" -o "${host_alias}" = "help" ] ; then
324         (echo "Usage: configure HOST" ;
325         echo ;
326         echo "Options: [defaults in brackets]" ;
327         echo " -exec_prefix=MYDIR       configure for installation of host dependent files into MYDIR. [\"/usr/local\"]" ;
328         echo " -gas                     configure the compilers for use with gas. [native as]" ;
329         echo " -help                    print this message. [normal config]" ;
330         echo " -lang=LANG               configure to build LANG. [gcc]" ;
331         echo " -nfp                     configure the compilers default to soft floating point. [hard float]" ;
332         echo " -norecursion             configure this directory only. [recurse]" ;
333         echo " -prefix=MYDIR            configure for installation of host dependent files into MYDIR. [\"/usr/local\"]" ;
334         echo " -program_prefix=FOO      install programs with FOO prepended to their names. [ \"\" ]" ;
335         echo " -program_suffix=FOO      install programs with FOO appended to their names. [ \"\" ]" ;
336         echo " -program_transform_name=FOO      install programs with names transformed by sed pattern FOO. [ \"\" ]" ;
337         echo " -site=SITE               configure with site specific makefile for SITE" ;
338         echo " -srcdir=DIR              find the sources in DIR. [\".\" or \"..\"]" ;
339         echo " -target=TARGET           configure for TARGET.  [TARGET = HOST]" ;
340         echo " -tmpdir=TMPDIR           create temporary files in TMPDIR.  [ TMPDIR = \"/tmp\" ]" ;
341         echo ;
342         echo "Where HOST and TARGET are something like \"vax\", \"sun3\", \"encore\", etc." ;
343         ) 1>&2
344
345         if [ -r config.status ] ; then
346                 cat config.status
347         fi
348
349         exit 1
350 fi
351
352 configsub=`echo ${progname} | sed 's/configure$/config.sub/'`
353 moveifchange=`echo ${progname} | sed 's/configure$/move-if-change/'`
354
355 # this is a hack.  sun4 must always be a valid host alias or this will fail.
356 if ${configsub} sun4 >/dev/null 2>&1 ; then
357         true
358 else
359         echo '***' cannot find config.sub.  1>&2
360         exit 1
361 fi
362
363 touch config.junk
364 if ${moveifchange} config.junk config.trash ; then
365         true
366 else
367         echo '***' cannot find move-if-change.  1>&2
368         exit 1
369 fi
370 rm -f config.junk config.trash
371
372 case "${srcdir}" in
373 "")
374         if [ -r configure.in ] ; then
375                 srcdir=.
376         else
377                 if [ -r ${progname}.in ] ; then
378                         srcdir=`echo ${progname} | sed 's:/configure$::'`
379                 else
380                         echo '***' "Can't find configure.in.  Try using -srcdir=some_dir"  1>&2
381                         exit 1
382                 fi
383         fi
384         ;;
385 *) ;;
386 esac
387
388 ### warn about some conflicting configurations.
389
390 case "${srcdir}" in
391 ".") ;;
392 *)
393         if [ -f ${srcdir}/config.status ] ; then
394                 echo '***' Cannot configure here in \"${PWD=`pwd`}\" when \"${srcdir}\" is currently configured. 1>&2
395                 exit 1
396         fi
397 esac
398
399 # default exec_prefix
400 case "${exec_prefix}" in
401 "") exec_prefix="\$(prefix)" ;;
402 *) ;;
403 esac
404
405 ### break up ${srcdir}/configure.in.
406 case "`grep '^# per\-host:' ${srcdir}/configure.in`" in
407 "")
408         echo '***' ${srcdir}/configure.in has no "per-host:" line. 1>&2
409         exit 1
410         ;;
411 *) ;;
412 esac
413
414 case "`grep '^# per\-target:' ${srcdir}/configure.in`" in
415 "")
416         echo '***' ${srcdir}/configure.in has no "per-target:" line. 1>&2
417         exit 1
418         ;;
419 *) ;;
420 esac
421
422 case "${TMPDIR}" in
423 "") TMPDIR=/tmp ; export TMPDIR ;;
424 *) ;;
425 esac
426
427 # keep this filename short for &%*%$*# 14 char file names
428 tmpfile=${TMPDIR}/cONf$$
429 trap "rm -f ${tmpfile}.com ${tmpfile}.tgt ${tmpfile}.hst ${tmpfile}.pos" 0
430
431 # split ${srcdir}/configure.in into common, per-host, per-target,
432 # and post-target parts.  Post-target is optional.
433 sed -e '/^# per\-host:/,$d' ${srcdir}/configure.in > ${tmpfile}.com
434 sed -e '1,/^# per\-host:/d' -e '/^# per\-target:/,$d' ${srcdir}/configure.in > ${tmpfile}.hst
435 if grep '^# post-target:' ${srcdir}/configure.in >/dev/null ; then
436   sed -e '1,/^# per\-target:/d' -e '/^# post\-target:/,$d' ${srcdir}/configure.in > ${tmpfile}.tgt
437   sed -e '1,/^# post\-target:/d' ${srcdir}/configure.in > ${tmpfile}.pos
438 else
439   sed -e '1,/^# per\-target:/d' ${srcdir}/configure.in > ${tmpfile}.tgt
440   echo >${tmpfile}.pos
441 fi
442
443 ### do common part of configure.in
444
445 . ${tmpfile}.com
446
447 # some sanity checks on configure.in
448 case "${srctrigger}" in
449 "")
450         echo '***' srctrigger not set in ${PWD=`pwd`}/configure.in.  1>&2
451         exit 1
452         ;;
453 *) ;;
454 esac
455
456 result=`${configsub} ${host_alias}`
457 host_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
458 host_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
459 host_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
460 host=${host_cpu}-${host_vendor}-${host_os}
461
462 . ${tmpfile}.hst
463
464 result=`${configsub} ${target_alias}`
465 target_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
466 target_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
467 target_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
468 target=${target_cpu}-${target_vendor}-${target_os}
469
470 . ${tmpfile}.tgt
471
472 # Find the source files, if location was not specified.
473 case "${srcdir}" in
474 "")
475         srcdirdefaulted=1
476         srcdir=.
477         if [ ! -r ${srctrigger} ] ; then
478                 srcdir=..
479         fi
480         ;;
481 *) ;;
482 esac
483
484 if [ ! -r ${srcdir}/${srctrigger} ] ; then
485         case "${srcdirdefaulted}" in
486         "") echo '***' "${progname}: Can't find ${srcname} sources in ${PWD=`pwd`}/${srcdir}" 1>&2 ;;
487         *)  echo '***' "${progname}: Can't find ${srcname} sources in ${PWD=`pwd`}/. or ${PWD=`pwd`}/.." 1>&2 ;;
488         esac
489
490         echo '***' \(At least ${srctrigger} is missing.\) 1>&2
491         exit 1
492 fi
493
494 tooldir="\$(libdir)/${target_alias}"
495
496 if [ "${host_alias}" != "${target_alias}" ] ; then
497     if [ "${program_prefix}" = "" ] ; then
498         if [ "${program_suffix}" = "" ] ; then 
499             if [ "${program_transform_name}" = "" ] ; then
500                 program_prefix=${target_alias}- ;
501             fi
502         fi
503     fi
504 fi
505
506 # Merge program_prefix and program_suffix onto program_transform_name
507 # Use a double $ so that make ignores it
508 if [ "${program_suffix}" != "" ] ; then
509     program_transform_name="-e s/\$\$/${program_suffix}/ ${program_transform_name}"
510 fi
511
512 if [ "${program_prefix}" != "" ] ; then
513     program_transform_name="-e s/^/${program_prefix}/ ${program_transform_name}"
514 fi
515
516 for subdir in . ${subdirs} ; do
517
518     # ${subdir} is relative path from . to the directory we're currently
519     # configuring.
520     # ${invsubdir} is inverse of ${subdir), *with* trailing /, if needed.
521     invsubdir=`echo ${subdir}/ | sed -e 's|\./||g' -e 's|[^/]*/|../|g'`
522
523     ### figure out what to do with srcdir
524     case "${srcdir}" in
525         ".")  # no -srcdir option.  We're building in place.
526                 makesrcdir=. ;;
527         /*) # absolute path
528                 makesrcdir=`echo ${srcdir}/${subdir} | sed -e 's|/\.$||'`
529                 ;;
530         *) # otherwise relative
531                 case "${subdir}" in
532                 .) makesrcdir=${srcdir} ;;
533                 *) makesrcdir=`echo ${subdir} | sed -e 's:[^./][^./]*:..:g'`/${srcdir}/${subdir} ;;
534                 esac
535                 ;;
536     esac
537
538     if [ "${subdir}/" != "./" ] ; then
539         Makefile=${subdir}/Makefile
540     fi
541
542     if [ ! -d ${subdir} ] ; then
543         mkdir ${subdir}
544     fi
545
546     case "${removing}" in
547     "")
548         case "${subdir}" in
549         .) ;;
550         *) eval echo Building in ${subdir} ${redirect} ;;
551         esac
552
553         # FIXME Should this be done recursively ??? (Useful for e.g. gdbtest)
554         # Set up the list of links to be made.
555         # ${links} is the list of link names, and ${files} is the list of names to link to.
556
557         # Make the links.
558         configlinks="${links}"
559         if [ -r ${subdir}/config.status ] ; then
560                 mv -f ${subdir}/config.status ${subdir}/config.back
561         fi
562         while [ -n "${files}" ] ; do
563                 # set file to car of files, files to cdr of files
564                 set ${files}; file=$1; shift; files=$*
565                 set ${links}; link=$1; shift; links=$*
566
567                 if [ ! -r ${srcdir}/${file} ] ; then
568                         echo '***' "${progname}: cannot create a link \"${link}\"," 1>&2
569                         echo '***' "since the file \"${file}\" does not exist." 1>&2
570                         exit 1
571                 fi
572
573                 ${remove} -f ${link}
574                 # Make a symlink if possible, otherwise try a hard link
575                 ${symbolic_link} ${srcdir}/${file} ${link} 2>/dev/null || ${hard_link} ${srcdir}/${file} ${link}
576
577                 if [ ! -r ${link} ] ; then
578                         echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
579                         exit 1
580                 fi
581
582                 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
583         done
584
585         # Create a .gdbinit file which runs the one in srcdir
586         # and tells GDB to look there for source files.
587
588         if [ -r ${srcdir}/${subdir}/.gdbinit ] ; then
589                 case ${srcdir} in
590                 .) ;;
591                 *) cat > ${subdir}/.gdbinit <<EOF
592 # ${NO_EDIT}
593 dir .
594 dir ${makesrcdir}
595 source ${makesrcdir}/.gdbinit
596 EOF
597                         ;;
598                 esac
599         fi
600
601         # Install a makefile, and make it set VPATH
602         # if necessary so that the sources are found.
603         # Also change its value of srcdir.
604         # NOTE: Makefile generation constitutes the majority of the time in configure.  Hence, this section has
605         # been somewhat optimized and is perhaps a bit twisty.
606
607         # code is order so as to try to sed the smallest input files we know.
608
609         # the three makefile fragments MUST end up in the resulting Makefile in this order: target, host, and site.
610         # so do these separately because I don't trust the order of sed -e expressions.
611
612         # Conditionalize for this site from "Makefile.in" (or whatever it's called) into Makefile.tem
613         rm -f ${subdir}/Makefile.tem
614         case "${site}" in
615         "") cp ${srcdir}/${subdir}/${Makefile_in} ${subdir}/Makefile.tem ;;
616         *)
617                 site_makefile_frag=${srcdir}/config/ms-${site}
618
619                 if [ -f ${site_makefile_frag} ] ; then
620                         sed -e "/^####/  r ${site_makefile_frag}" ${srcdir}/${subdir}/${Makefile_in} \
621                                 > ${subdir}/Makefile.tem
622                 else
623                         cp ${srcdir}/${subdir}/${Makefile_in} ${subdir}/Makefile.tem
624                         site_makefile_frag=
625                 fi
626                 ;;
627         esac
628         # working copy now in ${subdir}/Makefile.tem
629
630         # Conditionalize the makefile for this host.
631         rm -f ${Makefile}
632         case "${host_makefile_frag}" in
633         "") mv ${subdir}/Makefile.tem ${Makefile} ;;
634         *)
635                 if [ ! -f ${host_makefile_frag} ] ; then
636                         host_makefile_frag=${srcdir}/${host_makefile_frag}
637                 fi
638                 if [ -f ${host_makefile_frag} ] ; then
639                         sed -e "/^####/  r ${host_makefile_frag}" ${subdir}/Makefile.tem > ${Makefile}
640                 else
641                         echo '***' Expected host makefile fragment \"${host_makefile_frag}\" 1>&2
642                         echo '***' is missing in ${PWD=`pwd`}. 1>&2
643                         mv ${subdir}/Makefile.tem ${Makefile}
644                 fi
645         esac
646         # working copy now in ${Makefile}
647
648         # Conditionalize the makefile for this target.
649         rm -f ${subdir}/Makefile.tem
650         case "${target_makefile_frag}" in
651         "") mv ${Makefile} ${subdir}/Makefile.tem ;;
652         *)
653                 if [ ! -f ${target_makefile_frag} ] ; then
654                         target_makefile_frag=${srcdir}/${target_makefile_frag}
655                 fi
656                 if [ -f ${target_makefile_frag} ] ; then
657                         sed -e "/^####/  r ${target_makefile_frag}" ${Makefile} > ${subdir}/Makefile.tem
658                 else
659                         mv ${Makefile} ${subdir}/Makefile.tem
660                         target_makefile_frag=
661                 fi
662                 ;;
663         esac
664         # real copy now in ${subdir}/Makefile.tem
665
666         # prepend warning about editting, and a bunch of variables.
667         rm -f ${Makefile}
668         cat > ${Makefile} <<EOF
669 # ${NO_EDIT}
670 VPATH = ${makesrcdir}
671 links = ${configlinks}
672 host_alias = ${host_alias}
673 host_cpu = ${host_cpu}
674 host_vendor = ${host_vendor}
675 host_os = ${host_os}
676 target_alias = ${target_alias}
677 target_cpu = ${target_cpu}
678 target_vendor = ${target_vendor}
679 target_os = ${target_os}
680 EOF
681         case "${target_makefile_frag}" in
682         "") ;;
683         /*)
684   echo target_makefile_frag = ${target_makefile_frag} >>${Makefile} ;;
685         *)
686   echo target_makefile_frag = ${invsubdir}${target_makefile_frag} >>${Makefile} ;;
687         esac
688
689         case "${host_makefile_frag}" in
690         "") ;;
691         /*)
692   echo host_makefile_frag = ${host_makefile_frag} >>${Makefile} ;;
693         *)
694   echo host_makefile_frag = ${invsubdir}${host_makefile_frag} >>${Makefile} ;;
695         esac
696
697         if [ "${site_makefile_frag}" != "" ] ; then
698             echo site_makefile_frag = ${invsubdir}${site_makefile_frag} >>${Makefile}
699         fi 
700
701         # fixme: this shouldn't be in configure.
702         # Define macro CROSS_COMPILE in compilation if this is a cross-compiler.
703         case "${host_alias}" in
704         "${target_alias}")
705                 echo "ALL=all.internal" >> ${Makefile}
706                 ;;
707         *)
708                 echo "CROSS=-DCROSS_COMPILE" >> ${Makefile}
709                 echo "ALL=all.cross" >> ${Makefile}
710                 ;;
711         esac
712
713         # reset prefix, exec_prefix, srcdir, SUBDIRS, NONSUBDIRS,
714         # remove any form feeds.
715         if [ -z "${subdirs}" ]; then
716             rm -f ${subdir}/Makefile.tem2
717             sed -e "s:^SUBDIRS[         ]*=.*$:SUBDIRS = ${configdirs}:" \
718                 -e "s:^NONSUBDIRS[      ]*=.*$:NONSUBDIRS = ${noconfigdirs}:" \
719                 ${subdir}/Makefile.tem > ${subdir}/Makefile.tem2
720             rm -f ${subdir}/Makefile.tem
721             mv ${subdir}/Makefile.tem2 ${subdir}/Makefile.tem
722         fi
723         sed -e "s:^prefix[      ]*=.*$:prefix = ${prefix}:" \
724                 -e "s:^exec_prefix[     ]*=.*$:exec_prefix = ${exec_prefix}:" \
725                 -e "s:^srcdir[  ]*=.*$:srcdir = ${makesrcdir}:" \
726                 -e "s/\f//" \
727                 -e "s:^program_prefix[  ]*=.*$:program_prefix = ${program_prefix}:" \
728                 -e "s:^program_suffix[  ]*=.*$:program_suffix = ${program_suffix}:" \
729                 -e "s:^program_transform_name[  ]*=.*$:program_transform_name = ${program_transform_name}:" \
730                 -e "s:^tooldir[         ]*=.*$:tooldir = ${tooldir}:" \
731                 ${subdir}/Makefile.tem >> ${Makefile}
732         # final copy now in ${Makefile}
733
734         rm -f ${subdir}/Makefile.tem
735
736         case "${host_makefile_frag}" in
737         "") using= ;;
738         *) using="and \"${host_makefile_frag}\"" ;;
739         esac
740
741         case "${target_makefile_frag}" in
742         "") ;;
743         *) using="${using} and \"${target_makefile_frag}\"" ;;
744         esac
745
746         case "${site_makefile_frag}" in
747         "") ;;
748         *) using="${using} and \"${site_makefile_frag}\"" ;;
749         esac
750
751         newusing=`echo "${using}" | sed 's/and/using/'`
752         using=${newusing}
753         echo "Created \"${Makefile}\" in" ${PWD=`pwd`} ${using}
754
755         . ${tmpfile}.pos
756
757         # describe the chosen configuration in config.status.
758         # Make that file a shellscript which will reestablish
759         # the same configuration.  Used in Makefiles to rebuild
760         # Makefiles.
761
762         case "${norecursion}" in
763         "") arguments="${arguments} -norecursion" ;;
764         *) ;;
765         esac
766
767         if [ ${subdir} = . ] ; then
768             echo "#!/bin/sh
769 # ${NO_EDIT}
770 # This directory was configured as follows:
771 ${progname}" ${arguments}  "
772 # ${using}" > ${subdir}/config.new
773         else
774             echo "#!/bin/sh
775 # ${NO_EDIT}
776 # This directory was configured as follows:
777 cd ${invsubdir}
778 ${progname}" ${arguments}  "
779 # ${using}" > ${subdir}/config.new
780         fi
781         chmod a+x ${subdir}/config.new
782         if [ -r ${subdir}/config.back ] ; then
783                 mv -f ${subdir}/config.back ${subdir}/config.status
784         fi
785         ${moveifchange} ${subdir}/config.new ${subdir}/config.status
786         ;;
787
788     *)  rm -f ${Makefile} ${subdir}/config.status ${links} ;;
789     esac
790 done
791
792 # If there are subdirectories, then recur. 
793 if [ -z "${norecursion}" -a -n "${configdirs}" ] ; then 
794         for configdir in ${configdirs} ; do
795                 eval echo Configuring ${configdir}... ${redirect}
796
797                 if [ -d ${srcdir}/${configdir} ] ; then
798                         case "${srcdir}" in
799                         ".") ;;
800                         *)
801                                 if [ ! -d ./${configdir} ] ; then
802                                         mkdir ./${configdir}
803                                 fi
804                                 ;;
805                         esac
806
807                         POPDIR=${PWD=`pwd`}
808                         cd ${configdir} 
809
810 ### figure out what to do with srcdir
811                         case "${srcdir}" in
812                         ".") newsrcdir=${srcdir} ;; # no -srcdir option.  We're building in place.
813                         /*) # absolute path
814                                 newsrcdir=${srcdir}/${configdir}
815                                 srcdiroption="-srcdir=${newsrcdir}"
816                                 ;;
817                         *) # otherwise relative
818                                 newsrcdir=../${srcdir}/${configdir}
819                                 srcdiroption="-srcdir=${newsrcdir}"
820                                 ;;
821                         esac
822
823 ### check for guested configure, otherwise fix possibly relative progname
824                         if [ -f ${newsrcdir}/configure ] ; then
825                                 recprog=${newsrcdir}/configure
826                         else
827                                 case "${progname}" in
828                                 /*)     recprog=${progname} ;;
829                                 *)      recprog=../${progname} ;;
830                                 esac
831                         fi
832
833 ### The recursion line is here.
834                         if eval ${recprog} ${verbose} ${host_alias} -target=${target_alias} \
835                                 ${prefixoption} ${tmpdiroption} ${exec_prefixoption} \
836                                 ${srcdiroption} ${program_prefixoption} ${program_suffixoption} ${program_transform_nameoption} ${site_option} ${removing} ${redirect} ; then
837                                 true
838                         else
839                                 exit 1
840                         fi
841
842                         cd ${POPDIR}
843                 else
844                         eval echo Warning: source directory \"${srcdir}/${configdir}\" is missing. ${redirect}
845                 fi
846         done
847 fi
848
849 exit 0
850
851 #
852 # Local Variables:
853 # fill-column: 131
854 # End:
855 #
856
857 # end of configure