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