Skip to content
Snippets Groups Projects
configure.ac 129 KiB
Newer Older
AC_ARG_ENABLE(linker-plugin-configure-flags,
  [AS_HELP_STRING([[--enable-linker-plugin-configure-flags=FLAGS]],
    [additional flags for configuring linker plugins @<:@none@:>@])],
  extra_linker_plugin_configure_flags=$enableval,
  extra_linker_plugin_configure_flags=)
AC_SUBST(extra_linker_plugin_configure_flags)
AC_ARG_ENABLE(linker-plugin-flags,
  [AS_HELP_STRING([[--enable-linker-plugin-flags=FLAGS]],
    [additional flags for configuring and building linker plugins @<:@none@:>@])],
  extra_linker_plugin_flags=$enableval,
  extra_linker_plugin_flags=)
AC_SUBST(extra_linker_plugin_flags)

# Handle --enable-host-pie
# If host PIE executables are the default (or must be forced on) for some host,
# we must pass that configuration to the gcc directory.
gcc_host_pie=
AC_ARG_ENABLE(host-pie,
[AS_HELP_STRING([--enable-host-pie],
		[build position independent host executables])],
[host_pie=$enableval
 case $host in
     if test x$host_pie != xyes ; then
       # for Darwin20+ this is required.
       AC_MSG_WARN([PIE executables are required for the configured host, host-pie setting ignored.])
     fi ;;
  *) ;;
 esac],
[case $host in
  *-*-darwin2*)
    # Default to PIE (mandatory for aarch64).
    host_pie=yes
    gcc_host_pie=--enable-host-pie
    ;;
  *) host_pie=no ;;
 esac])

AC_SUBST(host_pie)
# Enable --enable-host-shared.
# Checked early to determine whether jit is an 'all' language
AC_ARG_ENABLE(host-shared,
[AS_HELP_STRING([--enable-host-shared],
		[build host code as shared libraries])],
   x86_64-*-darwin* | aarch64-*-darwin*)
     if test x$host_shared != xyes ; then
       # PIC is the default, and actually cannot be switched off.
       AC_MSG_WARN([PIC code is required for the configured host; host-shared setting ignored.])
     if test x$host_pie = xyes -a x$host_shared != xyes ; then
       AC_MSG_WARN([PIC code is required for PIE host executables host-shared setting ignored.])
       host_shared=yes
     fi ;;
  # 64B x86_64 and Aarch64 Darwin default to PIC.
  x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;;
  # 32B and powerpc64 Darwin must use PIC to link PIE exes.
  *-*-darwin*) host_shared=$host_pie ;;
  *) host_shared=no;;
if test x$host_shared = xyes; then
  case $host in
    *-*-darwin*)
      # Since host shared is the default for 64b Darwin, and also enabled for
      # host_pie, ensure that we present the PIE flag when host_pie is active.
      if test x$host_pie = xyes; then
        PICFLAG=-fPIE
      fi
      ;;
    *)
      PICFLAG=-fPIC
      ;;
  esac
elif test x$host_pie = xyes; then
  PICFLAG=-fPIE
else
  PICFLAG=
fi

AC_SUBST(PICFLAG)

# Check for libgdiagnostics support.
AC_MSG_CHECKING([whether to enable libgdiagnostics])
AC_ARG_ENABLE(libgdiagnostics,
[AS_HELP_STRING([--enable-libgdiagnostics],
		[build libgdiagnostics shared library])],
enable_libgdiagnostics=$enableval,
enable_libgdiagnostics=no)

if test x$enable_libgdiagnostics = xyes; then
  # Disable libgdiagnostics if -enable-host-shared not specified
David Malcolm's avatar
David Malcolm committed
  # but not if building for Mingw. All code in Windows
  # is position independent code (PIC).
  case $target in
     *mingw*) ;;
     *)
       if test x$host_shared != xyes; then
	 AC_MSG_ERROR([
Enabling libgdiagnostics requires --enable-host-shared.
David Malcolm's avatar
David Malcolm committed

--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 libgdiagnostics and the regular compiler, it is often
David Malcolm's avatar
David Malcolm committed
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.])
       fi
       ;;
   esac
fi
AC_MSG_RESULT($enable_libgdiagnostics)
AC_SUBST(enable_libgdiagnostics)
# Rust requires -ldl and -lpthread if you are using an old glibc that does not include them by
# default, so we check for them here
# We are doing the test here and not in the gcc/configure to be able to nicely disable the
# build of the Rust frontend in case a dep is missing.
save_LIBS="$LIBS"
LIBS=
AC_SEARCH_LIBS([dlopen], [dl])
AC_SEARCH_LIBS([pthread_create], [pthread])
CRAB1_LIBS="$LIBS"
LIBS="$save_LIBS"
if test "$ac_cv_search_dlopen" = no; then
if test "$ac_cv_search_pthread_create" = no; then
    missing_rust_dynlibs="$missing_rust_dynlibs, libpthread"
fi

AC_SUBST(CRAB1_LIBS, "$CRAB1_LIBS")

# 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
        # pollutes 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

        # Disable Rust if we are missing some required C libraries for the Rust runtime.
        case ${add_this_lang}:${language}:${missing_rust_dynlibs} in
          *:rust:none)
            # Nothing to do - we're not missing any C libraries
            ;;
          yes:rust:*)
            AC_MSG_ERROR([some C libraries are required to build $language: $missing_rust_dynlibs])
            add_this_lang=unsupported
            ;;
          all:rust:*)
            AC_MSG_WARN([some C libraries are required to build $language: $missing_rust_dynlibs])
            add_this_lang=unsupported
            ;;
          *:rust:*)
            # 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
        # Pre-conditions to consider whether cargo being supported.
        if test x"$have_cargo" = xyes \
          && test x"$build" != x"$host"; then
          # Until <https://github.com/Rust-GCC/gccrs/issues/2898>
          # "'cargo' should build for the host system" is resolved:
          AC_MSG_WARN([use of cargo not yet supported here in Canadian cross configurations])
          have_cargo=no
        else
          # Assume that cargo-produced object files are compatible with what
          # we're going to build here.
          :
        fi
        # Disable Rust if cargo is unavailable.
        case ${add_this_lang}:${language}:${have_cargo} in
          yes:rust:no)
            # Specifically requested language; tell them.
            AC_MSG_ERROR([cargo is required to build $language])
            ;;
          all:rust:no)
            AC_MSG_WARN([cargo is required to build $language])
            add_this_lang=unsupported
            ;;
          *:rust:no)
            # Silently disable.
            add_this_lang=unsupported
            ;;
        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"
case ,${enable_languages}, in
  *,rust,*)
    case " ${noconfigdirs} " in
      *\ target-libstdc++-v3\ *)
        # Disable target libgrust if we're not building target libstdc++.
        noconfigdirs="$noconfigdirs target-libgrust"
        ;;
    esac
    ;;
esac

# 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