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.
42 #symbolic_link="echo ln -s"
46 # clear some things potentially inherited from environment.
49 Makefile_in=Makefile.in
68 #if [ "$0" != "./configure" ] ; then
72 #if [ ! -f ./config.sub ] ; then
73 # echo '***' Can not find config.sub.
84 -destdir=* | +destdir=* | +destdi=* | +destd=* | +dest=* | +des=* | +de=* | +d=*)
85 destdir=`echo ${arg} | sed 's/[+-]d[a-z]*=//'`
87 -languages=* | +languages=* | +language=* | +languag=* \
88 | +langua=* | +langu=* | +lang=* | +lan=* | +la=* \
90 languages="${languages} `echo ${arg} | sed 's/[+-]l[a-z]*=//'`"
104 -recurring | +recurring | +recurrin | +recurri | +recurr | +recur | +recu | +rec | +re)
110 -site=* | +site=* | +sit=* | +si=*)
111 site=`echo ${arg} | sed 's/[+-]s[a-z]*=//'`
113 # -srcdir=* | +srcdir=* | +srcdi=* | +srcd=* | +src=* | +sr=*)
114 # srcdir=`echo ${arg} | sed 's/[+-]s[a-z]*=//'`
119 -target=* | +target=* | +targe=* | +targ=* | +tar=* | +ta=*)
120 if [ -n "${targets}" ] ; then
124 newtargets="${targets} `echo ${arg} | sed 's/[+-]t[a-z]*=//'`"
125 targets="${newtargets}"
132 echo "Unrecognized option: \"${arg}\"". ;
137 if [ -n "${hosts}" ] ; then
141 newhosts="${hosts} ${arg}"
147 if [ -n "${verbose}" ] ; then
148 echo `pwd`/configure $*
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
156 echo "configure: No HOST specified." ;
162 if [ -n "${fatal}" -o "${hosts}" = "help" ] ; then
163 (echo "Usage: configure HOST" ;
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]" ;
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
181 if [ -r config.status ] ; then
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
195 if [ -z "`grep '^# per\-target:' configure.in`" ] ; then
196 echo '***' `pwd`/configure.in has no "per-target:" line. 1>&2
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
208 sed -e '1,/^# per\-target:/d' configure.in > configure.tgt
213 echo '***' No configure.in in `pwd`
217 ### do common part of configure.in
221 # some sanity checks on configure.in
222 if [ -z "${srctrigger}" ] ; then
223 echo '***' srctrigger not set in `pwd`/configure.in.
227 for host in ${hosts} ; do
229 if [ -z "${targets}" -o -n "${defaulttargets}" ] ; then
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}
245 for target in ${targets} ; do
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}
257 # Temporarily, we support only direct subdir builds.
258 hostsubdir=H-${host_alias}
259 targetsubdir=T-${target_alias}
261 if [ -n "${removing}" ] ; then
262 if [ -n "${subdirs}" ] ; then
263 if [ -d "${hostsubdir}" ] ; then
264 rm -rf ${hostsubdir}/${targetsubdir}
266 if [ -z "`(ls ${hostsubdir}) 2>&1 | grep T- | grep -v T-independent`" ] ; then
270 echo Warning: no `pwd`/${hostsubdir} to remove.
273 rm -f ${Makefile} config.status ${links}
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
283 if [ ! -d ${hostsubdir} ] ; then mkdir ${hostsubdir} ; fi
286 if [ ! -d ${targetsubdir} ] ; then
287 if [ -z "${commontargets}" ] ; then
288 mkdir ${targetsubdir}
290 if [ ! -d T-independent ] ; then
294 ${symbolic_link} T-independent ${targetsubdir}
295 fi # if target independent
296 fi # if no target dir yet
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
311 # Find the source files, if location was not specified.
312 if [ -z "${srcdir}" ] ; then
315 if [ -n "${srctrigger}" -a ! -r ${srctrigger} ] ; then
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
324 echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/. or `pwd`/.." 1>&2
327 echo '***' \(At least ${srctrigger} is missing.\) 1>&2
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.
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=$*
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
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}
351 if [ ! -r ${link} ] ; then
352 echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
356 if [ -n "${verbose}" ] ; then
357 echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
361 # Create a .gdbinit file which runs the one in srcdir
362 # and tells GDB to look there for source files.
368 echo "dir ." > .gdbinit
369 echo "dir ${srcdir}" >> .gdbinit
370 echo "source ${srcdir}/.gdbinit" >> .gdbinit
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.
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.
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}
387 echo "ALL=all.internal" > ${Makefile}
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}
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}
401 if [ -n "${subdirs}" ] ; then
402 echo "subdir = /${hostsubdir}/${targetsubdir}" >> ${Makefile}
404 echo "subdir =" >> ${Makefile}
407 # echo "workdir = `pwd`" >> ${Makefile}
408 echo "VPATH = ${srcdir}" >> ${Makefile}
410 # add "Makefile.in" (or whatever it's called)
411 cat ${srcdir}/${Makefile_in} >> ${Makefile}
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}
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}
427 # Conditionalize the makefile for this site.
428 if [ -n "${site}" ] ; then
429 site_makefile_frag=smake-${site}
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}
439 sed "s@^srcdir = \.@srcdir = ${srcdir}@" ${Makefile} > Makefile.tem
440 mv Makefile.tem ${Makefile}
443 if [ -n "${destdir}" ] ; then
444 sed "s:^destdir =.*$:destdir = ${destdir}:" ${Makefile} > Makefile.tem
445 mv Makefile.tem ${Makefile}
449 sed "s:^SUBDIRS =.*$:SUBDIRS = ${configdirs}:" ${Makefile} > Makefile.tem
450 mv Makefile.tem ${Makefile}
453 sed "s:^NONSUBDIRS =.*$:NONSUBDIRS = ${noconfigdirs}:" ${Makefile} > Makefile.tem
454 mv Makefile.tem ${Makefile}
456 # remove any form feeds.
457 sed -e "s/
\f//" ${Makefile} > Makefile.tem
458 mv Makefile.tem ${Makefile}
461 if [ -f ${srcdir}/${host_makefile_frag} ] ; then
462 using=" using \"${host_makefile_frag}\""
465 if [ -f ${srcdir}/${target_makefile_frag} ] ; then
466 if [ -z "${using}" ] ; then
467 andusing=" using \"${target_makefile_frag}\""
469 andusing="${using} and \"${target_makefile_frag}\""
475 if [ -f ${srcdir}/${site_makefile_frag} ] ; then
476 if [ -z "${andusing}" ] ; then
477 andandusing=" using \"${site_makefile_frag}\""
479 andandusing="${andusing} and \"${site_makefile_frag}\""
485 if [ -n "${verbose}" -o -z "${recurring}" ] ; then
486 echo "Created \"${Makefile}\"" in `pwd`${andandusing}.
489 if [ -f ./configure.pos ] ; then
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
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
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}...
514 if [ -d ${configdir} ] ; then
516 configure +recurring ${host_alias} +target=${target_alias} \
517 ${verbose} ${subdirs} ${removing} +destdir=${destdir}) \
520 if [ -n "${verbose}" ] ; then
521 echo Warning: directory \"${configdir}\" is missing.
526 done # for each target
528 # Now build a Makefile for this host.
529 if [ -n "${subdirs}" -a ! -n "${removing}" ] ; then
531 cat > GNUmakefile << E!O!F
532 # Makefile generated by configure for host ${host_alias}.
534 ALL := $(shell ls -d T-*)
537 $(foreach subdir,$(ALL),$(MAKE) -C $(subdir) \$@ &&) true
547 rm -f configure.com configure.tgt configure.hst configure.pos
554 # Revision 1.46 1991/10/02 06:29:53 rich
555 # Added +site=foo option for naming site specific Makefile fragments.
557 # Revision 1.45 1991/10/02 06:15:13 rich
558 # Removed +f option. Used to stand for +forcesubdirs which is now
561 # Revision 1.44 1991/10/02 06:02:35 rich
562 # Added rcs log line.