kuma
1# Explanation of used GNU Make concepts used in the file:
2#
3# "| $(DIRECTORY_NAME)" is an order-only prerequisite, which means prerequisite
4# that is never checked when determining if the target is out of date;
5# even order-only prerequisites marked as phony will not cause the target
6# to be rebuilt. In our case it's used to make $(DIRECTORY_NAME) directory,
7# if it doesn't exist.
8# ref. https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html
9#
10# "$(@D)" is the directory part of the file name of the target, with the trailing
11# slash removed. If the value of $(@) is "dir/foo.o" then $(@D) will be
12# equal "dir". This value will be equal "." if $(@) does not contain a slash.
13# ref. https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables
14
15RELEASE_TAG ?= main-dd8b1946a31a8ce03009a2743b18ebcc716cda6116RELEASE_REPO ?= https://github.com/kumahq/merbridge17# You can provide your own url if the tarball with all ebpf programs should be
18# fetched from somewhere else
19TARBALL_URL ?= $(RELEASE_REPO)/releases/download/$(RELEASE_TAG)20# Where should be placed directory with $(RELEASE_TAG) as name placed. We don't
21# allow to overwrite the final $(BUILD_OUTPUT) variable, because without $(RELEASE_TAG) and $(GOARCH), it may result in situation
22# where without realizing, ebpf programs are not re-fetched when $(RELEASE_TAG) or $(GOARCH) changes
23BASE_BUILD_OUTPUT = build/ebpf/$(RELEASE_TAG)24# Path where ebpf programs should be placed, to be compiled in when building kumactl
25COMPILE_IN_PATH ?= ./pkg/transparentproxy/ebpf/programs26
27# We are placing ebpf programs inside $(BUILD_OUTPUT_WITH_TAG) directory first,
28# as by default it contains $(RELEASE_TAG) in the path, which means
29# if the tag changes, we will re-fetch programs
30
31define make_ebpf_targets32$(1)/mb_*: | $(1)33curl --progress-bar --location $(TARBALL_URL)/all-$(3).tar.gz | tar -C $$(@D) -xz34
35$(2)/mb_*: | $(2) $(1)/mb_*36cp $(1)/mb_* $(2)37
38# Make $(2) $(1) directories if they don't
39# exist
40$(1) $(2):41mkdir -p $$@42endef
43
44EBF_ARCH:=amd64 arm6445$(foreach elt,$(EBF_ARCH),$(eval $(call make_ebpf_targets,$(BASE_BUILD_OUTPUT)/$(elt),$(COMPILE_IN_PATH)/$(elt),$(elt))))46
47EBF_TARGETS:=$(foreach elt,$(EBF_ARCH),$(BASE_BUILD_OUTPUT)/$(elt)/mb_* $(COMPILE_IN_PATH)/$(elt)/mb_*)48.PHONY: build/ebpf49build/ebpf: $(EBF_TARGETS)50
51.PHONY: clean/ebpf52clean/ebpf :53-rm -rf $(BUILD_DIR)/ebpf54find $(COMPILE_IN_PATH) -type f -name 'mb_*' -exec rm {} \;55