+ if [ -n "${subdirs}" ] ; then
+ # check for existing status before allowing forced subdirs.
+ if [ -f ${Makefile} ] ; then
+ echo '***' "${Makefile} already exists in source directory. `pwd` not configured." 1>&2
+ exit 1
+ fi
+
+ if [ ! -d ${hostsubdir} ] ; then mkdir ${hostsubdir} ; fi
+ cd ${hostsubdir}
+
+ if [ ! -d ${targetsubdir} ] ; then
+ if [ -z "${commontargets}" ] ; then
+ mkdir ${targetsubdir}
+ else
+ if [ ! -d Target-independent ] ; then
+ mkdir Target-independent
+ fi
+
+ ${symbolic_link} Target-independent ${targetsubdir}
+ fi # if target independent
+ fi # if no target dir yet
+
+ cd ${targetsubdir}
+
+ srcdir=../..
+ else
+ # if not subdir builds, then make sure none exist.
+ if [ -n "`(ls .) 2>&1 | grep Host-`" ] ; then
+ echo '***' "Configured subdirs exist. `pwd` not configured." 1>&2
+ exit 1
+ fi
+ fi
+
+ # Find the source files, if location was not specified.
+ if [ -z "${srcdir}" ] ; then
+ srcdirdefaulted=1
+ srcdir=.
+ if [ -n "${srctrigger}" -a ! -r ${srctrigger} ] ; then
+ srcdir=..
+ fi
+ fi
+
+ if [ -n "${srctrigger}" -a ! -r ${srcdir}/${srctrigger} ] ; then
+ if [ -z "${srcdirdefaulted}" ] ; then
+ echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/${srcdir}" 1>&2
+ else
+ echo '***' "${progname}: Can't find ${srcname} sources in `pwd`/. or `pwd`/.." 1>&2
+ fi
+
+ echo '***' \(At least ${srctrigger} is missing.\) 1>&2
+ exit 1
+ fi
+
+ # Set up the list of links to be made.
+ # ${links} is the list of link names, and ${files} is the list of names to link to.
+
+ # Make the links.
+ while [ -n "${files}" ] ; do
+ # set file to car of files, files to cdr of files
+ set ${files}; file=$1; shift; files=$*
+ set ${links}; link=$1; shift; links=$*
+
+ if [ ! -r ${srcdir}/${file} ] ; then
+ echo '***' "${progname}: cannot create a link \"${link}\"," 1>&2
+ echo '***' "since the file \"${file}\" does not exist." 1>&2
+ exit 1
+ fi
+
+ ${remove} -f ${link}
+ rm -f config.status
+ # Make a symlink if possible, otherwise try a hard link
+ ${symbolic_link} ${srcdir}/${file} ${link} 2>/dev/null || ${hard_link} ${srcdir}/${file} ${link}
+
+ if [ ! -r ${link} ] ; then
+ echo '***' "${progname}: unable to link \"${link}\" to \"${srcdir}/${file}\"." 1>&2
+ exit 1
+ fi
+
+ if [ -n "${verbose}" ] ; then
+ echo "Linked \"${link}\" to \"${srcdir}/${file}\"."
+ fi
+ done
+
+ # Create a .gdbinit file which runs the one in srcdir
+ # and tells GDB to look there for source files.
+
+ case ${srcdir} in
+ .)
+ ;;
+ *)
+ echo "dir ." > .gdbinit
+ echo "dir ${srcdir}" >> .gdbinit
+ echo "source ${srcdir}/.gdbinit" >> .gdbinit
+ ;;
+ esac
+
+ # Install a makefile, and make it set VPATH
+ # if necessary so that the sources are found.
+ # Also change its value of srcdir.
+
+ # FIXME-someday: This business of always writing to .tem and mv back
+ # is so that I don't screw things up while developing. Once this
+ # template is stable, these should be optimized. xoxorich.
+
+ # Define macro CROSS_COMPILE in compilation if this is a cross-compiler.
+ if [ "${host}" != "${target}" ] ; then
+ echo "CROSS=-DCROSS_COMPILE" > ${Makefile}
+ echo "ALL=start.encap" >> ${Makefile}
+ else
+ echo "ALL=all.internal" > ${Makefile}
+ fi
+
+ # set target, host, VPATH
+ echo "host = ${host}" >> ${Makefile}
+ echo "target = ${target}" >> ${Makefile}
+
+ if [ -n "${subdirs}" ] ; then
+ echo "subdir = /${hostsubdir}/${targetsubdir}" >> ${Makefile}
+ else
+ echo "subdir =" >> ${Makefile}
+ fi
+
+ # echo "workdir = `pwd`" >> ${Makefile}
+ echo "VPATH = ${srcdir}" >> ${Makefile}
+
+ # add "Makefile.in" (or whatever it's called)
+ cat ${srcdir}/${Makefile_in} >> ${Makefile}
+
+ # Conditionalize the makefile for this host.
+ if [ -f ${srcdir}/${host_makefile_frag} ] ; then
+ sed -e "/^####/ r ${srcdir}/${host_makefile_frag}" ${Makefile} > Makefile.tem
+ mv Makefile.tem ${Makefile}
+ fi
+
+ # Conditionalize the makefile for this target.
+ if [ -f ${srcdir}/${target_makefile_frag} ] ; then
+ sed -e "/^####/ r ${srcdir}/${target_makefile_frag}" ${Makefile} > Makefile.tem
+ mv Makefile.tem ${Makefile}
+ fi
+
+ # set srcdir
+ sed "s@^srcdir = \.@srcdir = ${srcdir}@" ${Makefile} > Makefile.tem
+ mv Makefile.tem ${Makefile}
+
+ # set destdir
+ if [ -n "${destdir}" ] ; then
+ sed "s:^destdir =.*$:destdir = ${destdir}:" ${Makefile} > Makefile.tem
+ mv Makefile.tem ${Makefile}
+ fi
+
+ # reset SUBDIRS
+ sed "s:^SUBDIRS =.*$:SUBDIRS = ${configdirs}:" ${Makefile} > Makefile.tem
+ mv Makefile.tem ${Makefile}
+
+ # reset NONSUBDIRS
+ sed "s:^NONSUBDIRS =.*$:NONSUBDIRS = ${noconfigdirs}:" ${Makefile} > Makefile.tem
+ mv Makefile.tem ${Makefile}
+
+ using=
+ if [ -f ${srcdir}/${host_makefile_frag} ] ; then
+ using=" using \"${host_makefile_frag}\""
+ fi
+
+ if [ -f ${srcdir}/${target_makefile_frag} ] ; then
+ if [ -z "${using}" ] ; then
+ andusing=" using \"${target_makefile_frag}\""
+ else
+ andusing="${using} and \"${target_makefile_frag}\""
+ fi
+ else
+ andusing=${using}
+ fi
+
+ if [ -n "${verbose}" -o -z "${recursing}" ] ; then
+ echo "Created \"${Makefile}\"" in `pwd`${andusing}.
+ fi
+
+#### configure.in post-target parts come in here.
+
+## end of post-target part.
+
+ if [ "${host}" = "${target}" ] ; then
+ echo "Links are now set up for use with a ${target}." \
+ > config.status
+ # | tee ${srcdir}/config.status
+ else
+ echo "Links are now set up for host ${host} and target ${target}." \
+ > config.status
+ # | tee ${srcdir}/config.status
+ fi
+
+ originaldir=`pwd`
+ cd ${srcdir}