-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
83 lines (70 loc) · 2.75 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
DEBUG ?= 1
TARGET ?=
SHELL := /usr/bin/env bash
ifneq ($(DEBUG), 0)
BUILD_ARGS :=
TARGET_DIR = target/$(TARGET)/debug/
else
BUILD_ARGS := $(BUILD_ARGS) --release
TARGET_DIR = target/$(TARGET)/release/
endif
ifdef TARGET
BUILD_ARGS := $(BUILD_ARGS) --target=$(TARGET)
endif
CARGO ?= cargo
PACKAGE_METADATA = $(shell cargo metadata --format-version=1 --no-deps)
PACKAGE_NAME = $(shell echo '$(PACKAGE_METADATA)' | jq -r .packages[0].name)
CURRENT_VERSION = $(shell echo '$(PACKAGE_METADATA)' | jq -r .packages[0].version)
CURRENT_REVISION = $(shell git rev-parse --short HEAD)
ifeq ($(RELEASE), 1)
VERSION = $(CURRENT_VERSION)
else
VERSION = $(CURRENT_VERSION)-$(CURRENT_REVISION)
endif
DIST_DIR = target/dist
PACKAGE_NAME_AND_VERSION = $(PACKAGE_NAME)-$(VERSION)-$(SUFFIX)
ARCHIVE_DIR = $(DIST_DIR)/$(PACKAGE_NAME_AND_VERSION)
ARCHIVE_NAME = $(PACKAGE_NAME_AND_VERSION).tar.zz
.DEFAULT_GOAL = help
.PHONY: dist build check-dist help container-binaries
dist: check-dist build
rm -rf $(ARCHIVE_DIR)
mkdir -p $(ARCHIVE_DIR)
ifneq (, $(findstring linux, $(TARGET)))
$(info Building distribution with Linux layout)
mkdir -p $(ARCHIVE_DIR)/etc/$(PACKAGE_NAME) \
$(ARCHIVE_DIR)/usr/local/bin \
$(ARCHIVE_DIR)/etc/systemd/system
cp $(TARGET_DIR)/$(PACKAGE_NAME) $(ARCHIVE_DIR)/usr/local/bin/
cp $(PACKAGE_NAME).service $(ARCHIVE_DIR)/etc/systemd/system/
cp weathermen.toml.dist $(ARCHIVE_DIR)/etc/$(PACKAGE_NAME)/
else
$(info Building distribution with basic layout)
cp $(TARGET_DIR)/$(PACKAGE_NAME) $(ARCHIVE_DIR)/
cp weathermen.toml.dist $(ARCHIVE_DIR)
endif
tar -C $(DIST_DIR) -Jcvf $(ARCHIVE_NAME) $(PACKAGE_NAME_AND_VERSION)
build:
PROMW_VERSION=$(VERSION) $(CARGO) build $(BUILD_ARGS)
check-dist:
ifndef SUFFIX
_ := $(error SUFFIX must be defined)
endif
container-binaries: $(wildcard $(BINARY_ARCHIVE_DIR)/*/*.tar.zz)
mkdir -p $(CONTAINER_BINARY_DIR)
for archive in $^; do tar -C $(CONTAINER_BINARY_DIR) -Jxf $$archive ; done
platforms=(linux/amd64 linux/arm64 linux/arm/v7); \
targets=(x86_64-linux-static arm64-linux-static arm-linux-static); \
let "len = $${#platforms[@]} - 1"; \
for n in $$(seq 0 $$len); do \
platform=$${platforms[$$n]}; \
target=$${targets[$$n]}; \
mkdir -p $(CONTAINER_BINARY_DIR)/$${platform}; \
cp $(CONTAINER_BINARY_DIR)/prometheus-weathermen-*-$${target}/usr/local/bin/prometheus-weathermen $(CONTAINER_BINARY_DIR)/$${platform}; \
done; \
echo platforms=$${platforms[@]} | tr " " "," >> $(PLATFORM_FILE)
help:
@echo "Targets:"
@echo "Build dev target on the current machine: make build"
@echo "Build distribution package: make dist [DEBUG=1] [RELEASE=0] [TARGET=] [SUFFIX=]"
@echo "Prepare container binaries: make container-binaries [BINARY_ARCHIVE_DIR=] [CONTAINER_BINARY_DIR=] [PLATFORM_FILE=]"