2020-02-18 16:51:10 +01:00
DIST := dist
2020-02-14 21:46:02 +01:00
GO ?= go
2020-02-18 16:51:10 +01:00
SHASUM ?= shasum -a 256
2020-02-14 21:46:02 +01:00
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
LDFLAGS := $( LDFLAGS) -X " main.Version= $( LONG_VERSION) "
.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" ; \
2020-02-27 05:58:02 +01:00
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $( go env GOPATH) /bin v1.23.6; \
2020-02-14 21:46:02 +01:00
fi
golangci-lint run --timeout 5m
.PHONY : fmt
fmt :
$( GO) fmt ./...
.PHONY : test
test :
2020-02-18 16:51:10 +01:00
$( 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 sip-$( 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 sip-$( 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 sip-$( 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 ;