2019-04-26 01:06:53 +08:00
DIST := dist
IMPORT := code.gitea.io/tea
2020-03-05 17:22:41 +08:00
export GO111MODULE = on
2019-04-26 01:06:53 +08:00
GO ?= go
SED_INPLACE := sed -i
SHASUM ?= shasum -a 256
export PATH := $( $( GO) env GOPATH) /bin:$( PATH)
i f e q ( $( OS ) , W i n d o w s _ N T )
EXECUTABLE := tea.exe
e l s e
EXECUTABLE := tea
UNAME_S := $( shell uname -s)
ifeq ( $( UNAME_S) ,Darwin)
SED_INPLACE := sed -i ''
endif
e n d i f
GOFILES := $( shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go" )
GOFMT ?= gofmt -s
GOFLAGS := -i -v
EXTRA_GOFLAGS ?=
MAKE_VERSION := $( shell make -v | head -n 1)
i f n e q ( $( DRONE_TAG ) , )
VERSION ?= $( subst v,,$( DRONE_TAG) )
2019-04-26 11:41:21 +08:00
TEA_VERSION ?= $( VERSION)
2019-04-26 01:06:53 +08:00
e l s e
ifneq ( $( DRONE_BRANCH) ,)
VERSION ?= $( subst release/v,,$( DRONE_BRANCH) )
else
VERSION ?= master
endif
2019-04-26 11:41:21 +08:00
TEA_VERSION ?= $( shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//' )
2019-04-26 01:06:53 +08:00
e n d i f
2019-04-26 11:41:21 +08:00
LDFLAGS := -X " main.Version= $( TEA_VERSION) " -X " main.Tags= $( TAGS) "
2019-04-26 01:06:53 +08:00
2019-04-26 11:41:21 +08:00
PACKAGES ?= $( shell $( GO) list ./... | grep -v /vendor/)
2019-04-26 01:06:53 +08:00
SOURCES ?= $( shell find . -name "*.go" -type f)
TAGS ?=
i f e q ( $( OS ) , W i n d o w s _ N T )
EXECUTABLE := tea.exe
e l s e
EXECUTABLE := tea
e n d i f
# $(call strip-suffix,filename)
strip-suffix = $( firstword $( subst ., ,$( 1) ) )
.PHONY : all
all : build
.PHONY : clean
clean :
2020-03-05 17:22:41 +08:00
$( GO) clean -mod= vendor -i ./...
2019-04-26 11:41:21 +08:00
rm -rf $( EXECUTABLE) $( DIST)
2019-04-26 01:06:53 +08:00
.PHONY : fmt
fmt :
$( GOFMT) -w $( GOFILES)
.PHONY : vet
vet :
2020-03-05 17:22:41 +08:00
$( GO) vet -mod= vendor $( PACKAGES)
2019-04-26 01:06:53 +08:00
.PHONY : lint
lint :
@hash revive > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u github.com/mgechev/revive; \
2019-04-26 01:06:53 +08:00
fi
revive -config .revive.toml -exclude= ./vendor/... ./... || exit 1
.PHONY : misspell -check
misspell-check :
@hash misspell > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u github.com/client9/misspell/cmd/misspell; \
2019-04-26 01:06:53 +08:00
fi
misspell -error -i unknwon,destory $( GOFILES)
.PHONY : misspell
misspell :
@hash misspell > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u github.com/client9/misspell/cmd/misspell; \
2019-04-26 01:06:53 +08:00
fi
misspell -w -i unknwon $( GOFILES)
.PHONY : fmt -check
fmt-check :
# get all go files and run go fmt on them
@diff= $$ ( $( GOFMT) -d $( GOFILES) ) ; \
if [ -n " $$ diff " ] ; then \
echo "Please run 'make fmt' and commit the result:" ; \
echo " $$ {diff} " ; \
exit 1; \
fi ;
.PHONY : test
test :
2020-03-05 17:22:41 +08:00
$( GO) test -mod= vendor -tags= 'sqlite sqlite_unlock_notify' $( PACKAGES)
2019-04-26 01:06:53 +08:00
.PHONY : unit -test -coverage
unit-test-coverage :
2020-03-05 17:22:41 +08:00
$( GO) test -mod= vendor -tags= 'sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $( PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
2019-04-26 01:06:53 +08:00
.PHONY : vendor
vendor :
2020-03-05 17:22:41 +08:00
$( GO) mod tidy && $( GO) mod vendor
2019-04-26 01:06:53 +08:00
.PHONY : test -vendor
test-vendor : vendor
@diff= $$ ( git diff vendor/) ; \
if [ -n " $$ diff " ] ; then \
echo "Please run 'make vendor' and commit the result:" ; \
echo " $$ {diff} " ; \
exit 1; \
fi ;
.PHONY : check
check : test
.PHONY : install
install : $( wildcard *.go )
$( GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
.PHONY : build
build : $( EXECUTABLE )
$(EXECUTABLE) : $( SOURCES )
2020-03-05 17:22:41 +08:00
$( GO) build -mod= vendor $( GOFLAGS) $( EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
2019-04-26 01:06:53 +08:00
.PHONY : release
release : release -dirs release -windows release -linux release -darwin release -copy release -compress release -check
.PHONY : release -dirs
release-dirs :
mkdir -p $( DIST) /binaries $( DIST) /release
.PHONY : release -windows
release-windows :
@hash xgo > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u src.techknowlogick.com/xgo; \
2019-04-26 01:06:53 +08:00
fi
2019-04-26 11:41:21 +08:00
xgo -dest $( DIST) /binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out tea-$( VERSION) .
2019-04-26 01:06:53 +08:00
i f e q ( $( CI ) , d r o n e )
cp /build/* $( DIST) /binaries
e n d i f
.PHONY : release -linux
release-linux :
@hash xgo > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u src.techknowlogick.com/xgo; \
2019-04-26 01:06:53 +08:00
fi
2019-11-15 11:46:18 +08:00
xgo -dest $( DIST) /binaries -tags 'netgo $(TAGS)' -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 tea-$( VERSION) .
2019-04-26 01:06:53 +08:00
i f e q ( $( CI ) , d r o n e )
cp /build/* $( DIST) /binaries
e n d i f
.PHONY : release -darwin
release-darwin :
@hash xgo > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u src.techknowlogick.com/xgo; \
2019-04-26 01:06:53 +08:00
fi
2019-04-26 11:41:21 +08:00
xgo -dest $( DIST) /binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out tea-$( VERSION) .
2019-04-26 01:06:53 +08:00
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 ;
2019-04-27 21:01:07 +08:00
.PHONY : release -compress
release-compress :
@hash gxz > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 17:22:41 +08:00
cd /tmp && $( GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
2019-04-27 21:01:07 +08:00
fi
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " compressing $$ {file} " && gxz -k -9 $$ { file} ; done ;
2019-04-26 01:06:53 +08:00
.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 ;