Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加编译版本时间等信息Makefile方案 #10

Open
lingr7 opened this issue Nov 17, 2022 · 0 comments
Open

添加编译版本时间等信息Makefile方案 #10

lingr7 opened this issue Nov 17, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@lingr7
Copy link

lingr7 commented Nov 17, 2022

参考博主文章https://zhuanlan.zhihu.com/p/88688319

.PHONY: all build deploy help
BINARY=$(shell basename "$(PWD)")
WORKDIR=`pwd`

default: deploy

CUR_DIR := $(shell pwd)
CUR_TIME := $(shell date +"%Y-%m-%d_%H:%M.%S")


# 获取git tag版本号
GitTag :=$(shell git tag --sort=version:refname | tail -n 1)
# 获取源码最近一次git commit log,包含commit sha 值,以及commit message
GitCommitLog :=$(shell git log --pretty=oneline -n 1)
# 将log原始字符串中的单引号替换成双引号
# GitCommitLog :=${GitCommitLog//\'/\"}
# 检查源码在git commit基础上,是否有本地修改,且未提交的内容
GitStatus := $(shell git status -s)
# 获取当前时间
BuildTime := $(shell date +"%Y-%m-%d_%H:%M.%S")
# 获取Go的版本
BuildGoVersion := $(shell go version)

LDFLAGS=-ldflags "-s -w \
    -X 'github.com/q191201771/naza/pkg/bininfo.GitCommitLog=${GitCommitLog}' \
    -X 'github.com/q191201771/naza/pkg/bininfo.GitStatus=${GitStatus}' \
    -X 'github.com/q191201771/naza/pkg/bininfo.BuildTime=${BuildTime}' \
    -X 'github.com/q191201771/naza/pkg/bininfo.BuildGoVersion=${BuildGoVersion}' \
"

all:
	@echo $(CUR_DIR)
	@echo $(CUR_TIME)


build:
	go build ./

deploy:
	@echo "build notify"
	@echo ${LDFLAGS} 
	@go build -o ${BINARY} -v ${LDFLAGS} 

help:
	@echo "make 格式化go代码 并编译生成二进制文件"
	@echo "make build 编译go代码生成二进制文件"
	@echo "make deploy 生成二进制文件并发布"
@q191201771 q191201771 added the documentation Improvements or additions to documentation label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants