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