[v2,2/5] Makefiles: auto-detect python version - prefer python2

Submitted by Adrian Reber on May 14, 2018, 1:33 p.m.

Details

Message ID 1526304810-21335-3-git-send-email-adrian@lisas.de
State Accepted
Series "Series without cover letter"
Headers show

Commit Message

Adrian Reber May 14, 2018, 1:33 p.m.
From: Adrian Reber <areber@redhat.com>

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

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 Makefile.config        | 9 +++++++++
 lib/Makefile           | 3 +--
 lib/py/images/Makefile | 4 ++--
 3 files changed, 12 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/Makefile.config b/Makefile.config
index 0e55780..cb0fd77 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -12,6 +12,15 @@  ifeq ($(call pkg-config-check,libselinux),y)
         FEATURE_DEFINES	+= -DCONFIG_HAS_SELINUX
 endif
 
+ifndef CRIU_PYTHON
+	CRIU_PYTHON := $(shell python2 -V 2>/dev/null || echo python3)
+ifneq ($(CRIU_PYTHON),python3)
+	CRIU_PYTHON := python2
+endif
+endif
+
+export CRIU_PYTHON
+
 export LIBS += $(LIBS_FEATURES)
 
 CONFIG_FILE = .config
diff --git a/lib/Makefile b/lib/Makefile
index 26b355a..7c0ab76 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,@version@,$(CRIU_VERSION),' -e 's,@libdir@,$(LIBDIR),' -e 's,@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) $(CRIU_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..06e1aee 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)/$@
+	$(CRIU_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