grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/2] autogen.sh: Detect python


From: Petr Vorel
Subject: [PATCH v2 2/2] autogen.sh: Detect python
Date: Mon, 30 Aug 2021 11:53:17 +0200

It help to avoid error on distros which has only python3 binary:
./autogen.sh: line 20: python: command not found

Use python3 as the default as python2 is EOL since Jan 2020, but check
also python which is on most distros if not all python2 because
code still works on python2.

Although it should not be needed keep the possibility to define PYTHON.

For detection use "command -v" which is POSIX [3] and supported on all
common shells (bash, zsh, dash, busybox sh, mksh) instead requiring
"which" as extra dependency (usable on containers).

Update INSTALL.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v1->v2:
* update INSTALL (Require python 3, but still note python 2.6)
NOTE: 2.6 is dead most people who still use python 2 use python 2.7,
but I suggest to keep it ()
* drop python2

 INSTALL    |  7 +++----
 autogen.sh | 17 +++++++++++++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/INSTALL b/INSTALL
index 3270743b7..bf7695e21 100644
--- a/INSTALL
+++ b/INSTALL
@@ -42,7 +42,7 @@ To build GRUB's graphical terminal (gfxterm), you need:
 If you use a development snapshot or want to hack on GRUB you may
 need the following.
 
-* Python 2.6 or later
+* Python 3 (NOTE: python 2.6 should still work, but it's not tested)
 * Autoconf 2.63 or later
 * Automake 1.11 or later
 
@@ -87,9 +87,8 @@ The simplest way to compile this package is:
   
   3. Type `./bootstrap'.
 
-     * autogen.sh (called by bootstrap) uses python. By default the
-       invocation is "python", but it can be overridden by setting the
-       variable $PYTHON.
+        * autogen.sh (called by bootstrap) uses python. By default autodetect
+       it, but it can be overridden by setting the $PYTHON variable.
 
   4. Type `./configure' to configure the package for your system.
      If you're using `csh' on an old version of System V, you might
diff --git a/autogen.sh b/autogen.sh
index 31b0ced7e..81df21816 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -7,8 +7,21 @@ if [ ! -e grub-core/lib/gnulib/stdlib.in.h ]; then
   exit 1
 fi
 
-# Set ${PYTHON} to plain 'python' if not set already
-: ${PYTHON:=python}
+# Detect python
+if [ -z "$PYTHON" ]; then
+  for i in python3 python; do
+    if command -v "$i" > /dev/null 2>&1; then
+      PYTHON="$i"
+      echo "Using $PYTHON" >&2
+      break
+    fi
+  done
+
+  if [ -z "$PYTHON" ]; then
+    echo "python not found" >&2
+    exit 1
+  fi
+fi
 
 export LC_COLLATE=C
 unset LC_ALL
-- 
2.33.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]