Now handles multiple hosts and targets.
[binutils-gdb.git] / binutils / configure
1 #!/bin/sh
2 # Please do not edit this file. It is generated automatically from
3 # configure.in and a configure template.
4 configdirs=
5
6 #!/bin/sh
7
8 # Configuration script template
9 # Copyright (C) 1988, 1990, 1991 Free Software Foundation, Inc.
10
11 #This file is part of GNU.
12
13 #GNU CC is free software; you can redistribute it and/or modify
14 #it under the terms of the GNU General Public License as published by
15 #the Free Software Foundation; either version 1, or (at your option)
16 #any later version.
17
18 #GNU CC is distributed in the hope that it will be useful,
19 #but WITHOUT ANY WARRANTY; without even the implied warranty of
20 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 #GNU General Public License for more details.
22
23 #You should have received a copy of the GNU General Public License
24 #along with GNU CC; see the file COPYING. If not, write to
25 #the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 # $Id$
28
29 #
30 # Shell script to create proper links to machine-dependent files in
31 # preparation for compilation.
32 #
33 # If configure succeeds, it leaves its status in config.status.
34 # If configure fails after disturbing the status quo,
35 # config.status is removed.
36 #
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 ansi=
49 defaulttargets=
50 destdir=
51 fatal=
52 hostsubdir=
53 norecurse=
54 removing=
55 srcdir=
56 srctrigger=
57 target=
58 targets=
59 targetsubdir=
60 template=
61 verbose=
62
63 for arg in $*;
64 do
65 case ${arg} in
66 -ansi | +ansi)
67 ansi=true
68 ;;
69 -destdir=* | +destdir=* | +destdi=* | +destd=* | +dest=* | +des=* | +de=* | +d=*)
70 destdir=`echo ${arg} | sed 's/[+-]d[a-z]*=//'`
71 ;;
72 -forcesubdirs | +forcesubdirs | +f)
73 forcesubdirs=${arg}
74 ;;
75 -languages=* | +languages=* | +language=* | +languag=* \
76 | +langua=* | +langu=* | +lang=* | +lan=* | +la=* \
77 | +l=*)
78 languages="${languages} `echo ${arg} | sed 's/[+-]l[a-z]*=//'`"
79 ;;
80 -gas | +gas | +ga | +g)
81 gas=yes
82 ;;
83 -help | +h | +help)
84 fatal=true
85 ;;
86 -nfp | +nfp | +nf | +n)
87 nfp=yes
88 ;;
89 -norecurse | +norecurse)
90 norecurse=true
91 ;;
92 -rm | +rm)
93 removing=${arg}
94 ;;
95 # -srcdir=* | +srcdir=* | +srcdi=* | +srcd=* | +src=* | +sr=* | +s=*)
96 # srcdir=`echo ${arg} | sed 's/[+-]s[a-z]*=//'`
97 # ;;
98 -target=* | +target=* | +targe=* | +targ=* | +tar=* | +ta=* | +t=*)
99 if [ -n "${targets}" ] ; then
100 forcesubdirs="+forcesubdirs"
101 fi
102
103 newtargets="${targets} `echo ${arg} | sed 's/[+-]t[a-z]*=//'`"
104 targets="${newtargets}"
105 ;;
106 -template=* | +template=*)
107 template=`echo ${arg} | sed 's/[+-]template=//'`
108 ;;
109 +verbose | +verbos | +verbo | +verb | +ver | +ve | +v)
110 verbose=${arg}
111 ;;
112 -* | +*)
113 (echo ;
114 echo "Unrecognized option: \"${arg}\"". ;
115 echo) 1>&2
116 fatal=true
117 ;;
118 *)
119 if [ -n "${hosts}" ] ; then
120 forcesubdirs="+forcesubdirs"
121 fi
122
123 newhosts="${hosts} ${arg}"
124 hosts=${newhosts}
125 ;;
126 esac
127 done
128
129 if [ -n "${verbose}" ] ; then
130 echo `pwd`/configure $*
131 echo targets=\"${targets}\"
132 fi
133
134 # process host and target only if not rebuilding configure itself or removing.
135 if [ -z "${template}" -a -z "${removing}" -a -z "${fatal}" ] ; then
136 # Complain if an arg is missing
137 if [ -z "${hosts}" ] ; then
138 (echo ;
139 echo "configure: No HOST specified." ;
140 echo) 2>&1
141 fatal=true
142 fi
143 fi
144
145 if [ -n "${fatal}" -o "${hosts}" = "help" ] ; then
146 (echo "Usage: configure HOST" ;
147 echo ;
148 echo "Options: [defaults in brackets]" ;
149 echo " +ansi configure w/ANSI library. [no ansi lib]" ;
150 echo " +destdir=MYDIR configure for installation into MYDIR. [/usr/local]" ;
151 echo " +forcesubdirs configure in subdirectories. [in source directories]" ;
152 echo " +lang=LANG configure to build LANG. [gcc]" ;
153 echo " +help print this message. [normal config]" ;
154 echo " +gas configure the compilers for use with gas. [native as]" ;
155 echo " +nfp configure the compilers default to soft floating point. [hard float]" ;
156 echo " +norecurse configure this directory only. [recurse]" ;
157 echo " +rm remove this configuration. [build a configuration]" ;
158 echo " +target=TARGET configure for TARGET. [TARGET = HOST]" ;
159 echo " +template=TEM rebuild configure using TEM. [normal config]" ;
160 echo ;
161 echo "Where HOST and TARGET are something like \"vax\", \"sun3\", \"encore\", etc." ;
162 echo "Asking for more than one \"+target\" implies \"+forcesubdirs\". Any other" ;
163 echo "options given will apply to all targets.") 1>&2
164
165 if [ -r config.status ] ; then
166 cat config.status
167 fi
168
169 exit 1
170 fi
171
172 #### configure.in common parts come in here.
173 # This file is a shell script that supplies the information necessary
174 # to tailor a template configure script into the configure script
175 # appropriate for this directory. For more information, check any
176 # existing configure script.
177
178 srctrigger=ar.c
179 srcname="binutils"
180
181 # per-host:
182
183
184 files=
185 links=
186
187 ## end of common part
188
189 # are we rebuilding config itself?
190 if [ -n "${template}" ] ; then
191 if [ ! -r ${template} ] ; then
192 echo "Can't find template ${template}."
193 exit 1
194 fi
195
196 mv configure configure.old
197 echo "#!/bin/sh" > configure
198 echo "# Please do not edit this file. It is generated automatically from" >> configure
199 echo "# configure.in and a configure template." >> configure
200 echo "configdirs=" >> configure
201 echo >> configure
202
203 if [ -r configure.in ] ; then
204 if [ -z "`grep '^# per\-host:' configure.in`" ] ; then
205 echo `pwd`/configure.in has no "per-host:" line.
206 exit 1
207 fi
208
209 if [ -z "`grep '^# per\-target:' configure.in`" ] ; then
210 echo `pwd`/configure.in has no "per-target:" line.
211 exit 1
212 fi
213
214 sed -e '/^# per\-target:/,$d' configure.in > configure.com
215 sed -e '1,/^# per\-target:/d' configure.in > configure.tgt
216
217 sed -e '/^#### configure.in common parts/ r configure.com' \
218 -e '/^#### / r configure.tgt' \
219 ${template} >> configure
220
221 rm -f configure.com configure.tgt configure.hst
222 else
223 echo Warning: no configure.in in `pwd`
224 cat ${template} >> configure
225 fi
226
227 chmod a+x configure
228 rm configure.old
229 echo Rebuilt configure in `pwd`
230
231 if [ -z "${norecurse}" ] ; then
232 while [ -n "${configdirs}" ] ; do
233 # set configdir to car of configdirs, configdirs to cdr of configdirs
234 set ${configdirs}; configdir=$1; shift; configdirs=$*
235
236 if [ "`echo ${configdir}.*`" != "${configdir}.*" ] ; then
237 targetspecificdirs=${configdir}.*
238 else
239 targetspecificdirs=
240 fi
241
242 for i in ${configdir} ${targetspecificdirs} ; do
243 if [ -r $i/configure ] ; then
244 (cd $i ;
245 ./configure +template=${template} ${verbose})
246 else
247 echo No configure script in `pwd`/$i
248 fi
249 done
250 done
251 fi
252
253 exit 0
254 fi
255
256 # some sanity checks on configure.in
257 if [ -z "${srctrigger}" ] ; then
258 echo srctrigger not set in configure.in. `pwd` not configured.
259 exit 1
260 fi
261
262 for host in ${hosts} ; do
263 # Default other arg
264 if [ -z "${targets}" -o -n "${defaulttargets}" ] ; then
265 targets=${host}
266 defaulttargets=true
267 fi
268
269 #### configure.in per-host parts come in here.
270
271 files=
272 links=
273
274 ## end of per-target part
275
276
277 for target in ${targets} ; do
278
279 if [ -n "${verbose}" ] ; then
280 echo " "target=\"${target}\"
281 fi
282
283 #### configure.in per-target parts come in here.
284
285 files=
286 links=
287
288 ## end of per-target part
289
290 # Temporarily, we support only direct subdir builds.
291 hostsubdir=Host-${host}
292 targetsubdir=Target-${target}
293
294 if [ -n "${removing}" ] ; then
295 if [ -d "${hostsubdir}/${targetsubdir}" ] ; then
296 rm -rf ${hostsubdir}/${targetsubdir}
297
298 if [ -z "`(ls ${hostsubdir}) 2>&1 | grep Target-`" ] ; then
299 rm -rf ${hostsubdir}
300 fi
301 else
302 rm -f Makefile config.status ${links}
303 fi
304 else
305 if [ -n "${forcesubdirs}" ] ; then
306 # check for existing status before allowing forced subdirs.
307 if [ -f Makefile ] ; then
308 echo "Makefile already exists in source directory. `pwd` not configured."
309 exit 1
310 fi
311
312 if [ ! -d ${hostsubdir} ] ; then mkdir ${hostsubdir} ; fi
313 cd ${hostsubdir}
314
315 if [ ! -d ${targetsubdir} ] ; then mkdir ${targetsubdir} ; fi
316 cd ${targetsubdir}
317
318 srcdir=../..
319 else
320 # if not subdir builds, then make sure none exist.
321 if [ -n "`(ls .) 2>&1 | grep Host-`" ] ; then
322 echo "Configured subdirs exist. `pwd` not configured."
323 exit 1
324 fi
325 fi
326
327 # Find the source files, if location was not specified.
328 if [ -z "${srcdir}" ] ; then
329 srcdirdefaulted=1
330 srcdir=.
331 if [ -n "${srctrigger}" -a ! -r ${srctrigger} ] ; then
332 srcdir=..
333 fi
334 fi
335
336 if [ -n "${srctrigger}" -a ! -r ${srcdir}/${srctrigger} ] ; then
337 if [ -z "${srcdirdefaulted}" ] ; then
338 echo "${progname}: Can't find ${srcname} sources in \`${srcdir}'." 1>&2
339 else
340 echo "${progname}: Can't find ${srcname} sources in \`.' or \`..'." 1>&2
341 fi
342
343 exit 1
344 fi
345
346 # Set up the list of links to be made.
347 # ${links} is the list of link names, and ${files} is the list of names to link to.
348
349 # Make the links.
350 while [ -n "${files}" ] ; do
351 # set file to car of files, files to cdr of files
352 set ${files}; file=$1; shift; files=$*
353 set ${links}; link=$1; shift; links=$*
354
355 if [ ! -r ${srcdir}/${file} ] ; then
356 echo "${progname}: cannot create a link \"${link}\"," 1>&2
357 echo "since the file \"${file}\" does not exist." 1>&2
358 exit 1
359 fi
360
361 ${remove} -f ${link}
362 rm -f config.status
363 # Make a symlink if possible, otherwise try a hard link
364 ${symbolic_link} ${srcdir}/${file} ${link} 2>/dev/null || ${hard_link} ${srcdir}/${file} ${link}
365
366 if [ ! -r ${link} ] ; then
367 echo "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
368 exit 1
369 fi
370 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
371 done
372
373 # Create a .gdbinit file which runs the one in srcdir
374 # and tells GDB to look there for source files.
375
376 case ${srcdir} in
377 .)
378 ;;
379 *)
380 echo "dir ." > .gdbinit
381 echo "dir ${srcdir}" >> .gdbinit
382 echo "source ${srcdir}/.gdbinit" >> .gdbinit
383 ;;
384 esac
385
386 # Install a makefile, and make it set VPATH
387 # if necessary so that the sources are found.
388 # Also change its value of srcdir.
389
390 # FIXME-someday: This business of always writing to .tem and mv back
391 # is so that I don't screw things up while developing. Once this
392 # template is stable, these should be optimized. xoxorich.
393
394 # Define macro CROSS_COMPILE in compilation if this is a cross-compiler.
395 if [ "${host}" != "${target}" ] ; then
396 echo "CROSS=-DCROSS_COMPILE" > Makefile
397 echo "ALL=start.encap" >> Makefile
398 else
399 echo "ALL=all.internal" > Makefile
400 fi
401
402 # set target, host, VPATH
403 echo "host = ${host}" >> Makefile
404 echo "target = ${target}" >> Makefile
405
406 if [ -n "${forcesubdirs}" ] ; then
407 echo "subdir = /${hostsubdir}/${targetsubdir}" >> Makefile
408 else
409 echo "subdir =" >> Makefile
410 fi
411
412 # echo "workdir = `pwd`" >> Makefile
413 echo "VPATH = ${srcdir}" >> Makefile
414
415 # add Makefile.in
416 cat ${srcdir}/Makefile.in >> Makefile
417
418 # and shake thoroughly.
419 host_var_file=hmake-${host}
420 target_var_file=tmake-${target}
421
422 # Conditionalize the makefile for this host.
423 if [ -f ${srcdir}/config/${host_var_file} ] ; then
424 sed -e "/^####/ r ${srcdir}/config/${host_var_file}" Makefile > Makefile.tem
425 mv Makefile.tem Makefile
426 fi
427
428 # Conditionalize the makefile for this target.
429 if [ -f ${srcdir}/config/${target_var_file} ] ; then
430 sed -e "/^####/ r ${srcdir}/config/${target_var_file}" Makefile > Makefile.tem
431 mv Makefile.tem Makefile
432 fi
433
434 # set srcdir
435 sed "s@^srcdir = \.@srcdir = ${srcdir}@" Makefile > Makefile.tem
436 mv Makefile.tem Makefile
437
438 # set destdir
439 if [ -n "${destdir}" ] ; then
440 sed "s:^destdir =.*$:destdir = ${destdir}:" Makefile > Makefile.tem
441 mv Makefile.tem Makefile
442 fi
443
444 # Remove all formfeeds, since some Makes get confused by them.
445 sed "s/\f//" Makefile >> Makefile.tem
446 mv Makefile.tem Makefile
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 using=
457 if [ -f ${srcdir}/config/${host_var_file} ] ; then
458 using=" using \"${host_var_file}\""
459 fi
460
461 if [ -f ${srcdir}/config/${target_var_file} ] ; then
462 if [ -z "${using}" ] ; then
463 andusing=" using \"${target_var_file}\""
464 else
465 andusing="${using} and \"${target_var_file}\""
466 fi
467 else
468 andusing=${using}
469 fi
470
471 echo "Created \"Makefile\"" in `pwd`${andusing}.
472
473 if [ "${host}" = "${target}" ] ; then
474 echo "Links are now set up for use with a ${target}." \
475 > config.status
476 # | tee ${srcdir}/config.status
477 else
478 echo "Links are now set up for host ${host} and target ${target}." \
479 > config.status
480 # | tee ${srcdir}/config.status
481 fi
482
483 originaldir=`pwd`
484 cd ${srcdir}
485 fi
486 done
487 done
488
489 # If there are subdirectories, then recurse.
490
491 if [ -n "${norecurse}" -o -z "${configdirs}" ] ; then exit 0 ; fi
492
493 # configdirs is not null
494 for configdir in ${configdirs} ; do
495 echo Configuring ${configdir}...
496 specifics=
497 commons=
498
499 if [ -n "${defaulttargets}" ] ; then
500 for host in ${hosts} ; do
501 if [ -d ${configdir}.${host} ] ; then
502 newspecifics="${specifics} ${host}"
503 specifics=${newspecifics}
504 else
505 newcommons="${commons} ${host}"
506 commons=${newcommons}
507 fi # if target specific
508 done # for each host
509
510 if [ -n "${commons}" ] ; then
511 (cd ${configdir} ;
512 ./configure ${commons} ${verbose} ${forcesubdirs} ${removing}) \
513 | sed 's/^/ /'
514 fi # if any common hosts
515
516 if [ -n "${specifics}" ] ; then
517 for host in ${specifics} ; do
518 echo Configuring target specific directory ${configdir}.${host}...
519 (cd ${configdir}.${host} ;
520 ./configure ${host} ${verbose} ${forcesubdirs} ${removing}) \
521 | sed 's/^/ /'
522 done # for host in specifics
523 fi # if there are any specifics
524 else
525
526 for target in ${targets} ; do
527 if [ -d ${configdir}.${target} ] ; then
528 newspecifics="${specifics} ${target}"
529 specifics=${newspecifics}
530 else
531 newcommons="${commons} +target=${target}"
532 commons=${newcommons}
533 fi
534
535 done # check for target specific dir override
536
537 if [ -n "${verbose}" ] ; then
538 echo " "commons=\"${commons}\"
539 echo " "specifics=\"${specifics}\"
540 fi # if verbose
541
542 if [ -n "${commons}" ] ; then
543 (cd ${configdir} ;
544 ./configure ${hosts} ${verbose} ${forcesubdirs} ${removing} ${commons}) \
545 | sed 's/^/ /'
546 fi # if any commons
547
548 if [ -n "${specifics}" ] ; then
549 for target in ${specifics} ; do
550 echo Configuring target specific directory ${configdir}.${target}...
551 (cd ${configdir}.${target} ;
552 ./configure ${hosts} ${verbose} ${forcesubdirs} ${removing} "+target=${target}") \
553 | sed 's/^/ /'
554 done
555 fi # if any specifics
556 fi # not default targets
557 done
558
559 exit 0
560
561 #
562 # $Log$
563 # Revision 1.6 1991/04/16 00:04:50 rich
564 # Now handles multiple hosts and targets.
565 #
566 # Revision 1.5 1991/04/15 23:43:44 rich
567 # Now handles multiple hosts and targets.
568 #
569 # Revision 1.4 1991/04/13 02:11:03 rich
570 # Config cut 3. We now almost install a29k.
571 #
572 # Revision 1.3 1991/04/11 02:41:54 rich
573 # Cut 2 config. Subdirs.
574 #
575 #
576 #
577
578 #
579 # Local Variables:
580 # fill-column: 131
581 # End:
582 #
583
584 # end of configure.template