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