Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mKdz4-00039D-59 for mharc-grub-devel@gnu.org; Mon, 30 Aug 2021 05:53:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKdz2-000366-DF for grub-devel@gnu.org; Mon, 30 Aug 2021 05:53:40 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:40830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKdyw-0005wp-B5 for grub-devel@gnu.org; Mon, 30 Aug 2021 05:53:36 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CA71D2210B; Mon, 30 Aug 2021 09:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630317212; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QPcjcu7+JMqiNtcZW01n9vM3f7WvGTtrlljrnoIrhUA=; b=lOGbAvHg28to7z7gysNaowMqtH2UJIGGrRo+D6dOIkcMeqjKDJrKbR53EbdGvoRIkeBZhY c7HVJpD1vWl7dMtA9Kn//bM+wNfQa9uzfKYpNEbz1SIAnjKzNGKmL1yB3n6w/g8H79jTgj Fpyv9bjbFnvSrcG1CJxNl90GR5FmVw0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630317212; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QPcjcu7+JMqiNtcZW01n9vM3f7WvGTtrlljrnoIrhUA=; b=8T8agUUZOHvBupL/6qhiNtGZVEtyvcUukQWtcWJ+hKZVtE6xZ3BFGy4HrwIUWok/QoqLrd wXSPqUzPPH0ZmsCg== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id A9AE913670; Mon, 30 Aug 2021 09:53:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id MPEfKJyqLGENPQAAGKfGzw (envelope-from ); Mon, 30 Aug 2021 09:53:32 +0000 From: Petr Vorel To: grub-devel@gnu.org Cc: Petr Vorel , Daniel Kiper Subject: [PATCH v2 2/2] autogen.sh: Detect python Date: Mon, 30 Aug 2021 11:53:17 +0200 Message-Id: <20210830095317.15290-2-pvorel@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210830095317.15290-1-pvorel@suse.cz> References: <20210830095317.15290-1-pvorel@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=195.135.220.28; envelope-from=pvorel@suse.cz; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2021 09:53:40 -0000 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 --- 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