Skip to content

Commit 75e4e70

Browse files
authored
Fix #9299 (Makefile: tools/matchcompiler.py is executed via Python 2) (cppcheck-opensource#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.
1 parent d27e70d commit 75e4e70

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ ifeq ($(SRCDIR),build)
1919
MATCHCOMPILER:=yes
2020
endif
2121
ifeq ($(MATCHCOMPILER),yes)
22+
# Find available Python interpreter
23+
PYTHON_INTERPRETER := $(shell which python)
24+
ifndef PYTHON_INTERPRETER
25+
PYTHON_INTERPRETER := $(shell which python3)
26+
endif
27+
ifndef PYTHON_INTERPRETER
28+
$(error Did not find a Python interpreter)
29+
endif
2230
ifdef VERIFY
23-
matchcompiler_S := $(shell python tools/matchcompiler.py --verify)
31+
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)
2432
else
25-
matchcompiler_S := $(shell python tools/matchcompiler.py)
33+
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)
2634
endif
2735
libcppdir:=build
2836
else

tools/dmake.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,18 @@ int main(int argc, char **argv)
231231
<< " MATCHCOMPILER:=yes\n"
232232
<< "endif\n";
233233
fout << "ifeq ($(MATCHCOMPILER),yes)\n"
234+
<< " # Find available Python interpreter\n"
235+
<< " PYTHON_INTERPRETER := $(shell which python)\n"
236+
<< " ifndef PYTHON_INTERPRETER\n"
237+
<< " PYTHON_INTERPRETER := $(shell which python3)\n"
238+
<< " endif\n"
239+
<< " ifndef PYTHON_INTERPRETER\n"
240+
<< " $(error Did not find a Python interpreter)\n"
241+
<< " endif\n"
234242
<< " ifdef VERIFY\n"
235-
<< " matchcompiler_S := $(shell python tools/matchcompiler.py --verify)\n"
243+
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)\n"
236244
<< " else\n"
237-
<< " matchcompiler_S := $(shell python tools/matchcompiler.py)\n"
245+
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)\n"
238246
<< " endif\n"
239247
<< " libcppdir:=build\n"
240248
<< "else\n"

0 commit comments

Comments
 (0)