From afc1f3a2c28664b6a0ddc6b79019d2c970926b32 Mon Sep 17 00:00:00 2001 From: Paul Wise Date: Mon, 5 Apr 2021 13:45:54 +0800 Subject: [PATCH] Try to install Python scripts with versioned Python shebangs Allow overriding the Python version. The Python setuptools based build system already modifies shebangs. The Python scripts have unversioned Python shebangs so they will fail if an unversioned Python is not provided by the OS. The Debian bullseye release will not have an unversioned Python by default. Avoid make pattern rules and shell functions since they are not portable. --- Makefile | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 070d33b..70485f2 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,28 @@ prefix := $(HOME) bindir := $(prefix)/bin mandir := $(prefix)/share/man/man1 -all: doc +all: build doc + +build: + if [ -n "$$PYTHON" ] && "$$PYTHON" -c 'import mercurial' 2> /dev/null ; then \ + : Use chosen Python version ; \ + elif python3 -c 'import mercurial' 2> /dev/null ; then \ + PYTHON=python3 ; \ + elif python2 -c 'import mercurial' 2> /dev/null ; then \ + PYTHON=python2 ; \ + elif python -c 'import mercurial' 2> /dev/null ; then \ + PYTHON=python ; \ + fi ; \ + if [ -n "$$PYTHON" ] ; then \ + PYTHON=python ; \ + fi ; \ + mkdir -p bin ; \ + for s in git-remote-hg git-hg-helper ; do \ + printf "%s\n" "#!/usr/bin/env $$PYTHON" > "bin/$$s" ; \ + tail -n +2 "./$$s" >> "bin/$$s" ; \ + chmod 755 "bin/$$s" ; \ + touch -r "./$$s" "bin/$$s" ; \ + done doc: doc/git-remote-hg.1 @@ -15,13 +36,14 @@ doc/git-remote-hg.1: doc/git-remote-hg.txt clean: $(RM) doc/git-remote-hg.1 + $(RM) -r bin/ D = $(DESTDIR) -install: +install: build install -d -m 755 $(D)$(bindir)/ - install -m 755 git-remote-hg $(D)$(bindir)/git-remote-hg - install -m 755 git-hg-helper $(D)$(bindir)/git-hg-helper + install -m 755 bin/git-remote-hg $(D)$(bindir)/git-remote-hg + install -m 755 bin/git-hg-helper $(D)$(bindir)/git-hg-helper install-doc: doc install -d -m 755 $(D)$(mandir)/ @@ -39,4 +61,4 @@ pypi-upload: pypi-test: twine upload --repository-url https://test.pypi.org/legacy/ dist/* -.PHONY: all test install install-doc clean pypy pypy-upload +.PHONY: all build test install install-doc clean pypy pypy-upload