Skip to content

Commit da3287c

Browse files
committed
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
1 parent 05a1a25 commit da3287c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ifdef GH_OAUTH_CLIENT_SECRET
2626
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS)
2727
endif
2828

29+
install-bins += bin/gh
2930
bin/gh: $(BUILD_FILES)
3031
@go build -trimpath -ldflags "$(GO_LDFLAGS)" -o "$@" ./cmd/gh
3132

@@ -62,3 +63,20 @@ endif
6263
.PHONY: manpages
6364
manpages:
6465
go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/
66+
67+
DESTDIR :=
68+
prefix := /usr/local
69+
bindir := ${prefix}/bin
70+
71+
.PHONY: install install-strip uninstall
72+
INSTALL_STRIP_FLAG =
73+
install-strip:
74+
@${MAKE} INSTALL_STRIP_FLAG=-s install
75+
76+
install: ${install-bins}
77+
install -d ${DESTDIR}${bindir}
78+
install -m555 ${INSTALL_STRIP_FLAG} ${install-bins} ${DESTDIR}${bindir}/
79+
80+
remove-bins := ${install-bins:bin/%=${DESTDIR}${bindir}/%}
81+
uninstall:
82+
rm -f ${remove-bins}

0 commit comments

Comments
 (0)