2020-02-19 05:18:36 +00:00
DIST := dist
GO ?= go
SHASUM ?= shasum -a 256
i f n e q ( $( DRONE_TAG ) , )
VERSION ?= $( subst v,,$( DRONE_TAG) )
LONG_VERSION ?= $( VERSION)
e l s e
ifneq ( $( DRONE_BRANCH) ,)
VERSION ?= $( subst release/v,,$( DRONE_BRANCH) )
else
VERSION ?= master
endif
LONG_VERSION ?= $( shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//' )
e n d i f
2020-02-20 19:09:56 +00:00
LDFLAGS := $( LDFLAGS) -X " go.jolheiser.com/gpm/modules/config.Version= $( LONG_VERSION) "
2020-02-19 05:18:36 +00:00
.PHONY : build
build :
$( GO) build -ldflags '-s -w $(LDFLAGS)'
.PHONY : lint
lint :
@hash golangci-lint > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
export BINARY = "golangci-lint" ; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $( go env GOPATH) /bin v1.23.1; \
fi
golangci-lint run --timeout 5m
.PHONY : fmt
fmt :
$( GO) fmt ./...
.PHONY : test
test :
$( GO) test -race ./...
.PHONY : release
release : release -dirs check -xgo release -windows release -linux release -darwin release -copy release -compress release -check
.PHONY : check -xgo
check-xgo :
@hash xgo > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
$( GO) get -u src.techknowlogick.com/xgo; \
fi
.PHONY : release -dirs
release-dirs :
mkdir -p $( DIST) /binaries $( DIST) /release
.PHONY : release -windows
release-windows :
xgo -dest $( DIST) /binaries -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gpm-$( VERSION) .
i f e q ( $( CI ) , d r o n e )
cp /build/* $( DIST) /binaries
e n d i f
.PHONY : release -linux
release-linux :
xgo -dest $( DIST) /binaries -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out gpm-$( VERSION) .
i f e q ( $( CI ) , d r o n e )
cp /build/* $( DIST) /binaries
e n d i f
.PHONY : release -darwin
release-darwin :
xgo -dest $( DIST) /binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gpm-$( VERSION) .
i f e q ( $( CI ) , d r o n e )
cp /build/* $( DIST) /binaries
e n d i f
.PHONY : release -copy
release-copy :
cd $( DIST) ; for file in ` find /build -type f -name "*" ` ; do cp $$ { file} ./release/; done ;
.PHONY : release -check
release-check :
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " checksumming $$ {file} " && $( SHASUM) ` echo $$ { file} | sed 's/^..//' ` > $$ { file} .sha256; done ;
.PHONY : release -compress
release-compress :
@hash gxz > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
$( GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
fi
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " compressing $$ {file} " && gxz -k -9 $$ { file} ; done ;