2020-01-26 03:43:05 +00:00
DIST := dist
GO ?= go
2020-01-26 20:09:41 +00:00
SED_INPLACE := sed -i
SHASUM ?= shasum -a 256
2020-01-26 03:43:05 +00:00
i f n e q ( $( DRONE_TAG ) , )
2020-01-26 19:43:59 +00:00
VERSION ?= $( subst v,,$( DRONE_TAG) )
LONG_VERSION ?= $( VERSION)
2020-01-26 03:43:05 +00:00
e l s e
2020-01-26 19:43:59 +00:00
ifneq ( $( DRONE_BRANCH) ,)
VERSION ?= $( subst release/v,,$( DRONE_BRANCH) )
else
VERSION ?= master
endif
2020-01-26 03:43:05 +00:00
LONG_VERSION ?= $( shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//' )
e n d i f
2022-06-22 01:27:24 +00:00
LDFLAGS := $( LDFLAGS) -X " code.gitea.io/changelog/cmd.Version= $( LONG_VERSION) "
2020-01-26 03:43:05 +00:00
.PHONY : build
2022-06-22 01:27:24 +00:00
build :
2020-01-26 03:43:05 +00:00
$( GO) build -ldflags '-s -w $(LDFLAGS)'
2022-06-22 01:27:24 +00:00
.PHONY : test
test :
$( GO) test -race -v ./...
2020-01-26 03:43:05 +00:00
.PHONY : lint
lint :
2023-02-27 21:59:03 +00:00
$( GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 run --timeout 5m
2020-01-26 03:43:05 +00:00
.PHONY : fmt
fmt :
2022-06-22 01:27:24 +00:00
$( GO) fmt ./...
2020-01-26 03:43:05 +00:00
.PHONY : release
2020-01-26 19:48:59 +00:00
release : release -dirs check -xgo release -windows release -linux release -darwin release -copy release -compress release -check
2020-01-26 03:43:05 +00:00
.PHONY : check -xgo
check-xgo :
@hash xgo > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
$( GO) get -u src.techknowlogick.com/xgo; \
fi
2020-01-26 19:43:59 +00:00
.PHONY : release -dirs
release-dirs :
mkdir -p $( DIST) /binaries $( DIST) /release
2020-01-26 03:43:05 +00:00
.PHONY : release -windows
release-windows :
2020-01-26 19:43:59 +00:00
xgo -dest $( DIST) /binaries -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out changelog-$( 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 changelog-$( VERSION) .
i f e q ( $( CI ) , d r o n e )
cp /build/* $( DIST) /binaries
e n d i f
2020-01-26 03:43:05 +00:00
.PHONY : release -darwin
release-darwin :
2020-01-26 19:43:59 +00:00
xgo -dest $( DIST) /binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out changelog-$( 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 ;
2020-01-26 03:43:05 +00:00
.PHONY : release -check
release-check :
2020-01-26 19:43:59 +00:00
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " checksumming $$ {file} " && $( SHASUM) ` echo $$ { file} | sed 's/^..//' ` > $$ { file} .sha256; done ;
2020-01-26 03:43:05 +00:00
.PHONY : release -compress
release-compress :
@hash gxz > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2022-06-23 12:23:37 +00:00
$( GO) install github.com/ulikunitz/xz/cmd/gxz@latest; \
2020-01-26 03:43:05 +00:00
fi
2020-01-26 19:43:59 +00:00
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " compressing $$ {file} " && gxz -k -9 $$ { file} ; done ;