2019-10-02 09:15:22 +00:00
BUILD_VERSION := $( shell cat version)
BUILD_TIME := $( shell date "+%F %T" )
COMMIT_SHA1 := $( shell git rev-parse HEAD)
ROOT_DIR := $( shell dirname $( realpath $( lastword $( MAKEFILE_LIST) ) ) ) /
DIST_DIR := $( ROOT_DIR) /dist/
2018-08-01 03:18:23 +00:00
2019-10-02 13:24:19 +00:00
VERSION_PATH := $( shell cat ` go env GOMOD` | awk '/^module/{print $$2}' ) /metadata
LD_GIT_COMMIT := -X '$(VERSION_PATH).GitCommit=$(COMMIT_SHA1)'
LD_BUILD_TIME := -X '$(VERSION_PATH).BuildTime=$(BUILD_TIME)'
LD_GO_VERSION := -X '$(VERSION_PATH).GoVersion=`go version`'
LD_VERSION := -X '$(VERSION_PATH).Version=$(BUILD_VERSION)'
LD_FLAGS := " $( LD_GIT_COMMIT) $( LD_BUILD_TIME) $( LD_GO_VERSION) $( LD_VERSION) -w -s "
2018-08-01 03:18:23 +00:00
2019-10-02 09:15:22 +00:00
.PHONY : build release clean install upx
2018-08-01 03:18:23 +00:00
build :
2019-10-02 09:15:22 +00:00
i f n e q ( $( shell type gox >/dev /null 2>&1;echo $ $ ?) , 0 )
@echo "Can't find gox command, will start installation..."
GO111MODULE = off go get -v -u github.com/mitchellh/gox
e n d i f
2019-10-03 02:18:49 +00:00
@# $( if $( findstring 0,$( shell type gox >/dev/null 2>& 1; echo $$ ?) ) ,,echo "Can't find gox command, will start installation..." ; GO111MODULE = off go get -v -u github.com/mitchellh/gox)
2019-10-02 09:15:22 +00:00
gox -ldflags $( LD_FLAGS) -osarch= "darwin/amd64 linux/386 linux/amd64 windows/amd64" \
-output= " $( DIST_DIR) {{.Dir}}_{{.OS}}_{{.Arch}} "
2018-08-01 03:18:23 +00:00
clean :
2019-10-02 09:15:22 +00:00
rm -rf $( DIST_DIR) *
2018-08-01 03:18:23 +00:00
2019-10-02 09:15:22 +00:00
install :
2019-10-03 02:18:49 +00:00
@# go install -ldflags $( LD_FLAGS)
go build -ldflags $( LD_FLAGS) -o $( GOBIN) /hc
2018-08-01 03:18:23 +00:00
# 压缩。需要安装 https://github.com/upx/upx
upx :
2019-10-02 09:15:22 +00:00
upx $( DIST_DIR) **
release : build upx
i f n e q ( $( shell type ghr >/dev /null 2>&1;echo $ $ ?) , 0 )
@echo "Can't find ghr command, will start installation..."
GO111MODULE = off go get -v -u github.com/tcnksm/ghr
e n d i f
2019-10-03 02:18:49 +00:00
@# $( if $( findstring 0,$( shell type ghr >/dev/null 2>& 1; echo $$ ?) ) ,,echo "Can't find ghr command, will start installation..." ; GO111MODULE = off go get -v -u github.com/tcnksm/ghr)
2019-10-02 09:15:22 +00:00
ghr -u ehlxr -t $( GITHUB_RELEASE_TOKEN) -replace -delete --debug ${ BUILD_VERSION } $( DIST_DIR)
# this tells 'make' to export all variables to child processes by default.
.EXPORT_ALL_VARIABLES :
GO111MODULE = on
GOPROXY = https://goproxy.cn,direct
GOSUMDB = sum.golang.google.cn