Skip to content

Commit 617e063

Browse files
authored
Merge pull request #3 from oldthreefeng/develop
add makefile
2 parents dcbb478 + d00ad34 commit 617e063

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
LDFLAGS += -X "github.com/oldthreefeng/stress/cmd.BuildTime=$(shell date '+%F %T')"
2+
LDFLAGS += -X "github.com/oldthreefeng/stress/cmd.Build=$(shell git rev-parse --short HEAD)"
3+
LDFLAGS += -X "github.com/oldthreefeng/stress/cmd.Version=latest"
4+
LDFLAGS += -X "github.com/oldthreefeng/stress/cmd.GoVersion=$(shell go version)"
5+
BRANCH := $(shell git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
6+
BUILD := $(shell git rev-parse --short HEAD)
7+
NEWTAG := $(shell git describe --tags `git rev-list --tags --max-count=1` || echo "1.0.0")
8+
VERSION = $(NEWTAG)-$(BUILD)
9+
10+
BASEPATH := $(shell pwd)
11+
CGO_ENABLED = 0
12+
GOCMD = go
13+
GOBUILD = $(GOCMD) build
14+
GOTEST = $(GOCMD) test
15+
GOMOD = $(GOCMD) mod
16+
GOFILES = $(shell find . -name "*.go" -type f )
17+
18+
NAME := stress
19+
DIRNAME := output/bin
20+
SRCFILE= main.go
21+
SOFTWARENAME=$(NAME)-$(VERSION)
22+
23+
PLATFORMS := windows darwin linux
24+
25+
.PHONY: fmt
26+
fmt:
27+
@gofmt -s -w ${GOFILES}
28+
29+
.PHONY: test
30+
test: deps
31+
$(GOTEST) -v ./...
32+
33+
.PHONY: deps
34+
deps:
35+
$(GOMOD) tidy
36+
$(GOMOD) download
37+
38+
.PHONY: release
39+
release: windows darwin linux
40+
41+
BUILDDIR:=$(BASEPATH)/output
42+
43+
.PHONY:Asset
44+
Asset:
45+
@[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
46+
@[ -d $(DIRNAME) ] || mkdir -p $(DIRNAME)
47+
48+
.PHONY: $(PLATFORMS)
49+
$(PLATFORMS): Asset deps
50+
@echo "编译" $@
51+
GOOS=$@ GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on GOPROXY=https://goproxy.cn $(GOBUILD) -ldflags '$(LDFLAGS)' -o $(NAME) $(SRCFILE)
52+
cp -f $(NAME) $(DIRNAME)
53+
tar czvf $(BUILDDIR)/$(SOFTWARENAME)-$@-amd64.tar.gz $(DIRNAME)
54+
55+
.PHONY: clean
56+
clean:
57+
-rm -rf $(NAME)
58+
-rm -rf $(BUILDDIR)
59+
60+
.PHONY: push
61+
push: clean
62+
git add .
63+
git commit -m "$m"
64+
git push origin develop

build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
COMMIT_SHA1=$(git rev-parse --short HEAD || echo "0.0.0")
22
BUILD_TIME=$(date "+%F %T")
3-
go build -o stress -ldflags "-X github.com/oldthreefeng/stress/cmd.Version=$1 -X github.com/oldthreefeng/stress/cmd.Build=${COMMIT_SHA1} -X 'github.com/oldthreefeng/stress/cmd.BuildTime=${BUILD_TIME}'" main.go
3+
GO_VERSION=$(go version)
4+
go build -o stress -ldflags "-X github.com/oldthreefeng/stress/cmd.Version=$1 -X github.com/oldthreefeng/stress/cmd.GoVersion=${GO_VERSION} -X github.com/oldthreefeng/stress/cmd.Build=${COMMIT_SHA1} -X 'github.com/oldthreefeng/stress/cmd.BuildTime=${BUILD_TIME}'" main.go

cmd/version.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package cmd
1717

1818
import (
1919
"fmt"
20-
"runtime"
21-
2220
"github.com/spf13/cobra"
2321
)
2422

@@ -50,5 +48,6 @@ var (
5048
Version = "latest"
5149
Build = ""
5250
BuildTime = ""
53-
VersionStr = fmt.Sprintf("stress version: %v, build git hash: %v ,Go version: %v, Build Time : %v", Version, Build, runtime.Version(), BuildTime)
51+
GoVersion = ""
52+
VersionStr = fmt.Sprintf("stress version: %v, build git hash: %v ,%v, Build Time : %v", Version, Build, GoVersion, BuildTime)
5453
)

0 commit comments

Comments
 (0)