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

Submitted by Adrian Reber on May 16, 2018, 6:20 a.m.

Details

Message ID 1526451626-22662-3-git-send-email-adrian@lisas.de
State New
Headers show

Patch hide | download patch | download mbox

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,@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) $(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;  \