This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMakefile
150 lines (117 loc) · 3.54 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
TARGET = kata-ksm-throttler
PACKAGE_URL = github.com/kata-containers/ksm-throttler
PACKAGE_NAME = $(TARGET)
BASE = $(GOPATH)/src/$(PACKAGE_URL)
PREFIX = /usr
BIN_DIR = $(PREFIX)/bin
LIBEXECDIR = $(PREFIX)/libexec
LOCALSTATEDIR = /var
SOURCES = $(shell find . 2>&1 | grep -E '.*\.(c|h|go)$$')
KSM_SOCKET = $(LOCALSTATEDIR)/run/$(TARGET)/ksm.sock
TRIGGER_DIR = $(GOPATH)/src/$(PACKAGE_URL)/trigger
GO = go
PKGS = $(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "/vendor/"))
TARGET_KICKER = $(TRIGGER_DIR)/kicker/kicker
TARGET_VC = $(TRIGGER_DIR)/virtcontainers/vc
VERSION_FILE := ./VERSION
VERSION := $(shell grep -v ^\# $(VERSION_FILE))
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
#
# Pretty printing
#
V = @
Q = $(V:1=)
QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
QUIET_GOBUILD = $(Q:@=@echo ' GOBUILD '$@;)
QUIET_INST = $(Q:@=@echo ' INSTALL '$@;)
#
# Build
#
all: build binaries
build:
$(QUIET_GOBUILD)go build $(PKGS)
$(TARGET):
$(QUIET_GOBUILD)go build -o $@ -ldflags \
"-X main.DefaultURI=$(KSM_SOCKET) -X main.name=$(TARGET) -X main.version=$(VERSION_COMMIT)" throttler.go ksm.go
$(TARGET_KICKER):
$(QUIET_GOBUILD)go build -o $@ \
-ldflags "-X main.DefaultURI=$(KSM_SOCKET)" $(wildcard $(TRIGGER_DIR)/kicker/*.go)
$(TARGET_VC):
$(QUIET_GOBUILD)go build -o $@ \
-ldflags "-X main.DefaultURI=$(KSM_SOCKET)" $(wildcard $(TRIGGER_DIR)/virtcontainers/*.go)
kicker: $(TARGET_KICKER)
virtcontainers: $(TARGET_VC)
binaries: $(TARGET) kicker virtcontainers
#
# systemd files
#
HAVE_SYSTEMD := $(shell pkg-config --exists systemd 2>/dev/null && echo 'yes')
ifeq ($(HAVE_SYSTEMD),yes)
DEFAULT_SERVICE_FILE := ksm-throttler.service
DEFAULT_SERVICE_FILE_IN := $(DEFAULT_SERVICE_FILE).in
SERVICE_FILE := $(TARGET).service
SERVICE_FILE_IN := $(SERVICE_FILE).in
UNIT_DIR := $(shell pkg-config --variable=systemdsystemunitdir systemd)
UNIT_FILES = $(TARGET).service kata-vc-throttler.service
GENERATED_FILES += $(UNIT_FILES)
endif
unit-files: $(UNIT_FILES)
#
# Tests
#
check: check-go-static check-go-test
check-go-static:
bash .ci/static-checks.sh
check-go-test:
bash .ci/go-test.sh
#
# install
#
define INSTALL_EXEC
$(QUIET_INST)install -D $1 $(DESTDIR)$2/$1 || exit 1;
endef
define INSTALL_FILE
$(QUIET_INST)install -D -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
endef
all-installable: $(TARGET) virtcontainers $(UNIT_FILES)
install: all-installable
$(call INSTALL_EXEC,$(TARGET),$(LIBEXECDIR)/$(TARGET))
$(call INSTALL_EXEC,trigger/virtcontainers/vc,$(LIBEXECDIR)/$(TARGET))
$(foreach f,$(UNIT_FILES),$(call INSTALL_FILE,$f,$(UNIT_DIR)))
#
# Clean
#
clean:
rm -f $(TARGET)
rm -f $(TARGET_KICKER)
rm -f $(TARGET_VC)
rm -f $(UNIT_FILES)
$(GENERATED_FILES): %: %.in Makefile
@mkdir -p `dirname $@`
$(QUIET_GEN)sed \
-e 's|[@]bindir[@]|$(BINDIR)|g' \
-e 's|[@]libexecdir[@]|$(LIBEXECDIR)|' \
-e "s|[@]localstatedir[@]|$(LOCALSTATEDIR)|" \
-e "s|[@]TARGET[@]|$(TARGET)|" \
-e "s|[@]PACKAGE_NAME[@]|$(PACKAGE_NAME)|" \
-e "s|[@]PACKAGE_URL[@]|$(PACKAGE_URL)|" \
-e "s|[@]SERVICE_FILE[@]|$(SERVICE_FILE)|" \
"$<" > "$@"
.PHONY: \
all \
all-installable \
build \
binaries \
check \
check-go-static \
check-go-test \
install \
uninstall \
unit-files \
clean