2016-12-07 08:40:00 +00:00
|
|
|
DIST := dist
|
|
|
|
EXECUTABLE := gorush
|
|
|
|
|
2017-08-15 04:16:04 +00:00
|
|
|
GO ?= go
|
2016-12-07 08:40:00 +00:00
|
|
|
DEPLOY_ACCOUNT := appleboy
|
|
|
|
DEPLOY_IMAGE := $(EXECUTABLE)
|
2021-03-27 01:18:07 +00:00
|
|
|
GOFMT ?= gofumpt -l -s -extra
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2021-07-23 17:56:33 +00:00
|
|
|
TARGETS ?= linux darwin windows
|
2021-07-11 12:54:52 +00:00
|
|
|
ARCHS ?= amd64
|
2019-03-16 03:37:01 +00:00
|
|
|
GOFILES := $(shell find . -name "*.go" -type f)
|
|
|
|
TAGS ?= sqlite
|
2017-01-17 02:44:33 +00:00
|
|
|
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2022-11-09 06:18:51 +00:00
|
|
|
PROTOC_GEN_GO=v1.28
|
|
|
|
PROTOC_GEN_GO_GRPC=v1.2
|
|
|
|
|
2016-08-15 12:43:34 +00:00
|
|
|
ifneq ($(shell uname), Darwin)
|
|
|
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
|
|
|
else
|
|
|
|
EXTLDFLAGS =
|
|
|
|
endif
|
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
ifneq ($(DRONE_TAG),)
|
|
|
|
VERSION ?= $(DRONE_TAG)
|
|
|
|
else
|
2016-12-09 17:15:45 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
2016-12-07 08:40:00 +00:00
|
|
|
endif
|
|
|
|
|
2017-07-26 15:24:43 +00:00
|
|
|
.PHONY: all
|
2016-03-27 12:20:57 +00:00
|
|
|
all: build
|
|
|
|
|
2016-05-22 03:17:40 +00:00
|
|
|
init:
|
|
|
|
ifeq ($(ANDROID_API_KEY),)
|
|
|
|
@echo "Missing ANDROID_API_KEY Parameter"
|
|
|
|
@exit 1
|
|
|
|
endif
|
|
|
|
ifeq ($(ANDROID_TEST_TOKEN),)
|
|
|
|
@echo "Missing ANDROID_TEST_TOKEN Parameter"
|
|
|
|
@exit 1
|
|
|
|
endif
|
|
|
|
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
|
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
vet:
|
2020-02-03 08:50:13 +00:00
|
|
|
$(GO) vet ./...
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-02-25 12:31:49 +00:00
|
|
|
embedmd:
|
2019-03-16 03:37:01 +00:00
|
|
|
@hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2021-03-27 06:20:49 +00:00
|
|
|
$(GO) install github.com/campoy/embedmd@master; \
|
2016-12-07 08:40:00 +00:00
|
|
|
fi
|
2019-03-16 03:37:01 +00:00
|
|
|
embedmd -d *.md
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2018-01-04 08:32:50 +00:00
|
|
|
.PHONY: install
|
2019-03-16 03:37:01 +00:00
|
|
|
install: $(GOFILES)
|
2017-10-22 23:42:38 +00:00
|
|
|
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
2019-03-18 16:04:50 +00:00
|
|
|
@echo "\n==>\033[32m Installed gorush to ${GOPATH}/bin/gorush\033[m"
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-08-19 13:23:29 +00:00
|
|
|
.PHONY: build
|
2017-12-11 01:17:36 +00:00
|
|
|
build: $(EXECUTABLE)
|
2016-07-30 14:05:38 +00:00
|
|
|
|
2019-02-04 10:13:55 +00:00
|
|
|
.PHONY: $(EXECUTABLE)
|
2019-03-16 03:37:01 +00:00
|
|
|
$(EXECUTABLE): $(GOFILES)
|
2017-12-10 11:07:58 +00:00
|
|
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/$@
|
2016-08-15 12:43:34 +00:00
|
|
|
|
2017-06-05 02:45:38 +00:00
|
|
|
.PHONY: misspell-check
|
2019-03-16 03:37:01 +00:00
|
|
|
misspell-check:
|
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2021-03-27 06:00:40 +00:00
|
|
|
$(GO) install github.com/client9/misspell/cmd/misspell@v0.3.4; \
|
2019-03-16 03:37:01 +00:00
|
|
|
fi
|
|
|
|
misspell -error $(GOFILES)
|
2017-06-05 02:42:07 +00:00
|
|
|
|
2017-06-05 03:50:00 +00:00
|
|
|
.PHONY: misspell
|
2019-03-16 03:37:01 +00:00
|
|
|
misspell:
|
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2021-03-27 06:00:40 +00:00
|
|
|
$(GO) install github.com/client9/misspell/cmd/misspell@v0.3.4; \
|
2018-04-22 01:17:16 +00:00
|
|
|
fi
|
2019-03-16 03:37:01 +00:00
|
|
|
misspell -w $(GOFILES)
|
2018-04-22 01:17:16 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
.PHONY: test
|
2022-12-20 14:20:24 +00:00
|
|
|
test: init
|
2020-02-03 08:50:13 +00:00
|
|
|
@$(GO) test -v -cover -tags $(TAGS) -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
2016-04-11 06:10:46 +00:00
|
|
|
|
2019-04-27 15:45:28 +00:00
|
|
|
release: release-dirs release-build release-copy release-compress release-check
|
2016-12-08 03:43:23 +00:00
|
|
|
|
|
|
|
release-dirs:
|
|
|
|
mkdir -p $(DIST)/binaries $(DIST)/release
|
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
release-build:
|
|
|
|
@hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2021-03-27 06:00:40 +00:00
|
|
|
$(GO) install github.com/mitchellh/gox@v1.0.1; \
|
2019-03-16 03:37:01 +00:00
|
|
|
fi
|
2019-03-18 06:16:29 +00:00
|
|
|
gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
|
2016-12-08 03:43:23 +00:00
|
|
|
|
2019-04-27 15:45:28 +00:00
|
|
|
.PHONY: release-compress
|
|
|
|
release-compress:
|
|
|
|
@hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2021-03-27 06:00:40 +00:00
|
|
|
$(GO) install github.com/ulikunitz/xz/cmd/gxz@v0.5.10; \
|
2019-04-27 15:45:28 +00:00
|
|
|
fi
|
|
|
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
|
|
|
|
|
2016-12-08 03:43:23 +00:00
|
|
|
release-copy:
|
|
|
|
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
|
|
|
|
|
|
|
|
release-check:
|
|
|
|
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
|
|
|
|
2017-12-10 11:00:15 +00:00
|
|
|
build_linux_amd64:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-12-10 11:00:15 +00:00
|
|
|
build_linux_i386:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
|
2017-08-31 06:25:56 +00:00
|
|
|
|
2017-12-10 11:00:15 +00:00
|
|
|
build_linux_arm64:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
|
|
|
|
|
|
|
|
build_linux_arm:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
|
2017-08-25 05:51:04 +00:00
|
|
|
|
2018-01-23 08:34:34 +00:00
|
|
|
build_linux_lambda:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags 'lambda' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/lambda/$(DEPLOY_IMAGE)
|
|
|
|
|
2021-12-09 15:59:48 +00:00
|
|
|
build_darwin_amd64:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/darwin/amd64/$(DEPLOY_IMAGE)
|
|
|
|
|
|
|
|
build_darwin_i386:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/darwin/i386/$(DEPLOY_IMAGE)
|
|
|
|
|
|
|
|
build_darwin_arm64:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/darwin/arm64/$(DEPLOY_IMAGE)
|
|
|
|
|
|
|
|
build_darwin_arm:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm GOARM=7 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/darwin/arm/$(DEPLOY_IMAGE)
|
|
|
|
|
|
|
|
build_darwin_lambda:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -tags 'lambda' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/darwin/lambda/$(DEPLOY_IMAGE)
|
|
|
|
|
2016-03-27 12:20:57 +00:00
|
|
|
clean:
|
2018-10-15 03:49:53 +00:00
|
|
|
$(GO) clean -modcache -x -i ./...
|
2016-12-07 08:40:00 +00:00
|
|
|
find . -name coverage.txt -delete
|
2016-12-08 04:01:10 +00:00
|
|
|
find . -name *.tar.gz -delete
|
|
|
|
find . -name *.db -delete
|
2017-12-11 01:17:36 +00:00
|
|
|
-rm -rf release dist .cover
|
2016-11-20 01:54:16 +00:00
|
|
|
|
2022-11-09 06:18:51 +00:00
|
|
|
.PHONY: proto_install
|
|
|
|
proto_install:
|
|
|
|
$(GO) install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO)
|
|
|
|
$(GO) install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC)
|
|
|
|
|
2021-10-25 01:34:46 +00:00
|
|
|
generate_proto_js:
|
|
|
|
npm install grpc-tools
|
|
|
|
protoc -I rpc/proto rpc/proto/gorush.proto --js_out=import_style=commonjs,binary:rpc/example/node/ --grpc_out=rpc/example/node/ --plugin=protoc-gen-grpc="node_modules/.bin/grpc_tools_node_protoc_plugin"
|
2017-07-25 14:50:00 +00:00
|
|
|
|
2021-10-25 01:34:46 +00:00
|
|
|
generate_proto_go:
|
|
|
|
protoc -I rpc/proto rpc/proto/gorush.proto --go_out=rpc/proto --go-grpc_out=require_unimplemented_servers=false:rpc/proto
|
2017-07-25 14:50:00 +00:00
|
|
|
|
2021-10-25 01:34:46 +00:00
|
|
|
generate_proto: generate_proto_go generate_proto_js
|
2017-07-25 14:50:00 +00:00
|
|
|
|
2016-11-20 01:54:16 +00:00
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|