The main build script for this project is `script/build.go` which
implements Makefile-like building of the `gh` binary and associated man
pages. Our Makefile defers to the Go script.
However, when setting GOOS, GOARCH, and other environment variables to
modify the target for the resulting binary, these environment variables
would affect the execution of `build.go` as well, which was unintended.
This tweaks our Makefile to reset variables like GOOS and GOARCH when
building the `build.go` script itself, ensuring that the built script
runs on the same platform, and adds the ability to pass environment
variables as arguments to `go run script/build.go`. This allows the
following usage on platforms without `make`:
go run script/build.go GOOS=linux
With this style of invocation, the GOOS setting does not actually affect
`go run` itself; just the `go build` that is executed in a child process.
74 lines
1.9 KiB
Makefile
74 lines
1.9 KiB
Makefile
CGO_CPPFLAGS ?= ${CPPFLAGS}
|
|
export CGO_CPPFLAGS
|
|
CGO_CFLAGS ?= ${CFLAGS}
|
|
export CGO_CFLAGS
|
|
CGO_LDFLAGS ?= $(filter -g -L% -l% -O%,${LDFLAGS})
|
|
export CGO_LDFLAGS
|
|
|
|
EXE =
|
|
ifeq ($(GOOS),windows)
|
|
EXE = .exe
|
|
endif
|
|
|
|
## The following tasks delegate to `script/build.go` so they can be run cross-platform.
|
|
|
|
.PHONY: bin/gh$(EXE)
|
|
bin/gh$(EXE): script/build
|
|
@script/build $@
|
|
|
|
script/build: script/build.go
|
|
GOOS= GOARCH= GOARM= GOFLAGS= CGO_ENABLED= go build -o $@ $<
|
|
|
|
.PHONY: clean
|
|
clean: script/build
|
|
@script/build $@
|
|
|
|
.PHONY: manpages
|
|
manpages: script/build
|
|
@script/build $@
|
|
|
|
# just a convenience task around `go test`
|
|
.PHONY: test
|
|
test:
|
|
go test ./...
|
|
|
|
## Site-related tasks are exclusively intended for use by the GitHub CLI team and for our release automation.
|
|
|
|
site:
|
|
git clone https://github.com/github/cli.github.com.git "$@"
|
|
|
|
.PHONY: site-docs
|
|
site-docs: site
|
|
git -C site pull
|
|
git -C site rm 'manual/gh*.md' 2>/dev/null || true
|
|
go run ./cmd/gen-docs --website --doc-path site/manual
|
|
rm -f site/manual/*.bak
|
|
git -C site add 'manual/gh*.md'
|
|
git -C site commit -m 'update help docs' || true
|
|
|
|
.PHONY: site-bump
|
|
site-bump: site-docs
|
|
ifndef GITHUB_REF
|
|
$(error GITHUB_REF is not set)
|
|
endif
|
|
sed -i.bak -E 's/(assign version = )".+"/\1"$(GITHUB_REF:refs/tags/v%=%)"/' site/index.html
|
|
rm -f site/index.html.bak
|
|
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
|
|
|
|
## Install/uninstall tasks are here for use on *nix platform. On Windows, there is no equivalent.
|
|
|
|
DESTDIR :=
|
|
prefix := /usr/local
|
|
bindir := ${prefix}/bin
|
|
mandir := ${prefix}/share/man
|
|
|
|
.PHONY: install
|
|
install: bin/gh manpages
|
|
install -d ${DESTDIR}${bindir}
|
|
install -m755 bin/gh ${DESTDIR}${bindir}/
|
|
install -d ${DESTDIR}${mandir}/man1
|
|
install -m644 ./share/man/man1/* ${DESTDIR}${mandir}/man1/
|
|
|
|
.PHONY: uninstall
|
|
uninstall:
|
|
rm -f ${DESTDIR}${bindir}/gh ${DESTDIR}${mandir}/man1/gh.1 ${DESTDIR}${mandir}/man1/gh-*.1
|