Skip to content

Commit a67057c

Browse files
committed
update makefile
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
1 parent 5eb45d5 commit a67057c

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ PKG := github.com/genuinetools/$(NAME)
44

55
CGO_ENABLED := 0
66

7+
# Set any default go build tags.
8+
BUILDTAGS :=
9+
710
include basic.mk
11+
12+
.PHONY: prebuild
13+
prebuild:

basic.mk

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Set an output prefix, which is the local directory if not specified
22
PREFIX?=$(shell pwd)
33

4-
# Set any default go build tags
5-
BUILDTAGS :=
6-
74
# Set the build dir, where built cross-compiled binaries will be output
85
BUILDDIR := ${PREFIX}/cross
96

@@ -29,14 +26,14 @@ GO := go
2926
GOOSARCHES = $(shell cat .goosarch)
3027

3128
.PHONY: build
32-
build: $(NAME) ## Builds a dynamic executable or package.
29+
build: prebuild $(NAME) ## Builds a dynamic executable or package.
3330

3431
$(NAME): $(wildcard *.go) $(wildcard */*.go) VERSION.txt
3532
@echo "+ $@"
3633
$(GO) build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) .
3734

3835
.PHONY: static
39-
static: ## Builds a static executable.
36+
static: prebuild ## Builds a static executable.
4037
@echo "+ $@"
4138
CGO_ENABLED=$(CGO_ENABLED) $(GO) build \
4239
-tags "$(BUILDTAGS) static_build" \
@@ -55,7 +52,7 @@ lint: ## Verifies `golint` passes.
5552
@golint ./... | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr
5653

5754
.PHONY: test
58-
test: ## Runs the go tests.
55+
test: prebuild ## Runs the go tests.
5956
@echo "+ $@"
6057
@$(GO) test -v -tags "$(BUILDTAGS) cgo" $(shell $(GO) list ./... | grep -v vendor)
6158

@@ -70,7 +67,7 @@ staticcheck: ## Verifies `staticcheck` passes.
7067
@staticcheck $(shell $(GO) list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr
7168

7269
.PHONY: cover
73-
cover: ## Runs go test with coverage.
70+
cover: prebuild ## Runs go test with coverage.
7471
@echo "" > coverage.txt
7572
@for d in $(shell $(GO) list ./... | grep -v vendor); do \
7673
$(GO) test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
@@ -81,7 +78,7 @@ cover: ## Runs go test with coverage.
8178
done;
8279

8380
.PHONY: install
84-
install: ## Installs the executable or package.
81+
install: prebuild ## Installs the executable or package.
8582
@echo "+ $@"
8683
$(GO) install -a -tags "$(BUILDTAGS)" ${GO_LDFLAGS} .
8784

@@ -96,7 +93,7 @@ sha256sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).sha256;
9693
endef
9794

9895
.PHONY: cross
99-
cross: *.go VERSION.txt ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary).
96+
cross: *.go VERSION.txt prebuild ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary).
10097
@echo "+ $@"
10198
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))
10299

@@ -110,7 +107,7 @@ sha256sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).sha256;
110107
endef
111108

112109
.PHONY: release
113-
release: *.go VERSION.txt ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH).
110+
release: *.go VERSION.txt prebuild ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH).
114111
@echo "+ $@"
115112
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))
116113

@@ -143,6 +140,15 @@ AUTHORS:
143140
@$(file >>$@,# For how it is generated, see `make AUTHORS`.)
144141
@echo "$(shell git log --format='\n%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf)" >> $@
145142

143+
.PHONY: vendor
144+
vendor: ## Updates the vendoring directory.
145+
@$(RM) Gopkg.toml Gopkg.lock
146+
@$(RM) go.mod go.sum
147+
@$(RM) -r vendor
148+
@GO111MODULE=on $(GO) mod init
149+
@GO111MODULE=on $(GO) mod tidy
150+
@GO111MODULE=on $(GO) mod vendor
151+
146152
.PHONY: clean
147153
clean: ## Cleanup any build binaries or packages.
148154
@echo "+ $@"

0 commit comments

Comments
 (0)