Port select portions of Makefile to `script/build.go` · whi-tw/github-cli@39431a1 · GitHub
Skip to content

Commit 39431a1

Browse files
committed
Port select portions of Makefile to script/build.go
This is to enable build tasks on Windows.
1 parent 5e97775 commit 39431a1

4 files changed

Lines changed: 215 additions & 32 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions

Makefile

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,49 @@
1-
BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
2-
{{end}}' ./...)
3-
4-
GH_VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
5-
DATE_FMT = +%Y-%m-%d
6-
ifdef SOURCE_DATE_EPOCH
7-
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
8-
else
9-
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
10-
endif
11-
121
CGO_CPPFLAGS ?= ${CPPFLAGS}
132
export CGO_CPPFLAGS
143
CGO_CFLAGS ?= ${CFLAGS}
154
export CGO_CFLAGS
165
CGO_LDFLAGS ?= $(filter -g -L% -l% -O%,${LDFLAGS})
176
export CGO_LDFLAGS
187

19-
GO_LDFLAGS := -X github.com/cli/cli/internal/build.Version=$(GH_VERSION) $(GO_LDFLAGS)
20-
GO_LDFLAGS := -X github.com/cli/cli/internal/build.Date=$(BUILD_DATE) $(GO_LDFLAGS)
21-
ifdef GH_OAUTH_CLIENT_SECRET
22-
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(GO_LDFLAGS)
23-
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS)
24-
endif
8+
.PHONY: bin/gh
9+
bin/gh: script/build
10+
@script/build bin/gh
2511

26-
bin/gh: $(BUILD_FILES)
27-
go build -trimpath -ldflags "${GO_LDFLAGS}" -o "$@" ./cmd/gh
12+
script/build: script/build.go
13+
go build -o script/build script/build.go
2814

29-
clean:
30-
rm -rf ./bin ./share
3115
.PHONY: clean
16+
clean: script/build
17+
@script/build clean
3218

19+
.PHONY: manpages
20+
manpages: script/build
21+
@script/build manpages
22+
23+
.PHONY: test
3324
test:
3425
go test ./...
35-
.PHONY: test
3626

3727
site:
3828
git clone https://github.com/github/cli.github.com.git "$@"
3929

30+
.PHONY: site-docs
4031
site-docs: site
4132
git -C site pull
4233
git -C site rm 'manual/gh*.md' 2>/dev/null || true
4334
go run ./cmd/gen-docs --website --doc-path site/manual
4435
rm -f site/manual/*.bak
4536
git -C site add 'manual/gh*.md'
4637
git -C site commit -m 'update help docs' || true
47-
.PHONY: site-docs
4838

39+
.PHONY: site-bump
4940
site-bump: site-docs
5041
ifndef GITHUB_REF
5142
$(error GITHUB_REF is not set)
5243
endif
5344
sed -i.bak -E 's/(assign version = )".+"/\1"$(GITHUB_REF:refs/tags/v%=%)"/' site/index.html
5445
rm -f site/index.html.bak
5546
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
56-
.PHONY: site-bump
57-
58-
.PHONY: manpages
59-
manpages:
60-
go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/
6147

6248
DESTDIR :=
6349
prefix := /usr/local

docs/source.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
# installs to '/usr/local' by default; sudo may be required
2323
$ make install
2424

25-
# install to a different location
25+
# or, install to a different location
2626
$ make install prefix=/path/to/gh
2727
```
2828

2929
#### Windows
3030
```sh
31-
# build the binary
32-
> go build -o gh.exe ./cmd/gh
31+
# build the `bin\gh.exe` binary
32+
> go run script/build.go
3333
```
3434
There is no install step available on Windows.
3535

3636
3. Run `gh version` to check if it worked.
3737

3838
#### Windows
39-
Run `.\gh version` to check if it worked.
39+
Run `bin\gh version` to check if it worked.

script/build.go

Lines changed: 196 additions & 0 deletions

0 commit comments

Comments
 (0)