Fix bug in smake- file code.
[deliverable/binutils-gdb.git] / configure
1 #!/bin/sh
2
3 # Configuration script
4 # Copyright (C) 1988, 1990, 1991 Free Software Foundation, Inc.
5
6 #This file is part of GNU.
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 # $Id$
23
24 # Please email any bugs, comments, and/or additions to this file to:
25 # configure@cygnus.com
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 # set -e
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 ansi=
52 arguments=$*
53 commontargets=
54 configdirs=
55 defaulttargets=
56 destdir=
57 fatal=
58 hostsubdir=
59 norecursion=
60 objdir=
61 objdiroption=
62 progname=
63 recurring=
64 removing=
65 srcdir=
66 srctrigger=
67 target=
68 targets=
69 targetsubdir=
70 verbose=
71
72 for arg in $*;
73 do
74 case ${arg} in
75 -ansi | +a*)
76 ansi=true
77 clib=clib
78 ;;
79 -destdir=* | +destdir=* | +destdi=* | +destd=* | +dest=* | +des=* | +de=* | +d=*)
80 destdir=`echo ${arg} | sed 's/[+-]d[a-z]*=//'`
81 ;;
82 -languages=* | +languages=* | +language=* | +languag=* \
83 | +langua=* | +langu=* | +lang=* | +lan=* | +la=* \
84 | +l=*)
85 languages="${languages} `echo ${arg} | sed 's/[+-]l[a-z]*=//'`"
86 ;;
87 -gas | +g*)
88 gas=yes
89 ;;
90 -help | +h*)
91 fatal=true
92 ;;
93 -nfp | +nf*)
94 nfp=yes
95 ;;
96 -norecursion | +no*)
97 norecursion=true
98 ;;
99 -objdir=* | +objdir=* | +objdi=* | +objd=* | +obj=* | +ob=* | +o=*)
100 objdiroption=${arg}
101 objdir=`echo ${arg} | sed 's/[+-]o[a-z]*=//'`
102 ;;
103 -recurring | +recurring | +recurrin | +recurri | +recurr | +recur | +recu | +rec | +re)
104 recurring=true
105 ;;
106 -rm | +rm)
107 removing=${arg}
108 ;;
109 -site=* | +site=* | +sit=* | +si=*)
110 site=`echo ${arg} | sed 's/[+-]s[a-z]*=//'`
111 ;;
112 # -srcdir=* | +srcdir=* | +srcdi=* | +srcd=* | +src=* | +sr=*)
113 # srcdir=`echo ${arg} | sed 's/[+-]s[a-z]*=//'`
114 # ;;
115 -subdirs | +su*)
116 subdirs=${arg}
117 ;;
118 -target=* | +target=* | +targe=* | +targ=* | +tar=* | +ta=*)
119 if [ -n "${targets}" ] ; then
120 subdirs="+subdirs"
121 fi
122
123 newtargets="${targets} `echo ${arg} | sed 's/[+-]t[a-z]*=//'`"
124 targets="${newtargets}"
125 ;;
126 -tmpdir=* | +tmpdir=* | +tmpdi=* | +tmpd=* | +tmp=* | +tm=*)
127 tmpdiroption=${arg}
128 TMPDIR=`echo ${arg} | sed 's/[+-]t[a-z]*=//'`
129 ;;
130 -v | -verbose | +v*)
131 verbose=${arg}
132 ;;
133 -* | +*)
134 (echo ;
135 echo "Unrecognized option: \"${arg}\"". ;
136 echo) 1>&2
137 fatal=true
138 ;;
139 *)
140 if [ -n "${hosts}" ] ; then
141 subdirs="+subdirs"
142 fi
143
144 newhosts="${hosts} ${arg}"
145 hosts=${newhosts}
146 ;;
147 esac
148 done
149
150 if [ -n "${verbose}" ] ; then
151 echo $0 $*
152 fi
153
154 ## this is a little touchy and won't always work, but...
155 ##
156 ## if the argv[0] starts with a slash then it is an absolute name that can be
157 ## used as is.
158 ##
159 ## otherwise, if argv[0] has no slash in it, we can assume that it is on the
160 ## path. Since PATH might include "." we also add `pwd` to the end of PATH.
161 ##
162 ## otherwise we prepend `pwd` to $0 and hope that will give us an absolute
163 ## path.
164 ##
165
166 if (echo $0 | grep '^/' > /dev/null) ; then
167 progname=$0
168 else
169 if (echo $0 | grep '/' > /dev/null) ; then
170 progname=`pwd`/$0
171 else
172 progname=$0
173 PATH=$PATH:`pwd` ; export PATH
174 fi
175 fi
176
177 configsub=`echo ${progname} | sed 's/configure\$/config.sub/'`
178
179 if [ ! -f ${configsub} ] ; then
180 echo '***' cannot find config.sub.
181 echo 1
182 fi
183
184 # process host and target only if not removing.
185 if [ -z "${removing}" -a -z "${fatal}" ] ; then
186 # Complain if an arg is missing
187 if [ -z "${hosts}" ] ; then
188 (echo ;
189 echo "configure: No HOST specified." ;
190 echo) 1>&2
191 fatal=true
192 fi
193 fi
194
195 if [ -n "${fatal}" -o "${hosts}" = "help" ] ; then
196 (echo "Usage: configure HOST" ;
197 echo ;
198 echo "Options: [defaults in brackets]" ;
199 echo " +ansi configure w/ANSI library. [no ansi lib]" ;
200 echo " +destdir=MYDIR configure for installation into MYDIR. [\"/usr/local\"]" ;
201 echo " +gas configure the compilers for use with gas. [native as]" ;
202 echo " +help print this message. [normal config]" ;
203 echo " +lang=LANG configure to build LANG. [gcc]" ;
204 echo " +nfp configure the compilers default to soft floating point. [hard float]" ;
205 echo " +norecursion configure this directory only. [recurse]" ;
206 echo " +objdir=ODIR configure in a parallel tree rooted in ODIR. [rooted in \".\"]" ;
207 echo " +rm remove this configuration. [build a configuration]" ;
208 echo " +subdirs configure in subdirectories. [in source directories]" ;
209 echo " +target=TARGET configure for TARGET. [TARGET = HOST]" ;
210 echo " +tmpdir=TMPDIR create temporary files in TMPDIR. [ TMPDIR = \"/tmp\" ]" ;
211 echo ;
212 echo "Where HOST and TARGET are something like \"vax\", \"sun3\", \"encore\", etc." ;
213 echo "Asking for more than one \"+target\" implies \"+subdirs\". Any other" ;
214 echo "options given will apply to all targets.") 1>&2
215
216 if [ -r config.status ] ; then
217 cat config.status
218 fi
219
220 exit 1
221 fi
222
223 ### break up configure.in.
224 if [ -r configure.in ] ; then
225 if [ -z "`grep '^# per\-host:' configure.in`" ] ; then
226 echo '***' `pwd`/configure.in has no "per-host:" line. 1>&2
227 exit 1
228 fi
229
230 if [ -z "`grep '^# per\-target:' configure.in`" ] ; then
231 echo '***' `pwd`/configure.in has no "per-target:" line. 1>&2
232 exit 1
233 fi
234
235 if [ -z "${TMPDIR}" ] ; then
236 TMPDIR=/tmp ; export TMPDIR
237 fi
238
239 # split configure.in into common, per-host, per-target,
240 # and post-target parts. Post-target is optional.
241 sed -e '/^# per\-host:/,$d' configure.in > ${TMPDIR}/configure.$$.com
242 sed -e '1,/^# per\-host:/d' -e '/^# per\-target:/,$d' configure.in > ${TMPDIR}/configure.$$.hst
243 if grep -s '^# post-target:' configure.in ; then
244 sed -e '1,/^# per\-target:/d' -e '/^# post\-target:/,$d' configure.in > ${TMPDIR}/configure.$$.tgt
245 sed -e '1,/^# post\-target:/d' configure.in > ${TMPDIR}/configure.$$.pos
246 else
247 sed -e '1,/^# per\-target:/d' configure.in > ${TMPDIR}/configure.$$.tgt
248 echo >${TMPDIR}/configure.$$.pos
249 fi
250
251 else
252 echo '***' No configure.in in `pwd`
253 exit 1
254 fi
255
256 ### do common part of configure.in
257
258 . ${TMPDIR}/configure.$$.com
259
260 # some sanity checks on configure.in
261 if [ -z "${srctrigger}" ] ; then
262 echo '***' srctrigger not set in `pwd`/configure.in.
263 exit 1
264 fi
265
266 for host in ${hosts} ; do
267 # Default other arg
268 if [ -z "${targets}" -o -n "${defaulttargets}" ] ; then
269 targets=${host}
270 defaulttargets=true
271 fi
272
273 host_alias=${host}
274
275 result=`${configsub} ${host}`
276 host_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
277 host_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
278 host_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
279 host=${host_cpu}-${host_vendor}-${host_os}
280 host_makefile_frag=config/hmake-${host}
281
282 . ${TMPDIR}/configure.$$.hst
283
284 for target in ${targets} ; do
285
286 target_alias=${target}
287 result=`${configsub} ${target}`
288 target_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
289 target_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
290 target_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
291 target=${target_cpu}-${target_vendor}-${target_os}
292 target_makefile_frag=config/tmake-${target}
293
294 . ${TMPDIR}/configure.$$.tgt
295
296 # Temporarily, we support only direct subdir builds.
297 hostsubdir=H-${host_alias}
298 targetsubdir=T-${target_alias}
299
300 if [ -n "${removing}" ] ; then
301 if [ -n "${objdir}" ] ; then
302 echo '***' +rm not supported for +objdir. Just \"rm -rf ${objdir}\" by hand.
303 exit 1
304 fi
305
306 if [ -n "${subdirs}" ] ; then
307 if [ -d "${hostsubdir}" ] ; then
308 rm -rf ${hostsubdir}/${targetsubdir}
309
310 if [ -z "`(ls ${hostsubdir}) 2>&1 | grep T- | grep -v T-independent`" ] ; then
311 rm -rf ${hostsubdir}
312 fi
313 else
314 echo Warning: no `pwd`/${hostsubdir} to remove.
315 fi
316 else
317 rm -f ${Makefile} config.status ${links}
318 fi
319 else
320 if [ -n "${objdir}" ]; then
321 srcdir=`pwd`
322 cd ${objdir}
323 fi
324
325 if [ -n "${subdirs}" ] ; then
326 # check for existing status before allowing forced subdirs.
327 if [ -f ${Makefile} ] ; then
328 echo '***' "${Makefile} already exists in source directory. `pwd` not configured." 1>&2
329 exit 1
330 fi
331
332 if [ ! -d ${hostsubdir} ] ; then mkdir ${hostsubdir} ; fi
333 cd ${hostsubdir}
334
335 if [ ! -d ${targetsubdir} ] ; then
336 if [ -z "${commontargets}" ] ; then
337 mkdir ${targetsubdir}
338 else
339 if [ ! -d T-independent ] ; then
340 mkdir T-independent
341 fi
342
343 ${symbolic_link} T-independent ${targetsubdir}
344 fi # if target independent
345 fi # if no target dir yet
346
347 cd ${targetsubdir}
348
349 if [ -z "${srcdir}" ] ; then
350 srcdir=../..
351 fi
352 else
353 # if not subdir builds, then make sure none exist.
354 if [ -n "`(ls .) 2>&1 | (grep H- ; true)`" ] ; then
355 echo '***' "Configured subdirs exist. `pwd` not configured." 1>&2
356 exit 1
357 else
358 true
359 fi
360 fi
361
362 # Find the source files, if location was not specified.
363 if [ -z "${srcdir}" ] ; then
364 srcdirdefaulted=1
365 srcdir=.
366 if [ -n "${srctrigger}" -a ! -r ${srctrigger} ] ; then
367 srcdir=..
368 fi
369 fi
370
371 if [ -n "${srctrigger}" -a ! -r ${srcdir}/${srctrigger} ] ; then
372 if [ -z "${srcdirdefaulted}" ] ; then
373 echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/${srcdir}" 1>&2
374 else
375 echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/. or `pwd`/.." 1>&2
376 fi
377
378 echo '***' \(At least ${srctrigger} is missing.\) 1>&2
379 exit 1
380 fi
381
382 # Set up the list of links to be made.
383 # ${links} is the list of link names, and ${files} is the list of names to link to.
384
385 # Make the links.
386 while [ -n "${files}" ] ; do
387 # set file to car of files, files to cdr of files
388 set ${files}; file=$1; shift; files=$*
389 set ${links}; link=$1; shift; links=$*
390
391 if [ ! -r ${srcdir}/${file} ] ; then
392 echo '***' "${progname}: cannot create a link \"${link}\"," 1>&2
393 echo '***' "since the file \"${file}\" does not exist." 1>&2
394 exit 1
395 fi
396
397 ${remove} -f ${link}
398 rm -f config.status
399 # Make a symlink if possible, otherwise try a hard link
400 ${symbolic_link} ${srcdir}/${file} ${link} 2>/dev/null || ${hard_link} ${srcdir}/${file} ${link}
401
402 if [ ! -r ${link} ] ; then
403 echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
404 exit 1
405 fi
406
407 if [ -n "${verbose}" ] ; then
408 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
409 fi
410 done
411
412 # Create a .gdbinit file which runs the one in srcdir
413 # and tells GDB to look there for source files.
414
415 case ${srcdir} in
416 .)
417 ;;
418 *)
419 echo "dir ." > .gdbinit
420 echo "dir ${srcdir}" >> .gdbinit
421 echo "source ${srcdir}/.gdbinit" >> .gdbinit
422 ;;
423 esac
424
425 # Install a makefile, and make it set VPATH
426 # if necessary so that the sources are found.
427 # Also change its value of srcdir.
428
429 # FIXME-someday: This business of always writing to .tem and mv back
430 # is so that I don't screw things up while developing. Once this
431 # template is stable, these should be optimized. xoxorich.
432
433 # Define macro CROSS_COMPILE in compilation if this is a cross-compiler.
434 if [ "${host}" != "${target}" ] ; then
435 echo "CROSS=-DCROSS_COMPILE" > ${Makefile}
436 echo "ALL=start.encap" >> ${Makefile}
437 else
438 echo "ALL=all.internal" > ${Makefile}
439 fi
440
441 # set target, host, VPATH
442 echo "host_alias = ${host_alias}" >> ${Makefile}
443 echo "host_cpu = ${host_cpu}" >> ${Makefile}
444 echo "host_vendor = ${host_vendor}" >> ${Makefile}
445 echo "host_os = ${host_os}" >> ${Makefile}
446
447 echo "target_alias = ${target_alias}" >> ${Makefile}
448 echo "target_cpu = ${target_cpu}" >> ${Makefile}
449 echo "target_vendor = ${target_vendor}" >> ${Makefile}
450 echo "target_os = ${target_os}" >> ${Makefile}
451
452 if [ -n "${subdirs}" ] ; then
453 (echo "subdir = /${hostsubdir}/${targetsubdir}" ;
454 echo "unsubdir = ../..") >> ${Makefile}
455 else
456 (echo "subdir =" ;
457 echo "unsubdir = .") >> ${Makefile}
458 fi
459
460 # echo "workdir = `pwd`" >> ${Makefile}
461 echo "VPATH = ${srcdir}" >> ${Makefile}
462
463 # add "Makefile.in" (or whatever it's called)
464 cat ${srcdir}/${Makefile_in} >> ${Makefile}
465
466 # Conditionalize the makefile for this host.
467 if [ -f ${srcdir}/${host_makefile_frag} ] ; then
468 (echo "host_makefile_frag = ${srcdir}/${host_makefile_frag}" ;
469 sed -e "/^####/ r ${srcdir}/${host_makefile_frag}" ${Makefile}) > Makefile.tem
470 mv Makefile.tem ${Makefile}
471 fi
472
473 # Conditionalize the makefile for this target.
474 if [ -f ${srcdir}/${target_makefile_frag} ] ; then
475 (echo "target_makefile_frag = ${srcdir}/${target_makefile_frag}" ;
476 sed -e "/^####/ r ${srcdir}/${target_makefile_frag}" ${Makefile}) > Makefile.tem
477 mv Makefile.tem ${Makefile}
478 fi
479
480 # Conditionalize the makefile for this site.
481 if [ -n "${site}" ] ; then
482 site_makefile_frag=smake-${site}
483
484 if [ -f ${srcdir}/${site_makefile_frag} ] ; then
485 (echo "site_makefile_frag = ${srcdir}/${site_makefile_frag}" ;
486 sed -e "/^####/ r ${srcdir}/${site_makefile_frag}" ${Makefile}) > Makefile.tem
487 mv Makefile.tem ${Makefile}
488 fi
489 fi
490
491 # set srcdir
492 sed "s@^srcdir = \.@srcdir = ${srcdir}@" ${Makefile} > Makefile.tem
493 mv Makefile.tem ${Makefile}
494
495 # set destdir
496 if [ -n "${destdir}" ] ; then
497 sed "s:^destdir =.*$:destdir = ${destdir}:" ${Makefile} > Makefile.tem
498 mv Makefile.tem ${Makefile}
499 fi
500
501 # reset SUBDIRS
502 sed "s:^SUBDIRS =.*$:SUBDIRS = ${configdirs}:" ${Makefile} > Makefile.tem
503 mv Makefile.tem ${Makefile}
504
505 # reset NONSUBDIRS
506 sed "s:^NONSUBDIRS =.*$:NONSUBDIRS = ${noconfigdirs}:" ${Makefile} > Makefile.tem
507 mv Makefile.tem ${Makefile}
508
509 # remove any form feeds.
510 sed -e "s/\f//" ${Makefile} > Makefile.tem
511 mv Makefile.tem ${Makefile}
512
513 using=
514 if [ -f ${srcdir}/${host_makefile_frag} ] ; then
515 using=" using \"${host_makefile_frag}\""
516 fi
517
518 if [ -f ${srcdir}/${target_makefile_frag} ] ; then
519 if [ -z "${using}" ] ; then
520 andusing=" using \"${target_makefile_frag}\""
521 else
522 andusing="${using} and \"${target_makefile_frag}\""
523 fi
524 else
525 andusing=${using}
526 fi
527
528 if [ -f ${srcdir}/${site_makefile_frag} ] ; then
529 if [ -z "${andusing}" ] ; then
530 andandusing=" using \"${site_makefile_frag}\""
531 else
532 andandusing="${andusing} and \"${site_makefile_frag}\""
533 fi
534 else
535 andandusing=${using}
536 fi
537
538 if [ -n "${verbose}" -o -z "${recurring}" ] ; then
539 echo "Created \"${Makefile}\"" in `pwd`${andandusing}.
540 fi
541
542 if [ -f ${TMPDIR}/configure.$$.pos ] ; then
543 . ${TMPDIR}/configure.$$.pos
544 fi
545
546 # describe the chosen configuration in config.status.
547 # Make that file a shellscript which will reestablish
548 # the same configuration. Used in Makefiles to rebuild
549 # Makefiles.
550
551 echo "#!/bin/sh
552 # `pwd` was configured as follows:
553 (cd ${srcdir} ; ${progname}" ${arguments} `if [ -z "${norecursion}" ] ; then echo +norecursion ; else true ; fi` ")" > config.status
554 chmod a+x config.status
555
556 originaldir=`pwd`
557 cd ${srcdir}
558 fi
559
560 # If there are subdirectories, then recurse.
561 if [ -z "${norecursion}" -a -n "${configdirs}" ] ; then
562 for configdir in ${configdirs} ; do
563 if [ -n "${verbose}" ] ; then
564 echo Configuring ${configdir}...
565 fi
566
567 if [ -d ${configdir} ] ; then
568 if [ -n "${objdir}" ] ; then
569 if [ ! -d ${objdir}/${configdir} ] ; then
570 mkdir ${objdir}/${configdir}
571 fi
572 fi
573
574 (cd ${configdir} ;
575 ${progname} +recurring ${host_alias} +target=${target_alias} \
576 ${verbose} ${subdirs} ${removing} +destdir=${destdir} \
577 `if [ -n "${objdir}" ] ; then echo +objdir=${objdir}/${configdir} ; fi` \
578 ${tmpdiroption}) \
579 | sed 's/^/ /'
580 else
581 if [ -n "${verbose}" ] ; then
582 echo Warning: directory \"${configdir}\" is missing.
583 fi
584 fi
585 done
586 fi
587 done # for each target
588
589 # Now build a Makefile for this host.
590 if [ -n "${subdirs}" -a ! -n "${removing}" ] ; then
591 push=`pwd`
592
593 if [ -n "${objdir}" ] ; then
594 cd ${objdir}
595 fi
596
597 cd ${hostsubdir}
598 cat > GNUmakefile << E!O!F
599 # Makefile generated by configure for host ${host_alias}.
600
601 ALL := $(shell ls -d T-*)
602
603 %:
604 $(foreach subdir,$(ALL),$(MAKE) -C $(subdir) \$@ &&) true
605
606 all:
607 E!O!F
608 cd ${push}
609 fi
610 done # for each host
611
612 ### clean up.
613
614 rm -f ${TMPDIR}/configure.$$.com ${TMPDIR}/configure.$$.tgt ${TMPDIR}/configure.$$.hst ${TMPDIR}/configure.$$.pos
615
616 exit 0
617
618 #
619 #
620 # $Log$
621 # Revision 1.51 1991/10/08 06:07:58 wilson
622 # Fix bug in smake- file code.
623 #
624 # Revision 1.50 1991/10/04 23:49:37 rich
625 # Per's patch for my config.sub botch.
626 #
627 # Revision 1.49 1991/10/04 22:52:09 rich
628 # Use john's heuristic for finding ourselves. kinda like hare krishna.
629 #
630 # Revision 1.48 1991/10/02 13:17:28 rich
631 # take out the set -e for now
632 #
633 # Revision 1.47 1991/10/02 10:02:23 rich
634 # * temporary files in TMPDIR
635 # * +objdir
636 #
637 # Revision 1.46 1991/10/02 06:29:53 rich
638 # Added +site=foo option for naming site specific Makefile fragments.
639 #
640 # Revision 1.45 1991/10/02 06:15:13 rich
641 # Removed +f option. Used to stand for +forcesubdirs which is now
642 # called +subdirs.
643 #
644 # Revision 1.44 1991/10/02 06:02:35 rich
645 # Added rcs log line.
646 #
647 #
648 #
649
650 #
651 # Local Variables:
652 # fill-column: 131
653 # End:
654 #
655
656 # end of configure
This page took 0.073109 seconds and 5 git commands to generate.