Skip to content
Snippets Groups Projects
configure.ac 122 KiB
Newer Older
elif test x$host_pie = xyes; then
  PICFLAG=-fPIE
else
  PICFLAG=
fi

AC_SUBST(PICFLAG)

# If we are building PIC/PIE host executables, and we are building dependent
# libs (e.g. GMP) in-tree those libs need to be configured to generate PIC
# code.
host_libs_picflag=
if test "$host_shared" = "yes" -o "$host_pie" = "yes"; then
host_libs_picflag='--with-pic'
fi
AC_SUBST(host_libs_picflag)

# By default, C and C++ are the only stage 1 languages.
# Target libraries that we bootstrap.
bootstrap_target_libs=,target-libgcc,
Paolo Bonzini's avatar
Paolo Bonzini committed
# Figure out what language subdirectories are present.
# Look if the user specified --enable-languages="..."; if not, use
# the environment variable $LANGUAGES if defined. $LANGUAGES might
# go away some day.
# NB:  embedded tabs in this IF block -- do not untabify
if test -d ${srcdir}/gcc; then
  if test x"${enable_languages+set}" != xset; then
    if test x"${LANGUAGES+set}" = xset; then
      enable_languages="${LANGUAGES}"
        echo configure.ac: warning: setting LANGUAGES is deprecated, use --enable-languages instead 1>&2
Paolo Bonzini's avatar
Paolo Bonzini committed
    else
Paolo Bonzini's avatar
Paolo Bonzini committed
    fi
  else
    if test x"${enable_languages}" = x ||
       test x"${enable_languages}" = xyes;
       then
      echo configure.ac: --enable-languages needs at least one language argument 1>&2
Paolo Bonzini's avatar
Paolo Bonzini committed
      exit 1
    fi
  fi
  enable_languages=`echo "${enable_languages}" | sed -e 's/[[ 	,]][[ 	,]]*/,/g' -e 's/,$//'`

  # 'f95' is the old name for the 'fortran' language. We issue a warning
  # and make the substitution.
  case ,${enable_languages}, in
    *,f95,*)
      echo configure.ac: warning: 'f95' as language name is deprecated, use 'fortran' instead 1>&2
      enable_languages=`echo "${enable_languages}" | sed -e 's/f95/fortran/g'`
      ;;
  esac

  # If bootstrapping, C++ must be enabled.
  case ",$enable_languages,:$enable_bootstrap" in
    *,c++,*:*) ;;
    *:yes)
      if test -f ${srcdir}/gcc/cp/config-lang.in; then
        enable_languages="${enable_languages},c++"
      else
        AC_MSG_ERROR([bootstrapping requires c++ sources])
Paolo Bonzini's avatar
Paolo Bonzini committed
  # First scan to see if an enabled language requires some other language.
  # We assume that a given config-lang.in will list all the language
  # front ends it requires, even if some are required indirectly.
  for lang_frag in ${srcdir}/gcc/*/config-lang.in .. ; do
    case ${lang_frag} in
      ..) ;;
      # The odd quoting in the next line works around
      # an apparent bug in bash 1.12 on linux.
      ${srcdir}/gcc/[[*]]/config-lang.in) ;;
      *)
        # From the config-lang.in, get $language, $lang_requires, and
        # $lang_requires_boot_languages.
Paolo Bonzini's avatar
Paolo Bonzini committed
        language=
        lang_requires=
        # set srcdir during sourcing lang_frag to the gcc dir.
        # Sadly overriding srcdir on the . line doesn't work in plain sh as it
        # polutes this shell
        saved_srcdir=${srcdir}
        srcdir=${srcdir}/gcc . ${lang_frag}
        srcdir=${saved_srcdir}
        for other in ${lang_requires} ${lang_requires_boot_languages}; do
Paolo Bonzini's avatar
Paolo Bonzini committed
          case ,${enable_languages}, in
	    *,$other,*) ;;
Paolo Bonzini's avatar
Paolo Bonzini committed
	    *,all,*) ;;
	    *,$language,*)
	      echo " \`$other' language required by \`$language'; enabling" 1>&2
	      enable_languages="${enable_languages},${other}"
	      ;;
	  esac
        done
	for other in ${lang_requires_boot_languages} ; do
	  if test "$other" != "c"; then
	    case ,${enable_stage1_languages}, in
	      *,$other,*) ;;
	      *,all,*) ;;
	      *)
		case ,${enable_languages}, in
		  *,$language,*)
		    echo " '$other' language required by '$language' in stage 1; enabling" 1>&2
		    enable_stage1_languages="$enable_stage1_languages,${other}"
		    ;;
		esac
		;;
	    esac
          fi
        done
Paolo Bonzini's avatar
Paolo Bonzini committed
        ;;
    esac
  done

  new_enable_languages=,c,

  # If LTO is enabled, add the LTO front end.
  if test "$enable_lto" = "yes" ; then
    case ,${enable_languages}, in
      *,lto,*) ;;
      *) enable_languages="${enable_languages},lto" ;;
    esac
    if test "${build_lto_plugin}" = "yes" ; then
      configdirs="$configdirs lto-plugin"
    fi
  fi

  # If we're building an offloading compiler, add the LTO front end.
  if test x"$enable_as_accelerator_for" != x ; then
    case ,${enable_languages}, in
      *,lto,*) ;;
      *) enable_languages="${enable_languages},lto" ;;
    esac
  fi

  missing_languages=`echo ",$enable_languages," | sed -e s/,default,/,/ -e s/,all,/,/ -e s/,c,/,/ `
  potential_languages=,c,
Paolo Bonzini's avatar
Paolo Bonzini committed

Paolo Bonzini's avatar
Paolo Bonzini committed
  for lang_frag in ${srcdir}/gcc/*/config-lang.in .. ; do
    case ${lang_frag} in
      ..) ;;
      # The odd quoting in the next line works around
      # an apparent bug in bash 1.12 on linux.
      ${srcdir}/gcc/[[*]]/config-lang.in) ;;
      *)
        # From the config-lang.in, get $language, $target_libs, 
        # $lang_dirs, $boot_language, and $build_by_default
Paolo Bonzini's avatar
Paolo Bonzini committed
        language=
        target_libs=
        lang_dirs=
        boot_language=no
        build_by_default=yes
        # set srcdir during sourcing.  See above about save & restore
        saved_srcdir=${srcdir}
        srcdir=${srcdir}/gcc . ${lang_frag}
        srcdir=${saved_srcdir}
        if test x${language} = x; then
          echo "${lang_frag} doesn't set \$language." 1>&2
          exit 1
        fi

	if test "$language" = "c++"; then
        add_this_lang=no
        # C is always enabled, so no need to add it again
        if test "$language" != "c"; then
          case ,${enable_languages}, in
            *,${language},*)
              # Language was explicitly selected; include it
              ;;
	    *,all,*)
	      # All languages are enabled
	      add_this_lang=all
              ;;
            *,default,*)
              # 'default' was selected, select it if it is a default language
	      add_this_lang=${build_by_default}
        # Disable languages that need other directories if these aren't available.
	for i in $subdir_requires; do
	  test -f "$srcdir/gcc/$i/config-lang.in" && continue
              # Specifically requested language; tell them.
              AC_MSG_ERROR([The gcc/$i directory contains parts of $language but is missing])
              ;;
            all)
              AC_MSG_WARN([The gcc/$i directory contains parts of $language but is missing])
              add_this_lang=unsupported
              ;;
              add_this_lang=unsupported
        # Disable Ada if no preexisting GNAT is available.
        case ${add_this_lang}:${language}:${have_gnat} in
          yes:ada:no)
            # Specifically requested language; tell them.
            AC_MSG_ERROR([GNAT is required to build $language])
            ;;
          all:ada:no)
            AC_MSG_WARN([GNAT is required to build $language])
            add_this_lang=unsupported
            ;;
          *:ada:no)
            # Silently disable.
            add_this_lang=unsupported
            ;;
        esac

        # Disable D if no preexisting GDC is available.
        case ${add_this_lang}:${language}:${have_gdc} in
          yes:d:no)
            # Specifically requested language; tell them.
            AC_MSG_ERROR([GDC is required to build $language])
           ;;
          all:d:no)
            AC_MSG_WARN([GDC is required to build $language])
            add_this_lang=unsupported
            ;;
          *:d:no)
            # Silently disable.
            add_this_lang=unsupported
            ;;
        esac

        # but not if building for Mingw. All code in Windows
        # is position independent code (PIC).
        case $target in
          *mingw*) ;;
          *)
          case ${add_this_lang}:${language}:${host_shared} in
            yes:jit:no)
	           # PR jit/64780: explicitly specify --enable-host-shared
	    AC_MSG_ERROR([
Enabling language "jit" requires --enable-host-shared.

--enable-host-shared typically slows the rest of the compiler down by
a few %, so you must explicitly enable it.

If you want to build both the jit and the regular compiler, it is often
best to do this via two separate configure/builds, in separate
directories, to avoid imposing the performance cost of
--enable-host-shared on the regular compiler.])
	            ;;
            all:jit:no)
	      AC_MSG_WARN([--enable-host-shared required to build $language])
              add_this_lang=unsupported
              ;;
            *:jit:no)
              # Silently disable.
              add_this_lang=unsupported
              ;;
	        esac
          ;;
        esac

        # Disable a language that is unsupported by the target.
	case "${add_this_lang}: $unsupported_languages " in
	  no:*) ;;
	  unsupported:*) ;;
	  *:*" $language "*)
	    AC_MSG_WARN([${language} not supported for this target])
	    add_this_lang=unsupported
	case $add_this_lang in
Paolo Bonzini's avatar
Paolo Bonzini committed
            # Remove language-dependent dirs.
	    disabled_target_libs="$disabled_target_libs $target_libs"
	    noconfigdirs="$noconfigdirs $lang_dirs"
	  no)
            # Remove language-dependent dirs; still show language as supported.
	    disabled_target_libs="$disabled_target_libs $target_libs"
	    noconfigdirs="$noconfigdirs $lang_dirs"
            potential_languages="${potential_languages}${language},"
	    ;;
	    new_enable_languages="${new_enable_languages}${language},"
            potential_languages="${potential_languages}${language},"
	    missing_languages=`echo "$missing_languages" | sed "s/,$language,/,/"`
	    enabled_target_libs="$enabled_target_libs $target_libs"
	    case "${boot_language}:,$enable_stage1_languages," in
	      yes:* | *:*,$language,* | *:*,yes, | *:*,all,)
		# Add to (comma-separated) list of stage 1 languages.
		case ",$stage1_languages," in
		  *,$language,* | ,yes, | ,all,) ;;
		  *) stage1_languages="${stage1_languages}${language}," ;;
		esac
		# We need to bootstrap any supporting libraries.
		bootstrap_target_libs=`echo "${bootstrap_target_libs}${target_libs}," | sed "s/ /,/g"`
Paolo Bonzini's avatar
Paolo Bonzini committed
        esac
        ;;
    esac
  done

  # Add target libraries which are only needed for disabled languages
  # to noconfigdirs.
  if test -n "$disabled_target_libs"; then
    for dir in $disabled_target_libs; do
      case " $enabled_target_libs " in
      *" ${dir} "*) ;;
      *) noconfigdirs="$noconfigdirs $dir" ;;
      esac
    done
  fi

  AC_ARG_ENABLE(stage1-languages,
  [AS_HELP_STRING([[--enable-stage1-languages[=all]]],
		  [choose additional languages to build during
		  stage1.  Mostly useful for compiler development])],
  [case ,${enable_stage1_languages}, in
    ,no,|,,)
      # Set it to something that will have no effect in the loop below
      enable_stage1_languages=c ;;
    ,yes,)
      enable_stage1_languages=`echo $new_enable_languages | \
	sed -e "s/^,//" -e "s/,$//" ` ;;
    *,all,*)
      enable_stage1_languages=`echo ,$enable_stage1_languages, | \
	sed -e "s/,all,/$new_enable_languages/" -e "s/^,//" -e "s/,$//" ` ;;
  esac

  # Add "good" languages from enable_stage1_languages to stage1_languages,
  # while "bad" languages go in missing_languages.  Leave no duplicates.
  for i in `echo $enable_stage1_languages | sed 's/,/ /g' `; do
    case $potential_languages in
      *,$i,*)
        case $stage1_languages in
          *,$i,*) ;;
          *) stage1_languages="$stage1_languages$i," ;;
        esac ;;
      *)
        case $missing_languages in
          *,$i,*) ;;
          *) missing_languages="$missing_languages$i," ;;
        esac ;;
     esac
  done])

  # Remove leading/trailing commas that were added for simplicity
  potential_languages=`echo "$potential_languages" | sed -e "s/^,//" -e "s/,$//"`
  missing_languages=`echo "$missing_languages" | sed -e "s/^,//" -e "s/,$//"`
  stage1_languages=`echo "$stage1_languages" | sed -e "s/^,//" -e "s/,$//"`
  new_enable_languages=`echo "$new_enable_languages" | sed -e "s/^,//" -e "s/,$//"`

Paolo Bonzini's avatar
Paolo Bonzini committed
  if test "x$missing_languages" != x; then
    AC_MSG_ERROR([
The following requested languages could not be built: ${missing_languages}
Supported languages are: ${potential_languages}])
Paolo Bonzini's avatar
Paolo Bonzini committed
  fi
  if test "x$new_enable_languages" != "x$enable_languages"; then
    echo The following languages will be built: ${new_enable_languages}
    enable_languages="$new_enable_languages"
Paolo Bonzini's avatar
Paolo Bonzini committed
  fi

  AC_SUBST(stage1_languages)
  ac_configure_args=`echo " $ac_configure_args" | sed -e "s/ '--enable-languages=[[^ ]]*'//g" -e "s/$/ '--enable-languages="$enable_languages"'/" `
Paolo Bonzini's avatar
Paolo Bonzini committed
fi

# Handle --disable-<component> generically.
for dir in $configdirs $build_configdirs $target_configdirs ; do
  dirname=`echo $dir | sed -e s/target-//g -e s/build-//g -e s/-/_/g`
  varname=`echo $dirname | sed -e s/+/_/g`
  if eval test x\${enable_${varname}} "=" xno ; then
    noconfigdirs="$noconfigdirs $dir"
  fi
done

# Check for Boehm's garbage collector
AC_ARG_ENABLE(objc-gc,
[AS_HELP_STRING([--enable-objc-gc],
		[enable use of Boehm's garbage collector with the
		 GNU Objective-C runtime])])
AC_ARG_WITH([target-bdw-gc],
[AS_HELP_STRING([--with-target-bdw-gc=PATHLIST],
		[specify prefix directory for installed bdw-gc package.
		 Equivalent to --with-target-bdw-gc-include=PATH/include
		 plus --with-target-bdw-gc-lib=PATH/lib])])
AC_ARG_WITH([target-bdw-gc-include],
[AS_HELP_STRING([--with-target-bdw-gc-include=PATHLIST],
		[specify directories for installed bdw-gc include files])])
AC_ARG_WITH([target-bdw-gc-lib],
[AS_HELP_STRING([--with-target-bdw-gc-lib=PATHLIST],
		[specify directories for installed bdw-gc library])])
		  
case ,${enable_languages},:${enable_objc_gc} in *,objc,*:yes|*,objc,*:auto)
  AC_MSG_CHECKING([for bdw garbage collector])
  if test "x$with_target_bdw_gc$with_target_bdw_gc_include$with_target_bdw_gc_lib" = x; then
    dnl no bdw-gw options, assume default locations
    AC_MSG_RESULT([using bdw-gc in default locations])
  else
    dnl bdw-gw options, first error checking, complete checking in libobjc
    if test "x$with_target_bdw_gc_include" = x && test "x$with_target_bdw_gc_lib" != x; then
      AC_MSG_ERROR([found --with-target-bdw-gc-lib but --with-target-bdw-gc-include missing])
    elif test "x$with_target_bdw_gc_include" != x && test "x$with_target_bdw_gc_lib" = x; then
      AC_MSG_ERROR([found --with-target-bdw-gc-include but --with-target-bdw-gc-lib missing])
    else
      AC_MSG_RESULT([using paths configured with --with-target-bdw-gc options])
    fi
  fi
# Disable libitm, libsanitizer, libvtv if we're not building C++
Julia Koval's avatar
Julia Koval committed
    # Disable libitm, libsanitizer if we're not building libstdc++
Julia Koval's avatar
Julia Koval committed
        noconfigdirs="$noconfigdirs target-libitm target-libsanitizer"
    noconfigdirs="$noconfigdirs target-libitm target-libsanitizer target-libvtv"
# If gcc/ is not in the source tree then we'll not be building a
# target compiler, assume in that case we don't want to build any
# target libraries or tools.
#
# This was added primarily for the benefit for binutils-gdb who reuse
# this configure script, but don't always have target tools available.
if test ! -d ${srcdir}/gcc; then
   skipdirs="${skipdirs} ${target_configdirs}"
fi

# Remove the entries in $skipdirs and $noconfigdirs from $configdirs,
# $build_configdirs and $target_configdirs.
Paolo Bonzini's avatar
Paolo Bonzini committed
# If we have the source for $noconfigdirs entries, add them to $notsupp.

notsupp=""
for dir in . $skipdirs $noconfigdirs ; do
  dirname=`echo $dir | sed -e s/target-//g -e s/build-//g`
Paolo Bonzini's avatar
Paolo Bonzini committed
  if test $dir != .  && echo " ${configdirs} " | grep " ${dir} " >/dev/null 2>&1; then
    configdirs=`echo " ${configdirs} " | sed -e "s/ ${dir} / /"`
    if test -r $srcdir/$dirname/configure ; then
      if echo " ${skipdirs} " | grep " ${dir} " >/dev/null 2>&1; then
	true
      else
	notsupp="$notsupp $dir"
      fi
    fi
  fi
  if test $dir != .  && echo " ${build_configdirs} " | grep " ${dir} " >/dev/null 2>&1; then
    build_configdirs=`echo " ${build_configdirs} " | sed -e "s/ ${dir} / /"`
    if test -r $srcdir/$dirname/configure ; then
      if echo " ${skipdirs} " | grep " ${dir} " >/dev/null 2>&1; then
	true
      else
	notsupp="$notsupp $dir"
      fi
    fi
  fi
Paolo Bonzini's avatar
Paolo Bonzini committed
  if test $dir != . && echo " ${target_configdirs} " | grep " ${dir} " >/dev/null 2>&1; then
    target_configdirs=`echo " ${target_configdirs} " | sed -e "s/ ${dir} / /"`
    if test -r $srcdir/$dirname/configure ; then
      if echo " ${skipdirs} " | grep " ${dir} " >/dev/null 2>&1; then
	true
      else
	notsupp="$notsupp $dir"
      fi
    fi
  fi
done

# Quietly strip out all directories which aren't configurable in this tree.
# This relies on all configurable subdirectories being autoconfiscated, which
# is now the case.
build_configdirs_all="$build_configdirs"
build_configdirs=
for i in ${build_configdirs_all} ; do
  j=`echo $i | sed -e s/build-//g` 
  if test -f ${srcdir}/$j/configure ; then
    build_configdirs="${build_configdirs} $i"
  fi
done

Paolo Bonzini's avatar
Paolo Bonzini committed
configdirs_all="$configdirs"
configdirs=
for i in ${configdirs_all} ; do
  if test -f ${srcdir}/$i/configure ; then
    configdirs="${configdirs} $i"
  fi
done
Paolo Bonzini's avatar
Paolo Bonzini committed
target_configdirs_all="$target_configdirs"
target_configdirs=
for i in ${target_configdirs_all} ; do
  j=`echo $i | sed -e s/target-//g` 
  if test -f ${srcdir}/$j/configure ; then
    target_configdirs="${target_configdirs} $i"
  fi
done

# libiberty-linker-plugin is special: it doesn't have its own source directory,
# so we have to add it after the preceding checks.
if test x"$extra_linker_plugin_flags$extra_linker_plugin_configure_flags" != x
then
  case " $configdirs " in
    *" libiberty "*)
      # If we can build libiberty, we can also build libiberty-linker-plugin.
      configdirs="$configdirs libiberty-linker-plugin"
      extra_linker_plugin_configure_flags="$extra_linker_plugin_configure_flags \
        --with-libiberty=../libiberty-linker-plugin";;
    *)
      AC_MSG_ERROR([libiberty missing]);;
  esac
fi

# Sometimes we have special requirements for the host libiberty.
extra_host_libiberty_configure_flags=
case " $configdirs " in
  *" lto-plugin "* | *" libcc1 "* | *" gdbserver "*)
    # When these are to be built as shared libraries, the same applies to
    # libiberty.
    extra_host_libiberty_configure_flags=--enable-shared
    ;;
esac
AC_SUBST(extra_host_libiberty_configure_flags)

# Sometimes we have special requirements for the host zlib.
extra_host_zlib_configure_flags=
case " $configdirs " in
  *" bfd "*)
    # When bfd is to be built as a shared library, the same applies to
    # zlib.
    if test "$enable_shared" = "yes"; then
      extra_host_zlib_configure_flags=--enable-host-shared
    fi
    ;;
AC_SUBST(extra_host_zlib_configure_flags)
Paolo Bonzini's avatar
Paolo Bonzini committed
# Produce a warning message for the subdirs we can't configure.
# This isn't especially interesting in the Cygnus tree, but in the individual
# FSF releases, it's important to let people know when their machine isn't
# supported by the one or two programs in a package.

if test -n "${notsupp}" && test -z "${norecursion}" ; then
  # If $appdirs is non-empty, at least one of those directories must still
  # be configured, or we error out.  (E.g., if the gas release supports a
  # specified target in some subdirs but not the gas subdir, we shouldn't
  # pretend that all is well.)
  if test -n "$appdirs" ; then
    for dir in $appdirs ; do
      if test -r $dir/Makefile.in ; then
	if echo " ${configdirs} " | grep " ${dir} " >/dev/null 2>&1; then
	  appdirs=""
	  break
	fi
	if echo " ${target_configdirs} " | grep " target-${dir} " >/dev/null 2>&1; then
Paolo Bonzini's avatar
Paolo Bonzini committed
	  appdirs=""
	  break
	fi
      fi
    done
    if test -n "$appdirs" ; then
      echo "*** This configuration is not supported by this package." 1>&2
      exit 1
    fi
  fi
  # Okay, some application will build, or we don't care to check.  Still
  # notify of subdirs not getting built.
  echo "*** This configuration is not supported in the following subdirectories:" 1>&2
  echo "    ${notsupp}" 1>&2
  echo "    (Any other directories should still work fine.)" 1>&2
fi

case "$host" in
  *msdosdjgpp*)
    enable_gdbtk=no ;;
esac

# To find our prefix, in gcc_cv_tool_prefix.
ACX_TOOL_DIRS

Paolo Bonzini's avatar
Paolo Bonzini committed
copy_dirs=

AC_ARG_WITH([build-sysroot], 
  [AS_HELP_STRING([--with-build-sysroot=SYSROOT],
		  [use sysroot as the system root during the build])],
  [if test x"$withval" != x ; then
     SYSROOT_CFLAGS_FOR_TARGET="--sysroot=$withval"
   fi],
  [SYSROOT_CFLAGS_FOR_TARGET=])
AC_SUBST(SYSROOT_CFLAGS_FOR_TARGET)

AC_ARG_WITH([debug-prefix-map],
  [AS_HELP_STRING([--with-debug-prefix-map='A=B C=D ...'],
		  [map A to B, C to D ... in debug information])],
  [if test x"$withval" != x; then
     DEBUG_PREFIX_CFLAGS_FOR_TARGET=
     for debug_map in $withval; do
       DEBUG_PREFIX_CFLAGS_FOR_TARGET="$DEBUG_PREFIX_CFLAGS_FOR_TARGET -fdebug-prefix-map=$debug_map"
     done
   fi],
  [DEBUG_PREFIX_CFLAGS_FOR_TARGET=])
AC_SUBST(DEBUG_PREFIX_CFLAGS_FOR_TARGET)

# During gcc bootstrap, if we use some random cc for stage1 then CFLAGS
# might be empty or "-g".  We don't require a C++ compiler, so CXXFLAGS
# might also be empty (or "-g", if a non-GCC C++ compiler is in the path).
# We want to ensure that TARGET libraries (which we know are built with
# gcc) are built with "-O2 -g", so include those options when setting
# CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET.
if test "x$CFLAGS_FOR_TARGET" = x; then
  if test "x${is_cross_compiler}" = xyes; then
    CFLAGS_FOR_TARGET="-g -O2"
  else
    CFLAGS_FOR_TARGET=$CFLAGS
    case " $CFLAGS " in
      *" -O2 "*) ;;
      *) CFLAGS_FOR_TARGET="-O2 $CFLAGS_FOR_TARGET" ;;
    esac
    case " $CFLAGS " in
      *" -g "* | *" -g3 "*) ;;
      *) CFLAGS_FOR_TARGET="-g $CFLAGS_FOR_TARGET" ;;
    esac
  fi
fi
AC_SUBST(CFLAGS_FOR_TARGET)

if test "x$CXXFLAGS_FOR_TARGET" = x; then
  if test "x${is_cross_compiler}" = xyes; then
    CXXFLAGS_FOR_TARGET="-g -O2"
  else
    CXXFLAGS_FOR_TARGET=$CXXFLAGS
    case " $CXXFLAGS " in
      *" -O2 "*) ;;
      *) CXXFLAGS_FOR_TARGET="-O2 $CXXFLAGS_FOR_TARGET" ;;
    esac
    case " $CXXFLAGS " in
      *" -g "* | *" -g3 "*) ;;
      *) CXXFLAGS_FOR_TARGET="-g $CXXFLAGS_FOR_TARGET" ;;
    esac
  fi
AC_SUBST(LDFLAGS_FOR_TARGET)

Paolo Bonzini's avatar
Paolo Bonzini committed
# Handle --with-headers=XXX.  If the value is not "yes", the contents of
# the named directory are copied to $(tooldir)/sys-include.
if test x"${with_headers}" != x && test x"${with_headers}" != xno ; then
  if test x${is_cross_compiler} = xno ; then
    echo 1>&2 '***' --with-headers is only supported when cross compiling
    exit 1
  fi
  if test x"${with_headers}" != xyes ; then
    copy_dirs="${copy_dirs} ${with_headers} $x/${target_noncanonical}/sys-include"
Paolo Bonzini's avatar
Paolo Bonzini committed
  fi
fi

# Handle --with-libs=XXX.  If the value is not "yes", the contents of
# the name directories are copied to $(tooldir)/lib.  Multiple directories
# are permitted.
if test x"${with_libs}" != x && test x"${with_libs}" != xno ; then
  if test x${is_cross_compiler} = xno ; then
    echo 1>&2 '***' --with-libs is only supported when cross compiling
    exit 1
  fi
  if test x"${with_libs}" != xyes ; then
    # Copy the libraries in reverse order, so that files in the first named
    # library override files in subsequent libraries.
Paolo Bonzini's avatar
Paolo Bonzini committed
    for l in ${with_libs}; do
      copy_dirs="$l $x/${target_noncanonical}/lib ${copy_dirs}"
Paolo Bonzini's avatar
Paolo Bonzini committed
    done
  fi
fi

# Set with_gnu_as, with_gnu_ld, and with_system_zlib as appropriate.
#
# This is done by determining whether or not the appropriate directory
# is available, and by checking whether or not specific configurations
# have requested that this magic not happen.
# 
# The command line options always override the explicit settings in 
# configure.ac, and the settings in configure.ac override this magic.
#
# If the default for a toolchain is to use GNU as and ld, and you don't 
# want to do that, then you should use the --without-gnu-as and
# --without-gnu-ld options for the configure script.  Similarly, if
# the default is to use the included zlib and you don't want to do that,
# you should use the --with-system-zlib option for the configure script.

if test x${use_gnu_as} = x &&
   echo " ${configdirs} " | grep " gas " > /dev/null 2>&1 ; then
  with_gnu_as=yes
  extra_host_args="$extra_host_args --with-gnu-as"
fi

if test x${use_gnu_ld} = x &&
   echo " ${configdirs} " | egrep " (go)?ld " > /dev/null 2>&1 ; then
  with_gnu_ld=yes
  extra_host_args="$extra_host_args --with-gnu-ld"
fi

if test x${use_included_zlib} = x &&
   echo " ${configdirs} " | grep " zlib " > /dev/null 2>&1 ; then
  :
else
  with_system_zlib=yes
  extra_host_args="$extra_host_args --with-system-zlib"
fi

# If using newlib, add --with-newlib to the extra_host_args so that gcc/configure
# can detect this case.

if test x${with_newlib} != xno && echo " ${target_configdirs} " | grep " target-newlib " > /dev/null 2>&1 ; then
  with_newlib=yes
  extra_host_args="$extra_host_args --with-newlib"
fi

Paolo Bonzini's avatar
Paolo Bonzini committed
# Handle ${copy_dirs}
set fnord ${copy_dirs}
shift
while test $# != 0 ; do
  if test -f $2/COPIED && test x"`cat $2/COPIED`" = x"$1" ; then
    :
  else
    echo Copying $1 to $2

    # Use the install script to create the directory and all required
    # parent directories.
    if test -d $2 ; then
      :
    else
      echo >config.temp
      ${srcdir}/install-sh -c -m 644 config.temp $2/COPIED
    fi

    # Copy the directory, assuming we have tar.
    # FIXME: Should we use B in the second tar?  Not all systems support it.
    (cd $1; tar -cf - .) | (cd $2; tar -xpf -)

    # It is the responsibility of the user to correctly adjust all
    # symlinks.  If somebody can figure out how to handle them correctly
    # here, feel free to add the code.

    echo $1 > $2/COPIED
  fi
  shift; shift
done

# Determine a target-dependent exec_prefix that the installed
# gcc will search in.  Keep this list sorted by triplet, with
# the *-*-osname triplets last.
md_exec_prefix=
case "${target}" in
    md_exec_prefix=/dev/env/DJDIR/bin
    ;;
  *-*-hpux* | \
  *-*-nto-qnx* | \
extra_arflags_for_target=
extra_nmflags_for_target=
extra_ranlibflags_for_target=
target_makefile_frag=/dev/null
case "${target}" in
  spu-*-*)
    target_makefile_frag="config/mt-spu"
    ;;
  mips*-sde-elf* | mips*-mti-elf* | mips*-img-elf*)
Richard Sandiford's avatar
Richard Sandiford committed
    target_makefile_frag="config/mt-sde"
    ;;
  mipsisa*-*-elfoabi*)
    target_makefile_frag="config/mt-mips-elfoabi"
    ;;
  mips*-*-*linux* | mips*-*-gnu*)
    target_makefile_frag="config/mt-mips-gnu"
    ;;
  nios2-*-elf*)
    target_makefile_frag="config/mt-nios2-elf"
    ;;
  *-*-linux-android*)
    target_makefile_frag="config/mt-android"
    ;;
  *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu | *-*-kopensolaris*-gnu)
    target_makefile_frag="config/mt-gnu"
  *-*-aix4.[[3456789]]* | *-*-aix[[56789]].*)
    # nm and ar from AIX 4.3 and above require -X32_64 flag to all ar and nm 
    # commands to handle both 32-bit and 64-bit objects.  These flags are
    # harmless if we're using GNU nm or ar.
    extra_arflags_for_target=" -X32_64"
    extra_nmflags_for_target=" -B -X32_64"
alphaieee_frag=/dev/null
case $target in
  alpha*-*-*)
    # This just makes sure to use the -mieee option to build target libs.
    # This should probably be set individually by each library.
    alphaieee_frag="config/mt-alphaieee"
# If --enable-target-optspace always use -Os instead of -O2 to build
# the target libraries, similarly if it is not specified, use -Os
# on selected platforms.
ospace_frag=/dev/null
case "${enable_target_optspace}:${target}" in
  yes:*)
  :m32r-* | :d10v-* | :fr30-* | :i?86*-*-elfiamcu)
    ;;
  no:* | :*)
    ;;
  *)
    echo "*** bad value \"${enable_target_optspace}\" for --enable-target-optspace flag; ignored" 1>&2
    ;;
esac
Jason Merrill's avatar
Jason Merrill committed

# Some systems (e.g., one of the i386-aix systems the gas testers are
# using) don't handle "\$" correctly, so don't use it here.
tooldir='${exec_prefix}'/${target_noncanonical}
build_tooldir=${tooldir}

# Create a .gdbinit file which runs the one in srcdir
# and tells GDB to look there for source files.

if test -r ${srcdir}/.gdbinit ; then
  case ${srcdir} in
    .) ;;
    *) cat > ./.gdbinit <<EOF
# ${NO_EDIT}
dir ${srcdir}
dir .
source ${srcdir}/.gdbinit
EOF
    ;;
  esac
fi

Jason Merrill's avatar
Jason Merrill committed
# Make sure that the compiler is able to generate an executable.  If it
# can't, we are probably in trouble.  We don't care whether we can run the
# executable--we might be using a cross compiler--we only care whether it
# can be created.  At this point the main configure script has set CC.
Jason Merrill's avatar
Jason Merrill committed
echo "int main () { return 0; }" > conftest.c
${CC} -o conftest ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} conftest.c
if test $? = 0 ; then
  if test -s conftest || test -s conftest.exe ; then
    we_are_ok=yes
  fi
fi 
case $we_are_ok in
  no)
    echo 1>&2 "*** The command '${CC} -o conftest ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} conftest.c' failed."
    echo 1>&2 "*** You must set the environment variable CC to a working compiler."
    rm -f conftest*
    exit 1
    ;;
esac
Jason Merrill's avatar
Jason Merrill committed
rm -f conftest*

# Decide which environment variable is used to find dynamic libraries.
case "${host}" in
  *-*-hpux*) RPATH_ENVVAR=SHLIB_PATH ;;
  *-*-darwin*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
  *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
  *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
esac

# On systems where the dynamic library environment variable is PATH,
# gcc/ will put dynamic libraries into a subdirectory to avoid adding
# built executables to PATH.
if test "$RPATH_ENVVAR" = PATH; then
  GCC_SHLIB_SUBDIR=/shlib
else
  GCC_SHLIB_SUBDIR=
fi

# Adjust the toplevel makefile according to whether bootstrap was selected.
case $enable_bootstrap in
  yes)
    bootstrap_suffix=bootstrap
    BUILD_CONFIG=bootstrap-debug
    ;;
  no)
    bootstrap_suffix=no-bootstrap
    BUILD_CONFIG=
    ;;
esac

AC_MSG_CHECKING(for default BUILD_CONFIG)

AC_ARG_WITH([build-config],
  [AS_HELP_STRING([--with-build-config='NAME NAME2...'],
		  [use config/NAME.mk build configuration])],
  [case $with_build_config in
   yes) with_build_config= ;;
   no) with_build_config= BUILD_CONFIG= ;;
   esac])

if test "x${with_build_config}" != x; then
  BUILD_CONFIG=$with_build_config
else
  case $BUILD_CONFIG in
  bootstrap-debug)
    if echo "int f (void) { return 0; }" > conftest.c &&
       ${CC} -c conftest.c &&
       mv conftest.o conftest.o.g0 &&
       ${CC} -c -g conftest.c &&
       mv conftest.o conftest.o.g &&
       ${srcdir}/contrib/compare-debug conftest.o.g0 conftest.o.g > /dev/null 2>&1; then
      :
    else
      BUILD_CONFIG=
    fi
    rm -f conftest.c conftest.o conftest.o.g0 conftest.o.g
    ;;
  esac
fi
AC_MSG_RESULT($BUILD_CONFIG)
AC_SUBST(BUILD_CONFIG)

# Use same top-level configure hooks in libgcc/libstdc++/libvtv.
AC_MSG_CHECKING([for --enable-vtable-verify])
AC_ARG_ENABLE(vtable-verify,
[AS_HELP_STRING([--enable-vtable-verify],
		[Enable vtable verification feature])],
[case "$enableval" in
 yes) enable_vtable_verify=yes ;;
 no)  enable_vtable_verify=no ;;
 *)   enable_vtable_verify=no;;
 esac],
[enable_vtable_verify=no])
AC_MSG_RESULT($enable_vtable_verify)

# Record target_configdirs and the configure arguments for target and
# build configuration in Makefile.
target_configdirs=`echo "${target_configdirs}" | sed -e 's/target-//g'`
build_configdirs=`echo "${build_configdirs}" | sed -e 's/build-//g'`
# If we are building libgomp, bootstrap it.
if echo " ${target_configdirs} " | grep " libgomp " > /dev/null 2>&1 ; then
  bootstrap_target_libs=${bootstrap_target_libs}target-libgomp,
fi

# If we are building libsanitizer and $BUILD_CONFIG contains bootstrap-asan
# or bootstrap-ubsan, bootstrap it.
if echo " ${target_configdirs} " | grep " libsanitizer " > /dev/null 2>&1; then
  case "$BUILD_CONFIG" in
    *bootstrap-hwasan* | *bootstrap-asan* | *bootstrap-ubsan* )
      bootstrap_target_libs=${bootstrap_target_libs}target-libsanitizer,
# If we are building libvtv and --enable-vtable-verify, bootstrap it.
if echo " ${target_configdirs} " | grep " libvtv " > /dev/null 2>&1 &&