From da3287c26cc7e39cddee46363df8821a305c7a8c Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Sat, 21 Nov 2020 21:46:32 +0100 Subject: [PATCH 1/4] Add make (un)install targets for POSIX systems The implementation imitates the behavior of build-systems generated by GNU Automake. Implemented targets: - install - install-strip - uninstall Implemented variables: - DESTDIR - prefix - bindir - INSTALL_STRIP_FLAG Internal implementation details: - install-bins variable collects user binaries to be installed - install-dirs variable collects directories to be created --- Makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Makefile b/Makefile index 859461984..a5b5f815a 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ ifdef GH_OAUTH_CLIENT_SECRET GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS) endif +install-bins += bin/gh bin/gh: $(BUILD_FILES) @go build -trimpath -ldflags "$(GO_LDFLAGS)" -o "$@" ./cmd/gh @@ -62,3 +63,20 @@ endif .PHONY: manpages manpages: go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/ + +DESTDIR := +prefix := /usr/local +bindir := ${prefix}/bin + +.PHONY: install install-strip uninstall +INSTALL_STRIP_FLAG = +install-strip: + @${MAKE} INSTALL_STRIP_FLAG=-s install + +install: ${install-bins} + install -d ${DESTDIR}${bindir} + install -m555 ${INSTALL_STRIP_FLAG} ${install-bins} ${DESTDIR}${bindir}/ + +remove-bins := ${install-bins:bin/%=${DESTDIR}${bindir}/%} +uninstall: + rm -f ${remove-bins} From 8d2881d5ea4412439179ca748e7ba47a70e6e4af Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Sun, 29 Nov 2020 20:36:32 +0100 Subject: [PATCH 2/4] Install manual pages --- .gitignore | 1 + Makefile | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9895939a6..8f460efe7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /site .github/**/node_modules /CHANGELOG.md +/manpages.list # VS Code .vscode diff --git a/Makefile b/Makefile index a5b5f815a..b6db4eab9 100644 --- a/Makefile +++ b/Makefile @@ -61,22 +61,28 @@ endif .PHONY: manpages -manpages: +manpages: manpages.list +manpages.list: go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/ + find share/man -type f > $@ DESTDIR := prefix := /usr/local bindir := ${prefix}/bin +mandir := ${prefix}/share/man .PHONY: install install-strip uninstall INSTALL_STRIP_FLAG = install-strip: @${MAKE} INSTALL_STRIP_FLAG=-s install -install: ${install-bins} +install: ${install-bins} manpages.list install -d ${DESTDIR}${bindir} install -m555 ${INSTALL_STRIP_FLAG} ${install-bins} ${DESTDIR}${bindir}/ + install -d ${DESTDIR}${mandir}/man1 + install -m444 $(shell cat manpages.list) ${DESTDIR}${mandir}/man1/ remove-bins := ${install-bins:bin/%=${DESTDIR}${bindir}/%} -uninstall: +uninstall: manpages.list rm -f ${remove-bins} + rm -f $(patsubst share/man/%,${DESTDIR}${mandir}/%,$(shell cat manpages.list)) From c92f416cc0a590cdef6e6b8bef88b91306e66a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 1 Dec 2020 15:46:18 +0100 Subject: [PATCH 3/4] Simplify `make install/uninstall` --- .gitignore | 1 - Makefile | 25 ++++++++----------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 8f460efe7..9895939a6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ /site .github/**/node_modules /CHANGELOG.md -/manpages.list # VS Code .vscode diff --git a/Makefile b/Makefile index b6db4eab9..8ee9e7dc6 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ ifdef GH_OAUTH_CLIENT_SECRET GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS) endif -install-bins += bin/gh bin/gh: $(BUILD_FILES) @go build -trimpath -ldflags "$(GO_LDFLAGS)" -o "$@" ./cmd/gh @@ -59,30 +58,22 @@ endif git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html .PHONY: site-bump - .PHONY: manpages -manpages: manpages.list -manpages.list: +manpages: go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/ - find share/man -type f > $@ DESTDIR := prefix := /usr/local bindir := ${prefix}/bin mandir := ${prefix}/share/man -.PHONY: install install-strip uninstall -INSTALL_STRIP_FLAG = -install-strip: - @${MAKE} INSTALL_STRIP_FLAG=-s install - -install: ${install-bins} manpages.list +.PHONY: install +install: bin/gh manpages install -d ${DESTDIR}${bindir} - install -m555 ${INSTALL_STRIP_FLAG} ${install-bins} ${DESTDIR}${bindir}/ + install -m755 bin/gh ${DESTDIR}${bindir}/ install -d ${DESTDIR}${mandir}/man1 - install -m444 $(shell cat manpages.list) ${DESTDIR}${mandir}/man1/ + install -m644 ./share/man/man1/* ${DESTDIR}${mandir}/man1/ -remove-bins := ${install-bins:bin/%=${DESTDIR}${bindir}/%} -uninstall: manpages.list - rm -f ${remove-bins} - rm -f $(patsubst share/man/%,${DESTDIR}${mandir}/%,$(shell cat manpages.list)) +.PHONY: uninstall +uninstall: + rm -f ${DESTDIR}${bindir}/gh ${DESTDIR}${mandir}/man1/gh.1 ${DESTDIR}${mandir}/man1/gh-*.1 From 6f689ff051d0be160fb3014d57f3162722ac658d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 1 Dec 2020 20:31:20 +0100 Subject: [PATCH 4/4] Document `make install` --- docs/source.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/source.md b/docs/source.md index fc90ef94f..1c6a8470a 100644 --- a/docs/source.md +++ b/docs/source.md @@ -15,16 +15,18 @@ $ cd gh-cli ``` -2. Build the project - - ``` - $ make - ``` - -3. Move the resulting `bin/gh` executable to somewhere in your PATH +2. Build and install ```sh - $ sudo mv ./bin/gh /usr/local/bin/ + # installs to '/usr/local' by default; sudo may be required + $ make install ``` -4. Run `gh version` to check if it worked. + To install to a different location: + ```sh + $ make install prefix=/path/to/gh + ``` + + Make sure that the `${prefix}/bin` directory is in your PATH. + +3. Run `gh version` to check if it worked.