categraf/Makefile

37 lines
1.2 KiB
Makefile
Raw Normal View History

2022-06-04 22:22:26 +08:00
.SILENT:
2022-06-04 22:11:40 +08:00
.PHONY: build build-linux build-windows pack
2022-05-29 17:37:57 +08:00
2022-06-04 22:11:40 +08:00
APP:=categraf
ROOT:=$(shell pwd -P)
GIT_COMMIT:=$(shell git --work-tree ${ROOT} rev-parse 'HEAD^{commit}')
_GIT_VERSION:=$(shell git --work-tree ${ROOT} describe --tags --abbrev=14 "${GIT_COMMIT}^{commit}" 2>/dev/null)
GIT_VERSION:=$(shell echo "${_GIT_VERSION}"| sed "s/-g\([0-9a-f]\{14\}\)$$/+\1/")
TAR_TAG:=$(shell echo ${GIT_VERSION}| awk -F"-" '{print $$1}')
2022-06-04 22:28:04 +08:00
BUILD_VERSION:='flashcat.cloud/categraf/config.Version=$(GIT_VERSION)'
2022-06-04 22:11:40 +08:00
LDFLAGS:="-w -s -X $(BUILD_VERSION)"
vendor:
GOPROXY=https://goproxy.cn go mod vendor
2022-05-29 17:37:57 +08:00
build:
2022-06-04 22:11:40 +08:00
echo "Building version $(GIT_VERSION)"
go build -ldflags $(LDFLAGS) -o $(APP)
build-linux:
echo "Building version $(GIT_VERSION) for linux"
2022-06-05 15:40:16 +08:00
GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(APP)
2022-06-04 22:11:40 +08:00
build-windows:
echo "Building version $(GIT_VERSION) for windows"
2022-06-04 22:22:26 +08:00
GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(APP).exe
2022-06-04 22:11:40 +08:00
build-mac:
echo "Building version $(GIT_VERSION) for mac"
2022-06-04 22:22:26 +08:00
GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(APP).mac
2022-06-04 22:11:40 +08:00
pack:build-linux build-windows
rm -rf $(APP)-$(TAR_TAG).tar.gz
rm -rf $(APP)-$(TAR_TAG).zip
tar -zcvf $(APP)-$(TAR_TAG)-linux-amd64.tar.gz conf $(APP)
zip -r $(APP)-$(TAR_TAG)-windows-amd64.zip conf $(APP).exe