From b0749cd06f155113ddb70937d9cd266ae41dba42 Mon Sep 17 00:00:00 2001 From: Kenn Sebesta Date: Thu, 2 Dec 2021 07:05:43 -0500 Subject: [PATCH] [Make][Python] Look for Python3 --- make/linux.mk | 15 ++++++++------- make/macos.mk | 33 +++++++++++++++++++++++++++------ make/windows.mk | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 13 deletions(-) diff --git a/make/linux.mk b/make/linux.mk index 30bc00c1..e34a0ad7 100644 --- a/make/linux.mk +++ b/make/linux.mk @@ -5,8 +5,6 @@ # system. -QT_SPEC ?= linux-g++ - ############################ # Check for and find Python ############################ @@ -14,25 +12,28 @@ QT_SPEC ?= linux-g++ # Get Python version, separate major/minor/patch, then put into wordlist PYTHON_VERSION_=$(wordlist 2,4,$(subst ., ,$(shell python -V 2>&1))) + # Get major version from aforementioned list PYTHON_MAJOR_VERSION_=$(word 1,$(PYTHON_VERSION_)) + # Just in case Make has some weird scope stuff PYTHON=0 + # If the major Python version is the one we want.. -ifeq ($(PYTHON_MAJOR_VERSION_),2) +ifeq ($(PYTHON_MAJOR_VERSION_),3) # Then we can just use the normal Python executable PYTHON:=python else # However, this isn't always the case.. - # Let's look for `python2`. If `which` doesn't return a null value, then + # Let's look for `python3`. If `which` doesn't return a null value, then # it exists! - ifneq ($(shell which python2), "") - PYTHON:=python2 + ifneq ($(shell which python3), "") + PYTHON:=python3 else # And if it doesn't exist, let's use the default Python, and warn the user. # PYTHON NOT FOUND. PYTHON:=python - echo "Python not found." + $(warning "Python3 not found.") endif endif diff --git a/make/macos.mk b/make/macos.mk index c48e97e4..62b715e3 100755 --- a/make/macos.mk +++ b/make/macos.mk @@ -9,15 +9,36 @@ # Check for and find Python ############################ -ifneq (, $(shell which /usr/local/bin/python)) - # Homebrew python present. Use it. - PYTHON_ROOT:=/usr/local/bin/ + +# Get Python version, separate major/minor/patch, then put into wordlist +PYTHON_VERSION_=$(wordlist 2,4,$(subst ., ,$(shell python -V 2>&1))) + +# Get major version from aforementioned list +PYTHON_MAJOR_VERSION_=$(word 1,$(PYTHON_VERSION_)) + +# Just in case Make has some weird scope stuff +PYTHON=0 + +# If the major Python version is the one we want.. +ifeq ($(PYTHON_MAJOR_VERSION_),3) + # Then we can just use the normal Python executable + PYTHON:=python else - # Homebrew python not present. Use the system python command. - PYTHON_ROOT:=/usr/bin/ + # However, this isn't always the case.. + # Let's look for `python3`. If `which` doesn't return a null value, then + # it exists! + ifneq ($(shell which python3), "") + PYTHON:=python3 + else + # And if it doesn't exist, let's use the default Python, and warn the user. + # PYTHON NOT FOUND. + PYTHON:=python \ + $(warning "Python3 not found.") + endif endif -#include $(ROOT_DIR)/make/python.mk +export PYTHON + ############################ # Configure shell commands diff --git a/make/windows.mk b/make/windows.mk index fdc59984..bbd734a6 100644 --- a/make/windows.mk +++ b/make/windows.mk @@ -4,6 +4,42 @@ # Configure an environment that will allow VESC's code to be built on a Windows # system. + +############################ +# Check for and find Python +############################ + + +# Get Python version, separate major/minor/patch, then put into wordlist +PYTHON_VERSION_=$(wordlist 2,4,$(subst ., ,$(shell python -V 2>&1))) + +# Get major version from aforementioned list +PYTHON_MAJOR_VERSION_=$(word 1,$(PYTHON_VERSION_)) + +# Just in case Make has some weird scope stuff +PYTHON=0 + +# If the major Python version is the one we want.. +ifeq ($(PYTHON_MAJOR_VERSION_),3) + # Then we can just use the normal Python executable + PYTHON:=python +else + # However, this isn't always the case.. + # Let's look for `python3`. If `where` doesn't return a null value, then + # it exists! + ifneq ($(shell where python3), "") + PYTHON:=python3 + else + # And if it doesn't exist, let's use the default Python, and warn the user. + # PYTHON NOT FOUND. + PYTHON:=python \ + $(warning "Python3 not found.") + endif +endif + +export PYTHON + + ############################ # Configure shell commands ############################