[CRIU] [PATCH v3 2/5] Makefiles: auto-detect python version - prefer python2

Adrian Reber adrian at lisas.de
Wed May 16 09:20:23 MSK 2018


From: Adrian Reber <areber at redhat.com>

This prepares CRIT for python2/python3 compatibility by auto-detecting
the installed python version. python2 is detected first and then the
variable PYTHON is set.

By setting the variable PYTHON to python2/python3 the user can override
the auto-detection.

Signed-off-by: Adrian Reber <areber at redhat.com>
---
 lib/Makefile                 | 3 +--
 lib/py/images/Makefile       | 4 ++--
 scripts/nmk/scripts/tools.mk | 3 ++-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/Makefile b/lib/Makefile
index 26b355a..9463284 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,5 @@
 CRIU_SO			:= libcriu.so
 UAPI_HEADERS		:= lib/c/criu.h images/rpc.proto
-PYTHON_BIN ?= python2
 
 #
 # File to keep track of files installed by setup.py
@@ -54,7 +53,7 @@ install: lib-c lib-py crit/crit lib/c/criu.pc.in
 	$(Q) sed -e 's, at version@,$(CRIU_VERSION),' -e 's, at libdir@,$(LIBDIR),' -e 's, at includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
 	$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
 	$(E) "  INSTALL " crit
-	$(Q) $(PYTHON_BIN) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
+	$(Q) $(PYTHON) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
 .PHONY: install
 
 uninstall:
diff --git a/lib/py/images/Makefile b/lib/py/images/Makefile
index cb328ec..f7df20f 100644
--- a/lib/py/images/Makefile
+++ b/lib/py/images/Makefile
@@ -12,11 +12,11 @@ images:
 
 magic.py: scripts/magic-gen.py criu/include/magic.h
 	$(call msg-gen, $@)
-	$(Q) python $^ $(obj)/$@
+	$(Q) $(PYTHON) $^ $(obj)/$@
 
 pb.py: images
 	$(Q) echo "# Autogenerated. Do not edit!" > $(obj)/$@
-	$(Q) for m in $(proto-py-modules); do \
+	$(Q) for m in $(filter-out opts_pb2, $(proto-py-modules)); do \
 		echo "from .$$m import *" >> $(obj)/$@ ;\
 	done
 .PHONY: pb.py
diff --git a/scripts/nmk/scripts/tools.mk b/scripts/nmk/scripts/tools.mk
index 56dba84..485fe9f 100644
--- a/scripts/nmk/scripts/tools.mk
+++ b/scripts/nmk/scripts/tools.mk
@@ -18,7 +18,8 @@ MAKE		:= make
 MKDIR		:= mkdir -p
 AWK		:= awk
 PERL		:= perl
-PYTHON		:= python
+FULL_PYTHON	:= $(shell which python2 2>/dev/null || which python3 2>/dev/null)
+PYTHON		?= $(shell basename $(FULL_PYTHON))
 FIND		:= find
 SH		:= $(shell if [ -x "$$BASH" ]; then echo $$BASH;        \
                         else if [ -x /bin/bash ]; then echo /bin/bash;  \
-- 
1.8.3.1



More information about the CRIU mailing list