forked from falcosecurity/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
120 lines (99 loc) · 4.27 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
SHELL := /bin/bash
DRIVERKIT := $(shell command -v driverkit)
ifeq ($(DRIVERKIT),)
DRIVERKIT := "/bin/driverkit"
endif
ALL_ARCHS := x86_64 aarch64
# Recursive wildcard
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# Equals function
eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
CONFIGS := $(call rwildcard,config/*,*.yaml)
VERSIONS := $(patsubst config/%,%,$(sort $(dir $(wildcard config/*/))))
VERSIONS := $(VERSIONS:/=)
TARGET_VERSION ?= *
TARGET_DISTRO ?= *
TARGET_KERNEL_RELEASE ?= *
TARGET_KERNEL_VERSION ?= *
TARGET_KERNEL ?= ${TARGET_KERNEL_RELEASE}_${TARGET_KERNEL_VERSION}
TARGET_ARCH ?= *
# If TARGET_ARCH value is "*" then we consider all the the supported archs in ALL_ARCHS,
# otherwise we just keep the one passed as parameter.
TARGET_ARCHS := $(if $(call eq,$(TARGET_ARCH),*),$(ALL_ARCHS),$(TARGET_ARCH))
TARGET_HEADERS ?=
TARGET_KERNEL_DEFCONFIG ?=
S3_DRIVERS_BUCKET ?= "falco-distribution"
S3_DRIVERS_KEY_PREFIX ?= "driver"
DRIVERKIT_BACKEND ?= docker
DRIVERKIT_EXTRA_ARGS ?=
SKIP_EXISTING ?= true
validate: $(patsubst config_%,validate/%,$(subst /,_,$(wildcard config/${TARGET_VERSION}*/${TARGET_ARCH}/${TARGET_DISTRO}_${TARGET_KERNEL}.yaml)))
all: $(patsubst config_%,%,$(subst /,_,$(CONFIGS)))
specific_target: $(patsubst config_%,%,$(subst /,_,$(wildcard config/${TARGET_VERSION}*/${TARGET_ARCH}/${TARGET_DISTRO}_${TARGET_KERNEL}.yaml)))
prepare: $(addprefix prepare_,$(VERSIONS))
publish: publish_s3 # alias publish_s3; bintray is no more supported
publish_s3: $(addprefix publish_s3_,$(VERSIONS))
generate:
$(foreach ARCH,$(TARGET_ARCHS),\
$(foreach VERSION,$(VERSIONS),\
utils/generate -a '$(ARCH)' -k '${TARGET_KERNEL}' -r '${TARGET_KERNEL_RELEASE}' -t '${TARGET_KERNEL_VERSION}' -d '${TARGET_DISTRO}' -h '${TARGET_HEADERS}' -v '${VERSION}' -c '${TARGET_KERNEL_DEFCONFIG}'; \
)\
)
# clean old configurations before generating the new ones
generate/auto:
$(foreach ARCH,$(TARGET_ARCHS),\
utils/scrape_and_generate $(ARCH); \
)
cleanup: cleanup_s3 # alias cleanup_s3; bintray is no more supported
cleanup_s3:
S3_DRIVERS_BUCKET=${S3_DRIVERS_BUCKET} S3_DRIVERS_KEY_PREFIX=${S3_DRIVERS_KEY_PREFIX} utils/cleanup_s3 $(addprefix -v ,$(VERSIONS))
# $(1): pseudo-target name
# $(2): config file path
define gen_build_targets
validate/$(1): $(2)
utils/checkfiles $(2)
$(1): validate/$(1) $(2)
DRIVERKIT=${DRIVERKIT} S3_DRIVERS_BUCKET=${S3_DRIVERS_BUCKET} S3_DRIVERS_KEY_PREFIX=${S3_DRIVERS_KEY_PREFIX} SKIP_EXISTING=${SKIP_EXISTING} DRIVERKIT_BACKEND=${DRIVERKIT_BACKEND} DRIVERKIT_EXTRA_ARGS="${DRIVERKIT_EXTRA_ARGS}" utils/build $(2)
endef
$(foreach CONFIG,$(CONFIGS),\
$(eval TARGET := $(patsubst config_%,%,$(subst /,_,$(CONFIG))))\
$(eval $(call gen_build_targets,$(TARGET),$(CONFIG)))\
)
# $(1): driver version
define gen_publish_targets
split_$(1)_kernelmodules:
ifneq ("$(wildcard output/$(1)/x86_64/*.ko)","")
@mkdir -p output/$(1)/kernel-module/x86_64
@mv -f output/$(1)/x86_64/*.ko output/$(1)/kernel-module/x86_64
endif
ifneq ("$(wildcard output/$(1)/aarch64/*.ko)","")
@mkdir -p output/$(1)/kernel-module/aarch64
@mv -f output/$(1)/aarch64/*.ko output/$(1)/kernel-module/aarch64
endif
split_$(1)_ebpfprobes:
ifneq ("$(wildcard output/$(1)/x86_64/*.o)","")
@mkdir -p output/$(1)/ebpf-probe/x86_64
@mv -f output/$(1)/x86_64/*.o output/$(1)/ebpf-probe/x86_64
endif
ifneq ("$(wildcard output/$(1)/aarch64/*.o)","")
@mkdir -p output/$(1)/ebpf-probe/aarch64
@mv -f output/$(1)/aarch64/*.o output/$(1)/ebpf-probe/aarch64
endif
publish_s3_$(1): split_$(1)_kernelmodules split_$(1)_ebpfprobes
if [ -d "output/$(1)/ebpf-probe" ]; then \
echo "publishing eBPF probes (version $(1)) to S3 ..."; \
aws s3 cp "output/$(1)/ebpf-probe/" s3://${S3_DRIVERS_BUCKET}/${S3_DRIVERS_KEY_PREFIX}/$(1) --recursive --exclude "*" --include "*.o" --acl public-read; \
fi
if [ -d "output/$(1)/kernel-module" ]; then \
echo "publishing kernel modules (version $(1)) to S3 ..."; \
aws s3 cp "output/$(1)/kernel-module/" s3://${S3_DRIVERS_BUCKET}/${S3_DRIVERS_KEY_PREFIX}/$(1) --recursive --exclude "*" --include "*.ko" --acl public-read; \
fi
endef
$(foreach VERSION,$(VERSIONS),\
$(eval $(call gen_publish_targets,$(VERSION)))\
)
.PHONY: clean
clean:
find output/ -not -name '.gitignore' -not -name 'output' -delete
stats:
@utils/driverstats