-
Notifications
You must be signed in to change notification settings - Fork 21
/
tools.mk
40 lines (31 loc) · 1.68 KB
/
tools.mk
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
# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
export TOOLS_BIN_DIR := $(TOOLS_BIN_DIR)
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
#########################################
# Common #
#########################################
# Tool targets should declare go.mod as a prerequisite, if the tool's version is managed via go modules. This causes
# make to rebuild the tool in the desired version, when go.mod is changed.
# For tools where the version is not managed via go.mod, we use a file per tool and version as an indicator for make
# whether we need to install the tool or a different version of the tool (make doesn't rerun the rule if the rule is
# changed).
# Use this "function" to add the version file as a prerequisite for the tool target: e.g.
# $(HELM): $(call tool_version_file,$(HELM),$(HELM_VERSION))
tool_version_file = $(TOOLS_BIN_DIR)/.version_$(subst $(TOOLS_BIN_DIR)/,,$(1))_$(2)
# This target cleans up any previous version files for the given tool and creates the given version file.
# This way, we can generically determine, which version was installed without calling each and every binary explicitly.
$(TOOLS_BIN_DIR)/.version_%:
@version_file=$@; rm -f $${version_file%_*}*
@touch $@
.PHONY: clean-tools-bin
clean-tools-bin:
rm -rf $(TOOLS_BIN_DIR)/*
#########################################
# Tools #
#########################################
$(MOCKGEN): go.mod
go build -o $(MOCKGEN) github.com/golang/mock/mockgen