From f5c96ef1a40e81d4e0b4e2a2a0bef1093b22c286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=B4=D1=8E=D0=B3=D0=BE=D0=B2=20=D0=9C?= =?UTF-8?q?=D0=B0=D0=BA=D1=81=D0=B8=D0=BC?= Date: Thu, 27 Jul 2023 09:53:29 +0300 Subject: [PATCH] add Makefile (#3) Co-authored-by: m.bordyugov --- Makefile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..1960e65f --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +BUILD_VERSION := $(if $(BUILD_VERSION),$(BUILD_VERSION),$(shell git describe --tags --always --dirty)) +BUILD_COMMIT := $(if $(BUILD_COMMIT),$(BUILD_COMMIT),$(shell git log --format="%H" -n 1)) +BUILD_COMMIT_TS := $(if $(BUILD_COMMIT_TS),$(BUILD_COMMIT_TS),$(shell git log --format="%ct" -n 1)) +BUILD_BRANCH := $(if $(BUILD_BRANCH),$(BUILD_BRANCH),$(shell git rev-parse --abbrev-ref HEAD)) +BUILD_TIME := $(if $(BUILD_TIME),$(BUILD_TIME),$(shell date +%FT%T%z)) +BUILD_MACHINE := $(if $(BUILD_MACHINE),$(BUILD_MACHINE),$(shell uname -n -m -r -s)) +BUILD_GO_VERSION := $(if $(BUILD_GO_VERSION),$(BUILD_GO_VERSION),$(shell go version | cut -d' ' -f3)) + +COMMON_BUILD_VARS := \ + -X 'github.com/vkcom/tl/internal/build.buildTimestamp=$(BUILD_TIME)' \ + -X 'github.com/vkcom/tl/internal/build.machine=$(BUILD_MACHINE)' \ + -X 'github.com/vkcom/tl/internal/build.commit=$(BUILD_COMMIT)' \ + -X 'github.com/vkcom/tl/internal/build.version=$(BUILD_VERSION)' \ + -X 'github.com/vkcom/tl/internal/build.commitTimestamp=$(BUILD_COMMIT_TS)' \ + -X 'github.com/vkcom/tl/internal/build.branchName=$(BUILD_BRANCH)' \ + +COMMON_LDFLAGS = $(COMMON_BUILD_VARS) -extldflags '-O2' + +GO = go + +SHA256_CHECKSUM := $(shell go run ./cmd/sha256sum ./internal) +ifndef SHA256_CHECKSUM +$(error SHA256_CHECKSUM failed to set, problem with go run cmd/sha256sum internal) +endif + +.PHONY: build + +all: build + +build: + @echo "Building tlgen with sha256 checksum $(SHA256_CHECKSUM)" + @$(GO) build -ldflags "$(COMMON_LDFLAGS) -X 'github.com/vkcom/tl/internal/tlcodegen.buildSHA256Checksum=$(SHA256_CHECKSUM)'" ./cmd/tlgen + +