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