4 # Copyright (C) 1988, 1990, 1991 Free Software Foundation, Inc.
6 #This file is part of GNU.
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.
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.
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. */
25 # Shell script to create proper links to machine-dependent files in
26 # preparation for compilation.
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.
40 #symbolic_link="echo ln -s"
44 # clear some things potentially inherited from environment.
52 Makefile_in=Makefile.in
73 -destdir=* | +destdir=* | +destdi=* | +destd=* | +dest=* | +des=* | +de=* | +d=*)
74 destdir=`echo ${arg} | sed 's/[+-]d[a-z]*=//'`
76 -languages=* | +languages=* | +language=* | +languag=* \
77 | +langua=* | +langu=* | +lang=* | +lan=* | +la=* \
79 languages="${languages} `echo ${arg} | sed 's/[+-]l[a-z]*=//'`"
93 -recurring | +recurring | +recurrin | +recurri | +recurr | +recur | +recu | +rec | +re)
99 # -srcdir=* | +srcdir=* | +srcdi=* | +srcd=* | +src=* | +sr=* | +s=*)
100 # srcdir=`echo ${arg} | sed 's/[+-]s[a-z]*=//'`
102 -subdirs | +f* | +su*)
105 -target=* | +target=* | +targe=* | +targ=* | +tar=* | +ta=*)
106 if [ -n "${targets}" ] ; then
110 newtargets="${targets} `echo ${arg} | sed 's/[+-]t[a-z]*=//'`"
111 targets="${newtargets}"
113 -template=* | +template=* | +templat=* | +templa=* | +templ=* | +temp=* | +tem=* | +te=*)
114 template=`echo ${arg} | sed 's/[+-]template=//'`
121 echo "Unrecognized option: \"${arg}\"". ;
126 if [ -n "${hosts}" ] ; then
130 newhosts="${hosts} ${arg}"
136 if [ -n "${verbose}" ] ; then
137 echo `pwd`/configure $*
140 # process host and target only if not rebuilding configure itself or removing.
141 if [ -z "${template}" -a -z "${removing}" -a -z "${fatal}" ] ; then
142 # Complain if an arg is missing
143 if [ -z "${hosts}" ] ; then
145 echo "configure: No HOST specified." ;
151 if [ -n "${fatal}" -o "${hosts}" = "help" ] ; then
152 (echo "Usage: configure HOST" ;
154 echo "Options: [defaults in brackets]" ;
155 echo " +ansi configure w/ANSI library. [no ansi lib]" ;
156 echo " +destdir=MYDIR configure for installation into MYDIR. [/usr/local]" ;
157 echo " +subdirs configure in subdirectories. [in source directories]" ;
158 echo " +lang=LANG configure to build LANG. [gcc]" ;
159 echo " +help print this message. [normal config]" ;
160 echo " +gas configure the compilers for use with gas. [native as]" ;
161 echo " +nfp configure the compilers default to soft floating point. [hard float]" ;
162 echo " +norecursion configure this directory only. [recurse]" ;
163 echo " +rm remove this configuration. [build a configuration]" ;
164 echo " +target=TARGET configure for TARGET. [TARGET = HOST]" ;
165 echo " +template=TEM rebuild configure using TEM. [normal config]" ;
167 echo "Where HOST and TARGET are something like \"vax\", \"sun3\", \"encore\", etc." ;
168 echo "Asking for more than one \"+target\" implies \"+subdirs\". Any other" ;
169 echo "options given will apply to all targets.") 1>&2
171 if [ -r config.status ] ; then
178 #### configure.in common parts come in here.
179 # This file is a shell script that supplies the information necessary
180 # to tailor a template configure script into the configure script
181 # appropriate for this directory. For more information, check any
182 # existing configure script.
187 ## end of common part.
189 # are we rebuilding config itself?
190 if [ -n "${template}" ] ; then
191 if [ ! -r ${template} ] ; then
192 echo '***' "Can't find template ${template}." 1>&2
197 sed -e '/^#### configure.in common parts come in here.$/,/^## end of common part.$/c\
198 #### configure.in common parts come in here.\
199 ## end of common part.' \
200 -e '/^#### configure.in per-host parts come in here.$/,/^## end of per-host part.$/c\
201 #### configure.in per-host parts come in here.\
202 ## end of per-host part.' \
203 -e '/^#### configure.in per-target parts come in here.$/,/^## end of per-target part.$/c\
204 #### configure.in per-target parts come in here.\
205 ## end of per-target part.' \
206 -e '/^#### configure.in post-target parts come in here.$/,/^## end of post-target part.$/c\
207 #### configure.in post-target parts come in here.\
208 ## end of post-target part.' \
209 < ${template} > template.new
211 if [ -r configure.in ] ; then
212 if [ -z "`grep '^# per\-host:' configure.in`" ] ; then
213 echo '***' `pwd`/configure.in has no "per-host:" line. 1>&2
217 if [ -z "`grep '^# per\-target:' configure.in`" ] ; then
218 echo '***' `pwd`/configure.in has no "per-target:" line. 1>&2
222 # split configure.in into common, per-host, per-target,
223 # and post-target parts. Post-target is optional.
224 sed -e '/^# per\-host:/,$d' configure.in > configure.com
225 sed -e '1,/^# per\-host:/d' -e '/^# per\-target:/,$d' configure.in > configure.hst
226 if grep -s '^# post-target:' configure.in ; then
227 sed -e '1,/^# per\-target:/d' -e '/^# post\-target:/,$d' configure.in > configure.tgt
228 sed -e '1,/^# post\-target:/d' configure.in > configure.pos
230 sed -e '1,/^# per\-target:/d' configure.in > configure.tgt
235 sed -e '/^#### configure.in common parts come in here.$/ r configure.com' \
236 -e '/^#### configure.in per\-host parts come in here.$/ r configure.hst' \
237 -e '/^#### configure.in per\-target parts come in here.$/ r configure.tgt' \
238 -e '/^#### configure.in post\-target parts come in here.$/ r configure.pos' \
239 template.new > configure.new
241 rm -f configure.com configure.tgt configure.hst configure.pos
243 echo Warning: no configure.in in `pwd`
244 cat ${template} >> configure
247 chmod a+x configure.new
249 # mv configure configure.old
250 mv configure.new configure
252 if [ -n "${verbose}" ] ; then
253 echo Rebuilt configure in `pwd`
256 # Now update config.sub from the template directory.
257 if echo "$template" | grep -s 'configure$' ; then
258 cp `echo "$template" | sed s/configure$/config.sub/` ./config.sub.new
259 # mv config.sub config.sub.old
260 mv config.sub.new config.sub
262 if [ -n "${verbose}" ] ; then
263 echo Rebuilt config.sub in `pwd`
267 if [ -z "${norecursion}" ] ; then
268 # If template is relative path, make it absolute for recurring.
269 if echo "${template}" | grep -s '^/' ; then
272 template=`pwd`/${template}
275 while [ -n "${configdirs}" ] ; do
276 # set configdir to car of configdirs, configdirs to cdr of configdirs
277 set ${configdirs}; configdir=$1; shift; configdirs=$*
279 if [ "`echo ${configdir}.*`" != "${configdir}.*" ] ; then
280 targetspecificdirs=${configdir}.*
285 for i in ${configdir} ${targetspecificdirs} ; do
287 if [ -r $i/configure ] ; then
289 ./configure +template=${template} ${verbose})
291 echo Warning: No configure script in `pwd`/$i
294 if [ -n "${verbose}" ] ; then
295 echo Warning: directory $i is missing.
305 # some sanity checks on configure.in
306 if [ -z "${srctrigger}" ] ; then
307 echo Warning: srctrigger not set in configure.in. `pwd` not configured.
311 for host in ${hosts} ; do
313 if [ -z "${targets}" -o -n "${defaulttargets}" ] ; then
320 result=`/bin/sh ./config.sub ${host}`
321 host_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
322 host_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
323 host_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
324 host=${host_cpu}-${host_vendor}-${host_os}
325 host_makefile_frag=config/hmake-${host}
327 #### configure.in per-host parts come in here.
329 if [ "${host_os}" = "posix" ] ; then
332 case "${host_cpu}" in
333 rs6000) bfd_host=aix ;;
335 case "${host_vendor}" in
336 dec) bfd_host=dec3100 ;;
337 sgi) bfd_host=irix3 ;;
341 case "${host_vendor}" in
344 dgux) bfd_host=dgux ;;
350 case "${host_vendor}" in
353 amigados) bfd_host=amigados ;;
354 svr4) bfd_host=amix ;;
359 hpux) bfd_host=hp9000 ;;
360 bsd) bfd_host=hp300bsd ;;
363 sony) bfd_host=news ;;
364 sun) bfd_host=sun3 ;;
369 case "${host_vendor}" in
372 sysv) bfd_host=i386v ;;
379 case "${host_vendor}" in
380 sun) bfd_host=sun4 ;;
387 a29k) bfd_host=ultra3
395 ultrix) bfd_host=vaxult ;;
402 if [ ! -f config/h-${bfd_host} ] ; then
403 echo '***' BFD does not support host ${host}: no file config/h-${bfd_host}
407 host_makefile_frag=config/h-${bfd_host}
409 ## end of per-host part.
411 for target in ${targets} ; do
413 target_alias=${target}
414 result=`/bin/sh ./config.sub ${target}`
415 target_cpu=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
416 target_vendor=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
417 target_os=`echo $result | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
418 target=${target_cpu}-${target_vendor}-${target_os}
419 target_makefile_frag=config/tmake-${target}
421 #### configure.in per-target parts come in here.
423 case "${target_vendor}" in
424 aout | coff | bout | elf) bfd_target=${target_cpu}-${target_vendor} ;;
425 sony) bfd_target=news ;;
426 intel) bfd_target=${target_cpu}-coff ;;
427 cbm) bfd_target=${target_cpu}-elf ;;
430 case "${target_cpu}" in
431 h8300) bfd_target=h8300-ieee ;;
432 *) echo "bad hitachi cpu" ;;
438 case "${target_cpu}" in
439 i960) bfd_target=i960-bout ;;
440 m68k) bfd_target=m68k-aout ;;
444 case "${target_cpu}" in
445 m68k) bfd_target=m68k-aout ;;
446 sparc) bfd_target=sparc-aout ;;
450 case "${target_cpu}" in
451 mips) bfd_target=dec3100 ;;
452 vax) bfd_target=vax ;;
456 case "${target_cpu}" in
458 case "${target_os}" in
459 hpux) bfd_target=hp9000 ;;
460 bsd) bfd_target=hp300bsd ;;
466 case "${target_cpu}" in
472 case "${target_cpu}" in
473 i386) bfd_target=i386-coff ;;
474 a29k) case "${target_os}" in
475 aout) bfd_target=a29k-aout ;;
476 coff) bfd_target=a29k-coff ;;
477 sym1) bfd_target=a29k-coff ;;
480 tahoe | vax) bfd_target=${target_cpu} ;;
484 case "${target_cpu}" in
485 tahoe | vax) bfd_target=${target_cpu} ;;
490 if [ ! -f config/t-${bfd_target} ] ; then
491 echo '***' BFD does not support target ${target}: no file config/t-${bfd_target}
495 target_makefile_frag=config/t-${bfd_target}
499 ## end of per-target part.
501 # Temporarily, we support only direct subdir builds.
502 hostsubdir=H-${host_alias}
503 targetsubdir=T-${target_alias}
505 if [ -n "${removing}" ] ; then
506 if [ -n "${subdirs}" ] ; then
507 if [ -d "${hostsubdir}" ] ; then
508 rm -rf ${hostsubdir}/${targetsubdir}
510 if [ -z "`(ls ${hostsubdir}) 2>&1 | grep Target- | grep -v Target-independent`" ] ; then
514 echo Warning: no `pwd`/${hostsubdir} to remove.
517 rm -f ${Makefile} config.status ${links}
520 if [ -n "${subdirs}" ] ; then
521 # check for existing status before allowing forced subdirs.
522 if [ -f ${Makefile} ] ; then
523 echo '***' "${Makefile} already exists in source directory. `pwd` not configured." 1>&2
527 if [ ! -d ${hostsubdir} ] ; then mkdir ${hostsubdir} ; fi
530 if [ ! -d ${targetsubdir} ] ; then
531 if [ -z "${commontargets}" ] ; then
532 mkdir ${targetsubdir}
534 if [ ! -d Target-independent ] ; then
535 mkdir Target-independent
538 ${symbolic_link} Target-independent ${targetsubdir}
539 fi # if target independent
540 fi # if no target dir yet
546 # if not subdir builds, then make sure none exist.
547 if [ -n "`(ls .) 2>&1 | grep Host-`" ] ; then
548 echo '***' "Configured subdirs exist. `pwd` not configured." 1>&2
553 # Find the source files, if location was not specified.
554 if [ -z "${srcdir}" ] ; then
557 if [ -n "${srctrigger}" -a ! -r ${srctrigger} ] ; then
562 if [ -n "${srctrigger}" -a ! -r ${srcdir}/${srctrigger} ] ; then
563 if [ -z "${srcdirdefaulted}" ] ; then
564 echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/${srcdir}" 1>&2
566 echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/. or `pwd`/.." 1>&2
569 echo '***' \(At least ${srctrigger} is missing.\) 1>&2
573 # Set up the list of links to be made.
574 # ${links} is the list of link names, and ${files} is the list of names to link to.
577 while [ -n "${files}" ] ; do
578 # set file to car of files, files to cdr of files
579 set ${files}; file=$1; shift; files=$*
580 set ${links}; link=$1; shift; links=$*
582 if [ ! -r ${srcdir}/${file} ] ; then
583 echo '***' "${progname}: cannot create a link \"${link}\"," 1>&2
584 echo '***' "since the file \"${file}\" does not exist." 1>&2
590 # Make a symlink if possible, otherwise try a hard link
591 ${symbolic_link} ${srcdir}/${file} ${link} 2>/dev/null || ${hard_link} ${srcdir}/${file} ${link}
593 if [ ! -r ${link} ] ; then
594 echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
598 if [ -n "${verbose}" ] ; then
599 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
603 # Create a .gdbinit file which runs the one in srcdir
604 # and tells GDB to look there for source files.
610 echo "dir ." > .gdbinit
611 echo "dir ${srcdir}" >> .gdbinit
612 echo "source ${srcdir}/.gdbinit" >> .gdbinit
616 # Install a makefile, and make it set VPATH
617 # if necessary so that the sources are found.
618 # Also change its value of srcdir.
620 # FIXME-someday: This business of always writing to .tem and mv back
621 # is so that I don't screw things up while developing. Once this
622 # template is stable, these should be optimized. xoxorich.
624 # Define macro CROSS_COMPILE in compilation if this is a cross-compiler.
625 if [ "${host}" != "${target}" ] ; then
626 echo "CROSS=-DCROSS_COMPILE" > ${Makefile}
627 echo "ALL=start.encap" >> ${Makefile}
629 echo "ALL=all.internal" > ${Makefile}
632 # set target, host, VPATH
633 echo "host_alias = ${host_alias}" >> ${Makefile}
634 echo "host_cpu = ${host_cpu}" >> ${Makefile}
635 echo "host_vendor = ${host_vendor}" >> ${Makefile}
636 echo "host_os = ${host_os}" >> ${Makefile}
638 echo "target_alias = ${target_alias}" >> ${Makefile}
639 echo "target_cpu = ${target_cpu}" >> ${Makefile}
640 echo "target_vendor = ${target_vendor}" >> ${Makefile}
641 echo "target_os = ${target_os}" >> ${Makefile}
643 if [ -n "${subdirs}" ] ; then
644 echo "subdir = /${hostsubdir}/${targetsubdir}" >> ${Makefile}
646 echo "subdir =" >> ${Makefile}
649 # echo "workdir = `pwd`" >> ${Makefile}
650 echo "VPATH = ${srcdir}" >> ${Makefile}
652 # add "Makefile.in" (or whatever it's called)
653 cat ${srcdir}/${Makefile_in} >> ${Makefile}
655 # Conditionalize the makefile for this host.
656 if [ -f ${srcdir}/${host_makefile_frag} ] ; then
657 (echo "host_makefile_frag = ${srcdir}/${host_makefile_frag}" ;
658 sed -e "/^####/ r ${srcdir}/${host_makefile_frag}" ${Makefile}) > Makefile.tem
659 mv Makefile.tem ${Makefile}
662 # Conditionalize the makefile for this target.
663 if [ -f ${srcdir}/${target_makefile_frag} ] ; then
664 (echo "target_makefile_frag = ${srcdir}/${target_makefile_frag}" ;
665 sed -e "/^####/ r ${srcdir}/${target_makefile_frag}" ${Makefile}) > Makefile.tem
666 mv Makefile.tem ${Makefile}
670 sed "s@^srcdir = \.@srcdir = ${srcdir}@" ${Makefile} > Makefile.tem
671 mv Makefile.tem ${Makefile}
674 if [ -n "${destdir}" ] ; then
675 sed "s:^destdir =.*$:destdir = ${destdir}:" ${Makefile} > Makefile.tem
676 mv Makefile.tem ${Makefile}
680 sed "s:^SUBDIRS =.*$:SUBDIRS = ${configdirs}:" ${Makefile} > Makefile.tem
681 mv Makefile.tem ${Makefile}
684 sed "s:^NONSUBDIRS =.*$:NONSUBDIRS = ${noconfigdirs}:" ${Makefile} > Makefile.tem
685 mv Makefile.tem ${Makefile}
688 if [ -f ${srcdir}/${host_makefile_frag} ] ; then
689 using=" using \"${host_makefile_frag}\""
692 # remove any form feeds.
693 sed -e "s/
\f//" ${Makefile} > Makefile.tem
694 mv Makefile.tem ${Makefile}
696 if [ -f ${srcdir}/${target_makefile_frag} ] ; then
697 if [ -z "${using}" ] ; then
698 andusing=" using \"${target_makefile_frag}\""
700 andusing="${using} and \"${target_makefile_frag}\""
706 if [ -n "${verbose}" -o -z "${recurring}" ] ; then
707 echo "Created \"${Makefile}\"" in `pwd`${andusing}.
710 #### configure.in post-target parts come in here.
712 ## end of post-target part.
714 # describe the chosen configuration in config.status.
715 # Make that file a shellscript which will reestablish
716 # the same configuration. Used in Makefiles to rebuild
720 # ${srcname} was configured as follows:
721 ${srcdir}/configure" ${arguments} `if [ -z "${norecursion}" ] ; then echo +norecursion ; else true ; fi` > config.status
722 chmod a+x config.status
728 # If there are subdirectories, then recurse.
729 if [ -z "${norecursion}" -a -n "${configdirs}" ] ; then
730 for configdir in ${configdirs} ; do
731 if [ -n "${verbose}" ] ; then
732 echo Configuring ${configdir}...
735 if [ -d ${configdir} ] ; then
737 ./configure +recurring ${host_alias} +target=${target_alias} \
738 ${verbose} ${subdirs} ${removing} +destdir=${destdir}) \
741 if [ -n "${verbose}" ] ; then
742 echo Warning: directory \"${configdir}\" is missing.
747 done # for each target
749 # Now build a Makefile for this host.
750 if [ -n "${subdirs}" -a ! -n "${removing}" ] ; then
752 cat > GNUmakefile << E!O!F
753 # Makefile generated by configure for host ${host_alias}.
755 ALL := $(shell ls -d Target-*)
758 $(foreach subdir,$(ALL),$(MAKE) -C $(subdir) \$@ &&) true