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)
|
2022-06-13 12:20:04 +08:00
|
|
|
TAG=$(shell echo "${_GIT_VERSION}" | awk -F"-" '{print $$1}')
|
|
|
|
GIT_VERSION:="$(TAG)-$(GIT_COMMIT)"
|
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)"
|
|
|
|
|
2022-06-07 10:36:17 +08:00
|
|
|
all: build
|
|
|
|
|
2022-06-04 22:11:40 +08:00
|
|
|
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)
|
|
|
|
|
2022-06-13 12:20:04 +08:00
|
|
|
|
2022-06-04 22:11:40 +08:00
|
|
|
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
|
|
|
|
2022-06-13 12:20:04 +08:00
|
|
|
build-image: build-linux
|
|
|
|
echo "Building image flashcatcloud/categraf:$(TAG)"
|
|
|
|
cp -f categraf docker/ && cd docker && docker build -t flashcatcloud/categraf:$(TAG) .
|
|
|
|
|
2022-06-04 22:11:40 +08:00
|
|
|
pack:build-linux build-windows
|
2022-06-13 12:20:04 +08:00
|
|
|
rm -rf $(APP)-$(TAG).tar.gz
|
|
|
|
rm -rf $(APP)-$(TAG).zip
|
|
|
|
tar -zcvf $(APP)-$(TAG)-linux-amd64.tar.gz conf $(APP)
|
|
|
|
zip -r $(APP)-$(TAG)-windows-amd64.zip conf $(APP).exe
|