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