On 29.05.2017 15:40, Georg-Johann Lay wrote:
Hi.

This thread is about https://savannah.nongnu.org/bugs/?49567 and how
it can be solved.

The current implementation is agnostic of gcc's multilib layout and
uses much of hard-coded knowledge.

This makes it hard to extend avr-gcc and add new multilib variants
because avr-libc must always be adjusted in sync.

Information about multilib layout can be retrieved from the compiler
by --print-multi-lib.  This exposes the available multilib directories
together with the options needed to select that multilib variant.

Moreover, for each set of options, in particular -mmcu=<device>, the
compiler can report the respective multilib directory by means of
--print-multi-directory.

These are old features available "since ever" and nothing new.

The current problem with avr-libc is that it abuses autotools in
some weird way:  The "bootstrap" script generates a tree of .am
automake templates by using input templates with special <<fixme>>
entries, replaces the <<fixme>>s to get automake input, them runs
automake, then runs autoconf.

The major problem here is that "bootstrap" is completely agnostic
of the compiler in use, and hence no information can be retrieved
from the compiler.

The following approach is more conservative and builds on the present
bootstrap scheme:

"bootstrap" gets the compiler from the command line so it can be
used in the poor man's configure-like queries for avr-gcc features
and multilib layout by devtools.

The specified compiler, "avr-gcc" per default, is written to a file,
and configure picks it up and will use it as CC.

That way, "configure" and "bootstrap" are basing on the same avr-gcc
and features.  Specifying CC on the configure command line is
explicitly forbidden.

The patch below shows how it would look like.  The devtools and
how multilib tree is build has not been changed, it's still all
about how to teach "bootstrap" about the compiler and keeping
consistency between "bootstrap" and "configure".


Johann

The first question is: Would work on #49567 be welcome?



diff --git a/bootstrap b/bootstrap
index 43625b2..d429495 100755
--- a/bootstrap
+++ b/bootstrap
@@ -14,6 +14,49 @@ AUTOMAKE="${AUTOMAKE} --foreign --add-missing --copy"
 
 export AUTOMAKE AUTOCONF ACLOCAL AUTOHEADER
 
+# Get the avr-gcc to use.  Do NOT assume the environment has CC set,
+# because if the user exported CC before running bootstrap, that CC
+# will remain in the environment after this script and might confuse
+# other scripts.
+
+# Consume all arguments to support CC=$mypath/xgcc -B $mypath
+
+if test -z "$*"; then
+    CC="avr-gcc"
+else
+    CC="$*"
+fi
+
+# Check similar to the one in configure.ac to ensure we've got
+# something that looks like avr-gcc.
+
+bad_cc ()
+{
+    quot='"'
+    echo "error: wrong C compiler found or specified: ${quot}${CC}${quot}"
+    exit 1
+}
+
+case "${CC}" in
+    *gcc*)
+	case "X`${CC} -dumpmachine`X" in
+            XavrX) ;;
+            *) bad_cc ;;
+	esac ;;
+    *) bad_cc ;;
+esac
+
+# Export CC so that devtools can use it.
+export CC
+
+# Notify the user about the compiler version.
+echo "avr compiler: `$CC --version | head -n 1`"
+
+# Write the compiler to a file so configure can pick it up.
+# This is needed to make sure that bootstrap and configure
+# are using the same compiler and same features.
+echo "$CC" > cc.btstrp
+
 # to see what is executed
 set -x
 
diff --git a/configure.ac b/configure.ac
index 174fbeb..5b6703d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,6 +136,33 @@ m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.64],
 
 # Checks for programs.
 
+# The bootstrap scripts runs before this one and also runs autoconf.
+# As bootstrap makes assumptions about the compiler, the following
+# lines ensure that configure will use the same compiler as bootstrap.
+# The nuisance is that autoconf does not provide any useful arguments
+# to ship information from the caller of autoconf (bootstrap) to here,
+# hence bootstrap wrote the used CC to cc.btstrp.  Pick it up now.
+
+AC_MSG_CHECKING([which compiler was used during bootstrap])
+
+if test -f ${srcdir}/cc.btstrp; then
+   cc_boot="`cat ${srcdir}/cc.btstrp`"
+   AC_MSG_RESULT([${cc_boot}])
+else
+    AC_MSG_RESULT([no bootstrap was run])
+    AC_MSG_ERROR([you must run bootstrap before configure])
+fi
+
+if test -n "${CC}"; then
+   AC_MSG_ERROR([setting CC on the command line or in the environment is not
+        supported. if you want to use a special version of avr-gcc, please
+	run "bootstrap my-avr-gcc" before configure])
+fi
+
+CC="${cc_boot}"
+
+AC_MSG_NOTICE([bootstrap implies CC=${CC}])
+
 AC_PROG_CC
 AC_CHECK_TOOL(AS, as, as)
 AM_PROG_AS
_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to