mirror of
https://github.com/wonli/aqi.git
synced 2025-12-24 10:40:58 +08:00
51 lines
1.3 KiB
Cheetah
51 lines
1.3 KiB
Cheetah
APP_NAME = {{.PackageName}}
|
|
APP_PATH = .
|
|
|
|
# 编译路径
|
|
BUILD_PATH := ./dist
|
|
|
|
# 编译时间
|
|
BUILD_DATE = $(shell date +'%F %T')
|
|
|
|
ifeq ($(shell test -d .git && echo yes),yes)
|
|
# git已初始化,可以安全执行git命令
|
|
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
|
GIT_COMMIT = $(shell git rev-list --count HEAD)
|
|
GIT_REVISION = $(shell git rev-parse --short HEAD)
|
|
GIT_COMMITAT = $(shell git --no-pager log -1 --format="%at")
|
|
else
|
|
# git未初始化,相关变量设为默认值
|
|
GIT_BRANCH = -
|
|
GIT_COMMIT = -
|
|
GIT_REVISION = -
|
|
GIT_COMMITAT = -
|
|
endif
|
|
|
|
# support包名称
|
|
FLAGS_PKG = github.com/wonli/aqi
|
|
LDFLAGS = "-X '$(FLAGS_PKG).BuildDate=$(BUILD_DATE)' \
|
|
-X '$(FLAGS_PKG).Branch=$(GIT_BRANCH)' \
|
|
-X '$(FLAGS_PKG).CommitVersion=$(GIT_COMMIT)' \
|
|
-X '$(FLAGS_PKG).Revision=$(GIT_REVISION)' \
|
|
-extldflags '-static -s -w'"
|
|
|
|
# 编译参数
|
|
GO_FLAGS = -ldflags $(LDFLAGS) -trimpath -tags netgo
|
|
|
|
# Go编译命令 1-GOOS 2-GOARCH 3-FILE EXT
|
|
define go/build
|
|
go mod tidy
|
|
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build $(GO_FLAGS) -o $(BUILD_PATH)/$(APP_NAME)-$(1)-$(2)-latest$(3) ${APP_PATH}
|
|
endef
|
|
|
|
# Generate binaries
|
|
.PHONY: build darwin linux windows
|
|
|
|
darwin:
|
|
$(call go/build,darwin,arm64)
|
|
|
|
linux:
|
|
$(call go/build,linux,amd64)
|
|
|
|
windows:
|
|
$(call go/build,windows,amd64,.exe) |