Fix #9299 (Makefile: tools/matchcompiler.py is executed via Python 2) (#2247)

Check if "python" is available, if not check for "python3" and use
the available Python interpreter. If no Python interpreter is found,
"make" fails with an according error message.
This solves the issue that not all modern Linux distributions any longer
install Python 2 by default, so "python" is not available and
"make MATCHCOMPILER=yes" would fail. Instead of forcing the users to
install Python 2, Python 3 is used in such a case now if it is
available.
This commit is contained in:
Sebastian 2019-10-08 10:55:40 +02:00 committed by GitHub
parent d27e70db8e
commit 75e4e70ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -19,10 +19,18 @@ ifeq ($(SRCDIR),build)
MATCHCOMPILER:=yes
endif
ifeq ($(MATCHCOMPILER),yes)
# Find available Python interpreter
PYTHON_INTERPRETER := $(shell which python)
ifndef PYTHON_INTERPRETER
PYTHON_INTERPRETER := $(shell which python3)
endif
ifndef PYTHON_INTERPRETER
$(error Did not find a Python interpreter)
endif
ifdef VERIFY
matchcompiler_S := $(shell python tools/matchcompiler.py --verify)
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)
else
matchcompiler_S := $(shell python tools/matchcompiler.py)
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)
endif
libcppdir:=build
else

View File

@ -231,10 +231,18 @@ int main(int argc, char **argv)
<< " MATCHCOMPILER:=yes\n"
<< "endif\n";
fout << "ifeq ($(MATCHCOMPILER),yes)\n"
<< " # Find available Python interpreter\n"
<< " PYTHON_INTERPRETER := $(shell which python)\n"
<< " ifndef PYTHON_INTERPRETER\n"
<< " PYTHON_INTERPRETER := $(shell which python3)\n"
<< " endif\n"
<< " ifndef PYTHON_INTERPRETER\n"
<< " $(error Did not find a Python interpreter)\n"
<< " endif\n"
<< " ifdef VERIFY\n"
<< " matchcompiler_S := $(shell python tools/matchcompiler.py --verify)\n"
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)\n"
<< " else\n"
<< " matchcompiler_S := $(shell python tools/matchcompiler.py)\n"
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)\n"
<< " endif\n"
<< " libcppdir:=build\n"
<< "else\n"