Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
  2. IMAGE_NAME := mtg
  3. APP_NAME := $(IMAGE_NAME)
  4. CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
  5. GOLANGCI_LINT_VERSION := v1.39.0
  6. VERSION_GO := $(shell go version)
  7. VERSION_DATE := $(shell date -Ru)
  8. VERSION_TAG := $(shell git describe --tags --always)
  9. COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-extldflags '-static' -s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
  10. GOBIN := $(ROOT_DIR)/.bin
  11. GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
  12. # -----------------------------------------------------------------------------
  13. .PHONY: all
  14. all: build
  15. .PHONY: build
  16. build:
  17. @go build $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"
  18. $(APP_NAME): build
  19. .PHONY: static
  20. static:
  21. @env CGO_ENABLED=0 GOOS=linux go build \
  22. $(COMMON_BUILD_FLAGS) \
  23. -tags netgo \
  24. -a \
  25. -o "$(APP_NAME)"
  26. $(APP_NAME)-%: GOOS=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f1 -d-)
  27. $(APP_NAME)-%: GOARCH=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f2 -d-)
  28. $(APP_NAME)-%: ccbuilds
  29. @env "GOOS=$(GOOS)" "GOARCH=$(GOARCH)" \
  30. go build \
  31. $(COMMON_BUILD_FLAGS) \
  32. -tags netgo \
  33. -a \
  34. -o "./ccbuilds/$(APP_NAME)-$(GOOS)-$(GOARCH)"
  35. .PHONY: ccbuilds
  36. ccbuilds:
  37. @rm -rf ./ccbuilds && mkdir -p ./ccbuilds
  38. vendor: go.mod go.sum
  39. @$(MOD_ON) go mod vendor
  40. .PHONY: fmt
  41. fmt:
  42. @$(GOTOOL) gofumpt -w -s -extra "$(ROOT_DIR)"
  43. .PHONY: test
  44. test:
  45. @go test -v ./...
  46. .PHONY: citest
  47. citest:
  48. @go test -coverprofile=coverage.txt -covermode=atomic -parallel 2 -race -v ./...
  49. .PHONY: crosscompile
  50. crosscompile: $(CC_BINARIES)
  51. .PHONY: clean
  52. clean:
  53. @git clean -xfd && \
  54. git reset --hard >/dev/null && \
  55. git submodule foreach --recursive sh -c 'git clean -xfd && git reset --hard' >/dev/null
  56. .PHONY: lint
  57. lint:
  58. @$(GOTOOL) golangci-lint run
  59. .PHONY: docker
  60. docker:
  61. @docker build --pull -t "$(IMAGE_NAME)" "$(ROOT_DIR)"
  62. .PHONY: doc
  63. doc:
  64. @$(GOTOOL) godoc -http 0.0.0.0:10000
  65. .PHONY: install-tools
  66. install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt
  67. .PHONY: install-tools-lint
  68. install-tools-lint:
  69. @mkdir -p "$(GOBIN)" || true && \
  70. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
  71. | bash -s -- -b "$(GOBIN)" "$(GOLANGCI_LINT_VERSION)"
  72. .PHONY: install-tools-godoc
  73. install-tools-godoc:
  74. @mkdir -p "$(GOBIN)" || true && \
  75. $(GOTOOL) go get -u golang.org/x/tools/cmd/godoc
  76. .PHONY: install-tools-gofumpt
  77. install-tools-gofumpt:
  78. @mkdir -p "$(GOBIN)" || true && \
  79. $(GOTOOL) go get -u mvdan.cc/gofumpt
  80. .PHONY: update-deps
  81. update-deps:
  82. @go get -u && go mod tidy