ADDR ?= 127.0.0.1
BUILD_TYPE ?= Release

PREFIX := build/$(BUILD_TYPE)
PACKAGE_DIR := $(PREFIX)/monitor

# 日期 + git hash
BUILD_DATE := $(shell date +%Y%m%d)
GIT_HASH   := $(shell git rev-parse --short=8 HEAD 2>/dev/null)

PACKAGE_NAME := monitor_$(BUILD_TYPE)_$(BUILD_DATE)_$(GIT_HASH).tar.gz

all: clean build install

# -DCMAKE_TOOLCHAIN_FILE=./conf/toolchain.cmake
build:
	@cmake -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_INSTALL_PREFIX=$(PREFIX) -B build -S .
	@cmake --build build -j$(nproc)

install:
	cmake --install build

deploy:
	scp -r  PREFIX/monitor forlinx@${ADDR}:/home/forlinx

# 打包：将指定目录下的所有内容打包到压缩包根目录
package:
	@mkdir -p packages
	@echo "Packaging $(PACKAGE_DIR) -> $(PACKAGE_NAME)"
	@tar -zcvf packages/$(PACKAGE_NAME) -C $(PACKAGE_DIR) .

.PHONY: clean
clean:
	rm -rf build