From e0507bc451edcbe5911ec46c16b9479bbe7d56f6 Mon Sep 17 00:00:00 2001 From: tx7do Date: Mon, 2 Dec 2024 14:45:31 +0800 Subject: [PATCH] feat: edit makefile. --- backend/app.mk | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/app.mk b/backend/app.mk index 9b578e80..99f92571 100644 --- a/backend/app.mk +++ b/backend/app.mk @@ -1,4 +1,6 @@ GOPATH ?= $(shell go env GOPATH) +# GOVERSION is the current go version, e.g. go1.9.2 +GOVERSION ?= $(shell go version | awk '{print $$3;}') # Ensure GOPATH is set before running build process. ifeq "$(GOPATH)" "" @@ -6,17 +8,51 @@ ifeq "$(GOPATH)" "" endif FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }' -GO := GO111MODULE=on go +GO_CMD := GO111MODULE=on go +GIT_CMD := git +DOCKER_CMD := docker ARCH := "`uname -s`" LINUX := "Linux" MAC := "Darwin" +DEFAULT_VERSION=0.0.1 + ifeq ($(OS),Windows_NT) - IS_WINDOWS:=1 + IS_WINDOWS:=TRUE +endif + +ifneq (git,) + GIT_EXIST:=TRUE +endif + +ifneq ("$(wildcard .git)", "") + HAS_DOTGIT:=TRUE +endif + +ifeq ($(GIT_EXIST),TRUE) +ifeq ($(HAS_DOTGIT),TRUE) + # CUR_TAG is the last git tag plus the delta from the current commit to the tag + # e.g. v1.5.5--g + CUR_TAG ?= $(shell git describe --tags --first-parent) + + # LAST_TAG is the last git tag + # e.g. v1.5.5 + LAST_TAG ?= $(shell git describe --match "v*" --abbrev=0 --tags --first-parent) + + # VERSION is the last git tag without the 'v' + # e.g. 1.5.5 + VERSION ?= $(shell git describe --match "v*" --abbrev=0 --tags --first-parent | cut -c 2-) endif +endif + +CUR_TAG ?= $(DEFAULT_VERSION) +LAST_TAG ?= v$(DEFAULT_VERSION) +VERSION ?= $(DEFAULT_VERSION) + +# GOFLAGS is the flags for the go compiler. +GOFLAGS ?= -ldflags "-X main.version=$(VERSION)" -APP_VERSION=$(shell git describe --tags --always) APP_RELATIVE_PATH=$(shell a=`basename $$PWD` && cd .. && b=`basename $$PWD` && echo $$b/$$a) APP_NAME=$(shell echo $(APP_RELATIVE_PATH) | sed -En "s/\//-/p") APP_DOCKER_IMAGE=$(shell echo $(APP_NAME) |awk -F '@' '{print "restroom-system/" $$0 ":0.1.0"}')