From cd87e1ba2d08523a6c8b575b18d2eab9d842fc5f Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 24 Jun 2017 20:35:59 +0200 Subject: buildgcc: Adapt messages about GNAT and bootstrapping Don't ask for bootstrapping in case of a different host GCC major version. GCC's versioning scheme changed starting with the release of GCC 5. There are no big changes between the versions any more. Instead, show the message when the host GCC's version is below 4. In case GNAT can't be found, ask the user to abort and install it. Also give hints for Ubuntu where the package versions are a little messy (e.g. the meta packages gcc and gnat often point to different versions). In case GNAT is found but is too old (< 4.9), enable bootstrapping by default and tell the user that building will take longer. In all three cases show a timeout to draw the user's attention. v2: Update GNAT check to also look for `gnatbind`. It has to be somewhere in $PATH. Change-Id: I4d9de11d7469e137ede8ad138296d20c0f8ba78f Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/20332 Reviewed-by: Patrick Georgi Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- util/crossgcc/buildgcc | 122 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 88 insertions(+), 34 deletions(-) (limited to 'util/crossgcc') diff --git a/util/crossgcc/buildgcc b/util/crossgcc/buildgcc index 4d269d3f38..d04fe5f872 100755 --- a/util/crossgcc/buildgcc +++ b/util/crossgcc/buildgcc @@ -143,6 +143,43 @@ normalize_dirs() perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la } +countdown() +{ + tout=${1:-10} + + printf "\nPress Ctrl-C to abort, Enter to continue... %2ds" $tout + while [ $tout -gt 0 ]; do + sleep 1 + tout=$((tout - 1)) + printf "\b\b\b%2ds" $tout + done + printf "\n" +} + +timeout() +{ + tout=${1:-10} + + # Ignore SIGUSR1, should interrupt `read` though. + trap false USR1 + # Clean up in case the user aborts. + trap 'kill $counter > /dev/null 2>&1' EXIT + + (countdown $tout; kill -USR1 $$)& + counter=$! + + # Some shells with sh compatibility mode (e.g. zsh, mksh) only + # let us interrupt `read` if a non-standard -t parameter is given. + if echo | read -t 1 foo 2>/dev/null; then + read -t $((tout + 1)) foo + else + read foo + fi + + kill $counter > /dev/null 2>&1 + trap - USR1 EXIT +} + please_install() { HALT_FOR_TOOLS=1 @@ -258,37 +295,13 @@ hostcc_has_gnat1() { [ -x "$(${CC} -print-prog-name=gnat1)" ] } -ada_requested() { - echo "${LANGUAGES}" | grep -q '\' -} - -check_gnat() { - if hostcc_has_gnat1; then - if [ \( "$(hostcc_major)" -lt 4 -o \ - \( "$(hostcc_major)" -eq 4 -a "$(hostcc_minor)" -lt 9 \) \) -a \ - "${BOOTSTRAP}" != "1" ]; - then - printf "\n${RED}ERROR:${red} Building the Ada compiler (gnat $(buildcc_version)) " - printf "with a host compiler older\n than 4.9.x (yours $(hostcc_version)) " - printf "requires bootstrapping (-b).${NC}\n\n" - HALT_FOR_TOOLS=1 - fi - else - please_install gnat - fi +have_gnat() { + hostcc_has_gnat1 && \ + searchtool gnatbind "Free Software Foundation" nofail > /dev/null } -check_cc() { - if is_package_enabled "GCC"; then - if [ "$(hostcc_major)" != "$(buildcc_major)" -a "${BOOTSTRAP}" != "1" ]; then - printf "\n${red}warning: Building GCC $(buildcc_version) with a different major " - printf "version ($(hostcc_version)).\n" - printf " Bootstrapping (-b) is recommended.${NC}\n\n" - fi - if ada_requested; then - check_gnat - fi - fi +ada_requested() { + echo "${LANGUAGES}" | grep -q '\' } check_sum() { @@ -1040,17 +1053,58 @@ elif [ $UNAME = "NetBSD" ]; then fi fi if [ -z "${LANGUAGES}" ]; then - if hostcc_has_gnat1 && \ - [ "$(hostcc_major)" -ge 5 -o \ - \( "$(hostcc_major)" -eq 4 -a "$(hostcc_minor)" -ge 9 \) -o \ - "${BOOTSTRAP}" = "1" ]; - then + if have_gnat; then printf "\nFound compatible Ada compiler, enabling Ada support by default.\n\n" LANGUAGES="ada,${DEFAULT_LANGUAGES}" else + printf "\n${red}WARNING${NC}\n" + printf "No compatible Ada compiler (GNAT) found. You can continue without\n" + printf "Ada support, but this will limit the features of ${blue}coreboot${NC} (e.g.\n" + printf "native graphics initialization won't be available on most Intel\n" + printf "boards).\n\n" + + printf "Usually, you can install GNAT with your package management system\n" + printf "(the package is called \`gnat\` or \`gcc-ada\`). It has to match the\n" + printf "\`gcc\` package in version. If there are multiple versions of GCC in-\n" + printf "stalled, you can point this script to the matching version through\n" + printf "the \`CC\` and \`CXX\` environment variables.\n\n" + + printf "e.g. on Ubuntu 14.04, if \`gcc\` is \`gcc-4.8\`:\n" + printf " apt-get install gnat-4.8 && make crossgcc\n\n" + + printf "on Ubuntu 16.04, if \`gcc\` is \`gcc-5\`:\n" + printf " apt-get install gnat-5 && make crossgcc\n" + timeout 30 LANGUAGES="${DEFAULT_LANGUAGES}" fi fi +if ada_requested; then + if have_gnat; then + if [ "$BOOTSTRAP" != 1 -a \ + \( "$(hostcc_major)" -lt 4 -o \ + \( "$(hostcc_major)" -eq 4 -a "$(hostcc_minor)" -lt 9 \) \) ] + then + printf "\n${red}WARNING${NC}\n" + printf "Building the Ada compiler (GNAT $(buildcc_version)) with a host compiler older\n" + printf "than 4.9.x (yours $(hostcc_version)) requires bootstrapping. This will take\n" + printf "significantly longer than a usual build. You can abort and update\n" + printf "your host GNAT or disable Ada support with BUILD_LANGUAGES=c (or\n" + printf "\`-l c\` in case you invoke \`buildgcc\` directly).\n" + timeout 15 + BOOTSTRAP=1 + fi + else + please_install gnat gcc-ada + exit 1 + fi +else + if [ "$(hostcc_major)" -lt 4 -a "$BOOTSTRAP" != 1 ]; then + printf "\n${red}WARNING${NC}\n" + printf "Building GCC $(buildcc_version) with a very old host compiler ($(hostcc_version)).\n" + printf "Bootstrapping (-b) is recommended.\n" + timeout 10 + fi +fi fi # GCC export HOSTCFLAGS="-Os" -- cgit v1.2.3